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