nfsproc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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. int hosterr;
  172. dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
  173. dprintk("nfsd: CREATE %s %.*s\n",
  174. SVCFH_fmt(dirfhp), argp->len, argp->name);
  175. /* First verify the parent file handle */
  176. nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC);
  177. if (nfserr)
  178. goto done; /* must fh_put dirfhp even on error */
  179. /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */
  180. nfserr = nfserr_acces;
  181. if (!argp->len)
  182. goto done;
  183. nfserr = nfserr_exist;
  184. if (isdotent(argp->name, argp->len))
  185. goto done;
  186. hosterr = fh_want_write(dirfhp);
  187. if (hosterr) {
  188. nfserr = nfserrno(hosterr);
  189. goto done;
  190. }
  191. fh_lock_nested(dirfhp, I_MUTEX_PARENT);
  192. dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
  193. if (IS_ERR(dchild)) {
  194. nfserr = nfserrno(PTR_ERR(dchild));
  195. goto out_unlock;
  196. }
  197. fh_init(newfhp, NFS_FHSIZE);
  198. nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
  199. if (!nfserr && !dchild->d_inode)
  200. nfserr = nfserr_noent;
  201. dput(dchild);
  202. if (nfserr) {
  203. if (nfserr != nfserr_noent)
  204. goto out_unlock;
  205. /*
  206. * If the new file handle wasn't verified, we can't tell
  207. * whether the file exists or not. Time to bail ...
  208. */
  209. nfserr = nfserr_acces;
  210. if (!newfhp->fh_dentry) {
  211. printk(KERN_WARNING
  212. "nfsd_proc_create: file handle not verified\n");
  213. goto out_unlock;
  214. }
  215. }
  216. inode = newfhp->fh_dentry->d_inode;
  217. /* Unfudge the mode bits */
  218. if (attr->ia_valid & ATTR_MODE) {
  219. type = attr->ia_mode & S_IFMT;
  220. mode = attr->ia_mode & ~S_IFMT;
  221. if (!type) {
  222. /* no type, so if target exists, assume same as that,
  223. * else assume a file */
  224. if (inode) {
  225. type = inode->i_mode & S_IFMT;
  226. switch(type) {
  227. case S_IFCHR:
  228. case S_IFBLK:
  229. /* reserve rdev for later checking */
  230. rdev = inode->i_rdev;
  231. attr->ia_valid |= ATTR_SIZE;
  232. /* FALLTHROUGH */
  233. case S_IFIFO:
  234. /* this is probably a permission check..
  235. * at least IRIX implements perm checking on
  236. * echo thing > device-special-file-or-pipe
  237. * by doing a CREATE with type==0
  238. */
  239. nfserr = nfsd_permission(rqstp,
  240. newfhp->fh_export,
  241. newfhp->fh_dentry,
  242. NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
  243. if (nfserr && nfserr != nfserr_rofs)
  244. goto out_unlock;
  245. }
  246. } else
  247. type = S_IFREG;
  248. }
  249. } else if (inode) {
  250. type = inode->i_mode & S_IFMT;
  251. mode = inode->i_mode & ~S_IFMT;
  252. } else {
  253. type = S_IFREG;
  254. mode = 0; /* ??? */
  255. }
  256. attr->ia_valid |= ATTR_MODE;
  257. attr->ia_mode = mode;
  258. /* Special treatment for non-regular files according to the
  259. * gospel of sun micro
  260. */
  261. if (type != S_IFREG) {
  262. if (type != S_IFBLK && type != S_IFCHR) {
  263. rdev = 0;
  264. } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
  265. /* If you think you've seen the worst, grok this. */
  266. type = S_IFIFO;
  267. } else {
  268. /* Okay, char or block special */
  269. if (!rdev)
  270. rdev = wanted;
  271. }
  272. /* we've used the SIZE information, so discard it */
  273. attr->ia_valid &= ~ATTR_SIZE;
  274. /* Make sure the type and device matches */
  275. nfserr = nfserr_exist;
  276. if (inode && type != (inode->i_mode & S_IFMT))
  277. goto out_unlock;
  278. }
  279. nfserr = 0;
  280. if (!inode) {
  281. /* File doesn't exist. Create it and set attrs */
  282. nfserr = nfsd_create(rqstp, dirfhp, argp->name, argp->len,
  283. attr, type, rdev, newfhp);
  284. } else if (type == S_IFREG) {
  285. dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
  286. argp->name, attr->ia_valid, (long) attr->ia_size);
  287. /* File already exists. We ignore all attributes except
  288. * size, so that creat() behaves exactly like
  289. * open(..., O_CREAT|O_TRUNC|O_WRONLY).
  290. */
  291. attr->ia_valid &= ATTR_SIZE;
  292. if (attr->ia_valid)
  293. nfserr = nfsd_setattr(rqstp, newfhp, attr, 0, (time_t)0);
  294. }
  295. out_unlock:
  296. /* We don't really need to unlock, as fh_put does it. */
  297. fh_unlock(dirfhp);
  298. fh_drop_write(dirfhp);
  299. done:
  300. fh_put(dirfhp);
  301. return nfsd_return_dirop(nfserr, resp);
  302. }
  303. static __be32
  304. nfsd_proc_remove(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
  305. void *resp)
  306. {
  307. __be32 nfserr;
  308. dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh),
  309. argp->len, argp->name);
  310. /* Unlink. -SIFDIR means file must not be a directory */
  311. nfserr = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR, argp->name, argp->len);
  312. fh_put(&argp->fh);
  313. return nfserr;
  314. }
  315. static __be32
  316. nfsd_proc_rename(struct svc_rqst *rqstp, struct nfsd_renameargs *argp,
  317. void *resp)
  318. {
  319. __be32 nfserr;
  320. dprintk("nfsd: RENAME %s %.*s -> \n",
  321. SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
  322. dprintk("nfsd: -> %s %.*s\n",
  323. SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname);
  324. nfserr = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
  325. &argp->tfh, argp->tname, argp->tlen);
  326. fh_put(&argp->ffh);
  327. fh_put(&argp->tfh);
  328. return nfserr;
  329. }
  330. static __be32
  331. nfsd_proc_link(struct svc_rqst *rqstp, struct nfsd_linkargs *argp,
  332. void *resp)
  333. {
  334. __be32 nfserr;
  335. dprintk("nfsd: LINK %s ->\n",
  336. SVCFH_fmt(&argp->ffh));
  337. dprintk("nfsd: %s %.*s\n",
  338. SVCFH_fmt(&argp->tfh),
  339. argp->tlen,
  340. argp->tname);
  341. nfserr = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
  342. &argp->ffh);
  343. fh_put(&argp->ffh);
  344. fh_put(&argp->tfh);
  345. return nfserr;
  346. }
  347. static __be32
  348. nfsd_proc_symlink(struct svc_rqst *rqstp, struct nfsd_symlinkargs *argp,
  349. void *resp)
  350. {
  351. struct svc_fh newfh;
  352. __be32 nfserr;
  353. dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n",
  354. SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
  355. argp->tlen, argp->tname);
  356. fh_init(&newfh, NFS_FHSIZE);
  357. /*
  358. * Create the link, look up new file and set attrs.
  359. */
  360. nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
  361. argp->tname, argp->tlen,
  362. &newfh, &argp->attrs);
  363. fh_put(&argp->ffh);
  364. fh_put(&newfh);
  365. return nfserr;
  366. }
  367. /*
  368. * Make directory. This operation is not idempotent.
  369. * N.B. After this call resp->fh needs an fh_put
  370. */
  371. static __be32
  372. nfsd_proc_mkdir(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
  373. struct nfsd_diropres *resp)
  374. {
  375. __be32 nfserr;
  376. dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  377. if (resp->fh.fh_dentry) {
  378. printk(KERN_WARNING
  379. "nfsd_proc_mkdir: response already verified??\n");
  380. }
  381. argp->attrs.ia_valid &= ~ATTR_SIZE;
  382. fh_init(&resp->fh, NFS_FHSIZE);
  383. nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
  384. &argp->attrs, S_IFDIR, 0, &resp->fh);
  385. fh_put(&argp->fh);
  386. return nfsd_return_dirop(nfserr, resp);
  387. }
  388. /*
  389. * Remove a directory
  390. */
  391. static __be32
  392. nfsd_proc_rmdir(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
  393. void *resp)
  394. {
  395. __be32 nfserr;
  396. dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  397. nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len);
  398. fh_put(&argp->fh);
  399. return nfserr;
  400. }
  401. /*
  402. * Read a portion of a directory.
  403. */
  404. static __be32
  405. nfsd_proc_readdir(struct svc_rqst *rqstp, struct nfsd_readdirargs *argp,
  406. struct nfsd_readdirres *resp)
  407. {
  408. int count;
  409. __be32 nfserr;
  410. loff_t offset;
  411. dprintk("nfsd: READDIR %s %d bytes at %d\n",
  412. SVCFH_fmt(&argp->fh),
  413. argp->count, argp->cookie);
  414. /* Shrink to the client read size */
  415. count = (argp->count >> 2) - 2;
  416. /* Make sure we've room for the NULL ptr & eof flag */
  417. count -= 2;
  418. if (count < 0)
  419. count = 0;
  420. resp->buffer = argp->buffer;
  421. resp->offset = NULL;
  422. resp->buflen = count;
  423. resp->common.err = nfs_ok;
  424. /* Read directory and encode entries on the fly */
  425. offset = argp->cookie;
  426. nfserr = nfsd_readdir(rqstp, &argp->fh, &offset,
  427. &resp->common, nfssvc_encode_entry);
  428. resp->count = resp->buffer - argp->buffer;
  429. if (resp->offset)
  430. *resp->offset = htonl(offset);
  431. fh_put(&argp->fh);
  432. return nfserr;
  433. }
  434. /*
  435. * Get file system info
  436. */
  437. static __be32
  438. nfsd_proc_statfs(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
  439. struct nfsd_statfsres *resp)
  440. {
  441. __be32 nfserr;
  442. dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
  443. nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
  444. NFSD_MAY_BYPASS_GSS_ON_ROOT);
  445. fh_put(&argp->fh);
  446. return nfserr;
  447. }
  448. /*
  449. * NFSv2 Server procedures.
  450. * Only the results of non-idempotent operations are cached.
  451. */
  452. struct nfsd_void { int dummy; };
  453. #define ST 1 /* status */
  454. #define FH 8 /* filehandle */
  455. #define AT 18 /* attributes */
  456. static struct svc_procedure nfsd_procedures2[18] = {
  457. [NFSPROC_NULL] = {
  458. .pc_func = (svc_procfunc) nfsd_proc_null,
  459. .pc_decode = (kxdrproc_t) nfssvc_decode_void,
  460. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  461. .pc_argsize = sizeof(struct nfsd_void),
  462. .pc_ressize = sizeof(struct nfsd_void),
  463. .pc_cachetype = RC_NOCACHE,
  464. .pc_xdrressize = ST,
  465. },
  466. [NFSPROC_GETATTR] = {
  467. .pc_func = (svc_procfunc) nfsd_proc_getattr,
  468. .pc_decode = (kxdrproc_t) nfssvc_decode_fhandle,
  469. .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
  470. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  471. .pc_argsize = sizeof(struct nfsd_fhandle),
  472. .pc_ressize = sizeof(struct nfsd_attrstat),
  473. .pc_cachetype = RC_NOCACHE,
  474. .pc_xdrressize = ST+AT,
  475. },
  476. [NFSPROC_SETATTR] = {
  477. .pc_func = (svc_procfunc) nfsd_proc_setattr,
  478. .pc_decode = (kxdrproc_t) nfssvc_decode_sattrargs,
  479. .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
  480. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  481. .pc_argsize = sizeof(struct nfsd_sattrargs),
  482. .pc_ressize = sizeof(struct nfsd_attrstat),
  483. .pc_cachetype = RC_REPLBUFF,
  484. .pc_xdrressize = ST+AT,
  485. },
  486. [NFSPROC_ROOT] = {
  487. .pc_decode = (kxdrproc_t) nfssvc_decode_void,
  488. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  489. .pc_argsize = sizeof(struct nfsd_void),
  490. .pc_ressize = sizeof(struct nfsd_void),
  491. .pc_cachetype = RC_NOCACHE,
  492. .pc_xdrressize = ST,
  493. },
  494. [NFSPROC_LOOKUP] = {
  495. .pc_func = (svc_procfunc) nfsd_proc_lookup,
  496. .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs,
  497. .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
  498. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  499. .pc_argsize = sizeof(struct nfsd_diropargs),
  500. .pc_ressize = sizeof(struct nfsd_diropres),
  501. .pc_cachetype = RC_NOCACHE,
  502. .pc_xdrressize = ST+FH+AT,
  503. },
  504. [NFSPROC_READLINK] = {
  505. .pc_func = (svc_procfunc) nfsd_proc_readlink,
  506. .pc_decode = (kxdrproc_t) nfssvc_decode_readlinkargs,
  507. .pc_encode = (kxdrproc_t) nfssvc_encode_readlinkres,
  508. .pc_argsize = sizeof(struct nfsd_readlinkargs),
  509. .pc_ressize = sizeof(struct nfsd_readlinkres),
  510. .pc_cachetype = RC_NOCACHE,
  511. .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4,
  512. },
  513. [NFSPROC_READ] = {
  514. .pc_func = (svc_procfunc) nfsd_proc_read,
  515. .pc_decode = (kxdrproc_t) nfssvc_decode_readargs,
  516. .pc_encode = (kxdrproc_t) nfssvc_encode_readres,
  517. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  518. .pc_argsize = sizeof(struct nfsd_readargs),
  519. .pc_ressize = sizeof(struct nfsd_readres),
  520. .pc_cachetype = RC_NOCACHE,
  521. .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4,
  522. },
  523. [NFSPROC_WRITECACHE] = {
  524. .pc_decode = (kxdrproc_t) nfssvc_decode_void,
  525. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  526. .pc_argsize = sizeof(struct nfsd_void),
  527. .pc_ressize = sizeof(struct nfsd_void),
  528. .pc_cachetype = RC_NOCACHE,
  529. .pc_xdrressize = ST,
  530. },
  531. [NFSPROC_WRITE] = {
  532. .pc_func = (svc_procfunc) nfsd_proc_write,
  533. .pc_decode = (kxdrproc_t) nfssvc_decode_writeargs,
  534. .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat,
  535. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  536. .pc_argsize = sizeof(struct nfsd_writeargs),
  537. .pc_ressize = sizeof(struct nfsd_attrstat),
  538. .pc_cachetype = RC_REPLBUFF,
  539. .pc_xdrressize = ST+AT,
  540. },
  541. [NFSPROC_CREATE] = {
  542. .pc_func = (svc_procfunc) nfsd_proc_create,
  543. .pc_decode = (kxdrproc_t) nfssvc_decode_createargs,
  544. .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
  545. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  546. .pc_argsize = sizeof(struct nfsd_createargs),
  547. .pc_ressize = sizeof(struct nfsd_diropres),
  548. .pc_cachetype = RC_REPLBUFF,
  549. .pc_xdrressize = ST+FH+AT,
  550. },
  551. [NFSPROC_REMOVE] = {
  552. .pc_func = (svc_procfunc) nfsd_proc_remove,
  553. .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs,
  554. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  555. .pc_argsize = sizeof(struct nfsd_diropargs),
  556. .pc_ressize = sizeof(struct nfsd_void),
  557. .pc_cachetype = RC_REPLSTAT,
  558. .pc_xdrressize = ST,
  559. },
  560. [NFSPROC_RENAME] = {
  561. .pc_func = (svc_procfunc) nfsd_proc_rename,
  562. .pc_decode = (kxdrproc_t) nfssvc_decode_renameargs,
  563. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  564. .pc_argsize = sizeof(struct nfsd_renameargs),
  565. .pc_ressize = sizeof(struct nfsd_void),
  566. .pc_cachetype = RC_REPLSTAT,
  567. .pc_xdrressize = ST,
  568. },
  569. [NFSPROC_LINK] = {
  570. .pc_func = (svc_procfunc) nfsd_proc_link,
  571. .pc_decode = (kxdrproc_t) nfssvc_decode_linkargs,
  572. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  573. .pc_argsize = sizeof(struct nfsd_linkargs),
  574. .pc_ressize = sizeof(struct nfsd_void),
  575. .pc_cachetype = RC_REPLSTAT,
  576. .pc_xdrressize = ST,
  577. },
  578. [NFSPROC_SYMLINK] = {
  579. .pc_func = (svc_procfunc) nfsd_proc_symlink,
  580. .pc_decode = (kxdrproc_t) nfssvc_decode_symlinkargs,
  581. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  582. .pc_argsize = sizeof(struct nfsd_symlinkargs),
  583. .pc_ressize = sizeof(struct nfsd_void),
  584. .pc_cachetype = RC_REPLSTAT,
  585. .pc_xdrressize = ST,
  586. },
  587. [NFSPROC_MKDIR] = {
  588. .pc_func = (svc_procfunc) nfsd_proc_mkdir,
  589. .pc_decode = (kxdrproc_t) nfssvc_decode_createargs,
  590. .pc_encode = (kxdrproc_t) nfssvc_encode_diropres,
  591. .pc_release = (kxdrproc_t) nfssvc_release_fhandle,
  592. .pc_argsize = sizeof(struct nfsd_createargs),
  593. .pc_ressize = sizeof(struct nfsd_diropres),
  594. .pc_cachetype = RC_REPLBUFF,
  595. .pc_xdrressize = ST+FH+AT,
  596. },
  597. [NFSPROC_RMDIR] = {
  598. .pc_func = (svc_procfunc) nfsd_proc_rmdir,
  599. .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs,
  600. .pc_encode = (kxdrproc_t) nfssvc_encode_void,
  601. .pc_argsize = sizeof(struct nfsd_diropargs),
  602. .pc_ressize = sizeof(struct nfsd_void),
  603. .pc_cachetype = RC_REPLSTAT,
  604. .pc_xdrressize = ST,
  605. },
  606. [NFSPROC_READDIR] = {
  607. .pc_func = (svc_procfunc) nfsd_proc_readdir,
  608. .pc_decode = (kxdrproc_t) nfssvc_decode_readdirargs,
  609. .pc_encode = (kxdrproc_t) nfssvc_encode_readdirres,
  610. .pc_argsize = sizeof(struct nfsd_readdirargs),
  611. .pc_ressize = sizeof(struct nfsd_readdirres),
  612. .pc_cachetype = RC_NOCACHE,
  613. },
  614. [NFSPROC_STATFS] = {
  615. .pc_func = (svc_procfunc) nfsd_proc_statfs,
  616. .pc_decode = (kxdrproc_t) nfssvc_decode_fhandle,
  617. .pc_encode = (kxdrproc_t) nfssvc_encode_statfsres,
  618. .pc_argsize = sizeof(struct nfsd_fhandle),
  619. .pc_ressize = sizeof(struct nfsd_statfsres),
  620. .pc_cachetype = RC_NOCACHE,
  621. .pc_xdrressize = ST+5,
  622. },
  623. };
  624. struct svc_version nfsd_version2 = {
  625. .vs_vers = 2,
  626. .vs_nproc = 18,
  627. .vs_proc = nfsd_procedures2,
  628. .vs_dispatch = nfsd_dispatch,
  629. .vs_xdrsize = NFS2_SVC_XDRSIZE,
  630. };
  631. /*
  632. * Map errnos to NFS errnos.
  633. */
  634. __be32
  635. nfserrno (int errno)
  636. {
  637. static struct {
  638. __be32 nfserr;
  639. int syserr;
  640. } nfs_errtbl[] = {
  641. { nfs_ok, 0 },
  642. { nfserr_perm, -EPERM },
  643. { nfserr_noent, -ENOENT },
  644. { nfserr_io, -EIO },
  645. { nfserr_nxio, -ENXIO },
  646. { nfserr_acces, -EACCES },
  647. { nfserr_exist, -EEXIST },
  648. { nfserr_xdev, -EXDEV },
  649. { nfserr_mlink, -EMLINK },
  650. { nfserr_nodev, -ENODEV },
  651. { nfserr_notdir, -ENOTDIR },
  652. { nfserr_isdir, -EISDIR },
  653. { nfserr_inval, -EINVAL },
  654. { nfserr_fbig, -EFBIG },
  655. { nfserr_nospc, -ENOSPC },
  656. { nfserr_rofs, -EROFS },
  657. { nfserr_mlink, -EMLINK },
  658. { nfserr_nametoolong, -ENAMETOOLONG },
  659. { nfserr_notempty, -ENOTEMPTY },
  660. #ifdef EDQUOT
  661. { nfserr_dquot, -EDQUOT },
  662. #endif
  663. { nfserr_stale, -ESTALE },
  664. { nfserr_jukebox, -ETIMEDOUT },
  665. { nfserr_jukebox, -ERESTARTSYS },
  666. { nfserr_jukebox, -EAGAIN },
  667. { nfserr_jukebox, -EWOULDBLOCK },
  668. { nfserr_jukebox, -ENOMEM },
  669. { nfserr_io, -ETXTBSY },
  670. { nfserr_notsupp, -EOPNOTSUPP },
  671. { nfserr_toosmall, -ETOOSMALL },
  672. { nfserr_serverfault, -ESERVERFAULT },
  673. };
  674. int i;
  675. for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
  676. if (nfs_errtbl[i].syserr == errno)
  677. return nfs_errtbl[i].nfserr;
  678. }
  679. printk (KERN_INFO "nfsd: non-standard errno: %d\n", errno);
  680. return nfserr_io;
  681. }