1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Process version 2 NFS requests.
4 *
5 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
6 */
7
8 #include <linux/namei.h>
9
10 #include "cache.h"
11 #include "xdr.h"
12 #include "vfs.h"
13 #include "trace.h"
14
15 #define NFSDDBG_FACILITY NFSDDBG_PROC
16
nfsd_map_status(__be32 status)17 static __be32 nfsd_map_status(__be32 status)
18 {
19 switch (status) {
20 case nfs_ok:
21 break;
22 case nfserr_nofilehandle:
23 case nfserr_badhandle:
24 status = nfserr_stale;
25 break;
26 case nfserr_wrongsec:
27 case nfserr_xdev:
28 case nfserr_file_open:
29 status = nfserr_acces;
30 break;
31 case nfserr_symlink_not_dir:
32 status = nfserr_notdir;
33 break;
34 case nfserr_symlink:
35 case nfserr_wrong_type:
36 status = nfserr_io;
37 break;
38 }
39 return status;
40 }
41
42 static __be32
nfsd_proc_null(struct svc_rqst * rqstp)43 nfsd_proc_null(struct svc_rqst *rqstp)
44 {
45 return rpc_success;
46 }
47
48 /*
49 * Get a file's attributes
50 * N.B. After this call resp->fh needs an fh_put
51 */
52 static __be32
nfsd_proc_getattr(struct svc_rqst * rqstp)53 nfsd_proc_getattr(struct svc_rqst *rqstp)
54 {
55 struct nfsd_fhandle *argp = rqstp->rq_argp;
56 struct nfsd_attrstat *resp = rqstp->rq_resp;
57
58 trace_nfsd_vfs_getattr(rqstp, &argp->fh);
59
60 fh_copy(&resp->fh, &argp->fh);
61 resp->status = fh_verify(rqstp, &resp->fh, 0,
62 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
63 if (resp->status != nfs_ok)
64 goto out;
65 resp->status = fh_getattr(&resp->fh, &resp->stat);
66 out:
67 resp->status = nfsd_map_status(resp->status);
68 return rpc_success;
69 }
70
71 /*
72 * Set a file's attributes
73 * N.B. After this call resp->fh needs an fh_put
74 */
75 static __be32
nfsd_proc_setattr(struct svc_rqst * rqstp)76 nfsd_proc_setattr(struct svc_rqst *rqstp)
77 {
78 struct nfsd_sattrargs *argp = rqstp->rq_argp;
79 struct nfsd_attrstat *resp = rqstp->rq_resp;
80 struct iattr *iap = &argp->attrs;
81 struct nfsd_attrs attrs = {
82 .na_iattr = iap,
83 };
84 struct svc_fh *fhp;
85 int hosterr;
86
87 dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n",
88 SVCFH_fmt(&argp->fh),
89 argp->attrs.ia_valid, (long) argp->attrs.ia_size);
90
91 fhp = fh_copy(&resp->fh, &argp->fh);
92
93 /*
94 * NFSv2 does not differentiate between "set-[ac]time-to-now"
95 * which only requires access, and "set-[ac]time-to-X" which
96 * requires ownership.
97 * So if it looks like it might be "set both to the same time which
98 * is close to now", and if setattr_prepare fails, then we
99 * convert to "set to now" instead of "set to explicit time"
100 *
101 * We only call setattr_prepare as the last test as technically
102 * it is not an interface that we should be using.
103 */
104 #define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET)
105 #define MAX_TOUCH_TIME_ERROR (30*60)
106 if ((iap->ia_valid & BOTH_TIME_SET) == BOTH_TIME_SET &&
107 iap->ia_mtime.tv_sec == iap->ia_atime.tv_sec) {
108 /*
109 * Looks probable.
110 *
111 * Now just make sure time is in the right ballpark.
112 * Solaris, at least, doesn't seem to care what the time
113 * request is. We require it be within 30 minutes of now.
114 */
115 time64_t delta = iap->ia_atime.tv_sec - ktime_get_real_seconds();
116
117 resp->status = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP);
118 if (resp->status != nfs_ok)
119 goto out;
120
121 hosterr = fh_want_write(fhp);
122 if (hosterr) {
123 resp->status = nfserrno(hosterr);
124 goto out;
125 }
126
127 if (delta < 0)
128 delta = -delta;
129 if (delta < MAX_TOUCH_TIME_ERROR &&
130 setattr_prepare(&nop_mnt_idmap, fhp->fh_dentry, iap) != 0) {
131 /*
132 * Turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME.
133 * This will cause notify_change to set these times
134 * to "now"
135 */
136 iap->ia_valid &= ~BOTH_TIME_SET;
137 }
138 }
139
140 resp->status = nfsd_setattr(rqstp, fhp, &attrs, NULL);
141 if (resp->status != nfs_ok)
142 goto out;
143
144 resp->status = fh_getattr(&resp->fh, &resp->stat);
145 out:
146 resp->status = nfsd_map_status(resp->status);
147 return rpc_success;
148 }
149
150 /* Obsolete, replaced by MNTPROC_MNT. */
151 static __be32
nfsd_proc_root(struct svc_rqst * rqstp)152 nfsd_proc_root(struct svc_rqst *rqstp)
153 {
154 return rpc_success;
155 }
156
157 /*
158 * Look up a path name component
159 * Note: the dentry in the resp->fh may be negative if the file
160 * doesn't exist yet.
161 * N.B. After this call resp->fh needs an fh_put
162 */
163 static __be32
nfsd_proc_lookup(struct svc_rqst * rqstp)164 nfsd_proc_lookup(struct svc_rqst *rqstp)
165 {
166 struct nfsd_diropargs *argp = rqstp->rq_argp;
167 struct nfsd_diropres *resp = rqstp->rq_resp;
168
169 dprintk("nfsd: LOOKUP %s %.*s\n",
170 SVCFH_fmt(&argp->fh), argp->len, argp->name);
171
172 fh_init(&resp->fh, NFS_FHSIZE);
173 resp->status = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len,
174 &resp->fh);
175 fh_put(&argp->fh);
176 if (resp->status != nfs_ok)
177 goto out;
178
179 resp->status = fh_getattr(&resp->fh, &resp->stat);
180 out:
181 resp->status = nfsd_map_status(resp->status);
182 return rpc_success;
183 }
184
185 /*
186 * Read a symlink.
187 */
188 static __be32
nfsd_proc_readlink(struct svc_rqst * rqstp)189 nfsd_proc_readlink(struct svc_rqst *rqstp)
190 {
191 struct nfsd_fhandle *argp = rqstp->rq_argp;
192 struct nfsd_readlinkres *resp = rqstp->rq_resp;
193
194 dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh));
195
196 /* Read the symlink. */
197 resp->len = NFS_MAXPATHLEN;
198 resp->page = *(rqstp->rq_next_page++);
199 resp->status = nfsd_readlink(rqstp, &argp->fh,
200 page_address(resp->page), &resp->len);
201
202 fh_put(&argp->fh);
203 resp->status = nfsd_map_status(resp->status);
204 return rpc_success;
205 }
206
207 /*
208 * Read a portion of a file.
209 * N.B. After this call resp->fh needs an fh_put
210 */
211 static __be32
nfsd_proc_read(struct svc_rqst * rqstp)212 nfsd_proc_read(struct svc_rqst *rqstp)
213 {
214 struct nfsd_readargs *argp = rqstp->rq_argp;
215 struct nfsd_readres *resp = rqstp->rq_resp;
216 u32 eof;
217
218 dprintk("nfsd: READ %s %d bytes at %d\n",
219 SVCFH_fmt(&argp->fh),
220 argp->count, argp->offset);
221
222 argp->count = min_t(u32, argp->count, NFS_MAXDATA);
223 argp->count = min_t(u32, argp->count, rqstp->rq_res.buflen);
224
225 resp->pages = rqstp->rq_next_page;
226
227 /* Obtain buffer pointer for payload. 19 is 1 word for
228 * status, 17 words for fattr, and 1 word for the byte count.
229 */
230 svc_reserve_auth(rqstp, (19<<2) + argp->count + 4);
231
232 resp->count = argp->count;
233 fh_copy(&resp->fh, &argp->fh);
234 resp->status = nfsd_read(rqstp, &resp->fh, argp->offset,
235 &resp->count, &eof);
236 if (resp->status == nfs_ok)
237 resp->status = fh_getattr(&resp->fh, &resp->stat);
238 else if (resp->status == nfserr_jukebox)
239 set_bit(RQ_DROPME, &rqstp->rq_flags);
240 resp->status = nfsd_map_status(resp->status);
241 return rpc_success;
242 }
243
244 /* Reserved */
245 static __be32
nfsd_proc_writecache(struct svc_rqst * rqstp)246 nfsd_proc_writecache(struct svc_rqst *rqstp)
247 {
248 return rpc_success;
249 }
250
251 /*
252 * Write data to a file
253 * N.B. After this call resp->fh needs an fh_put
254 */
255 static __be32
nfsd_proc_write(struct svc_rqst * rqstp)256 nfsd_proc_write(struct svc_rqst *rqstp)
257 {
258 struct nfsd_writeargs *argp = rqstp->rq_argp;
259 struct nfsd_attrstat *resp = rqstp->rq_resp;
260 unsigned long cnt = argp->len;
261
262 dprintk("nfsd: WRITE %s %u bytes at %d\n",
263 SVCFH_fmt(&argp->fh),
264 argp->len, argp->offset);
265
266 fh_copy(&resp->fh, &argp->fh);
267 resp->status = nfsd_write(rqstp, &resp->fh, argp->offset,
268 &argp->payload, &cnt, NFS_DATA_SYNC, NULL);
269 if (resp->status == nfs_ok)
270 resp->status = fh_getattr(&resp->fh, &resp->stat);
271 else if (resp->status == nfserr_jukebox)
272 set_bit(RQ_DROPME, &rqstp->rq_flags);
273 resp->status = nfsd_map_status(resp->status);
274 return rpc_success;
275 }
276
277 /*
278 * CREATE processing is complicated. The keyword here is `overloaded.'
279 * The parent directory is kept locked between the check for existence
280 * and the actual create() call in compliance with VFS protocols.
281 * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
282 */
283 static __be32
nfsd_proc_create(struct svc_rqst * rqstp)284 nfsd_proc_create(struct svc_rqst *rqstp)
285 {
286 struct nfsd_createargs *argp = rqstp->rq_argp;
287 struct nfsd_diropres *resp = rqstp->rq_resp;
288 svc_fh *dirfhp = &argp->fh;
289 svc_fh *newfhp = &resp->fh;
290 struct iattr *attr = &argp->attrs;
291 struct nfsd_attrs attrs = {
292 .na_iattr = attr,
293 };
294 struct inode *inode;
295 struct dentry *dchild;
296 int type, mode;
297 int hosterr;
298 dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
299
300 /* First verify the parent file handle */
301 resp->status = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC);
302 if (resp->status != nfs_ok)
303 goto done; /* must fh_put dirfhp even on error */
304
305 /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */
306
307 resp->status = nfserr_exist;
308 if (name_is_dot_dotdot(argp->name, argp->len))
309 goto done;
310 hosterr = fh_want_write(dirfhp);
311 if (hosterr) {
312 resp->status = nfserrno(hosterr);
313 goto done;
314 }
315
316 dchild = start_creating(&nop_mnt_idmap, dirfhp->fh_dentry,
317 &QSTR_LEN(argp->name, argp->len));
318 if (IS_ERR(dchild)) {
319 resp->status = nfserrno(PTR_ERR(dchild));
320 goto out_write;
321 }
322 fh_init(newfhp, NFS_FHSIZE);
323 resp->status = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
324 if (!resp->status && d_really_is_negative(dchild))
325 resp->status = nfserr_noent;
326 if (resp->status) {
327 if (resp->status != nfserr_noent)
328 goto out_unlock;
329 /*
330 * If the new file handle wasn't verified, we can't tell
331 * whether the file exists or not. Time to bail ...
332 */
333 resp->status = nfserr_acces;
334 if (!newfhp->fh_dentry) {
335 printk(KERN_WARNING
336 "nfsd_proc_create: file handle not verified\n");
337 goto out_unlock;
338 }
339 }
340
341 inode = d_inode(newfhp->fh_dentry);
342
343 /* Unfudge the mode bits */
344 if (attr->ia_valid & ATTR_MODE) {
345 type = attr->ia_mode & S_IFMT;
346 mode = attr->ia_mode & ~S_IFMT;
347 if (!type) {
348 /* no type, so if target exists, assume same as that,
349 * else assume a file */
350 if (inode) {
351 type = inode->i_mode & S_IFMT;
352 switch(type) {
353 case S_IFCHR:
354 case S_IFBLK:
355 /* reserve rdev for later checking */
356 rdev = inode->i_rdev;
357 attr->ia_valid |= ATTR_SIZE;
358
359 fallthrough;
360 case S_IFIFO:
361 /* this is probably a permission check..
362 * at least IRIX implements perm checking on
363 * echo thing > device-special-file-or-pipe
364 * by doing a CREATE with type==0
365 */
366 resp->status = nfsd_permission(
367 &rqstp->rq_cred,
368 newfhp->fh_export,
369 newfhp->fh_dentry,
370 NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
371 if (resp->status && resp->status != nfserr_rofs)
372 goto out_unlock;
373 }
374 } else
375 type = S_IFREG;
376 }
377 } else if (inode) {
378 type = inode->i_mode & S_IFMT;
379 mode = inode->i_mode & ~S_IFMT;
380 } else {
381 type = S_IFREG;
382 mode = 0; /* ??? */
383 }
384
385 attr->ia_valid |= ATTR_MODE;
386 attr->ia_mode = mode;
387
388 /* Special treatment for non-regular files according to the
389 * gospel of sun micro
390 */
391 if (type != S_IFREG) {
392 if (type != S_IFBLK && type != S_IFCHR) {
393 rdev = 0;
394 } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
395 /* If you think you've seen the worst, grok this. */
396 type = S_IFIFO;
397 } else {
398 /* Okay, char or block special */
399 if (!rdev)
400 rdev = wanted;
401 }
402
403 /* we've used the SIZE information, so discard it */
404 attr->ia_valid &= ~ATTR_SIZE;
405
406 /* Make sure the type and device matches */
407 resp->status = nfserr_exist;
408 if (inode && inode_wrong_type(inode, type))
409 goto out_unlock;
410 }
411
412 resp->status = nfs_ok;
413 if (!inode) {
414 /* File doesn't exist. Create it and set attrs */
415 resp->status = nfsd_create_locked(rqstp, dirfhp, &attrs, type,
416 rdev, newfhp);
417 /* nfsd_create_locked() unlocked the parent */
418 dput(dchild);
419 goto out_write;
420 } else if (type == S_IFREG) {
421 dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
422 argp->name, attr->ia_valid, (long) attr->ia_size);
423 /* File already exists. We ignore all attributes except
424 * size, so that creat() behaves exactly like
425 * open(..., O_CREAT|O_TRUNC|O_WRONLY).
426 */
427 attr->ia_valid &= ATTR_SIZE;
428 if (attr->ia_valid)
429 resp->status = nfsd_setattr(rqstp, newfhp, &attrs,
430 NULL);
431 }
432
433 out_unlock:
434 end_creating(dchild);
435 out_write:
436 fh_drop_write(dirfhp);
437 done:
438 fh_put(dirfhp);
439 if (resp->status != nfs_ok)
440 goto out;
441 resp->status = fh_getattr(&resp->fh, &resp->stat);
442 out:
443 resp->status = nfsd_map_status(resp->status);
444 return rpc_success;
445 }
446
447 static __be32
nfsd_proc_remove(struct svc_rqst * rqstp)448 nfsd_proc_remove(struct svc_rqst *rqstp)
449 {
450 struct nfsd_diropargs *argp = rqstp->rq_argp;
451 struct nfsd_stat *resp = rqstp->rq_resp;
452
453 /* Unlink. -SIFDIR means file must not be a directory */
454 resp->status = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR,
455 argp->name, argp->len);
456 fh_put(&argp->fh);
457 resp->status = nfsd_map_status(resp->status);
458 return rpc_success;
459 }
460
461 static __be32
nfsd_proc_rename(struct svc_rqst * rqstp)462 nfsd_proc_rename(struct svc_rqst *rqstp)
463 {
464 struct nfsd_renameargs *argp = rqstp->rq_argp;
465 struct nfsd_stat *resp = rqstp->rq_resp;
466
467 resp->status = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
468 &argp->tfh, argp->tname, argp->tlen);
469 fh_put(&argp->ffh);
470 fh_put(&argp->tfh);
471 resp->status = nfsd_map_status(resp->status);
472 return rpc_success;
473 }
474
475 static __be32
nfsd_proc_link(struct svc_rqst * rqstp)476 nfsd_proc_link(struct svc_rqst *rqstp)
477 {
478 struct nfsd_linkargs *argp = rqstp->rq_argp;
479 struct nfsd_stat *resp = rqstp->rq_resp;
480
481 resp->status = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
482 &argp->ffh);
483 fh_put(&argp->ffh);
484 fh_put(&argp->tfh);
485 resp->status = nfsd_map_status(resp->status);
486 return rpc_success;
487 }
488
489 static __be32
nfsd_proc_symlink(struct svc_rqst * rqstp)490 nfsd_proc_symlink(struct svc_rqst *rqstp)
491 {
492 struct nfsd_symlinkargs *argp = rqstp->rq_argp;
493 struct nfsd_stat *resp = rqstp->rq_resp;
494 struct nfsd_attrs attrs = {
495 .na_iattr = &argp->attrs,
496 };
497 struct svc_fh newfh;
498
499 if (argp->tlen > NFS_MAXPATHLEN) {
500 resp->status = nfserr_nametoolong;
501 goto out;
502 }
503
504 argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
505 page_address(rqstp->rq_arg.pages[0]),
506 argp->tlen);
507 if (IS_ERR(argp->tname)) {
508 resp->status = nfserrno(PTR_ERR(argp->tname));
509 goto out;
510 }
511
512 fh_init(&newfh, NFS_FHSIZE);
513 resp->status = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
514 argp->tname, &attrs, &newfh);
515
516 kfree(argp->tname);
517 fh_put(&argp->ffh);
518 fh_put(&newfh);
519 out:
520 resp->status = nfsd_map_status(resp->status);
521 return rpc_success;
522 }
523
524 /*
525 * Make directory. This operation is not idempotent.
526 * N.B. After this call resp->fh needs an fh_put
527 */
528 static __be32
nfsd_proc_mkdir(struct svc_rqst * rqstp)529 nfsd_proc_mkdir(struct svc_rqst *rqstp)
530 {
531 struct nfsd_createargs *argp = rqstp->rq_argp;
532 struct nfsd_diropres *resp = rqstp->rq_resp;
533 struct nfsd_attrs attrs = {
534 .na_iattr = &argp->attrs,
535 };
536
537 if (resp->fh.fh_dentry) {
538 printk(KERN_WARNING
539 "nfsd_proc_mkdir: response already verified??\n");
540 }
541
542 argp->attrs.ia_valid &= ~ATTR_SIZE;
543 fh_init(&resp->fh, NFS_FHSIZE);
544 resp->status = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
545 &attrs, S_IFDIR, 0, &resp->fh);
546 fh_put(&argp->fh);
547 if (resp->status != nfs_ok)
548 goto out;
549
550 resp->status = fh_getattr(&resp->fh, &resp->stat);
551 out:
552 resp->status = nfsd_map_status(resp->status);
553 return rpc_success;
554 }
555
556 /*
557 * Remove a directory
558 */
559 static __be32
nfsd_proc_rmdir(struct svc_rqst * rqstp)560 nfsd_proc_rmdir(struct svc_rqst *rqstp)
561 {
562 struct nfsd_diropargs *argp = rqstp->rq_argp;
563 struct nfsd_stat *resp = rqstp->rq_resp;
564
565 resp->status = nfsd_unlink(rqstp, &argp->fh, S_IFDIR,
566 argp->name, argp->len);
567 fh_put(&argp->fh);
568 resp->status = nfsd_map_status(resp->status);
569 return rpc_success;
570 }
571
nfsd_init_dirlist_pages(struct svc_rqst * rqstp,struct nfsd_readdirres * resp,u32 count)572 static void nfsd_init_dirlist_pages(struct svc_rqst *rqstp,
573 struct nfsd_readdirres *resp,
574 u32 count)
575 {
576 struct xdr_buf *buf = &resp->dirlist;
577 struct xdr_stream *xdr = &resp->xdr;
578
579 memset(buf, 0, sizeof(*buf));
580
581 /* Reserve room for the NULL ptr & eof flag (-2 words) */
582 buf->buflen = clamp(count, (u32)(XDR_UNIT * 2), (u32)PAGE_SIZE);
583 buf->buflen -= XDR_UNIT * 2;
584 buf->pages = rqstp->rq_next_page;
585 rqstp->rq_next_page++;
586
587 xdr_init_encode_pages(xdr, buf);
588 }
589
590 /*
591 * Read a portion of a directory.
592 */
593 static __be32
nfsd_proc_readdir(struct svc_rqst * rqstp)594 nfsd_proc_readdir(struct svc_rqst *rqstp)
595 {
596 struct nfsd_readdirargs *argp = rqstp->rq_argp;
597 struct nfsd_readdirres *resp = rqstp->rq_resp;
598 loff_t offset;
599
600 trace_nfsd_vfs_readdir(rqstp, &argp->fh, argp->count, argp->cookie);
601
602 nfsd_init_dirlist_pages(rqstp, resp, argp->count);
603
604 resp->common.err = nfs_ok;
605 resp->cookie_offset = 0;
606 offset = argp->cookie;
607 resp->status = nfsd_readdir(rqstp, &argp->fh, &offset,
608 &resp->common, nfssvc_encode_entry);
609 nfssvc_encode_nfscookie(resp, offset);
610
611 fh_put(&argp->fh);
612 resp->status = nfsd_map_status(resp->status);
613 return rpc_success;
614 }
615
616 /*
617 * Get file system info
618 */
619 static __be32
nfsd_proc_statfs(struct svc_rqst * rqstp)620 nfsd_proc_statfs(struct svc_rqst *rqstp)
621 {
622 struct nfsd_fhandle *argp = rqstp->rq_argp;
623 struct nfsd_statfsres *resp = rqstp->rq_resp;
624
625 resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
626 NFSD_MAY_BYPASS_GSS_ON_ROOT);
627 fh_put(&argp->fh);
628 resp->status = nfsd_map_status(resp->status);
629 return rpc_success;
630 }
631
632 /*
633 * NFSv2 Server procedures.
634 * Only the results of non-idempotent operations are cached.
635 */
636
637 #define ST 1 /* status */
638 #define FH 8 /* filehandle */
639 #define AT 18 /* attributes */
640
641 static const struct svc_procedure nfsd_procedures2[18] = {
642 [NFSPROC_NULL] = {
643 .pc_func = nfsd_proc_null,
644 .pc_decode = nfssvc_decode_voidarg,
645 .pc_encode = nfssvc_encode_voidres,
646 .pc_argsize = sizeof(struct nfsd_voidargs),
647 .pc_argzero = sizeof(struct nfsd_voidargs),
648 .pc_ressize = sizeof(struct nfsd_voidres),
649 .pc_cachetype = RC_NOCACHE,
650 .pc_xdrressize = 0,
651 .pc_name = "NULL",
652 },
653 [NFSPROC_GETATTR] = {
654 .pc_func = nfsd_proc_getattr,
655 .pc_decode = nfssvc_decode_fhandleargs,
656 .pc_encode = nfssvc_encode_attrstatres,
657 .pc_release = nfssvc_release_attrstat,
658 .pc_argsize = sizeof(struct nfsd_fhandle),
659 .pc_argzero = sizeof(struct nfsd_fhandle),
660 .pc_ressize = sizeof(struct nfsd_attrstat),
661 .pc_cachetype = RC_NOCACHE,
662 .pc_xdrressize = ST+AT,
663 .pc_name = "GETATTR",
664 },
665 [NFSPROC_SETATTR] = {
666 .pc_func = nfsd_proc_setattr,
667 .pc_decode = nfssvc_decode_sattrargs,
668 .pc_encode = nfssvc_encode_attrstatres,
669 .pc_release = nfssvc_release_attrstat,
670 .pc_argsize = sizeof(struct nfsd_sattrargs),
671 .pc_argzero = sizeof(struct nfsd_sattrargs),
672 .pc_ressize = sizeof(struct nfsd_attrstat),
673 .pc_cachetype = RC_REPLBUFF,
674 .pc_xdrressize = ST+AT,
675 .pc_name = "SETATTR",
676 },
677 [NFSPROC_ROOT] = {
678 .pc_func = nfsd_proc_root,
679 .pc_decode = nfssvc_decode_voidarg,
680 .pc_encode = nfssvc_encode_voidres,
681 .pc_argsize = sizeof(struct nfsd_voidargs),
682 .pc_argzero = sizeof(struct nfsd_voidargs),
683 .pc_ressize = sizeof(struct nfsd_voidres),
684 .pc_cachetype = RC_NOCACHE,
685 .pc_xdrressize = 0,
686 .pc_name = "ROOT",
687 },
688 [NFSPROC_LOOKUP] = {
689 .pc_func = nfsd_proc_lookup,
690 .pc_decode = nfssvc_decode_diropargs,
691 .pc_encode = nfssvc_encode_diropres,
692 .pc_release = nfssvc_release_diropres,
693 .pc_argsize = sizeof(struct nfsd_diropargs),
694 .pc_argzero = sizeof(struct nfsd_diropargs),
695 .pc_ressize = sizeof(struct nfsd_diropres),
696 .pc_cachetype = RC_NOCACHE,
697 .pc_xdrressize = ST+FH+AT,
698 .pc_name = "LOOKUP",
699 },
700 [NFSPROC_READLINK] = {
701 .pc_func = nfsd_proc_readlink,
702 .pc_decode = nfssvc_decode_fhandleargs,
703 .pc_encode = nfssvc_encode_readlinkres,
704 .pc_argsize = sizeof(struct nfsd_fhandle),
705 .pc_argzero = sizeof(struct nfsd_fhandle),
706 .pc_ressize = sizeof(struct nfsd_readlinkres),
707 .pc_cachetype = RC_NOCACHE,
708 .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4,
709 .pc_name = "READLINK",
710 },
711 [NFSPROC_READ] = {
712 .pc_func = nfsd_proc_read,
713 .pc_decode = nfssvc_decode_readargs,
714 .pc_encode = nfssvc_encode_readres,
715 .pc_release = nfssvc_release_readres,
716 .pc_argsize = sizeof(struct nfsd_readargs),
717 .pc_argzero = sizeof(struct nfsd_readargs),
718 .pc_ressize = sizeof(struct nfsd_readres),
719 .pc_cachetype = RC_NOCACHE,
720 .pc_xdrressize = ST+AT+1+NFS_MAXDATA/4,
721 .pc_name = "READ",
722 },
723 [NFSPROC_WRITECACHE] = {
724 .pc_func = nfsd_proc_writecache,
725 .pc_decode = nfssvc_decode_voidarg,
726 .pc_encode = nfssvc_encode_voidres,
727 .pc_argsize = sizeof(struct nfsd_voidargs),
728 .pc_argzero = sizeof(struct nfsd_voidargs),
729 .pc_ressize = sizeof(struct nfsd_voidres),
730 .pc_cachetype = RC_NOCACHE,
731 .pc_xdrressize = 0,
732 .pc_name = "WRITECACHE",
733 },
734 [NFSPROC_WRITE] = {
735 .pc_func = nfsd_proc_write,
736 .pc_decode = nfssvc_decode_writeargs,
737 .pc_encode = nfssvc_encode_attrstatres,
738 .pc_release = nfssvc_release_attrstat,
739 .pc_argsize = sizeof(struct nfsd_writeargs),
740 .pc_argzero = sizeof(struct nfsd_writeargs),
741 .pc_ressize = sizeof(struct nfsd_attrstat),
742 .pc_cachetype = RC_REPLBUFF,
743 .pc_xdrressize = ST+AT,
744 .pc_name = "WRITE",
745 },
746 [NFSPROC_CREATE] = {
747 .pc_func = nfsd_proc_create,
748 .pc_decode = nfssvc_decode_createargs,
749 .pc_encode = nfssvc_encode_diropres,
750 .pc_release = nfssvc_release_diropres,
751 .pc_argsize = sizeof(struct nfsd_createargs),
752 .pc_argzero = sizeof(struct nfsd_createargs),
753 .pc_ressize = sizeof(struct nfsd_diropres),
754 .pc_cachetype = RC_REPLBUFF,
755 .pc_xdrressize = ST+FH+AT,
756 .pc_name = "CREATE",
757 },
758 [NFSPROC_REMOVE] = {
759 .pc_func = nfsd_proc_remove,
760 .pc_decode = nfssvc_decode_diropargs,
761 .pc_encode = nfssvc_encode_statres,
762 .pc_argsize = sizeof(struct nfsd_diropargs),
763 .pc_argzero = sizeof(struct nfsd_diropargs),
764 .pc_ressize = sizeof(struct nfsd_stat),
765 .pc_cachetype = RC_REPLSTAT,
766 .pc_xdrressize = ST,
767 .pc_name = "REMOVE",
768 },
769 [NFSPROC_RENAME] = {
770 .pc_func = nfsd_proc_rename,
771 .pc_decode = nfssvc_decode_renameargs,
772 .pc_encode = nfssvc_encode_statres,
773 .pc_argsize = sizeof(struct nfsd_renameargs),
774 .pc_argzero = sizeof(struct nfsd_renameargs),
775 .pc_ressize = sizeof(struct nfsd_stat),
776 .pc_cachetype = RC_REPLSTAT,
777 .pc_xdrressize = ST,
778 .pc_name = "RENAME",
779 },
780 [NFSPROC_LINK] = {
781 .pc_func = nfsd_proc_link,
782 .pc_decode = nfssvc_decode_linkargs,
783 .pc_encode = nfssvc_encode_statres,
784 .pc_argsize = sizeof(struct nfsd_linkargs),
785 .pc_argzero = sizeof(struct nfsd_linkargs),
786 .pc_ressize = sizeof(struct nfsd_stat),
787 .pc_cachetype = RC_REPLSTAT,
788 .pc_xdrressize = ST,
789 .pc_name = "LINK",
790 },
791 [NFSPROC_SYMLINK] = {
792 .pc_func = nfsd_proc_symlink,
793 .pc_decode = nfssvc_decode_symlinkargs,
794 .pc_encode = nfssvc_encode_statres,
795 .pc_argsize = sizeof(struct nfsd_symlinkargs),
796 .pc_argzero = sizeof(struct nfsd_symlinkargs),
797 .pc_ressize = sizeof(struct nfsd_stat),
798 .pc_cachetype = RC_REPLSTAT,
799 .pc_xdrressize = ST,
800 .pc_name = "SYMLINK",
801 },
802 [NFSPROC_MKDIR] = {
803 .pc_func = nfsd_proc_mkdir,
804 .pc_decode = nfssvc_decode_createargs,
805 .pc_encode = nfssvc_encode_diropres,
806 .pc_release = nfssvc_release_diropres,
807 .pc_argsize = sizeof(struct nfsd_createargs),
808 .pc_argzero = sizeof(struct nfsd_createargs),
809 .pc_ressize = sizeof(struct nfsd_diropres),
810 .pc_cachetype = RC_REPLBUFF,
811 .pc_xdrressize = ST+FH+AT,
812 .pc_name = "MKDIR",
813 },
814 [NFSPROC_RMDIR] = {
815 .pc_func = nfsd_proc_rmdir,
816 .pc_decode = nfssvc_decode_diropargs,
817 .pc_encode = nfssvc_encode_statres,
818 .pc_argsize = sizeof(struct nfsd_diropargs),
819 .pc_argzero = sizeof(struct nfsd_diropargs),
820 .pc_ressize = sizeof(struct nfsd_stat),
821 .pc_cachetype = RC_REPLSTAT,
822 .pc_xdrressize = ST,
823 .pc_name = "RMDIR",
824 },
825 [NFSPROC_READDIR] = {
826 .pc_func = nfsd_proc_readdir,
827 .pc_decode = nfssvc_decode_readdirargs,
828 .pc_encode = nfssvc_encode_readdirres,
829 .pc_argsize = sizeof(struct nfsd_readdirargs),
830 .pc_argzero = sizeof(struct nfsd_readdirargs),
831 .pc_ressize = sizeof(struct nfsd_readdirres),
832 .pc_cachetype = RC_NOCACHE,
833 .pc_name = "READDIR",
834 },
835 [NFSPROC_STATFS] = {
836 .pc_func = nfsd_proc_statfs,
837 .pc_decode = nfssvc_decode_fhandleargs,
838 .pc_encode = nfssvc_encode_statfsres,
839 .pc_argsize = sizeof(struct nfsd_fhandle),
840 .pc_argzero = sizeof(struct nfsd_fhandle),
841 .pc_ressize = sizeof(struct nfsd_statfsres),
842 .pc_cachetype = RC_NOCACHE,
843 .pc_xdrressize = ST+5,
844 .pc_name = "STATFS",
845 },
846 };
847
848 const struct svc_version nfsd_version2 = {
849 .vs_vers = 2,
850 .vs_nproc = ARRAY_SIZE(nfsd_procedures2),
851 .vs_proc = nfsd_procedures2,
852 .vs_dispatch = nfsd_dispatch,
853 .vs_xdrsize = NFS2_SVC_XDRSIZE,
854 };
855