2 * include/linux/nfsd/nfsfh.h
4 * This file describes the layout of the file handles as passed
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>
19 # include <linux/config.h>
20 # include <linux/types.h>
21 # include <linux/string.h>
22 # include <linux/fs.h>
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.
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 */
43 #define NFS_FH_PADDING (NFS_FHSIZE - sizeof(struct nfs_fhbase))
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
60 * Conversion macros for the filehandle fields.
62 extern inline __u32
kdev_t_to_u32(kdev_t dev
)
67 extern inline kdev_t
u32_to_kdev_t(__u32 udev
)
72 extern inline __u32
ino_t_to_u32(ino_t ino
)
77 extern inline ino_t
u32_to_ino_t(__u32 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 */
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 */
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 */
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
);
150 static __inline__
struct svc_fh
*
151 fh_init(struct svc_fh
*fhp
)
153 memset(fhp
, 0, sizeof(*fhp
));
157 #ifdef CONFIG_NFSD_V3
159 * Fill in the pre_op attr for the wcc data
162 fill_pre_wcc(struct svc_fh
*fhp
)
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;
177 * Fill in the post_op attr for the wcc data
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
;
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;
207 #endif /* CONFIG_NFSD_V3 */
211 * Lock a file handle/inode
214 fh_lock(struct svc_fh
*fhp
)
216 struct dentry
*dentry
= fhp
->fh_dentry
;
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");
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
);
232 inode
= dentry
->d_inode
;
234 #ifdef CONFIG_NFSD_V3
238 #endif /* CONFIG_NFSD_V3 */
242 * Unlock a file handle/inode
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
253 up(&fhp
->fh_dentry
->d_inode
->i_sem
);
255 struct dentry
*dentry
= fhp
->fh_dentry
;
256 struct inode
*inode
= dentry
->d_inode
;
260 #endif /* CONFIG_NFSD_V3 */
263 #endif /* __KERNEL__ */
266 #endif /* _LINUX_NFSD_FH_H */