]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 | 2 | /* |
1da177e4 LT |
3 | * Process version 2 NFS requests. |
4 | * | |
5 | * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de> | |
6 | */ | |
7 | ||
1da177e4 | 8 | #include <linux/namei.h> |
1da177e4 | 9 | |
9a74af21 BH |
10 | #include "cache.h" |
11 | #include "xdr.h" | |
0a3adade | 12 | #include "vfs.h" |
1da177e4 | 13 | |
1da177e4 LT |
14 | #define NFSDDBG_FACILITY NFSDDBG_PROC |
15 | ||
16 | ||
7111c66e | 17 | static __be32 |
a6beb732 | 18 | nfsd_proc_null(struct svc_rqst *rqstp) |
1da177e4 LT |
19 | { |
20 | return nfs_ok; | |
21 | } | |
22 | ||
c4d987ba AV |
23 | static __be32 |
24 | nfsd_return_attrs(__be32 err, struct nfsd_attrstat *resp) | |
846f2fcd DS |
25 | { |
26 | if (err) return err; | |
3dadecce | 27 | return fh_getattr(&resp->fh, &resp->stat); |
846f2fcd | 28 | } |
c4d987ba AV |
29 | static __be32 |
30 | nfsd_return_dirop(__be32 err, struct nfsd_diropres *resp) | |
846f2fcd DS |
31 | { |
32 | if (err) return err; | |
3dadecce | 33 | return fh_getattr(&resp->fh, &resp->stat); |
846f2fcd | 34 | } |
1da177e4 LT |
35 | /* |
36 | * Get a file's attributes | |
37 | * N.B. After this call resp->fh needs an fh_put | |
38 | */ | |
7111c66e | 39 | static __be32 |
a6beb732 | 40 | nfsd_proc_getattr(struct svc_rqst *rqstp) |
1da177e4 | 41 | { |
a6beb732 CH |
42 | struct nfsd_fhandle *argp = rqstp->rq_argp; |
43 | struct nfsd_attrstat *resp = rqstp->rq_resp; | |
c4d987ba | 44 | __be32 nfserr; |
1da177e4 LT |
45 | dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh)); |
46 | ||
47 | fh_copy(&resp->fh, &argp->fh); | |
04716e66 BF |
48 | nfserr = fh_verify(rqstp, &resp->fh, 0, |
49 | NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT); | |
846f2fcd | 50 | return nfsd_return_attrs(nfserr, resp); |
1da177e4 LT |
51 | } |
52 | ||
53 | /* | |
54 | * Set a file's attributes | |
55 | * N.B. After this call resp->fh needs an fh_put | |
56 | */ | |
7111c66e | 57 | static __be32 |
a6beb732 | 58 | nfsd_proc_setattr(struct svc_rqst *rqstp) |
1da177e4 | 59 | { |
a6beb732 CH |
60 | struct nfsd_sattrargs *argp = rqstp->rq_argp; |
61 | struct nfsd_attrstat *resp = rqstp->rq_resp; | |
cc265089 AG |
62 | struct iattr *iap = &argp->attrs; |
63 | struct svc_fh *fhp; | |
c4d987ba | 64 | __be32 nfserr; |
cc265089 | 65 | |
1da177e4 LT |
66 | dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n", |
67 | SVCFH_fmt(&argp->fh), | |
68 | argp->attrs.ia_valid, (long) argp->attrs.ia_size); | |
69 | ||
cc265089 AG |
70 | fhp = fh_copy(&resp->fh, &argp->fh); |
71 | ||
72 | /* | |
73 | * NFSv2 does not differentiate between "set-[ac]time-to-now" | |
74 | * which only requires access, and "set-[ac]time-to-X" which | |
75 | * requires ownership. | |
76 | * So if it looks like it might be "set both to the same time which | |
31051c85 | 77 | * is close to now", and if setattr_prepare fails, then we |
cc265089 AG |
78 | * convert to "set to now" instead of "set to explicit time" |
79 | * | |
31051c85 | 80 | * We only call setattr_prepare as the last test as technically |
cc265089 AG |
81 | * it is not an interface that we should be using. |
82 | */ | |
83 | #define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET) | |
84 | #define MAX_TOUCH_TIME_ERROR (30*60) | |
85 | if ((iap->ia_valid & BOTH_TIME_SET) == BOTH_TIME_SET && | |
86 | iap->ia_mtime.tv_sec == iap->ia_atime.tv_sec) { | |
87 | /* | |
88 | * Looks probable. | |
89 | * | |
90 | * Now just make sure time is in the right ballpark. | |
91 | * Solaris, at least, doesn't seem to care what the time | |
92 | * request is. We require it be within 30 minutes of now. | |
93 | */ | |
b6356d42 | 94 | time64_t delta = iap->ia_atime.tv_sec - ktime_get_real_seconds(); |
cc265089 AG |
95 | |
96 | nfserr = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP); | |
97 | if (nfserr) | |
98 | goto done; | |
cc265089 AG |
99 | |
100 | if (delta < 0) | |
101 | delta = -delta; | |
102 | if (delta < MAX_TOUCH_TIME_ERROR && | |
31051c85 | 103 | setattr_prepare(fhp->fh_dentry, iap) != 0) { |
cc265089 AG |
104 | /* |
105 | * Turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME. | |
106 | * This will cause notify_change to set these times | |
107 | * to "now" | |
108 | */ | |
109 | iap->ia_valid &= ~BOTH_TIME_SET; | |
110 | } | |
111 | } | |
112 | ||
2a1aa489 | 113 | nfserr = nfsd_setattr(rqstp, fhp, iap, 0, (time64_t)0); |
cc265089 | 114 | done: |
846f2fcd | 115 | return nfsd_return_attrs(nfserr, resp); |
1da177e4 LT |
116 | } |
117 | ||
6b3dccd4 CL |
118 | /* Obsolete, replaced by MNTPROC_MNT. */ |
119 | static __be32 | |
120 | nfsd_proc_root(struct svc_rqst *rqstp) | |
121 | { | |
122 | return nfs_ok; | |
123 | } | |
124 | ||
1da177e4 LT |
125 | /* |
126 | * Look up a path name component | |
127 | * Note: the dentry in the resp->fh may be negative if the file | |
128 | * doesn't exist yet. | |
129 | * N.B. After this call resp->fh needs an fh_put | |
130 | */ | |
7111c66e | 131 | static __be32 |
a6beb732 | 132 | nfsd_proc_lookup(struct svc_rqst *rqstp) |
1da177e4 | 133 | { |
a6beb732 CH |
134 | struct nfsd_diropargs *argp = rqstp->rq_argp; |
135 | struct nfsd_diropres *resp = rqstp->rq_resp; | |
c4d987ba | 136 | __be32 nfserr; |
1da177e4 LT |
137 | |
138 | dprintk("nfsd: LOOKUP %s %.*s\n", | |
139 | SVCFH_fmt(&argp->fh), argp->len, argp->name); | |
140 | ||
141 | fh_init(&resp->fh, NFS_FHSIZE); | |
142 | nfserr = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len, | |
143 | &resp->fh); | |
144 | ||
145 | fh_put(&argp->fh); | |
846f2fcd | 146 | return nfsd_return_dirop(nfserr, resp); |
1da177e4 LT |
147 | } |
148 | ||
149 | /* | |
150 | * Read a symlink. | |
151 | */ | |
7111c66e | 152 | static __be32 |
a6beb732 | 153 | nfsd_proc_readlink(struct svc_rqst *rqstp) |
1da177e4 | 154 | { |
a6beb732 CH |
155 | struct nfsd_readlinkargs *argp = rqstp->rq_argp; |
156 | struct nfsd_readlinkres *resp = rqstp->rq_resp; | |
c4d987ba | 157 | __be32 nfserr; |
1da177e4 LT |
158 | |
159 | dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh)); | |
160 | ||
161 | /* Read the symlink. */ | |
162 | resp->len = NFS_MAXPATHLEN; | |
163 | nfserr = nfsd_readlink(rqstp, &argp->fh, argp->buffer, &resp->len); | |
164 | ||
165 | fh_put(&argp->fh); | |
166 | return nfserr; | |
167 | } | |
168 | ||
169 | /* | |
170 | * Read a portion of a file. | |
171 | * N.B. After this call resp->fh needs an fh_put | |
172 | */ | |
7111c66e | 173 | static __be32 |
a6beb732 | 174 | nfsd_proc_read(struct svc_rqst *rqstp) |
1da177e4 | 175 | { |
a6beb732 CH |
176 | struct nfsd_readargs *argp = rqstp->rq_argp; |
177 | struct nfsd_readres *resp = rqstp->rq_resp; | |
c4d987ba | 178 | __be32 nfserr; |
83a63072 | 179 | u32 eof; |
1da177e4 LT |
180 | |
181 | dprintk("nfsd: READ %s %d bytes at %d\n", | |
182 | SVCFH_fmt(&argp->fh), | |
183 | argp->count, argp->offset); | |
184 | ||
185 | /* Obtain buffer pointer for payload. 19 is 1 word for | |
186 | * status, 17 words for fattr, and 1 word for the byte count. | |
187 | */ | |
188 | ||
7adae489 | 189 | if (NFSSVC_MAXBLKSIZE_V2 < argp->count) { |
ad06e4bd | 190 | char buf[RPC_MAX_ADDRBUFLEN]; |
1da177e4 | 191 | printk(KERN_NOTICE |
ad06e4bd CL |
192 | "oversized read request from %s (%d bytes)\n", |
193 | svc_print_addr(rqstp, buf, sizeof(buf)), | |
1da177e4 | 194 | argp->count); |
7adae489 | 195 | argp->count = NFSSVC_MAXBLKSIZE_V2; |
1da177e4 | 196 | } |
cd123012 | 197 | svc_reserve_auth(rqstp, (19<<2) + argp->count + 4); |
1da177e4 LT |
198 | |
199 | resp->count = argp->count; | |
039a87ca | 200 | nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh), |
1da177e4 | 201 | argp->offset, |
3cc03b16 | 202 | rqstp->rq_vec, argp->vlen, |
83a63072 TM |
203 | &resp->count, |
204 | &eof); | |
1da177e4 | 205 | |
846f2fcd | 206 | if (nfserr) return nfserr; |
3dadecce | 207 | return fh_getattr(&resp->fh, &resp->stat); |
1da177e4 LT |
208 | } |
209 | ||
6b3dccd4 CL |
210 | /* Reserved */ |
211 | static __be32 | |
212 | nfsd_proc_writecache(struct svc_rqst *rqstp) | |
213 | { | |
214 | return nfs_ok; | |
215 | } | |
216 | ||
1da177e4 LT |
217 | /* |
218 | * Write data to a file | |
219 | * N.B. After this call resp->fh needs an fh_put | |
220 | */ | |
7111c66e | 221 | static __be32 |
a6beb732 | 222 | nfsd_proc_write(struct svc_rqst *rqstp) |
1da177e4 | 223 | { |
a6beb732 CH |
224 | struct nfsd_writeargs *argp = rqstp->rq_argp; |
225 | struct nfsd_attrstat *resp = rqstp->rq_resp; | |
c4d987ba | 226 | __be32 nfserr; |
31dec253 | 227 | unsigned long cnt = argp->len; |
8154ef27 | 228 | unsigned int nvecs; |
1da177e4 LT |
229 | |
230 | dprintk("nfsd: WRITE %s %d bytes at %d\n", | |
231 | SVCFH_fmt(&argp->fh), | |
232 | argp->len, argp->offset); | |
233 | ||
3fd9557a CL |
234 | nvecs = svc_fill_write_vector(rqstp, rqstp->rq_arg.pages, |
235 | &argp->first, cnt); | |
8154ef27 CL |
236 | if (!nvecs) |
237 | return nfserr_io; | |
238 | nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), | |
239 | argp->offset, rqstp->rq_vec, nvecs, | |
19e0663f | 240 | &cnt, NFS_DATA_SYNC, NULL); |
846f2fcd | 241 | return nfsd_return_attrs(nfserr, resp); |
1da177e4 LT |
242 | } |
243 | ||
244 | /* | |
245 | * CREATE processing is complicated. The keyword here is `overloaded.' | |
246 | * The parent directory is kept locked between the check for existence | |
247 | * and the actual create() call in compliance with VFS protocols. | |
248 | * N.B. After this call _both_ argp->fh and resp->fh need an fh_put | |
249 | */ | |
7111c66e | 250 | static __be32 |
a6beb732 | 251 | nfsd_proc_create(struct svc_rqst *rqstp) |
1da177e4 | 252 | { |
a6beb732 CH |
253 | struct nfsd_createargs *argp = rqstp->rq_argp; |
254 | struct nfsd_diropres *resp = rqstp->rq_resp; | |
1da177e4 LT |
255 | svc_fh *dirfhp = &argp->fh; |
256 | svc_fh *newfhp = &resp->fh; | |
257 | struct iattr *attr = &argp->attrs; | |
258 | struct inode *inode; | |
259 | struct dentry *dchild; | |
c4d987ba AV |
260 | int type, mode; |
261 | __be32 nfserr; | |
4a55c101 | 262 | int hosterr; |
1da177e4 LT |
263 | dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size); |
264 | ||
265 | dprintk("nfsd: CREATE %s %.*s\n", | |
266 | SVCFH_fmt(dirfhp), argp->len, argp->name); | |
267 | ||
268 | /* First verify the parent file handle */ | |
8837abca | 269 | nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC); |
1da177e4 LT |
270 | if (nfserr) |
271 | goto done; /* must fh_put dirfhp even on error */ | |
272 | ||
8837abca | 273 | /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */ |
1da177e4 | 274 | |
1da177e4 LT |
275 | nfserr = nfserr_exist; |
276 | if (isdotent(argp->name, argp->len)) | |
277 | goto done; | |
4a55c101 JK |
278 | hosterr = fh_want_write(dirfhp); |
279 | if (hosterr) { | |
280 | nfserr = nfserrno(hosterr); | |
281 | goto done; | |
282 | } | |
283 | ||
7ed94296 | 284 | fh_lock_nested(dirfhp, I_MUTEX_PARENT); |
1da177e4 LT |
285 | dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len); |
286 | if (IS_ERR(dchild)) { | |
287 | nfserr = nfserrno(PTR_ERR(dchild)); | |
288 | goto out_unlock; | |
289 | } | |
290 | fh_init(newfhp, NFS_FHSIZE); | |
291 | nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp); | |
2b0143b5 | 292 | if (!nfserr && d_really_is_negative(dchild)) |
1da177e4 LT |
293 | nfserr = nfserr_noent; |
294 | dput(dchild); | |
295 | if (nfserr) { | |
296 | if (nfserr != nfserr_noent) | |
297 | goto out_unlock; | |
298 | /* | |
299 | * If the new file handle wasn't verified, we can't tell | |
300 | * whether the file exists or not. Time to bail ... | |
301 | */ | |
302 | nfserr = nfserr_acces; | |
303 | if (!newfhp->fh_dentry) { | |
304 | printk(KERN_WARNING | |
305 | "nfsd_proc_create: file handle not verified\n"); | |
306 | goto out_unlock; | |
307 | } | |
308 | } | |
309 | ||
2b0143b5 | 310 | inode = d_inode(newfhp->fh_dentry); |
1da177e4 LT |
311 | |
312 | /* Unfudge the mode bits */ | |
313 | if (attr->ia_valid & ATTR_MODE) { | |
314 | type = attr->ia_mode & S_IFMT; | |
315 | mode = attr->ia_mode & ~S_IFMT; | |
316 | if (!type) { | |
317 | /* no type, so if target exists, assume same as that, | |
318 | * else assume a file */ | |
319 | if (inode) { | |
320 | type = inode->i_mode & S_IFMT; | |
321 | switch(type) { | |
322 | case S_IFCHR: | |
323 | case S_IFBLK: | |
324 | /* reserve rdev for later checking */ | |
325 | rdev = inode->i_rdev; | |
326 | attr->ia_valid |= ATTR_SIZE; | |
327 | ||
df561f66 | 328 | fallthrough; |
1da177e4 LT |
329 | case S_IFIFO: |
330 | /* this is probably a permission check.. | |
331 | * at least IRIX implements perm checking on | |
332 | * echo thing > device-special-file-or-pipe | |
333 | * by doing a CREATE with type==0 | |
334 | */ | |
0ec757df BF |
335 | nfserr = nfsd_permission(rqstp, |
336 | newfhp->fh_export, | |
1da177e4 | 337 | newfhp->fh_dentry, |
8837abca | 338 | NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS); |
1da177e4 LT |
339 | if (nfserr && nfserr != nfserr_rofs) |
340 | goto out_unlock; | |
341 | } | |
342 | } else | |
343 | type = S_IFREG; | |
344 | } | |
345 | } else if (inode) { | |
346 | type = inode->i_mode & S_IFMT; | |
347 | mode = inode->i_mode & ~S_IFMT; | |
348 | } else { | |
349 | type = S_IFREG; | |
350 | mode = 0; /* ??? */ | |
351 | } | |
352 | ||
353 | attr->ia_valid |= ATTR_MODE; | |
354 | attr->ia_mode = mode; | |
355 | ||
356 | /* Special treatment for non-regular files according to the | |
357 | * gospel of sun micro | |
358 | */ | |
359 | if (type != S_IFREG) { | |
1da177e4 LT |
360 | if (type != S_IFBLK && type != S_IFCHR) { |
361 | rdev = 0; | |
362 | } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) { | |
363 | /* If you think you've seen the worst, grok this. */ | |
364 | type = S_IFIFO; | |
365 | } else { | |
366 | /* Okay, char or block special */ | |
1da177e4 LT |
367 | if (!rdev) |
368 | rdev = wanted; | |
369 | } | |
370 | ||
371 | /* we've used the SIZE information, so discard it */ | |
372 | attr->ia_valid &= ~ATTR_SIZE; | |
373 | ||
374 | /* Make sure the type and device matches */ | |
375 | nfserr = nfserr_exist; | |
376 | if (inode && type != (inode->i_mode & S_IFMT)) | |
377 | goto out_unlock; | |
378 | } | |
379 | ||
380 | nfserr = 0; | |
381 | if (!inode) { | |
382 | /* File doesn't exist. Create it and set attrs */ | |
b44061d0 BF |
383 | nfserr = nfsd_create_locked(rqstp, dirfhp, argp->name, |
384 | argp->len, attr, type, rdev, newfhp); | |
1da177e4 LT |
385 | } else if (type == S_IFREG) { |
386 | dprintk("nfsd: existing %s, valid=%x, size=%ld\n", | |
387 | argp->name, attr->ia_valid, (long) attr->ia_size); | |
388 | /* File already exists. We ignore all attributes except | |
389 | * size, so that creat() behaves exactly like | |
390 | * open(..., O_CREAT|O_TRUNC|O_WRONLY). | |
391 | */ | |
392 | attr->ia_valid &= ATTR_SIZE; | |
393 | if (attr->ia_valid) | |
2a1aa489 | 394 | nfserr = nfsd_setattr(rqstp, newfhp, attr, 0, (time64_t)0); |
1da177e4 LT |
395 | } |
396 | ||
397 | out_unlock: | |
398 | /* We don't really need to unlock, as fh_put does it. */ | |
399 | fh_unlock(dirfhp); | |
4a55c101 | 400 | fh_drop_write(dirfhp); |
1da177e4 LT |
401 | done: |
402 | fh_put(dirfhp); | |
846f2fcd | 403 | return nfsd_return_dirop(nfserr, resp); |
1da177e4 LT |
404 | } |
405 | ||
7111c66e | 406 | static __be32 |
a6beb732 | 407 | nfsd_proc_remove(struct svc_rqst *rqstp) |
1da177e4 | 408 | { |
a6beb732 | 409 | struct nfsd_diropargs *argp = rqstp->rq_argp; |
c4d987ba | 410 | __be32 nfserr; |
1da177e4 LT |
411 | |
412 | dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh), | |
413 | argp->len, argp->name); | |
414 | ||
415 | /* Unlink. -SIFDIR means file must not be a directory */ | |
416 | nfserr = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR, argp->name, argp->len); | |
417 | fh_put(&argp->fh); | |
418 | return nfserr; | |
419 | } | |
420 | ||
7111c66e | 421 | static __be32 |
a6beb732 | 422 | nfsd_proc_rename(struct svc_rqst *rqstp) |
1da177e4 | 423 | { |
a6beb732 | 424 | struct nfsd_renameargs *argp = rqstp->rq_argp; |
c4d987ba | 425 | __be32 nfserr; |
1da177e4 LT |
426 | |
427 | dprintk("nfsd: RENAME %s %.*s -> \n", | |
428 | SVCFH_fmt(&argp->ffh), argp->flen, argp->fname); | |
429 | dprintk("nfsd: -> %s %.*s\n", | |
430 | SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname); | |
431 | ||
432 | nfserr = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen, | |
433 | &argp->tfh, argp->tname, argp->tlen); | |
434 | fh_put(&argp->ffh); | |
435 | fh_put(&argp->tfh); | |
436 | return nfserr; | |
437 | } | |
438 | ||
7111c66e | 439 | static __be32 |
a6beb732 | 440 | nfsd_proc_link(struct svc_rqst *rqstp) |
1da177e4 | 441 | { |
a6beb732 | 442 | struct nfsd_linkargs *argp = rqstp->rq_argp; |
c4d987ba | 443 | __be32 nfserr; |
1da177e4 LT |
444 | |
445 | dprintk("nfsd: LINK %s ->\n", | |
446 | SVCFH_fmt(&argp->ffh)); | |
447 | dprintk("nfsd: %s %.*s\n", | |
448 | SVCFH_fmt(&argp->tfh), | |
449 | argp->tlen, | |
450 | argp->tname); | |
451 | ||
452 | nfserr = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen, | |
453 | &argp->ffh); | |
454 | fh_put(&argp->ffh); | |
455 | fh_put(&argp->tfh); | |
456 | return nfserr; | |
457 | } | |
458 | ||
7111c66e | 459 | static __be32 |
a6beb732 | 460 | nfsd_proc_symlink(struct svc_rqst *rqstp) |
1da177e4 | 461 | { |
a6beb732 | 462 | struct nfsd_symlinkargs *argp = rqstp->rq_argp; |
1da177e4 | 463 | struct svc_fh newfh; |
c4d987ba | 464 | __be32 nfserr; |
1da177e4 | 465 | |
38a70315 CL |
466 | if (argp->tlen > NFS_MAXPATHLEN) |
467 | return nfserr_nametoolong; | |
468 | ||
469 | argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first, | |
11b4d66e | 470 | page_address(rqstp->rq_arg.pages[0]), |
38a70315 CL |
471 | argp->tlen); |
472 | if (IS_ERR(argp->tname)) | |
473 | return nfserrno(PTR_ERR(argp->tname)); | |
474 | ||
1da177e4 LT |
475 | dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n", |
476 | SVCFH_fmt(&argp->ffh), argp->flen, argp->fname, | |
477 | argp->tlen, argp->tname); | |
478 | ||
479 | fh_init(&newfh, NFS_FHSIZE); | |
1da177e4 | 480 | nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen, |
1e444f5b | 481 | argp->tname, &newfh); |
1da177e4 | 482 | |
11b4d66e | 483 | kfree(argp->tname); |
1da177e4 LT |
484 | fh_put(&argp->ffh); |
485 | fh_put(&newfh); | |
486 | return nfserr; | |
487 | } | |
488 | ||
489 | /* | |
490 | * Make directory. This operation is not idempotent. | |
491 | * N.B. After this call resp->fh needs an fh_put | |
492 | */ | |
7111c66e | 493 | static __be32 |
a6beb732 | 494 | nfsd_proc_mkdir(struct svc_rqst *rqstp) |
1da177e4 | 495 | { |
a6beb732 CH |
496 | struct nfsd_createargs *argp = rqstp->rq_argp; |
497 | struct nfsd_diropres *resp = rqstp->rq_resp; | |
c4d987ba | 498 | __be32 nfserr; |
1da177e4 LT |
499 | |
500 | dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name); | |
501 | ||
502 | if (resp->fh.fh_dentry) { | |
503 | printk(KERN_WARNING | |
504 | "nfsd_proc_mkdir: response already verified??\n"); | |
505 | } | |
506 | ||
507 | argp->attrs.ia_valid &= ~ATTR_SIZE; | |
508 | fh_init(&resp->fh, NFS_FHSIZE); | |
509 | nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len, | |
510 | &argp->attrs, S_IFDIR, 0, &resp->fh); | |
511 | fh_put(&argp->fh); | |
846f2fcd | 512 | return nfsd_return_dirop(nfserr, resp); |
1da177e4 LT |
513 | } |
514 | ||
515 | /* | |
516 | * Remove a directory | |
517 | */ | |
7111c66e | 518 | static __be32 |
a6beb732 | 519 | nfsd_proc_rmdir(struct svc_rqst *rqstp) |
1da177e4 | 520 | { |
a6beb732 | 521 | struct nfsd_diropargs *argp = rqstp->rq_argp; |
c4d987ba | 522 | __be32 nfserr; |
1da177e4 LT |
523 | |
524 | dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name); | |
525 | ||
526 | nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len); | |
527 | fh_put(&argp->fh); | |
528 | return nfserr; | |
529 | } | |
530 | ||
531 | /* | |
532 | * Read a portion of a directory. | |
533 | */ | |
7111c66e | 534 | static __be32 |
a6beb732 | 535 | nfsd_proc_readdir(struct svc_rqst *rqstp) |
1da177e4 | 536 | { |
a6beb732 CH |
537 | struct nfsd_readdirargs *argp = rqstp->rq_argp; |
538 | struct nfsd_readdirres *resp = rqstp->rq_resp; | |
c4d987ba AV |
539 | int count; |
540 | __be32 nfserr; | |
1da177e4 LT |
541 | loff_t offset; |
542 | ||
543 | dprintk("nfsd: READDIR %s %d bytes at %d\n", | |
544 | SVCFH_fmt(&argp->fh), | |
545 | argp->count, argp->cookie); | |
546 | ||
547 | /* Shrink to the client read size */ | |
548 | count = (argp->count >> 2) - 2; | |
549 | ||
550 | /* Make sure we've room for the NULL ptr & eof flag */ | |
551 | count -= 2; | |
552 | if (count < 0) | |
553 | count = 0; | |
554 | ||
555 | resp->buffer = argp->buffer; | |
556 | resp->offset = NULL; | |
557 | resp->buflen = count; | |
558 | resp->common.err = nfs_ok; | |
559 | /* Read directory and encode entries on the fly */ | |
560 | offset = argp->cookie; | |
561 | nfserr = nfsd_readdir(rqstp, &argp->fh, &offset, | |
562 | &resp->common, nfssvc_encode_entry); | |
563 | ||
564 | resp->count = resp->buffer - argp->buffer; | |
565 | if (resp->offset) | |
566 | *resp->offset = htonl(offset); | |
567 | ||
568 | fh_put(&argp->fh); | |
569 | return nfserr; | |
570 | } | |
571 | ||
572 | /* | |
573 | * Get file system info | |
574 | */ | |
7111c66e | 575 | static __be32 |
a6beb732 | 576 | nfsd_proc_statfs(struct svc_rqst *rqstp) |
1da177e4 | 577 | { |
a6beb732 CH |
578 | struct nfsd_fhandle *argp = rqstp->rq_argp; |
579 | struct nfsd_statfsres *resp = rqstp->rq_resp; | |
c4d987ba | 580 | __be32 nfserr; |
1da177e4 LT |
581 | |
582 | dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh)); | |
583 | ||
04716e66 BF |
584 | nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats, |
585 | NFSD_MAY_BYPASS_GSS_ON_ROOT); | |
1da177e4 LT |
586 | fh_put(&argp->fh); |
587 | return nfserr; | |
588 | } | |
589 | ||
590 | /* | |
591 | * NFSv2 Server procedures. | |
592 | * Only the results of non-idempotent operations are cached. | |
593 | */ | |
1da177e4 LT |
594 | struct nfsd_void { int dummy; }; |
595 | ||
1da177e4 LT |
596 | #define ST 1 /* status */ |
597 | #define FH 8 /* filehandle */ | |
598 | #define AT 18 /* attributes */ | |
599 | ||
860bda29 | 600 | static const struct svc_procedure nfsd_procedures2[18] = { |
b9081d90 | 601 | [NFSPROC_NULL] = { |
a6beb732 | 602 | .pc_func = nfsd_proc_null, |
026fec7e | 603 | .pc_decode = nfssvc_decode_void, |
63f8de37 | 604 | .pc_encode = nfssvc_encode_void, |
b9081d90 YZ |
605 | .pc_argsize = sizeof(struct nfsd_void), |
606 | .pc_ressize = sizeof(struct nfsd_void), | |
607 | .pc_cachetype = RC_NOCACHE, | |
608 | .pc_xdrressize = ST, | |
609 | }, | |
610 | [NFSPROC_GETATTR] = { | |
a6beb732 | 611 | .pc_func = nfsd_proc_getattr, |
026fec7e | 612 | .pc_decode = nfssvc_decode_fhandle, |
63f8de37 | 613 | .pc_encode = nfssvc_encode_attrstat, |
1841b9b6 | 614 | .pc_release = nfssvc_release_attrstat, |
b9081d90 YZ |
615 | .pc_argsize = sizeof(struct nfsd_fhandle), |
616 | .pc_ressize = sizeof(struct nfsd_attrstat), | |
617 | .pc_cachetype = RC_NOCACHE, | |
618 | .pc_xdrressize = ST+AT, | |
619 | }, | |
620 | [NFSPROC_SETATTR] = { | |
a6beb732 | 621 | .pc_func = nfsd_proc_setattr, |
026fec7e | 622 | .pc_decode = nfssvc_decode_sattrargs, |
63f8de37 | 623 | .pc_encode = nfssvc_encode_attrstat, |
1841b9b6 | 624 | .pc_release = nfssvc_release_attrstat, |
b9081d90 YZ |
625 | .pc_argsize = sizeof(struct nfsd_sattrargs), |
626 | .pc_ressize = sizeof(struct nfsd_attrstat), | |
627 | .pc_cachetype = RC_REPLBUFF, | |
628 | .pc_xdrressize = ST+AT, | |
629 | }, | |
630 | [NFSPROC_ROOT] = { | |
6b3dccd4 | 631 | .pc_func = nfsd_proc_root, |
026fec7e | 632 | .pc_decode = nfssvc_decode_void, |
63f8de37 | 633 | .pc_encode = nfssvc_encode_void, |
b9081d90 YZ |
634 | .pc_argsize = sizeof(struct nfsd_void), |
635 | .pc_ressize = sizeof(struct nfsd_void), | |
636 | .pc_cachetype = RC_NOCACHE, | |
637 | .pc_xdrressize = ST, | |
638 | }, | |
639 | [NFSPROC_LOOKUP] = { | |
a6beb732 | 640 | .pc_func = nfsd_proc_lookup, |
026fec7e | 641 | .pc_decode = nfssvc_decode_diropargs, |
63f8de37 | 642 | .pc_encode = nfssvc_encode_diropres, |
1841b9b6 | 643 | .pc_release = nfssvc_release_diropres, |
b9081d90 YZ |
644 | .pc_argsize = sizeof(struct nfsd_diropargs), |
645 | .pc_ressize = sizeof(struct nfsd_diropres), | |
646 | .pc_cachetype = RC_NOCACHE, | |
647 | .pc_xdrressize = ST+FH+AT, | |
648 | }, | |
649 | [NFSPROC_READLINK] = { | |
a6beb732 | 650 | .pc_func = nfsd_proc_readlink, |
026fec7e | 651 | .pc_decode = nfssvc_decode_readlinkargs, |
63f8de37 | 652 | .pc_encode = nfssvc_encode_readlinkres, |
b9081d90 YZ |
653 | .pc_argsize = sizeof(struct nfsd_readlinkargs), |
654 | .pc_ressize = sizeof(struct nfsd_readlinkres), | |
655 | .pc_cachetype = RC_NOCACHE, | |
656 | .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4, | |
657 | }, | |
658 | [NFSPROC_READ] = { | |
a6beb732 | 659 | .pc_func = nfsd_proc_read, |
026fec7e | 660 | .pc_decode = nfssvc_decode_readargs, |
63f8de37 | 661 | .pc_encode = nfssvc_encode_readres, |
1841b9b6 | 662 | .pc_release = nfssvc_release_readres, |
b9081d90 YZ |
663 | .pc_argsize = sizeof(struct nfsd_readargs), |
664 | .pc_ressize = sizeof(struct nfsd_readres), | |
665 | .pc_cachetype = RC_NOCACHE, | |
666 | .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4, | |
667 | }, | |
668 | [NFSPROC_WRITECACHE] = { | |
6b3dccd4 | 669 | .pc_func = nfsd_proc_writecache, |
026fec7e | 670 | .pc_decode = nfssvc_decode_void, |
63f8de37 | 671 | .pc_encode = nfssvc_encode_void, |
b9081d90 YZ |
672 | .pc_argsize = sizeof(struct nfsd_void), |
673 | .pc_ressize = sizeof(struct nfsd_void), | |
674 | .pc_cachetype = RC_NOCACHE, | |
675 | .pc_xdrressize = ST, | |
676 | }, | |
677 | [NFSPROC_WRITE] = { | |
a6beb732 | 678 | .pc_func = nfsd_proc_write, |
026fec7e | 679 | .pc_decode = nfssvc_decode_writeargs, |
63f8de37 | 680 | .pc_encode = nfssvc_encode_attrstat, |
1841b9b6 | 681 | .pc_release = nfssvc_release_attrstat, |
b9081d90 YZ |
682 | .pc_argsize = sizeof(struct nfsd_writeargs), |
683 | .pc_ressize = sizeof(struct nfsd_attrstat), | |
684 | .pc_cachetype = RC_REPLBUFF, | |
685 | .pc_xdrressize = ST+AT, | |
686 | }, | |
687 | [NFSPROC_CREATE] = { | |
a6beb732 | 688 | .pc_func = nfsd_proc_create, |
026fec7e | 689 | .pc_decode = nfssvc_decode_createargs, |
63f8de37 | 690 | .pc_encode = nfssvc_encode_diropres, |
1841b9b6 | 691 | .pc_release = nfssvc_release_diropres, |
b9081d90 YZ |
692 | .pc_argsize = sizeof(struct nfsd_createargs), |
693 | .pc_ressize = sizeof(struct nfsd_diropres), | |
694 | .pc_cachetype = RC_REPLBUFF, | |
695 | .pc_xdrressize = ST+FH+AT, | |
696 | }, | |
697 | [NFSPROC_REMOVE] = { | |
a6beb732 | 698 | .pc_func = nfsd_proc_remove, |
026fec7e | 699 | .pc_decode = nfssvc_decode_diropargs, |
63f8de37 | 700 | .pc_encode = nfssvc_encode_void, |
b9081d90 YZ |
701 | .pc_argsize = sizeof(struct nfsd_diropargs), |
702 | .pc_ressize = sizeof(struct nfsd_void), | |
703 | .pc_cachetype = RC_REPLSTAT, | |
704 | .pc_xdrressize = ST, | |
705 | }, | |
706 | [NFSPROC_RENAME] = { | |
a6beb732 | 707 | .pc_func = nfsd_proc_rename, |
026fec7e | 708 | .pc_decode = nfssvc_decode_renameargs, |
63f8de37 | 709 | .pc_encode = nfssvc_encode_void, |
b9081d90 YZ |
710 | .pc_argsize = sizeof(struct nfsd_renameargs), |
711 | .pc_ressize = sizeof(struct nfsd_void), | |
712 | .pc_cachetype = RC_REPLSTAT, | |
713 | .pc_xdrressize = ST, | |
714 | }, | |
715 | [NFSPROC_LINK] = { | |
a6beb732 | 716 | .pc_func = nfsd_proc_link, |
026fec7e | 717 | .pc_decode = nfssvc_decode_linkargs, |
63f8de37 | 718 | .pc_encode = nfssvc_encode_void, |
b9081d90 YZ |
719 | .pc_argsize = sizeof(struct nfsd_linkargs), |
720 | .pc_ressize = sizeof(struct nfsd_void), | |
721 | .pc_cachetype = RC_REPLSTAT, | |
722 | .pc_xdrressize = ST, | |
723 | }, | |
724 | [NFSPROC_SYMLINK] = { | |
a6beb732 | 725 | .pc_func = nfsd_proc_symlink, |
026fec7e | 726 | .pc_decode = nfssvc_decode_symlinkargs, |
63f8de37 | 727 | .pc_encode = nfssvc_encode_void, |
b9081d90 YZ |
728 | .pc_argsize = sizeof(struct nfsd_symlinkargs), |
729 | .pc_ressize = sizeof(struct nfsd_void), | |
730 | .pc_cachetype = RC_REPLSTAT, | |
731 | .pc_xdrressize = ST, | |
732 | }, | |
733 | [NFSPROC_MKDIR] = { | |
a6beb732 | 734 | .pc_func = nfsd_proc_mkdir, |
026fec7e | 735 | .pc_decode = nfssvc_decode_createargs, |
63f8de37 | 736 | .pc_encode = nfssvc_encode_diropres, |
1841b9b6 | 737 | .pc_release = nfssvc_release_diropres, |
b9081d90 YZ |
738 | .pc_argsize = sizeof(struct nfsd_createargs), |
739 | .pc_ressize = sizeof(struct nfsd_diropres), | |
740 | .pc_cachetype = RC_REPLBUFF, | |
741 | .pc_xdrressize = ST+FH+AT, | |
742 | }, | |
743 | [NFSPROC_RMDIR] = { | |
a6beb732 | 744 | .pc_func = nfsd_proc_rmdir, |
026fec7e | 745 | .pc_decode = nfssvc_decode_diropargs, |
63f8de37 | 746 | .pc_encode = nfssvc_encode_void, |
b9081d90 YZ |
747 | .pc_argsize = sizeof(struct nfsd_diropargs), |
748 | .pc_ressize = sizeof(struct nfsd_void), | |
749 | .pc_cachetype = RC_REPLSTAT, | |
750 | .pc_xdrressize = ST, | |
751 | }, | |
752 | [NFSPROC_READDIR] = { | |
a6beb732 | 753 | .pc_func = nfsd_proc_readdir, |
026fec7e | 754 | .pc_decode = nfssvc_decode_readdirargs, |
63f8de37 | 755 | .pc_encode = nfssvc_encode_readdirres, |
b9081d90 YZ |
756 | .pc_argsize = sizeof(struct nfsd_readdirargs), |
757 | .pc_ressize = sizeof(struct nfsd_readdirres), | |
758 | .pc_cachetype = RC_NOCACHE, | |
759 | }, | |
760 | [NFSPROC_STATFS] = { | |
a6beb732 | 761 | .pc_func = nfsd_proc_statfs, |
026fec7e | 762 | .pc_decode = nfssvc_decode_fhandle, |
63f8de37 | 763 | .pc_encode = nfssvc_encode_statfsres, |
b9081d90 YZ |
764 | .pc_argsize = sizeof(struct nfsd_fhandle), |
765 | .pc_ressize = sizeof(struct nfsd_statfsres), | |
766 | .pc_cachetype = RC_NOCACHE, | |
767 | .pc_xdrressize = ST+5, | |
768 | }, | |
1da177e4 LT |
769 | }; |
770 | ||
771 | ||
7fd38af9 | 772 | static unsigned int nfsd_count2[ARRAY_SIZE(nfsd_procedures2)]; |
e9679189 CH |
773 | const struct svc_version nfsd_version2 = { |
774 | .vs_vers = 2, | |
775 | .vs_nproc = 18, | |
776 | .vs_proc = nfsd_procedures2, | |
777 | .vs_count = nfsd_count2, | |
778 | .vs_dispatch = nfsd_dispatch, | |
779 | .vs_xdrsize = NFS2_SVC_XDRSIZE, | |
1da177e4 LT |
780 | }; |
781 | ||
782 | /* | |
783 | * Map errnos to NFS errnos. | |
784 | */ | |
63f10311 | 785 | __be32 |
1da177e4 LT |
786 | nfserrno (int errno) |
787 | { | |
788 | static struct { | |
63f10311 | 789 | __be32 nfserr; |
1da177e4 LT |
790 | int syserr; |
791 | } nfs_errtbl[] = { | |
792 | { nfs_ok, 0 }, | |
793 | { nfserr_perm, -EPERM }, | |
794 | { nfserr_noent, -ENOENT }, | |
795 | { nfserr_io, -EIO }, | |
796 | { nfserr_nxio, -ENXIO }, | |
62814d6a | 797 | { nfserr_fbig, -E2BIG }, |
1da177e4 LT |
798 | { nfserr_acces, -EACCES }, |
799 | { nfserr_exist, -EEXIST }, | |
800 | { nfserr_xdev, -EXDEV }, | |
801 | { nfserr_mlink, -EMLINK }, | |
802 | { nfserr_nodev, -ENODEV }, | |
803 | { nfserr_notdir, -ENOTDIR }, | |
804 | { nfserr_isdir, -EISDIR }, | |
805 | { nfserr_inval, -EINVAL }, | |
806 | { nfserr_fbig, -EFBIG }, | |
807 | { nfserr_nospc, -ENOSPC }, | |
808 | { nfserr_rofs, -EROFS }, | |
809 | { nfserr_mlink, -EMLINK }, | |
810 | { nfserr_nametoolong, -ENAMETOOLONG }, | |
811 | { nfserr_notempty, -ENOTEMPTY }, | |
812 | #ifdef EDQUOT | |
813 | { nfserr_dquot, -EDQUOT }, | |
814 | #endif | |
815 | { nfserr_stale, -ESTALE }, | |
816 | { nfserr_jukebox, -ETIMEDOUT }, | |
599eb304 | 817 | { nfserr_jukebox, -ERESTARTSYS }, |
062304a8 BF |
818 | { nfserr_jukebox, -EAGAIN }, |
819 | { nfserr_jukebox, -EWOULDBLOCK }, | |
3beb6cd1 | 820 | { nfserr_jukebox, -ENOMEM }, |
1da177e4 | 821 | { nfserr_io, -ETXTBSY }, |
a838cc49 | 822 | { nfserr_notsupp, -EOPNOTSUPP }, |
b7aeda40 | 823 | { nfserr_toosmall, -ETOOSMALL }, |
f39bde24 | 824 | { nfserr_serverfault, -ESERVERFAULT }, |
b3fbfe0e | 825 | { nfserr_serverfault, -ENFILE }, |
42e61616 | 826 | { nfserr_io, -EUCLEAN }, |
c952cd4e | 827 | { nfserr_perm, -ENOKEY }, |
1da177e4 LT |
828 | }; |
829 | int i; | |
830 | ||
63f10311 | 831 | for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) { |
1da177e4 LT |
832 | if (nfs_errtbl[i].syserr == errno) |
833 | return nfs_errtbl[i].nfserr; | |
834 | } | |
ff30f08c | 835 | WARN_ONCE(1, "nfsd: non-standard errno: %d\n", errno); |
1da177e4 LT |
836 | return nfserr_io; |
837 | } | |
838 |