[PATCH] ARM: Fix VFP to use do_div()
[linux-2.6/verdex.git] / include / linux / nfsd / nfsfh.h
blobbb842ea410334ec6a2163480c1591aad6e163110
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 old "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_old {
34 __u32 fb_dcookie; /* dentry cookie - always 0xfeebbaca */
35 __u32 fb_ino; /* our inode number */
36 __u32 fb_dirino; /* dir inode number, 0 for directories */
37 __u32 fb_dev; /* our device */
38 __u32 fb_xdev;
39 __u32 fb_xino;
40 __u32 fb_generation;
44 * This is the new flexible, extensible style NFSv2/v3 file handle.
45 * by Neil Brown <neilb@cse.unsw.edu.au> - March 2000
47 * The file handle is seens as a list of 4byte words.
48 * The first word contains a version number (1) and four descriptor bytes
49 * that tell how the remaining 3 variable length fields should be handled.
50 * These three bytes are auth_type, fsid_type and fileid_type.
52 * All 4byte values are in host-byte-order.
54 * The auth_type field specifies how the filehandle can be authenticated
55 * This might allow a file to be confirmed to be in a writable part of a
56 * filetree without checking the path from it upto the root.
57 * Current values:
58 * 0 - No authentication. fb_auth is 0 bytes long
59 * Possible future values:
60 * 1 - 4 bytes taken from MD5 hash of the remainer of the file handle
61 * prefixed by a secret and with the important export flags.
63 * The fsid_type identifies how the filesystem (or export point) is
64 * encoded.
65 * Current values:
66 * 0 - 4 byte device id (ms-2-bytes major, ls-2-bytes minor), 4byte inode number
67 * NOTE: we cannot use the kdev_t device id value, because kdev_t.h
68 * says we mustn't. We must break it up and reassemble.
69 * 1 - 4 byte user specified identifier
70 * 2 - 4 byte major, 4 byte minor, 4 byte inode number - DEPRECATED
71 * 3 - 4 byte device id, encoded for user-space, 4 byte inode number
73 * The fileid_type identified how the file within the filesystem is encoded.
74 * This is (will be) passed to, and set by, the underlying filesystem if it supports
75 * filehandle operations. The filesystem must not use the value '0' or '0xff' and may
76 * only use the values 1 and 2 as defined below:
77 * Current values:
78 * 0 - The root, or export point, of the filesystem. fb_fileid is 0 bytes.
79 * 1 - 32bit inode number, 32 bit generation number.
80 * 2 - 32bit inode number, 32 bit generation number, 32 bit parent directory inode number.
83 struct nfs_fhbase_new {
84 __u8 fb_version; /* == 1, even => nfs_fhbase_old */
85 __u8 fb_auth_type;
86 __u8 fb_fsid_type;
87 __u8 fb_fileid_type;
88 __u32 fb_auth[1];
89 /* __u32 fb_fsid[0]; floating */
90 /* __u32 fb_fileid[0]; floating */
93 struct knfsd_fh {
94 unsigned int fh_size; /* significant for NFSv3.
95 * Points to the current size while building
96 * a new file handle
98 union {
99 struct nfs_fhbase_old fh_old;
100 __u32 fh_pad[NFS4_FHSIZE/4];
101 struct nfs_fhbase_new fh_new;
102 } fh_base;
105 #define ofh_dcookie fh_base.fh_old.fb_dcookie
106 #define ofh_ino fh_base.fh_old.fb_ino
107 #define ofh_dirino fh_base.fh_old.fb_dirino
108 #define ofh_dev fh_base.fh_old.fb_dev
109 #define ofh_xdev fh_base.fh_old.fb_xdev
110 #define ofh_xino fh_base.fh_old.fb_xino
111 #define ofh_generation fh_base.fh_old.fb_generation
113 #define fh_version fh_base.fh_new.fb_version
114 #define fh_fsid_type fh_base.fh_new.fb_fsid_type
115 #define fh_auth_type fh_base.fh_new.fb_auth_type
116 #define fh_fileid_type fh_base.fh_new.fb_fileid_type
117 #define fh_auth fh_base.fh_new.fb_auth
118 #define fh_fsid fh_base.fh_new.fb_auth
120 #ifdef __KERNEL__
122 static inline __u32 ino_t_to_u32(ino_t ino)
124 return (__u32) ino;
127 static inline ino_t u32_to_ino_t(__u32 uino)
129 return (ino_t) uino;
133 * This is the internal representation of an NFS handle used in knfsd.
134 * pre_mtime/post_version will be used to support wcc_attr's in NFSv3.
136 typedef struct svc_fh {
137 struct knfsd_fh fh_handle; /* FH data */
138 struct dentry * fh_dentry; /* validated dentry */
139 struct svc_export * fh_export; /* export pointer */
140 int fh_maxsize; /* max size for fh_handle */
142 unsigned char fh_locked; /* inode locked by us */
144 #ifdef CONFIG_NFSD_V3
145 unsigned char fh_post_saved; /* post-op attrs saved */
146 unsigned char fh_pre_saved; /* pre-op attrs saved */
148 /* Pre-op attributes saved during fh_lock */
149 __u64 fh_pre_size; /* size before operation */
150 struct timespec fh_pre_mtime; /* mtime before oper */
151 struct timespec fh_pre_ctime; /* ctime before oper */
153 /* Post-op attributes saved in fh_unlock */
154 umode_t fh_post_mode; /* i_mode */
155 nlink_t fh_post_nlink; /* i_nlink */
156 uid_t fh_post_uid; /* i_uid */
157 gid_t fh_post_gid; /* i_gid */
158 __u64 fh_post_size; /* i_size */
159 unsigned long fh_post_blocks; /* i_blocks */
160 unsigned long fh_post_blksize;/* i_blksize */
161 __u32 fh_post_rdev[2];/* i_rdev */
162 struct timespec fh_post_atime; /* i_atime */
163 struct timespec fh_post_mtime; /* i_mtime */
164 struct timespec fh_post_ctime; /* i_ctime */
165 #endif /* CONFIG_NFSD_V3 */
167 } svc_fh;
169 static inline void mk_fsid_v0(u32 *fsidv, dev_t dev, ino_t ino)
171 fsidv[0] = htonl((MAJOR(dev)<<16) |
172 MINOR(dev));
173 fsidv[1] = ino_t_to_u32(ino);
176 static inline void mk_fsid_v1(u32 *fsidv, u32 fsid)
178 fsidv[0] = fsid;
181 static inline void mk_fsid_v2(u32 *fsidv, dev_t dev, ino_t ino)
183 fsidv[0] = htonl(MAJOR(dev));
184 fsidv[1] = htonl(MINOR(dev));
185 fsidv[2] = ino_t_to_u32(ino);
188 static inline void mk_fsid_v3(u32 *fsidv, dev_t dev, ino_t ino)
190 fsidv[0] = new_encode_dev(dev);
191 fsidv[1] = ino_t_to_u32(ino);
194 static inline int key_len(int type)
196 switch(type) {
197 case 0: return 8;
198 case 1: return 4;
199 case 2: return 12;
200 case 3: return 8;
201 default: return 0;
206 * Shorthand for dprintk()'s
208 extern char * SVCFH_fmt(struct svc_fh *fhp);
211 * Function prototypes
213 u32 fh_verify(struct svc_rqst *, struct svc_fh *, int, int);
214 int fh_compose(struct svc_fh *, struct svc_export *, struct dentry *, struct svc_fh *);
215 int fh_update(struct svc_fh *);
216 void fh_put(struct svc_fh *);
218 static __inline__ struct svc_fh *
219 fh_copy(struct svc_fh *dst, struct svc_fh *src)
221 if (src->fh_dentry || src->fh_locked) {
222 struct dentry *dentry = src->fh_dentry;
223 printk(KERN_ERR "fh_copy: copying %s/%s, already verified!\n",
224 dentry->d_parent->d_name.name, dentry->d_name.name);
227 *dst = *src;
228 return dst;
231 static __inline__ struct svc_fh *
232 fh_init(struct svc_fh *fhp, int maxsize)
234 memset(fhp, 0, sizeof(*fhp));
235 fhp->fh_maxsize = maxsize;
236 return fhp;
239 #ifdef CONFIG_NFSD_V3
241 * Fill in the pre_op attr for the wcc data
243 static inline void
244 fill_pre_wcc(struct svc_fh *fhp)
246 struct inode *inode;
248 inode = fhp->fh_dentry->d_inode;
249 if (!fhp->fh_pre_saved) {
250 fhp->fh_pre_mtime = inode->i_mtime;
251 fhp->fh_pre_ctime = inode->i_ctime;
252 fhp->fh_pre_size = inode->i_size;
253 fhp->fh_pre_saved = 1;
258 * Fill in the post_op attr for the wcc data
260 static inline void
261 fill_post_wcc(struct svc_fh *fhp)
263 struct inode *inode = fhp->fh_dentry->d_inode;
265 if (fhp->fh_post_saved)
266 printk("nfsd: inode locked twice during operation.\n");
268 fhp->fh_post_mode = inode->i_mode;
269 fhp->fh_post_nlink = inode->i_nlink;
270 fhp->fh_post_uid = inode->i_uid;
271 fhp->fh_post_gid = inode->i_gid;
272 fhp->fh_post_size = inode->i_size;
273 if (inode->i_blksize) {
274 fhp->fh_post_blksize = inode->i_blksize;
275 fhp->fh_post_blocks = inode->i_blocks;
276 } else {
277 fhp->fh_post_blksize = BLOCK_SIZE;
278 /* how much do we care for accuracy with MinixFS? */
279 fhp->fh_post_blocks = (inode->i_size+511) >> 9;
281 fhp->fh_post_rdev[0] = htonl((u32)imajor(inode));
282 fhp->fh_post_rdev[1] = htonl((u32)iminor(inode));
283 fhp->fh_post_atime = inode->i_atime;
284 fhp->fh_post_mtime = inode->i_mtime;
285 fhp->fh_post_ctime = inode->i_ctime;
286 fhp->fh_post_saved = 1;
288 #else
289 #define fill_pre_wcc(ignored)
290 #define fill_post_wcc(notused)
291 #endif /* CONFIG_NFSD_V3 */
295 * Lock a file handle/inode
296 * NOTE: both fh_lock and fh_unlock are done "by hand" in
297 * vfs.c:nfsd_rename as it needs to grab 2 i_sem's at once
298 * so, any changes here should be reflected there.
300 static inline void
301 fh_lock(struct svc_fh *fhp)
303 struct dentry *dentry = fhp->fh_dentry;
304 struct inode *inode;
306 dfprintk(FILEOP, "nfsd: fh_lock(%s) locked = %d\n",
307 SVCFH_fmt(fhp), fhp->fh_locked);
309 if (!fhp->fh_dentry) {
310 printk(KERN_ERR "fh_lock: fh not verified!\n");
311 return;
313 if (fhp->fh_locked) {
314 printk(KERN_WARNING "fh_lock: %s/%s already locked!\n",
315 dentry->d_parent->d_name.name, dentry->d_name.name);
316 return;
319 inode = dentry->d_inode;
320 down(&inode->i_sem);
321 fill_pre_wcc(fhp);
322 fhp->fh_locked = 1;
326 * Unlock a file handle/inode
328 static inline void
329 fh_unlock(struct svc_fh *fhp)
331 if (!fhp->fh_dentry)
332 printk(KERN_ERR "fh_unlock: fh not verified!\n");
334 if (fhp->fh_locked) {
335 fill_post_wcc(fhp);
336 up(&fhp->fh_dentry->d_inode->i_sem);
337 fhp->fh_locked = 0;
340 #endif /* __KERNEL__ */
343 #endif /* _LINUX_NFSD_FH_H */