nfsproc.c 21 KB

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