Import 2.3.1pre1
[davej-history.git] / include / linux / nfsd / nfsfh.h
blob5c0d673f2447d86bee71a43ef33b8fc51c385c6d
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 NFSD_FH_H
15 #define NFSD_FH_H
17 #include <linux/types.h>
18 #include <linux/string.h>
19 #include <linux/fs.h>
20 #include <linux/nfsd/const.h>
21 #include <linux/nfsd/debug.h>
24 * This is the new "dentry style" Linux NFSv2 file handle.
26 * The xino and xdev fields are currently used to transport the
27 * ino/dev of the exported inode.
29 struct nfs_fhbase {
30 struct dentry * fb_dentry; /* dentry cookie */
31 __u32 fb_ino; /* our inode number */
32 __u32 fb_dirino; /* dir inode number */
33 __u32 fb_dev; /* our device */
34 __u32 fb_xdev;
35 __u32 fb_xino;
36 __u32 fb_generation;
39 #define NFS_FH_PADDING (NFS_FHSIZE - sizeof(struct nfs_fhbase))
40 struct knfs_fh {
41 struct nfs_fhbase fh_base;
42 __u8 fh_cookie[NFS_FH_PADDING];
45 #define fh_dcookie fh_base.fb_dentry
46 #define fh_ino fh_base.fb_ino
47 #define fh_dirino fh_base.fb_dirino
48 #define fh_dev fh_base.fb_dev
49 #define fh_xdev fh_base.fb_xdev
50 #define fh_xino fh_base.fb_xino
51 #define fh_generation fh_base.fb_generation
53 #ifdef __KERNEL__
56 * Conversion macros for the filehandle fields.
58 extern inline __u32 kdev_t_to_u32(kdev_t dev)
60 return (__u32) dev;
63 extern inline kdev_t u32_to_kdev_t(__u32 udev)
65 return (kdev_t) udev;
68 extern inline __u32 ino_t_to_u32(ino_t ino)
70 return (__u32) ino;
73 extern inline ino_t u32_to_ino_t(__u32 uino)
75 return (ino_t) uino;
79 * This is the internal representation of an NFS handle used in knfsd.
80 * pre_mtime/post_version will be used to support wcc_attr's in NFSv3.
82 typedef struct svc_fh {
83 struct knfs_fh fh_handle; /* FH data */
84 struct dentry * fh_dentry; /* validated dentry */
85 struct svc_export * fh_export; /* export pointer */
86 size_t fh_pre_size; /* size before operation */
87 time_t fh_pre_mtime; /* mtime before oper */
88 time_t fh_pre_ctime; /* ctime before oper */
89 unsigned long fh_post_version;/* inode version after oper */
90 unsigned char fh_locked; /* inode locked by us */
91 unsigned char fh_dverified; /* dentry has been checked */
92 } svc_fh;
95 * Shorthand for dprintk()'s
97 #define SVCFH_DENTRY(f) ((f)->fh_dentry)
98 #define SVCFH_INO(f) ((f)->fh_handle.fh_ino)
99 #define SVCFH_DEV(f) ((f)->fh_handle.fh_dev)
102 * Function prototypes
104 u32 fh_verify(struct svc_rqst *, struct svc_fh *, int, int);
105 void fh_compose(struct svc_fh *, struct svc_export *, struct dentry *);
106 void fh_update(struct svc_fh *);
107 void fh_put(struct svc_fh *);
108 void nfsd_fh_flush(kdev_t);
109 void nfsd_fh_init(void);
110 void nfsd_fh_free(void);
112 void expire_all(void);
113 void expire_by_dentry(struct dentry *);
115 static __inline__ struct svc_fh *
116 fh_copy(struct svc_fh *dst, struct svc_fh *src)
118 if (src->fh_dverified || src->fh_locked) {
119 struct dentry *dentry = src->fh_dentry;
120 printk(KERN_ERR "fh_copy: copying %s/%s, already verified!\n",
121 dentry->d_parent->d_name.name, dentry->d_name.name);
124 *dst = *src;
125 return dst;
128 static __inline__ struct svc_fh *
129 fh_init(struct svc_fh *fhp)
131 memset(fhp, 0, sizeof(*fhp));
132 return fhp;
136 * Lock a file handle/inode
138 static inline void
139 fh_lock(struct svc_fh *fhp)
141 struct dentry *dentry = fhp->fh_dentry;
142 struct inode *inode;
145 dfprintk(FILEOP, "nfsd: fh_lock(%x/%ld) locked = %d\n",
146 SVCFH_DEV(fhp), SVCFH_INO(fhp), fhp->fh_locked);
148 if (!fhp->fh_dverified) {
149 printk(KERN_ERR "fh_lock: fh not verified!\n");
150 return;
152 if (fhp->fh_locked) {
153 printk(KERN_WARNING "fh_lock: %s/%s already locked!\n",
154 dentry->d_parent->d_name.name, dentry->d_name.name);
155 return;
158 inode = dentry->d_inode;
159 down(&inode->i_sem);
160 if (!fhp->fh_pre_mtime)
161 fhp->fh_pre_mtime = inode->i_mtime;
162 fhp->fh_locked = 1;
166 * Unlock a file handle/inode
168 static inline void
169 fh_unlock(struct svc_fh *fhp)
171 if (!fhp->fh_dverified)
172 printk(KERN_ERR "fh_unlock: fh not verified!\n");
174 if (fhp->fh_locked) {
175 struct dentry *dentry = fhp->fh_dentry;
176 struct inode *inode = dentry->d_inode;
178 if (!fhp->fh_post_version)
179 fhp->fh_post_version = inode->i_version;
180 fhp->fh_locked = 0;
181 up(&inode->i_sem);
186 * Release an inode
188 #if 0
189 #define fh_put(fhp) __fh_put(fhp, __FILE__, __LINE__)
191 static inline void
192 __fh_put(struct svc_fh *fhp, char *file, int line)
194 struct dentry *dentry;
196 if (!fhp->fh_dverified)
197 return;
199 dentry = fhp->fh_dentry;
200 if (!dentry->d_count) {
201 printk("nfsd: trying to free free dentry in %s:%d\n"
202 " file %s/%s\n",
203 file, line,
204 dentry->d_parent->d_name.name, dentry->d_name.name);
205 } else {
206 fh_unlock(fhp);
207 fhp->fh_dverified = 0;
208 dput(dentry);
211 #endif
213 #endif /* __KERNEL__ */
215 #endif /* NFSD_FH_H */