nfsproc.c 20 KB

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