nfsproc.c 20 KB

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