nfsproc.c 22 KB

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