nfsproc.c 22 KB

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