4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
55 #define NFSDBG_FACILITY NFSDBG_XDR
57 /* Mapping from NFS error code to "errno" error code. */
58 #define errno_NFSERR_IO EIO
60 static int nfs_stat_to_errno(int);
62 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
64 #define NFS4_MAXTAGLEN 20
66 #define NFS4_MAXTAGLEN 0
69 /* lock,open owner id:
70 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
72 #define owner_id_maxsz (1 + 1)
73 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
74 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
75 #define op_encode_hdr_maxsz (1)
76 #define op_decode_hdr_maxsz (2)
77 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
79 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
80 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
81 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
82 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
83 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
84 ((3+NFS4_FHSIZE) >> 2))
85 #define encode_getattr_maxsz (op_encode_hdr_maxsz + 3)
86 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
87 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
88 #define nfs4_fattr_bitmap_maxsz (36 + 2 * nfs4_name_maxsz)
89 #define decode_getattr_maxsz (op_decode_hdr_maxsz + 3 + \
90 nfs4_fattr_bitmap_maxsz)
91 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
92 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
93 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
94 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
95 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
96 #define decode_renew_maxsz (op_decode_hdr_maxsz)
97 #define encode_setclientid_maxsz \
98 (op_encode_hdr_maxsz + \
99 4 /*server->ip_addr*/ + \
102 6 + (NFS4_VERIFIER_SIZE >> 2))
103 #define decode_setclientid_maxsz \
104 (op_decode_hdr_maxsz + \
106 1024) /* large value for CLID_INUSE */
107 #define encode_setclientid_confirm_maxsz \
108 (op_encode_hdr_maxsz + \
109 3 + (NFS4_VERIFIER_SIZE >> 2))
110 #define decode_setclientid_confirm_maxsz \
111 (op_decode_hdr_maxsz)
112 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
113 1 + ((3 + NFS4_FHSIZE) >> 2))
114 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
116 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
118 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
119 #define encode_link_maxsz (op_encode_hdr_maxsz + \
121 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
122 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
123 1 + nfs4_name_maxsz + \
125 nfs4_fattr_bitmap_maxsz)
126 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
127 #define encode_create_maxsz (op_encode_hdr_maxsz + \
128 2 + nfs4_name_maxsz + \
129 nfs4_fattr_bitmap_maxsz)
130 #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
131 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
132 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
133 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
134 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
135 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
136 encode_putfh_maxsz + \
137 op_encode_hdr_maxsz + 7)
138 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
139 decode_putfh_maxsz + \
140 op_decode_hdr_maxsz + 2)
141 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
142 encode_putfh_maxsz + \
144 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
145 decode_putfh_maxsz + \
147 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
148 encode_putfh_maxsz + \
149 op_encode_hdr_maxsz + 9)
150 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
151 decode_putfh_maxsz + \
152 op_decode_hdr_maxsz + 2)
153 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
154 encode_putfh_maxsz + \
155 op_encode_hdr_maxsz + 8)
156 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
157 decode_putfh_maxsz + \
158 op_decode_hdr_maxsz + 4)
159 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
160 encode_putfh_maxsz + \
161 op_encode_hdr_maxsz + 3)
162 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
163 decode_putfh_maxsz + \
164 op_decode_hdr_maxsz + 2)
165 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
166 encode_putfh_maxsz + \
167 op_encode_hdr_maxsz + \
169 encode_getattr_maxsz + \
171 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
172 decode_putfh_maxsz + \
173 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
174 decode_getattr_maxsz + \
176 #define NFS4_enc_open_confirm_sz \
177 (compound_encode_hdr_maxsz + \
178 encode_putfh_maxsz + \
179 op_encode_hdr_maxsz + 5)
180 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
181 decode_putfh_maxsz + \
182 op_decode_hdr_maxsz + 4)
183 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
184 encode_putfh_maxsz + \
185 op_encode_hdr_maxsz + \
187 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
188 decode_putfh_maxsz + \
189 op_decode_hdr_maxsz + \
191 #define NFS4_enc_open_downgrade_sz \
192 (compound_encode_hdr_maxsz + \
193 encode_putfh_maxsz + \
194 op_encode_hdr_maxsz + 7)
195 #define NFS4_dec_open_downgrade_sz \
196 (compound_decode_hdr_maxsz + \
197 decode_putfh_maxsz + \
198 op_decode_hdr_maxsz + 4)
199 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
200 encode_putfh_maxsz + \
201 op_encode_hdr_maxsz + 5)
202 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
203 decode_putfh_maxsz + \
204 op_decode_hdr_maxsz + 4)
205 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
206 encode_putfh_maxsz + \
207 op_encode_hdr_maxsz + 4 + \
208 nfs4_fattr_bitmap_maxsz + \
209 encode_getattr_maxsz)
210 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
211 decode_putfh_maxsz + \
212 op_decode_hdr_maxsz + 3)
213 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
214 encode_putfh_maxsz + \
216 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
217 decode_putfh_maxsz + \
219 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
221 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
223 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
224 encode_setclientid_maxsz)
225 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
226 decode_setclientid_maxsz)
227 #define NFS4_enc_setclientid_confirm_sz \
228 (compound_encode_hdr_maxsz + \
229 encode_setclientid_confirm_maxsz + \
230 encode_putrootfh_maxsz + \
232 #define NFS4_dec_setclientid_confirm_sz \
233 (compound_decode_hdr_maxsz + \
234 decode_setclientid_confirm_maxsz + \
235 decode_putrootfh_maxsz + \
237 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
238 encode_putfh_maxsz + \
239 encode_getattr_maxsz + \
240 op_encode_hdr_maxsz + \
244 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
245 decode_putfh_maxsz + \
246 decode_getattr_maxsz + \
247 op_decode_hdr_maxsz + \
250 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
251 encode_putfh_maxsz + \
252 encode_getattr_maxsz + \
253 op_encode_hdr_maxsz + \
256 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
257 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
258 encode_putfh_maxsz + \
259 encode_getattr_maxsz + \
260 op_encode_hdr_maxsz + \
262 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
263 decode_putfh_maxsz + \
264 decode_getattr_maxsz + \
265 op_decode_hdr_maxsz + 4)
266 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
267 encode_putfh_maxsz + \
268 op_encode_hdr_maxsz + 1)
269 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
270 decode_putfh_maxsz + \
271 op_decode_hdr_maxsz + 2)
272 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
273 encode_putfh_maxsz + \
274 encode_getattr_maxsz)
275 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
276 decode_putfh_maxsz + \
277 decode_getattr_maxsz)
278 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
279 encode_putfh_maxsz + \
280 encode_lookup_maxsz + \
281 encode_getattr_maxsz + \
283 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
284 decode_putfh_maxsz + \
285 op_decode_hdr_maxsz + \
286 decode_getattr_maxsz + \
288 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
289 encode_putrootfh_maxsz + \
290 encode_getattr_maxsz + \
292 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
293 decode_putrootfh_maxsz + \
294 decode_getattr_maxsz + \
296 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
297 encode_putfh_maxsz + \
299 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
300 decode_putfh_maxsz + \
301 op_decode_hdr_maxsz + 5)
302 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
303 encode_putfh_maxsz + \
304 encode_savefh_maxsz + \
305 encode_putfh_maxsz + \
307 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
308 decode_putfh_maxsz + \
309 decode_savefh_maxsz + \
310 decode_putfh_maxsz + \
312 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
313 encode_putfh_maxsz + \
314 encode_savefh_maxsz + \
315 encode_putfh_maxsz + \
317 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
318 decode_putfh_maxsz + \
319 decode_savefh_maxsz + \
320 decode_putfh_maxsz + \
322 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
323 encode_putfh_maxsz + \
324 encode_symlink_maxsz + \
325 encode_getattr_maxsz + \
327 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
328 decode_putfh_maxsz + \
329 decode_symlink_maxsz + \
330 decode_getattr_maxsz + \
332 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
333 encode_putfh_maxsz + \
334 encode_create_maxsz + \
335 encode_getattr_maxsz + \
337 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
338 decode_putfh_maxsz + \
339 decode_create_maxsz + \
340 decode_getattr_maxsz + \
342 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
343 encode_putfh_maxsz + \
344 encode_getattr_maxsz)
345 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
346 decode_putfh_maxsz + \
347 decode_getattr_maxsz)
348 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
349 encode_putfh_maxsz + \
350 encode_getattr_maxsz)
351 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
352 decode_putfh_maxsz + \
353 op_decode_hdr_maxsz + 12)
354 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
355 encode_getattr_maxsz)
356 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
357 decode_getattr_maxsz)
358 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
359 encode_putfh_maxsz + \
360 encode_delegreturn_maxsz)
361 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
362 decode_delegreturn_maxsz)
366 unsigned int nfs2type;
374 { S_IFSOCK, NFSOCK },
380 struct compound_hdr {
388 * START OF "GENERIC" ENCODE ROUTINES.
389 * These may look a little ugly since they are imported from a "generic"
390 * set of XDR encode/decode routines which are intended to be shared by
391 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
393 * If the pain of reading these is too great, it should be a straightforward
394 * task to translate them into Linux-specific versions which are more
395 * consistent with the style used in NFSv2/v3...
397 #define WRITE32(n) *p++ = htonl(n)
398 #define WRITE64(n) do { \
399 *p++ = htonl((uint32_t)((n) >> 32)); \
400 *p++ = htonl((uint32_t)(n)); \
402 #define WRITEMEM(ptr,nbytes) do { \
403 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
406 #define RESERVE_SPACE(nbytes) do { \
407 p = xdr_reserve_space(xdr, nbytes); \
408 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
412 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
416 p = xdr_reserve_space(xdr, 4 + len);
418 xdr_encode_opaque(p, str, len);
421 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
425 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
426 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
427 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
428 WRITE32(hdr->taglen);
429 WRITEMEM(hdr->tag, hdr->taglen);
430 WRITE32(NFS4_MINOR_VERSION);
435 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
439 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
441 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
444 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
446 char owner_name[IDMAP_NAMESZ];
447 char owner_group[IDMAP_NAMESZ];
448 int owner_namelen = 0;
449 int owner_grouplen = 0;
458 * We reserve enough space to write the entire attribute buffer at once.
459 * In the worst-case, this would be
460 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
461 * = 36 bytes, plus any contribution from variable-length fields
462 * such as owner/group/acl's.
467 if (iap->ia_valid & ATTR_SIZE)
469 if (iap->ia_valid & ATTR_MODE)
471 if (iap->ia_valid & ATTR_UID) {
472 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
473 if (owner_namelen < 0) {
474 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
477 strcpy(owner_name, "nobody");
478 owner_namelen = sizeof("nobody") - 1;
481 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
483 if (iap->ia_valid & ATTR_GID) {
484 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
485 if (owner_grouplen < 0) {
486 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
488 strcpy(owner_group, "nobody");
489 owner_grouplen = sizeof("nobody") - 1;
492 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
494 if (iap->ia_valid & ATTR_ATIME_SET)
496 else if (iap->ia_valid & ATTR_ATIME)
498 if (iap->ia_valid & ATTR_MTIME_SET)
500 else if (iap->ia_valid & ATTR_MTIME)
505 * We write the bitmap length now, but leave the bitmap and the attribute
506 * buffer length to be backfilled at the end of this routine.
512 if (iap->ia_valid & ATTR_SIZE) {
513 bmval0 |= FATTR4_WORD0_SIZE;
514 WRITE64(iap->ia_size);
516 if (iap->ia_valid & ATTR_MODE) {
517 bmval1 |= FATTR4_WORD1_MODE;
518 WRITE32(iap->ia_mode);
520 if (iap->ia_valid & ATTR_UID) {
521 bmval1 |= FATTR4_WORD1_OWNER;
522 WRITE32(owner_namelen);
523 WRITEMEM(owner_name, owner_namelen);
525 if (iap->ia_valid & ATTR_GID) {
526 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
527 WRITE32(owner_grouplen);
528 WRITEMEM(owner_group, owner_grouplen);
530 if (iap->ia_valid & ATTR_ATIME_SET) {
531 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
532 WRITE32(NFS4_SET_TO_CLIENT_TIME);
534 WRITE32(iap->ia_mtime.tv_sec);
535 WRITE32(iap->ia_mtime.tv_nsec);
537 else if (iap->ia_valid & ATTR_ATIME) {
538 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
539 WRITE32(NFS4_SET_TO_SERVER_TIME);
541 if (iap->ia_valid & ATTR_MTIME_SET) {
542 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
543 WRITE32(NFS4_SET_TO_CLIENT_TIME);
545 WRITE32(iap->ia_mtime.tv_sec);
546 WRITE32(iap->ia_mtime.tv_nsec);
548 else if (iap->ia_valid & ATTR_MTIME) {
549 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
550 WRITE32(NFS4_SET_TO_SERVER_TIME);
554 * Now we backfill the bitmap and the attribute buffer length.
556 if (len != ((char *)p - (char *)q) + 4) {
557 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
558 len, ((char *)p - (char *)q) + 4);
561 len = (char *)p - (char *)q - 12;
562 *q++ = htonl(bmval0);
563 *q++ = htonl(bmval1);
571 static int encode_access(struct xdr_stream *xdr, u32 access)
582 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
586 RESERVE_SPACE(8+sizeof(arg->stateid.data));
589 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
594 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
600 WRITE64(args->offset);
601 WRITE32(args->count);
606 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
612 WRITE32(create->ftype);
614 switch (create->ftype) {
616 RESERVE_SPACE(4 + create->u.symlink->len);
617 WRITE32(create->u.symlink->len);
618 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
621 case NF4BLK: case NF4CHR:
623 WRITE32(create->u.device.specdata1);
624 WRITE32(create->u.device.specdata2);
631 RESERVE_SPACE(4 + create->name->len);
632 WRITE32(create->name->len);
633 WRITEMEM(create->name->name, create->name->len);
635 return encode_attrs(xdr, create->attrs, create->server);
638 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
649 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
661 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
663 extern u32 nfs4_fattr_bitmap[];
665 return encode_getattr_two(xdr,
666 bitmask[0] & nfs4_fattr_bitmap[0],
667 bitmask[1] & nfs4_fattr_bitmap[1]);
670 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
672 extern u32 nfs4_fsinfo_bitmap[];
674 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
675 bitmask[1] & nfs4_fsinfo_bitmap[1]);
678 static int encode_getfh(struct xdr_stream *xdr)
688 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
692 RESERVE_SPACE(8 + name->len);
695 WRITEMEM(name->name, name->len);
701 * opcode,type,reclaim,offset,length,new_lock_owner = 32
702 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
704 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
707 struct nfs_lock_opargs *opargs = arg->u.lock;
712 WRITE32(opargs->reclaim);
713 WRITE64(arg->offset);
714 WRITE64(arg->length);
715 WRITE32(opargs->new_lock_owner);
716 if (opargs->new_lock_owner){
717 struct nfs_open_to_lock *ol = opargs->u.open_lock;
720 WRITE32(ol->open_seqid);
721 WRITEMEM(&ol->open_stateid, sizeof(ol->open_stateid));
722 WRITE32(ol->lock_seqid);
723 WRITE64(ol->lock_owner.clientid);
725 WRITE32(ol->lock_owner.id);
728 struct nfs_exist_lock *el = opargs->u.exist_lock;
731 WRITEMEM(&el->stateid, sizeof(el->stateid));
738 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
741 struct nfs_lowner *opargs = arg->u.lockt;
746 WRITE64(arg->offset);
747 WRITE64(arg->length);
748 WRITE64(opargs->clientid);
755 static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
758 struct nfs_locku_opargs *opargs = arg->u.locku;
763 WRITE32(opargs->seqid);
764 WRITEMEM(&opargs->stateid, sizeof(opargs->stateid));
765 WRITE64(arg->offset);
766 WRITE64(arg->length);
771 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
776 RESERVE_SPACE(8 + len);
779 WRITEMEM(name->name, len);
784 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
789 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
791 WRITE32(NFS4_SHARE_ACCESS_READ);
794 WRITE32(NFS4_SHARE_ACCESS_WRITE);
796 case FMODE_READ|FMODE_WRITE:
797 WRITE32(NFS4_SHARE_ACCESS_BOTH);
802 WRITE32(0); /* for linux, share_deny = 0 always */
805 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
809 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
815 encode_share_access(xdr, arg->open_flags);
817 WRITE64(arg->clientid);
822 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
827 switch(arg->open_flags & O_EXCL) {
829 WRITE32(NFS4_CREATE_UNCHECKED);
830 encode_attrs(xdr, arg->u.attrs, arg->server);
833 WRITE32(NFS4_CREATE_EXCLUSIVE);
834 encode_nfs4_verifier(xdr, &arg->u.verifier);
838 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
843 switch (arg->open_flags & O_CREAT) {
845 WRITE32(NFS4_OPEN_NOCREATE);
848 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
849 WRITE32(NFS4_OPEN_CREATE);
850 encode_createmode(xdr, arg);
854 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
859 switch (delegation_type) {
861 WRITE32(NFS4_OPEN_DELEGATE_NONE);
864 WRITE32(NFS4_OPEN_DELEGATE_READ);
866 case FMODE_WRITE|FMODE_READ:
867 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
874 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
879 WRITE32(NFS4_OPEN_CLAIM_NULL);
880 encode_string(xdr, name->len, name->name);
883 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
888 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
889 encode_delegation_type(xdr, type);
892 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
896 RESERVE_SPACE(4+sizeof(stateid->data));
897 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
898 WRITEMEM(stateid->data, sizeof(stateid->data));
899 encode_string(xdr, name->len, name->name);
902 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
904 encode_openhdr(xdr, arg);
905 encode_opentype(xdr, arg);
906 switch (arg->claim) {
907 case NFS4_OPEN_CLAIM_NULL:
908 encode_claim_null(xdr, arg->name);
910 case NFS4_OPEN_CLAIM_PREVIOUS:
911 encode_claim_previous(xdr, arg->u.delegation_type);
913 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
914 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
922 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
926 RESERVE_SPACE(8+sizeof(arg->stateid.data));
927 WRITE32(OP_OPEN_CONFIRM);
928 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
934 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
938 RESERVE_SPACE(8+sizeof(arg->stateid.data));
939 WRITE32(OP_OPEN_DOWNGRADE);
940 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
942 encode_share_access(xdr, arg->open_flags);
947 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
952 RESERVE_SPACE(8 + len);
955 WRITEMEM(fh->data, len);
960 static int encode_putrootfh(struct xdr_stream *xdr)
965 WRITE32(OP_PUTROOTFH);
970 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
972 extern nfs4_stateid zero_stateid;
973 nfs4_stateid stateid;
977 if (ctx->state != NULL) {
978 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
979 WRITEMEM(stateid.data, sizeof(stateid.data));
981 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
984 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
991 encode_stateid(xdr, args->context);
994 WRITE64(args->offset);
995 WRITE32(args->count);
1000 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1002 struct rpc_auth *auth = req->rq_task->tk_auth;
1006 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1007 WRITE32(OP_READDIR);
1008 WRITE64(readdir->cookie);
1009 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1010 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1011 WRITE32(readdir->count);
1013 WRITE32(FATTR4_WORD0_FILEID);
1016 /* set up reply kvec
1017 * toplevel_status + taglen + rescount + OP_PUTFH + status
1018 * + OP_READDIR + status + verifer(2) = 9
1020 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1021 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1022 readdir->pgbase, readdir->count);
1027 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1029 struct rpc_auth *auth = req->rq_task->tk_auth;
1030 unsigned int replen;
1034 WRITE32(OP_READLINK);
1036 /* set up reply kvec
1037 * toplevel_status + taglen + rescount + OP_PUTFH + status
1038 * + OP_READLINK + status + string length = 8
1040 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1041 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1042 readlink->pgbase, readlink->pglen);
1047 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1051 RESERVE_SPACE(8 + name->len);
1054 WRITEMEM(name->name, name->len);
1059 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1063 RESERVE_SPACE(8 + oldname->len);
1065 WRITE32(oldname->len);
1066 WRITEMEM(oldname->name, oldname->len);
1068 RESERVE_SPACE(4 + newname->len);
1069 WRITE32(newname->len);
1070 WRITEMEM(newname->name, newname->len);
1075 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1081 WRITE64(client_stateid->cl_clientid);
1087 encode_savefh(struct xdr_stream *xdr)
1097 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1102 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1103 WRITE32(OP_SETATTR);
1104 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1106 if ((status = encode_attrs(xdr, arg->iap, server)))
1112 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1116 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1117 WRITE32(OP_SETCLIENTID);
1118 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1120 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1122 WRITE32(setclientid->sc_prog);
1123 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1124 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1126 WRITE32(setclientid->sc_cb_ident);
1131 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1135 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1136 WRITE32(OP_SETCLIENTID_CONFIRM);
1137 WRITE64(client_state->cl_clientid);
1138 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1143 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1150 encode_stateid(xdr, args->context);
1153 WRITE64(args->offset);
1154 WRITE32(args->stable);
1155 WRITE32(args->count);
1157 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1162 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1168 WRITE32(OP_DELEGRETURN);
1169 WRITEMEM(stateid->data, sizeof(stateid->data));
1174 * END OF "GENERIC" ENCODE ROUTINES.
1178 * Encode an ACCESS request
1180 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1182 struct xdr_stream xdr;
1183 struct compound_hdr hdr = {
1188 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1189 encode_compound_hdr(&xdr, &hdr);
1190 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1191 status = encode_access(&xdr, args->access);
1196 * Encode LOOKUP request
1198 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1200 struct xdr_stream xdr;
1201 struct compound_hdr hdr = {
1206 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1207 encode_compound_hdr(&xdr, &hdr);
1208 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1210 if ((status = encode_lookup(&xdr, args->name)) != 0)
1212 if ((status = encode_getfh(&xdr)) != 0)
1214 status = encode_getfattr(&xdr, args->bitmask);
1220 * Encode LOOKUP_ROOT request
1222 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1224 struct xdr_stream xdr;
1225 struct compound_hdr hdr = {
1230 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1231 encode_compound_hdr(&xdr, &hdr);
1232 if ((status = encode_putrootfh(&xdr)) != 0)
1234 if ((status = encode_getfh(&xdr)) == 0)
1235 status = encode_getfattr(&xdr, args->bitmask);
1241 * Encode REMOVE request
1243 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1245 struct xdr_stream xdr;
1246 struct compound_hdr hdr = {
1251 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1252 encode_compound_hdr(&xdr, &hdr);
1253 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1254 status = encode_remove(&xdr, args->name);
1259 * Encode RENAME request
1261 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1263 struct xdr_stream xdr;
1264 struct compound_hdr hdr = {
1269 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1270 encode_compound_hdr(&xdr, &hdr);
1271 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1273 if ((status = encode_savefh(&xdr)) != 0)
1275 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1277 status = encode_rename(&xdr, args->old_name, args->new_name);
1283 * Encode LINK request
1285 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1287 struct xdr_stream xdr;
1288 struct compound_hdr hdr = {
1293 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1294 encode_compound_hdr(&xdr, &hdr);
1295 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1297 if ((status = encode_savefh(&xdr)) != 0)
1299 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1301 status = encode_link(&xdr, args->name);
1307 * Encode CREATE request
1309 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1311 struct xdr_stream xdr;
1312 struct compound_hdr hdr = {
1317 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1318 encode_compound_hdr(&xdr, &hdr);
1319 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1321 if ((status = encode_create(&xdr, args)) != 0)
1323 if ((status = encode_getfh(&xdr)) != 0)
1325 status = encode_getfattr(&xdr, args->bitmask);
1331 * Encode SYMLINK request
1333 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1335 return nfs4_xdr_enc_create(req, p, args);
1339 * Encode GETATTR request
1341 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1343 struct xdr_stream xdr;
1344 struct compound_hdr hdr = {
1349 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1350 encode_compound_hdr(&xdr, &hdr);
1351 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1352 status = encode_getfattr(&xdr, args->bitmask);
1357 * Encode a CLOSE request
1359 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1361 struct xdr_stream xdr;
1362 struct compound_hdr hdr = {
1367 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1368 encode_compound_hdr(&xdr, &hdr);
1369 status = encode_putfh(&xdr, args->fh);
1372 status = encode_close(&xdr, args);
1378 * Encode an OPEN request
1380 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1382 struct xdr_stream xdr;
1383 struct compound_hdr hdr = {
1388 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1389 encode_compound_hdr(&xdr, &hdr);
1390 status = encode_putfh(&xdr, args->fh);
1393 status = encode_open(&xdr, args);
1396 status = encode_getfh(&xdr);
1399 status = encode_getfattr(&xdr, args->bitmask);
1405 * Encode an OPEN_CONFIRM request
1407 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1409 struct xdr_stream xdr;
1410 struct compound_hdr hdr = {
1415 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1416 encode_compound_hdr(&xdr, &hdr);
1417 status = encode_putfh(&xdr, args->fh);
1420 status = encode_open_confirm(&xdr, args);
1426 * Encode an OPEN request with no attributes.
1428 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1430 struct xdr_stream xdr;
1431 struct compound_hdr hdr = {
1436 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1437 encode_compound_hdr(&xdr, &hdr);
1438 status = encode_putfh(&xdr, args->fh);
1441 status = encode_open(&xdr, args);
1447 * Encode an OPEN_DOWNGRADE request
1449 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1451 struct xdr_stream xdr;
1452 struct compound_hdr hdr = {
1457 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1458 encode_compound_hdr(&xdr, &hdr);
1459 status = encode_putfh(&xdr, args->fh);
1462 status = encode_open_downgrade(&xdr, args);
1468 * Encode a LOCK request
1470 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1472 struct xdr_stream xdr;
1473 struct compound_hdr hdr = {
1478 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1479 encode_compound_hdr(&xdr, &hdr);
1480 status = encode_putfh(&xdr, args->fh);
1483 status = encode_lock(&xdr, args);
1489 * Encode a LOCKT request
1491 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1493 struct xdr_stream xdr;
1494 struct compound_hdr hdr = {
1499 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1500 encode_compound_hdr(&xdr, &hdr);
1501 status = encode_putfh(&xdr, args->fh);
1504 status = encode_lockt(&xdr, args);
1510 * Encode a LOCKU request
1512 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1514 struct xdr_stream xdr;
1515 struct compound_hdr hdr = {
1520 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1521 encode_compound_hdr(&xdr, &hdr);
1522 status = encode_putfh(&xdr, args->fh);
1525 status = encode_locku(&xdr, args);
1531 * Encode a READLINK request
1533 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1535 struct xdr_stream xdr;
1536 struct compound_hdr hdr = {
1541 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1542 encode_compound_hdr(&xdr, &hdr);
1543 status = encode_putfh(&xdr, args->fh);
1546 status = encode_readlink(&xdr, args, req);
1552 * Encode a READDIR request
1554 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1556 struct xdr_stream xdr;
1557 struct compound_hdr hdr = {
1562 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1563 encode_compound_hdr(&xdr, &hdr);
1564 status = encode_putfh(&xdr, args->fh);
1567 status = encode_readdir(&xdr, args, req);
1573 * Encode a READ request
1575 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1577 struct rpc_auth *auth = req->rq_task->tk_auth;
1578 struct xdr_stream xdr;
1579 struct compound_hdr hdr = {
1584 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1585 encode_compound_hdr(&xdr, &hdr);
1586 status = encode_putfh(&xdr, args->fh);
1589 status = encode_read(&xdr, args);
1593 /* set up reply kvec
1594 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1595 * + OP_READ + status + eof + datalen = 9
1597 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1598 xdr_inline_pages(&req->rq_rcv_buf, replen,
1599 args->pages, args->pgbase, args->count);
1605 * Encode an SETATTR request
1607 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1610 struct xdr_stream xdr;
1611 struct compound_hdr hdr = {
1616 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1617 encode_compound_hdr(&xdr, &hdr);
1618 status = encode_putfh(&xdr, args->fh);
1621 status = encode_setattr(&xdr, args, args->server);
1624 status = encode_getfattr(&xdr, args->bitmask);
1630 * Encode a WRITE request
1632 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1634 struct xdr_stream xdr;
1635 struct compound_hdr hdr = {
1640 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1641 encode_compound_hdr(&xdr, &hdr);
1642 status = encode_putfh(&xdr, args->fh);
1645 status = encode_write(&xdr, args);
1653 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1655 struct xdr_stream xdr;
1656 struct compound_hdr hdr = {
1661 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1662 encode_compound_hdr(&xdr, &hdr);
1663 status = encode_putfh(&xdr, args->fh);
1666 status = encode_commit(&xdr, args);
1674 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1676 struct xdr_stream xdr;
1677 struct compound_hdr hdr = {
1682 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1683 encode_compound_hdr(&xdr, &hdr);
1684 status = encode_putfh(&xdr, args->fh);
1686 status = encode_fsinfo(&xdr, args->bitmask);
1691 * a PATHCONF request
1693 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1695 extern u32 nfs4_pathconf_bitmap[2];
1696 struct xdr_stream xdr;
1697 struct compound_hdr hdr = {
1702 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1703 encode_compound_hdr(&xdr, &hdr);
1704 status = encode_putfh(&xdr, args->fh);
1706 status = encode_getattr_one(&xdr,
1707 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1714 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1716 extern u32 nfs4_statfs_bitmap[];
1717 struct xdr_stream xdr;
1718 struct compound_hdr hdr = {
1723 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1724 encode_compound_hdr(&xdr, &hdr);
1725 status = encode_putfh(&xdr, args->fh);
1727 status = encode_getattr_two(&xdr,
1728 args->bitmask[0] & nfs4_statfs_bitmap[0],
1729 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1734 * GETATTR_BITMAP request
1736 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1738 struct xdr_stream xdr;
1739 struct compound_hdr hdr = {
1744 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1745 encode_compound_hdr(&xdr, &hdr);
1746 status = encode_putfh(&xdr, fhandle);
1748 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1749 FATTR4_WORD0_LINK_SUPPORT|
1750 FATTR4_WORD0_SYMLINK_SUPPORT|
1751 FATTR4_WORD0_ACLSUPPORT);
1758 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1760 struct xdr_stream xdr;
1761 struct compound_hdr hdr = {
1765 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1766 encode_compound_hdr(&xdr, &hdr);
1767 return encode_renew(&xdr, clp);
1771 * a SETCLIENTID request
1773 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1775 struct xdr_stream xdr;
1776 struct compound_hdr hdr = {
1780 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1781 encode_compound_hdr(&xdr, &hdr);
1782 return encode_setclientid(&xdr, sc);
1786 * a SETCLIENTID_CONFIRM request
1788 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1790 struct xdr_stream xdr;
1791 struct compound_hdr hdr = {
1794 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1797 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1798 encode_compound_hdr(&xdr, &hdr);
1799 status = encode_setclientid_confirm(&xdr, clp);
1801 status = encode_putrootfh(&xdr);
1803 status = encode_fsinfo(&xdr, lease_bitmap);
1808 * DELEGRETURN request
1810 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1812 struct xdr_stream xdr;
1813 struct compound_hdr hdr = {
1818 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1819 encode_compound_hdr(&xdr, &hdr);
1820 if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
1821 status = encode_delegreturn(&xdr, args->stateid);
1826 * START OF "GENERIC" DECODE ROUTINES.
1827 * These may look a little ugly since they are imported from a "generic"
1828 * set of XDR encode/decode routines which are intended to be shared by
1829 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1831 * If the pain of reading these is too great, it should be a straightforward
1832 * task to translate them into Linux-specific versions which are more
1833 * consistent with the style used in NFSv2/v3...
1835 #define READ32(x) (x) = ntohl(*p++)
1836 #define READ64(x) do { \
1837 (x) = (u64)ntohl(*p++) << 32; \
1838 (x) |= ntohl(*p++); \
1840 #define READTIME(x) do { \
1842 (x.tv_sec) = ntohl(*p++); \
1843 (x.tv_nsec) = ntohl(*p++); \
1845 #define COPYMEM(x,nbytes) do { \
1846 memcpy((x), p, nbytes); \
1847 p += XDR_QUADLEN(nbytes); \
1850 #define READ_BUF(nbytes) do { \
1851 p = xdr_inline_decode(xdr, nbytes); \
1853 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
1854 __FUNCTION__, __LINE__); \
1859 static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
1866 *string = (char *)p;
1870 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
1875 READ32(hdr->status);
1876 READ32(hdr->taglen);
1878 READ_BUF(hdr->taglen + 4);
1879 hdr->tag = (char *)p;
1880 p += XDR_QUADLEN(hdr->taglen);
1885 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
1893 if (opnum != expected) {
1895 "nfs4_decode_op_hdr: Server returned operation"
1896 " %d but we issued a request for %d\n",
1901 if (nfserr != NFS_OK)
1902 return -nfs_stat_to_errno(nfserr);
1907 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
1914 return decode_opaque_inline(xdr, &strlen, &str);
1917 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
1924 bitmap[0] = bitmap[1] = 0;
1925 READ_BUF((bmlen << 2));
1934 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
1944 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
1946 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
1947 decode_attr_bitmap(xdr, bitmask);
1948 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
1950 bitmask[0] = bitmask[1] = 0;
1951 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
1955 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
1960 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
1962 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
1965 if (*type < NF4REG || *type > NF4NAMEDATTR) {
1966 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
1969 bitmap[0] &= ~FATTR4_WORD0_TYPE;
1971 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
1975 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
1980 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
1982 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
1985 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
1987 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
1988 (unsigned long long)*change);
1992 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
1997 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
1999 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2002 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2004 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2008 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2013 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2015 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2018 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2020 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2024 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2029 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2031 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2034 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2036 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2040 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2046 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2048 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2050 READ64(fsid->major);
2051 READ64(fsid->minor);
2052 bitmap[0] &= ~FATTR4_WORD0_FSID;
2054 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2055 (unsigned long long)fsid->major,
2056 (unsigned long long)fsid->minor);
2060 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2065 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2067 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2070 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2072 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2076 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2080 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2081 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2083 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2086 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2088 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2092 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2097 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2099 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2102 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2104 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2108 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2114 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2116 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2119 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2121 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2125 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2131 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2133 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2136 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2138 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2142 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2148 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2150 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2153 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2155 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2159 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2165 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2167 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2170 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2172 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2176 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2182 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2184 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2187 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2189 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2193 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2199 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2201 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2204 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2206 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2210 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2216 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2218 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2222 if (maxread > 0x7FFFFFFF)
2223 maxread = 0x7FFFFFFF;
2224 *res = (uint32_t)maxread;
2225 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2227 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2231 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2237 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2239 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2243 if (maxwrite > 0x7FFFFFFF)
2244 maxwrite = 0x7FFFFFFF;
2245 *res = (uint32_t)maxwrite;
2246 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2248 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2252 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2257 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2259 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2263 bitmap[1] &= ~FATTR4_WORD1_MODE;
2265 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2269 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2274 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2276 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2279 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2281 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2285 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2290 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2292 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2296 if (len < XDR_MAX_NETOBJ) {
2297 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2298 dprintk("%s: nfs_map_name_to_uid failed!\n",
2301 printk(KERN_WARNING "%s: name too long (%u)!\n",
2303 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2305 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2309 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2314 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2316 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2320 if (len < XDR_MAX_NETOBJ) {
2321 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2322 dprintk("%s: nfs_map_group_to_gid failed!\n",
2325 printk(KERN_WARNING "%s: name too long (%u)!\n",
2327 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2329 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2333 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2335 uint32_t major = 0, minor = 0, *p;
2338 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2340 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2346 tmp = MKDEV(major, minor);
2347 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2349 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2351 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2355 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2361 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2363 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2366 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2368 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2372 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2378 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2380 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2383 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2385 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2389 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2395 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2397 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2400 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2402 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2406 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2411 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2413 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2416 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2418 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2419 (unsigned long long)*used);
2423 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2432 time->tv_sec = (time_t)sec;
2433 time->tv_nsec = (long)nsec;
2437 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2443 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2445 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2446 status = decode_attr_time(xdr, time);
2447 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2449 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2453 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2459 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2461 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2462 status = decode_attr_time(xdr, time);
2463 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2465 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2469 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2475 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2477 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2478 status = decode_attr_time(xdr, time);
2479 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2481 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2485 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2487 unsigned int attrwords = XDR_QUADLEN(attrlen);
2488 unsigned int nwords = xdr->p - savep;
2490 if (unlikely(attrwords != nwords)) {
2491 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2494 (attrwords < nwords) ? '<' : '>',
2501 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2506 READ32(cinfo->atomic);
2507 READ64(cinfo->before);
2508 READ64(cinfo->after);
2512 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2518 status = decode_op_hdr(xdr, OP_ACCESS);
2524 access->supported = supp;
2525 access->access = acc;
2529 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2534 status = decode_op_hdr(xdr, OP_CLOSE);
2537 READ_BUF(sizeof(res->stateid.data));
2538 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2542 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2547 status = decode_op_hdr(xdr, OP_COMMIT);
2551 COPYMEM(res->verf->verifier, 8);
2555 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2561 status = decode_op_hdr(xdr, OP_CREATE);
2564 if ((status = decode_change_info(xdr, cinfo)))
2568 READ_BUF(bmlen << 2);
2572 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2579 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2581 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2583 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2585 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2587 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2589 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2591 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2593 status = verify_attr_len(xdr, savep, attrlen);
2596 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2600 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2607 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2609 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2611 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2614 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2616 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2618 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2620 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2622 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2624 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2627 status = verify_attr_len(xdr, savep, attrlen);
2630 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2634 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2641 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2643 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2645 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2648 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2650 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2653 status = verify_attr_len(xdr, savep, attrlen);
2656 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2660 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2666 int status, fmode = 0;
2668 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2670 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2673 fattr->bitmap[0] = bitmap[0];
2674 fattr->bitmap[1] = bitmap[1];
2676 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2680 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2682 fattr->type = nfs_type2fmt[type].nfs2type;
2683 fmode = nfs_type2fmt[type].mode;
2685 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2687 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2689 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2691 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2693 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2695 fattr->mode |= fmode;
2696 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2698 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2700 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2702 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2704 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2706 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2708 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2710 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2712 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) {
2713 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2714 fattr->timestamp = jiffies;
2718 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2723 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2726 uint32_t attrlen, bitmap[2];
2729 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2731 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2733 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2736 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2738 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2740 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2742 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2744 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2745 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2747 fsinfo->wtpref = fsinfo->wtmax;
2749 status = verify_attr_len(xdr, savep, attrlen);
2752 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2756 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2762 status = decode_op_hdr(xdr, OP_GETFH);
2765 /* Zero handle first to allow comparisons */
2766 memset(fh, 0, sizeof(*fh));
2770 if (len > NFS4_FHSIZE)
2774 COPYMEM(fh->data, len);
2778 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2782 status = decode_op_hdr(xdr, OP_LINK);
2785 return decode_change_info(xdr, cinfo);
2789 * We create the owner, so we know a proper owner.id length is 4.
2791 static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2797 READ64(denied->offset);
2798 READ64(denied->length);
2799 READ32(denied->type);
2800 READ64(denied->owner.clientid);
2804 READ32(denied->owner.id);
2805 return -NFS4ERR_DENIED;
2808 static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2813 status = decode_op_hdr(xdr, OP_LOCK);
2815 READ_BUF(sizeof(nfs4_stateid));
2816 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2817 } else if (status == -NFS4ERR_DENIED)
2818 return decode_lock_denied(xdr, &res->u.denied);
2822 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2825 status = decode_op_hdr(xdr, OP_LOCKT);
2826 if (status == -NFS4ERR_DENIED)
2827 return decode_lock_denied(xdr, &res->u.denied);
2831 static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2836 status = decode_op_hdr(xdr, OP_LOCKU);
2838 READ_BUF(sizeof(nfs4_stateid));
2839 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2844 static int decode_lookup(struct xdr_stream *xdr)
2846 return decode_op_hdr(xdr, OP_LOOKUP);
2849 /* This is too sick! */
2850 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
2853 uint32_t limit_type, nblocks, blocksize;
2857 switch (limit_type) {
2864 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
2869 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
2872 uint32_t delegation_type;
2875 READ32(delegation_type);
2876 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
2877 res->delegation_type = 0;
2881 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
2882 READ32(res->do_recall);
2883 switch (delegation_type) {
2884 case NFS4_OPEN_DELEGATE_READ:
2885 res->delegation_type = FMODE_READ;
2887 case NFS4_OPEN_DELEGATE_WRITE:
2888 res->delegation_type = FMODE_WRITE|FMODE_READ;
2889 if (decode_space_limit(xdr, &res->maxsize) < 0)
2892 return decode_ace(xdr, NULL, res->server->nfs4_state);
2895 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
2901 status = decode_op_hdr(xdr, OP_OPEN);
2904 READ_BUF(sizeof(res->stateid.data));
2905 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2907 decode_change_info(xdr, &res->cinfo);
2910 READ32(res->rflags);
2915 READ_BUF(bmlen << 2);
2917 return decode_delegation(xdr, res);
2919 printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
2923 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
2928 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
2931 READ_BUF(sizeof(res->stateid.data));
2932 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2936 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
2941 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
2944 READ_BUF(sizeof(res->stateid.data));
2945 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2949 static int decode_putfh(struct xdr_stream *xdr)
2951 return decode_op_hdr(xdr, OP_PUTFH);
2954 static int decode_putrootfh(struct xdr_stream *xdr)
2956 return decode_op_hdr(xdr, OP_PUTROOTFH);
2959 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
2961 struct kvec *iov = req->rq_rcv_buf.head;
2963 uint32_t count, eof, recvd, hdrlen;
2966 status = decode_op_hdr(xdr, OP_READ);
2972 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
2973 recvd = req->rq_rcv_buf.len - hdrlen;
2974 if (count > recvd) {
2975 printk(KERN_WARNING "NFS: server cheating in read reply: "
2976 "count %u > recvd %u\n", count, recvd);
2980 xdr_read_pages(xdr, count);
2986 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
2988 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
2989 struct page *page = *rcvbuf->pages;
2990 struct kvec *iov = rcvbuf->head;
2991 unsigned int nr, pglen = rcvbuf->page_len;
2992 uint32_t *end, *entry, *p, *kaddr;
2993 uint32_t len, attrlen;
2994 int hdrlen, recvd, status;
2996 status = decode_op_hdr(xdr, OP_READDIR);
3000 COPYMEM(readdir->verifier.data, 8);
3002 hdrlen = (char *) p - (char *) iov->iov_base;
3003 recvd = rcvbuf->len - hdrlen;
3006 xdr_read_pages(xdr, pglen);
3008 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3009 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3010 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3012 for (nr = 0; *p++; nr++) {
3015 p += 2; /* cookie */
3016 len = ntohl(*p++); /* filename length */
3017 if (len > NFS4_MAXNAMLEN) {
3018 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3021 p += XDR_QUADLEN(len);
3024 len = ntohl(*p++); /* bitmap length */
3028 attrlen = XDR_QUADLEN(ntohl(*p++));
3029 p += attrlen; /* attributes */
3034 if (!nr && (entry[0] != 0 || entry[1] == 0))
3037 kunmap_atomic(kaddr, KM_USER0);
3040 entry[0] = entry[1] = 0;
3041 /* truncate listing ? */
3043 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3048 kunmap_atomic(kaddr, KM_USER0);
3049 return -errno_NFSERR_IO;
3052 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3054 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3055 struct kvec *iov = rcvbuf->head;
3056 int hdrlen, len, recvd;
3061 status = decode_op_hdr(xdr, OP_READLINK);
3065 /* Convert length of symlink */
3068 if (len >= rcvbuf->page_len || len <= 0) {
3069 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3070 return -ENAMETOOLONG;
3072 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3073 recvd = req->rq_rcv_buf.len - hdrlen;
3075 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3076 "count %u > recvd %u\n", len, recvd);
3079 xdr_read_pages(xdr, len);
3081 * The XDR encode routine has set things up so that
3082 * the link text will be copied directly into the
3083 * buffer. We just have to do overflow-checking,
3084 * and and null-terminate the text (the VFS expects
3085 * null-termination).
3087 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3088 kaddr[len+rcvbuf->page_base] = '\0';
3089 kunmap_atomic(kaddr, KM_USER0);
3093 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3097 status = decode_op_hdr(xdr, OP_REMOVE);
3100 status = decode_change_info(xdr, cinfo);
3105 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3106 struct nfs4_change_info *new_cinfo)
3110 status = decode_op_hdr(xdr, OP_RENAME);
3113 if ((status = decode_change_info(xdr, old_cinfo)))
3115 status = decode_change_info(xdr, new_cinfo);
3120 static int decode_renew(struct xdr_stream *xdr)
3122 return decode_op_hdr(xdr, OP_RENEW);
3126 decode_savefh(struct xdr_stream *xdr)
3128 return decode_op_hdr(xdr, OP_SAVEFH);
3131 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3138 status = decode_op_hdr(xdr, OP_SETATTR);
3143 READ_BUF(bmlen << 2);
3147 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3155 if (opnum != OP_SETCLIENTID) {
3157 "nfs4_decode_setclientid: Server returned operation"
3162 if (nfserr == NFS_OK) {
3163 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3164 READ64(clp->cl_clientid);
3165 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3166 } else if (nfserr == NFSERR_CLID_INUSE) {
3169 /* skip netid string */
3174 /* skip uaddr string */
3180 return -nfs_stat_to_errno(nfserr);
3185 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3187 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3190 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3195 status = decode_op_hdr(xdr, OP_WRITE);
3201 READ32(res->verf->committed);
3202 COPYMEM(res->verf->verifier, 8);
3206 static int decode_delegreturn(struct xdr_stream *xdr)
3208 return decode_op_hdr(xdr, OP_DELEGRETURN);
3212 * Decode OPEN_DOWNGRADE response
3214 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3216 struct xdr_stream xdr;
3217 struct compound_hdr hdr;
3220 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3221 status = decode_compound_hdr(&xdr, &hdr);
3224 status = decode_putfh(&xdr);
3227 status = decode_open_downgrade(&xdr, res);
3233 * END OF "GENERIC" DECODE ROUTINES.
3237 * Decode ACCESS response
3239 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3241 struct xdr_stream xdr;
3242 struct compound_hdr hdr;
3245 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3246 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3248 if ((status = decode_putfh(&xdr)) == 0)
3249 status = decode_access(&xdr, res);
3255 * Decode LOOKUP response
3257 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3259 struct xdr_stream xdr;
3260 struct compound_hdr hdr;
3263 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3264 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3266 if ((status = decode_putfh(&xdr)) != 0)
3268 if ((status = decode_lookup(&xdr)) != 0)
3270 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3272 status = decode_getfattr(&xdr, res->fattr, res->server);
3278 * Decode LOOKUP_ROOT response
3280 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3282 struct xdr_stream xdr;
3283 struct compound_hdr hdr;
3286 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3287 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3289 if ((status = decode_putrootfh(&xdr)) != 0)
3291 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3292 status = decode_getfattr(&xdr, res->fattr, res->server);
3298 * Decode REMOVE response
3300 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3302 struct xdr_stream xdr;
3303 struct compound_hdr hdr;
3306 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3307 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3309 if ((status = decode_putfh(&xdr)) == 0)
3310 status = decode_remove(&xdr, cinfo);
3316 * Decode RENAME response
3318 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3320 struct xdr_stream xdr;
3321 struct compound_hdr hdr;
3324 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3325 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3327 if ((status = decode_putfh(&xdr)) != 0)
3329 if ((status = decode_savefh(&xdr)) != 0)
3331 if ((status = decode_putfh(&xdr)) != 0)
3333 status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
3339 * Decode LINK response
3341 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3343 struct xdr_stream xdr;
3344 struct compound_hdr hdr;
3347 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3348 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3350 if ((status = decode_putfh(&xdr)) != 0)
3352 if ((status = decode_savefh(&xdr)) != 0)
3354 if ((status = decode_putfh(&xdr)) != 0)
3356 status = decode_link(&xdr, cinfo);
3362 * Decode CREATE response
3364 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3366 struct xdr_stream xdr;
3367 struct compound_hdr hdr;
3370 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3371 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3373 if ((status = decode_putfh(&xdr)) != 0)
3375 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3377 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3379 status = decode_getfattr(&xdr, res->fattr, res->server);
3380 if (status == NFS4ERR_DELAY)
3387 * Decode SYMLINK response
3389 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3391 return nfs4_xdr_dec_create(rqstp, p, res);
3395 * Decode GETATTR response
3397 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3399 struct xdr_stream xdr;
3400 struct compound_hdr hdr;
3403 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3404 status = decode_compound_hdr(&xdr, &hdr);
3407 status = decode_putfh(&xdr);
3410 status = decode_getfattr(&xdr, res->fattr, res->server);
3418 * Decode CLOSE response
3420 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3422 struct xdr_stream xdr;
3423 struct compound_hdr hdr;
3426 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3427 status = decode_compound_hdr(&xdr, &hdr);
3430 status = decode_putfh(&xdr);
3433 status = decode_close(&xdr, res);
3439 * Decode OPEN response
3441 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3443 struct xdr_stream xdr;
3444 struct compound_hdr hdr;
3447 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3448 status = decode_compound_hdr(&xdr, &hdr);
3451 status = decode_putfh(&xdr);
3454 status = decode_open(&xdr, res);
3457 status = decode_getfh(&xdr, &res->fh);
3460 status = decode_getfattr(&xdr, res->f_attr, res->server);
3461 if (status == NFS4ERR_DELAY)
3468 * Decode OPEN_CONFIRM response
3470 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3472 struct xdr_stream xdr;
3473 struct compound_hdr hdr;
3476 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3477 status = decode_compound_hdr(&xdr, &hdr);
3480 status = decode_putfh(&xdr);
3483 status = decode_open_confirm(&xdr, res);
3489 * Decode OPEN response
3491 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3493 struct xdr_stream xdr;
3494 struct compound_hdr hdr;
3497 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3498 status = decode_compound_hdr(&xdr, &hdr);
3501 status = decode_putfh(&xdr);
3504 status = decode_open(&xdr, res);
3510 * Decode SETATTR response
3512 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3514 struct xdr_stream xdr;
3515 struct compound_hdr hdr;
3518 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3519 status = decode_compound_hdr(&xdr, &hdr);
3522 status = decode_putfh(&xdr);
3525 status = decode_setattr(&xdr, res);
3528 status = decode_getfattr(&xdr, res->fattr, res->server);
3529 if (status == NFS4ERR_DELAY)
3536 * Decode LOCK response
3538 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3540 struct xdr_stream xdr;
3541 struct compound_hdr hdr;
3544 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3545 status = decode_compound_hdr(&xdr, &hdr);
3548 status = decode_putfh(&xdr);
3551 status = decode_lock(&xdr, res);
3557 * Decode LOCKT response
3559 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3561 struct xdr_stream xdr;
3562 struct compound_hdr hdr;
3565 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3566 status = decode_compound_hdr(&xdr, &hdr);
3569 status = decode_putfh(&xdr);
3572 status = decode_lockt(&xdr, res);
3578 * Decode LOCKU response
3580 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3582 struct xdr_stream xdr;
3583 struct compound_hdr hdr;
3586 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3587 status = decode_compound_hdr(&xdr, &hdr);
3590 status = decode_putfh(&xdr);
3593 status = decode_locku(&xdr, res);
3599 * Decode READLINK response
3601 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3603 struct xdr_stream xdr;
3604 struct compound_hdr hdr;
3607 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3608 status = decode_compound_hdr(&xdr, &hdr);
3611 status = decode_putfh(&xdr);
3614 status = decode_readlink(&xdr, rqstp);
3620 * Decode READDIR response
3622 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3624 struct xdr_stream xdr;
3625 struct compound_hdr hdr;
3628 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3629 status = decode_compound_hdr(&xdr, &hdr);
3632 status = decode_putfh(&xdr);
3635 status = decode_readdir(&xdr, rqstp, res);
3641 * Decode Read response
3643 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3645 struct xdr_stream xdr;
3646 struct compound_hdr hdr;
3649 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3650 status = decode_compound_hdr(&xdr, &hdr);
3653 status = decode_putfh(&xdr);
3656 status = decode_read(&xdr, rqstp, res);
3658 status = res->count;
3664 * Decode WRITE response
3666 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3668 struct xdr_stream xdr;
3669 struct compound_hdr hdr;
3672 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3673 status = decode_compound_hdr(&xdr, &hdr);
3676 status = decode_putfh(&xdr);
3679 status = decode_write(&xdr, res);
3681 status = res->count;
3687 * Decode COMMIT response
3689 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3691 struct xdr_stream xdr;
3692 struct compound_hdr hdr;
3695 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3696 status = decode_compound_hdr(&xdr, &hdr);
3699 status = decode_putfh(&xdr);
3702 status = decode_commit(&xdr, res);
3710 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3712 struct xdr_stream xdr;
3713 struct compound_hdr hdr;
3716 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3717 status = decode_compound_hdr(&xdr, &hdr);
3719 status = decode_putfh(&xdr);
3721 status = decode_fsinfo(&xdr, fsinfo);
3723 status = -nfs_stat_to_errno(hdr.status);
3730 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
3732 struct xdr_stream xdr;
3733 struct compound_hdr hdr;
3736 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3737 status = decode_compound_hdr(&xdr, &hdr);
3739 status = decode_putfh(&xdr);
3741 status = decode_pathconf(&xdr, pathconf);
3748 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
3750 struct xdr_stream xdr;
3751 struct compound_hdr hdr;
3754 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3755 status = decode_compound_hdr(&xdr, &hdr);
3757 status = decode_putfh(&xdr);
3759 status = decode_statfs(&xdr, fsstat);
3764 * GETATTR_BITMAP request
3766 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
3768 struct xdr_stream xdr;
3769 struct compound_hdr hdr;
3772 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3773 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3775 if ((status = decode_putfh(&xdr)) != 0)
3777 status = decode_server_caps(&xdr, res);
3783 * Decode RENEW response
3785 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3787 struct xdr_stream xdr;
3788 struct compound_hdr hdr;
3791 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3792 status = decode_compound_hdr(&xdr, &hdr);
3794 status = decode_renew(&xdr);
3799 * a SETCLIENTID request
3801 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
3802 struct nfs4_client *clp)
3804 struct xdr_stream xdr;
3805 struct compound_hdr hdr;
3808 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3809 status = decode_compound_hdr(&xdr, &hdr);
3811 status = decode_setclientid(&xdr, clp);
3813 status = -nfs_stat_to_errno(hdr.status);
3818 * a SETCLIENTID_CONFIRM request
3820 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3822 struct xdr_stream xdr;
3823 struct compound_hdr hdr;
3826 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3827 status = decode_compound_hdr(&xdr, &hdr);
3829 status = decode_setclientid_confirm(&xdr);
3831 status = decode_putrootfh(&xdr);
3833 status = decode_fsinfo(&xdr, fsinfo);
3835 status = -nfs_stat_to_errno(hdr.status);
3840 * DELEGRETURN request
3842 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3844 struct xdr_stream xdr;
3845 struct compound_hdr hdr;
3848 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3849 status = decode_compound_hdr(&xdr, &hdr);
3851 status = decode_putfh(&xdr);
3853 status = decode_delegreturn(&xdr);
3858 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
3860 uint32_t bitmap[1] = {0};
3865 return ERR_PTR(-EAGAIN);
3867 return ERR_PTR(-EBADCOOKIE);
3870 entry->prev_cookie = entry->cookie;
3871 p = xdr_decode_hyper(p, &entry->cookie);
3872 entry->len = ntohl(*p++);
3873 entry->name = (const char *) p;
3874 p += XDR_QUADLEN(entry->len);
3877 * In case the server doesn't return an inode number,
3878 * we fake one here. (We don't use inode number 0,
3879 * since glibc seems to choke on it...)
3883 len = ntohl(*p++); /* bitmap length */
3885 bitmap[0] = ntohl(*p);
3888 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
3890 if (bitmap[0] == FATTR4_WORD0_FILEID)
3891 xdr_decode_hyper(p, &entry->ino);
3895 entry->eof = !p[0] && p[1];
3900 * We need to translate between nfs status return values and
3901 * the local errno values which may not be the same.
3908 { NFS4ERR_PERM, EPERM },
3909 { NFS4ERR_NOENT, ENOENT },
3910 { NFS4ERR_IO, errno_NFSERR_IO },
3911 { NFS4ERR_NXIO, ENXIO },
3912 { NFS4ERR_ACCESS, EACCES },
3913 { NFS4ERR_EXIST, EEXIST },
3914 { NFS4ERR_XDEV, EXDEV },
3915 { NFS4ERR_NOTDIR, ENOTDIR },
3916 { NFS4ERR_ISDIR, EISDIR },
3917 { NFS4ERR_INVAL, EINVAL },
3918 { NFS4ERR_FBIG, EFBIG },
3919 { NFS4ERR_NOSPC, ENOSPC },
3920 { NFS4ERR_ROFS, EROFS },
3921 { NFS4ERR_MLINK, EMLINK },
3922 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
3923 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
3924 { NFS4ERR_DQUOT, EDQUOT },
3925 { NFS4ERR_STALE, ESTALE },
3926 { NFS4ERR_BADHANDLE, EBADHANDLE },
3927 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
3928 { NFS4ERR_NOTSUPP, ENOTSUPP },
3929 { NFS4ERR_TOOSMALL, ETOOSMALL },
3930 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
3931 { NFS4ERR_BADTYPE, EBADTYPE },
3932 { NFS4ERR_LOCKED, EAGAIN },
3933 { NFS4ERR_RESOURCE, EREMOTEIO },
3934 { NFS4ERR_SYMLINK, ELOOP },
3935 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
3936 { NFS4ERR_DEADLOCK, EDEADLK },
3937 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
3938 * to be handled by a
3945 * Convert an NFS error code to a local one.
3946 * This one is used jointly by NFSv2 and NFSv3.
3949 nfs_stat_to_errno(int stat)
3952 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
3953 if (nfs_errtbl[i].stat == stat)
3954 return nfs_errtbl[i].errno;
3956 if (stat <= 10000 || stat > 10100) {
3957 /* The server is looney tunes. */
3958 return ESERVERFAULT;
3960 /* If we cannot translate the error, the recovery routines should
3962 * Note: remaining NFSv4 error codes have values > 10000, so should
3963 * not conflict with native Linux error codes.
3969 # define MAX(a, b) (((a) > (b))? (a) : (b))
3972 #define PROC(proc, argtype, restype) \
3973 [NFSPROC4_CLNT_##proc] = { \
3974 .p_proc = NFSPROC4_COMPOUND, \
3975 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
3976 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
3977 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
3980 struct rpc_procinfo nfs4_procedures[] = {
3981 PROC(READ, enc_read, dec_read),
3982 PROC(WRITE, enc_write, dec_write),
3983 PROC(COMMIT, enc_commit, dec_commit),
3984 PROC(OPEN, enc_open, dec_open),
3985 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
3986 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
3987 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
3988 PROC(CLOSE, enc_close, dec_close),
3989 PROC(SETATTR, enc_setattr, dec_setattr),
3990 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
3991 PROC(RENEW, enc_renew, dec_renew),
3992 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
3993 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
3994 PROC(LOCK, enc_lock, dec_lock),
3995 PROC(LOCKT, enc_lockt, dec_lockt),
3996 PROC(LOCKU, enc_locku, dec_locku),
3997 PROC(ACCESS, enc_access, dec_access),
3998 PROC(GETATTR, enc_getattr, dec_getattr),
3999 PROC(LOOKUP, enc_lookup, dec_lookup),
4000 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4001 PROC(REMOVE, enc_remove, dec_remove),
4002 PROC(RENAME, enc_rename, dec_rename),
4003 PROC(LINK, enc_link, dec_link),
4004 PROC(SYMLINK, enc_symlink, dec_symlink),
4005 PROC(CREATE, enc_create, dec_create),
4006 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4007 PROC(STATFS, enc_statfs, dec_statfs),
4008 PROC(READLINK, enc_readlink, dec_readlink),
4009 PROC(READDIR, enc_readdir, dec_readdir),
4010 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4011 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4014 struct rpc_version nfs_version4 = {
4016 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
4017 .procs = nfs4_procedures