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