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