Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * nfsproc2.c Process version 2 NFS requests. | |
3 | * linux/fs/nfsd/nfs2proc.c | |
4 | * | |
5 | * Process version 2 NFS requests. | |
6 | * | |
7 | * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de> | |
8 | */ | |
9 | ||
10 | #include <linux/linkage.h> | |
11 | #include <linux/time.h> | |
12 | #include <linux/errno.h> | |
13 | #include <linux/fs.h> | |
14 | #include <linux/stat.h> | |
15 | #include <linux/fcntl.h> | |
16 | #include <linux/net.h> | |
17 | #include <linux/in.h> | |
18 | #include <linux/namei.h> | |
19 | #include <linux/unistd.h> | |
20 | #include <linux/slab.h> | |
21 | ||
ad06e4bd | 22 | #include <linux/sunrpc/clnt.h> |
1da177e4 LT |
23 | #include <linux/sunrpc/svc.h> |
24 | #include <linux/nfsd/nfsd.h> | |
25 | #include <linux/nfsd/cache.h> | |
26 | #include <linux/nfsd/xdr.h> | |
0a3adade | 27 | #include "vfs.h" |
1da177e4 LT |
28 | |
29 | typedef struct svc_rqst svc_rqst; | |
30 | typedef struct svc_buf svc_buf; | |
31 | ||
32 | #define NFSDDBG_FACILITY NFSDDBG_PROC | |
33 | ||
34 | ||
7111c66e | 35 | static __be32 |
1da177e4 LT |
36 | nfsd_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) |
37 | { | |
38 | return nfs_ok; | |
39 | } | |
40 | ||
c4d987ba AV |
41 | static __be32 |
42 | nfsd_return_attrs(__be32 err, struct nfsd_attrstat *resp) | |
846f2fcd DS |
43 | { |
44 | if (err) return err; | |
54775491 | 45 | return nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt, |
846f2fcd DS |
46 | resp->fh.fh_dentry, |
47 | &resp->stat)); | |
48 | } | |
c4d987ba AV |
49 | static __be32 |
50 | nfsd_return_dirop(__be32 err, struct nfsd_diropres *resp) | |
846f2fcd DS |
51 | { |
52 | if (err) return err; | |
54775491 | 53 | return nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt, |
846f2fcd DS |
54 | resp->fh.fh_dentry, |
55 | &resp->stat)); | |
56 | } | |
1da177e4 LT |
57 | /* |
58 | * Get a file's attributes | |
59 | * N.B. After this call resp->fh needs an fh_put | |
60 | */ | |
7111c66e | 61 | static __be32 |
1da177e4 LT |
62 | nfsd_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle *argp, |
63 | struct nfsd_attrstat *resp) | |
64 | { | |
c4d987ba | 65 | __be32 nfserr; |
1da177e4 LT |
66 | dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh)); |
67 | ||
68 | fh_copy(&resp->fh, &argp->fh); | |
04716e66 BF |
69 | nfserr = fh_verify(rqstp, &resp->fh, 0, |
70 | NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT); | |
846f2fcd | 71 | return nfsd_return_attrs(nfserr, resp); |
1da177e4 LT |
72 | } |
73 | ||
74 | /* | |
75 | * Set a file's attributes | |
76 | * N.B. After this call resp->fh needs an fh_put | |
77 | */ | |
7111c66e | 78 | static __be32 |
1da177e4 LT |
79 | nfsd_proc_setattr(struct svc_rqst *rqstp, struct nfsd_sattrargs *argp, |
80 | struct nfsd_attrstat *resp) | |
81 | { | |
c4d987ba | 82 | __be32 nfserr; |
1da177e4 LT |
83 | dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n", |
84 | SVCFH_fmt(&argp->fh), | |
85 | argp->attrs.ia_valid, (long) argp->attrs.ia_size); | |
86 | ||
87 | fh_copy(&resp->fh, &argp->fh); | |
846f2fcd DS |
88 | nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,0, (time_t)0); |
89 | return nfsd_return_attrs(nfserr, resp); | |
1da177e4 LT |
90 | } |
91 | ||
92 | /* | |
93 | * Look up a path name component | |
94 | * Note: the dentry in the resp->fh may be negative if the file | |
95 | * doesn't exist yet. | |
96 | * N.B. After this call resp->fh needs an fh_put | |
97 | */ | |
7111c66e | 98 | static __be32 |
1da177e4 LT |
99 | nfsd_proc_lookup(struct svc_rqst *rqstp, struct nfsd_diropargs *argp, |
100 | struct nfsd_diropres *resp) | |
101 | { | |
c4d987ba | 102 | __be32 nfserr; |
1da177e4 LT |
103 | |
104 | dprintk("nfsd: LOOKUP %s %.*s\n", | |
105 | SVCFH_fmt(&argp->fh), argp->len, argp->name); | |
106 | ||
107 | fh_init(&resp->fh, NFS_FHSIZE); | |
108 | nfserr = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len, | |
109 | &resp->fh); | |
110 | ||
111 | fh_put(&argp->fh); | |
846f2fcd | 112 | return nfsd_return_dirop(nfserr, resp); |
1da177e4 LT |
113 | } |
114 | ||
115 | /* | |
116 | * Read a symlink. | |
117 | */ | |
7111c66e | 118 | static __be32 |
1da177e4 LT |
119 | nfsd_proc_readlink(struct svc_rqst *rqstp, struct nfsd_readlinkargs *argp, |
120 | struct nfsd_readlinkres *resp) | |
121 | { | |
c4d987ba | 122 | __be32 nfserr; |
1da177e4 LT |
123 | |
124 | dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh)); | |
125 | ||
126 | /* Read the symlink. */ | |
127 | resp->len = NFS_MAXPATHLEN; | |
128 | nfserr = nfsd_readlink(rqstp, &argp->fh, argp->buffer, &resp->len); | |
129 | ||
130 | fh_put(&argp->fh); | |
131 | return nfserr; | |
132 | } | |
133 | ||
134 | /* | |
135 | * Read a portion of a file. | |
136 | * N.B. After this call resp->fh needs an fh_put | |
137 | */ | |
7111c66e | 138 | static __be32 |
1da177e4 LT |
139 | nfsd_proc_read(struct svc_rqst *rqstp, struct nfsd_readargs *argp, |
140 | struct nfsd_readres *resp) | |
141 | { | |
c4d987ba | 142 | __be32 nfserr; |
1da177e4 LT |
143 | |
144 | dprintk("nfsd: READ %s %d bytes at %d\n", | |
145 | SVCFH_fmt(&argp->fh), | |
146 | argp->count, argp->offset); | |
147 | ||
148 | /* Obtain buffer pointer for payload. 19 is 1 word for | |
149 | * status, 17 words for fattr, and 1 word for the byte count. | |
150 | */ | |
151 | ||
7adae489 | 152 | if (NFSSVC_MAXBLKSIZE_V2 < argp->count) { |
ad06e4bd | 153 | char buf[RPC_MAX_ADDRBUFLEN]; |
1da177e4 | 154 | printk(KERN_NOTICE |
ad06e4bd CL |
155 | "oversized read request from %s (%d bytes)\n", |
156 | svc_print_addr(rqstp, buf, sizeof(buf)), | |
1da177e4 | 157 | argp->count); |
7adae489 | 158 | argp->count = NFSSVC_MAXBLKSIZE_V2; |
1da177e4 | 159 | } |
cd123012 | 160 | svc_reserve_auth(rqstp, (19<<2) + argp->count + 4); |
1da177e4 LT |
161 | |
162 | resp->count = argp->count; | |
163 | nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh), NULL, | |
164 | argp->offset, | |
3cc03b16 | 165 | rqstp->rq_vec, argp->vlen, |
1da177e4 LT |
166 | &resp->count); |
167 | ||
846f2fcd | 168 | if (nfserr) return nfserr; |
54775491 | 169 | return nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt, |
846f2fcd DS |
170 | resp->fh.fh_dentry, |
171 | &resp->stat)); | |
1da177e4 LT |
172 | } |
173 | ||
174 | /* | |
175 | * Write data to a file | |
176 | * N.B. After this call resp->fh needs an fh_put | |
177 | */ | |
7111c66e | 178 | static __be32 |
1da177e4 LT |
179 | nfsd_proc_write(struct svc_rqst *rqstp, struct nfsd_writeargs *argp, |
180 | struct nfsd_attrstat *resp) | |
181 | { | |
c4d987ba | 182 | __be32 nfserr; |
1da177e4 | 183 | int stable = 1; |
31dec253 | 184 | unsigned long cnt = argp->len; |
1da177e4 LT |
185 | |
186 | dprintk("nfsd: WRITE %s %d bytes at %d\n", | |
187 | SVCFH_fmt(&argp->fh), | |
188 | argp->len, argp->offset); | |
189 | ||
190 | nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), NULL, | |
191 | argp->offset, | |
3cc03b16 | 192 | rqstp->rq_vec, argp->vlen, |
31dec253 | 193 | &cnt, |
1da177e4 | 194 | &stable); |
846f2fcd | 195 | return nfsd_return_attrs(nfserr, resp); |
1da177e4 LT |
196 | } |
197 | ||
198 | /* | |
199 | * CREATE processing is complicated. The keyword here is `overloaded.' | |
200 | * The parent directory is kept locked between the check for existence | |
201 | * and the actual create() call in compliance with VFS protocols. | |
202 | * N.B. After this call _both_ argp->fh and resp->fh need an fh_put | |
203 | */ | |
7111c66e | 204 | static __be32 |
1da177e4 LT |
205 | nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp, |
206 | struct nfsd_diropres *resp) | |
207 | { | |
208 | svc_fh *dirfhp = &argp->fh; | |
209 | svc_fh *newfhp = &resp->fh; | |
210 | struct iattr *attr = &argp->attrs; | |
211 | struct inode *inode; | |
212 | struct dentry *dchild; | |
c4d987ba AV |
213 | int type, mode; |
214 | __be32 nfserr; | |
1da177e4 LT |
215 | dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size); |
216 | ||
217 | dprintk("nfsd: CREATE %s %.*s\n", | |
218 | SVCFH_fmt(dirfhp), argp->len, argp->name); | |
219 | ||
220 | /* First verify the parent file handle */ | |
8837abca | 221 | nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC); |
1da177e4 LT |
222 | if (nfserr) |
223 | goto done; /* must fh_put dirfhp even on error */ | |
224 | ||
8837abca | 225 | /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */ |
1da177e4 LT |
226 | |
227 | nfserr = nfserr_acces; | |
228 | if (!argp->len) | |
229 | goto done; | |
230 | nfserr = nfserr_exist; | |
231 | if (isdotent(argp->name, argp->len)) | |
232 | goto done; | |
7ed94296 | 233 | fh_lock_nested(dirfhp, I_MUTEX_PARENT); |
1da177e4 LT |
234 | dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len); |
235 | if (IS_ERR(dchild)) { | |
236 | nfserr = nfserrno(PTR_ERR(dchild)); | |
237 | goto out_unlock; | |
238 | } | |
239 | fh_init(newfhp, NFS_FHSIZE); | |
240 | nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp); | |
241 | if (!nfserr && !dchild->d_inode) | |
242 | nfserr = nfserr_noent; | |
243 | dput(dchild); | |
244 | if (nfserr) { | |
245 | if (nfserr != nfserr_noent) | |
246 | goto out_unlock; | |
247 | /* | |
248 | * If the new file handle wasn't verified, we can't tell | |
249 | * whether the file exists or not. Time to bail ... | |
250 | */ | |
251 | nfserr = nfserr_acces; | |
252 | if (!newfhp->fh_dentry) { | |
253 | printk(KERN_WARNING | |
254 | "nfsd_proc_create: file handle not verified\n"); | |
255 | goto out_unlock; | |
256 | } | |
257 | } | |
258 | ||
259 | inode = newfhp->fh_dentry->d_inode; | |
260 | ||
261 | /* Unfudge the mode bits */ | |
262 | if (attr->ia_valid & ATTR_MODE) { | |
263 | type = attr->ia_mode & S_IFMT; | |
264 | mode = attr->ia_mode & ~S_IFMT; | |
265 | if (!type) { | |
266 | /* no type, so if target exists, assume same as that, | |
267 | * else assume a file */ | |
268 | if (inode) { | |
269 | type = inode->i_mode & S_IFMT; | |
270 | switch(type) { | |
271 | case S_IFCHR: | |
272 | case S_IFBLK: | |
273 | /* reserve rdev for later checking */ | |
274 | rdev = inode->i_rdev; | |
275 | attr->ia_valid |= ATTR_SIZE; | |
276 | ||
277 | /* FALLTHROUGH */ | |
278 | case S_IFIFO: | |
279 | /* this is probably a permission check.. | |
280 | * at least IRIX implements perm checking on | |
281 | * echo thing > device-special-file-or-pipe | |
282 | * by doing a CREATE with type==0 | |
283 | */ | |
0ec757df BF |
284 | nfserr = nfsd_permission(rqstp, |
285 | newfhp->fh_export, | |
1da177e4 | 286 | newfhp->fh_dentry, |
8837abca | 287 | NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS); |
1da177e4 LT |
288 | if (nfserr && nfserr != nfserr_rofs) |
289 | goto out_unlock; | |
290 | } | |
291 | } else | |
292 | type = S_IFREG; | |
293 | } | |
294 | } else if (inode) { | |
295 | type = inode->i_mode & S_IFMT; | |
296 | mode = inode->i_mode & ~S_IFMT; | |
297 | } else { | |
298 | type = S_IFREG; | |
299 | mode = 0; /* ??? */ | |
300 | } | |
301 | ||
302 | attr->ia_valid |= ATTR_MODE; | |
303 | attr->ia_mode = mode; | |
304 | ||
305 | /* Special treatment for non-regular files according to the | |
306 | * gospel of sun micro | |
307 | */ | |
308 | if (type != S_IFREG) { | |
309 | int is_borc = 0; | |
310 | if (type != S_IFBLK && type != S_IFCHR) { | |
311 | rdev = 0; | |
312 | } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) { | |
313 | /* If you think you've seen the worst, grok this. */ | |
314 | type = S_IFIFO; | |
315 | } else { | |
316 | /* Okay, char or block special */ | |
317 | is_borc = 1; | |
318 | if (!rdev) | |
319 | rdev = wanted; | |
320 | } | |
321 | ||
322 | /* we've used the SIZE information, so discard it */ | |
323 | attr->ia_valid &= ~ATTR_SIZE; | |
324 | ||
325 | /* Make sure the type and device matches */ | |
326 | nfserr = nfserr_exist; | |
327 | if (inode && type != (inode->i_mode & S_IFMT)) | |
328 | goto out_unlock; | |
329 | } | |
330 | ||
331 | nfserr = 0; | |
332 | if (!inode) { | |
333 | /* File doesn't exist. Create it and set attrs */ | |
334 | nfserr = nfsd_create(rqstp, dirfhp, argp->name, argp->len, | |
335 | attr, type, rdev, newfhp); | |
336 | } else if (type == S_IFREG) { | |
337 | dprintk("nfsd: existing %s, valid=%x, size=%ld\n", | |
338 | argp->name, attr->ia_valid, (long) attr->ia_size); | |
339 | /* File already exists. We ignore all attributes except | |
340 | * size, so that creat() behaves exactly like | |
341 | * open(..., O_CREAT|O_TRUNC|O_WRONLY). | |
342 | */ | |
343 | attr->ia_valid &= ATTR_SIZE; | |
344 | if (attr->ia_valid) | |
345 | nfserr = nfsd_setattr(rqstp, newfhp, attr, 0, (time_t)0); | |
346 | } | |
347 | ||
348 | out_unlock: | |
349 | /* We don't really need to unlock, as fh_put does it. */ | |
350 | fh_unlock(dirfhp); | |
351 | ||
352 | done: | |
353 | fh_put(dirfhp); | |
846f2fcd | 354 | return nfsd_return_dirop(nfserr, resp); |
1da177e4 LT |
355 | } |
356 | ||
7111c66e | 357 | static __be32 |
1da177e4 LT |
358 | nfsd_proc_remove(struct svc_rqst *rqstp, struct nfsd_diropargs *argp, |
359 | void *resp) | |
360 | { | |
c4d987ba | 361 | __be32 nfserr; |
1da177e4 LT |
362 | |
363 | dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh), | |
364 | argp->len, argp->name); | |
365 | ||
366 | /* Unlink. -SIFDIR means file must not be a directory */ | |
367 | nfserr = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR, argp->name, argp->len); | |
368 | fh_put(&argp->fh); | |
369 | return nfserr; | |
370 | } | |
371 | ||
7111c66e | 372 | static __be32 |
1da177e4 LT |
373 | nfsd_proc_rename(struct svc_rqst *rqstp, struct nfsd_renameargs *argp, |
374 | void *resp) | |
375 | { | |
c4d987ba | 376 | __be32 nfserr; |
1da177e4 LT |
377 | |
378 | dprintk("nfsd: RENAME %s %.*s -> \n", | |
379 | SVCFH_fmt(&argp->ffh), argp->flen, argp->fname); | |
380 | dprintk("nfsd: -> %s %.*s\n", | |
381 | SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname); | |
382 | ||
383 | nfserr = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen, | |
384 | &argp->tfh, argp->tname, argp->tlen); | |
385 | fh_put(&argp->ffh); | |
386 | fh_put(&argp->tfh); | |
387 | return nfserr; | |
388 | } | |
389 | ||
7111c66e | 390 | static __be32 |
1da177e4 LT |
391 | nfsd_proc_link(struct svc_rqst *rqstp, struct nfsd_linkargs *argp, |
392 | void *resp) | |
393 | { | |
c4d987ba | 394 | __be32 nfserr; |
1da177e4 LT |
395 | |
396 | dprintk("nfsd: LINK %s ->\n", | |
397 | SVCFH_fmt(&argp->ffh)); | |
398 | dprintk("nfsd: %s %.*s\n", | |
399 | SVCFH_fmt(&argp->tfh), | |
400 | argp->tlen, | |
401 | argp->tname); | |
402 | ||
403 | nfserr = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen, | |
404 | &argp->ffh); | |
405 | fh_put(&argp->ffh); | |
406 | fh_put(&argp->tfh); | |
407 | return nfserr; | |
408 | } | |
409 | ||
7111c66e | 410 | static __be32 |
1da177e4 LT |
411 | nfsd_proc_symlink(struct svc_rqst *rqstp, struct nfsd_symlinkargs *argp, |
412 | void *resp) | |
413 | { | |
414 | struct svc_fh newfh; | |
c4d987ba | 415 | __be32 nfserr; |
1da177e4 LT |
416 | |
417 | dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n", | |
418 | SVCFH_fmt(&argp->ffh), argp->flen, argp->fname, | |
419 | argp->tlen, argp->tname); | |
420 | ||
421 | fh_init(&newfh, NFS_FHSIZE); | |
422 | /* | |
423 | * Create the link, look up new file and set attrs. | |
424 | */ | |
425 | nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen, | |
426 | argp->tname, argp->tlen, | |
427 | &newfh, &argp->attrs); | |
428 | ||
429 | ||
430 | fh_put(&argp->ffh); | |
431 | fh_put(&newfh); | |
432 | return nfserr; | |
433 | } | |
434 | ||
435 | /* | |
436 | * Make directory. This operation is not idempotent. | |
437 | * N.B. After this call resp->fh needs an fh_put | |
438 | */ | |
7111c66e | 439 | static __be32 |
1da177e4 LT |
440 | nfsd_proc_mkdir(struct svc_rqst *rqstp, struct nfsd_createargs *argp, |
441 | struct nfsd_diropres *resp) | |
442 | { | |
c4d987ba | 443 | __be32 nfserr; |
1da177e4 LT |
444 | |
445 | dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name); | |
446 | ||
447 | if (resp->fh.fh_dentry) { | |
448 | printk(KERN_WARNING | |
449 | "nfsd_proc_mkdir: response already verified??\n"); | |
450 | } | |
451 | ||
452 | argp->attrs.ia_valid &= ~ATTR_SIZE; | |
453 | fh_init(&resp->fh, NFS_FHSIZE); | |
454 | nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len, | |
455 | &argp->attrs, S_IFDIR, 0, &resp->fh); | |
456 | fh_put(&argp->fh); | |
846f2fcd | 457 | return nfsd_return_dirop(nfserr, resp); |
1da177e4 LT |
458 | } |
459 | ||
460 | /* | |
461 | * Remove a directory | |
462 | */ | |
7111c66e | 463 | static __be32 |
1da177e4 LT |
464 | nfsd_proc_rmdir(struct svc_rqst *rqstp, struct nfsd_diropargs *argp, |
465 | void *resp) | |
466 | { | |
c4d987ba | 467 | __be32 nfserr; |
1da177e4 LT |
468 | |
469 | dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name); | |
470 | ||
471 | nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len); | |
472 | fh_put(&argp->fh); | |
473 | return nfserr; | |
474 | } | |
475 | ||
476 | /* | |
477 | * Read a portion of a directory. | |
478 | */ | |
7111c66e | 479 | static __be32 |
1da177e4 LT |
480 | nfsd_proc_readdir(struct svc_rqst *rqstp, struct nfsd_readdirargs *argp, |
481 | struct nfsd_readdirres *resp) | |
482 | { | |
c4d987ba AV |
483 | int count; |
484 | __be32 nfserr; | |
1da177e4 LT |
485 | loff_t offset; |
486 | ||
487 | dprintk("nfsd: READDIR %s %d bytes at %d\n", | |
488 | SVCFH_fmt(&argp->fh), | |
489 | argp->count, argp->cookie); | |
490 | ||
491 | /* Shrink to the client read size */ | |
492 | count = (argp->count >> 2) - 2; | |
493 | ||
494 | /* Make sure we've room for the NULL ptr & eof flag */ | |
495 | count -= 2; | |
496 | if (count < 0) | |
497 | count = 0; | |
498 | ||
499 | resp->buffer = argp->buffer; | |
500 | resp->offset = NULL; | |
501 | resp->buflen = count; | |
502 | resp->common.err = nfs_ok; | |
503 | /* Read directory and encode entries on the fly */ | |
504 | offset = argp->cookie; | |
505 | nfserr = nfsd_readdir(rqstp, &argp->fh, &offset, | |
506 | &resp->common, nfssvc_encode_entry); | |
507 | ||
508 | resp->count = resp->buffer - argp->buffer; | |
509 | if (resp->offset) | |
510 | *resp->offset = htonl(offset); | |
511 | ||
512 | fh_put(&argp->fh); | |
513 | return nfserr; | |
514 | } | |
515 | ||
516 | /* | |
517 | * Get file system info | |
518 | */ | |
7111c66e | 519 | static __be32 |
1da177e4 LT |
520 | nfsd_proc_statfs(struct svc_rqst * rqstp, struct nfsd_fhandle *argp, |
521 | struct nfsd_statfsres *resp) | |
522 | { | |
c4d987ba | 523 | __be32 nfserr; |
1da177e4 LT |
524 | |
525 | dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh)); | |
526 | ||
04716e66 BF |
527 | nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats, |
528 | NFSD_MAY_BYPASS_GSS_ON_ROOT); | |
1da177e4 LT |
529 | fh_put(&argp->fh); |
530 | return nfserr; | |
531 | } | |
532 | ||
533 | /* | |
534 | * NFSv2 Server procedures. | |
535 | * Only the results of non-idempotent operations are cached. | |
536 | */ | |
1da177e4 LT |
537 | struct nfsd_void { int dummy; }; |
538 | ||
1da177e4 LT |
539 | #define ST 1 /* status */ |
540 | #define FH 8 /* filehandle */ | |
541 | #define AT 18 /* attributes */ | |
542 | ||
543 | static struct svc_procedure nfsd_procedures2[18] = { | |
b9081d90 YZ |
544 | [NFSPROC_NULL] = { |
545 | .pc_func = (svc_procfunc) nfsd_proc_null, | |
546 | .pc_decode = (kxdrproc_t) nfssvc_decode_void, | |
547 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, | |
548 | .pc_argsize = sizeof(struct nfsd_void), | |
549 | .pc_ressize = sizeof(struct nfsd_void), | |
550 | .pc_cachetype = RC_NOCACHE, | |
551 | .pc_xdrressize = ST, | |
552 | }, | |
553 | [NFSPROC_GETATTR] = { | |
554 | .pc_func = (svc_procfunc) nfsd_proc_getattr, | |
555 | .pc_decode = (kxdrproc_t) nfssvc_decode_fhandle, | |
556 | .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat, | |
557 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, | |
558 | .pc_argsize = sizeof(struct nfsd_fhandle), | |
559 | .pc_ressize = sizeof(struct nfsd_attrstat), | |
560 | .pc_cachetype = RC_NOCACHE, | |
561 | .pc_xdrressize = ST+AT, | |
562 | }, | |
563 | [NFSPROC_SETATTR] = { | |
564 | .pc_func = (svc_procfunc) nfsd_proc_setattr, | |
565 | .pc_decode = (kxdrproc_t) nfssvc_decode_sattrargs, | |
566 | .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat, | |
567 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, | |
568 | .pc_argsize = sizeof(struct nfsd_sattrargs), | |
569 | .pc_ressize = sizeof(struct nfsd_attrstat), | |
570 | .pc_cachetype = RC_REPLBUFF, | |
571 | .pc_xdrressize = ST+AT, | |
572 | }, | |
573 | [NFSPROC_ROOT] = { | |
574 | .pc_decode = (kxdrproc_t) nfssvc_decode_void, | |
575 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, | |
576 | .pc_argsize = sizeof(struct nfsd_void), | |
577 | .pc_ressize = sizeof(struct nfsd_void), | |
578 | .pc_cachetype = RC_NOCACHE, | |
579 | .pc_xdrressize = ST, | |
580 | }, | |
581 | [NFSPROC_LOOKUP] = { | |
582 | .pc_func = (svc_procfunc) nfsd_proc_lookup, | |
583 | .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs, | |
584 | .pc_encode = (kxdrproc_t) nfssvc_encode_diropres, | |
585 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, | |
586 | .pc_argsize = sizeof(struct nfsd_diropargs), | |
587 | .pc_ressize = sizeof(struct nfsd_diropres), | |
588 | .pc_cachetype = RC_NOCACHE, | |
589 | .pc_xdrressize = ST+FH+AT, | |
590 | }, | |
591 | [NFSPROC_READLINK] = { | |
592 | .pc_func = (svc_procfunc) nfsd_proc_readlink, | |
593 | .pc_decode = (kxdrproc_t) nfssvc_decode_readlinkargs, | |
594 | .pc_encode = (kxdrproc_t) nfssvc_encode_readlinkres, | |
595 | .pc_argsize = sizeof(struct nfsd_readlinkargs), | |
596 | .pc_ressize = sizeof(struct nfsd_readlinkres), | |
597 | .pc_cachetype = RC_NOCACHE, | |
598 | .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4, | |
599 | }, | |
600 | [NFSPROC_READ] = { | |
601 | .pc_func = (svc_procfunc) nfsd_proc_read, | |
602 | .pc_decode = (kxdrproc_t) nfssvc_decode_readargs, | |
603 | .pc_encode = (kxdrproc_t) nfssvc_encode_readres, | |
604 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, | |
605 | .pc_argsize = sizeof(struct nfsd_readargs), | |
606 | .pc_ressize = sizeof(struct nfsd_readres), | |
607 | .pc_cachetype = RC_NOCACHE, | |
608 | .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4, | |
609 | }, | |
610 | [NFSPROC_WRITECACHE] = { | |
611 | .pc_decode = (kxdrproc_t) nfssvc_decode_void, | |
612 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, | |
613 | .pc_argsize = sizeof(struct nfsd_void), | |
614 | .pc_ressize = sizeof(struct nfsd_void), | |
615 | .pc_cachetype = RC_NOCACHE, | |
616 | .pc_xdrressize = ST, | |
617 | }, | |
618 | [NFSPROC_WRITE] = { | |
619 | .pc_func = (svc_procfunc) nfsd_proc_write, | |
620 | .pc_decode = (kxdrproc_t) nfssvc_decode_writeargs, | |
621 | .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat, | |
622 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, | |
623 | .pc_argsize = sizeof(struct nfsd_writeargs), | |
624 | .pc_ressize = sizeof(struct nfsd_attrstat), | |
625 | .pc_cachetype = RC_REPLBUFF, | |
626 | .pc_xdrressize = ST+AT, | |
627 | }, | |
628 | [NFSPROC_CREATE] = { | |
629 | .pc_func = (svc_procfunc) nfsd_proc_create, | |
630 | .pc_decode = (kxdrproc_t) nfssvc_decode_createargs, | |
631 | .pc_encode = (kxdrproc_t) nfssvc_encode_diropres, | |
632 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, | |
633 | .pc_argsize = sizeof(struct nfsd_createargs), | |
634 | .pc_ressize = sizeof(struct nfsd_diropres), | |
635 | .pc_cachetype = RC_REPLBUFF, | |
636 | .pc_xdrressize = ST+FH+AT, | |
637 | }, | |
638 | [NFSPROC_REMOVE] = { | |
639 | .pc_func = (svc_procfunc) nfsd_proc_remove, | |
640 | .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs, | |
641 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, | |
642 | .pc_argsize = sizeof(struct nfsd_diropargs), | |
643 | .pc_ressize = sizeof(struct nfsd_void), | |
644 | .pc_cachetype = RC_REPLSTAT, | |
645 | .pc_xdrressize = ST, | |
646 | }, | |
647 | [NFSPROC_RENAME] = { | |
648 | .pc_func = (svc_procfunc) nfsd_proc_rename, | |
649 | .pc_decode = (kxdrproc_t) nfssvc_decode_renameargs, | |
650 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, | |
651 | .pc_argsize = sizeof(struct nfsd_renameargs), | |
652 | .pc_ressize = sizeof(struct nfsd_void), | |
653 | .pc_cachetype = RC_REPLSTAT, | |
654 | .pc_xdrressize = ST, | |
655 | }, | |
656 | [NFSPROC_LINK] = { | |
657 | .pc_func = (svc_procfunc) nfsd_proc_link, | |
658 | .pc_decode = (kxdrproc_t) nfssvc_decode_linkargs, | |
659 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, | |
660 | .pc_argsize = sizeof(struct nfsd_linkargs), | |
661 | .pc_ressize = sizeof(struct nfsd_void), | |
662 | .pc_cachetype = RC_REPLSTAT, | |
663 | .pc_xdrressize = ST, | |
664 | }, | |
665 | [NFSPROC_SYMLINK] = { | |
666 | .pc_func = (svc_procfunc) nfsd_proc_symlink, | |
667 | .pc_decode = (kxdrproc_t) nfssvc_decode_symlinkargs, | |
668 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, | |
669 | .pc_argsize = sizeof(struct nfsd_symlinkargs), | |
670 | .pc_ressize = sizeof(struct nfsd_void), | |
671 | .pc_cachetype = RC_REPLSTAT, | |
672 | .pc_xdrressize = ST, | |
673 | }, | |
674 | [NFSPROC_MKDIR] = { | |
675 | .pc_func = (svc_procfunc) nfsd_proc_mkdir, | |
676 | .pc_decode = (kxdrproc_t) nfssvc_decode_createargs, | |
677 | .pc_encode = (kxdrproc_t) nfssvc_encode_diropres, | |
678 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, | |
679 | .pc_argsize = sizeof(struct nfsd_createargs), | |
680 | .pc_ressize = sizeof(struct nfsd_diropres), | |
681 | .pc_cachetype = RC_REPLBUFF, | |
682 | .pc_xdrressize = ST+FH+AT, | |
683 | }, | |
684 | [NFSPROC_RMDIR] = { | |
685 | .pc_func = (svc_procfunc) nfsd_proc_rmdir, | |
686 | .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs, | |
687 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, | |
688 | .pc_argsize = sizeof(struct nfsd_diropargs), | |
689 | .pc_ressize = sizeof(struct nfsd_void), | |
690 | .pc_cachetype = RC_REPLSTAT, | |
691 | .pc_xdrressize = ST, | |
692 | }, | |
693 | [NFSPROC_READDIR] = { | |
694 | .pc_func = (svc_procfunc) nfsd_proc_readdir, | |
695 | .pc_decode = (kxdrproc_t) nfssvc_decode_readdirargs, | |
696 | .pc_encode = (kxdrproc_t) nfssvc_encode_readdirres, | |
697 | .pc_argsize = sizeof(struct nfsd_readdirargs), | |
698 | .pc_ressize = sizeof(struct nfsd_readdirres), | |
699 | .pc_cachetype = RC_NOCACHE, | |
700 | }, | |
701 | [NFSPROC_STATFS] = { | |
702 | .pc_func = (svc_procfunc) nfsd_proc_statfs, | |
703 | .pc_decode = (kxdrproc_t) nfssvc_decode_fhandle, | |
704 | .pc_encode = (kxdrproc_t) nfssvc_encode_statfsres, | |
705 | .pc_argsize = sizeof(struct nfsd_fhandle), | |
706 | .pc_ressize = sizeof(struct nfsd_statfsres), | |
707 | .pc_cachetype = RC_NOCACHE, | |
708 | .pc_xdrressize = ST+5, | |
709 | }, | |
1da177e4 LT |
710 | }; |
711 | ||
712 | ||
713 | struct svc_version nfsd_version2 = { | |
714 | .vs_vers = 2, | |
715 | .vs_nproc = 18, | |
716 | .vs_proc = nfsd_procedures2, | |
717 | .vs_dispatch = nfsd_dispatch, | |
718 | .vs_xdrsize = NFS2_SVC_XDRSIZE, | |
719 | }; | |
720 | ||
721 | /* | |
722 | * Map errnos to NFS errnos. | |
723 | */ | |
63f10311 | 724 | __be32 |
1da177e4 LT |
725 | nfserrno (int errno) |
726 | { | |
727 | static struct { | |
63f10311 | 728 | __be32 nfserr; |
1da177e4 LT |
729 | int syserr; |
730 | } nfs_errtbl[] = { | |
731 | { nfs_ok, 0 }, | |
732 | { nfserr_perm, -EPERM }, | |
733 | { nfserr_noent, -ENOENT }, | |
734 | { nfserr_io, -EIO }, | |
735 | { nfserr_nxio, -ENXIO }, | |
736 | { nfserr_acces, -EACCES }, | |
737 | { nfserr_exist, -EEXIST }, | |
738 | { nfserr_xdev, -EXDEV }, | |
739 | { nfserr_mlink, -EMLINK }, | |
740 | { nfserr_nodev, -ENODEV }, | |
741 | { nfserr_notdir, -ENOTDIR }, | |
742 | { nfserr_isdir, -EISDIR }, | |
743 | { nfserr_inval, -EINVAL }, | |
744 | { nfserr_fbig, -EFBIG }, | |
745 | { nfserr_nospc, -ENOSPC }, | |
746 | { nfserr_rofs, -EROFS }, | |
747 | { nfserr_mlink, -EMLINK }, | |
748 | { nfserr_nametoolong, -ENAMETOOLONG }, | |
749 | { nfserr_notempty, -ENOTEMPTY }, | |
750 | #ifdef EDQUOT | |
751 | { nfserr_dquot, -EDQUOT }, | |
752 | #endif | |
753 | { nfserr_stale, -ESTALE }, | |
754 | { nfserr_jukebox, -ETIMEDOUT }, | |
599eb304 | 755 | { nfserr_jukebox, -ERESTARTSYS }, |
1da177e4 LT |
756 | { nfserr_dropit, -EAGAIN }, |
757 | { nfserr_dropit, -ENOMEM }, | |
758 | { nfserr_badname, -ESRCH }, | |
759 | { nfserr_io, -ETXTBSY }, | |
a838cc49 | 760 | { nfserr_notsupp, -EOPNOTSUPP }, |
b7aeda40 | 761 | { nfserr_toosmall, -ETOOSMALL }, |
f39bde24 | 762 | { nfserr_serverfault, -ESERVERFAULT }, |
1da177e4 LT |
763 | }; |
764 | int i; | |
765 | ||
63f10311 | 766 | for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) { |
1da177e4 LT |
767 | if (nfs_errtbl[i].syserr == errno) |
768 | return nfs_errtbl[i].nfserr; | |
769 | } | |
770 | printk (KERN_INFO "nfsd: non-standard errno: %d\n", errno); | |
771 | return nfserr_io; | |
772 | } | |
773 |