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_fattr_bitmap_maxsz (36 + 2 * nfs4_name_maxsz)
88 #define decode_getattr_maxsz (op_decode_hdr_maxsz + 3 + \
89 nfs4_fattr_bitmap_maxsz)
90 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
91 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
92 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
93 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
94 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
95 #define decode_renew_maxsz (op_decode_hdr_maxsz)
96 #define encode_setclientid_maxsz \
97 (op_encode_hdr_maxsz + \
98 4 /*server->ip_addr*/ + \
101 6 + (NFS4_VERIFIER_SIZE >> 2))
102 #define decode_setclientid_maxsz \
103 (op_decode_hdr_maxsz + \
105 1024) /* large value for CLID_INUSE */
106 #define encode_setclientid_confirm_maxsz \
107 (op_encode_hdr_maxsz + \
108 3 + (NFS4_VERIFIER_SIZE >> 2))
109 #define decode_setclientid_confirm_maxsz \
110 (op_decode_hdr_maxsz)
111 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
112 1 + ((3 + NFS4_FHSIZE) >> 2))
113 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
115 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
117 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
118 #define encode_link_maxsz (op_encode_hdr_maxsz + \
120 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
121 #define encode_create_maxsz (op_encode_hdr_maxsz + \
122 2 + 2 * nfs4_name_maxsz + \
123 nfs4_fattr_bitmap_maxsz)
124 #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
125 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
126 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
127 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
128 encode_putfh_maxsz + \
129 op_encode_hdr_maxsz + 7)
130 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
131 decode_putfh_maxsz + \
132 op_decode_hdr_maxsz + 2)
133 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
134 encode_putfh_maxsz + \
136 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
137 decode_putfh_maxsz + \
139 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
140 encode_putfh_maxsz + \
141 op_encode_hdr_maxsz + 9)
142 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
143 decode_putfh_maxsz + \
144 op_decode_hdr_maxsz + 2)
145 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
146 encode_putfh_maxsz + \
147 op_encode_hdr_maxsz + 8)
148 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
149 decode_putfh_maxsz + \
150 op_decode_hdr_maxsz + 4)
151 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
152 encode_putfh_maxsz + \
153 op_encode_hdr_maxsz + 3)
154 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
155 decode_putfh_maxsz + \
156 op_decode_hdr_maxsz + 2)
157 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
158 encode_putfh_maxsz + \
159 op_encode_hdr_maxsz + \
161 encode_getattr_maxsz + \
163 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
164 decode_putfh_maxsz + \
165 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
166 decode_getattr_maxsz + \
168 #define NFS4_enc_open_confirm_sz \
169 (compound_encode_hdr_maxsz + \
170 encode_putfh_maxsz + \
171 op_encode_hdr_maxsz + 5)
172 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
173 decode_putfh_maxsz + \
174 op_decode_hdr_maxsz + 4)
175 #define NFS4_enc_open_reclaim_sz (compound_encode_hdr_maxsz + \
176 encode_putfh_maxsz + \
177 op_encode_hdr_maxsz + \
179 encode_getattr_maxsz)
180 #define NFS4_dec_open_reclaim_sz (compound_decode_hdr_maxsz + \
181 decode_putfh_maxsz + \
182 op_decode_hdr_maxsz + \
184 decode_getattr_maxsz)
185 #define NFS4_enc_open_downgrade_sz \
186 (compound_encode_hdr_maxsz + \
187 encode_putfh_maxsz + \
188 op_encode_hdr_maxsz + 7)
189 #define NFS4_dec_open_downgrade_sz \
190 (compound_decode_hdr_maxsz + \
191 decode_putfh_maxsz + \
192 op_decode_hdr_maxsz + 4)
193 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
194 encode_putfh_maxsz + \
195 op_encode_hdr_maxsz + 5)
196 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
197 decode_putfh_maxsz + \
198 op_decode_hdr_maxsz + 4)
199 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
200 encode_putfh_maxsz + \
201 op_encode_hdr_maxsz + 4 + \
202 nfs4_fattr_bitmap_maxsz + \
203 encode_getattr_maxsz)
204 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
205 decode_putfh_maxsz + \
206 op_decode_hdr_maxsz + 3)
207 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
208 encode_putfh_maxsz + \
210 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
211 decode_putfh_maxsz + \
213 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
215 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
217 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
218 encode_setclientid_maxsz)
219 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
220 decode_setclientid_maxsz)
221 #define NFS4_enc_setclientid_confirm_sz \
222 (compound_encode_hdr_maxsz + \
223 encode_setclientid_confirm_maxsz + \
224 encode_putrootfh_maxsz + \
226 #define NFS4_dec_setclientid_confirm_sz \
227 (compound_decode_hdr_maxsz + \
228 decode_setclientid_confirm_maxsz + \
229 decode_putrootfh_maxsz + \
231 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
232 encode_putfh_maxsz + \
233 encode_getattr_maxsz + \
234 op_encode_hdr_maxsz + \
238 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
239 decode_putfh_maxsz + \
240 decode_getattr_maxsz + \
241 op_decode_hdr_maxsz + \
244 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
245 encode_putfh_maxsz + \
246 encode_getattr_maxsz + \
247 op_encode_hdr_maxsz + \
250 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
251 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
252 encode_putfh_maxsz + \
253 encode_getattr_maxsz + \
254 op_encode_hdr_maxsz + \
256 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
257 decode_putfh_maxsz + \
258 decode_getattr_maxsz + \
259 op_decode_hdr_maxsz + 4)
260 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
261 encode_putfh_maxsz + \
262 op_encode_hdr_maxsz + 1)
263 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
264 decode_putfh_maxsz + \
265 op_decode_hdr_maxsz + 2)
266 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
267 encode_putfh_maxsz + \
268 encode_getattr_maxsz)
269 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
270 decode_putfh_maxsz + \
271 decode_getattr_maxsz)
272 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
273 encode_putfh_maxsz + \
274 encode_lookup_maxsz + \
275 encode_getattr_maxsz + \
277 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
278 decode_putfh_maxsz + \
279 op_decode_hdr_maxsz + \
280 decode_getattr_maxsz + \
282 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
283 encode_putrootfh_maxsz + \
284 encode_getattr_maxsz + \
286 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
287 decode_putrootfh_maxsz + \
288 decode_getattr_maxsz + \
290 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
291 encode_putfh_maxsz + \
293 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
294 decode_putfh_maxsz + \
295 op_decode_hdr_maxsz + 5)
296 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
297 encode_putfh_maxsz + \
298 encode_savefh_maxsz + \
299 encode_putfh_maxsz + \
301 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
302 decode_putfh_maxsz + \
303 decode_savefh_maxsz + \
304 decode_putfh_maxsz + \
306 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
307 encode_putfh_maxsz + \
308 encode_savefh_maxsz + \
309 encode_putfh_maxsz + \
311 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
312 decode_putfh_maxsz + \
313 decode_savefh_maxsz + \
314 decode_putfh_maxsz + \
316 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
317 encode_putfh_maxsz + \
318 encode_create_maxsz + \
319 encode_getattr_maxsz + \
321 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
322 decode_putfh_maxsz + \
323 decode_create_maxsz + \
324 decode_getattr_maxsz + \
326 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
327 encode_putfh_maxsz + \
328 encode_getattr_maxsz)
329 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
330 decode_putfh_maxsz + \
331 decode_getattr_maxsz)
332 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
333 encode_putfh_maxsz + \
334 encode_getattr_maxsz)
335 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
336 decode_putfh_maxsz + \
337 op_decode_hdr_maxsz + 12)
338 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
339 encode_getattr_maxsz)
340 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
341 decode_getattr_maxsz)
345 unsigned int nfs2type;
353 { S_IFSOCK, NFSOCK },
359 struct compound_hdr {
367 * START OF "GENERIC" ENCODE ROUTINES.
368 * These may look a little ugly since they are imported from a "generic"
369 * set of XDR encode/decode routines which are intended to be shared by
370 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
372 * If the pain of reading these is too great, it should be a straightforward
373 * task to translate them into Linux-specific versions which are more
374 * consistent with the style used in NFSv2/v3...
376 #define WRITE32(n) *p++ = htonl(n)
377 #define WRITE64(n) do { \
378 *p++ = htonl((uint32_t)((n) >> 32)); \
379 *p++ = htonl((uint32_t)(n)); \
381 #define WRITEMEM(ptr,nbytes) do { \
382 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
385 #define RESERVE_SPACE(nbytes) do { \
386 p = xdr_reserve_space(xdr, nbytes); \
387 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
391 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
395 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
396 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
397 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
398 WRITE32(hdr->taglen);
399 WRITEMEM(hdr->tag, hdr->taglen);
400 WRITE32(NFS4_MINOR_VERSION);
405 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
407 char owner_name[IDMAP_NAMESZ];
408 char owner_group[IDMAP_NAMESZ];
409 int owner_namelen = 0;
410 int owner_grouplen = 0;
419 * We reserve enough space to write the entire attribute buffer at once.
420 * In the worst-case, this would be
421 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
422 * = 36 bytes, plus any contribution from variable-length fields
423 * such as owner/group/acl's.
428 if (iap->ia_valid & ATTR_SIZE)
430 if (iap->ia_valid & ATTR_MODE)
432 if (iap->ia_valid & ATTR_UID) {
433 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
434 if (owner_namelen < 0) {
435 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
438 strcpy(owner_name, "nobody");
439 owner_namelen = sizeof("nobody") - 1;
442 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
444 if (iap->ia_valid & ATTR_GID) {
445 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
446 if (owner_grouplen < 0) {
447 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
449 strcpy(owner_group, "nobody");
450 owner_grouplen = sizeof("nobody") - 1;
453 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
455 if (iap->ia_valid & ATTR_ATIME_SET)
457 else if (iap->ia_valid & ATTR_ATIME)
459 if (iap->ia_valid & ATTR_MTIME_SET)
461 else if (iap->ia_valid & ATTR_MTIME)
466 * We write the bitmap length now, but leave the bitmap and the attribute
467 * buffer length to be backfilled at the end of this routine.
473 if (iap->ia_valid & ATTR_SIZE) {
474 bmval0 |= FATTR4_WORD0_SIZE;
475 WRITE64(iap->ia_size);
477 if (iap->ia_valid & ATTR_MODE) {
478 bmval1 |= FATTR4_WORD1_MODE;
479 WRITE32(iap->ia_mode);
481 if (iap->ia_valid & ATTR_UID) {
482 bmval1 |= FATTR4_WORD1_OWNER;
483 WRITE32(owner_namelen);
484 WRITEMEM(owner_name, owner_namelen);
486 if (iap->ia_valid & ATTR_GID) {
487 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
488 WRITE32(owner_grouplen);
489 WRITEMEM(owner_group, owner_grouplen);
491 if (iap->ia_valid & ATTR_ATIME_SET) {
492 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
493 WRITE32(NFS4_SET_TO_CLIENT_TIME);
495 WRITE32(iap->ia_mtime.tv_sec);
496 WRITE32(iap->ia_mtime.tv_nsec);
498 else if (iap->ia_valid & ATTR_ATIME) {
499 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
500 WRITE32(NFS4_SET_TO_SERVER_TIME);
502 if (iap->ia_valid & ATTR_MTIME_SET) {
503 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
504 WRITE32(NFS4_SET_TO_CLIENT_TIME);
506 WRITE32(iap->ia_mtime.tv_sec);
507 WRITE32(iap->ia_mtime.tv_nsec);
509 else if (iap->ia_valid & ATTR_MTIME) {
510 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
511 WRITE32(NFS4_SET_TO_SERVER_TIME);
515 * Now we backfill the bitmap and the attribute buffer length.
517 if (len != ((char *)p - (char *)q) + 4) {
518 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
519 len, ((char *)p - (char *)q) + 4);
522 len = (char *)p - (char *)q - 12;
523 *q++ = htonl(bmval0);
524 *q++ = htonl(bmval1);
532 static int encode_access(struct xdr_stream *xdr, u32 access)
543 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
547 RESERVE_SPACE(8+sizeof(arg->stateid.data));
550 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
555 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
561 WRITE64(args->offset);
562 WRITE32(args->count);
567 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
573 WRITE32(create->ftype);
575 switch (create->ftype) {
577 RESERVE_SPACE(4 + create->u.symlink->len);
578 WRITE32(create->u.symlink->len);
579 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
582 case NF4BLK: case NF4CHR:
584 WRITE32(create->u.device.specdata1);
585 WRITE32(create->u.device.specdata2);
592 RESERVE_SPACE(4 + create->name->len);
593 WRITE32(create->name->len);
594 WRITEMEM(create->name->name, create->name->len);
596 return encode_attrs(xdr, create->attrs, create->server);
599 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
610 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
622 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
624 extern u32 nfs4_fattr_bitmap[];
626 return encode_getattr_two(xdr,
627 bitmask[0] & nfs4_fattr_bitmap[0],
628 bitmask[1] & nfs4_fattr_bitmap[1]);
631 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
633 extern u32 nfs4_fsinfo_bitmap[];
635 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
636 bitmask[1] & nfs4_fsinfo_bitmap[1]);
639 static int encode_getfh(struct xdr_stream *xdr)
649 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
653 RESERVE_SPACE(8 + name->len);
656 WRITEMEM(name->name, name->len);
662 * opcode,type,reclaim,offset,length,new_lock_owner = 32
663 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
665 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
668 struct nfs_lock_opargs *opargs = arg->u.lock;
673 WRITE32(opargs->reclaim);
674 WRITE64(arg->offset);
675 WRITE64(arg->length);
676 WRITE32(opargs->new_lock_owner);
677 if (opargs->new_lock_owner){
678 struct nfs_open_to_lock *ol = opargs->u.open_lock;
681 WRITE32(ol->open_seqid);
682 WRITEMEM(&ol->open_stateid, sizeof(ol->open_stateid));
683 WRITE32(ol->lock_seqid);
684 WRITE64(ol->lock_owner.clientid);
686 WRITE32(ol->lock_owner.id);
689 struct nfs_exist_lock *el = opargs->u.exist_lock;
692 WRITEMEM(&el->stateid, sizeof(el->stateid));
699 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
702 struct nfs_lowner *opargs = arg->u.lockt;
707 WRITE64(arg->offset);
708 WRITE64(arg->length);
709 WRITE64(opargs->clientid);
716 static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
719 struct nfs_locku_opargs *opargs = arg->u.locku;
724 WRITE32(opargs->seqid);
725 WRITEMEM(&opargs->stateid, sizeof(opargs->stateid));
726 WRITE64(arg->offset);
727 WRITE64(arg->length);
732 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
737 RESERVE_SPACE(8 + len);
740 WRITEMEM(name->name, len);
745 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
751 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
752 * owner 4, opentype 4 = 36
757 switch (arg->share_access) {
759 WRITE32(NFS4_SHARE_ACCESS_READ);
762 WRITE32(NFS4_SHARE_ACCESS_WRITE);
764 case FMODE_READ|FMODE_WRITE:
765 WRITE32(NFS4_SHARE_ACCESS_BOTH);
770 WRITE32(0); /* for linux, share_deny = 0 always */
771 WRITE64(arg->clientid);
774 WRITE32(arg->opentype);
776 if (arg->opentype == NFS4_OPEN_CREATE) {
777 if (arg->createmode == NFS4_CREATE_EXCLUSIVE) {
779 WRITE32(arg->createmode);
780 WRITEMEM(arg->u.verifier.data, sizeof(arg->u.verifier.data));
782 else if (arg->u.attrs) {
784 WRITE32(arg->createmode);
785 if ((status = encode_attrs(xdr, arg->u.attrs, arg->server)))
790 WRITE32(arg->createmode);
796 RESERVE_SPACE(8 + arg->name->len);
797 WRITE32(NFS4_OPEN_CLAIM_NULL);
798 WRITE32(arg->name->len);
799 WRITEMEM(arg->name->name, arg->name->len);
804 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
808 RESERVE_SPACE(8+sizeof(arg->stateid.data));
809 WRITE32(OP_OPEN_CONFIRM);
810 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
817 static int encode_open_reclaim(struct xdr_stream *xdr, const struct nfs_open_reclaimargs *arg)
822 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
823 * owner 4, opentype 4, claim 4, delegation_type 4 = 44
828 switch (arg->share_access) {
830 WRITE32(NFS4_SHARE_ACCESS_READ);
833 WRITE32(NFS4_SHARE_ACCESS_WRITE);
835 case FMODE_READ|FMODE_WRITE:
836 WRITE32(NFS4_SHARE_ACCESS_BOTH);
841 WRITE32(0); /* for linux, share_deny = 0 always */
842 WRITE64(arg->clientid);
845 WRITE32(NFS4_OPEN_NOCREATE);
846 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
847 WRITE32(NFS4_OPEN_DELEGATE_NONE);
851 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
855 RESERVE_SPACE(16+sizeof(arg->stateid.data));
856 WRITE32(OP_OPEN_DOWNGRADE);
857 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
859 WRITE32(arg->share_access);
867 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
872 RESERVE_SPACE(8 + len);
875 WRITEMEM(fh->data, len);
880 static int encode_putrootfh(struct xdr_stream *xdr)
885 WRITE32(OP_PUTROOTFH);
890 static void encode_stateid(struct xdr_stream *xdr, struct nfs4_state *state, fl_owner_t lockowner)
892 extern nfs4_stateid zero_stateid;
893 nfs4_stateid stateid;
898 nfs4_copy_stateid(&stateid, state, lockowner);
899 WRITEMEM(stateid.data, sizeof(stateid.data));
901 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
904 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
911 encode_stateid(xdr, args->state, args->lockowner);
914 WRITE64(args->offset);
915 WRITE32(args->count);
920 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
922 struct rpc_auth *auth = req->rq_task->tk_auth;
926 RESERVE_SPACE(32+sizeof(nfs4_verifier));
928 WRITE64(readdir->cookie);
929 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
930 WRITE32(readdir->count >> 5); /* meaningless "dircount" field */
931 WRITE32(readdir->count);
933 WRITE32(FATTR4_WORD0_FILEID);
937 * toplevel_status + taglen + rescount + OP_PUTFH + status
938 * + OP_READDIR + status + verifer(2) = 9
940 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
941 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
942 readdir->pgbase, readdir->count);
947 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
949 struct rpc_auth *auth = req->rq_task->tk_auth;
950 unsigned int count = readlink->count - 5;
955 WRITE32(OP_READLINK);
958 * toplevel_status + taglen + rescount + OP_PUTFH + status
959 * + OP_READLINK + status = 7
961 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
962 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages, 0, count);
967 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
971 RESERVE_SPACE(8 + name->len);
974 WRITEMEM(name->name, name->len);
979 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
983 RESERVE_SPACE(8 + oldname->len);
985 WRITE32(oldname->len);
986 WRITEMEM(oldname->name, oldname->len);
988 RESERVE_SPACE(4 + newname->len);
989 WRITE32(newname->len);
990 WRITEMEM(newname->name, newname->len);
995 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1001 WRITE64(client_stateid->cl_clientid);
1007 encode_savefh(struct xdr_stream *xdr)
1017 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1022 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1023 WRITE32(OP_SETATTR);
1024 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1026 if ((status = encode_attrs(xdr, arg->iap, server)))
1032 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1035 uint32_t len1, len2, len3;
1038 len1 = strlen(setclientid->sc_name);
1039 len2 = strlen(setclientid->sc_netid);
1040 len3 = strlen(setclientid->sc_uaddr);
1041 total_len = XDR_QUADLEN(len1) + XDR_QUADLEN(len2) + XDR_QUADLEN(len3);
1042 total_len = (total_len << 2) + 24 + sizeof(setclientid->sc_verifier.data);
1044 RESERVE_SPACE(total_len);
1045 WRITE32(OP_SETCLIENTID);
1046 WRITEMEM(setclientid->sc_verifier.data, sizeof(setclientid->sc_verifier.data));
1048 WRITEMEM(setclientid->sc_name, len1);
1049 WRITE32(setclientid->sc_prog);
1051 WRITEMEM(setclientid->sc_netid, len2);
1053 WRITEMEM(setclientid->sc_uaddr, len3);
1054 WRITE32(setclientid->sc_cb_ident);
1059 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1063 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1064 WRITE32(OP_SETCLIENTID_CONFIRM);
1065 WRITE64(client_state->cl_clientid);
1066 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1071 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1078 encode_stateid(xdr, args->state, args->lockowner);
1081 WRITE64(args->offset);
1082 WRITE32(args->stable);
1083 WRITE32(args->count);
1085 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1090 * END OF "GENERIC" ENCODE ROUTINES.
1094 * Encode an ACCESS request
1096 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1098 struct xdr_stream xdr;
1099 struct compound_hdr hdr = {
1104 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1105 encode_compound_hdr(&xdr, &hdr);
1106 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1107 status = encode_access(&xdr, args->access);
1112 * Encode LOOKUP request
1114 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1116 struct xdr_stream xdr;
1117 struct compound_hdr hdr = {
1122 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1123 encode_compound_hdr(&xdr, &hdr);
1124 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1126 if ((status = encode_lookup(&xdr, args->name)) != 0)
1128 if ((status = encode_getfh(&xdr)) != 0)
1130 status = encode_getfattr(&xdr, args->bitmask);
1136 * Encode LOOKUP_ROOT request
1138 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1140 struct xdr_stream xdr;
1141 struct compound_hdr hdr = {
1146 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1147 encode_compound_hdr(&xdr, &hdr);
1148 if ((status = encode_putrootfh(&xdr)) != 0)
1150 if ((status = encode_getfh(&xdr)) == 0)
1151 status = encode_getfattr(&xdr, args->bitmask);
1157 * Encode REMOVE request
1159 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1161 struct xdr_stream xdr;
1162 struct compound_hdr hdr = {
1167 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1168 encode_compound_hdr(&xdr, &hdr);
1169 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1170 status = encode_remove(&xdr, args->name);
1175 * Encode RENAME request
1177 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1179 struct xdr_stream xdr;
1180 struct compound_hdr hdr = {
1185 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1186 encode_compound_hdr(&xdr, &hdr);
1187 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1189 if ((status = encode_savefh(&xdr)) != 0)
1191 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1193 status = encode_rename(&xdr, args->old_name, args->new_name);
1199 * Encode LINK request
1201 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1203 struct xdr_stream xdr;
1204 struct compound_hdr hdr = {
1209 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1210 encode_compound_hdr(&xdr, &hdr);
1211 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1213 if ((status = encode_savefh(&xdr)) != 0)
1215 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1217 status = encode_link(&xdr, args->name);
1223 * Encode CREATE request
1225 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1227 struct xdr_stream xdr;
1228 struct compound_hdr hdr = {
1233 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1234 encode_compound_hdr(&xdr, &hdr);
1235 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1237 if ((status = encode_create(&xdr, args)) != 0)
1239 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1241 status = encode_getfh(&xdr);
1247 * Encode GETATTR request
1249 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1251 struct xdr_stream xdr;
1252 struct compound_hdr hdr = {
1257 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1258 encode_compound_hdr(&xdr, &hdr);
1259 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1260 status = encode_getfattr(&xdr, args->bitmask);
1265 * Encode a CLOSE request
1267 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1269 struct xdr_stream xdr;
1270 struct compound_hdr hdr = {
1275 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1276 encode_compound_hdr(&xdr, &hdr);
1277 status = encode_putfh(&xdr, args->fh);
1280 status = encode_close(&xdr, args);
1286 * Encode an OPEN request
1288 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1290 struct xdr_stream xdr;
1291 struct compound_hdr hdr = {
1296 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1297 encode_compound_hdr(&xdr, &hdr);
1298 status = encode_putfh(&xdr, args->fh);
1301 status = encode_open(&xdr, args);
1304 status = encode_getfattr(&xdr, args->bitmask);
1307 status = encode_getfh(&xdr);
1313 * Encode an OPEN_CONFIRM request
1315 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1317 struct xdr_stream xdr;
1318 struct compound_hdr hdr = {
1323 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1324 encode_compound_hdr(&xdr, &hdr);
1325 status = encode_putfh(&xdr, args->fh);
1328 status = encode_open_confirm(&xdr, args);
1334 * Encode an OPEN request
1336 static int nfs4_xdr_enc_open_reclaim(struct rpc_rqst *req, uint32_t *p, struct nfs_open_reclaimargs *args)
1338 struct xdr_stream xdr;
1339 struct compound_hdr hdr = {
1344 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1345 encode_compound_hdr(&xdr, &hdr);
1346 status = encode_putfh(&xdr, args->fh);
1349 status = encode_open_reclaim(&xdr, args);
1352 status = encode_getfattr(&xdr, args->bitmask);
1358 * Encode an OPEN_DOWNGRADE request
1360 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1362 struct xdr_stream xdr;
1363 struct compound_hdr hdr = {
1368 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1369 encode_compound_hdr(&xdr, &hdr);
1370 status = encode_putfh(&xdr, args->fh);
1373 status = encode_open_downgrade(&xdr, args);
1379 * Encode a LOCK request
1381 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1383 struct xdr_stream xdr;
1384 struct compound_hdr hdr = {
1389 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1390 encode_compound_hdr(&xdr, &hdr);
1391 status = encode_putfh(&xdr, args->fh);
1394 status = encode_lock(&xdr, args);
1400 * Encode a LOCKT request
1402 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1404 struct xdr_stream xdr;
1405 struct compound_hdr hdr = {
1410 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1411 encode_compound_hdr(&xdr, &hdr);
1412 status = encode_putfh(&xdr, args->fh);
1415 status = encode_lockt(&xdr, args);
1421 * Encode a LOCKU request
1423 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1425 struct xdr_stream xdr;
1426 struct compound_hdr hdr = {
1431 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1432 encode_compound_hdr(&xdr, &hdr);
1433 status = encode_putfh(&xdr, args->fh);
1436 status = encode_locku(&xdr, args);
1442 * Encode a READLINK request
1444 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1446 struct xdr_stream xdr;
1447 struct compound_hdr hdr = {
1452 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1453 encode_compound_hdr(&xdr, &hdr);
1454 status = encode_putfh(&xdr, args->fh);
1457 status = encode_readlink(&xdr, args, req);
1463 * Encode a READDIR request
1465 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1467 struct xdr_stream xdr;
1468 struct compound_hdr hdr = {
1473 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1474 encode_compound_hdr(&xdr, &hdr);
1475 status = encode_putfh(&xdr, args->fh);
1478 status = encode_readdir(&xdr, args, req);
1484 * Encode a READ request
1486 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1488 struct rpc_auth *auth = req->rq_task->tk_auth;
1489 struct xdr_stream xdr;
1490 struct compound_hdr hdr = {
1495 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1496 encode_compound_hdr(&xdr, &hdr);
1497 status = encode_putfh(&xdr, args->fh);
1500 status = encode_read(&xdr, args);
1504 /* set up reply kvec
1505 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1506 * + OP_READ + status + eof + datalen = 9
1508 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1509 xdr_inline_pages(&req->rq_rcv_buf, replen,
1510 args->pages, args->pgbase, args->count);
1516 * Encode an SETATTR request
1518 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1521 struct xdr_stream xdr;
1522 struct compound_hdr hdr = {
1527 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1528 encode_compound_hdr(&xdr, &hdr);
1529 status = encode_putfh(&xdr, args->fh);
1532 status = encode_setattr(&xdr, args, args->server);
1535 status = encode_getfattr(&xdr, args->bitmask);
1541 * Encode a WRITE request
1543 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1545 struct xdr_stream xdr;
1546 struct compound_hdr hdr = {
1551 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1552 encode_compound_hdr(&xdr, &hdr);
1553 status = encode_putfh(&xdr, args->fh);
1556 status = encode_write(&xdr, args);
1564 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1566 struct xdr_stream xdr;
1567 struct compound_hdr hdr = {
1572 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1573 encode_compound_hdr(&xdr, &hdr);
1574 status = encode_putfh(&xdr, args->fh);
1577 status = encode_commit(&xdr, args);
1585 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1587 struct xdr_stream xdr;
1588 struct compound_hdr hdr = {
1593 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1594 encode_compound_hdr(&xdr, &hdr);
1595 status = encode_putfh(&xdr, args->fh);
1597 status = encode_fsinfo(&xdr, args->bitmask);
1602 * a PATHCONF request
1604 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1606 extern u32 nfs4_pathconf_bitmap[2];
1607 struct xdr_stream xdr;
1608 struct compound_hdr hdr = {
1613 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1614 encode_compound_hdr(&xdr, &hdr);
1615 status = encode_putfh(&xdr, args->fh);
1617 status = encode_getattr_one(&xdr,
1618 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1625 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1627 extern u32 nfs4_statfs_bitmap[];
1628 struct xdr_stream xdr;
1629 struct compound_hdr hdr = {
1634 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1635 encode_compound_hdr(&xdr, &hdr);
1636 status = encode_putfh(&xdr, args->fh);
1638 status = encode_getattr_two(&xdr,
1639 args->bitmask[0] & nfs4_statfs_bitmap[0],
1640 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1645 * GETATTR_BITMAP request
1647 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1649 struct xdr_stream xdr;
1650 struct compound_hdr hdr = {
1655 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1656 encode_compound_hdr(&xdr, &hdr);
1657 status = encode_putfh(&xdr, fhandle);
1659 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1660 FATTR4_WORD0_LINK_SUPPORT|
1661 FATTR4_WORD0_SYMLINK_SUPPORT|
1662 FATTR4_WORD0_ACLSUPPORT);
1669 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1671 struct xdr_stream xdr;
1672 struct compound_hdr hdr = {
1676 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1677 encode_compound_hdr(&xdr, &hdr);
1678 return encode_renew(&xdr, clp);
1682 * a SETCLIENTID request
1684 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1686 struct xdr_stream xdr;
1687 struct compound_hdr hdr = {
1691 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1692 encode_compound_hdr(&xdr, &hdr);
1693 return encode_setclientid(&xdr, sc);
1697 * a SETCLIENTID_CONFIRM request
1699 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1701 struct xdr_stream xdr;
1702 struct compound_hdr hdr = {
1705 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1708 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1709 encode_compound_hdr(&xdr, &hdr);
1710 status = encode_setclientid_confirm(&xdr, clp);
1712 status = encode_putrootfh(&xdr);
1714 status = encode_fsinfo(&xdr, lease_bitmap);
1719 * START OF "GENERIC" DECODE ROUTINES.
1720 * These may look a little ugly since they are imported from a "generic"
1721 * set of XDR encode/decode routines which are intended to be shared by
1722 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1724 * If the pain of reading these is too great, it should be a straightforward
1725 * task to translate them into Linux-specific versions which are more
1726 * consistent with the style used in NFSv2/v3...
1728 #define READ32(x) (x) = ntohl(*p++)
1729 #define READ64(x) do { \
1730 (x) = (u64)ntohl(*p++) << 32; \
1731 (x) |= ntohl(*p++); \
1733 #define READTIME(x) do { \
1735 (x.tv_sec) = ntohl(*p++); \
1736 (x.tv_nsec) = ntohl(*p++); \
1738 #define COPYMEM(x,nbytes) do { \
1739 memcpy((x), p, nbytes); \
1740 p += XDR_QUADLEN(nbytes); \
1743 #define READ_BUF(nbytes) do { \
1744 p = xdr_inline_decode(xdr, nbytes); \
1746 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
1747 __FUNCTION__, __LINE__); \
1752 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
1757 READ32(hdr->status);
1758 READ32(hdr->taglen);
1760 READ_BUF(hdr->taglen + 4);
1761 hdr->tag = (char *)p;
1762 p += XDR_QUADLEN(hdr->taglen);
1767 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
1775 if (opnum != expected) {
1777 "nfs4_decode_op_hdr: Server returned operation"
1778 " %d but we issued a request for %d\n",
1783 if (nfserr != NFS_OK)
1784 return -nfs_stat_to_errno(nfserr);
1788 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
1795 bitmap[0] = bitmap[1] = 0;
1796 READ_BUF((bmlen << 2));
1805 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
1815 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
1817 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
1818 decode_attr_bitmap(xdr, bitmask);
1819 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
1821 bitmask[0] = bitmask[1] = 0;
1822 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
1826 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
1831 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
1833 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
1836 if (*type < NF4REG || *type > NF4NAMEDATTR) {
1837 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
1840 bitmap[0] &= ~FATTR4_WORD0_TYPE;
1842 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
1846 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
1851 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
1853 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
1856 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
1858 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
1859 (unsigned long long)*change);
1863 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
1868 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
1870 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
1873 bitmap[0] &= ~FATTR4_WORD0_SIZE;
1875 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
1879 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
1884 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
1886 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
1889 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
1891 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
1895 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
1900 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
1902 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
1905 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
1907 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
1911 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
1917 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
1919 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
1921 READ64(fsid->major);
1922 READ64(fsid->minor);
1923 bitmap[0] &= ~FATTR4_WORD0_FSID;
1925 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
1926 (unsigned long long)fsid->major,
1927 (unsigned long long)fsid->minor);
1931 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
1936 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
1938 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
1941 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
1943 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
1947 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
1951 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
1952 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
1954 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
1957 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
1959 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
1963 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
1968 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
1970 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
1973 bitmap[0] &= ~FATTR4_WORD0_FILEID;
1975 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
1979 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
1985 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
1987 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
1990 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
1992 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
1996 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2002 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2004 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2007 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2009 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2013 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2019 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2021 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2024 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2026 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2030 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2036 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2038 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2041 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2043 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2047 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2053 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2055 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2058 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2060 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2064 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2070 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2072 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2075 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2077 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2081 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2087 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2089 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2093 if (maxread > 0x7FFFFFFF)
2094 maxread = 0x7FFFFFFF;
2095 *res = (uint32_t)maxread;
2096 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2098 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2102 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2108 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2110 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2114 if (maxwrite > 0x7FFFFFFF)
2115 maxwrite = 0x7FFFFFFF;
2116 *res = (uint32_t)maxwrite;
2117 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2119 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2123 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2128 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2130 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2134 bitmap[1] &= ~FATTR4_WORD1_MODE;
2136 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2140 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2145 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2147 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2150 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2152 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2156 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2161 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2163 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2167 if (len < XDR_MAX_NETOBJ) {
2168 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2169 dprintk("%s: nfs_map_name_to_uid failed!\n",
2172 printk(KERN_WARNING "%s: name too long (%u)!\n",
2174 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2176 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2180 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2185 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2187 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2191 if (len < XDR_MAX_NETOBJ) {
2192 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2193 dprintk("%s: nfs_map_group_to_gid failed!\n",
2196 printk(KERN_WARNING "%s: name too long (%u)!\n",
2198 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2200 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2204 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2206 uint32_t major = 0, minor = 0, *p;
2209 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2211 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2217 tmp = MKDEV(major, minor);
2218 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2220 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2222 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2226 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2232 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2234 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2237 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2239 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2243 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2249 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2251 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2254 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2256 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2260 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2266 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2268 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2271 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2273 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2277 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2282 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2284 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2287 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2289 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2290 (unsigned long long)*used);
2294 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2303 time->tv_sec = (time_t)sec;
2304 time->tv_nsec = (long)nsec;
2308 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2314 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2316 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2317 status = decode_attr_time(xdr, time);
2318 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2320 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2324 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2330 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2332 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2333 status = decode_attr_time(xdr, time);
2334 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2336 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2340 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2346 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2348 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2349 status = decode_attr_time(xdr, time);
2350 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2352 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2356 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2358 unsigned int attrwords = XDR_QUADLEN(attrlen);
2359 unsigned int nwords = xdr->p - savep;
2361 if (unlikely(attrwords != nwords)) {
2362 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2365 (attrwords < nwords) ? '<' : '>',
2372 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2377 READ32(cinfo->atomic);
2378 READ64(cinfo->before);
2379 READ64(cinfo->after);
2383 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2389 status = decode_op_hdr(xdr, OP_ACCESS);
2395 access->supported = supp;
2396 access->access = acc;
2400 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2405 status = decode_op_hdr(xdr, OP_CLOSE);
2408 READ_BUF(sizeof(res->stateid.data));
2409 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2413 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2418 status = decode_op_hdr(xdr, OP_COMMIT);
2422 COPYMEM(res->verf->verifier, 8);
2426 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2432 status = decode_op_hdr(xdr, OP_CREATE);
2435 if ((status = decode_change_info(xdr, cinfo)))
2439 READ_BUF(bmlen << 2);
2443 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2450 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2452 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2454 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2456 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2458 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2460 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2462 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2464 status = verify_attr_len(xdr, savep, attrlen);
2467 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2471 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2478 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2480 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2482 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2485 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2487 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2489 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2491 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2493 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2495 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2498 status = verify_attr_len(xdr, savep, attrlen);
2501 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2505 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2512 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2514 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2516 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2519 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2521 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2524 status = verify_attr_len(xdr, savep, attrlen);
2527 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2531 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2537 int status, fmode = 0;
2539 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2541 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2544 fattr->bitmap[0] = bitmap[0];
2545 fattr->bitmap[1] = bitmap[1];
2547 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2551 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2553 fattr->type = nfs_type2fmt[type].nfs2type;
2554 fmode = nfs_type2fmt[type].mode;
2556 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2558 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2560 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2562 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2564 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2566 fattr->mode |= fmode;
2567 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2569 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2571 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2573 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2575 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2577 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2579 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2581 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2583 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) {
2584 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2585 fattr->timestamp = jiffies;
2589 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2594 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2597 uint32_t attrlen, bitmap[2];
2600 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2602 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2604 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2607 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2609 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2611 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2613 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2615 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2616 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2618 fsinfo->wtpref = fsinfo->wtmax;
2620 status = verify_attr_len(xdr, savep, attrlen);
2623 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2627 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2633 status = decode_op_hdr(xdr, OP_GETFH);
2636 /* Zero handle first to allow comparisons */
2637 memset(fh, 0, sizeof(*fh));
2641 if (len > NFS4_FHSIZE)
2645 COPYMEM(fh->data, len);
2649 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2653 status = decode_op_hdr(xdr, OP_LINK);
2656 return decode_change_info(xdr, cinfo);
2660 * We create the owner, so we know a proper owner.id length is 4.
2662 static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2668 READ64(denied->offset);
2669 READ64(denied->length);
2670 READ32(denied->type);
2671 READ64(denied->owner.clientid);
2675 READ32(denied->owner.id);
2676 return -NFS4ERR_DENIED;
2679 static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2684 status = decode_op_hdr(xdr, OP_LOCK);
2686 READ_BUF(sizeof(nfs4_stateid));
2687 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2688 } else if (status == -NFS4ERR_DENIED)
2689 return decode_lock_denied(xdr, &res->u.denied);
2693 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2696 status = decode_op_hdr(xdr, OP_LOCKT);
2697 if (status == -NFS4ERR_DENIED)
2698 return decode_lock_denied(xdr, &res->u.denied);
2702 static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2707 status = decode_op_hdr(xdr, OP_LOCKU);
2709 READ_BUF(sizeof(nfs4_stateid));
2710 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2715 static int decode_lookup(struct xdr_stream *xdr)
2717 return decode_op_hdr(xdr, OP_LOOKUP);
2720 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
2723 uint32_t bmlen, delegation_type;
2726 status = decode_op_hdr(xdr, OP_OPEN);
2729 READ_BUF(sizeof(res->stateid.data));
2730 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2732 decode_change_info(xdr, &res->cinfo);
2735 READ32(res->rflags);
2740 READ_BUF((bmlen << 2) + 4);
2742 READ32(delegation_type);
2743 if (delegation_type == NFS4_OPEN_DELEGATE_NONE)
2746 printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
2750 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
2755 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
2758 READ_BUF(sizeof(res->stateid.data));
2759 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2763 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
2768 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
2771 READ_BUF(sizeof(res->stateid.data));
2772 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2776 static int decode_putfh(struct xdr_stream *xdr)
2778 return decode_op_hdr(xdr, OP_PUTFH);
2781 static int decode_putrootfh(struct xdr_stream *xdr)
2783 return decode_op_hdr(xdr, OP_PUTROOTFH);
2786 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
2788 struct kvec *iov = req->rq_rcv_buf.head;
2790 uint32_t count, eof, recvd, hdrlen;
2793 status = decode_op_hdr(xdr, OP_READ);
2799 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
2800 recvd = req->rq_rcv_buf.len - hdrlen;
2801 if (count > recvd) {
2802 printk(KERN_WARNING "NFS: server cheating in read reply: "
2803 "count %u > recvd %u\n", count, recvd);
2807 xdr_read_pages(xdr, count);
2813 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
2815 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
2816 struct page *page = *rcvbuf->pages;
2817 struct kvec *iov = rcvbuf->head;
2818 unsigned int nr, pglen = rcvbuf->page_len;
2819 uint32_t *end, *entry, *p, *kaddr;
2820 uint32_t len, attrlen, word;
2821 int i, hdrlen, recvd, status;
2823 status = decode_op_hdr(xdr, OP_READDIR);
2827 COPYMEM(readdir->verifier.data, 8);
2829 hdrlen = (char *) p - (char *) iov->iov_base;
2830 recvd = rcvbuf->len - hdrlen;
2833 xdr_read_pages(xdr, pglen);
2835 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
2836 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
2837 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
2839 for (nr = 0; *p++; nr++) {
2842 p += 2; /* cookie */
2843 len = ntohl(*p++); /* filename length */
2844 if (len > NFS4_MAXNAMLEN) {
2845 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
2849 p += XDR_QUADLEN(len);
2852 len = ntohl(*p++); /* bitmap length */
2854 printk(KERN_WARNING "NFS: giant bitmap in readdir (len 0x%x)\n", len);
2857 if (p + len + 1 > end)
2860 for (i = 0; i < len; i++) {
2864 else if (i == 0 && word == FATTR4_WORD0_FILEID) {
2868 printk(KERN_WARNING "NFS: unexpected bitmap word in readdir (0x%x)\n", word);
2871 if (ntohl(*p++) != attrlen) {
2872 printk(KERN_WARNING "NFS: unexpected attrlen in readdir\n");
2875 p += XDR_QUADLEN(attrlen);
2879 if (!nr && (entry[0] != 0 || entry[1] == 0))
2882 kunmap_atomic(kaddr, KM_USER0);
2885 entry[0] = entry[1] = 0;
2886 /* truncate listing ? */
2888 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
2893 kunmap_atomic(kaddr, KM_USER0);
2894 return -errno_NFSERR_IO;
2897 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
2899 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
2900 struct kvec *iov = rcvbuf->head;
2902 unsigned int hdrlen, len;
2906 status = decode_op_hdr(xdr, OP_READLINK);
2910 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
2911 if (iov->iov_len > hdrlen) {
2912 dprintk("NFS: READLINK header is short. iovec will be shifted.\n");
2913 xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen);
2917 * The XDR encode routine has set things up so that
2918 * the link text will be copied directly into the
2919 * buffer. We just have to do overflow-checking,
2920 * and and null-terminate the text (the VFS expects
2921 * null-termination).
2923 strlen = (uint32_t *) kmap_atomic(rcvbuf->pages[0], KM_USER0);
2924 len = ntohl(*strlen);
2925 if (len > rcvbuf->page_len) {
2926 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
2927 kunmap_atomic(strlen, KM_USER0);
2928 return -ENAMETOOLONG;
2932 string = (char *)(strlen + 1);
2934 kunmap_atomic(strlen, KM_USER0);
2938 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2942 status = decode_op_hdr(xdr, OP_REMOVE);
2945 status = decode_change_info(xdr, cinfo);
2950 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
2951 struct nfs4_change_info *new_cinfo)
2955 status = decode_op_hdr(xdr, OP_RENAME);
2958 if ((status = decode_change_info(xdr, old_cinfo)))
2960 status = decode_change_info(xdr, new_cinfo);
2965 static int decode_renew(struct xdr_stream *xdr)
2967 return decode_op_hdr(xdr, OP_RENEW);
2971 decode_savefh(struct xdr_stream *xdr)
2973 return decode_op_hdr(xdr, OP_SAVEFH);
2976 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
2983 status = decode_op_hdr(xdr, OP_SETATTR);
2988 READ_BUF(bmlen << 2);
2992 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3000 if (opnum != OP_SETCLIENTID) {
3002 "nfs4_decode_setclientid: Server returned operation"
3007 if (nfserr == NFS_OK) {
3008 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3009 READ64(clp->cl_clientid);
3010 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3011 } else if (nfserr == NFSERR_CLID_INUSE) {
3014 /* skip netid string */
3019 /* skip uaddr string */
3025 return -nfs_stat_to_errno(nfserr);
3030 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3032 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3035 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3040 status = decode_op_hdr(xdr, OP_WRITE);
3046 READ32(res->verf->committed);
3047 COPYMEM(res->verf->verifier, 8);
3052 * Decode OPEN_DOWNGRADE response
3054 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3056 struct xdr_stream xdr;
3057 struct compound_hdr hdr;
3060 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3061 status = decode_compound_hdr(&xdr, &hdr);
3064 status = decode_putfh(&xdr);
3067 status = decode_open_downgrade(&xdr, res);
3073 * END OF "GENERIC" DECODE ROUTINES.
3077 * Decode ACCESS response
3079 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3081 struct xdr_stream xdr;
3082 struct compound_hdr hdr;
3085 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3086 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3088 if ((status = decode_putfh(&xdr)) == 0)
3089 status = decode_access(&xdr, res);
3095 * Decode LOOKUP response
3097 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3099 struct xdr_stream xdr;
3100 struct compound_hdr hdr;
3103 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3104 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3106 if ((status = decode_putfh(&xdr)) != 0)
3108 if ((status = decode_lookup(&xdr)) != 0)
3110 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3112 status = decode_getfattr(&xdr, res->fattr, res->server);
3118 * Decode LOOKUP_ROOT response
3120 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3122 struct xdr_stream xdr;
3123 struct compound_hdr hdr;
3126 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3127 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3129 if ((status = decode_putrootfh(&xdr)) != 0)
3131 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3132 status = decode_getfattr(&xdr, res->fattr, res->server);
3138 * Decode REMOVE response
3140 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3142 struct xdr_stream xdr;
3143 struct compound_hdr hdr;
3146 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3147 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3149 if ((status = decode_putfh(&xdr)) == 0)
3150 status = decode_remove(&xdr, cinfo);
3156 * Decode RENAME response
3158 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3160 struct xdr_stream xdr;
3161 struct compound_hdr hdr;
3164 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3165 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3167 if ((status = decode_putfh(&xdr)) != 0)
3169 if ((status = decode_savefh(&xdr)) != 0)
3171 if ((status = decode_putfh(&xdr)) != 0)
3173 status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
3179 * Decode LINK response
3181 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3183 struct xdr_stream xdr;
3184 struct compound_hdr hdr;
3187 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3188 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3190 if ((status = decode_putfh(&xdr)) != 0)
3192 if ((status = decode_savefh(&xdr)) != 0)
3194 if ((status = decode_putfh(&xdr)) != 0)
3196 status = decode_link(&xdr, cinfo);
3202 * Decode CREATE response
3204 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3206 struct xdr_stream xdr;
3207 struct compound_hdr hdr;
3210 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3211 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3213 if ((status = decode_putfh(&xdr)) != 0)
3215 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3217 if ((status = decode_getfattr(&xdr, res->fattr, res->server)) != 0)
3219 status = decode_getfh(&xdr, res->fh);
3225 * Decode GETATTR response
3227 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3229 struct xdr_stream xdr;
3230 struct compound_hdr hdr;
3233 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3234 status = decode_compound_hdr(&xdr, &hdr);
3237 status = decode_putfh(&xdr);
3240 status = decode_getfattr(&xdr, res->fattr, res->server);
3248 * Decode CLOSE response
3250 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3252 struct xdr_stream xdr;
3253 struct compound_hdr hdr;
3256 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3257 status = decode_compound_hdr(&xdr, &hdr);
3260 status = decode_putfh(&xdr);
3263 status = decode_close(&xdr, res);
3269 * Decode OPEN response
3271 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3273 struct xdr_stream xdr;
3274 struct compound_hdr hdr;
3277 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3278 status = decode_compound_hdr(&xdr, &hdr);
3281 status = decode_putfh(&xdr);
3284 status = decode_open(&xdr, res);
3287 status = decode_getfattr(&xdr, res->f_attr, res->server);
3290 status = decode_getfh(&xdr, &res->fh);
3296 * Decode OPEN_CONFIRM response
3298 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3300 struct xdr_stream xdr;
3301 struct compound_hdr hdr;
3304 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3305 status = decode_compound_hdr(&xdr, &hdr);
3308 status = decode_putfh(&xdr);
3311 status = decode_open_confirm(&xdr, res);
3317 * Decode OPEN_RECLAIM response
3319 static int nfs4_xdr_dec_open_reclaim(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3321 struct xdr_stream xdr;
3322 struct compound_hdr hdr;
3325 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3326 status = decode_compound_hdr(&xdr, &hdr);
3329 status = decode_putfh(&xdr);
3332 status = decode_open(&xdr, res);
3335 status = decode_getfattr(&xdr, res->f_attr, res->server);
3341 * Decode SETATTR response
3343 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3345 struct xdr_stream xdr;
3346 struct compound_hdr hdr;
3349 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3350 status = decode_compound_hdr(&xdr, &hdr);
3353 status = decode_putfh(&xdr);
3356 status = decode_setattr(&xdr, res);
3359 status = decode_getfattr(&xdr, res->fattr, res->server);
3365 * Decode LOCK response
3367 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3369 struct xdr_stream xdr;
3370 struct compound_hdr hdr;
3373 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3374 status = decode_compound_hdr(&xdr, &hdr);
3377 status = decode_putfh(&xdr);
3380 status = decode_lock(&xdr, res);
3386 * Decode LOCKT response
3388 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3390 struct xdr_stream xdr;
3391 struct compound_hdr hdr;
3394 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3395 status = decode_compound_hdr(&xdr, &hdr);
3398 status = decode_putfh(&xdr);
3401 status = decode_lockt(&xdr, res);
3407 * Decode LOCKU response
3409 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3411 struct xdr_stream xdr;
3412 struct compound_hdr hdr;
3415 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3416 status = decode_compound_hdr(&xdr, &hdr);
3419 status = decode_putfh(&xdr);
3422 status = decode_locku(&xdr, res);
3428 * Decode READLINK response
3430 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3432 struct xdr_stream xdr;
3433 struct compound_hdr hdr;
3436 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3437 status = decode_compound_hdr(&xdr, &hdr);
3440 status = decode_putfh(&xdr);
3443 status = decode_readlink(&xdr, rqstp);
3449 * Decode READDIR response
3451 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3453 struct xdr_stream xdr;
3454 struct compound_hdr hdr;
3457 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3458 status = decode_compound_hdr(&xdr, &hdr);
3461 status = decode_putfh(&xdr);
3464 status = decode_readdir(&xdr, rqstp, res);
3470 * Decode Read response
3472 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3474 struct xdr_stream xdr;
3475 struct compound_hdr hdr;
3478 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3479 status = decode_compound_hdr(&xdr, &hdr);
3482 status = decode_putfh(&xdr);
3485 status = decode_read(&xdr, rqstp, res);
3487 status = res->count;
3493 * Decode WRITE response
3495 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3497 struct xdr_stream xdr;
3498 struct compound_hdr hdr;
3501 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3502 status = decode_compound_hdr(&xdr, &hdr);
3505 status = decode_putfh(&xdr);
3508 status = decode_write(&xdr, res);
3510 status = res->count;
3516 * Decode COMMIT response
3518 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3520 struct xdr_stream xdr;
3521 struct compound_hdr hdr;
3524 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3525 status = decode_compound_hdr(&xdr, &hdr);
3528 status = decode_putfh(&xdr);
3531 status = decode_commit(&xdr, res);
3539 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3541 struct xdr_stream xdr;
3542 struct compound_hdr hdr;
3545 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3546 status = decode_compound_hdr(&xdr, &hdr);
3548 status = decode_putfh(&xdr);
3550 status = decode_fsinfo(&xdr, fsinfo);
3552 status = -nfs_stat_to_errno(hdr.status);
3559 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
3561 struct xdr_stream xdr;
3562 struct compound_hdr hdr;
3565 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3566 status = decode_compound_hdr(&xdr, &hdr);
3568 status = decode_putfh(&xdr);
3570 status = decode_pathconf(&xdr, pathconf);
3577 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
3579 struct xdr_stream xdr;
3580 struct compound_hdr hdr;
3583 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3584 status = decode_compound_hdr(&xdr, &hdr);
3586 status = decode_putfh(&xdr);
3588 status = decode_statfs(&xdr, fsstat);
3593 * GETATTR_BITMAP request
3595 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
3597 struct xdr_stream xdr;
3598 struct compound_hdr hdr;
3601 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3602 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3604 if ((status = decode_putfh(&xdr)) != 0)
3606 status = decode_server_caps(&xdr, res);
3612 * Decode RENEW response
3614 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3616 struct xdr_stream xdr;
3617 struct compound_hdr hdr;
3620 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3621 status = decode_compound_hdr(&xdr, &hdr);
3623 status = decode_renew(&xdr);
3628 * a SETCLIENTID request
3630 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
3631 struct nfs4_client *clp)
3633 struct xdr_stream xdr;
3634 struct compound_hdr hdr;
3637 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3638 status = decode_compound_hdr(&xdr, &hdr);
3640 status = decode_setclientid(&xdr, clp);
3642 status = -nfs_stat_to_errno(hdr.status);
3647 * a SETCLIENTID_CONFIRM request
3649 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3651 struct xdr_stream xdr;
3652 struct compound_hdr hdr;
3655 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3656 status = decode_compound_hdr(&xdr, &hdr);
3658 status = decode_setclientid_confirm(&xdr);
3660 status = decode_putrootfh(&xdr);
3662 status = decode_fsinfo(&xdr, fsinfo);
3664 status = -nfs_stat_to_errno(hdr.status);
3668 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
3674 return ERR_PTR(-EAGAIN);
3676 return ERR_PTR(-EBADCOOKIE);
3679 entry->prev_cookie = entry->cookie;
3680 p = xdr_decode_hyper(p, &entry->cookie);
3681 entry->len = ntohl(*p++);
3682 entry->name = (const char *) p;
3683 p += XDR_QUADLEN(entry->len);
3686 * In case the server doesn't return an inode number,
3687 * we fake one here. (We don't use inode number 0,
3688 * since glibc seems to choke on it...)
3692 len = ntohl(*p++); /* bitmap length */
3694 len = ntohl(*p++); /* attribute buffer length */
3696 p = xdr_decode_hyper(p, &entry->ino);
3698 entry->eof = !p[0] && p[1];
3703 * We need to translate between nfs status return values and
3704 * the local errno values which may not be the same.
3711 { NFS4ERR_PERM, EPERM },
3712 { NFS4ERR_NOENT, ENOENT },
3713 { NFS4ERR_IO, errno_NFSERR_IO },
3714 { NFS4ERR_NXIO, ENXIO },
3715 { NFS4ERR_ACCESS, EACCES },
3716 { NFS4ERR_EXIST, EEXIST },
3717 { NFS4ERR_XDEV, EXDEV },
3718 { NFS4ERR_NOTDIR, ENOTDIR },
3719 { NFS4ERR_ISDIR, EISDIR },
3720 { NFS4ERR_INVAL, EINVAL },
3721 { NFS4ERR_FBIG, EFBIG },
3722 { NFS4ERR_NOSPC, ENOSPC },
3723 { NFS4ERR_ROFS, EROFS },
3724 { NFS4ERR_MLINK, EMLINK },
3725 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
3726 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
3727 { NFS4ERR_DQUOT, EDQUOT },
3728 { NFS4ERR_STALE, ESTALE },
3729 { NFS4ERR_BADHANDLE, EBADHANDLE },
3730 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
3731 { NFS4ERR_NOTSUPP, ENOTSUPP },
3732 { NFS4ERR_TOOSMALL, ETOOSMALL },
3733 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
3734 { NFS4ERR_BADTYPE, EBADTYPE },
3735 { NFS4ERR_LOCKED, EAGAIN },
3736 { NFS4ERR_RESOURCE, EREMOTEIO },
3737 { NFS4ERR_SYMLINK, ELOOP },
3738 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
3739 { NFS4ERR_DEADLOCK, EDEADLK },
3740 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
3741 * to be handled by a
3748 * Convert an NFS error code to a local one.
3749 * This one is used jointly by NFSv2 and NFSv3.
3752 nfs_stat_to_errno(int stat)
3755 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
3756 if (nfs_errtbl[i].stat == stat)
3757 return nfs_errtbl[i].errno;
3760 /* The server is looney tunes. */
3761 return ESERVERFAULT;
3763 /* If we cannot translate the error, the recovery routines should
3765 * Note: remaining NFSv4 error codes have values > 10000, so should
3766 * not conflict with native Linux error codes.
3772 # define MAX(a, b) (((a) > (b))? (a) : (b))
3775 #define PROC(proc, argtype, restype) \
3776 [NFSPROC4_CLNT_##proc] = { \
3777 .p_proc = NFSPROC4_COMPOUND, \
3778 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
3779 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
3780 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
3783 struct rpc_procinfo nfs4_procedures[] = {
3784 PROC(READ, enc_read, dec_read),
3785 PROC(WRITE, enc_write, dec_write),
3786 PROC(COMMIT, enc_commit, dec_commit),
3787 PROC(OPEN, enc_open, dec_open),
3788 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
3789 PROC(OPEN_RECLAIM, enc_open_reclaim, dec_open_reclaim),
3790 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
3791 PROC(CLOSE, enc_close, dec_close),
3792 PROC(SETATTR, enc_setattr, dec_setattr),
3793 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
3794 PROC(RENEW, enc_renew, dec_renew),
3795 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
3796 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
3797 PROC(LOCK, enc_lock, dec_lock),
3798 PROC(LOCKT, enc_lockt, dec_lockt),
3799 PROC(LOCKU, enc_locku, dec_locku),
3800 PROC(ACCESS, enc_access, dec_access),
3801 PROC(GETATTR, enc_getattr, dec_getattr),
3802 PROC(LOOKUP, enc_lookup, dec_lookup),
3803 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
3804 PROC(REMOVE, enc_remove, dec_remove),
3805 PROC(RENAME, enc_rename, dec_rename),
3806 PROC(LINK, enc_link, dec_link),
3807 PROC(CREATE, enc_create, dec_create),
3808 PROC(PATHCONF, enc_pathconf, dec_pathconf),
3809 PROC(STATFS, enc_statfs, dec_statfs),
3810 PROC(READLINK, enc_readlink, dec_readlink),
3811 PROC(READDIR, enc_readdir, dec_readdir),
3812 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
3815 struct rpc_version nfs_version4 = {
3817 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
3818 .procs = nfs4_procedures