blob: 10f6e7dcf6336b48746cd6c16d7ed5c1d04cae28 [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;
NeilBrown072f62e2007-05-09 02:34:57 -0700242 if (dentry && dentry->d_inode) {
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{
NeilBrown072f62e2007-05-09 02:34:57 -0700303 if (!(p = decode_fh(p, &args->fh)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 return 0;
NeilBrown072f62e2007-05-09 02:34:57 -0700305 p = decode_sattr3(p, &args->attrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
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
NeilBrown072f62e2007-05-09 02:34:57 -0700346 if (!(p = decode_fh(p, &args->fh)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 return 0;
NeilBrown072f62e2007-05-09 02:34:57 -0700348 p = xdr_decode_hyper(p, &args->offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
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{
Peter Staubachf34b9562007-05-09 02:34:48 -0700372 unsigned int len, v, hdr, dlen;
Greg Banks7adae482006-10-04 02:15:47 -0700373 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
NeilBrown072f62e2007-05-09 02:34:57 -0700375 if (!(p = decode_fh(p, &args->fh)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return 0;
NeilBrown072f62e2007-05-09 02:34:57 -0700377 p = xdr_decode_hyper(p, &args->offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379 args->count = ntohl(*p++);
380 args->stable = ntohl(*p++);
381 len = args->len = ntohl(*p++);
Peter Staubachf34b9562007-05-09 02:34:48 -0700382 /*
383 * The count must equal the amount of data passed.
384 */
385 if (args->count != args->len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 return 0;
387
Peter Staubachf34b9562007-05-09 02:34:48 -0700388 /*
389 * Check to make sure that we got the right number of
390 * bytes.
Peter Staubachf34b9562007-05-09 02:34:48 -0700391 */
392 hdr = (void*)p - rqstp->rq_arg.head[0].iov_base;
NeilBrown072f62e2007-05-09 02:34:57 -0700393 dlen = rqstp->rq_arg.head[0].iov_len + rqstp->rq_arg.page_len
394 - hdr;
Peter Staubachf34b9562007-05-09 02:34:48 -0700395 /*
396 * Round the length of the data which was specified up to
397 * the next multiple of XDR units and then compare that
398 * against the length which was actually received.
399 */
NeilBrown072f62e2007-05-09 02:34:57 -0700400 if (dlen != XDR_QUADLEN(len)*4)
Peter Staubachf34b9562007-05-09 02:34:48 -0700401 return 0;
402
403 if (args->count > max_blocksize) {
404 args->count = max_blocksize;
405 len = args->len = max_blocksize;
406 }
NeilBrown3cc03b12006-10-04 02:15:47 -0700407 rqstp->rq_vec[0].iov_base = (void*)p;
408 rqstp->rq_vec[0].iov_len = rqstp->rq_arg.head[0].iov_len - hdr;
Peter Staubachf34b9562007-05-09 02:34:48 -0700409 v = 0;
NeilBrown3cc03b12006-10-04 02:15:47 -0700410 while (len > rqstp->rq_vec[v].iov_len) {
411 len -= rqstp->rq_vec[v].iov_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 v++;
NeilBrown3cc03b12006-10-04 02:15:47 -0700413 rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_pages[v]);
414 rqstp->rq_vec[v].iov_len = PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
NeilBrown3cc03b12006-10-04 02:15:47 -0700416 rqstp->rq_vec[v].iov_len = len;
Peter Staubachf34b9562007-05-09 02:34:48 -0700417 args->vlen = v + 1;
418 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420
421int
Al Viro91f07162006-10-19 23:28:57 -0700422nfs3svc_decode_createargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 struct nfsd3_createargs *args)
424{
425 if (!(p = decode_fh(p, &args->fh))
426 || !(p = decode_filename(p, &args->name, &args->len)))
427 return 0;
428
429 switch (args->createmode = ntohl(*p++)) {
430 case NFS3_CREATE_UNCHECKED:
431 case NFS3_CREATE_GUARDED:
NeilBrown072f62e2007-05-09 02:34:57 -0700432 p = decode_sattr3(p, &args->attrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 break;
434 case NFS3_CREATE_EXCLUSIVE:
435 args->verf = p;
436 p += 2;
437 break;
438 default:
439 return 0;
440 }
441
442 return xdr_argsize_check(rqstp, p);
443}
444int
Al Viro91f07162006-10-19 23:28:57 -0700445nfs3svc_decode_mkdirargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 struct nfsd3_createargs *args)
447{
NeilBrown072f62e2007-05-09 02:34:57 -0700448 if (!(p = decode_fh(p, &args->fh)) ||
449 !(p = decode_filename(p, &args->name, &args->len)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 return 0;
NeilBrown072f62e2007-05-09 02:34:57 -0700451 p = decode_sattr3(p, &args->attrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 return xdr_argsize_check(rqstp, p);
454}
455
456int
Al Viro91f07162006-10-19 23:28:57 -0700457nfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 struct nfsd3_symlinkargs *args)
459{
460 unsigned int len;
461 int avail;
462 char *old, *new;
463 struct kvec *vec;
464
NeilBrown072f62e2007-05-09 02:34:57 -0700465 if (!(p = decode_fh(p, &args->ffh)) ||
466 !(p = decode_filename(p, &args->fname, &args->flen))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 )
468 return 0;
NeilBrown072f62e2007-05-09 02:34:57 -0700469 p = decode_sattr3(p, &args->attrs);
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 /* now decode the pathname, which might be larger than the first page.
472 * As we have to check for nul's anyway, we copy it into a new page
473 * This page appears in the rq_res.pages list, but as pages_len is always
474 * 0, it won't get in the way
475 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 len = ntohl(*p++);
477 if (len == 0 || len > NFS3_MAXPATHLEN || len >= PAGE_SIZE)
478 return 0;
NeilBrown44524352006-10-04 02:15:46 -0700479 args->tname = new =
480 page_address(rqstp->rq_respages[rqstp->rq_resused++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 args->tlen = len;
482 /* first copy and check from the first page */
483 old = (char*)p;
484 vec = &rqstp->rq_arg.head[0];
485 avail = vec->iov_len - (old - (char*)vec->iov_base);
486 while (len && avail && *old) {
487 *new++ = *old++;
488 len--;
489 avail--;
490 }
491 /* now copy next page if there is one */
492 if (len && !avail && rqstp->rq_arg.page_len) {
493 avail = rqstp->rq_arg.page_len;
494 if (avail > PAGE_SIZE) avail = PAGE_SIZE;
495 old = page_address(rqstp->rq_arg.pages[0]);
496 }
497 while (len && avail && *old) {
498 *new++ = *old++;
499 len--;
500 avail--;
501 }
502 *new = '\0';
503 if (len)
504 return 0;
505
506 return 1;
507}
508
509int
Al Viro91f07162006-10-19 23:28:57 -0700510nfs3svc_decode_mknodargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 struct nfsd3_mknodargs *args)
512{
513 if (!(p = decode_fh(p, &args->fh))
514 || !(p = decode_filename(p, &args->name, &args->len)))
515 return 0;
516
517 args->ftype = ntohl(*p++);
518
519 if (args->ftype == NF3BLK || args->ftype == NF3CHR
NeilBrown072f62e2007-05-09 02:34:57 -0700520 || args->ftype == NF3SOCK || args->ftype == NF3FIFO)
521 p = decode_sattr3(p, &args->attrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 if (args->ftype == NF3BLK || args->ftype == NF3CHR) {
524 args->major = ntohl(*p++);
525 args->minor = ntohl(*p++);
526 }
527
528 return xdr_argsize_check(rqstp, p);
529}
530
531int
Al Viro91f07162006-10-19 23:28:57 -0700532nfs3svc_decode_renameargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 struct nfsd3_renameargs *args)
534{
535 if (!(p = decode_fh(p, &args->ffh))
536 || !(p = decode_filename(p, &args->fname, &args->flen))
537 || !(p = decode_fh(p, &args->tfh))
538 || !(p = decode_filename(p, &args->tname, &args->tlen)))
539 return 0;
540
541 return xdr_argsize_check(rqstp, p);
542}
543
544int
Al Viro91f07162006-10-19 23:28:57 -0700545nfs3svc_decode_readlinkargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 struct nfsd3_readlinkargs *args)
547{
548 if (!(p = decode_fh(p, &args->fh)))
549 return 0;
NeilBrown44524352006-10-04 02:15:46 -0700550 args->buffer =
551 page_address(rqstp->rq_respages[rqstp->rq_resused++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 return xdr_argsize_check(rqstp, p);
554}
555
556int
Al Viro91f07162006-10-19 23:28:57 -0700557nfs3svc_decode_linkargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 struct nfsd3_linkargs *args)
559{
560 if (!(p = decode_fh(p, &args->ffh))
561 || !(p = decode_fh(p, &args->tfh))
562 || !(p = decode_filename(p, &args->tname, &args->tlen)))
563 return 0;
564
565 return xdr_argsize_check(rqstp, p);
566}
567
568int
Al Viro91f07162006-10-19 23:28:57 -0700569nfs3svc_decode_readdirargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 struct nfsd3_readdirargs *args)
571{
572 if (!(p = decode_fh(p, &args->fh)))
573 return 0;
574 p = xdr_decode_hyper(p, &args->cookie);
575 args->verf = p; p += 2;
576 args->dircount = ~0;
577 args->count = ntohl(*p++);
578
579 if (args->count > PAGE_SIZE)
580 args->count = PAGE_SIZE;
581
NeilBrown44524352006-10-04 02:15:46 -0700582 args->buffer =
583 page_address(rqstp->rq_respages[rqstp->rq_resused++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 return xdr_argsize_check(rqstp, p);
586}
587
588int
Al Viro91f07162006-10-19 23:28:57 -0700589nfs3svc_decode_readdirplusargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 struct nfsd3_readdirargs *args)
591{
592 int len, pn;
Greg Banks7adae482006-10-04 02:15:47 -0700593 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595 if (!(p = decode_fh(p, &args->fh)))
596 return 0;
597 p = xdr_decode_hyper(p, &args->cookie);
598 args->verf = p; p += 2;
599 args->dircount = ntohl(*p++);
600 args->count = ntohl(*p++);
601
Greg Banks7adae482006-10-04 02:15:47 -0700602 len = (args->count > max_blocksize) ? max_blocksize :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 args->count;
604 args->count = len;
605
606 while (len > 0) {
NeilBrown44524352006-10-04 02:15:46 -0700607 pn = rqstp->rq_resused++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 if (!args->buffer)
609 args->buffer = page_address(rqstp->rq_respages[pn]);
610 len -= PAGE_SIZE;
611 }
612
613 return xdr_argsize_check(rqstp, p);
614}
615
616int
Al Viro91f07162006-10-19 23:28:57 -0700617nfs3svc_decode_commitargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 struct nfsd3_commitargs *args)
619{
620 if (!(p = decode_fh(p, &args->fh)))
621 return 0;
622 p = xdr_decode_hyper(p, &args->offset);
623 args->count = ntohl(*p++);
624
625 return xdr_argsize_check(rqstp, p);
626}
627
628/*
629 * XDR encode functions
630 */
631/*
632 * There must be an encoding function for void results so svc_process
633 * will work properly.
634 */
635int
Al Viro91f07162006-10-19 23:28:57 -0700636nfs3svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
638 return xdr_ressize_check(rqstp, p);
639}
640
641/* GETATTR */
642int
Al Viro91f07162006-10-19 23:28:57 -0700643nfs3svc_encode_attrstat(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 struct nfsd3_attrstat *resp)
645{
646 if (resp->status == 0)
David Shawa334de22006-01-06 00:19:58 -0800647 p = encode_fattr3(rqstp, p, &resp->fh, &resp->stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return xdr_ressize_check(rqstp, p);
649}
650
651/* SETATTR, REMOVE, RMDIR */
652int
Al Viro91f07162006-10-19 23:28:57 -0700653nfs3svc_encode_wccstat(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 struct nfsd3_attrstat *resp)
655{
656 p = encode_wcc_data(rqstp, p, &resp->fh);
657 return xdr_ressize_check(rqstp, p);
658}
659
660/* LOOKUP */
661int
Al Viro91f07162006-10-19 23:28:57 -0700662nfs3svc_encode_diropres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 struct nfsd3_diropres *resp)
664{
665 if (resp->status == 0) {
666 p = encode_fh(p, &resp->fh);
667 p = encode_post_op_attr(rqstp, p, &resp->fh);
668 }
669 p = encode_post_op_attr(rqstp, p, &resp->dirfh);
670 return xdr_ressize_check(rqstp, p);
671}
672
673/* ACCESS */
674int
Al Viro91f07162006-10-19 23:28:57 -0700675nfs3svc_encode_accessres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 struct nfsd3_accessres *resp)
677{
678 p = encode_post_op_attr(rqstp, p, &resp->fh);
679 if (resp->status == 0)
680 *p++ = htonl(resp->access);
681 return xdr_ressize_check(rqstp, p);
682}
683
684/* READLINK */
685int
Al Viro91f07162006-10-19 23:28:57 -0700686nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 struct nfsd3_readlinkres *resp)
688{
689 p = encode_post_op_attr(rqstp, p, &resp->fh);
690 if (resp->status == 0) {
691 *p++ = htonl(resp->len);
692 xdr_ressize_check(rqstp, p);
693 rqstp->rq_res.page_len = resp->len;
694 if (resp->len & 3) {
695 /* need to pad the tail */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 rqstp->rq_res.tail[0].iov_base = p;
697 *p = 0;
698 rqstp->rq_res.tail[0].iov_len = 4 - (resp->len&3);
699 }
700 return 1;
701 } else
702 return xdr_ressize_check(rqstp, p);
703}
704
705/* READ */
706int
Al Viro91f07162006-10-19 23:28:57 -0700707nfs3svc_encode_readres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 struct nfsd3_readres *resp)
709{
710 p = encode_post_op_attr(rqstp, p, &resp->fh);
711 if (resp->status == 0) {
712 *p++ = htonl(resp->count);
713 *p++ = htonl(resp->eof);
714 *p++ = htonl(resp->count); /* xdr opaque count */
715 xdr_ressize_check(rqstp, p);
716 /* now update rqstp->rq_res to reflect data aswell */
717 rqstp->rq_res.page_len = resp->count;
718 if (resp->count & 3) {
719 /* need to pad the tail */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 rqstp->rq_res.tail[0].iov_base = p;
721 *p = 0;
722 rqstp->rq_res.tail[0].iov_len = 4 - (resp->count & 3);
723 }
724 return 1;
725 } else
726 return xdr_ressize_check(rqstp, p);
727}
728
729/* WRITE */
730int
Al Viro91f07162006-10-19 23:28:57 -0700731nfs3svc_encode_writeres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 struct nfsd3_writeres *resp)
733{
734 p = encode_wcc_data(rqstp, p, &resp->fh);
735 if (resp->status == 0) {
736 *p++ = htonl(resp->count);
737 *p++ = htonl(resp->committed);
738 *p++ = htonl(nfssvc_boot.tv_sec);
739 *p++ = htonl(nfssvc_boot.tv_usec);
740 }
741 return xdr_ressize_check(rqstp, p);
742}
743
744/* CREATE, MKDIR, SYMLINK, MKNOD */
745int
Al Viro91f07162006-10-19 23:28:57 -0700746nfs3svc_encode_createres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 struct nfsd3_diropres *resp)
748{
749 if (resp->status == 0) {
750 *p++ = xdr_one;
751 p = encode_fh(p, &resp->fh);
752 p = encode_post_op_attr(rqstp, p, &resp->fh);
753 }
754 p = encode_wcc_data(rqstp, p, &resp->dirfh);
755 return xdr_ressize_check(rqstp, p);
756}
757
758/* RENAME */
759int
Al Viro91f07162006-10-19 23:28:57 -0700760nfs3svc_encode_renameres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 struct nfsd3_renameres *resp)
762{
763 p = encode_wcc_data(rqstp, p, &resp->ffh);
764 p = encode_wcc_data(rqstp, p, &resp->tfh);
765 return xdr_ressize_check(rqstp, p);
766}
767
768/* LINK */
769int
Al Viro91f07162006-10-19 23:28:57 -0700770nfs3svc_encode_linkres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 struct nfsd3_linkres *resp)
772{
773 p = encode_post_op_attr(rqstp, p, &resp->fh);
774 p = encode_wcc_data(rqstp, p, &resp->tfh);
775 return xdr_ressize_check(rqstp, p);
776}
777
778/* READDIR */
779int
Al Viro91f07162006-10-19 23:28:57 -0700780nfs3svc_encode_readdirres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 struct nfsd3_readdirres *resp)
782{
783 p = encode_post_op_attr(rqstp, p, &resp->fh);
784
785 if (resp->status == 0) {
786 /* stupid readdir cookie */
787 memcpy(p, resp->verf, 8); p += 2;
788 xdr_ressize_check(rqstp, p);
789 if (rqstp->rq_res.head[0].iov_len + (2<<2) > PAGE_SIZE)
790 return 1; /*No room for trailer */
791 rqstp->rq_res.page_len = (resp->count) << 2;
792
793 /* add the 'tail' to the end of the 'head' page - page 0. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 rqstp->rq_res.tail[0].iov_base = p;
795 *p++ = 0; /* no more entries */
796 *p++ = htonl(resp->common.err == nfserr_eof);
797 rqstp->rq_res.tail[0].iov_len = 2<<2;
798 return 1;
799 } else
800 return xdr_ressize_check(rqstp, p);
801}
802
Adrian Bunk3ee6f612006-12-06 20:40:23 -0800803static __be32 *
Al Viro91f07162006-10-19 23:28:57 -0700804encode_entry_baggage(struct nfsd3_readdirres *cd, __be32 *p, const char *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 int namlen, ino_t ino)
806{
807 *p++ = xdr_one; /* mark entry present */
808 p = xdr_encode_hyper(p, ino); /* file id */
809 p = xdr_encode_array(p, name, namlen);/* name length & name */
810
811 cd->offset = p; /* remember pointer */
812 p = xdr_encode_hyper(p, NFS_OFFSET_MAX);/* offset of next entry */
813
814 return p;
815}
816
Adrian Bunk3ee6f612006-12-06 20:40:23 -0800817static __be32 *
Al Viro91f07162006-10-19 23:28:57 -0700818encode_entryplus_baggage(struct nfsd3_readdirres *cd, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 struct svc_fh *fhp)
820{
821 p = encode_post_op_attr(cd->rqstp, p, fhp);
822 *p++ = xdr_one; /* yes, a file handle follows */
823 p = encode_fh(p, fhp);
824 fh_put(fhp);
825 return p;
826}
827
828static int
829compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,
830 const char *name, int namlen)
831{
832 struct svc_export *exp;
833 struct dentry *dparent, *dchild;
834 int rv = 0;
835
836 dparent = cd->fh.fh_dentry;
837 exp = cd->fh.fh_export;
838
839 fh_init(fhp, NFS3_FHSIZE);
840 if (isdotent(name, namlen)) {
841 if (namlen == 2) {
842 dchild = dget_parent(dparent);
843 if (dchild == dparent) {
844 /* filesystem root - cannot return filehandle for ".." */
845 dput(dchild);
846 return 1;
847 }
848 } else
849 dchild = dget(dparent);
850 } else
851 dchild = lookup_one_len(name, dparent, namlen);
852 if (IS_ERR(dchild))
853 return 1;
854 if (d_mountpoint(dchild) ||
855 fh_compose(fhp, exp, dchild, &cd->fh) != 0 ||
856 !dchild->d_inode)
857 rv = 1;
858 dput(dchild);
859 return rv;
860}
861
862/*
863 * Encode a directory entry. This one works for both normal readdir
864 * and readdirplus.
865 * The normal readdir reply requires 2 (fileid) + 1 (stringlen)
866 * + string + 2 (cookie) + 1 (next) words, i.e. 6 + strlen.
867 *
868 * The readdirplus baggage is 1+21 words for post_op_attr, plus the
869 * file handle.
870 */
871
872#define NFS3_ENTRY_BAGGAGE (2 + 1 + 2 + 1)
873#define NFS3_ENTRYPLUS_BAGGAGE (1 + 21 + 1 + (NFS3_FHSIZE >> 2))
874static int
NeilBrown598b9a52007-03-26 21:32:08 -0800875encode_entry(struct readdir_cd *ccd, const char *name, int namlen,
876 loff_t offset, ino_t ino, unsigned int d_type, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
878 struct nfsd3_readdirres *cd = container_of(ccd, struct nfsd3_readdirres,
879 common);
Al Viro91f07162006-10-19 23:28:57 -0700880 __be32 *p = cd->buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 caddr_t curr_page_addr = NULL;
882 int pn; /* current page number */
883 int slen; /* string (name) length */
884 int elen; /* estimated entry length in words */
885 int num_entry_words = 0; /* actual number of words */
886
887 if (cd->offset) {
888 u64 offset64 = offset;
889
890 if (unlikely(cd->offset1)) {
891 /* we ended up with offset on a page boundary */
892 *cd->offset = htonl(offset64 >> 32);
893 *cd->offset1 = htonl(offset64 & 0xffffffff);
894 cd->offset1 = NULL;
895 } else {
NeilBrown598b9a52007-03-26 21:32:08 -0800896 xdr_encode_hyper(cd->offset, offset64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 }
898 }
899
900 /*
901 dprintk("encode_entry(%.*s @%ld%s)\n",
902 namlen, name, (long) offset, plus? " plus" : "");
903 */
904
905 /* truncate filename if too long */
906 if (namlen > NFS3_MAXNAMLEN)
907 namlen = NFS3_MAXNAMLEN;
908
909 slen = XDR_QUADLEN(namlen);
910 elen = slen + NFS3_ENTRY_BAGGAGE
911 + (plus? NFS3_ENTRYPLUS_BAGGAGE : 0);
912
913 if (cd->buflen < elen) {
914 cd->common.err = nfserr_toosmall;
915 return -EINVAL;
916 }
917
918 /* determine which page in rq_respages[] we are currently filling */
919 for (pn=1; pn < cd->rqstp->rq_resused; pn++) {
920 curr_page_addr = page_address(cd->rqstp->rq_respages[pn]);
921
922 if (((caddr_t)cd->buffer >= curr_page_addr) &&
923 ((caddr_t)cd->buffer < curr_page_addr + PAGE_SIZE))
924 break;
925 }
926
927 if ((caddr_t)(cd->buffer + elen) < (curr_page_addr + PAGE_SIZE)) {
928 /* encode entry in current page */
929
930 p = encode_entry_baggage(cd, p, name, namlen, ino);
931
932 /* throw in readdirplus baggage */
933 if (plus) {
934 struct svc_fh fh;
935
936 if (compose_entry_fh(cd, &fh, name, namlen) > 0) {
937 *p++ = 0;
938 *p++ = 0;
939 } else
940 p = encode_entryplus_baggage(cd, p, &fh);
941 }
942 num_entry_words = p - cd->buffer;
943 } else if (cd->rqstp->rq_respages[pn+1] != NULL) {
944 /* temporarily encode entry into next page, then move back to
945 * current and next page in rq_respages[] */
Al Viro91f07162006-10-19 23:28:57 -0700946 __be32 *p1, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 int len1, len2;
948
949 /* grab next page for temporary storage of entry */
950 p1 = tmp = page_address(cd->rqstp->rq_respages[pn+1]);
951
952 p1 = encode_entry_baggage(cd, p1, name, namlen, ino);
953
954 /* throw in readdirplus baggage */
955 if (plus) {
956 struct svc_fh fh;
957
958 if (compose_entry_fh(cd, &fh, name, namlen) > 0) {
959 /* zero out the filehandle */
960 *p1++ = 0;
961 *p1++ = 0;
962 } else
963 p1 = encode_entryplus_baggage(cd, p1, &fh);
964 }
965
966 /* determine entry word length and lengths to go in pages */
967 num_entry_words = p1 - tmp;
968 len1 = curr_page_addr + PAGE_SIZE - (caddr_t)cd->buffer;
969 if ((num_entry_words << 2) < len1) {
970 /* the actual number of words in the entry is less
971 * than elen and can still fit in the current page
972 */
973 memmove(p, tmp, num_entry_words << 2);
974 p += num_entry_words;
975
976 /* update offset */
977 cd->offset = cd->buffer + (cd->offset - tmp);
978 } else {
979 unsigned int offset_r = (cd->offset - tmp) << 2;
980
981 /* update pointer to offset location.
982 * This is a 64bit quantity, so we need to
983 * deal with 3 cases:
984 * - entirely in first page
985 * - entirely in second page
986 * - 4 bytes in each page
987 */
988 if (offset_r + 8 <= len1) {
989 cd->offset = p + (cd->offset - tmp);
990 } else if (offset_r >= len1) {
991 cd->offset -= len1 >> 2;
992 } else {
993 /* sitting on the fence */
994 BUG_ON(offset_r != len1 - 4);
995 cd->offset = p + (cd->offset - tmp);
996 cd->offset1 = tmp;
997 }
998
999 len2 = (num_entry_words << 2) - len1;
1000
1001 /* move from temp page to current and next pages */
1002 memmove(p, tmp, len1);
1003 memmove(tmp, (caddr_t)tmp+len1, len2);
1004
1005 p = tmp + (len2 >> 2);
1006 }
1007 }
1008 else {
1009 cd->common.err = nfserr_toosmall;
1010 return -EINVAL;
1011 }
1012
1013 cd->buflen -= num_entry_words;
1014 cd->buffer = p;
1015 cd->common.err = nfs_ok;
1016 return 0;
1017
1018}
1019
1020int
NeilBrowna0ad13e2007-01-26 00:57:10 -08001021nfs3svc_encode_entry(void *cd, const char *name,
1022 int namlen, loff_t offset, u64 ino, unsigned int d_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023{
1024 return encode_entry(cd, name, namlen, offset, ino, d_type, 0);
1025}
1026
1027int
NeilBrowna0ad13e2007-01-26 00:57:10 -08001028nfs3svc_encode_entry_plus(void *cd, const char *name,
1029 int namlen, loff_t offset, u64 ino,
1030 unsigned int d_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031{
1032 return encode_entry(cd, name, namlen, offset, ino, d_type, 1);
1033}
1034
1035/* FSSTAT */
1036int
Al Viro91f07162006-10-19 23:28:57 -07001037nfs3svc_encode_fsstatres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 struct nfsd3_fsstatres *resp)
1039{
1040 struct kstatfs *s = &resp->stats;
1041 u64 bs = s->f_bsize;
1042
1043 *p++ = xdr_zero; /* no post_op_attr */
1044
1045 if (resp->status == 0) {
1046 p = xdr_encode_hyper(p, bs * s->f_blocks); /* total bytes */
1047 p = xdr_encode_hyper(p, bs * s->f_bfree); /* free bytes */
1048 p = xdr_encode_hyper(p, bs * s->f_bavail); /* user available bytes */
1049 p = xdr_encode_hyper(p, s->f_files); /* total inodes */
1050 p = xdr_encode_hyper(p, s->f_ffree); /* free inodes */
1051 p = xdr_encode_hyper(p, s->f_ffree); /* user available inodes */
1052 *p++ = htonl(resp->invarsec); /* mean unchanged time */
1053 }
1054 return xdr_ressize_check(rqstp, p);
1055}
1056
1057/* FSINFO */
1058int
Al Viro91f07162006-10-19 23:28:57 -07001059nfs3svc_encode_fsinfores(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 struct nfsd3_fsinfores *resp)
1061{
1062 *p++ = xdr_zero; /* no post_op_attr */
1063
1064 if (resp->status == 0) {
1065 *p++ = htonl(resp->f_rtmax);
1066 *p++ = htonl(resp->f_rtpref);
1067 *p++ = htonl(resp->f_rtmult);
1068 *p++ = htonl(resp->f_wtmax);
1069 *p++ = htonl(resp->f_wtpref);
1070 *p++ = htonl(resp->f_wtmult);
1071 *p++ = htonl(resp->f_dtpref);
1072 p = xdr_encode_hyper(p, resp->f_maxfilesize);
1073 *p++ = xdr_one;
1074 *p++ = xdr_zero;
1075 *p++ = htonl(resp->f_properties);
1076 }
1077
1078 return xdr_ressize_check(rqstp, p);
1079}
1080
1081/* PATHCONF */
1082int
Al Viro91f07162006-10-19 23:28:57 -07001083nfs3svc_encode_pathconfres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 struct nfsd3_pathconfres *resp)
1085{
1086 *p++ = xdr_zero; /* no post_op_attr */
1087
1088 if (resp->status == 0) {
1089 *p++ = htonl(resp->p_link_max);
1090 *p++ = htonl(resp->p_name_max);
1091 *p++ = htonl(resp->p_no_trunc);
1092 *p++ = htonl(resp->p_chown_restricted);
1093 *p++ = htonl(resp->p_case_insensitive);
1094 *p++ = htonl(resp->p_case_preserving);
1095 }
1096
1097 return xdr_ressize_check(rqstp, p);
1098}
1099
1100/* COMMIT */
1101int
Al Viro91f07162006-10-19 23:28:57 -07001102nfs3svc_encode_commitres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 struct nfsd3_commitres *resp)
1104{
1105 p = encode_wcc_data(rqstp, p, &resp->fh);
1106 /* Write verifier */
1107 if (resp->status == 0) {
1108 *p++ = htonl(nfssvc_boot.tv_sec);
1109 *p++ = htonl(nfssvc_boot.tv_usec);
1110 }
1111 return xdr_ressize_check(rqstp, p);
1112}
1113
1114/*
1115 * XDR release functions
1116 */
1117int
Al Viro91f07162006-10-19 23:28:57 -07001118nfs3svc_release_fhandle(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 struct nfsd3_attrstat *resp)
1120{
1121 fh_put(&resp->fh);
1122 return 1;
1123}
1124
1125int
Al Viro91f07162006-10-19 23:28:57 -07001126nfs3svc_release_fhandle2(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 struct nfsd3_fhandle_pair *resp)
1128{
1129 fh_put(&resp->fh1);
1130 fh_put(&resp->fh2);
1131 return 1;
1132}