Import 2.3.49pre2
[davej-history.git] / include / linux / nfsd / nfsfh.h
blob20e850ec54d48448cbd7dc122d59cd65c6e8fdad
1 /*
2 * include/linux/nfsd/nfsfh.h
4 * This file describes the layout of the file handles as passed
5 * over the wire.
7 * Earlier versions of knfsd used to sign file handles using keyed MD5
8 * or SHA. I've removed this code, because it doesn't give you more
9 * security than blocking external access to port 2049 on your firewall.
11 * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
14 #ifndef _LINUX_NFSD_FH_H
15 #define _LINUX_NFSD_FH_H
17 #include <asm/types.h>
18 #ifdef __KERNEL__
19 # include <linux/config.h>
20 # include <linux/types.h>
21 # include <linux/string.h>
22 # include <linux/fs.h>
23 #endif
24 #include <linux/nfsd/const.h>
25 #include <linux/nfsd/debug.h>
28 * This is the new "dentry style" Linux NFSv2 file handle.
30 * The xino and xdev fields are currently used to transport the
31 * ino/dev of the exported inode.
33 struct nfs_fhbase {
34 struct dentry * fb_dentry; /* dentry cookie */
35 __u32 fb_ino; /* our inode number */
36 __u32 fb_dirino; /* dir inode number */
37 __u32 fb_dev; /* our device */
38 __u32 fb_xdev;
39 __u32 fb_xino;
40 __u32 fb_generation;
43 #define NFS_FH_PADDING (NFS_FHSIZE - sizeof(struct nfs_fhbase))
44 struct knfs_fh {
45 struct nfs_fhbase fh_base;
46 __u8 fh_cookie[NFS_FH_PADDING];
49 #define fh_dcookie fh_base.fb_dentry
50 #define fh_ino fh_base.fb_ino
51 #define fh_dirino fh_base.fb_dirino
52 #define fh_dev fh_base.fb_dev
53 #define fh_xdev fh_base.fb_xdev
54 #define fh_xino fh_base.fb_xino
55 #define fh_generation fh_base.fb_generation
57 #ifdef __KERNEL__
60 * Conversion macros for the filehandle fields.
62 extern inline __u32 kdev_t_to_u32(kdev_t dev)
64 return (__u32) dev;
67 extern inline kdev_t u32_to_kdev_t(__u32 udev)
69 return (kdev_t) udev;
72 extern inline __u32 ino_t_to_u32(ino_t ino)
74 return (__u32) ino;
77 extern inline ino_t u32_to_ino_t(__u32 uino)
79 return (ino_t) uino;
83 * This is the internal representation of an NFS handle used in knfsd.
84 * pre_mtime/post_version will be used to support wcc_attr's in NFSv3.
86 typedef struct svc_fh {
87 struct knfs_fh fh_handle; /* FH data */
88 struct dentry * fh_dentry; /* validated dentry */
89 struct svc_export * fh_export; /* export pointer */
90 #ifdef CONFIG_NFSD_V3
91 unsigned char fh_post_saved; /* post-op attrs saved */
92 unsigned char fh_pre_saved; /* pre-op attrs saved */
93 #endif /* CONFIG_NFSD_V3 */
94 unsigned char fh_locked; /* inode locked by us */
95 unsigned char fh_dverified; /* dentry has been checked */
97 #ifdef CONFIG_NFSD_V3
98 /* Pre-op attributes saved during fh_lock */
99 __u64 fh_pre_size; /* size before operation */
100 time_t fh_pre_mtime; /* mtime before oper */
101 time_t fh_pre_ctime; /* ctime before oper */
103 /* Post-op attributes saved in fh_unlock */
104 umode_t fh_post_mode; /* i_mode */
105 nlink_t fh_post_nlink; /* i_nlink */
106 uid_t fh_post_uid; /* i_uid */
107 gid_t fh_post_gid; /* i_gid */
108 __u64 fh_post_size; /* i_size */
109 unsigned long fh_post_blocks; /* i_blocks */
110 unsigned long fh_post_blksize;/* i_blksize */
111 kdev_t fh_post_rdev; /* i_rdev */
112 time_t fh_post_atime; /* i_atime */
113 time_t fh_post_mtime; /* i_mtime */
114 time_t fh_post_ctime; /* i_ctime */
115 #endif /* CONFIG_NFSD_V3 */
117 } svc_fh;
120 * Shorthand for dprintk()'s
122 #define SVCFH_DENTRY(f) ((f)->fh_dentry)
123 #define SVCFH_INO(f) ((f)->fh_handle.fh_ino)
124 #define SVCFH_DEV(f) ((f)->fh_handle.fh_dev)
127 * Function prototypes
129 u32 fh_verify(struct svc_rqst *, struct svc_fh *, int, int);
130 void fh_compose(struct svc_fh *, struct svc_export *, struct dentry *);
131 void fh_update(struct svc_fh *);
132 void fh_put(struct svc_fh *);
133 void nfsd_fh_flush(kdev_t);
134 void nfsd_fh_init(void);
135 void nfsd_fh_free(void);
137 static __inline__ struct svc_fh *
138 fh_copy(struct svc_fh *dst, struct svc_fh *src)
140 if (src->fh_dverified || src->fh_locked) {
141 struct dentry *dentry = src->fh_dentry;
142 printk(KERN_ERR "fh_copy: copying %s/%s, already verified!\n",
143 dentry->d_parent->d_name.name, dentry->d_name.name);
146 *dst = *src;
147 return dst;
150 static __inline__ struct svc_fh *
151 fh_init(struct svc_fh *fhp)
153 memset(fhp, 0, sizeof(*fhp));
154 return fhp;
157 #ifdef CONFIG_NFSD_V3
159 * Fill in the pre_op attr for the wcc data
161 static inline void
162 fill_pre_wcc(struct svc_fh *fhp)
164 struct inode *inode;
166 inode = fhp->fh_dentry->d_inode;
167 if (!fhp->fh_pre_saved) {
168 fhp->fh_pre_mtime = inode->i_mtime;
169 fhp->fh_pre_ctime = inode->i_ctime;
170 fhp->fh_pre_size = inode->i_size;
171 fhp->fh_pre_saved = 1;
173 fhp->fh_locked = 1;
177 * Fill in the post_op attr for the wcc data
179 static inline void
180 fill_post_wcc(struct svc_fh *fhp)
182 struct inode *inode = fhp->fh_dentry->d_inode;
184 if (fhp->fh_post_saved)
185 printk("nfsd: inode locked twice during operation.\n");
187 fhp->fh_post_mode = inode->i_mode;
188 fhp->fh_post_nlink = inode->i_nlink;
189 fhp->fh_post_uid = inode->i_uid;
190 fhp->fh_post_gid = inode->i_gid;
191 fhp->fh_post_size = inode->i_size;
192 if (inode->i_blksize) {
193 fhp->fh_post_blksize = inode->i_blksize;
194 fhp->fh_post_blocks = inode->i_blocks;
195 } else {
196 fhp->fh_post_blksize = BLOCK_SIZE;
197 /* how much do we care for accuracy with MinixFS? */
198 fhp->fh_post_blocks = (inode->i_size+511) >> 9;
200 fhp->fh_post_rdev = inode->i_rdev;
201 fhp->fh_post_atime = inode->i_atime;
202 fhp->fh_post_mtime = inode->i_mtime;
203 fhp->fh_post_ctime = inode->i_ctime;
204 fhp->fh_post_saved = 1;
205 fhp->fh_locked = 0;
207 #endif /* CONFIG_NFSD_V3 */
211 * Lock a file handle/inode
213 static inline void
214 fh_lock(struct svc_fh *fhp)
216 struct dentry *dentry = fhp->fh_dentry;
217 struct inode *inode;
219 dfprintk(FILEOP, "nfsd: fh_lock(%x/%ld) locked = %d\n",
220 SVCFH_DEV(fhp), (long)SVCFH_INO(fhp), fhp->fh_locked);
222 if (!fhp->fh_dverified) {
223 printk(KERN_ERR "fh_lock: fh not verified!\n");
224 return;
226 if (fhp->fh_locked) {
227 printk(KERN_WARNING "fh_lock: %s/%s already locked!\n",
228 dentry->d_parent->d_name.name, dentry->d_name.name);
229 return;
232 inode = dentry->d_inode;
233 down(&inode->i_sem);
234 #ifdef CONFIG_NFSD_V3
235 fill_pre_wcc(fhp);
236 #else
237 fhp->fh_locked = 1;
238 #endif /* CONFIG_NFSD_V3 */
242 * Unlock a file handle/inode
244 static inline void
245 fh_unlock(struct svc_fh *fhp)
247 if (!fhp->fh_dverified)
248 printk(KERN_ERR "fh_unlock: fh not verified!\n");
250 if (fhp->fh_locked) {
251 #ifdef CONFIG_NFSD_V3
252 fill_post_wcc(fhp);
253 up(&fhp->fh_dentry->d_inode->i_sem);
254 #else
255 struct dentry *dentry = fhp->fh_dentry;
256 struct inode *inode = dentry->d_inode;
258 fhp->fh_locked = 0;
259 up(&inode->i_sem);
260 #endif /* CONFIG_NFSD_V3 */
263 #endif /* __KERNEL__ */
266 #endif /* _LINUX_NFSD_FH_H */