nfsproc.c 20 KB

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