nfsproc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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/svc.h>
  21. #include <linux/nfsd/nfsd.h>
  22. #include <linux/nfsd/cache.h>
  23. #include <linux/nfsd/xdr.h>
  24. typedef struct svc_rqst svc_rqst;
  25. typedef struct svc_buf svc_buf;
  26. #define NFSDDBG_FACILITY NFSDDBG_PROC
  27. static __be32
  28. nfsd_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
  29. {
  30. return nfs_ok;
  31. }
  32. static __be32
  33. nfsd_return_attrs(__be32 err, struct nfsd_attrstat *resp)
  34. {
  35. if (err) return err;
  36. return nfserrno(vfs_getattr(resp->fh.fh_export->ex_mnt,
  37. resp->fh.fh_dentry,
  38. &resp->stat));
  39. }
  40. static __be32
  41. nfsd_return_dirop(__be32 err, struct nfsd_diropres *resp)
  42. {
  43. if (err) return err;
  44. return nfserrno(vfs_getattr(resp->fh.fh_export->ex_mnt,
  45. resp->fh.fh_dentry,
  46. &resp->stat));
  47. }
  48. /*
  49. * Get a file's attributes
  50. * N.B. After this call resp->fh needs an fh_put
  51. */
  52. static __be32
  53. nfsd_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle *argp,
  54. struct nfsd_attrstat *resp)
  55. {
  56. __be32 nfserr;
  57. dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
  58. fh_copy(&resp->fh, &argp->fh);
  59. nfserr = fh_verify(rqstp, &resp->fh, 0, MAY_NOP);
  60. return nfsd_return_attrs(nfserr, resp);
  61. }
  62. /*
  63. * Set a file's attributes
  64. * N.B. After this call resp->fh needs an fh_put
  65. */
  66. static __be32
  67. nfsd_proc_setattr(struct svc_rqst *rqstp, struct nfsd_sattrargs *argp,
  68. struct nfsd_attrstat *resp)
  69. {
  70. __be32 nfserr;
  71. dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n",
  72. SVCFH_fmt(&argp->fh),
  73. argp->attrs.ia_valid, (long) argp->attrs.ia_size);
  74. fh_copy(&resp->fh, &argp->fh);
  75. nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,0, (time_t)0);
  76. return nfsd_return_attrs(nfserr, resp);
  77. }
  78. /*
  79. * Look up a path name component
  80. * Note: the dentry in the resp->fh may be negative if the file
  81. * doesn't exist yet.
  82. * N.B. After this call resp->fh needs an fh_put
  83. */
  84. static __be32
  85. nfsd_proc_lookup(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
  86. struct nfsd_diropres *resp)
  87. {
  88. __be32 nfserr;
  89. dprintk("nfsd: LOOKUP %s %.*s\n",
  90. SVCFH_fmt(&argp->fh), argp->len, argp->name);
  91. fh_init(&resp->fh, NFS_FHSIZE);
  92. nfserr = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len,
  93. &resp->fh);
  94. fh_put(&argp->fh);
  95. return nfsd_return_dirop(nfserr, resp);
  96. }
  97. /*
  98. * Read a symlink.
  99. */
  100. static __be32
  101. nfsd_proc_readlink(struct svc_rqst *rqstp, struct nfsd_readlinkargs *argp,
  102. struct nfsd_readlinkres *resp)
  103. {
  104. __be32 nfserr;
  105. dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh));
  106. /* Read the symlink. */
  107. resp->len = NFS_MAXPATHLEN;
  108. nfserr = nfsd_readlink(rqstp, &argp->fh, argp->buffer, &resp->len);
  109. fh_put(&argp->fh);
  110. return nfserr;
  111. }
  112. /*
  113. * Read a portion of a file.
  114. * N.B. After this call resp->fh needs an fh_put
  115. */
  116. static __be32
  117. nfsd_proc_read(struct svc_rqst *rqstp, struct nfsd_readargs *argp,
  118. struct nfsd_readres *resp)
  119. {
  120. __be32 nfserr;
  121. dprintk("nfsd: READ %s %d bytes at %d\n",
  122. SVCFH_fmt(&argp->fh),
  123. argp->count, argp->offset);
  124. /* Obtain buffer pointer for payload. 19 is 1 word for
  125. * status, 17 words for fattr, and 1 word for the byte count.
  126. */
  127. if (NFSSVC_MAXBLKSIZE_V2 < argp->count) {
  128. printk(KERN_NOTICE
  129. "oversized read request from %u.%u.%u.%u:%d (%d bytes)\n",
  130. NIPQUAD(rqstp->rq_addr.sin_addr.s_addr),
  131. ntohs(rqstp->rq_addr.sin_port),
  132. argp->count);
  133. argp->count = NFSSVC_MAXBLKSIZE_V2;
  134. }
  135. svc_reserve(rqstp, (19<<2) + argp->count + 4);
  136. resp->count = argp->count;
  137. nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
  138. argp->offset,
  139. rqstp->rq_vec, argp->vlen,
  140. &resp->count);
  141. if (nfserr) return nfserr;
  142. return nfserrno(vfs_getattr(resp->fh.fh_export->ex_mnt,
  143. resp->fh.fh_dentry,
  144. &resp->stat));
  145. }
  146. /*
  147. * Write data to a file
  148. * N.B. After this call resp->fh needs an fh_put
  149. */
  150. static __be32
  151. nfsd_proc_write(struct svc_rqst *rqstp, struct nfsd_writeargs *argp,
  152. struct nfsd_attrstat *resp)
  153. {
  154. __be32 nfserr;
  155. int stable = 1;
  156. dprintk("nfsd: WRITE %s %d bytes at %d\n",
  157. SVCFH_fmt(&argp->fh),
  158. argp->len, argp->offset);
  159. nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
  160. argp->offset,
  161. rqstp->rq_vec, argp->vlen,
  162. argp->len,
  163. &stable);
  164. return nfsd_return_attrs(nfserr, resp);
  165. }
  166. /*
  167. * CREATE processing is complicated. The keyword here is `overloaded.'
  168. * The parent directory is kept locked between the check for existence
  169. * and the actual create() call in compliance with VFS protocols.
  170. * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
  171. */
  172. static __be32
  173. nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
  174. struct nfsd_diropres *resp)
  175. {
  176. svc_fh *dirfhp = &argp->fh;
  177. svc_fh *newfhp = &resp->fh;
  178. struct iattr *attr = &argp->attrs;
  179. struct inode *inode;
  180. struct dentry *dchild;
  181. int type, mode;
  182. __be32 nfserr;
  183. dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
  184. dprintk("nfsd: CREATE %s %.*s\n",
  185. SVCFH_fmt(dirfhp), argp->len, argp->name);
  186. /* First verify the parent file handle */
  187. nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, MAY_EXEC);
  188. if (nfserr)
  189. goto done; /* must fh_put dirfhp even on error */
  190. /* Check for MAY_WRITE in nfsd_create if necessary */
  191. nfserr = nfserr_acces;
  192. if (!argp->len)
  193. goto done;
  194. nfserr = nfserr_exist;
  195. if (isdotent(argp->name, argp->len))
  196. goto done;
  197. fh_lock_nested(dirfhp, I_MUTEX_PARENT);
  198. dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
  199. if (IS_ERR(dchild)) {
  200. nfserr = nfserrno(PTR_ERR(dchild));
  201. goto out_unlock;
  202. }
  203. fh_init(newfhp, NFS_FHSIZE);
  204. nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
  205. if (!nfserr && !dchild->d_inode)
  206. nfserr = nfserr_noent;
  207. dput(dchild);
  208. if (nfserr) {
  209. if (nfserr != nfserr_noent)
  210. goto out_unlock;
  211. /*
  212. * If the new file handle wasn't verified, we can't tell
  213. * whether the file exists or not. Time to bail ...
  214. */
  215. nfserr = nfserr_acces;
  216. if (!newfhp->fh_dentry) {
  217. printk(KERN_WARNING
  218. "nfsd_proc_create: file handle not verified\n");
  219. goto out_unlock;
  220. }
  221. }
  222. inode = newfhp->fh_dentry->d_inode;
  223. /* Unfudge the mode bits */
  224. if (attr->ia_valid & ATTR_MODE) {
  225. type = attr->ia_mode & S_IFMT;
  226. mode = attr->ia_mode & ~S_IFMT;
  227. if (!type) {
  228. /* no type, so if target exists, assume same as that,
  229. * else assume a file */
  230. if (inode) {
  231. type = inode->i_mode & S_IFMT;
  232. switch(type) {
  233. case S_IFCHR:
  234. case S_IFBLK:
  235. /* reserve rdev for later checking */
  236. rdev = inode->i_rdev;
  237. attr->ia_valid |= ATTR_SIZE;
  238. /* FALLTHROUGH */
  239. case S_IFIFO:
  240. /* this is probably a permission check..
  241. * at least IRIX implements perm checking on
  242. * echo thing > device-special-file-or-pipe
  243. * by doing a CREATE with type==0
  244. */
  245. nfserr = nfsd_permission(newfhp->fh_export,
  246. newfhp->fh_dentry,
  247. MAY_WRITE|MAY_LOCAL_ACCESS);
  248. if (nfserr && nfserr != nfserr_rofs)
  249. goto out_unlock;
  250. }
  251. } else
  252. type = S_IFREG;
  253. }
  254. } else if (inode) {
  255. type = inode->i_mode & S_IFMT;
  256. mode = inode->i_mode & ~S_IFMT;
  257. } else {
  258. type = S_IFREG;
  259. mode = 0; /* ??? */
  260. }
  261. attr->ia_valid |= ATTR_MODE;
  262. attr->ia_mode = mode;
  263. /* Special treatment for non-regular files according to the
  264. * gospel of sun micro
  265. */
  266. if (type != S_IFREG) {
  267. int is_borc = 0;
  268. if (type != S_IFBLK && type != S_IFCHR) {
  269. rdev = 0;
  270. } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
  271. /* If you think you've seen the worst, grok this. */
  272. type = S_IFIFO;
  273. } else {
  274. /* Okay, char or block special */
  275. is_borc = 1;
  276. if (!rdev)
  277. rdev = wanted;
  278. }
  279. /* we've used the SIZE information, so discard it */
  280. attr->ia_valid &= ~ATTR_SIZE;
  281. /* Make sure the type and device matches */
  282. nfserr = nfserr_exist;
  283. if (inode && type != (inode->i_mode & S_IFMT))
  284. goto out_unlock;
  285. }
  286. nfserr = 0;
  287. if (!inode) {
  288. /* File doesn't exist. Create it and set attrs */
  289. nfserr = nfsd_create(rqstp, dirfhp, argp->name, argp->len,
  290. attr, type, rdev, newfhp);
  291. } else if (type == S_IFREG) {
  292. dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
  293. argp->name, attr->ia_valid, (long) attr->ia_size);
  294. /* File already exists. We ignore all attributes except
  295. * size, so that creat() behaves exactly like
  296. * open(..., O_CREAT|O_TRUNC|O_WRONLY).
  297. */
  298. attr->ia_valid &= ATTR_SIZE;
  299. if (attr->ia_valid)
  300. nfserr = nfsd_setattr(rqstp, newfhp, attr, 0, (time_t)0);
  301. }
  302. out_unlock:
  303. /* We don't really need to unlock, as fh_put does it. */
  304. fh_unlock(dirfhp);
  305. done:
  306. fh_put(dirfhp);
  307. return nfsd_return_dirop(nfserr, resp);
  308. }
  309. static __be32
  310. nfsd_proc_remove(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
  311. void *resp)
  312. {
  313. __be32 nfserr;
  314. dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh),
  315. argp->len, argp->name);
  316. /* Unlink. -SIFDIR means file must not be a directory */
  317. nfserr = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR, argp->name, argp->len);
  318. fh_put(&argp->fh);
  319. return nfserr;
  320. }
  321. static __be32
  322. nfsd_proc_rename(struct svc_rqst *rqstp, struct nfsd_renameargs *argp,
  323. void *resp)
  324. {
  325. __be32 nfserr;
  326. dprintk("nfsd: RENAME %s %.*s -> \n",
  327. SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
  328. dprintk("nfsd: -> %s %.*s\n",
  329. SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname);
  330. nfserr = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
  331. &argp->tfh, argp->tname, argp->tlen);
  332. fh_put(&argp->ffh);
  333. fh_put(&argp->tfh);
  334. return nfserr;
  335. }
  336. static __be32
  337. nfsd_proc_link(struct svc_rqst *rqstp, struct nfsd_linkargs *argp,
  338. void *resp)
  339. {
  340. __be32 nfserr;
  341. dprintk("nfsd: LINK %s ->\n",
  342. SVCFH_fmt(&argp->ffh));
  343. dprintk("nfsd: %s %.*s\n",
  344. SVCFH_fmt(&argp->tfh),
  345. argp->tlen,
  346. argp->tname);
  347. nfserr = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
  348. &argp->ffh);
  349. fh_put(&argp->ffh);
  350. fh_put(&argp->tfh);
  351. return nfserr;
  352. }
  353. static __be32
  354. nfsd_proc_symlink(struct svc_rqst *rqstp, struct nfsd_symlinkargs *argp,
  355. void *resp)
  356. {
  357. struct svc_fh newfh;
  358. __be32 nfserr;
  359. dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n",
  360. SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
  361. argp->tlen, argp->tname);
  362. fh_init(&newfh, NFS_FHSIZE);
  363. /*
  364. * Create the link, look up new file and set attrs.
  365. */
  366. nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
  367. argp->tname, argp->tlen,
  368. &newfh, &argp->attrs);
  369. fh_put(&argp->ffh);
  370. fh_put(&newfh);
  371. return nfserr;
  372. }
  373. /*
  374. * Make directory. This operation is not idempotent.
  375. * N.B. After this call resp->fh needs an fh_put
  376. */
  377. static __be32
  378. nfsd_proc_mkdir(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
  379. struct nfsd_diropres *resp)
  380. {
  381. __be32 nfserr;
  382. dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  383. if (resp->fh.fh_dentry) {
  384. printk(KERN_WARNING
  385. "nfsd_proc_mkdir: response already verified??\n");
  386. }
  387. argp->attrs.ia_valid &= ~ATTR_SIZE;
  388. fh_init(&resp->fh, NFS_FHSIZE);
  389. nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
  390. &argp->attrs, S_IFDIR, 0, &resp->fh);
  391. fh_put(&argp->fh);
  392. return nfsd_return_dirop(nfserr, resp);
  393. }
  394. /*
  395. * Remove a directory
  396. */
  397. static __be32
  398. nfsd_proc_rmdir(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
  399. void *resp)
  400. {
  401. __be32 nfserr;
  402. dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  403. nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len);
  404. fh_put(&argp->fh);
  405. return nfserr;
  406. }
  407. /*
  408. * Read a portion of a directory.
  409. */
  410. static __be32
  411. nfsd_proc_readdir(struct svc_rqst *rqstp, struct nfsd_readdirargs *argp,
  412. struct nfsd_readdirres *resp)
  413. {
  414. int count;
  415. __be32 nfserr;
  416. loff_t offset;
  417. dprintk("nfsd: READDIR %s %d bytes at %d\n",
  418. SVCFH_fmt(&argp->fh),
  419. argp->count, argp->cookie);
  420. /* Shrink to the client read size */
  421. count = (argp->count >> 2) - 2;
  422. /* Make sure we've room for the NULL ptr & eof flag */
  423. count -= 2;
  424. if (count < 0)
  425. count = 0;
  426. resp->buffer = argp->buffer;
  427. resp->offset = NULL;
  428. resp->buflen = count;
  429. resp->common.err = nfs_ok;
  430. /* Read directory and encode entries on the fly */
  431. offset = argp->cookie;
  432. nfserr = nfsd_readdir(rqstp, &argp->fh, &offset,
  433. &resp->common, nfssvc_encode_entry);
  434. resp->count = resp->buffer - argp->buffer;
  435. if (resp->offset)
  436. *resp->offset = htonl(offset);
  437. fh_put(&argp->fh);
  438. return nfserr;
  439. }
  440. /*
  441. * Get file system info
  442. */
  443. static __be32
  444. nfsd_proc_statfs(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
  445. struct nfsd_statfsres *resp)
  446. {
  447. __be32 nfserr;
  448. dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
  449. nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats);
  450. fh_put(&argp->fh);
  451. return nfserr;
  452. }
  453. /*
  454. * NFSv2 Server procedures.
  455. * Only the results of non-idempotent operations are cached.
  456. */
  457. #define nfsd_proc_none NULL
  458. #define nfssvc_release_none NULL
  459. struct nfsd_void { int dummy; };
  460. #define PROC(name, argt, rest, relt, cache, respsize) \
  461. { (svc_procfunc) nfsd_proc_##name, \
  462. (kxdrproc_t) nfssvc_decode_##argt, \
  463. (kxdrproc_t) nfssvc_encode_##rest, \
  464. (kxdrproc_t) nfssvc_release_##relt, \
  465. sizeof(struct nfsd_##argt), \
  466. sizeof(struct nfsd_##rest), \
  467. 0, \
  468. cache, \
  469. respsize, \
  470. }
  471. #define ST 1 /* status */
  472. #define FH 8 /* filehandle */
  473. #define AT 18 /* attributes */
  474. static struct svc_procedure nfsd_procedures2[18] = {
  475. PROC(null, void, void, none, RC_NOCACHE, ST),
  476. PROC(getattr, fhandle, attrstat, fhandle, RC_NOCACHE, ST+AT),
  477. PROC(setattr, sattrargs, attrstat, fhandle, RC_REPLBUFF, ST+AT),
  478. PROC(none, void, void, none, RC_NOCACHE, ST),
  479. PROC(lookup, diropargs, diropres, fhandle, RC_NOCACHE, ST+FH+AT),
  480. PROC(readlink, readlinkargs, readlinkres, none, RC_NOCACHE, ST+1+NFS_MAXPATHLEN/4),
  481. PROC(read, readargs, readres, fhandle, RC_NOCACHE, ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4),
  482. PROC(none, void, void, none, RC_NOCACHE, ST),
  483. PROC(write, writeargs, attrstat, fhandle, RC_REPLBUFF, ST+AT),
  484. PROC(create, createargs, diropres, fhandle, RC_REPLBUFF, ST+FH+AT),
  485. PROC(remove, diropargs, void, none, RC_REPLSTAT, ST),
  486. PROC(rename, renameargs, void, none, RC_REPLSTAT, ST),
  487. PROC(link, linkargs, void, none, RC_REPLSTAT, ST),
  488. PROC(symlink, symlinkargs, void, none, RC_REPLSTAT, ST),
  489. PROC(mkdir, createargs, diropres, fhandle, RC_REPLBUFF, ST+FH+AT),
  490. PROC(rmdir, diropargs, void, none, RC_REPLSTAT, ST),
  491. PROC(readdir, readdirargs, readdirres, none, RC_NOCACHE, 0),
  492. PROC(statfs, fhandle, statfsres, none, RC_NOCACHE, ST+5),
  493. };
  494. struct svc_version nfsd_version2 = {
  495. .vs_vers = 2,
  496. .vs_nproc = 18,
  497. .vs_proc = nfsd_procedures2,
  498. .vs_dispatch = nfsd_dispatch,
  499. .vs_xdrsize = NFS2_SVC_XDRSIZE,
  500. };
  501. /*
  502. * Map errnos to NFS errnos.
  503. */
  504. __be32
  505. nfserrno (int errno)
  506. {
  507. static struct {
  508. __be32 nfserr;
  509. int syserr;
  510. } nfs_errtbl[] = {
  511. { nfs_ok, 0 },
  512. { nfserr_perm, -EPERM },
  513. { nfserr_noent, -ENOENT },
  514. { nfserr_io, -EIO },
  515. { nfserr_nxio, -ENXIO },
  516. { nfserr_acces, -EACCES },
  517. { nfserr_exist, -EEXIST },
  518. { nfserr_xdev, -EXDEV },
  519. { nfserr_mlink, -EMLINK },
  520. { nfserr_nodev, -ENODEV },
  521. { nfserr_notdir, -ENOTDIR },
  522. { nfserr_isdir, -EISDIR },
  523. { nfserr_inval, -EINVAL },
  524. { nfserr_fbig, -EFBIG },
  525. { nfserr_nospc, -ENOSPC },
  526. { nfserr_rofs, -EROFS },
  527. { nfserr_mlink, -EMLINK },
  528. { nfserr_nametoolong, -ENAMETOOLONG },
  529. { nfserr_notempty, -ENOTEMPTY },
  530. #ifdef EDQUOT
  531. { nfserr_dquot, -EDQUOT },
  532. #endif
  533. { nfserr_stale, -ESTALE },
  534. { nfserr_jukebox, -ETIMEDOUT },
  535. { nfserr_dropit, -EAGAIN },
  536. { nfserr_dropit, -ENOMEM },
  537. { nfserr_badname, -ESRCH },
  538. { nfserr_io, -ETXTBSY },
  539. { nfserr_notsupp, -EOPNOTSUPP },
  540. };
  541. int i;
  542. for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
  543. if (nfs_errtbl[i].syserr == errno)
  544. return nfs_errtbl[i].nfserr;
  545. }
  546. printk (KERN_INFO "nfsd: non-standard errno: %d\n", errno);
  547. return nfserr_io;
  548. }