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 nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt,
  23. resp->fh.fh_dentry,
  24. &resp->stat));
  25. }
  26. static __be32
  27. nfsd_return_dirop(__be32 err, struct nfsd_diropres *resp)
  28. {
  29. if (err) return err;
  30. return nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt,
  31. resp->fh.fh_dentry,
  32. &resp->stat));
  33. }
  34. /*
  35. * Get a file's attributes
  36. * N.B. After this call resp->fh needs an fh_put
  37. */
  38. static __be32
  39. nfsd_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle *argp,
  40. struct nfsd_attrstat *resp)
  41. {
  42. __be32 nfserr;
  43. dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
  44. fh_copy(&resp->fh, &argp->fh);
  45. nfserr = fh_verify(rqstp, &resp->fh, 0,
  46. NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
  47. return nfsd_return_attrs(nfserr, resp);
  48. }
  49. /*
  50. * Set a file's attributes
  51. * N.B. After this call resp->fh needs an fh_put
  52. */
  53. static __be32
  54. nfsd_proc_setattr(struct svc_rqst *rqstp, struct nfsd_sattrargs *argp,
  55. struct nfsd_attrstat *resp)
  56. {
  57. __be32 nfserr;
  58. dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n",
  59. SVCFH_fmt(&argp->fh),
  60. argp->attrs.ia_valid, (long) argp->attrs.ia_size);
  61. fh_copy(&resp->fh, &argp->fh);
  62. nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,0, (time_t)0);
  63. return nfsd_return_attrs(nfserr, resp);
  64. }
  65. /*
  66. * Look up a path name component
  67. * Note: the dentry in the resp->fh may be negative if the file
  68. * doesn't exist yet.
  69. * N.B. After this call resp->fh needs an fh_put
  70. */
  71. static __be32
  72. nfsd_proc_lookup(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
  73. struct nfsd_diropres *resp)
  74. {
  75. __be32 nfserr;
  76. dprintk("nfsd: LOOKUP %s %.*s\n",
  77. SVCFH_fmt(&argp->fh), argp->len, argp->name);
  78. fh_init(&resp->fh, NFS_FHSIZE);
  79. nfserr = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len,
  80. &resp->fh);
  81. fh_put(&argp->fh);
  82. return nfsd_return_dirop(nfserr, resp);
  83. }
  84. /*
  85. * Read a symlink.
  86. */
  87. static __be32
  88. nfsd_proc_readlink(struct svc_rqst *rqstp, struct nfsd_readlinkargs *argp,
  89. struct nfsd_readlinkres *resp)
  90. {
  91. __be32 nfserr;
  92. dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh));
  93. /* Read the symlink. */
  94. resp->len = NFS_MAXPATHLEN;
  95. nfserr = nfsd_readlink(rqstp, &argp->fh, argp->buffer, &resp->len);
  96. fh_put(&argp->fh);
  97. return nfserr;
  98. }
  99. /*
  100. * Read a portion of a file.
  101. * N.B. After this call resp->fh needs an fh_put
  102. */
  103. static __be32
  104. nfsd_proc_read(struct svc_rqst *rqstp, struct nfsd_readargs *argp,
  105. struct nfsd_readres *resp)
  106. {
  107. __be32 nfserr;
  108. dprintk("nfsd: READ %s %d bytes at %d\n",
  109. SVCFH_fmt(&argp->fh),
  110. argp->count, argp->offset);
  111. /* Obtain buffer pointer for payload. 19 is 1 word for
  112. * status, 17 words for fattr, and 1 word for the byte count.
  113. */
  114. if (NFSSVC_MAXBLKSIZE_V2 < argp->count) {
  115. char buf[RPC_MAX_ADDRBUFLEN];
  116. printk(KERN_NOTICE
  117. "oversized read request from %s (%d bytes)\n",
  118. svc_print_addr(rqstp, buf, sizeof(buf)),
  119. argp->count);
  120. argp->count = NFSSVC_MAXBLKSIZE_V2;
  121. }
  122. svc_reserve_auth(rqstp, (19<<2) + argp->count + 4);
  123. resp->count = argp->count;
  124. nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh),
  125. argp->offset,
  126. rqstp->rq_vec, argp->vlen,
  127. &resp->count);
  128. if (nfserr) return nfserr;
  129. return nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt,
  130. resp->fh.fh_dentry,
  131. &resp->stat));
  132. }
  133. /*
  134. * Write data to a file
  135. * N.B. After this call resp->fh needs an fh_put
  136. */
  137. static __be32
  138. nfsd_proc_write(struct svc_rqst *rqstp, struct nfsd_writeargs *argp,
  139. struct nfsd_attrstat *resp)
  140. {
  141. __be32 nfserr;
  142. int stable = 1;
  143. unsigned long cnt = argp->len;
  144. dprintk("nfsd: WRITE %s %d bytes at %d\n",
  145. SVCFH_fmt(&argp->fh),
  146. argp->len, argp->offset);
  147. nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
  148. argp->offset,
  149. rqstp->rq_vec, argp->vlen,
  150. &cnt,
  151. &stable);
  152. return nfsd_return_attrs(nfserr, resp);
  153. }
  154. /*
  155. * CREATE processing is complicated. The keyword here is `overloaded.'
  156. * The parent directory is kept locked between the check for existence
  157. * and the actual create() call in compliance with VFS protocols.
  158. * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
  159. */
  160. static __be32
  161. nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
  162. struct nfsd_diropres *resp)
  163. {
  164. svc_fh *dirfhp = &argp->fh;
  165. svc_fh *newfhp = &resp->fh;
  166. struct iattr *attr = &argp->attrs;
  167. struct inode *inode;
  168. struct dentry *dchild;
  169. int type, mode;
  170. __be32 nfserr;
  171. dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
  172. dprintk("nfsd: CREATE %s %.*s\n",
  173. SVCFH_fmt(dirfhp), argp->len, argp->name);
  174. /* First verify the parent file handle */
  175. nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC);
  176. if (nfserr)
  177. goto done; /* must fh_put dirfhp even on error */
  178. /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */
  179. nfserr = nfserr_acces;
  180. if (!argp->len)
  181. goto done;
  182. nfserr = nfserr_exist;
  183. if (isdotent(argp->name, argp->len))
  184. goto done;
  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. done:
  293. fh_put(dirfhp);
  294. return nfsd_return_dirop(nfserr, resp);
  295. }
  296. static __be32
  297. nfsd_proc_remove(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
  298. void *resp)
  299. {
  300. __be32 nfserr;
  301. dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh),
  302. argp->len, argp->name);
  303. /* Unlink. -SIFDIR means file must not be a directory */
  304. nfserr = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR, argp->name, argp->len);
  305. fh_put(&argp->fh);
  306. return nfserr;
  307. }
  308. static __be32
  309. nfsd_proc_rename(struct svc_rqst *rqstp, struct nfsd_renameargs *argp,
  310. void *resp)
  311. {
  312. __be32 nfserr;
  313. dprintk("nfsd: RENAME %s %.*s -> \n",
  314. SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
  315. dprintk("nfsd: -> %s %.*s\n",
  316. SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname);
  317. nfserr = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
  318. &argp->tfh, argp->tname, argp->tlen);
  319. fh_put(&argp->ffh);
  320. fh_put(&argp->tfh);
  321. return nfserr;
  322. }
  323. static __be32
  324. nfsd_proc_link(struct svc_rqst *rqstp, struct nfsd_linkargs *argp,
  325. void *resp)
  326. {
  327. __be32 nfserr;
  328. dprintk("nfsd: LINK %s ->\n",
  329. SVCFH_fmt(&argp->ffh));
  330. dprintk("nfsd: %s %.*s\n",
  331. SVCFH_fmt(&argp->tfh),
  332. argp->tlen,
  333. argp->tname);
  334. nfserr = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
  335. &argp->ffh);
  336. fh_put(&argp->ffh);
  337. fh_put(&argp->tfh);
  338. return nfserr;
  339. }
  340. static __be32
  341. nfsd_proc_symlink(struct svc_rqst *rqstp, struct nfsd_symlinkargs *argp,
  342. void *resp)
  343. {
  344. struct svc_fh newfh;
  345. __be32 nfserr;
  346. dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n",
  347. SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
  348. argp->tlen, argp->tname);
  349. fh_init(&newfh, NFS_FHSIZE);
  350. /*
  351. * Create the link, look up new file and set attrs.
  352. */
  353. nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
  354. argp->tname, argp->tlen,
  355. &newfh, &argp->attrs);
  356. fh_put(&argp->ffh);
  357. fh_put(&newfh);
  358. return nfserr;
  359. }
  360. /*
  361. * Make directory. This operation is not idempotent.
  362. * N.B. After this call resp->fh needs an fh_put
  363. */
  364. static __be32
  365. nfsd_proc_mkdir(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
  366. struct nfsd_diropres *resp)
  367. {
  368. __be32 nfserr;
  369. dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  370. if (resp->fh.fh_dentry) {
  371. printk(KERN_WARNING
  372. "nfsd_proc_mkdir: response already verified??\n");
  373. }
  374. argp->attrs.ia_valid &= ~ATTR_SIZE;
  375. fh_init(&resp->fh, NFS_FHSIZE);
  376. nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
  377. &argp->attrs, S_IFDIR, 0, &resp->fh);
  378. fh_put(&argp->fh);
  379. return nfsd_return_dirop(nfserr, resp);
  380. }
  381. /*
  382. * Remove a directory
  383. */
  384. static __be32
  385. nfsd_proc_rmdir(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
  386. void *resp)
  387. {
  388. __be32 nfserr;
  389. dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  390. nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len);
  391. fh_put(&argp->fh);
  392. return nfserr;
  393. }
  394. /*
  395. * Read a portion of a directory.
  396. */
  397. static __be32
  398. nfsd_proc_readdir(struct svc_rqst *rqstp, struct nfsd_readdirargs *argp,
  399. struct nfsd_readdirres *resp)
  400. {
  401. int count;
  402. __be32 nfserr;
  403. loff_t offset;
  404. dprintk("nfsd: READDIR %s %d bytes at %d\n",
  405. SVCFH_fmt(&argp->fh),
  406. argp->count, argp->cookie);
  407. /* Shrink to the client read size */
  408. count = (argp->count >> 2) - 2;
  409. /* Make sure we've room for the NULL ptr & eof flag */
  410. count -= 2;
  411. if (count < 0)
  412. count = 0;
  413. resp->buffer = argp->buffer;
  414. resp->offset = NULL;
  415. resp->buflen = count;
  416. resp->common.err = nfs_ok;
  417. /* Read directory and encode entries on the fly */
  418. offset = argp->cookie;
  419. nfserr = nfsd_readdir(rqstp, &argp->fh, &offset,
  420. &resp->common, nfssvc_encode_entry);
  421. resp->count = resp->buffer - argp->buffer;
  422. if (resp->offset)
  423. *resp->offset = htonl(offset);
  424. fh_put(&argp->fh);
  425. return nfserr;
  426. }
  427. /*
  428. * Get file system info
  429. */
  430. static __be32
  431. nfsd_proc_statfs(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
  432. struct nfsd_statfsres *resp)
  433. {
  434. __be32 nfserr;
  435. dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
  436. nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
  437. NFSD_MAY_BYPASS_GSS_ON_ROOT);
  438. fh_put(&argp->fh);
  439. return nfserr;
  440. }
  441. /*
  442. * NFSv2 Server procedures.
  443. * Only the results of non-idempotent operations are cached.
  444. */
  445. struct nfsd_void { int dummy; };
  446. #define ST 1 /* status */
  447. #define FH 8 /* filehandle */
  448. #define AT 18 /* attributes */
  449. static struct svc_procedure nfsd_procedures2[18] = {
  450. [NFSPROC_NULL] = {
  451. .pc_func = (svc_procfunc) nfsd_proc_null,
  452. .pc_decode = (kxdrproc_t) nfssvc_decode_void,
  453. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  454. .pc_argsize = sizeof(struct nfsd_void),
  455. .pc_ressize = sizeof(struct nfsd_void),
  456. .pc_cachetype = RC_NOCACHE,
  457. .pc_xdrressize = ST,
  458. },
  459. [NFSPROC_GETATTR] = {
  460. .pc_func = (svc_procfunc) nfsd_proc_getattr,
  461. .pc_decode = (kxdrproc_t) nfssvc_decode_fhandle,
  462. .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
  463. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  464. .pc_argsize = sizeof(struct nfsd_fhandle),
  465. .pc_ressize = sizeof(struct nfsd_attrstat),
  466. .pc_cachetype = RC_NOCACHE,
  467. .pc_xdrressize = ST+AT,
  468. },
  469. [NFSPROC_SETATTR] = {
  470. .pc_func = (svc_procfunc) nfsd_proc_setattr,
  471. .pc_decode = (kxdrproc_t) nfssvc_decode_sattrargs,
  472. .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
  473. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  474. .pc_argsize = sizeof(struct nfsd_sattrargs),
  475. .pc_ressize = sizeof(struct nfsd_attrstat),
  476. .pc_cachetype = RC_REPLBUFF,
  477. .pc_xdrressize = ST+AT,
  478. },
  479. [NFSPROC_ROOT] = {
  480. .pc_decode = (kxdrproc_t) nfssvc_decode_void,
  481. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  482. .pc_argsize = sizeof(struct nfsd_void),
  483. .pc_ressize = sizeof(struct nfsd_void),
  484. .pc_cachetype = RC_NOCACHE,
  485. .pc_xdrressize = ST,
  486. },
  487. [NFSPROC_LOOKUP] = {
  488. .pc_func = (svc_procfunc) nfsd_proc_lookup,
  489. .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs,
  490. .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
  491. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  492. .pc_argsize = sizeof(struct nfsd_diropargs),
  493. .pc_ressize = sizeof(struct nfsd_diropres),
  494. .pc_cachetype = RC_NOCACHE,
  495. .pc_xdrressize = ST+FH+AT,
  496. },
  497. [NFSPROC_READLINK] = {
  498. .pc_func = (svc_procfunc) nfsd_proc_readlink,
  499. .pc_decode = (kxdrproc_t) nfssvc_decode_readlinkargs,
  500. .pc_encode = (kxdrproc_t) nfssvc_encode_readlinkres,
  501. .pc_argsize = sizeof(struct nfsd_readlinkargs),
  502. .pc_ressize = sizeof(struct nfsd_readlinkres),
  503. .pc_cachetype = RC_NOCACHE,
  504. .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4,
  505. },
  506. [NFSPROC_READ] = {
  507. .pc_func = (svc_procfunc) nfsd_proc_read,
  508. .pc_decode = (kxdrproc_t) nfssvc_decode_readargs,
  509. .pc_encode = (kxdrproc_t) nfssvc_encode_readres,
  510. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  511. .pc_argsize = sizeof(struct nfsd_readargs),
  512. .pc_ressize = sizeof(struct nfsd_readres),
  513. .pc_cachetype = RC_NOCACHE,
  514. .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4,
  515. },
  516. [NFSPROC_WRITECACHE] = {
  517. .pc_decode = (kxdrproc_t) nfssvc_decode_void,
  518. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  519. .pc_argsize = sizeof(struct nfsd_void),
  520. .pc_ressize = sizeof(struct nfsd_void),
  521. .pc_cachetype = RC_NOCACHE,
  522. .pc_xdrressize = ST,
  523. },
  524. [NFSPROC_WRITE] = {
  525. .pc_func = (svc_procfunc) nfsd_proc_write,
  526. .pc_decode = (kxdrproc_t) nfssvc_decode_writeargs,
  527. .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
  528. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  529. .pc_argsize = sizeof(struct nfsd_writeargs),
  530. .pc_ressize = sizeof(struct nfsd_attrstat),
  531. .pc_cachetype = RC_REPLBUFF,
  532. .pc_xdrressize = ST+AT,
  533. },
  534. [NFSPROC_CREATE] = {
  535. .pc_func = (svc_procfunc) nfsd_proc_create,
  536. .pc_decode = (kxdrproc_t) nfssvc_decode_createargs,
  537. .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
  538. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  539. .pc_argsize = sizeof(struct nfsd_createargs),
  540. .pc_ressize = sizeof(struct nfsd_diropres),
  541. .pc_cachetype = RC_REPLBUFF,
  542. .pc_xdrressize = ST+FH+AT,
  543. },
  544. [NFSPROC_REMOVE] = {
  545. .pc_func = (svc_procfunc) nfsd_proc_remove,
  546. .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs,
  547. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  548. .pc_argsize = sizeof(struct nfsd_diropargs),
  549. .pc_ressize = sizeof(struct nfsd_void),
  550. .pc_cachetype = RC_REPLSTAT,
  551. .pc_xdrressize = ST,
  552. },
  553. [NFSPROC_RENAME] = {
  554. .pc_func = (svc_procfunc) nfsd_proc_rename,
  555. .pc_decode = (kxdrproc_t) nfssvc_decode_renameargs,
  556. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  557. .pc_argsize = sizeof(struct nfsd_renameargs),
  558. .pc_ressize = sizeof(struct nfsd_void),
  559. .pc_cachetype = RC_REPLSTAT,
  560. .pc_xdrressize = ST,
  561. },
  562. [NFSPROC_LINK] = {
  563. .pc_func = (svc_procfunc) nfsd_proc_link,
  564. .pc_decode = (kxdrproc_t) nfssvc_decode_linkargs,
  565. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  566. .pc_argsize = sizeof(struct nfsd_linkargs),
  567. .pc_ressize = sizeof(struct nfsd_void),
  568. .pc_cachetype = RC_REPLSTAT,
  569. .pc_xdrressize = ST,
  570. },
  571. [NFSPROC_SYMLINK] = {
  572. .pc_func = (svc_procfunc) nfsd_proc_symlink,
  573. .pc_decode = (kxdrproc_t) nfssvc_decode_symlinkargs,
  574. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  575. .pc_argsize = sizeof(struct nfsd_symlinkargs),
  576. .pc_ressize = sizeof(struct nfsd_void),
  577. .pc_cachetype = RC_REPLSTAT,
  578. .pc_xdrressize = ST,
  579. },
  580. [NFSPROC_MKDIR] = {
  581. .pc_func = (svc_procfunc) nfsd_proc_mkdir,
  582. .pc_decode = (kxdrproc_t) nfssvc_decode_createargs,
  583. .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
  584. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  585. .pc_argsize = sizeof(struct nfsd_createargs),
  586. .pc_ressize = sizeof(struct nfsd_diropres),
  587. .pc_cachetype = RC_REPLBUFF,
  588. .pc_xdrressize = ST+FH+AT,
  589. },
  590. [NFSPROC_RMDIR] = {
  591. .pc_func = (svc_procfunc) nfsd_proc_rmdir,
  592. .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs,
  593. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  594. .pc_argsize = sizeof(struct nfsd_diropargs),
  595. .pc_ressize = sizeof(struct nfsd_void),
  596. .pc_cachetype = RC_REPLSTAT,
  597. .pc_xdrressize = ST,
  598. },
  599. [NFSPROC_READDIR] = {
  600. .pc_func = (svc_procfunc) nfsd_proc_readdir,
  601. .pc_decode = (kxdrproc_t) nfssvc_decode_readdirargs,
  602. .pc_encode = (kxdrproc_t) nfssvc_encode_readdirres,
  603. .pc_argsize = sizeof(struct nfsd_readdirargs),
  604. .pc_ressize = sizeof(struct nfsd_readdirres),
  605. .pc_cachetype = RC_NOCACHE,
  606. },
  607. [NFSPROC_STATFS] = {
  608. .pc_func = (svc_procfunc) nfsd_proc_statfs,
  609. .pc_decode = (kxdrproc_t) nfssvc_decode_fhandle,
  610. .pc_encode = (kxdrproc_t) nfssvc_encode_statfsres,
  611. .pc_argsize = sizeof(struct nfsd_fhandle),
  612. .pc_ressize = sizeof(struct nfsd_statfsres),
  613. .pc_cachetype = RC_NOCACHE,
  614. .pc_xdrressize = ST+5,
  615. },
  616. };
  617. struct svc_version nfsd_version2 = {
  618. .vs_vers = 2,
  619. .vs_nproc = 18,
  620. .vs_proc = nfsd_procedures2,
  621. .vs_dispatch = nfsd_dispatch,
  622. .vs_xdrsize = NFS2_SVC_XDRSIZE,
  623. };
  624. /*
  625. * Map errnos to NFS errnos.
  626. */
  627. __be32
  628. nfserrno (int errno)
  629. {
  630. static struct {
  631. __be32 nfserr;
  632. int syserr;
  633. } nfs_errtbl[] = {
  634. { nfs_ok, 0 },
  635. { nfserr_perm, -EPERM },
  636. { nfserr_noent, -ENOENT },
  637. { nfserr_io, -EIO },
  638. { nfserr_nxio, -ENXIO },
  639. { nfserr_acces, -EACCES },
  640. { nfserr_exist, -EEXIST },
  641. { nfserr_xdev, -EXDEV },
  642. { nfserr_mlink, -EMLINK },
  643. { nfserr_nodev, -ENODEV },
  644. { nfserr_notdir, -ENOTDIR },
  645. { nfserr_isdir, -EISDIR },
  646. { nfserr_inval, -EINVAL },
  647. { nfserr_fbig, -EFBIG },
  648. { nfserr_nospc, -ENOSPC },
  649. { nfserr_rofs, -EROFS },
  650. { nfserr_mlink, -EMLINK },
  651. { nfserr_nametoolong, -ENAMETOOLONG },
  652. { nfserr_notempty, -ENOTEMPTY },
  653. #ifdef EDQUOT
  654. { nfserr_dquot, -EDQUOT },
  655. #endif
  656. { nfserr_stale, -ESTALE },
  657. { nfserr_jukebox, -ETIMEDOUT },
  658. { nfserr_jukebox, -ERESTARTSYS },
  659. { nfserr_jukebox, -EAGAIN },
  660. { nfserr_jukebox, -EWOULDBLOCK },
  661. { nfserr_jukebox, -ENOMEM },
  662. { nfserr_io, -ETXTBSY },
  663. { nfserr_notsupp, -EOPNOTSUPP },
  664. { nfserr_toosmall, -ETOOSMALL },
  665. { nfserr_serverfault, -ESERVERFAULT },
  666. };
  667. int i;
  668. for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
  669. if (nfs_errtbl[i].syserr == errno)
  670. return nfs_errtbl[i].nfserr;
  671. }
  672. printk (KERN_INFO "nfsd: non-standard errno: %d\n", errno);
  673. return nfserr_io;
  674. }