blob: e695660921ec30adfd6f0ebb3546120ee536964e [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
Adrian Bunk3ee6f612006-12-06 20:40:23 -0800152static __be32 *
Al Viro91f07162006-10-19 23:28:57 -0700153encode_fattr3(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp,
David Shawa334de22006-01-06 00:19:58 -0800154 struct kstat *stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 struct dentry *dentry = fhp->fh_dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 struct timespec time;
158
David Shawa334de22006-01-06 00:19:58 -0800159 *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
160 *p++ = htonl((u32) stat->mode);
161 *p++ = htonl((u32) stat->nlink);
162 *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
163 *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
164 if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
166 } else {
David Shawa334de22006-01-06 00:19:58 -0800167 p = xdr_encode_hyper(p, (u64) stat->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
David Shawa334de22006-01-06 00:19:58 -0800169 p = xdr_encode_hyper(p, ((u64)stat->blocks) << 9);
170 *p++ = htonl((u32) MAJOR(stat->rdev));
171 *p++ = htonl((u32) MINOR(stat->rdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 if (is_fsid(fhp, rqstp->rq_reffh))
173 p = xdr_encode_hyper(p, (u64) fhp->fh_export->ex_fsid);
174 else
David Shawa334de22006-01-06 00:19:58 -0800175 p = xdr_encode_hyper(p, (u64) huge_encode_dev(stat->dev));
176 p = xdr_encode_hyper(p, (u64) stat->ino);
177 p = encode_time3(p, &stat->atime);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 lease_get_mtime(dentry->d_inode, &time);
179 p = encode_time3(p, &time);
David Shawa334de22006-01-06 00:19:58 -0800180 p = encode_time3(p, &stat->ctime);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 return p;
183}
184
Adrian Bunk3ee6f612006-12-06 20:40:23 -0800185static __be32 *
Al Viro91f07162006-10-19 23:28:57 -0700186encode_saved_post_attr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 struct inode *inode = fhp->fh_dentry->d_inode;
189
190 /* Attributes to follow */
191 *p++ = xdr_one;
192
193 *p++ = htonl(nfs3_ftypes[(fhp->fh_post_mode & S_IFMT) >> 12]);
194 *p++ = htonl((u32) fhp->fh_post_mode);
195 *p++ = htonl((u32) fhp->fh_post_nlink);
196 *p++ = htonl((u32) nfsd_ruid(rqstp, fhp->fh_post_uid));
197 *p++ = htonl((u32) nfsd_rgid(rqstp, fhp->fh_post_gid));
198 if (S_ISLNK(fhp->fh_post_mode) && fhp->fh_post_size > NFS3_MAXPATHLEN) {
199 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
200 } else {
201 p = xdr_encode_hyper(p, (u64) fhp->fh_post_size);
202 }
203 p = xdr_encode_hyper(p, ((u64)fhp->fh_post_blocks) << 9);
204 *p++ = fhp->fh_post_rdev[0];
205 *p++ = fhp->fh_post_rdev[1];
206 if (is_fsid(fhp, rqstp->rq_reffh))
207 p = xdr_encode_hyper(p, (u64) fhp->fh_export->ex_fsid);
208 else
209 p = xdr_encode_hyper(p, (u64)huge_encode_dev(inode->i_sb->s_dev));
210 p = xdr_encode_hyper(p, (u64) inode->i_ino);
211 p = encode_time3(p, &fhp->fh_post_atime);
212 p = encode_time3(p, &fhp->fh_post_mtime);
213 p = encode_time3(p, &fhp->fh_post_ctime);
214
215 return p;
216}
217
218/*
219 * Encode post-operation attributes.
220 * The inode may be NULL if the call failed because of a stale file
221 * handle. In this case, no attributes are returned.
222 */
Al Viro91f07162006-10-19 23:28:57 -0700223static __be32 *
224encode_post_op_attr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
226 struct dentry *dentry = fhp->fh_dentry;
227 if (dentry && dentry->d_inode != NULL) {
David Shawa334de22006-01-06 00:19:58 -0800228 int err;
229 struct kstat stat;
230
231 err = vfs_getattr(fhp->fh_export->ex_mnt, dentry, &stat);
232 if (!err) {
233 *p++ = xdr_one; /* attributes follow */
234 return encode_fattr3(rqstp, p, fhp, &stat);
235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
237 *p++ = xdr_zero;
238 return p;
239}
240
Andreas Gruenbachera257cdd2005-06-22 17:16:26 +0000241/* Helper for NFSv3 ACLs */
Al Viro91f07162006-10-19 23:28:57 -0700242__be32 *
243nfs3svc_encode_post_op_attr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
Andreas Gruenbachera257cdd2005-06-22 17:16:26 +0000244{
245 return encode_post_op_attr(rqstp, p, fhp);
246}
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248/*
249 * Enocde weak cache consistency data
250 */
Al Viro91f07162006-10-19 23:28:57 -0700251static __be32 *
252encode_wcc_data(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
254 struct dentry *dentry = fhp->fh_dentry;
255
256 if (dentry && dentry->d_inode && fhp->fh_post_saved) {
257 if (fhp->fh_pre_saved) {
258 *p++ = xdr_one;
259 p = xdr_encode_hyper(p, (u64) fhp->fh_pre_size);
260 p = encode_time3(p, &fhp->fh_pre_mtime);
261 p = encode_time3(p, &fhp->fh_pre_ctime);
262 } else {
263 *p++ = xdr_zero;
264 }
265 return encode_saved_post_attr(rqstp, p, fhp);
266 }
267 /* no pre- or post-attrs */
268 *p++ = xdr_zero;
269 return encode_post_op_attr(rqstp, p, fhp);
270}
271
272
273/*
274 * XDR decode functions
275 */
276int
Al Viro91f07162006-10-19 23:28:57 -0700277nfs3svc_decode_fhandle(struct svc_rqst *rqstp, __be32 *p, struct nfsd_fhandle *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
279 if (!(p = decode_fh(p, &args->fh)))
280 return 0;
281 return xdr_argsize_check(rqstp, p);
282}
283
284int
Al Viro91f07162006-10-19 23:28:57 -0700285nfs3svc_decode_sattrargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 struct nfsd3_sattrargs *args)
287{
288 if (!(p = decode_fh(p, &args->fh))
289 || !(p = decode_sattr3(p, &args->attrs)))
290 return 0;
291
292 if ((args->check_guard = ntohl(*p++)) != 0) {
293 struct timespec time;
294 p = decode_time3(p, &time);
295 args->guardtime = time.tv_sec;
296 }
297
298 return xdr_argsize_check(rqstp, p);
299}
300
301int
Al Viro91f07162006-10-19 23:28:57 -0700302nfs3svc_decode_diropargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 struct nfsd3_diropargs *args)
304{
305 if (!(p = decode_fh(p, &args->fh))
306 || !(p = decode_filename(p, &args->name, &args->len)))
307 return 0;
308
309 return xdr_argsize_check(rqstp, p);
310}
311
312int
Al Viro91f07162006-10-19 23:28:57 -0700313nfs3svc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 struct nfsd3_accessargs *args)
315{
316 if (!(p = decode_fh(p, &args->fh)))
317 return 0;
318 args->access = ntohl(*p++);
319
320 return xdr_argsize_check(rqstp, p);
321}
322
323int
Al Viro91f07162006-10-19 23:28:57 -0700324nfs3svc_decode_readargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 struct nfsd3_readargs *args)
326{
327 unsigned int len;
328 int v,pn;
Greg Banks7adae482006-10-04 02:15:47 -0700329 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 if (!(p = decode_fh(p, &args->fh))
332 || !(p = xdr_decode_hyper(p, &args->offset)))
333 return 0;
334
335 len = args->count = ntohl(*p++);
336
Greg Banks7adae482006-10-04 02:15:47 -0700337 if (len > max_blocksize)
338 len = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 /* set up the kvec */
341 v=0;
342 while (len > 0) {
NeilBrown44524352006-10-04 02:15:46 -0700343 pn = rqstp->rq_resused++;
NeilBrown3cc03b12006-10-04 02:15:47 -0700344 rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_respages[pn]);
345 rqstp->rq_vec[v].iov_len = len < PAGE_SIZE? len : PAGE_SIZE;
346 len -= rqstp->rq_vec[v].iov_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 v++;
348 }
349 args->vlen = v;
350 return xdr_argsize_check(rqstp, p);
351}
352
353int
Al Viro91f07162006-10-19 23:28:57 -0700354nfs3svc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 struct nfsd3_writeargs *args)
356{
357 unsigned int len, v, hdr;
Greg Banks7adae482006-10-04 02:15:47 -0700358 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 if (!(p = decode_fh(p, &args->fh))
361 || !(p = xdr_decode_hyper(p, &args->offset)))
362 return 0;
363
364 args->count = ntohl(*p++);
365 args->stable = ntohl(*p++);
366 len = args->len = ntohl(*p++);
367
368 hdr = (void*)p - rqstp->rq_arg.head[0].iov_base;
NeilBrown0ba75362005-11-07 01:00:26 -0800369 if (rqstp->rq_arg.len < hdr ||
370 rqstp->rq_arg.len - hdr < len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return 0;
372
NeilBrown3cc03b12006-10-04 02:15:47 -0700373 rqstp->rq_vec[0].iov_base = (void*)p;
374 rqstp->rq_vec[0].iov_len = rqstp->rq_arg.head[0].iov_len - hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Greg Banks7adae482006-10-04 02:15:47 -0700376 if (len > max_blocksize)
377 len = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 v= 0;
NeilBrown3cc03b12006-10-04 02:15:47 -0700379 while (len > rqstp->rq_vec[v].iov_len) {
380 len -= rqstp->rq_vec[v].iov_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 v++;
NeilBrown3cc03b12006-10-04 02:15:47 -0700382 rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_pages[v]);
383 rqstp->rq_vec[v].iov_len = PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 }
NeilBrown3cc03b12006-10-04 02:15:47 -0700385 rqstp->rq_vec[v].iov_len = len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 args->vlen = v+1;
387
NeilBrown3cc03b12006-10-04 02:15:47 -0700388 return args->count == args->len && rqstp->rq_vec[0].iov_len > 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
391int
Al Viro91f07162006-10-19 23:28:57 -0700392nfs3svc_decode_createargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 struct nfsd3_createargs *args)
394{
395 if (!(p = decode_fh(p, &args->fh))
396 || !(p = decode_filename(p, &args->name, &args->len)))
397 return 0;
398
399 switch (args->createmode = ntohl(*p++)) {
400 case NFS3_CREATE_UNCHECKED:
401 case NFS3_CREATE_GUARDED:
402 if (!(p = decode_sattr3(p, &args->attrs)))
403 return 0;
404 break;
405 case NFS3_CREATE_EXCLUSIVE:
406 args->verf = p;
407 p += 2;
408 break;
409 default:
410 return 0;
411 }
412
413 return xdr_argsize_check(rqstp, p);
414}
415int
Al Viro91f07162006-10-19 23:28:57 -0700416nfs3svc_decode_mkdirargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 struct nfsd3_createargs *args)
418{
419 if (!(p = decode_fh(p, &args->fh))
420 || !(p = decode_filename(p, &args->name, &args->len))
421 || !(p = decode_sattr3(p, &args->attrs)))
422 return 0;
423
424 return xdr_argsize_check(rqstp, p);
425}
426
427int
Al Viro91f07162006-10-19 23:28:57 -0700428nfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 struct nfsd3_symlinkargs *args)
430{
431 unsigned int len;
432 int avail;
433 char *old, *new;
434 struct kvec *vec;
435
436 if (!(p = decode_fh(p, &args->ffh))
437 || !(p = decode_filename(p, &args->fname, &args->flen))
438 || !(p = decode_sattr3(p, &args->attrs))
439 )
440 return 0;
441 /* now decode the pathname, which might be larger than the first page.
442 * As we have to check for nul's anyway, we copy it into a new page
443 * This page appears in the rq_res.pages list, but as pages_len is always
444 * 0, it won't get in the way
445 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 len = ntohl(*p++);
447 if (len == 0 || len > NFS3_MAXPATHLEN || len >= PAGE_SIZE)
448 return 0;
NeilBrown44524352006-10-04 02:15:46 -0700449 args->tname = new =
450 page_address(rqstp->rq_respages[rqstp->rq_resused++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 args->tlen = len;
452 /* first copy and check from the first page */
453 old = (char*)p;
454 vec = &rqstp->rq_arg.head[0];
455 avail = vec->iov_len - (old - (char*)vec->iov_base);
456 while (len && avail && *old) {
457 *new++ = *old++;
458 len--;
459 avail--;
460 }
461 /* now copy next page if there is one */
462 if (len && !avail && rqstp->rq_arg.page_len) {
463 avail = rqstp->rq_arg.page_len;
464 if (avail > PAGE_SIZE) avail = PAGE_SIZE;
465 old = page_address(rqstp->rq_arg.pages[0]);
466 }
467 while (len && avail && *old) {
468 *new++ = *old++;
469 len--;
470 avail--;
471 }
472 *new = '\0';
473 if (len)
474 return 0;
475
476 return 1;
477}
478
479int
Al Viro91f07162006-10-19 23:28:57 -0700480nfs3svc_decode_mknodargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 struct nfsd3_mknodargs *args)
482{
483 if (!(p = decode_fh(p, &args->fh))
484 || !(p = decode_filename(p, &args->name, &args->len)))
485 return 0;
486
487 args->ftype = ntohl(*p++);
488
489 if (args->ftype == NF3BLK || args->ftype == NF3CHR
490 || args->ftype == NF3SOCK || args->ftype == NF3FIFO) {
491 if (!(p = decode_sattr3(p, &args->attrs)))
492 return 0;
493 }
494
495 if (args->ftype == NF3BLK || args->ftype == NF3CHR) {
496 args->major = ntohl(*p++);
497 args->minor = ntohl(*p++);
498 }
499
500 return xdr_argsize_check(rqstp, p);
501}
502
503int
Al Viro91f07162006-10-19 23:28:57 -0700504nfs3svc_decode_renameargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 struct nfsd3_renameargs *args)
506{
507 if (!(p = decode_fh(p, &args->ffh))
508 || !(p = decode_filename(p, &args->fname, &args->flen))
509 || !(p = decode_fh(p, &args->tfh))
510 || !(p = decode_filename(p, &args->tname, &args->tlen)))
511 return 0;
512
513 return xdr_argsize_check(rqstp, p);
514}
515
516int
Al Viro91f07162006-10-19 23:28:57 -0700517nfs3svc_decode_readlinkargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 struct nfsd3_readlinkargs *args)
519{
520 if (!(p = decode_fh(p, &args->fh)))
521 return 0;
NeilBrown44524352006-10-04 02:15:46 -0700522 args->buffer =
523 page_address(rqstp->rq_respages[rqstp->rq_resused++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 return xdr_argsize_check(rqstp, p);
526}
527
528int
Al Viro91f07162006-10-19 23:28:57 -0700529nfs3svc_decode_linkargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 struct nfsd3_linkargs *args)
531{
532 if (!(p = decode_fh(p, &args->ffh))
533 || !(p = decode_fh(p, &args->tfh))
534 || !(p = decode_filename(p, &args->tname, &args->tlen)))
535 return 0;
536
537 return xdr_argsize_check(rqstp, p);
538}
539
540int
Al Viro91f07162006-10-19 23:28:57 -0700541nfs3svc_decode_readdirargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 struct nfsd3_readdirargs *args)
543{
544 if (!(p = decode_fh(p, &args->fh)))
545 return 0;
546 p = xdr_decode_hyper(p, &args->cookie);
547 args->verf = p; p += 2;
548 args->dircount = ~0;
549 args->count = ntohl(*p++);
550
551 if (args->count > PAGE_SIZE)
552 args->count = PAGE_SIZE;
553
NeilBrown44524352006-10-04 02:15:46 -0700554 args->buffer =
555 page_address(rqstp->rq_respages[rqstp->rq_resused++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 return xdr_argsize_check(rqstp, p);
558}
559
560int
Al Viro91f07162006-10-19 23:28:57 -0700561nfs3svc_decode_readdirplusargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 struct nfsd3_readdirargs *args)
563{
564 int len, pn;
Greg Banks7adae482006-10-04 02:15:47 -0700565 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
567 if (!(p = decode_fh(p, &args->fh)))
568 return 0;
569 p = xdr_decode_hyper(p, &args->cookie);
570 args->verf = p; p += 2;
571 args->dircount = ntohl(*p++);
572 args->count = ntohl(*p++);
573
Greg Banks7adae482006-10-04 02:15:47 -0700574 len = (args->count > max_blocksize) ? max_blocksize :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 args->count;
576 args->count = len;
577
578 while (len > 0) {
NeilBrown44524352006-10-04 02:15:46 -0700579 pn = rqstp->rq_resused++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 if (!args->buffer)
581 args->buffer = page_address(rqstp->rq_respages[pn]);
582 len -= PAGE_SIZE;
583 }
584
585 return xdr_argsize_check(rqstp, p);
586}
587
588int
Al Viro91f07162006-10-19 23:28:57 -0700589nfs3svc_decode_commitargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 struct nfsd3_commitargs *args)
591{
592 if (!(p = decode_fh(p, &args->fh)))
593 return 0;
594 p = xdr_decode_hyper(p, &args->offset);
595 args->count = ntohl(*p++);
596
597 return xdr_argsize_check(rqstp, p);
598}
599
600/*
601 * XDR encode functions
602 */
603/*
604 * There must be an encoding function for void results so svc_process
605 * will work properly.
606 */
607int
Al Viro91f07162006-10-19 23:28:57 -0700608nfs3svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
610 return xdr_ressize_check(rqstp, p);
611}
612
613/* GETATTR */
614int
Al Viro91f07162006-10-19 23:28:57 -0700615nfs3svc_encode_attrstat(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 struct nfsd3_attrstat *resp)
617{
618 if (resp->status == 0)
David Shawa334de22006-01-06 00:19:58 -0800619 p = encode_fattr3(rqstp, p, &resp->fh, &resp->stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 return xdr_ressize_check(rqstp, p);
621}
622
623/* SETATTR, REMOVE, RMDIR */
624int
Al Viro91f07162006-10-19 23:28:57 -0700625nfs3svc_encode_wccstat(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 struct nfsd3_attrstat *resp)
627{
628 p = encode_wcc_data(rqstp, p, &resp->fh);
629 return xdr_ressize_check(rqstp, p);
630}
631
632/* LOOKUP */
633int
Al Viro91f07162006-10-19 23:28:57 -0700634nfs3svc_encode_diropres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 struct nfsd3_diropres *resp)
636{
637 if (resp->status == 0) {
638 p = encode_fh(p, &resp->fh);
639 p = encode_post_op_attr(rqstp, p, &resp->fh);
640 }
641 p = encode_post_op_attr(rqstp, p, &resp->dirfh);
642 return xdr_ressize_check(rqstp, p);
643}
644
645/* ACCESS */
646int
Al Viro91f07162006-10-19 23:28:57 -0700647nfs3svc_encode_accessres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 struct nfsd3_accessres *resp)
649{
650 p = encode_post_op_attr(rqstp, p, &resp->fh);
651 if (resp->status == 0)
652 *p++ = htonl(resp->access);
653 return xdr_ressize_check(rqstp, p);
654}
655
656/* READLINK */
657int
Al Viro91f07162006-10-19 23:28:57 -0700658nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 struct nfsd3_readlinkres *resp)
660{
661 p = encode_post_op_attr(rqstp, p, &resp->fh);
662 if (resp->status == 0) {
663 *p++ = htonl(resp->len);
664 xdr_ressize_check(rqstp, p);
665 rqstp->rq_res.page_len = resp->len;
666 if (resp->len & 3) {
667 /* need to pad the tail */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 rqstp->rq_res.tail[0].iov_base = p;
669 *p = 0;
670 rqstp->rq_res.tail[0].iov_len = 4 - (resp->len&3);
671 }
672 return 1;
673 } else
674 return xdr_ressize_check(rqstp, p);
675}
676
677/* READ */
678int
Al Viro91f07162006-10-19 23:28:57 -0700679nfs3svc_encode_readres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 struct nfsd3_readres *resp)
681{
682 p = encode_post_op_attr(rqstp, p, &resp->fh);
683 if (resp->status == 0) {
684 *p++ = htonl(resp->count);
685 *p++ = htonl(resp->eof);
686 *p++ = htonl(resp->count); /* xdr opaque count */
687 xdr_ressize_check(rqstp, p);
688 /* now update rqstp->rq_res to reflect data aswell */
689 rqstp->rq_res.page_len = resp->count;
690 if (resp->count & 3) {
691 /* need to pad the tail */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 rqstp->rq_res.tail[0].iov_base = p;
693 *p = 0;
694 rqstp->rq_res.tail[0].iov_len = 4 - (resp->count & 3);
695 }
696 return 1;
697 } else
698 return xdr_ressize_check(rqstp, p);
699}
700
701/* WRITE */
702int
Al Viro91f07162006-10-19 23:28:57 -0700703nfs3svc_encode_writeres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 struct nfsd3_writeres *resp)
705{
706 p = encode_wcc_data(rqstp, p, &resp->fh);
707 if (resp->status == 0) {
708 *p++ = htonl(resp->count);
709 *p++ = htonl(resp->committed);
710 *p++ = htonl(nfssvc_boot.tv_sec);
711 *p++ = htonl(nfssvc_boot.tv_usec);
712 }
713 return xdr_ressize_check(rqstp, p);
714}
715
716/* CREATE, MKDIR, SYMLINK, MKNOD */
717int
Al Viro91f07162006-10-19 23:28:57 -0700718nfs3svc_encode_createres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 struct nfsd3_diropres *resp)
720{
721 if (resp->status == 0) {
722 *p++ = xdr_one;
723 p = encode_fh(p, &resp->fh);
724 p = encode_post_op_attr(rqstp, p, &resp->fh);
725 }
726 p = encode_wcc_data(rqstp, p, &resp->dirfh);
727 return xdr_ressize_check(rqstp, p);
728}
729
730/* RENAME */
731int
Al Viro91f07162006-10-19 23:28:57 -0700732nfs3svc_encode_renameres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 struct nfsd3_renameres *resp)
734{
735 p = encode_wcc_data(rqstp, p, &resp->ffh);
736 p = encode_wcc_data(rqstp, p, &resp->tfh);
737 return xdr_ressize_check(rqstp, p);
738}
739
740/* LINK */
741int
Al Viro91f07162006-10-19 23:28:57 -0700742nfs3svc_encode_linkres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 struct nfsd3_linkres *resp)
744{
745 p = encode_post_op_attr(rqstp, p, &resp->fh);
746 p = encode_wcc_data(rqstp, p, &resp->tfh);
747 return xdr_ressize_check(rqstp, p);
748}
749
750/* READDIR */
751int
Al Viro91f07162006-10-19 23:28:57 -0700752nfs3svc_encode_readdirres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 struct nfsd3_readdirres *resp)
754{
755 p = encode_post_op_attr(rqstp, p, &resp->fh);
756
757 if (resp->status == 0) {
758 /* stupid readdir cookie */
759 memcpy(p, resp->verf, 8); p += 2;
760 xdr_ressize_check(rqstp, p);
761 if (rqstp->rq_res.head[0].iov_len + (2<<2) > PAGE_SIZE)
762 return 1; /*No room for trailer */
763 rqstp->rq_res.page_len = (resp->count) << 2;
764
765 /* add the 'tail' to the end of the 'head' page - page 0. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 rqstp->rq_res.tail[0].iov_base = p;
767 *p++ = 0; /* no more entries */
768 *p++ = htonl(resp->common.err == nfserr_eof);
769 rqstp->rq_res.tail[0].iov_len = 2<<2;
770 return 1;
771 } else
772 return xdr_ressize_check(rqstp, p);
773}
774
Adrian Bunk3ee6f612006-12-06 20:40:23 -0800775static __be32 *
Al Viro91f07162006-10-19 23:28:57 -0700776encode_entry_baggage(struct nfsd3_readdirres *cd, __be32 *p, const char *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 int namlen, ino_t ino)
778{
779 *p++ = xdr_one; /* mark entry present */
780 p = xdr_encode_hyper(p, ino); /* file id */
781 p = xdr_encode_array(p, name, namlen);/* name length & name */
782
783 cd->offset = p; /* remember pointer */
784 p = xdr_encode_hyper(p, NFS_OFFSET_MAX);/* offset of next entry */
785
786 return p;
787}
788
Adrian Bunk3ee6f612006-12-06 20:40:23 -0800789static __be32 *
Al Viro91f07162006-10-19 23:28:57 -0700790encode_entryplus_baggage(struct nfsd3_readdirres *cd, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 struct svc_fh *fhp)
792{
793 p = encode_post_op_attr(cd->rqstp, p, fhp);
794 *p++ = xdr_one; /* yes, a file handle follows */
795 p = encode_fh(p, fhp);
796 fh_put(fhp);
797 return p;
798}
799
800static int
801compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,
802 const char *name, int namlen)
803{
804 struct svc_export *exp;
805 struct dentry *dparent, *dchild;
806 int rv = 0;
807
808 dparent = cd->fh.fh_dentry;
809 exp = cd->fh.fh_export;
810
811 fh_init(fhp, NFS3_FHSIZE);
812 if (isdotent(name, namlen)) {
813 if (namlen == 2) {
814 dchild = dget_parent(dparent);
815 if (dchild == dparent) {
816 /* filesystem root - cannot return filehandle for ".." */
817 dput(dchild);
818 return 1;
819 }
820 } else
821 dchild = dget(dparent);
822 } else
823 dchild = lookup_one_len(name, dparent, namlen);
824 if (IS_ERR(dchild))
825 return 1;
826 if (d_mountpoint(dchild) ||
827 fh_compose(fhp, exp, dchild, &cd->fh) != 0 ||
828 !dchild->d_inode)
829 rv = 1;
830 dput(dchild);
831 return rv;
832}
833
834/*
835 * Encode a directory entry. This one works for both normal readdir
836 * and readdirplus.
837 * The normal readdir reply requires 2 (fileid) + 1 (stringlen)
838 * + string + 2 (cookie) + 1 (next) words, i.e. 6 + strlen.
839 *
840 * The readdirplus baggage is 1+21 words for post_op_attr, plus the
841 * file handle.
842 */
843
844#define NFS3_ENTRY_BAGGAGE (2 + 1 + 2 + 1)
845#define NFS3_ENTRYPLUS_BAGGAGE (1 + 21 + 1 + (NFS3_FHSIZE >> 2))
846static int
847encode_entry(struct readdir_cd *ccd, const char *name,
848 int namlen, off_t offset, ino_t ino, unsigned int d_type, int plus)
849{
850 struct nfsd3_readdirres *cd = container_of(ccd, struct nfsd3_readdirres,
851 common);
Al Viro91f07162006-10-19 23:28:57 -0700852 __be32 *p = cd->buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 caddr_t curr_page_addr = NULL;
854 int pn; /* current page number */
855 int slen; /* string (name) length */
856 int elen; /* estimated entry length in words */
857 int num_entry_words = 0; /* actual number of words */
858
859 if (cd->offset) {
860 u64 offset64 = offset;
861
862 if (unlikely(cd->offset1)) {
863 /* we ended up with offset on a page boundary */
864 *cd->offset = htonl(offset64 >> 32);
865 *cd->offset1 = htonl(offset64 & 0xffffffff);
866 cd->offset1 = NULL;
867 } else {
868 xdr_encode_hyper(cd->offset, (u64) offset);
869 }
870 }
871
872 /*
873 dprintk("encode_entry(%.*s @%ld%s)\n",
874 namlen, name, (long) offset, plus? " plus" : "");
875 */
876
877 /* truncate filename if too long */
878 if (namlen > NFS3_MAXNAMLEN)
879 namlen = NFS3_MAXNAMLEN;
880
881 slen = XDR_QUADLEN(namlen);
882 elen = slen + NFS3_ENTRY_BAGGAGE
883 + (plus? NFS3_ENTRYPLUS_BAGGAGE : 0);
884
885 if (cd->buflen < elen) {
886 cd->common.err = nfserr_toosmall;
887 return -EINVAL;
888 }
889
890 /* determine which page in rq_respages[] we are currently filling */
891 for (pn=1; pn < cd->rqstp->rq_resused; pn++) {
892 curr_page_addr = page_address(cd->rqstp->rq_respages[pn]);
893
894 if (((caddr_t)cd->buffer >= curr_page_addr) &&
895 ((caddr_t)cd->buffer < curr_page_addr + PAGE_SIZE))
896 break;
897 }
898
899 if ((caddr_t)(cd->buffer + elen) < (curr_page_addr + PAGE_SIZE)) {
900 /* encode entry in current page */
901
902 p = encode_entry_baggage(cd, p, name, namlen, ino);
903
904 /* throw in readdirplus baggage */
905 if (plus) {
906 struct svc_fh fh;
907
908 if (compose_entry_fh(cd, &fh, name, namlen) > 0) {
909 *p++ = 0;
910 *p++ = 0;
911 } else
912 p = encode_entryplus_baggage(cd, p, &fh);
913 }
914 num_entry_words = p - cd->buffer;
915 } else if (cd->rqstp->rq_respages[pn+1] != NULL) {
916 /* temporarily encode entry into next page, then move back to
917 * current and next page in rq_respages[] */
Al Viro91f07162006-10-19 23:28:57 -0700918 __be32 *p1, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 int len1, len2;
920
921 /* grab next page for temporary storage of entry */
922 p1 = tmp = page_address(cd->rqstp->rq_respages[pn+1]);
923
924 p1 = encode_entry_baggage(cd, p1, name, namlen, ino);
925
926 /* throw in readdirplus baggage */
927 if (plus) {
928 struct svc_fh fh;
929
930 if (compose_entry_fh(cd, &fh, name, namlen) > 0) {
931 /* zero out the filehandle */
932 *p1++ = 0;
933 *p1++ = 0;
934 } else
935 p1 = encode_entryplus_baggage(cd, p1, &fh);
936 }
937
938 /* determine entry word length and lengths to go in pages */
939 num_entry_words = p1 - tmp;
940 len1 = curr_page_addr + PAGE_SIZE - (caddr_t)cd->buffer;
941 if ((num_entry_words << 2) < len1) {
942 /* the actual number of words in the entry is less
943 * than elen and can still fit in the current page
944 */
945 memmove(p, tmp, num_entry_words << 2);
946 p += num_entry_words;
947
948 /* update offset */
949 cd->offset = cd->buffer + (cd->offset - tmp);
950 } else {
951 unsigned int offset_r = (cd->offset - tmp) << 2;
952
953 /* update pointer to offset location.
954 * This is a 64bit quantity, so we need to
955 * deal with 3 cases:
956 * - entirely in first page
957 * - entirely in second page
958 * - 4 bytes in each page
959 */
960 if (offset_r + 8 <= len1) {
961 cd->offset = p + (cd->offset - tmp);
962 } else if (offset_r >= len1) {
963 cd->offset -= len1 >> 2;
964 } else {
965 /* sitting on the fence */
966 BUG_ON(offset_r != len1 - 4);
967 cd->offset = p + (cd->offset - tmp);
968 cd->offset1 = tmp;
969 }
970
971 len2 = (num_entry_words << 2) - len1;
972
973 /* move from temp page to current and next pages */
974 memmove(p, tmp, len1);
975 memmove(tmp, (caddr_t)tmp+len1, len2);
976
977 p = tmp + (len2 >> 2);
978 }
979 }
980 else {
981 cd->common.err = nfserr_toosmall;
982 return -EINVAL;
983 }
984
985 cd->buflen -= num_entry_words;
986 cd->buffer = p;
987 cd->common.err = nfs_ok;
988 return 0;
989
990}
991
992int
NeilBrowna0ad13e2007-01-26 00:57:10 -0800993nfs3svc_encode_entry(void *cd, const char *name,
994 int namlen, loff_t offset, u64 ino, unsigned int d_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
996 return encode_entry(cd, name, namlen, offset, ino, d_type, 0);
997}
998
999int
NeilBrowna0ad13e2007-01-26 00:57:10 -08001000nfs3svc_encode_entry_plus(void *cd, const char *name,
1001 int namlen, loff_t offset, u64 ino,
1002 unsigned int d_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003{
1004 return encode_entry(cd, name, namlen, offset, ino, d_type, 1);
1005}
1006
1007/* FSSTAT */
1008int
Al Viro91f07162006-10-19 23:28:57 -07001009nfs3svc_encode_fsstatres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 struct nfsd3_fsstatres *resp)
1011{
1012 struct kstatfs *s = &resp->stats;
1013 u64 bs = s->f_bsize;
1014
1015 *p++ = xdr_zero; /* no post_op_attr */
1016
1017 if (resp->status == 0) {
1018 p = xdr_encode_hyper(p, bs * s->f_blocks); /* total bytes */
1019 p = xdr_encode_hyper(p, bs * s->f_bfree); /* free bytes */
1020 p = xdr_encode_hyper(p, bs * s->f_bavail); /* user available bytes */
1021 p = xdr_encode_hyper(p, s->f_files); /* total inodes */
1022 p = xdr_encode_hyper(p, s->f_ffree); /* free inodes */
1023 p = xdr_encode_hyper(p, s->f_ffree); /* user available inodes */
1024 *p++ = htonl(resp->invarsec); /* mean unchanged time */
1025 }
1026 return xdr_ressize_check(rqstp, p);
1027}
1028
1029/* FSINFO */
1030int
Al Viro91f07162006-10-19 23:28:57 -07001031nfs3svc_encode_fsinfores(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 struct nfsd3_fsinfores *resp)
1033{
1034 *p++ = xdr_zero; /* no post_op_attr */
1035
1036 if (resp->status == 0) {
1037 *p++ = htonl(resp->f_rtmax);
1038 *p++ = htonl(resp->f_rtpref);
1039 *p++ = htonl(resp->f_rtmult);
1040 *p++ = htonl(resp->f_wtmax);
1041 *p++ = htonl(resp->f_wtpref);
1042 *p++ = htonl(resp->f_wtmult);
1043 *p++ = htonl(resp->f_dtpref);
1044 p = xdr_encode_hyper(p, resp->f_maxfilesize);
1045 *p++ = xdr_one;
1046 *p++ = xdr_zero;
1047 *p++ = htonl(resp->f_properties);
1048 }
1049
1050 return xdr_ressize_check(rqstp, p);
1051}
1052
1053/* PATHCONF */
1054int
Al Viro91f07162006-10-19 23:28:57 -07001055nfs3svc_encode_pathconfres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 struct nfsd3_pathconfres *resp)
1057{
1058 *p++ = xdr_zero; /* no post_op_attr */
1059
1060 if (resp->status == 0) {
1061 *p++ = htonl(resp->p_link_max);
1062 *p++ = htonl(resp->p_name_max);
1063 *p++ = htonl(resp->p_no_trunc);
1064 *p++ = htonl(resp->p_chown_restricted);
1065 *p++ = htonl(resp->p_case_insensitive);
1066 *p++ = htonl(resp->p_case_preserving);
1067 }
1068
1069 return xdr_ressize_check(rqstp, p);
1070}
1071
1072/* COMMIT */
1073int
Al Viro91f07162006-10-19 23:28:57 -07001074nfs3svc_encode_commitres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 struct nfsd3_commitres *resp)
1076{
1077 p = encode_wcc_data(rqstp, p, &resp->fh);
1078 /* Write verifier */
1079 if (resp->status == 0) {
1080 *p++ = htonl(nfssvc_boot.tv_sec);
1081 *p++ = htonl(nfssvc_boot.tv_usec);
1082 }
1083 return xdr_ressize_check(rqstp, p);
1084}
1085
1086/*
1087 * XDR release functions
1088 */
1089int
Al Viro91f07162006-10-19 23:28:57 -07001090nfs3svc_release_fhandle(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 struct nfsd3_attrstat *resp)
1092{
1093 fh_put(&resp->fh);
1094 return 1;
1095}
1096
1097int
Al Viro91f07162006-10-19 23:28:57 -07001098nfs3svc_release_fhandle2(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 struct nfsd3_fhandle_pair *resp)
1100{
1101 fh_put(&resp->fh1);
1102 fh_put(&resp->fh2);
1103 return 1;
1104}