blob: 7e4bb0af24d7d48d70a61feae9e5930efbde3e59 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/nfsd/nfs3xdr.c
3 *
4 * XDR support for nfsd/protocol version 3.
5 *
6 * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
7 *
8 * 2003-08-09 Jamie Lokier: Use htonl() for nanoseconds, not htons()!
9 */
10
11#include <linux/types.h>
12#include <linux/time.h>
13#include <linux/nfs3.h>
14#include <linux/list.h>
15#include <linux/spinlock.h>
16#include <linux/dcache.h>
17#include <linux/namei.h>
18#include <linux/mm.h>
19#include <linux/vfs.h>
20#include <linux/sunrpc/xdr.h>
21#include <linux/sunrpc/svc.h>
22#include <linux/nfsd/nfsd.h>
23#include <linux/nfsd/xdr3.h>
24
25#define NFSDDBG_FACILITY NFSDDBG_XDR
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/*
29 * Mapping of S_IF* types to NFS file types
30 */
31static u32 nfs3_ftypes[] = {
32 NF3NON, NF3FIFO, NF3CHR, NF3BAD,
33 NF3DIR, NF3BAD, NF3BLK, NF3BAD,
34 NF3REG, NF3BAD, NF3LNK, NF3BAD,
35 NF3SOCK, NF3BAD, NF3LNK, NF3BAD,
36};
37
38/*
39 * XDR functions for basic NFS types
40 */
Adrian Bunk3ee6f612006-12-06 20:40:23 -080041static __be32 *
Al Viro91f07162006-10-19 23:28:57 -070042encode_time3(__be32 *p, struct timespec *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 *p++ = htonl((u32) time->tv_sec); *p++ = htonl(time->tv_nsec);
45 return p;
46}
47
Adrian Bunk3ee6f612006-12-06 20:40:23 -080048static __be32 *
Al Viro91f07162006-10-19 23:28:57 -070049decode_time3(__be32 *p, struct timespec *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
51 time->tv_sec = ntohl(*p++);
52 time->tv_nsec = ntohl(*p++);
53 return p;
54}
55
Adrian Bunk3ee6f612006-12-06 20:40:23 -080056static __be32 *
Al Viro91f07162006-10-19 23:28:57 -070057decode_fh(__be32 *p, struct svc_fh *fhp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 unsigned int size;
60 fh_init(fhp, NFS3_FHSIZE);
61 size = ntohl(*p++);
62 if (size > NFS3_FHSIZE)
63 return NULL;
64
65 memcpy(&fhp->fh_handle.fh_base, p, size);
66 fhp->fh_handle.fh_size = size;
67 return p + XDR_QUADLEN(size);
68}
69
Andreas Gruenbachera257cdd2005-06-22 17:16:26 +000070/* Helper function for NFSv3 ACL code */
Al Viro91f07162006-10-19 23:28:57 -070071__be32 *nfs3svc_decode_fh(__be32 *p, struct svc_fh *fhp)
Andreas Gruenbachera257cdd2005-06-22 17:16:26 +000072{
73 return decode_fh(p, fhp);
74}
75
Adrian Bunk3ee6f612006-12-06 20:40:23 -080076static __be32 *
Al Viro91f07162006-10-19 23:28:57 -070077encode_fh(__be32 *p, struct svc_fh *fhp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
79 unsigned int size = fhp->fh_handle.fh_size;
80 *p++ = htonl(size);
81 if (size) p[XDR_QUADLEN(size)-1]=0;
82 memcpy(p, &fhp->fh_handle.fh_base, size);
83 return p + XDR_QUADLEN(size);
84}
85
86/*
87 * Decode a file name and make sure that the path contains
88 * no slashes or null bytes.
89 */
Adrian Bunk3ee6f612006-12-06 20:40:23 -080090static __be32 *
Al Viro91f07162006-10-19 23:28:57 -070091decode_filename(__be32 *p, char **namp, int *lenp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
93 char *name;
94 int i;
95
96 if ((p = xdr_decode_string_inplace(p, namp, lenp, NFS3_MAXNAMLEN)) != NULL) {
97 for (i = 0, name = *namp; i < *lenp; i++, name++) {
98 if (*name == '\0' || *name == '/')
99 return NULL;
100 }
101 }
102
103 return p;
104}
105
Adrian Bunk3ee6f612006-12-06 20:40:23 -0800106static __be32 *
Al Viro91f07162006-10-19 23:28:57 -0700107decode_sattr3(__be32 *p, struct iattr *iap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
109 u32 tmp;
110
111 iap->ia_valid = 0;
112
113 if (*p++) {
114 iap->ia_valid |= ATTR_MODE;
115 iap->ia_mode = ntohl(*p++);
116 }
117 if (*p++) {
118 iap->ia_valid |= ATTR_UID;
119 iap->ia_uid = ntohl(*p++);
120 }
121 if (*p++) {
122 iap->ia_valid |= ATTR_GID;
123 iap->ia_gid = ntohl(*p++);
124 }
125 if (*p++) {
126 u64 newsize;
127
128 iap->ia_valid |= ATTR_SIZE;
129 p = xdr_decode_hyper(p, &newsize);
130 if (newsize <= NFS_OFFSET_MAX)
131 iap->ia_size = newsize;
132 else
133 iap->ia_size = NFS_OFFSET_MAX;
134 }
135 if ((tmp = ntohl(*p++)) == 1) { /* set to server time */
136 iap->ia_valid |= ATTR_ATIME;
137 } else if (tmp == 2) { /* set to client time */
138 iap->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET;
139 iap->ia_atime.tv_sec = ntohl(*p++);
140 iap->ia_atime.tv_nsec = ntohl(*p++);
141 }
142 if ((tmp = ntohl(*p++)) == 1) { /* set to server time */
143 iap->ia_valid |= ATTR_MTIME;
144 } else if (tmp == 2) { /* set to client time */
145 iap->ia_valid |= ATTR_MTIME | ATTR_MTIME_SET;
146 iap->ia_mtime.tv_sec = ntohl(*p++);
147 iap->ia_mtime.tv_nsec = ntohl(*p++);
148 }
149 return p;
150}
151
NeilBrownaf6a4e22007-02-14 00:33:12 -0800152static __be32 *encode_fsid(__be32 *p, struct svc_fh *fhp)
153{
154 u64 f;
155 switch(fsid_source(fhp)) {
156 default:
157 case FSIDSOURCE_DEV:
158 p = xdr_encode_hyper(p, (u64)huge_encode_dev
159 (fhp->fh_dentry->d_inode->i_sb->s_dev));
160 break;
161 case FSIDSOURCE_FSID:
162 p = xdr_encode_hyper(p, (u64) fhp->fh_export->ex_fsid);
163 break;
164 case FSIDSOURCE_UUID:
165 f = ((u64*)fhp->fh_export->ex_uuid)[0];
166 f ^= ((u64*)fhp->fh_export->ex_uuid)[1];
167 p = xdr_encode_hyper(p, f);
168 break;
169 }
170 return p;
171}
172
Adrian Bunk3ee6f612006-12-06 20:40:23 -0800173static __be32 *
Al Viro91f07162006-10-19 23:28:57 -0700174encode_fattr3(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp,
David Shawa334de22006-01-06 00:19:58 -0800175 struct kstat *stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 struct dentry *dentry = fhp->fh_dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 struct timespec time;
179
David Shawa334de22006-01-06 00:19:58 -0800180 *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
181 *p++ = htonl((u32) stat->mode);
182 *p++ = htonl((u32) stat->nlink);
183 *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
184 *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
185 if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
187 } else {
David Shawa334de22006-01-06 00:19:58 -0800188 p = xdr_encode_hyper(p, (u64) stat->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 }
David Shawa334de22006-01-06 00:19:58 -0800190 p = xdr_encode_hyper(p, ((u64)stat->blocks) << 9);
191 *p++ = htonl((u32) MAJOR(stat->rdev));
192 *p++ = htonl((u32) MINOR(stat->rdev));
NeilBrownaf6a4e22007-02-14 00:33:12 -0800193 p = encode_fsid(p, fhp);
David Shawa334de22006-01-06 00:19:58 -0800194 p = xdr_encode_hyper(p, (u64) stat->ino);
195 p = encode_time3(p, &stat->atime);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 lease_get_mtime(dentry->d_inode, &time);
197 p = encode_time3(p, &time);
David Shawa334de22006-01-06 00:19:58 -0800198 p = encode_time3(p, &stat->ctime);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 return p;
201}
202
Adrian Bunk3ee6f612006-12-06 20:40:23 -0800203static __be32 *
Al Viro91f07162006-10-19 23:28:57 -0700204encode_saved_post_attr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 struct inode *inode = fhp->fh_dentry->d_inode;
207
208 /* Attributes to follow */
209 *p++ = xdr_one;
210
211 *p++ = htonl(nfs3_ftypes[(fhp->fh_post_mode & S_IFMT) >> 12]);
212 *p++ = htonl((u32) fhp->fh_post_mode);
213 *p++ = htonl((u32) fhp->fh_post_nlink);
214 *p++ = htonl((u32) nfsd_ruid(rqstp, fhp->fh_post_uid));
215 *p++ = htonl((u32) nfsd_rgid(rqstp, fhp->fh_post_gid));
216 if (S_ISLNK(fhp->fh_post_mode) && fhp->fh_post_size > NFS3_MAXPATHLEN) {
217 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
218 } else {
219 p = xdr_encode_hyper(p, (u64) fhp->fh_post_size);
220 }
221 p = xdr_encode_hyper(p, ((u64)fhp->fh_post_blocks) << 9);
222 *p++ = fhp->fh_post_rdev[0];
223 *p++ = fhp->fh_post_rdev[1];
NeilBrownaf6a4e22007-02-14 00:33:12 -0800224 p = encode_fsid(p, fhp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 p = xdr_encode_hyper(p, (u64) inode->i_ino);
226 p = encode_time3(p, &fhp->fh_post_atime);
227 p = encode_time3(p, &fhp->fh_post_mtime);
228 p = encode_time3(p, &fhp->fh_post_ctime);
229
230 return p;
231}
232
233/*
234 * Encode post-operation attributes.
235 * The inode may be NULL if the call failed because of a stale file
236 * handle. In this case, no attributes are returned.
237 */
Al Viro91f07162006-10-19 23:28:57 -0700238static __be32 *
239encode_post_op_attr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 struct dentry *dentry = fhp->fh_dentry;
242 if (dentry && dentry->d_inode != NULL) {
David Shawa334de22006-01-06 00:19:58 -0800243 int err;
244 struct kstat stat;
245
246 err = vfs_getattr(fhp->fh_export->ex_mnt, dentry, &stat);
247 if (!err) {
248 *p++ = xdr_one; /* attributes follow */
249 return encode_fattr3(rqstp, p, fhp, &stat);
250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 }
252 *p++ = xdr_zero;
253 return p;
254}
255
Andreas Gruenbachera257cdd2005-06-22 17:16:26 +0000256/* Helper for NFSv3 ACLs */
Al Viro91f07162006-10-19 23:28:57 -0700257__be32 *
258nfs3svc_encode_post_op_attr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
Andreas Gruenbachera257cdd2005-06-22 17:16:26 +0000259{
260 return encode_post_op_attr(rqstp, p, fhp);
261}
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263/*
264 * Enocde weak cache consistency data
265 */
Al Viro91f07162006-10-19 23:28:57 -0700266static __be32 *
267encode_wcc_data(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
269 struct dentry *dentry = fhp->fh_dentry;
270
271 if (dentry && dentry->d_inode && fhp->fh_post_saved) {
272 if (fhp->fh_pre_saved) {
273 *p++ = xdr_one;
274 p = xdr_encode_hyper(p, (u64) fhp->fh_pre_size);
275 p = encode_time3(p, &fhp->fh_pre_mtime);
276 p = encode_time3(p, &fhp->fh_pre_ctime);
277 } else {
278 *p++ = xdr_zero;
279 }
280 return encode_saved_post_attr(rqstp, p, fhp);
281 }
282 /* no pre- or post-attrs */
283 *p++ = xdr_zero;
284 return encode_post_op_attr(rqstp, p, fhp);
285}
286
287
288/*
289 * XDR decode functions
290 */
291int
Al Viro91f07162006-10-19 23:28:57 -0700292nfs3svc_decode_fhandle(struct svc_rqst *rqstp, __be32 *p, struct nfsd_fhandle *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
294 if (!(p = decode_fh(p, &args->fh)))
295 return 0;
296 return xdr_argsize_check(rqstp, p);
297}
298
299int
Al Viro91f07162006-10-19 23:28:57 -0700300nfs3svc_decode_sattrargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 struct nfsd3_sattrargs *args)
302{
303 if (!(p = decode_fh(p, &args->fh))
304 || !(p = decode_sattr3(p, &args->attrs)))
305 return 0;
306
307 if ((args->check_guard = ntohl(*p++)) != 0) {
308 struct timespec time;
309 p = decode_time3(p, &time);
310 args->guardtime = time.tv_sec;
311 }
312
313 return xdr_argsize_check(rqstp, p);
314}
315
316int
Al Viro91f07162006-10-19 23:28:57 -0700317nfs3svc_decode_diropargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 struct nfsd3_diropargs *args)
319{
320 if (!(p = decode_fh(p, &args->fh))
321 || !(p = decode_filename(p, &args->name, &args->len)))
322 return 0;
323
324 return xdr_argsize_check(rqstp, p);
325}
326
327int
Al Viro91f07162006-10-19 23:28:57 -0700328nfs3svc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 struct nfsd3_accessargs *args)
330{
331 if (!(p = decode_fh(p, &args->fh)))
332 return 0;
333 args->access = ntohl(*p++);
334
335 return xdr_argsize_check(rqstp, p);
336}
337
338int
Al Viro91f07162006-10-19 23:28:57 -0700339nfs3svc_decode_readargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 struct nfsd3_readargs *args)
341{
342 unsigned int len;
343 int v,pn;
Greg Banks7adae482006-10-04 02:15:47 -0700344 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 if (!(p = decode_fh(p, &args->fh))
347 || !(p = xdr_decode_hyper(p, &args->offset)))
348 return 0;
349
350 len = args->count = ntohl(*p++);
351
Greg Banks7adae482006-10-04 02:15:47 -0700352 if (len > max_blocksize)
353 len = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 /* set up the kvec */
356 v=0;
357 while (len > 0) {
NeilBrown44524352006-10-04 02:15:46 -0700358 pn = rqstp->rq_resused++;
NeilBrown3cc03b12006-10-04 02:15:47 -0700359 rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_respages[pn]);
360 rqstp->rq_vec[v].iov_len = len < PAGE_SIZE? len : PAGE_SIZE;
361 len -= rqstp->rq_vec[v].iov_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 v++;
363 }
364 args->vlen = v;
365 return xdr_argsize_check(rqstp, p);
366}
367
368int
Al Viro91f07162006-10-19 23:28:57 -0700369nfs3svc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 struct nfsd3_writeargs *args)
371{
372 unsigned int len, v, hdr;
Greg Banks7adae482006-10-04 02:15:47 -0700373 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 if (!(p = decode_fh(p, &args->fh))
376 || !(p = xdr_decode_hyper(p, &args->offset)))
377 return 0;
378
379 args->count = ntohl(*p++);
380 args->stable = ntohl(*p++);
381 len = args->len = ntohl(*p++);
382
383 hdr = (void*)p - rqstp->rq_arg.head[0].iov_base;
NeilBrown0ba75362005-11-07 01:00:26 -0800384 if (rqstp->rq_arg.len < hdr ||
385 rqstp->rq_arg.len - hdr < len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 return 0;
387
NeilBrown3cc03b12006-10-04 02:15:47 -0700388 rqstp->rq_vec[0].iov_base = (void*)p;
389 rqstp->rq_vec[0].iov_len = rqstp->rq_arg.head[0].iov_len - hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Greg Banks7adae482006-10-04 02:15:47 -0700391 if (len > max_blocksize)
392 len = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 v= 0;
NeilBrown3cc03b12006-10-04 02:15:47 -0700394 while (len > rqstp->rq_vec[v].iov_len) {
395 len -= rqstp->rq_vec[v].iov_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 v++;
NeilBrown3cc03b12006-10-04 02:15:47 -0700397 rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_pages[v]);
398 rqstp->rq_vec[v].iov_len = PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 }
NeilBrown3cc03b12006-10-04 02:15:47 -0700400 rqstp->rq_vec[v].iov_len = len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 args->vlen = v+1;
402
NeilBrown3cc03b12006-10-04 02:15:47 -0700403 return args->count == args->len && rqstp->rq_vec[0].iov_len > 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404}
405
406int
Al Viro91f07162006-10-19 23:28:57 -0700407nfs3svc_decode_createargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 struct nfsd3_createargs *args)
409{
410 if (!(p = decode_fh(p, &args->fh))
411 || !(p = decode_filename(p, &args->name, &args->len)))
412 return 0;
413
414 switch (args->createmode = ntohl(*p++)) {
415 case NFS3_CREATE_UNCHECKED:
416 case NFS3_CREATE_GUARDED:
417 if (!(p = decode_sattr3(p, &args->attrs)))
418 return 0;
419 break;
420 case NFS3_CREATE_EXCLUSIVE:
421 args->verf = p;
422 p += 2;
423 break;
424 default:
425 return 0;
426 }
427
428 return xdr_argsize_check(rqstp, p);
429}
430int
Al Viro91f07162006-10-19 23:28:57 -0700431nfs3svc_decode_mkdirargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 struct nfsd3_createargs *args)
433{
434 if (!(p = decode_fh(p, &args->fh))
435 || !(p = decode_filename(p, &args->name, &args->len))
436 || !(p = decode_sattr3(p, &args->attrs)))
437 return 0;
438
439 return xdr_argsize_check(rqstp, p);
440}
441
442int
Al Viro91f07162006-10-19 23:28:57 -0700443nfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 struct nfsd3_symlinkargs *args)
445{
446 unsigned int len;
447 int avail;
448 char *old, *new;
449 struct kvec *vec;
450
451 if (!(p = decode_fh(p, &args->ffh))
452 || !(p = decode_filename(p, &args->fname, &args->flen))
453 || !(p = decode_sattr3(p, &args->attrs))
454 )
455 return 0;
456 /* now decode the pathname, which might be larger than the first page.
457 * As we have to check for nul's anyway, we copy it into a new page
458 * This page appears in the rq_res.pages list, but as pages_len is always
459 * 0, it won't get in the way
460 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 len = ntohl(*p++);
462 if (len == 0 || len > NFS3_MAXPATHLEN || len >= PAGE_SIZE)
463 return 0;
NeilBrown44524352006-10-04 02:15:46 -0700464 args->tname = new =
465 page_address(rqstp->rq_respages[rqstp->rq_resused++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 args->tlen = len;
467 /* first copy and check from the first page */
468 old = (char*)p;
469 vec = &rqstp->rq_arg.head[0];
470 avail = vec->iov_len - (old - (char*)vec->iov_base);
471 while (len && avail && *old) {
472 *new++ = *old++;
473 len--;
474 avail--;
475 }
476 /* now copy next page if there is one */
477 if (len && !avail && rqstp->rq_arg.page_len) {
478 avail = rqstp->rq_arg.page_len;
479 if (avail > PAGE_SIZE) avail = PAGE_SIZE;
480 old = page_address(rqstp->rq_arg.pages[0]);
481 }
482 while (len && avail && *old) {
483 *new++ = *old++;
484 len--;
485 avail--;
486 }
487 *new = '\0';
488 if (len)
489 return 0;
490
491 return 1;
492}
493
494int
Al Viro91f07162006-10-19 23:28:57 -0700495nfs3svc_decode_mknodargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 struct nfsd3_mknodargs *args)
497{
498 if (!(p = decode_fh(p, &args->fh))
499 || !(p = decode_filename(p, &args->name, &args->len)))
500 return 0;
501
502 args->ftype = ntohl(*p++);
503
504 if (args->ftype == NF3BLK || args->ftype == NF3CHR
505 || args->ftype == NF3SOCK || args->ftype == NF3FIFO) {
506 if (!(p = decode_sattr3(p, &args->attrs)))
507 return 0;
508 }
509
510 if (args->ftype == NF3BLK || args->ftype == NF3CHR) {
511 args->major = ntohl(*p++);
512 args->minor = ntohl(*p++);
513 }
514
515 return xdr_argsize_check(rqstp, p);
516}
517
518int
Al Viro91f07162006-10-19 23:28:57 -0700519nfs3svc_decode_renameargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 struct nfsd3_renameargs *args)
521{
522 if (!(p = decode_fh(p, &args->ffh))
523 || !(p = decode_filename(p, &args->fname, &args->flen))
524 || !(p = decode_fh(p, &args->tfh))
525 || !(p = decode_filename(p, &args->tname, &args->tlen)))
526 return 0;
527
528 return xdr_argsize_check(rqstp, p);
529}
530
531int
Al Viro91f07162006-10-19 23:28:57 -0700532nfs3svc_decode_readlinkargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 struct nfsd3_readlinkargs *args)
534{
535 if (!(p = decode_fh(p, &args->fh)))
536 return 0;
NeilBrown44524352006-10-04 02:15:46 -0700537 args->buffer =
538 page_address(rqstp->rq_respages[rqstp->rq_resused++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540 return xdr_argsize_check(rqstp, p);
541}
542
543int
Al Viro91f07162006-10-19 23:28:57 -0700544nfs3svc_decode_linkargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 struct nfsd3_linkargs *args)
546{
547 if (!(p = decode_fh(p, &args->ffh))
548 || !(p = decode_fh(p, &args->tfh))
549 || !(p = decode_filename(p, &args->tname, &args->tlen)))
550 return 0;
551
552 return xdr_argsize_check(rqstp, p);
553}
554
555int
Al Viro91f07162006-10-19 23:28:57 -0700556nfs3svc_decode_readdirargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 struct nfsd3_readdirargs *args)
558{
559 if (!(p = decode_fh(p, &args->fh)))
560 return 0;
561 p = xdr_decode_hyper(p, &args->cookie);
562 args->verf = p; p += 2;
563 args->dircount = ~0;
564 args->count = ntohl(*p++);
565
566 if (args->count > PAGE_SIZE)
567 args->count = PAGE_SIZE;
568
NeilBrown44524352006-10-04 02:15:46 -0700569 args->buffer =
570 page_address(rqstp->rq_respages[rqstp->rq_resused++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572 return xdr_argsize_check(rqstp, p);
573}
574
575int
Al Viro91f07162006-10-19 23:28:57 -0700576nfs3svc_decode_readdirplusargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 struct nfsd3_readdirargs *args)
578{
579 int len, pn;
Greg Banks7adae482006-10-04 02:15:47 -0700580 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582 if (!(p = decode_fh(p, &args->fh)))
583 return 0;
584 p = xdr_decode_hyper(p, &args->cookie);
585 args->verf = p; p += 2;
586 args->dircount = ntohl(*p++);
587 args->count = ntohl(*p++);
588
Greg Banks7adae482006-10-04 02:15:47 -0700589 len = (args->count > max_blocksize) ? max_blocksize :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 args->count;
591 args->count = len;
592
593 while (len > 0) {
NeilBrown44524352006-10-04 02:15:46 -0700594 pn = rqstp->rq_resused++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 if (!args->buffer)
596 args->buffer = page_address(rqstp->rq_respages[pn]);
597 len -= PAGE_SIZE;
598 }
599
600 return xdr_argsize_check(rqstp, p);
601}
602
603int
Al Viro91f07162006-10-19 23:28:57 -0700604nfs3svc_decode_commitargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 struct nfsd3_commitargs *args)
606{
607 if (!(p = decode_fh(p, &args->fh)))
608 return 0;
609 p = xdr_decode_hyper(p, &args->offset);
610 args->count = ntohl(*p++);
611
612 return xdr_argsize_check(rqstp, p);
613}
614
615/*
616 * XDR encode functions
617 */
618/*
619 * There must be an encoding function for void results so svc_process
620 * will work properly.
621 */
622int
Al Viro91f07162006-10-19 23:28:57 -0700623nfs3svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
625 return xdr_ressize_check(rqstp, p);
626}
627
628/* GETATTR */
629int
Al Viro91f07162006-10-19 23:28:57 -0700630nfs3svc_encode_attrstat(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 struct nfsd3_attrstat *resp)
632{
633 if (resp->status == 0)
David Shawa334de22006-01-06 00:19:58 -0800634 p = encode_fattr3(rqstp, p, &resp->fh, &resp->stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 return xdr_ressize_check(rqstp, p);
636}
637
638/* SETATTR, REMOVE, RMDIR */
639int
Al Viro91f07162006-10-19 23:28:57 -0700640nfs3svc_encode_wccstat(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 struct nfsd3_attrstat *resp)
642{
643 p = encode_wcc_data(rqstp, p, &resp->fh);
644 return xdr_ressize_check(rqstp, p);
645}
646
647/* LOOKUP */
648int
Al Viro91f07162006-10-19 23:28:57 -0700649nfs3svc_encode_diropres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 struct nfsd3_diropres *resp)
651{
652 if (resp->status == 0) {
653 p = encode_fh(p, &resp->fh);
654 p = encode_post_op_attr(rqstp, p, &resp->fh);
655 }
656 p = encode_post_op_attr(rqstp, p, &resp->dirfh);
657 return xdr_ressize_check(rqstp, p);
658}
659
660/* ACCESS */
661int
Al Viro91f07162006-10-19 23:28:57 -0700662nfs3svc_encode_accessres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 struct nfsd3_accessres *resp)
664{
665 p = encode_post_op_attr(rqstp, p, &resp->fh);
666 if (resp->status == 0)
667 *p++ = htonl(resp->access);
668 return xdr_ressize_check(rqstp, p);
669}
670
671/* READLINK */
672int
Al Viro91f07162006-10-19 23:28:57 -0700673nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 struct nfsd3_readlinkres *resp)
675{
676 p = encode_post_op_attr(rqstp, p, &resp->fh);
677 if (resp->status == 0) {
678 *p++ = htonl(resp->len);
679 xdr_ressize_check(rqstp, p);
680 rqstp->rq_res.page_len = resp->len;
681 if (resp->len & 3) {
682 /* need to pad the tail */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 rqstp->rq_res.tail[0].iov_base = p;
684 *p = 0;
685 rqstp->rq_res.tail[0].iov_len = 4 - (resp->len&3);
686 }
687 return 1;
688 } else
689 return xdr_ressize_check(rqstp, p);
690}
691
692/* READ */
693int
Al Viro91f07162006-10-19 23:28:57 -0700694nfs3svc_encode_readres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 struct nfsd3_readres *resp)
696{
697 p = encode_post_op_attr(rqstp, p, &resp->fh);
698 if (resp->status == 0) {
699 *p++ = htonl(resp->count);
700 *p++ = htonl(resp->eof);
701 *p++ = htonl(resp->count); /* xdr opaque count */
702 xdr_ressize_check(rqstp, p);
703 /* now update rqstp->rq_res to reflect data aswell */
704 rqstp->rq_res.page_len = resp->count;
705 if (resp->count & 3) {
706 /* need to pad the tail */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 rqstp->rq_res.tail[0].iov_base = p;
708 *p = 0;
709 rqstp->rq_res.tail[0].iov_len = 4 - (resp->count & 3);
710 }
711 return 1;
712 } else
713 return xdr_ressize_check(rqstp, p);
714}
715
716/* WRITE */
717int
Al Viro91f07162006-10-19 23:28:57 -0700718nfs3svc_encode_writeres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 struct nfsd3_writeres *resp)
720{
721 p = encode_wcc_data(rqstp, p, &resp->fh);
722 if (resp->status == 0) {
723 *p++ = htonl(resp->count);
724 *p++ = htonl(resp->committed);
725 *p++ = htonl(nfssvc_boot.tv_sec);
726 *p++ = htonl(nfssvc_boot.tv_usec);
727 }
728 return xdr_ressize_check(rqstp, p);
729}
730
731/* CREATE, MKDIR, SYMLINK, MKNOD */
732int
Al Viro91f07162006-10-19 23:28:57 -0700733nfs3svc_encode_createres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 struct nfsd3_diropres *resp)
735{
736 if (resp->status == 0) {
737 *p++ = xdr_one;
738 p = encode_fh(p, &resp->fh);
739 p = encode_post_op_attr(rqstp, p, &resp->fh);
740 }
741 p = encode_wcc_data(rqstp, p, &resp->dirfh);
742 return xdr_ressize_check(rqstp, p);
743}
744
745/* RENAME */
746int
Al Viro91f07162006-10-19 23:28:57 -0700747nfs3svc_encode_renameres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 struct nfsd3_renameres *resp)
749{
750 p = encode_wcc_data(rqstp, p, &resp->ffh);
751 p = encode_wcc_data(rqstp, p, &resp->tfh);
752 return xdr_ressize_check(rqstp, p);
753}
754
755/* LINK */
756int
Al Viro91f07162006-10-19 23:28:57 -0700757nfs3svc_encode_linkres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 struct nfsd3_linkres *resp)
759{
760 p = encode_post_op_attr(rqstp, p, &resp->fh);
761 p = encode_wcc_data(rqstp, p, &resp->tfh);
762 return xdr_ressize_check(rqstp, p);
763}
764
765/* READDIR */
766int
Al Viro91f07162006-10-19 23:28:57 -0700767nfs3svc_encode_readdirres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 struct nfsd3_readdirres *resp)
769{
770 p = encode_post_op_attr(rqstp, p, &resp->fh);
771
772 if (resp->status == 0) {
773 /* stupid readdir cookie */
774 memcpy(p, resp->verf, 8); p += 2;
775 xdr_ressize_check(rqstp, p);
776 if (rqstp->rq_res.head[0].iov_len + (2<<2) > PAGE_SIZE)
777 return 1; /*No room for trailer */
778 rqstp->rq_res.page_len = (resp->count) << 2;
779
780 /* add the 'tail' to the end of the 'head' page - page 0. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 rqstp->rq_res.tail[0].iov_base = p;
782 *p++ = 0; /* no more entries */
783 *p++ = htonl(resp->common.err == nfserr_eof);
784 rqstp->rq_res.tail[0].iov_len = 2<<2;
785 return 1;
786 } else
787 return xdr_ressize_check(rqstp, p);
788}
789
Adrian Bunk3ee6f612006-12-06 20:40:23 -0800790static __be32 *
Al Viro91f07162006-10-19 23:28:57 -0700791encode_entry_baggage(struct nfsd3_readdirres *cd, __be32 *p, const char *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 int namlen, ino_t ino)
793{
794 *p++ = xdr_one; /* mark entry present */
795 p = xdr_encode_hyper(p, ino); /* file id */
796 p = xdr_encode_array(p, name, namlen);/* name length & name */
797
798 cd->offset = p; /* remember pointer */
799 p = xdr_encode_hyper(p, NFS_OFFSET_MAX);/* offset of next entry */
800
801 return p;
802}
803
Adrian Bunk3ee6f612006-12-06 20:40:23 -0800804static __be32 *
Al Viro91f07162006-10-19 23:28:57 -0700805encode_entryplus_baggage(struct nfsd3_readdirres *cd, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 struct svc_fh *fhp)
807{
808 p = encode_post_op_attr(cd->rqstp, p, fhp);
809 *p++ = xdr_one; /* yes, a file handle follows */
810 p = encode_fh(p, fhp);
811 fh_put(fhp);
812 return p;
813}
814
815static int
816compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,
817 const char *name, int namlen)
818{
819 struct svc_export *exp;
820 struct dentry *dparent, *dchild;
821 int rv = 0;
822
823 dparent = cd->fh.fh_dentry;
824 exp = cd->fh.fh_export;
825
826 fh_init(fhp, NFS3_FHSIZE);
827 if (isdotent(name, namlen)) {
828 if (namlen == 2) {
829 dchild = dget_parent(dparent);
830 if (dchild == dparent) {
831 /* filesystem root - cannot return filehandle for ".." */
832 dput(dchild);
833 return 1;
834 }
835 } else
836 dchild = dget(dparent);
837 } else
838 dchild = lookup_one_len(name, dparent, namlen);
839 if (IS_ERR(dchild))
840 return 1;
841 if (d_mountpoint(dchild) ||
842 fh_compose(fhp, exp, dchild, &cd->fh) != 0 ||
843 !dchild->d_inode)
844 rv = 1;
845 dput(dchild);
846 return rv;
847}
848
849/*
850 * Encode a directory entry. This one works for both normal readdir
851 * and readdirplus.
852 * The normal readdir reply requires 2 (fileid) + 1 (stringlen)
853 * + string + 2 (cookie) + 1 (next) words, i.e. 6 + strlen.
854 *
855 * The readdirplus baggage is 1+21 words for post_op_attr, plus the
856 * file handle.
857 */
858
859#define NFS3_ENTRY_BAGGAGE (2 + 1 + 2 + 1)
860#define NFS3_ENTRYPLUS_BAGGAGE (1 + 21 + 1 + (NFS3_FHSIZE >> 2))
861static int
NeilBrown598b9a52007-03-26 21:32:08 -0800862encode_entry(struct readdir_cd *ccd, const char *name, int namlen,
863 loff_t offset, ino_t ino, unsigned int d_type, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
865 struct nfsd3_readdirres *cd = container_of(ccd, struct nfsd3_readdirres,
866 common);
Al Viro91f07162006-10-19 23:28:57 -0700867 __be32 *p = cd->buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 caddr_t curr_page_addr = NULL;
869 int pn; /* current page number */
870 int slen; /* string (name) length */
871 int elen; /* estimated entry length in words */
872 int num_entry_words = 0; /* actual number of words */
873
874 if (cd->offset) {
875 u64 offset64 = offset;
876
877 if (unlikely(cd->offset1)) {
878 /* we ended up with offset on a page boundary */
879 *cd->offset = htonl(offset64 >> 32);
880 *cd->offset1 = htonl(offset64 & 0xffffffff);
881 cd->offset1 = NULL;
882 } else {
NeilBrown598b9a52007-03-26 21:32:08 -0800883 xdr_encode_hyper(cd->offset, offset64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 }
885 }
886
887 /*
888 dprintk("encode_entry(%.*s @%ld%s)\n",
889 namlen, name, (long) offset, plus? " plus" : "");
890 */
891
892 /* truncate filename if too long */
893 if (namlen > NFS3_MAXNAMLEN)
894 namlen = NFS3_MAXNAMLEN;
895
896 slen = XDR_QUADLEN(namlen);
897 elen = slen + NFS3_ENTRY_BAGGAGE
898 + (plus? NFS3_ENTRYPLUS_BAGGAGE : 0);
899
900 if (cd->buflen < elen) {
901 cd->common.err = nfserr_toosmall;
902 return -EINVAL;
903 }
904
905 /* determine which page in rq_respages[] we are currently filling */
906 for (pn=1; pn < cd->rqstp->rq_resused; pn++) {
907 curr_page_addr = page_address(cd->rqstp->rq_respages[pn]);
908
909 if (((caddr_t)cd->buffer >= curr_page_addr) &&
910 ((caddr_t)cd->buffer < curr_page_addr + PAGE_SIZE))
911 break;
912 }
913
914 if ((caddr_t)(cd->buffer + elen) < (curr_page_addr + PAGE_SIZE)) {
915 /* encode entry in current page */
916
917 p = encode_entry_baggage(cd, p, name, namlen, ino);
918
919 /* throw in readdirplus baggage */
920 if (plus) {
921 struct svc_fh fh;
922
923 if (compose_entry_fh(cd, &fh, name, namlen) > 0) {
924 *p++ = 0;
925 *p++ = 0;
926 } else
927 p = encode_entryplus_baggage(cd, p, &fh);
928 }
929 num_entry_words = p - cd->buffer;
930 } else if (cd->rqstp->rq_respages[pn+1] != NULL) {
931 /* temporarily encode entry into next page, then move back to
932 * current and next page in rq_respages[] */
Al Viro91f07162006-10-19 23:28:57 -0700933 __be32 *p1, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 int len1, len2;
935
936 /* grab next page for temporary storage of entry */
937 p1 = tmp = page_address(cd->rqstp->rq_respages[pn+1]);
938
939 p1 = encode_entry_baggage(cd, p1, name, namlen, ino);
940
941 /* throw in readdirplus baggage */
942 if (plus) {
943 struct svc_fh fh;
944
945 if (compose_entry_fh(cd, &fh, name, namlen) > 0) {
946 /* zero out the filehandle */
947 *p1++ = 0;
948 *p1++ = 0;
949 } else
950 p1 = encode_entryplus_baggage(cd, p1, &fh);
951 }
952
953 /* determine entry word length and lengths to go in pages */
954 num_entry_words = p1 - tmp;
955 len1 = curr_page_addr + PAGE_SIZE - (caddr_t)cd->buffer;
956 if ((num_entry_words << 2) < len1) {
957 /* the actual number of words in the entry is less
958 * than elen and can still fit in the current page
959 */
960 memmove(p, tmp, num_entry_words << 2);
961 p += num_entry_words;
962
963 /* update offset */
964 cd->offset = cd->buffer + (cd->offset - tmp);
965 } else {
966 unsigned int offset_r = (cd->offset - tmp) << 2;
967
968 /* update pointer to offset location.
969 * This is a 64bit quantity, so we need to
970 * deal with 3 cases:
971 * - entirely in first page
972 * - entirely in second page
973 * - 4 bytes in each page
974 */
975 if (offset_r + 8 <= len1) {
976 cd->offset = p + (cd->offset - tmp);
977 } else if (offset_r >= len1) {
978 cd->offset -= len1 >> 2;
979 } else {
980 /* sitting on the fence */
981 BUG_ON(offset_r != len1 - 4);
982 cd->offset = p + (cd->offset - tmp);
983 cd->offset1 = tmp;
984 }
985
986 len2 = (num_entry_words << 2) - len1;
987
988 /* move from temp page to current and next pages */
989 memmove(p, tmp, len1);
990 memmove(tmp, (caddr_t)tmp+len1, len2);
991
992 p = tmp + (len2 >> 2);
993 }
994 }
995 else {
996 cd->common.err = nfserr_toosmall;
997 return -EINVAL;
998 }
999
1000 cd->buflen -= num_entry_words;
1001 cd->buffer = p;
1002 cd->common.err = nfs_ok;
1003 return 0;
1004
1005}
1006
1007int
NeilBrowna0ad13e2007-01-26 00:57:10 -08001008nfs3svc_encode_entry(void *cd, const char *name,
1009 int namlen, loff_t offset, u64 ino, unsigned int d_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
1011 return encode_entry(cd, name, namlen, offset, ino, d_type, 0);
1012}
1013
1014int
NeilBrowna0ad13e2007-01-26 00:57:10 -08001015nfs3svc_encode_entry_plus(void *cd, const char *name,
1016 int namlen, loff_t offset, u64 ino,
1017 unsigned int d_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
1019 return encode_entry(cd, name, namlen, offset, ino, d_type, 1);
1020}
1021
1022/* FSSTAT */
1023int
Al Viro91f07162006-10-19 23:28:57 -07001024nfs3svc_encode_fsstatres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 struct nfsd3_fsstatres *resp)
1026{
1027 struct kstatfs *s = &resp->stats;
1028 u64 bs = s->f_bsize;
1029
1030 *p++ = xdr_zero; /* no post_op_attr */
1031
1032 if (resp->status == 0) {
1033 p = xdr_encode_hyper(p, bs * s->f_blocks); /* total bytes */
1034 p = xdr_encode_hyper(p, bs * s->f_bfree); /* free bytes */
1035 p = xdr_encode_hyper(p, bs * s->f_bavail); /* user available bytes */
1036 p = xdr_encode_hyper(p, s->f_files); /* total inodes */
1037 p = xdr_encode_hyper(p, s->f_ffree); /* free inodes */
1038 p = xdr_encode_hyper(p, s->f_ffree); /* user available inodes */
1039 *p++ = htonl(resp->invarsec); /* mean unchanged time */
1040 }
1041 return xdr_ressize_check(rqstp, p);
1042}
1043
1044/* FSINFO */
1045int
Al Viro91f07162006-10-19 23:28:57 -07001046nfs3svc_encode_fsinfores(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 struct nfsd3_fsinfores *resp)
1048{
1049 *p++ = xdr_zero; /* no post_op_attr */
1050
1051 if (resp->status == 0) {
1052 *p++ = htonl(resp->f_rtmax);
1053 *p++ = htonl(resp->f_rtpref);
1054 *p++ = htonl(resp->f_rtmult);
1055 *p++ = htonl(resp->f_wtmax);
1056 *p++ = htonl(resp->f_wtpref);
1057 *p++ = htonl(resp->f_wtmult);
1058 *p++ = htonl(resp->f_dtpref);
1059 p = xdr_encode_hyper(p, resp->f_maxfilesize);
1060 *p++ = xdr_one;
1061 *p++ = xdr_zero;
1062 *p++ = htonl(resp->f_properties);
1063 }
1064
1065 return xdr_ressize_check(rqstp, p);
1066}
1067
1068/* PATHCONF */
1069int
Al Viro91f07162006-10-19 23:28:57 -07001070nfs3svc_encode_pathconfres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 struct nfsd3_pathconfres *resp)
1072{
1073 *p++ = xdr_zero; /* no post_op_attr */
1074
1075 if (resp->status == 0) {
1076 *p++ = htonl(resp->p_link_max);
1077 *p++ = htonl(resp->p_name_max);
1078 *p++ = htonl(resp->p_no_trunc);
1079 *p++ = htonl(resp->p_chown_restricted);
1080 *p++ = htonl(resp->p_case_insensitive);
1081 *p++ = htonl(resp->p_case_preserving);
1082 }
1083
1084 return xdr_ressize_check(rqstp, p);
1085}
1086
1087/* COMMIT */
1088int
Al Viro91f07162006-10-19 23:28:57 -07001089nfs3svc_encode_commitres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 struct nfsd3_commitres *resp)
1091{
1092 p = encode_wcc_data(rqstp, p, &resp->fh);
1093 /* Write verifier */
1094 if (resp->status == 0) {
1095 *p++ = htonl(nfssvc_boot.tv_sec);
1096 *p++ = htonl(nfssvc_boot.tv_usec);
1097 }
1098 return xdr_ressize_check(rqstp, p);
1099}
1100
1101/*
1102 * XDR release functions
1103 */
1104int
Al Viro91f07162006-10-19 23:28:57 -07001105nfs3svc_release_fhandle(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 struct nfsd3_attrstat *resp)
1107{
1108 fh_put(&resp->fh);
1109 return 1;
1110}
1111
1112int
Al Viro91f07162006-10-19 23:28:57 -07001113nfs3svc_release_fhandle2(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 struct nfsd3_fhandle_pair *resp)
1115{
1116 fh_put(&resp->fh1);
1117 fh_put(&resp->fh2);
1118 return 1;
1119}