nfsproc.c 21 KB

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