blob: f5243f943996030896b9dc4280b7b5f550252fec [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * linux/fs/nfsd/nfsxdr.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * XDR support for nfsd
5 *
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
7 */
8
9#include <linux/types.h>
10#include <linux/time.h>
11#include <linux/nfs.h>
12#include <linux/vfs.h>
13#include <linux/sunrpc/xdr.h>
14#include <linux/sunrpc/svc.h>
15#include <linux/nfsd/nfsd.h>
16#include <linux/nfsd/xdr.h>
17#include <linux/mm.h>
18
19#define NFSDDBG_FACILITY NFSDDBG_XDR
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021/*
22 * Mapping of S_IF* types to NFS file types
23 */
24static u32 nfs_ftypes[] = {
25 NFNON, NFCHR, NFCHR, NFBAD,
26 NFDIR, NFBAD, NFBLK, NFBAD,
27 NFREG, NFBAD, NFLNK, NFBAD,
28 NFSOCK, NFBAD, NFLNK, NFBAD,
29};
30
31
32/*
33 * XDR functions for basic NFS types
34 */
Al Viro131a21c2006-10-19 23:28:56 -070035static __be32 *
36decode_fh(__be32 *p, struct svc_fh *fhp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
38 fh_init(fhp, NFS_FHSIZE);
39 memcpy(&fhp->fh_handle.fh_base, p, NFS_FHSIZE);
40 fhp->fh_handle.fh_size = NFS_FHSIZE;
41
42 /* FIXME: Look up export pointer here and verify
43 * Sun Secure RPC if requested */
44 return p + (NFS_FHSIZE >> 2);
45}
46
Andreas Gruenbachera257cdd2005-06-22 17:16:26 +000047/* Helper function for NFSv2 ACL code */
Al Viro131a21c2006-10-19 23:28:56 -070048__be32 *nfs2svc_decode_fh(__be32 *p, struct svc_fh *fhp)
Andreas Gruenbachera257cdd2005-06-22 17:16:26 +000049{
50 return decode_fh(p, fhp);
51}
52
Adrian Bunk3ee6f612006-12-06 20:40:23 -080053static __be32 *
Al Viro131a21c2006-10-19 23:28:56 -070054encode_fh(__be32 *p, struct svc_fh *fhp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 memcpy(p, &fhp->fh_handle.fh_base, NFS_FHSIZE);
57 return p + (NFS_FHSIZE>> 2);
58}
59
60/*
61 * Decode a file name and make sure that the path contains
62 * no slashes or null bytes.
63 */
Adrian Bunk3ee6f612006-12-06 20:40:23 -080064static __be32 *
Al Viro131a21c2006-10-19 23:28:56 -070065decode_filename(__be32 *p, char **namp, int *lenp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
67 char *name;
68 int i;
69
70 if ((p = xdr_decode_string_inplace(p, namp, lenp, NFS_MAXNAMLEN)) != NULL) {
71 for (i = 0, name = *namp; i < *lenp; i++, name++) {
72 if (*name == '\0' || *name == '/')
73 return NULL;
74 }
75 }
76
77 return p;
78}
79
Adrian Bunk3ee6f612006-12-06 20:40:23 -080080static __be32 *
Al Viro131a21c2006-10-19 23:28:56 -070081decode_pathname(__be32 *p, char **namp, int *lenp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
83 char *name;
84 int i;
85
86 if ((p = xdr_decode_string_inplace(p, namp, lenp, NFS_MAXPATHLEN)) != NULL) {
87 for (i = 0, name = *namp; i < *lenp; i++, name++) {
88 if (*name == '\0')
89 return NULL;
90 }
91 }
92
93 return p;
94}
95
Adrian Bunk3ee6f612006-12-06 20:40:23 -080096static __be32 *
Al Viro131a21c2006-10-19 23:28:56 -070097decode_sattr(__be32 *p, struct iattr *iap)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
99 u32 tmp, tmp1;
100
101 iap->ia_valid = 0;
102
103 /* Sun client bug compatibility check: some sun clients seem to
104 * put 0xffff in the mode field when they mean 0xffffffff.
105 * Quoting the 4.4BSD nfs server code: Nah nah nah nah na nah.
106 */
107 if ((tmp = ntohl(*p++)) != (u32)-1 && tmp != 0xffff) {
108 iap->ia_valid |= ATTR_MODE;
109 iap->ia_mode = tmp;
110 }
111 if ((tmp = ntohl(*p++)) != (u32)-1) {
112 iap->ia_valid |= ATTR_UID;
113 iap->ia_uid = tmp;
114 }
115 if ((tmp = ntohl(*p++)) != (u32)-1) {
116 iap->ia_valid |= ATTR_GID;
117 iap->ia_gid = tmp;
118 }
119 if ((tmp = ntohl(*p++)) != (u32)-1) {
120 iap->ia_valid |= ATTR_SIZE;
121 iap->ia_size = tmp;
122 }
123 tmp = ntohl(*p++); tmp1 = ntohl(*p++);
124 if (tmp != (u32)-1 && tmp1 != (u32)-1) {
125 iap->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET;
126 iap->ia_atime.tv_sec = tmp;
127 iap->ia_atime.tv_nsec = tmp1 * 1000;
128 }
129 tmp = ntohl(*p++); tmp1 = ntohl(*p++);
130 if (tmp != (u32)-1 && tmp1 != (u32)-1) {
131 iap->ia_valid |= ATTR_MTIME | ATTR_MTIME_SET;
132 iap->ia_mtime.tv_sec = tmp;
133 iap->ia_mtime.tv_nsec = tmp1 * 1000;
134 /*
135 * Passing the invalid value useconds=1000000 for mtime
136 * is a Sun convention for "set both mtime and atime to
137 * current server time". It's needed to make permissions
138 * checks for the "touch" program across v2 mounts to
139 * Solaris and Irix boxes work correctly. See description of
140 * sattr in section 6.1 of "NFS Illustrated" by
141 * Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5
142 */
143 if (tmp1 == 1000000)
144 iap->ia_valid &= ~(ATTR_ATIME_SET|ATTR_MTIME_SET);
145 }
146 return p;
147}
148
Al Viro131a21c2006-10-19 23:28:56 -0700149static __be32 *
150encode_fattr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp,
David Shawa334de22006-01-06 00:19:58 -0800151 struct kstat *stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 struct dentry *dentry = fhp->fh_dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 int type;
155 struct timespec time;
156
David Shawa334de22006-01-06 00:19:58 -0800157 type = (stat->mode & S_IFMT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 *p++ = htonl(nfs_ftypes[type >> 12]);
David Shawa334de22006-01-06 00:19:58 -0800160 *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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
David Shawa334de22006-01-06 00:19:58 -0800165 if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 *p++ = htonl(NFS_MAXPATHLEN);
167 } else {
David Shawa334de22006-01-06 00:19:58 -0800168 *p++ = htonl((u32) stat->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 }
David Shawa334de22006-01-06 00:19:58 -0800170 *p++ = htonl((u32) stat->blksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 if (S_ISCHR(type) || S_ISBLK(type))
David Shawa334de22006-01-06 00:19:58 -0800172 *p++ = htonl(new_encode_dev(stat->rdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 else
174 *p++ = htonl(0xffffffff);
David Shawa334de22006-01-06 00:19:58 -0800175 *p++ = htonl((u32) stat->blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 if (is_fsid(fhp, rqstp->rq_reffh))
177 *p++ = htonl((u32) fhp->fh_export->ex_fsid);
178 else
David Shawa334de22006-01-06 00:19:58 -0800179 *p++ = htonl(new_encode_dev(stat->dev));
180 *p++ = htonl((u32) stat->ino);
181 *p++ = htonl((u32) stat->atime.tv_sec);
182 *p++ = htonl(stat->atime.tv_nsec ? stat->atime.tv_nsec / 1000 : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 lease_get_mtime(dentry->d_inode, &time);
184 *p++ = htonl((u32) time.tv_sec);
185 *p++ = htonl(time.tv_nsec ? time.tv_nsec / 1000 : 0);
David Shawa334de22006-01-06 00:19:58 -0800186 *p++ = htonl((u32) stat->ctime.tv_sec);
187 *p++ = htonl(stat->ctime.tv_nsec ? stat->ctime.tv_nsec / 1000 : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 return p;
190}
191
Andreas Gruenbachera257cdd2005-06-22 17:16:26 +0000192/* Helper function for NFSv2 ACL code */
Al Viro131a21c2006-10-19 23:28:56 -0700193__be32 *nfs2svc_encode_fattr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
Andreas Gruenbachera257cdd2005-06-22 17:16:26 +0000194{
David Shawa334de22006-01-06 00:19:58 -0800195 struct kstat stat;
196 vfs_getattr(fhp->fh_export->ex_mnt, fhp->fh_dentry, &stat);
197 return encode_fattr(rqstp, p, fhp, &stat);
Andreas Gruenbachera257cdd2005-06-22 17:16:26 +0000198}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200/*
201 * XDR decode functions
202 */
203int
Al Viro131a21c2006-10-19 23:28:56 -0700204nfssvc_decode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 return xdr_argsize_check(rqstp, p);
207}
208
209int
Al Viro131a21c2006-10-19 23:28:56 -0700210nfssvc_decode_fhandle(struct svc_rqst *rqstp, __be32 *p, struct nfsd_fhandle *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
212 if (!(p = decode_fh(p, &args->fh)))
213 return 0;
214 return xdr_argsize_check(rqstp, p);
215}
216
217int
Al Viro131a21c2006-10-19 23:28:56 -0700218nfssvc_decode_sattrargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 struct nfsd_sattrargs *args)
220{
221 if (!(p = decode_fh(p, &args->fh))
222 || !(p = decode_sattr(p, &args->attrs)))
223 return 0;
224
225 return xdr_argsize_check(rqstp, p);
226}
227
228int
Al Viro131a21c2006-10-19 23:28:56 -0700229nfssvc_decode_diropargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 struct nfsd_diropargs *args)
231{
232 if (!(p = decode_fh(p, &args->fh))
233 || !(p = decode_filename(p, &args->name, &args->len)))
234 return 0;
235
236 return xdr_argsize_check(rqstp, p);
237}
238
239int
Al Viro131a21c2006-10-19 23:28:56 -0700240nfssvc_decode_readargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 struct nfsd_readargs *args)
242{
243 unsigned int len;
244 int v,pn;
245 if (!(p = decode_fh(p, &args->fh)))
246 return 0;
247
248 args->offset = ntohl(*p++);
249 len = args->count = ntohl(*p++);
250 p++; /* totalcount - unused */
251
Greg Banks7adae482006-10-04 02:15:47 -0700252 if (len > NFSSVC_MAXBLKSIZE_V2)
253 len = NFSSVC_MAXBLKSIZE_V2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 /* set up somewhere to store response.
256 * We take pages, put them on reslist and include in iovec
257 */
258 v=0;
259 while (len > 0) {
NeilBrown44524352006-10-04 02:15:46 -0700260 pn = rqstp->rq_resused++;
NeilBrown3cc03b12006-10-04 02:15:47 -0700261 rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_respages[pn]);
262 rqstp->rq_vec[v].iov_len = len < PAGE_SIZE?len:PAGE_SIZE;
263 len -= rqstp->rq_vec[v].iov_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 v++;
265 }
266 args->vlen = v;
267 return xdr_argsize_check(rqstp, p);
268}
269
270int
Al Viro131a21c2006-10-19 23:28:56 -0700271nfssvc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 struct nfsd_writeargs *args)
273{
274 unsigned int len;
275 int v;
276 if (!(p = decode_fh(p, &args->fh)))
277 return 0;
278
279 p++; /* beginoffset */
280 args->offset = ntohl(*p++); /* offset */
281 p++; /* totalcount */
282 len = args->len = ntohl(*p++);
NeilBrown3cc03b12006-10-04 02:15:47 -0700283 rqstp->rq_vec[0].iov_base = (void*)p;
284 rqstp->rq_vec[0].iov_len = rqstp->rq_arg.head[0].iov_len -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 (((void*)p) - rqstp->rq_arg.head[0].iov_base);
Greg Banks7adae482006-10-04 02:15:47 -0700286 if (len > NFSSVC_MAXBLKSIZE_V2)
287 len = NFSSVC_MAXBLKSIZE_V2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 v = 0;
NeilBrown3cc03b12006-10-04 02:15:47 -0700289 while (len > rqstp->rq_vec[v].iov_len) {
290 len -= rqstp->rq_vec[v].iov_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 v++;
NeilBrown3cc03b12006-10-04 02:15:47 -0700292 rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_pages[v]);
293 rqstp->rq_vec[v].iov_len = PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
NeilBrown3cc03b12006-10-04 02:15:47 -0700295 rqstp->rq_vec[v].iov_len = len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 args->vlen = v+1;
NeilBrown3cc03b12006-10-04 02:15:47 -0700297 return rqstp->rq_vec[0].iov_len > 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
300int
Al Viro131a21c2006-10-19 23:28:56 -0700301nfssvc_decode_createargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 struct nfsd_createargs *args)
303{
304 if (!(p = decode_fh(p, &args->fh))
305 || !(p = decode_filename(p, &args->name, &args->len))
306 || !(p = decode_sattr(p, &args->attrs)))
307 return 0;
308
309 return xdr_argsize_check(rqstp, p);
310}
311
312int
Al Viro131a21c2006-10-19 23:28:56 -0700313nfssvc_decode_renameargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 struct nfsd_renameargs *args)
315{
316 if (!(p = decode_fh(p, &args->ffh))
317 || !(p = decode_filename(p, &args->fname, &args->flen))
318 || !(p = decode_fh(p, &args->tfh))
319 || !(p = decode_filename(p, &args->tname, &args->tlen)))
320 return 0;
321
322 return xdr_argsize_check(rqstp, p);
323}
324
325int
Al Viro131a21c2006-10-19 23:28:56 -0700326nfssvc_decode_readlinkargs(struct svc_rqst *rqstp, __be32 *p, struct nfsd_readlinkargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
328 if (!(p = decode_fh(p, &args->fh)))
329 return 0;
NeilBrown44524352006-10-04 02:15:46 -0700330 args->buffer = page_address(rqstp->rq_respages[rqstp->rq_resused++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 return xdr_argsize_check(rqstp, p);
333}
334
335int
Al Viro131a21c2006-10-19 23:28:56 -0700336nfssvc_decode_linkargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 struct nfsd_linkargs *args)
338{
339 if (!(p = decode_fh(p, &args->ffh))
340 || !(p = decode_fh(p, &args->tfh))
341 || !(p = decode_filename(p, &args->tname, &args->tlen)))
342 return 0;
343
344 return xdr_argsize_check(rqstp, p);
345}
346
347int
Al Viro131a21c2006-10-19 23:28:56 -0700348nfssvc_decode_symlinkargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 struct nfsd_symlinkargs *args)
350{
351 if (!(p = decode_fh(p, &args->ffh))
352 || !(p = decode_filename(p, &args->fname, &args->flen))
353 || !(p = decode_pathname(p, &args->tname, &args->tlen))
354 || !(p = decode_sattr(p, &args->attrs)))
355 return 0;
356
357 return xdr_argsize_check(rqstp, p);
358}
359
360int
Al Viro131a21c2006-10-19 23:28:56 -0700361nfssvc_decode_readdirargs(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 struct nfsd_readdirargs *args)
363{
364 if (!(p = decode_fh(p, &args->fh)))
365 return 0;
366 args->cookie = ntohl(*p++);
367 args->count = ntohl(*p++);
368 if (args->count > PAGE_SIZE)
369 args->count = PAGE_SIZE;
370
NeilBrown44524352006-10-04 02:15:46 -0700371 args->buffer = page_address(rqstp->rq_respages[rqstp->rq_resused++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 return xdr_argsize_check(rqstp, p);
374}
375
376/*
377 * XDR encode functions
378 */
379int
Al Viro131a21c2006-10-19 23:28:56 -0700380nfssvc_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
382 return xdr_ressize_check(rqstp, p);
383}
384
385int
Al Viro131a21c2006-10-19 23:28:56 -0700386nfssvc_encode_attrstat(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 struct nfsd_attrstat *resp)
388{
David Shawa334de22006-01-06 00:19:58 -0800389 p = encode_fattr(rqstp, p, &resp->fh, &resp->stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 return xdr_ressize_check(rqstp, p);
391}
392
393int
Al Viro131a21c2006-10-19 23:28:56 -0700394nfssvc_encode_diropres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 struct nfsd_diropres *resp)
396{
397 p = encode_fh(p, &resp->fh);
David Shawa334de22006-01-06 00:19:58 -0800398 p = encode_fattr(rqstp, p, &resp->fh, &resp->stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 return xdr_ressize_check(rqstp, p);
400}
401
402int
Al Viro131a21c2006-10-19 23:28:56 -0700403nfssvc_encode_readlinkres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 struct nfsd_readlinkres *resp)
405{
406 *p++ = htonl(resp->len);
407 xdr_ressize_check(rqstp, p);
408 rqstp->rq_res.page_len = resp->len;
409 if (resp->len & 3) {
410 /* need to pad the tail */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 rqstp->rq_res.tail[0].iov_base = p;
412 *p = 0;
413 rqstp->rq_res.tail[0].iov_len = 4 - (resp->len&3);
414 }
415 return 1;
416}
417
418int
Al Viro131a21c2006-10-19 23:28:56 -0700419nfssvc_encode_readres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 struct nfsd_readres *resp)
421{
David Shawa334de22006-01-06 00:19:58 -0800422 p = encode_fattr(rqstp, p, &resp->fh, &resp->stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 *p++ = htonl(resp->count);
424 xdr_ressize_check(rqstp, p);
425
426 /* now update rqstp->rq_res to reflect data aswell */
427 rqstp->rq_res.page_len = resp->count;
428 if (resp->count & 3) {
429 /* need to pad the tail */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 rqstp->rq_res.tail[0].iov_base = p;
431 *p = 0;
432 rqstp->rq_res.tail[0].iov_len = 4 - (resp->count&3);
433 }
434 return 1;
435}
436
437int
Al Viro131a21c2006-10-19 23:28:56 -0700438nfssvc_encode_readdirres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 struct nfsd_readdirres *resp)
440{
441 xdr_ressize_check(rqstp, p);
442 p = resp->buffer;
443 *p++ = 0; /* no more entries */
444 *p++ = htonl((resp->common.err == nfserr_eof));
445 rqstp->rq_res.page_len = (((unsigned long)p-1) & ~PAGE_MASK)+1;
446
447 return 1;
448}
449
450int
Al Viro131a21c2006-10-19 23:28:56 -0700451nfssvc_encode_statfsres(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 struct nfsd_statfsres *resp)
453{
454 struct kstatfs *stat = &resp->stats;
455
Greg Banks7adae482006-10-04 02:15:47 -0700456 *p++ = htonl(NFSSVC_MAXBLKSIZE_V2); /* max transfer size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 *p++ = htonl(stat->f_bsize);
458 *p++ = htonl(stat->f_blocks);
459 *p++ = htonl(stat->f_bfree);
460 *p++ = htonl(stat->f_bavail);
461 return xdr_ressize_check(rqstp, p);
462}
463
464int
465nfssvc_encode_entry(struct readdir_cd *ccd, const char *name,
466 int namlen, loff_t offset, ino_t ino, unsigned int d_type)
467{
468 struct nfsd_readdirres *cd = container_of(ccd, struct nfsd_readdirres, common);
Al Viro131a21c2006-10-19 23:28:56 -0700469 __be32 *p = cd->buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 int buflen, slen;
471
472 /*
473 dprintk("nfsd: entry(%.*s off %ld ino %ld)\n",
474 namlen, name, offset, ino);
475 */
476
477 if (offset > ~((u32) 0)) {
478 cd->common.err = nfserr_fbig;
479 return -EINVAL;
480 }
481 if (cd->offset)
482 *cd->offset = htonl(offset);
483 if (namlen > NFS2_MAXNAMLEN)
484 namlen = NFS2_MAXNAMLEN;/* truncate filename */
485
486 slen = XDR_QUADLEN(namlen);
487 if ((buflen = cd->buflen - slen - 4) < 0) {
488 cd->common.err = nfserr_toosmall;
489 return -EINVAL;
490 }
491 *p++ = xdr_one; /* mark entry present */
492 *p++ = htonl((u32) ino); /* file id */
493 p = xdr_encode_array(p, name, namlen);/* name length & name */
494 cd->offset = p; /* remember pointer */
Al Viro131a21c2006-10-19 23:28:56 -0700495 *p++ = htonl(~0U); /* offset of next entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 cd->buflen = buflen;
498 cd->buffer = p;
499 cd->common.err = nfs_ok;
500 return 0;
501}
502
503/*
504 * XDR release functions
505 */
506int
Al Viro131a21c2006-10-19 23:28:56 -0700507nfssvc_release_fhandle(struct svc_rqst *rqstp, __be32 *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 struct nfsd_fhandle *resp)
509{
510 fh_put(&resp->fh);
511 return 1;
512}