Import 2.1.81
[davej-history.git] / include / linux / nfsd / nfsfh.h
blob3e341077639a67d79e7a9ba6e0ff184265000dc7
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 ino_t fb_ino; /* our inode number */
32 ino_t fb_dirino; /* dir inode number */
33 dev_t fb_dev; /* our device */
34 dev_t fb_xdev;
35 ino_t 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 * This is the internal representation of an NFS handle used in knfsd.
55 * pre_mtime/post_version will be used to support wcc_attr's in NFSv3.
57 typedef struct svc_fh {
58 struct knfs_fh fh_handle; /* FH data */
59 struct dentry * fh_dentry; /* validated dentry */
60 struct svc_export * fh_export; /* export pointer */
61 size_t fh_pre_size; /* size before operation */
62 time_t fh_pre_mtime; /* mtime before oper */
63 time_t fh_pre_ctime; /* ctime before oper */
64 unsigned long fh_post_version;/* inode version after oper */
65 unsigned char fh_locked; /* inode locked by us */
66 unsigned char fh_dverified; /* dentry has been checked */
67 } svc_fh;
70 * Shorthand for dprintk()'s
72 #define SVCFH_DENTRY(f) ((f)->fh_dentry)
73 #define SVCFH_INO(f) ((f)->fh_handle.fh_ino)
74 #define SVCFH_DEV(f) ((f)->fh_handle.fh_dev)
77 * Function prototypes
79 u32 fh_verify(struct svc_rqst *, struct svc_fh *, int, int);
80 void fh_compose(struct svc_fh *, struct svc_export *, struct dentry *);
81 void fh_update(struct svc_fh *);
82 void fh_put(struct svc_fh *);
83 void nfsd_fh_flush(dev_t);
84 void nfsd_fh_init(void);
85 void nfsd_fh_free(void);
87 static __inline__ struct svc_fh *
88 fh_copy(struct svc_fh *dst, struct svc_fh *src)
90 if (src->fh_dverified) {
91 struct dentry *dentry = src->fh_dentry;
92 printk("fh_copy: copying %s/%s, already verified!\n",
93 dentry->d_parent->d_name.name, dentry->d_name.name);
96 *dst = *src;
97 return dst;
100 static __inline__ struct svc_fh *
101 fh_init(struct svc_fh *fhp)
103 memset(fhp, 0, sizeof(*fhp));
104 return fhp;
108 * Lock a file handle/inode
110 static inline void
111 fh_lock(struct svc_fh *fhp)
113 struct inode *inode = fhp->fh_dentry->d_inode;
116 dfprintk(FILEOP, "nfsd: fh_lock(%x/%ld) locked = %d\n",
117 SVCFH_DEV(fhp), SVCFH_INO(fhp), fhp->fh_locked);
119 if (fhp->fh_locked) {
120 printk(KERN_WARNING "fh_lock: %s/%s already locked!\n",
121 fhp->fh_dentry->d_parent->d_name.name,
122 fhp->fh_dentry->d_name.name);
123 return;
125 down(&inode->i_sem);
126 if (!fhp->fh_pre_mtime)
127 fhp->fh_pre_mtime = inode->i_mtime;
128 fhp->fh_locked = 1;
132 * Unlock a file handle/inode
134 static inline void
135 fh_unlock(struct svc_fh *fhp)
137 if (fhp->fh_locked) {
138 struct inode *inode = fhp->fh_dentry->d_inode;
139 if (!fhp->fh_post_version)
140 fhp->fh_post_version = inode->i_version;
141 fhp->fh_locked = 0;
142 up(&inode->i_sem);
147 * Release an inode
149 #if 0
150 #define fh_put(fhp) __fh_put(fhp, __FILE__, __LINE__)
152 static inline void
153 __fh_put(struct svc_fh *fhp, char *file, int line)
155 struct dentry *dentry;
157 if (!fhp->fh_dverified)
158 return;
160 dentry = fhp->fh_dentry;
161 if (!dentry->d_count) {
162 printk("nfsd: trying to free free dentry in %s:%d\n"
163 " file %s/%s\n",
164 file, line,
165 dentry->d_parent->d_name.name, dentry->d_name.name);
166 } else {
167 fh_unlock(fhp);
168 fhp->fh_dverified = 0;
169 dput(dentry);
172 #endif
174 #endif /* __KERNEL__ */
176 #endif /* NFSD_FH_H */