- Add QNX4 file system.
[davej-history.git] / include / linux / nfsd / nfsfh.h
blobe33eaa41865582da422312bf668ce6794b5c06a5
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;
38 #define NFS_FH_PADDING (NFS_FHSIZE - sizeof(struct nfs_fhbase))
39 struct knfs_fh {
40 struct nfs_fhbase fh_base;
41 __u8 fh_cookie[NFS_FH_PADDING];
44 #define fh_dcookie fh_base.fb_dentry
45 #define fh_ino fh_base.fb_ino
46 #define fh_dirino fh_base.fb_dirino
47 #define fh_dev fh_base.fb_dev
48 #define fh_xdev fh_base.fb_xdev
49 #define fh_xino fh_base.fb_xino
51 #ifdef __KERNEL__
54 * Conversion macros for the filehandle fields.
56 extern inline __u32 kdev_t_to_u32(kdev_t dev)
58 return (__u32) dev;
61 extern inline kdev_t u32_to_kdev_t(__u32 udev)
63 return (kdev_t) udev;
66 extern inline __u32 ino_t_to_u32(ino_t ino)
68 return (__u32) ino;
71 extern inline ino_t u32_to_ino_t(__u32 uino)
73 return (ino_t) uino;
77 * This is the internal representation of an NFS handle used in knfsd.
78 * pre_mtime/post_version will be used to support wcc_attr's in NFSv3.
80 typedef struct svc_fh {
81 struct knfs_fh fh_handle; /* FH data */
82 struct dentry * fh_dentry; /* validated dentry */
83 struct svc_export * fh_export; /* export pointer */
84 size_t fh_pre_size; /* size before operation */
85 time_t fh_pre_mtime; /* mtime before oper */
86 time_t fh_pre_ctime; /* ctime before oper */
87 unsigned long fh_post_version;/* inode version after oper */
88 unsigned char fh_locked; /* inode locked by us */
89 unsigned char fh_dverified; /* dentry has been checked */
90 } svc_fh;
93 * Shorthand for dprintk()'s
95 #define SVCFH_DENTRY(f) ((f)->fh_dentry)
96 #define SVCFH_INO(f) ((f)->fh_handle.fh_ino)
97 #define SVCFH_DEV(f) ((f)->fh_handle.fh_dev)
100 * Function prototypes
102 u32 fh_verify(struct svc_rqst *, struct svc_fh *, int, int);
103 void fh_compose(struct svc_fh *, struct svc_export *, struct dentry *);
104 void fh_update(struct svc_fh *);
105 void fh_put(struct svc_fh *);
106 void nfsd_fh_flush(kdev_t);
107 void nfsd_fh_init(void);
108 void nfsd_fh_free(void);
110 static __inline__ struct svc_fh *
111 fh_copy(struct svc_fh *dst, struct svc_fh *src)
113 if (src->fh_dverified || src->fh_locked) {
114 struct dentry *dentry = src->fh_dentry;
115 printk(KERN_ERR "fh_copy: copying %s/%s, already verified!\n",
116 dentry->d_parent->d_name.name, dentry->d_name.name);
119 *dst = *src;
120 return dst;
123 static __inline__ struct svc_fh *
124 fh_init(struct svc_fh *fhp)
126 memset(fhp, 0, sizeof(*fhp));
127 return fhp;
131 * Lock a file handle/inode
133 static inline void
134 fh_lock(struct svc_fh *fhp)
136 struct dentry *dentry = fhp->fh_dentry;
137 struct inode *inode;
140 dfprintk(FILEOP, "nfsd: fh_lock(%x/%ld) locked = %d\n",
141 SVCFH_DEV(fhp), SVCFH_INO(fhp), fhp->fh_locked);
143 if (!fhp->fh_dverified) {
144 printk(KERN_ERR "fh_lock: fh not verified!\n");
145 return;
147 if (fhp->fh_locked) {
148 printk(KERN_WARNING "fh_lock: %s/%s already locked!\n",
149 dentry->d_parent->d_name.name, dentry->d_name.name);
150 return;
153 inode = dentry->d_inode;
154 down(&inode->i_sem);
155 if (!fhp->fh_pre_mtime)
156 fhp->fh_pre_mtime = inode->i_mtime;
157 fhp->fh_locked = 1;
161 * Unlock a file handle/inode
163 static inline void
164 fh_unlock(struct svc_fh *fhp)
166 if (!fhp->fh_dverified)
167 printk(KERN_ERR "fh_unlock: fh not verified!\n");
169 if (fhp->fh_locked) {
170 struct dentry *dentry = fhp->fh_dentry;
171 struct inode *inode = dentry->d_inode;
173 if (!fhp->fh_post_version)
174 fhp->fh_post_version = inode->i_version;
175 fhp->fh_locked = 0;
176 up(&inode->i_sem);
181 * Release an inode
183 #if 0
184 #define fh_put(fhp) __fh_put(fhp, __FILE__, __LINE__)
186 static inline void
187 __fh_put(struct svc_fh *fhp, char *file, int line)
189 struct dentry *dentry;
191 if (!fhp->fh_dverified)
192 return;
194 dentry = fhp->fh_dentry;
195 if (!dentry->d_count) {
196 printk("nfsd: trying to free free dentry in %s:%d\n"
197 " file %s/%s\n",
198 file, line,
199 dentry->d_parent->d_name.name, dentry->d_name.name);
200 } else {
201 fh_unlock(fhp);
202 fhp->fh_dverified = 0;
203 dput(dentry);
206 #endif
208 #endif /* __KERNEL__ */
210 #endif /* NFSD_FH_H */