nfsproc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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. * Create the link, look up new file and set attrs.
  353. */
  354. nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
  355. argp->tname, argp->tlen,
  356. &newfh, &argp->attrs);
  357. fh_put(&argp->ffh);
  358. fh_put(&newfh);
  359. return nfserr;
  360. }
  361. /*
  362. * Make directory. This operation is not idempotent.
  363. * N.B. After this call resp->fh needs an fh_put
  364. */
  365. static __be32
  366. nfsd_proc_mkdir(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
  367. struct nfsd_diropres *resp)
  368. {
  369. __be32 nfserr;
  370. dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  371. if (resp->fh.fh_dentry) {
  372. printk(KERN_WARNING
  373. "nfsd_proc_mkdir: response already verified??\n");
  374. }
  375. argp->attrs.ia_valid &= ~ATTR_SIZE;
  376. fh_init(&resp->fh, NFS_FHSIZE);
  377. nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
  378. &argp->attrs, S_IFDIR, 0, &resp->fh);
  379. fh_put(&argp->fh);
  380. return nfsd_return_dirop(nfserr, resp);
  381. }
  382. /*
  383. * Remove a directory
  384. */
  385. static __be32
  386. nfsd_proc_rmdir(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
  387. void *resp)
  388. {
  389. __be32 nfserr;
  390. dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  391. nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len);
  392. fh_put(&argp->fh);
  393. return nfserr;
  394. }
  395. /*
  396. * Read a portion of a directory.
  397. */
  398. static __be32
  399. nfsd_proc_readdir(struct svc_rqst *rqstp, struct nfsd_readdirargs *argp,
  400. struct nfsd_readdirres *resp)
  401. {
  402. int count;
  403. __be32 nfserr;
  404. loff_t offset;
  405. dprintk("nfsd: READDIR %s %d bytes at %d\n",
  406. SVCFH_fmt(&argp->fh),
  407. argp->count, argp->cookie);
  408. /* Shrink to the client read size */
  409. count = (argp->count >> 2) - 2;
  410. /* Make sure we've room for the NULL ptr & eof flag */
  411. count -= 2;
  412. if (count < 0)
  413. count = 0;
  414. resp->buffer = argp->buffer;
  415. resp->offset = NULL;
  416. resp->buflen = count;
  417. resp->common.err = nfs_ok;
  418. /* Read directory and encode entries on the fly */
  419. offset = argp->cookie;
  420. nfserr = nfsd_readdir(rqstp, &argp->fh, &offset,
  421. &resp->common, nfssvc_encode_entry);
  422. resp->count = resp->buffer - argp->buffer;
  423. if (resp->offset)
  424. *resp->offset = htonl(offset);
  425. fh_put(&argp->fh);
  426. return nfserr;
  427. }
  428. /*
  429. * Get file system info
  430. */
  431. static __be32
  432. nfsd_proc_statfs(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
  433. struct nfsd_statfsres *resp)
  434. {
  435. __be32 nfserr;
  436. dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
  437. nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
  438. NFSD_MAY_BYPASS_GSS_ON_ROOT);
  439. fh_put(&argp->fh);
  440. return nfserr;
  441. }
  442. /*
  443. * NFSv2 Server procedures.
  444. * Only the results of non-idempotent operations are cached.
  445. */
  446. struct nfsd_void { int dummy; };
  447. #define ST 1 /* status */
  448. #define FH 8 /* filehandle */
  449. #define AT 18 /* attributes */
  450. static struct svc_procedure nfsd_procedures2[18] = {
  451. [NFSPROC_NULL] = {
  452. .pc_func = (svc_procfunc) nfsd_proc_null,
  453. .pc_decode = (kxdrproc_t) nfssvc_decode_void,
  454. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  455. .pc_argsize = sizeof(struct nfsd_void),
  456. .pc_ressize = sizeof(struct nfsd_void),
  457. .pc_cachetype = RC_NOCACHE,
  458. .pc_xdrressize = ST,
  459. },
  460. [NFSPROC_GETATTR] = {
  461. .pc_func = (svc_procfunc) nfsd_proc_getattr,
  462. .pc_decode = (kxdrproc_t) nfssvc_decode_fhandle,
  463. .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
  464. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  465. .pc_argsize = sizeof(struct nfsd_fhandle),
  466. .pc_ressize = sizeof(struct nfsd_attrstat),
  467. .pc_cachetype = RC_NOCACHE,
  468. .pc_xdrressize = ST+AT,
  469. },
  470. [NFSPROC_SETATTR] = {
  471. .pc_func = (svc_procfunc) nfsd_proc_setattr,
  472. .pc_decode = (kxdrproc_t) nfssvc_decode_sattrargs,
  473. .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
  474. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  475. .pc_argsize = sizeof(struct nfsd_sattrargs),
  476. .pc_ressize = sizeof(struct nfsd_attrstat),
  477. .pc_cachetype = RC_REPLBUFF,
  478. .pc_xdrressize = ST+AT,
  479. },
  480. [NFSPROC_ROOT] = {
  481. .pc_decode = (kxdrproc_t) nfssvc_decode_void,
  482. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  483. .pc_argsize = sizeof(struct nfsd_void),
  484. .pc_ressize = sizeof(struct nfsd_void),
  485. .pc_cachetype = RC_NOCACHE,
  486. .pc_xdrressize = ST,
  487. },
  488. [NFSPROC_LOOKUP] = {
  489. .pc_func = (svc_procfunc) nfsd_proc_lookup,
  490. .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs,
  491. .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
  492. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  493. .pc_argsize = sizeof(struct nfsd_diropargs),
  494. .pc_ressize = sizeof(struct nfsd_diropres),
  495. .pc_cachetype = RC_NOCACHE,
  496. .pc_xdrressize = ST+FH+AT,
  497. },
  498. [NFSPROC_READLINK] = {
  499. .pc_func = (svc_procfunc) nfsd_proc_readlink,
  500. .pc_decode = (kxdrproc_t) nfssvc_decode_readlinkargs,
  501. .pc_encode = (kxdrproc_t) nfssvc_encode_readlinkres,
  502. .pc_argsize = sizeof(struct nfsd_readlinkargs),
  503. .pc_ressize = sizeof(struct nfsd_readlinkres),
  504. .pc_cachetype = RC_NOCACHE,
  505. .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4,
  506. },
  507. [NFSPROC_READ] = {
  508. .pc_func = (svc_procfunc) nfsd_proc_read,
  509. .pc_decode = (kxdrproc_t) nfssvc_decode_readargs,
  510. .pc_encode = (kxdrproc_t) nfssvc_encode_readres,
  511. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  512. .pc_argsize = sizeof(struct nfsd_readargs),
  513. .pc_ressize = sizeof(struct nfsd_readres),
  514. .pc_cachetype = RC_NOCACHE,
  515. .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4,
  516. },
  517. [NFSPROC_WRITECACHE] = {
  518. .pc_decode = (kxdrproc_t) nfssvc_decode_void,
  519. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  520. .pc_argsize = sizeof(struct nfsd_void),
  521. .pc_ressize = sizeof(struct nfsd_void),
  522. .pc_cachetype = RC_NOCACHE,
  523. .pc_xdrressize = ST,
  524. },
  525. [NFSPROC_WRITE] = {
  526. .pc_func = (svc_procfunc) nfsd_proc_write,
  527. .pc_decode = (kxdrproc_t) nfssvc_decode_writeargs,
  528. .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
  529. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  530. .pc_argsize = sizeof(struct nfsd_writeargs),
  531. .pc_ressize = sizeof(struct nfsd_attrstat),
  532. .pc_cachetype = RC_REPLBUFF,
  533. .pc_xdrressize = ST+AT,
  534. },
  535. [NFSPROC_CREATE] = {
  536. .pc_func = (svc_procfunc) nfsd_proc_create,
  537. .pc_decode = (kxdrproc_t) nfssvc_decode_createargs,
  538. .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
  539. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  540. .pc_argsize = sizeof(struct nfsd_createargs),
  541. .pc_ressize = sizeof(struct nfsd_diropres),
  542. .pc_cachetype = RC_REPLBUFF,
  543. .pc_xdrressize = ST+FH+AT,
  544. },
  545. [NFSPROC_REMOVE] = {
  546. .pc_func = (svc_procfunc) nfsd_proc_remove,
  547. .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs,
  548. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  549. .pc_argsize = sizeof(struct nfsd_diropargs),
  550. .pc_ressize = sizeof(struct nfsd_void),
  551. .pc_cachetype = RC_REPLSTAT,
  552. .pc_xdrressize = ST,
  553. },
  554. [NFSPROC_RENAME] = {
  555. .pc_func = (svc_procfunc) nfsd_proc_rename,
  556. .pc_decode = (kxdrproc_t) nfssvc_decode_renameargs,
  557. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  558. .pc_argsize = sizeof(struct nfsd_renameargs),
  559. .pc_ressize = sizeof(struct nfsd_void),
  560. .pc_cachetype = RC_REPLSTAT,
  561. .pc_xdrressize = ST,
  562. },
  563. [NFSPROC_LINK] = {
  564. .pc_func = (svc_procfunc) nfsd_proc_link,
  565. .pc_decode = (kxdrproc_t) nfssvc_decode_linkargs,
  566. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  567. .pc_argsize = sizeof(struct nfsd_linkargs),
  568. .pc_ressize = sizeof(struct nfsd_void),
  569. .pc_cachetype = RC_REPLSTAT,
  570. .pc_xdrressize = ST,
  571. },
  572. [NFSPROC_SYMLINK] = {
  573. .pc_func = (svc_procfunc) nfsd_proc_symlink,
  574. .pc_decode = (kxdrproc_t) nfssvc_decode_symlinkargs,
  575. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  576. .pc_argsize = sizeof(struct nfsd_symlinkargs),
  577. .pc_ressize = sizeof(struct nfsd_void),
  578. .pc_cachetype = RC_REPLSTAT,
  579. .pc_xdrressize = ST,
  580. },
  581. [NFSPROC_MKDIR] = {
  582. .pc_func = (svc_procfunc) nfsd_proc_mkdir,
  583. .pc_decode = (kxdrproc_t) nfssvc_decode_createargs,
  584. .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
  585. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  586. .pc_argsize = sizeof(struct nfsd_createargs),
  587. .pc_ressize = sizeof(struct nfsd_diropres),
  588. .pc_cachetype = RC_REPLBUFF,
  589. .pc_xdrressize = ST+FH+AT,
  590. },
  591. [NFSPROC_RMDIR] = {
  592. .pc_func = (svc_procfunc) nfsd_proc_rmdir,
  593. .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs,
  594. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  595. .pc_argsize = sizeof(struct nfsd_diropargs),
  596. .pc_ressize = sizeof(struct nfsd_void),
  597. .pc_cachetype = RC_REPLSTAT,
  598. .pc_xdrressize = ST,
  599. },
  600. [NFSPROC_READDIR] = {
  601. .pc_func = (svc_procfunc) nfsd_proc_readdir,
  602. .pc_decode = (kxdrproc_t) nfssvc_decode_readdirargs,
  603. .pc_encode = (kxdrproc_t) nfssvc_encode_readdirres,
  604. .pc_argsize = sizeof(struct nfsd_readdirargs),
  605. .pc_ressize = sizeof(struct nfsd_readdirres),
  606. .pc_cachetype = RC_NOCACHE,
  607. },
  608. [NFSPROC_STATFS] = {
  609. .pc_func = (svc_procfunc) nfsd_proc_statfs,
  610. .pc_decode = (kxdrproc_t) nfssvc_decode_fhandle,
  611. .pc_encode = (kxdrproc_t) nfssvc_encode_statfsres,
  612. .pc_argsize = sizeof(struct nfsd_fhandle),
  613. .pc_ressize = sizeof(struct nfsd_statfsres),
  614. .pc_cachetype = RC_NOCACHE,
  615. .pc_xdrressize = ST+5,
  616. },
  617. };
  618. struct svc_version nfsd_version2 = {
  619. .vs_vers = 2,
  620. .vs_nproc = 18,
  621. .vs_proc = nfsd_procedures2,
  622. .vs_dispatch = nfsd_dispatch,
  623. .vs_xdrsize = NFS2_SVC_XDRSIZE,
  624. };
  625. /*
  626. * Map errnos to NFS errnos.
  627. */
  628. __be32
  629. nfserrno (int errno)
  630. {
  631. static struct {
  632. __be32 nfserr;
  633. int syserr;
  634. } nfs_errtbl[] = {
  635. { nfs_ok, 0 },
  636. { nfserr_perm, -EPERM },
  637. { nfserr_noent, -ENOENT },
  638. { nfserr_io, -EIO },
  639. { nfserr_nxio, -ENXIO },
  640. { nfserr_acces, -EACCES },
  641. { nfserr_exist, -EEXIST },
  642. { nfserr_xdev, -EXDEV },
  643. { nfserr_mlink, -EMLINK },
  644. { nfserr_nodev, -ENODEV },
  645. { nfserr_notdir, -ENOTDIR },
  646. { nfserr_isdir, -EISDIR },
  647. { nfserr_inval, -EINVAL },
  648. { nfserr_fbig, -EFBIG },
  649. { nfserr_nospc, -ENOSPC },
  650. { nfserr_rofs, -EROFS },
  651. { nfserr_mlink, -EMLINK },
  652. { nfserr_nametoolong, -ENAMETOOLONG },
  653. { nfserr_notempty, -ENOTEMPTY },
  654. #ifdef EDQUOT
  655. { nfserr_dquot, -EDQUOT },
  656. #endif
  657. { nfserr_stale, -ESTALE },
  658. { nfserr_jukebox, -ETIMEDOUT },
  659. { nfserr_jukebox, -ERESTARTSYS },
  660. { nfserr_jukebox, -EAGAIN },
  661. { nfserr_jukebox, -EWOULDBLOCK },
  662. { nfserr_jukebox, -ENOMEM },
  663. { nfserr_io, -ETXTBSY },
  664. { nfserr_notsupp, -EOPNOTSUPP },
  665. { nfserr_toosmall, -ETOOSMALL },
  666. { nfserr_serverfault, -ESERVERFAULT },
  667. };
  668. int i;
  669. for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
  670. if (nfs_errtbl[i].syserr == errno)
  671. return nfs_errtbl[i].nfserr;
  672. }
  673. printk (KERN_INFO "nfsd: non-standard errno: %d\n", errno);
  674. return nfserr_io;
  675. }