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);
936 /* set up reply iovec
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;
954 WRITE32(OP_READLINK);
956 /* set up reply iovec
957 * toplevel_status + taglen + rescount + OP_PUTFH + status
958 * + OP_READLINK + status = 7
960 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
961 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages, 0, readlink->count);
966 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
970 RESERVE_SPACE(8 + name->len);
973 WRITEMEM(name->name, name->len);
978 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
982 RESERVE_SPACE(8 + oldname->len);
984 WRITE32(oldname->len);
985 WRITEMEM(oldname->name, oldname->len);
987 RESERVE_SPACE(4 + newname->len);
988 WRITE32(newname->len);
989 WRITEMEM(newname->name, newname->len);
994 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1000 WRITE64(client_stateid->cl_clientid);
1006 encode_savefh(struct xdr_stream *xdr)
1016 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1021 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1022 WRITE32(OP_SETATTR);
1023 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1025 if ((status = encode_attrs(xdr, arg->iap, server)))
1031 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1034 uint32_t len1, len2, len3;
1037 len1 = strlen(setclientid->sc_name);
1038 len2 = strlen(setclientid->sc_netid);
1039 len3 = strlen(setclientid->sc_uaddr);
1040 total_len = XDR_QUADLEN(len1) + XDR_QUADLEN(len2) + XDR_QUADLEN(len3);
1041 total_len = (total_len << 2) + 24 + sizeof(setclientid->sc_verifier.data);
1043 RESERVE_SPACE(total_len);
1044 WRITE32(OP_SETCLIENTID);
1045 WRITEMEM(setclientid->sc_verifier.data, sizeof(setclientid->sc_verifier.data));
1047 WRITEMEM(setclientid->sc_name, len1);
1048 WRITE32(setclientid->sc_prog);
1050 WRITEMEM(setclientid->sc_netid, len2);
1052 WRITEMEM(setclientid->sc_uaddr, len3);
1053 WRITE32(setclientid->sc_cb_ident);
1058 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1062 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1063 WRITE32(OP_SETCLIENTID_CONFIRM);
1064 WRITE64(client_state->cl_clientid);
1065 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1070 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1077 encode_stateid(xdr, args->state, args->lockowner);
1080 WRITE64(args->offset);
1081 WRITE32(args->stable);
1082 WRITE32(args->count);
1084 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1089 * END OF "GENERIC" ENCODE ROUTINES.
1093 * Encode an ACCESS request
1095 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1097 struct xdr_stream xdr;
1098 struct compound_hdr hdr = {
1103 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1104 encode_compound_hdr(&xdr, &hdr);
1105 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1106 status = encode_access(&xdr, args->access);
1111 * Encode LOOKUP request
1113 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1115 struct xdr_stream xdr;
1116 struct compound_hdr hdr = {
1121 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1122 encode_compound_hdr(&xdr, &hdr);
1123 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1125 if ((status = encode_lookup(&xdr, args->name)) != 0)
1127 if ((status = encode_getfh(&xdr)) != 0)
1129 status = encode_getfattr(&xdr, args->bitmask);
1135 * Encode LOOKUP_ROOT request
1137 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1139 struct xdr_stream xdr;
1140 struct compound_hdr hdr = {
1145 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1146 encode_compound_hdr(&xdr, &hdr);
1147 if ((status = encode_putrootfh(&xdr)) != 0)
1149 if ((status = encode_getfh(&xdr)) == 0)
1150 status = encode_getfattr(&xdr, args->bitmask);
1156 * Encode REMOVE request
1158 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1160 struct xdr_stream xdr;
1161 struct compound_hdr hdr = {
1166 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1167 encode_compound_hdr(&xdr, &hdr);
1168 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1169 status = encode_remove(&xdr, args->name);
1174 * Encode RENAME request
1176 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1178 struct xdr_stream xdr;
1179 struct compound_hdr hdr = {
1184 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1185 encode_compound_hdr(&xdr, &hdr);
1186 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1188 if ((status = encode_savefh(&xdr)) != 0)
1190 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1192 status = encode_rename(&xdr, args->old_name, args->new_name);
1198 * Encode LINK request
1200 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1202 struct xdr_stream xdr;
1203 struct compound_hdr hdr = {
1208 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1209 encode_compound_hdr(&xdr, &hdr);
1210 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1212 if ((status = encode_savefh(&xdr)) != 0)
1214 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1216 status = encode_link(&xdr, args->name);
1222 * Encode CREATE request
1224 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1226 struct xdr_stream xdr;
1227 struct compound_hdr hdr = {
1232 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1233 encode_compound_hdr(&xdr, &hdr);
1234 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1236 if ((status = encode_create(&xdr, args)) != 0)
1238 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1240 status = encode_getfh(&xdr);
1246 * Encode GETATTR request
1248 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1250 struct xdr_stream xdr;
1251 struct compound_hdr hdr = {
1256 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1257 encode_compound_hdr(&xdr, &hdr);
1258 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1259 status = encode_getfattr(&xdr, args->bitmask);
1264 * Encode a CLOSE request
1266 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1268 struct xdr_stream xdr;
1269 struct compound_hdr hdr = {
1274 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1275 encode_compound_hdr(&xdr, &hdr);
1276 status = encode_putfh(&xdr, args->fh);
1279 status = encode_close(&xdr, args);
1285 * Encode an OPEN request
1287 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1289 struct xdr_stream xdr;
1290 struct compound_hdr hdr = {
1295 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1296 encode_compound_hdr(&xdr, &hdr);
1297 status = encode_putfh(&xdr, args->fh);
1300 status = encode_open(&xdr, args);
1303 status = encode_getfattr(&xdr, args->bitmask);
1306 status = encode_getfh(&xdr);
1312 * Encode an OPEN_CONFIRM request
1314 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1316 struct xdr_stream xdr;
1317 struct compound_hdr hdr = {
1322 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1323 encode_compound_hdr(&xdr, &hdr);
1324 status = encode_putfh(&xdr, args->fh);
1327 status = encode_open_confirm(&xdr, args);
1333 * Encode an OPEN request
1335 static int nfs4_xdr_enc_open_reclaim(struct rpc_rqst *req, uint32_t *p, struct nfs_open_reclaimargs *args)
1337 struct xdr_stream xdr;
1338 struct compound_hdr hdr = {
1343 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1344 encode_compound_hdr(&xdr, &hdr);
1345 status = encode_putfh(&xdr, args->fh);
1348 status = encode_open_reclaim(&xdr, args);
1351 status = encode_getfattr(&xdr, args->bitmask);
1357 * Encode an OPEN_DOWNGRADE request
1359 static int nfs4_xdr_enc_open_downgrade(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_open_downgrade(&xdr, args);
1378 * Encode a LOCK request
1380 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *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_lock(&xdr, args);
1399 * Encode a LOCKT request
1401 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1403 struct xdr_stream xdr;
1404 struct compound_hdr hdr = {
1409 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1410 encode_compound_hdr(&xdr, &hdr);
1411 status = encode_putfh(&xdr, args->fh);
1414 status = encode_lockt(&xdr, args);
1420 * Encode a LOCKU request
1422 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1424 struct xdr_stream xdr;
1425 struct compound_hdr hdr = {
1430 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1431 encode_compound_hdr(&xdr, &hdr);
1432 status = encode_putfh(&xdr, args->fh);
1435 status = encode_locku(&xdr, args);
1441 * Encode a READLINK request
1443 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1445 struct xdr_stream xdr;
1446 struct compound_hdr hdr = {
1451 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1452 encode_compound_hdr(&xdr, &hdr);
1453 status = encode_putfh(&xdr, args->fh);
1456 status = encode_readlink(&xdr, args, req);
1462 * Encode a READDIR request
1464 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1466 struct xdr_stream xdr;
1467 struct compound_hdr hdr = {
1472 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1473 encode_compound_hdr(&xdr, &hdr);
1474 status = encode_putfh(&xdr, args->fh);
1477 status = encode_readdir(&xdr, args, req);
1483 * Encode a READ request
1485 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1487 struct rpc_auth *auth = req->rq_task->tk_auth;
1488 struct xdr_stream xdr;
1489 struct compound_hdr hdr = {
1494 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1495 encode_compound_hdr(&xdr, &hdr);
1496 status = encode_putfh(&xdr, args->fh);
1499 status = encode_read(&xdr, args);
1503 /* set up reply iovec
1504 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1505 * + OP_READ + status + eof + datalen = 9
1507 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1508 xdr_inline_pages(&req->rq_rcv_buf, replen,
1509 args->pages, args->pgbase, args->count);
1515 * Encode an SETATTR request
1517 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1520 struct xdr_stream xdr;
1521 struct compound_hdr hdr = {
1526 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1527 encode_compound_hdr(&xdr, &hdr);
1528 status = encode_putfh(&xdr, args->fh);
1531 status = encode_setattr(&xdr, args, args->server);
1534 status = encode_getfattr(&xdr, args->bitmask);
1540 * Encode a WRITE request
1542 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1544 struct xdr_stream xdr;
1545 struct compound_hdr hdr = {
1550 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1551 encode_compound_hdr(&xdr, &hdr);
1552 status = encode_putfh(&xdr, args->fh);
1555 status = encode_write(&xdr, args);
1563 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1565 struct xdr_stream xdr;
1566 struct compound_hdr hdr = {
1571 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1572 encode_compound_hdr(&xdr, &hdr);
1573 status = encode_putfh(&xdr, args->fh);
1576 status = encode_commit(&xdr, args);
1584 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1586 struct xdr_stream xdr;
1587 struct compound_hdr hdr = {
1592 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1593 encode_compound_hdr(&xdr, &hdr);
1594 status = encode_putfh(&xdr, args->fh);
1596 status = encode_fsinfo(&xdr, args->bitmask);
1601 * a PATHCONF request
1603 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1605 extern u32 nfs4_pathconf_bitmap[2];
1606 struct xdr_stream xdr;
1607 struct compound_hdr hdr = {
1612 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1613 encode_compound_hdr(&xdr, &hdr);
1614 status = encode_putfh(&xdr, args->fh);
1616 status = encode_getattr_one(&xdr,
1617 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1624 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1626 extern u32 nfs4_statfs_bitmap[];
1627 struct xdr_stream xdr;
1628 struct compound_hdr hdr = {
1633 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1634 encode_compound_hdr(&xdr, &hdr);
1635 status = encode_putfh(&xdr, args->fh);
1637 status = encode_getattr_two(&xdr,
1638 args->bitmask[0] & nfs4_statfs_bitmap[0],
1639 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1644 * GETATTR_BITMAP request
1646 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1648 struct xdr_stream xdr;
1649 struct compound_hdr hdr = {
1654 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1655 encode_compound_hdr(&xdr, &hdr);
1656 status = encode_putfh(&xdr, fhandle);
1658 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1659 FATTR4_WORD0_LINK_SUPPORT|
1660 FATTR4_WORD0_SYMLINK_SUPPORT|
1661 FATTR4_WORD0_ACLSUPPORT);
1668 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1670 struct xdr_stream xdr;
1671 struct compound_hdr hdr = {
1675 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1676 encode_compound_hdr(&xdr, &hdr);
1677 return encode_renew(&xdr, clp);
1681 * a SETCLIENTID request
1683 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1685 struct xdr_stream xdr;
1686 struct compound_hdr hdr = {
1690 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1691 encode_compound_hdr(&xdr, &hdr);
1692 return encode_setclientid(&xdr, sc);
1696 * a SETCLIENTID_CONFIRM request
1698 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1700 struct xdr_stream xdr;
1701 struct compound_hdr hdr = {
1704 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1707 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1708 encode_compound_hdr(&xdr, &hdr);
1709 status = encode_setclientid_confirm(&xdr, clp);
1711 status = encode_putrootfh(&xdr);
1713 status = encode_fsinfo(&xdr, lease_bitmap);
1718 * START OF "GENERIC" DECODE ROUTINES.
1719 * These may look a little ugly since they are imported from a "generic"
1720 * set of XDR encode/decode routines which are intended to be shared by
1721 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1723 * If the pain of reading these is too great, it should be a straightforward
1724 * task to translate them into Linux-specific versions which are more
1725 * consistent with the style used in NFSv2/v3...
1727 #define READ32(x) (x) = ntohl(*p++)
1728 #define READ64(x) do { \
1729 (x) = (u64)ntohl(*p++) << 32; \
1730 (x) |= ntohl(*p++); \
1732 #define READTIME(x) do { \
1734 (x.tv_sec) = ntohl(*p++); \
1735 (x.tv_nsec) = ntohl(*p++); \
1737 #define COPYMEM(x,nbytes) do { \
1738 memcpy((x), p, nbytes); \
1739 p += XDR_QUADLEN(nbytes); \
1742 #define READ_BUF(nbytes) do { \
1743 p = xdr_inline_decode(xdr, nbytes); \
1745 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
1746 __FUNCTION__, __LINE__); \
1751 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
1756 READ32(hdr->status);
1757 READ32(hdr->taglen);
1759 READ_BUF(hdr->taglen + 4);
1760 hdr->tag = (char *)p;
1761 p += XDR_QUADLEN(hdr->taglen);
1766 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
1774 if (opnum != expected) {
1776 "nfs4_decode_op_hdr: Server returned operation"
1777 " %d but we issued a request for %d\n",
1782 if (nfserr != NFS_OK)
1783 return -nfs_stat_to_errno(nfserr);
1787 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
1794 bitmap[0] = bitmap[1] = 0;
1795 READ_BUF((bmlen << 2));
1804 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
1814 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
1816 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
1817 decode_attr_bitmap(xdr, bitmask);
1818 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
1820 bitmask[0] = bitmask[1] = 0;
1821 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
1825 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
1830 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
1832 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
1835 if (*type < NF4REG || *type > NF4NAMEDATTR) {
1836 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
1839 bitmap[0] &= ~FATTR4_WORD0_TYPE;
1841 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
1845 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
1850 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
1852 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
1855 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
1857 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
1858 (unsigned long long)*change);
1862 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
1867 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
1869 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
1872 bitmap[0] &= ~FATTR4_WORD0_SIZE;
1874 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
1878 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
1883 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
1885 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
1888 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
1890 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
1894 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
1899 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
1901 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
1904 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
1906 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
1910 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
1916 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
1918 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
1920 READ64(fsid->major);
1921 READ64(fsid->minor);
1922 bitmap[0] &= ~FATTR4_WORD0_FSID;
1924 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
1925 (unsigned long long)fsid->major,
1926 (unsigned long long)fsid->minor);
1930 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
1935 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
1937 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
1940 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
1942 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
1946 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
1950 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
1951 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
1953 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
1956 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
1958 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
1962 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
1967 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
1969 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
1972 bitmap[0] &= ~FATTR4_WORD0_FILEID;
1974 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
1978 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
1984 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
1986 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
1989 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
1991 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
1995 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2001 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2003 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2006 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2008 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2012 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2018 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2020 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2023 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2025 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2029 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2035 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2037 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2040 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2042 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2046 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2052 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2054 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2057 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2059 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2063 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2069 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2071 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2074 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2076 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2080 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2086 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2088 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2092 if (maxread > 0x7FFFFFFF)
2093 maxread = 0x7FFFFFFF;
2094 *res = (uint32_t)maxread;
2095 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2097 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2101 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2107 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2109 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2113 if (maxwrite > 0x7FFFFFFF)
2114 maxwrite = 0x7FFFFFFF;
2115 *res = (uint32_t)maxwrite;
2116 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2118 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2122 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2127 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2129 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2133 bitmap[1] &= ~FATTR4_WORD1_MODE;
2135 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2139 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2144 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2146 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2149 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2151 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2155 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2160 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2162 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2166 if (len < XDR_MAX_NETOBJ) {
2167 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2168 dprintk("%s: nfs_map_name_to_uid failed!\n",
2171 printk(KERN_WARNING "%s: name too long (%u)!\n",
2173 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2175 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2179 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2184 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2186 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2190 if (len < XDR_MAX_NETOBJ) {
2191 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2192 dprintk("%s: nfs_map_group_to_gid failed!\n",
2195 printk(KERN_WARNING "%s: name too long (%u)!\n",
2197 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2199 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2203 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2205 uint32_t major = 0, minor = 0, *p;
2208 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2210 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2216 tmp = MKDEV(major, minor);
2217 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2219 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2221 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2225 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2231 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2233 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2236 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2238 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2242 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2248 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2250 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2253 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2255 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2259 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2265 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2267 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2270 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2272 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2276 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2281 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2283 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2286 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2288 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2289 (unsigned long long)*used);
2293 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2302 time->tv_sec = (time_t)sec;
2303 time->tv_nsec = (long)nsec;
2307 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2313 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2315 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2316 status = decode_attr_time(xdr, time);
2317 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2319 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2323 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2329 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2331 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2332 status = decode_attr_time(xdr, time);
2333 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2335 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2339 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2345 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2347 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2348 status = decode_attr_time(xdr, time);
2349 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2351 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2355 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2357 unsigned int attrwords = XDR_QUADLEN(attrlen);
2358 unsigned int nwords = xdr->p - savep;
2360 if (unlikely(attrwords != nwords)) {
2361 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2364 (attrwords < nwords) ? '<' : '>',
2371 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2376 READ32(cinfo->atomic);
2377 READ64(cinfo->before);
2378 READ64(cinfo->after);
2382 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2388 status = decode_op_hdr(xdr, OP_ACCESS);
2394 access->supported = supp;
2395 access->access = acc;
2399 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2404 status = decode_op_hdr(xdr, OP_CLOSE);
2407 READ_BUF(sizeof(res->stateid.data));
2408 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2412 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2417 status = decode_op_hdr(xdr, OP_COMMIT);
2421 COPYMEM(res->verf->verifier, 8);
2425 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2431 status = decode_op_hdr(xdr, OP_CREATE);
2434 if ((status = decode_change_info(xdr, cinfo)))
2438 READ_BUF(bmlen << 2);
2442 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2449 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2451 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2453 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2455 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2457 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2459 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2461 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2463 status = verify_attr_len(xdr, savep, attrlen);
2466 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2470 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2477 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2479 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2481 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2484 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2486 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2488 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2490 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2492 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2494 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2497 status = verify_attr_len(xdr, savep, attrlen);
2500 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2504 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2511 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2513 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2515 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2518 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2520 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2523 status = verify_attr_len(xdr, savep, attrlen);
2526 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2530 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2536 int status, fmode = 0;
2538 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2540 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2543 fattr->bitmap[0] = bitmap[0];
2544 fattr->bitmap[1] = bitmap[1];
2546 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2550 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2552 fattr->type = nfs_type2fmt[type].nfs2type;
2553 fmode = nfs_type2fmt[type].mode;
2555 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2557 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2559 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2561 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2563 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2565 fattr->mode |= fmode;
2566 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2568 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2570 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2572 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2574 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2576 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2578 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2580 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2582 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) {
2583 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2584 fattr->timestamp = jiffies;
2588 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2593 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2596 uint32_t attrlen, bitmap[2];
2599 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2601 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2603 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2606 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2608 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2610 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2612 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2614 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2615 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2617 fsinfo->wtpref = fsinfo->wtmax;
2619 status = verify_attr_len(xdr, savep, attrlen);
2622 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2626 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2632 status = decode_op_hdr(xdr, OP_GETFH);
2635 /* Zero handle first to allow comparisons */
2636 memset(fh, 0, sizeof(*fh));
2640 if (len > NFS4_FHSIZE)
2644 COPYMEM(fh->data, len);
2648 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2652 status = decode_op_hdr(xdr, OP_LINK);
2655 return decode_change_info(xdr, cinfo);
2659 * We create the owner, so we know a proper owner.id length is 4.
2661 static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2667 READ64(denied->offset);
2668 READ64(denied->length);
2669 READ32(denied->type);
2670 READ64(denied->owner.clientid);
2674 READ32(denied->owner.id);
2675 return -NFS4ERR_DENIED;
2678 static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2683 status = decode_op_hdr(xdr, OP_LOCK);
2685 READ_BUF(sizeof(nfs4_stateid));
2686 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2687 } else if (status == -NFS4ERR_DENIED)
2688 return decode_lock_denied(xdr, &res->u.denied);
2692 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2695 status = decode_op_hdr(xdr, OP_LOCKT);
2696 if (status == -NFS4ERR_DENIED)
2697 return decode_lock_denied(xdr, &res->u.denied);
2701 static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2706 status = decode_op_hdr(xdr, OP_LOCKU);
2708 READ_BUF(sizeof(nfs4_stateid));
2709 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2714 static int decode_lookup(struct xdr_stream *xdr)
2716 return decode_op_hdr(xdr, OP_LOOKUP);
2719 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
2722 uint32_t bmlen, delegation_type;
2725 status = decode_op_hdr(xdr, OP_OPEN);
2728 READ_BUF(sizeof(res->stateid.data));
2729 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2731 decode_change_info(xdr, &res->cinfo);
2734 READ32(res->rflags);
2739 READ_BUF((bmlen << 2) + 4);
2741 READ32(delegation_type);
2742 if (delegation_type == NFS4_OPEN_DELEGATE_NONE)
2745 printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
2749 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
2754 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
2757 READ_BUF(sizeof(res->stateid.data));
2758 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2762 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
2767 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
2770 READ_BUF(sizeof(res->stateid.data));
2771 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2775 static int decode_putfh(struct xdr_stream *xdr)
2777 return decode_op_hdr(xdr, OP_PUTFH);
2780 static int decode_putrootfh(struct xdr_stream *xdr)
2782 return decode_op_hdr(xdr, OP_PUTROOTFH);
2785 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
2787 struct iovec *iov = req->rq_rcv_buf.head;
2789 uint32_t count, eof, recvd, hdrlen;
2792 status = decode_op_hdr(xdr, OP_READ);
2798 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
2799 recvd = req->rq_rcv_buf.len - hdrlen;
2800 if (count > recvd) {
2801 printk(KERN_WARNING "NFS: server cheating in read reply: "
2802 "count %u > recvd %u\n", count, recvd);
2806 xdr_read_pages(xdr, count);
2812 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
2814 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
2815 struct page *page = *rcvbuf->pages;
2816 struct iovec *iov = rcvbuf->head;
2817 unsigned int nr, pglen = rcvbuf->page_len;
2818 uint32_t *end, *entry, *p, *kaddr;
2819 uint32_t len, attrlen, word;
2820 int i, hdrlen, recvd, status;
2822 status = decode_op_hdr(xdr, OP_READDIR);
2826 COPYMEM(readdir->verifier.data, 8);
2828 hdrlen = (char *) p - (char *) iov->iov_base;
2829 recvd = rcvbuf->len - hdrlen;
2832 xdr_read_pages(xdr, pglen);
2834 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
2835 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
2836 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
2838 for (nr = 0; *p++; nr++) {
2841 p += 2; /* cookie */
2842 len = ntohl(*p++); /* filename length */
2843 if (len > NFS4_MAXNAMLEN) {
2844 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
2848 p += XDR_QUADLEN(len);
2851 len = ntohl(*p++); /* bitmap length */
2853 printk(KERN_WARNING "NFS: giant bitmap in readdir (len 0x%x)\n", len);
2856 if (p + len + 1 > end)
2859 for (i = 0; i < len; i++) {
2863 else if (i == 0 && word == FATTR4_WORD0_FILEID) {
2867 printk(KERN_WARNING "NFS: unexpected bitmap word in readdir (0x%x)\n", word);
2870 if (ntohl(*p++) != attrlen) {
2871 printk(KERN_WARNING "NFS: unexpected attrlen in readdir\n");
2874 p += XDR_QUADLEN(attrlen);
2878 if (!nr && (entry[0] != 0 || entry[1] == 0))
2881 kunmap_atomic(kaddr, KM_USER0);
2884 entry[0] = entry[1] = 0;
2885 /* truncate listing ? */
2887 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
2892 kunmap_atomic(kaddr, KM_USER0);
2893 return -errno_NFSERR_IO;
2896 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
2898 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
2899 struct iovec *iov = rcvbuf->head;
2901 unsigned int hdrlen, len;
2905 status = decode_op_hdr(xdr, OP_READLINK);
2909 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
2910 if (iov->iov_len > hdrlen) {
2911 dprintk("NFS: READLINK header is short. iovec will be shifted.\n");
2912 xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen);
2916 * The XDR encode routine has set things up so that
2917 * the link text will be copied directly into the
2918 * buffer. We just have to do overflow-checking,
2919 * and and null-terminate the text (the VFS expects
2920 * null-termination).
2922 strlen = (uint32_t *) kmap_atomic(rcvbuf->pages[0], KM_USER0);
2923 len = ntohl(*strlen);
2924 if (len > PAGE_CACHE_SIZE - 5) {
2925 printk(KERN_WARNING "nfs: server returned giant symlink!\n");
2926 kunmap_atomic(strlen, KM_USER0);
2931 string = (char *)(strlen + 1);
2933 kunmap_atomic(strlen, KM_USER0);
2937 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2941 status = decode_op_hdr(xdr, OP_REMOVE);
2944 status = decode_change_info(xdr, cinfo);
2949 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
2950 struct nfs4_change_info *new_cinfo)
2954 status = decode_op_hdr(xdr, OP_RENAME);
2957 if ((status = decode_change_info(xdr, old_cinfo)))
2959 status = decode_change_info(xdr, new_cinfo);
2964 static int decode_renew(struct xdr_stream *xdr)
2966 return decode_op_hdr(xdr, OP_RENEW);
2970 decode_savefh(struct xdr_stream *xdr)
2972 return decode_op_hdr(xdr, OP_SAVEFH);
2975 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
2982 status = decode_op_hdr(xdr, OP_SETATTR);
2987 READ_BUF(bmlen << 2);
2991 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
2999 if (opnum != OP_SETCLIENTID) {
3001 "nfs4_decode_setclientid: Server returned operation"
3006 if (nfserr == NFS_OK) {
3007 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3008 READ64(clp->cl_clientid);
3009 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3010 } else if (nfserr == NFSERR_CLID_INUSE) {
3013 /* skip netid string */
3018 /* skip uaddr string */
3024 return -nfs_stat_to_errno(nfserr);
3029 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3031 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3034 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3039 status = decode_op_hdr(xdr, OP_WRITE);
3045 READ32(res->verf->committed);
3046 COPYMEM(res->verf->verifier, 8);
3051 * Decode OPEN_DOWNGRADE response
3053 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3055 struct xdr_stream xdr;
3056 struct compound_hdr hdr;
3059 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3060 status = decode_compound_hdr(&xdr, &hdr);
3063 status = decode_putfh(&xdr);
3066 status = decode_open_downgrade(&xdr, res);
3072 * END OF "GENERIC" DECODE ROUTINES.
3076 * Decode ACCESS response
3078 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3080 struct xdr_stream xdr;
3081 struct compound_hdr hdr;
3084 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3085 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3087 if ((status = decode_putfh(&xdr)) == 0)
3088 status = decode_access(&xdr, res);
3094 * Decode LOOKUP response
3096 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3098 struct xdr_stream xdr;
3099 struct compound_hdr hdr;
3102 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3103 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3105 if ((status = decode_putfh(&xdr)) != 0)
3107 if ((status = decode_lookup(&xdr)) != 0)
3109 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3111 status = decode_getfattr(&xdr, res->fattr, res->server);
3117 * Decode LOOKUP_ROOT response
3119 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3121 struct xdr_stream xdr;
3122 struct compound_hdr hdr;
3125 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3126 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3128 if ((status = decode_putrootfh(&xdr)) != 0)
3130 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3131 status = decode_getfattr(&xdr, res->fattr, res->server);
3137 * Decode REMOVE response
3139 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3141 struct xdr_stream xdr;
3142 struct compound_hdr hdr;
3145 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3146 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3148 if ((status = decode_putfh(&xdr)) == 0)
3149 status = decode_remove(&xdr, cinfo);
3155 * Decode RENAME response
3157 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3159 struct xdr_stream xdr;
3160 struct compound_hdr hdr;
3163 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3164 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3166 if ((status = decode_putfh(&xdr)) != 0)
3168 if ((status = decode_savefh(&xdr)) != 0)
3170 if ((status = decode_putfh(&xdr)) != 0)
3172 status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
3178 * Decode LINK response
3180 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3182 struct xdr_stream xdr;
3183 struct compound_hdr hdr;
3186 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3187 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3189 if ((status = decode_putfh(&xdr)) != 0)
3191 if ((status = decode_savefh(&xdr)) != 0)
3193 if ((status = decode_putfh(&xdr)) != 0)
3195 status = decode_link(&xdr, cinfo);
3201 * Decode CREATE response
3203 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3205 struct xdr_stream xdr;
3206 struct compound_hdr hdr;
3209 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3210 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3212 if ((status = decode_putfh(&xdr)) != 0)
3214 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3216 if ((status = decode_getfattr(&xdr, res->fattr, res->server)) != 0)
3218 status = decode_getfh(&xdr, res->fh);
3224 * Decode GETATTR response
3226 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3228 struct xdr_stream xdr;
3229 struct compound_hdr hdr;
3232 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3233 status = decode_compound_hdr(&xdr, &hdr);
3236 status = decode_putfh(&xdr);
3239 status = decode_getfattr(&xdr, res->fattr, res->server);
3247 * Decode CLOSE response
3249 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3251 struct xdr_stream xdr;
3252 struct compound_hdr hdr;
3255 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3256 status = decode_compound_hdr(&xdr, &hdr);
3259 status = decode_putfh(&xdr);
3262 status = decode_close(&xdr, res);
3268 * Decode OPEN response
3270 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3272 struct xdr_stream xdr;
3273 struct compound_hdr hdr;
3276 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3277 status = decode_compound_hdr(&xdr, &hdr);
3280 status = decode_putfh(&xdr);
3283 status = decode_open(&xdr, res);
3286 status = decode_getfattr(&xdr, res->f_attr, res->server);
3289 status = decode_getfh(&xdr, &res->fh);
3295 * Decode OPEN_CONFIRM response
3297 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3299 struct xdr_stream xdr;
3300 struct compound_hdr hdr;
3303 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3304 status = decode_compound_hdr(&xdr, &hdr);
3307 status = decode_putfh(&xdr);
3310 status = decode_open_confirm(&xdr, res);
3316 * Decode OPEN_RECLAIM response
3318 static int nfs4_xdr_dec_open_reclaim(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3320 struct xdr_stream xdr;
3321 struct compound_hdr hdr;
3324 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3325 status = decode_compound_hdr(&xdr, &hdr);
3328 status = decode_putfh(&xdr);
3331 status = decode_open(&xdr, res);
3334 status = decode_getfattr(&xdr, res->f_attr, res->server);
3340 * Decode SETATTR response
3342 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3344 struct xdr_stream xdr;
3345 struct compound_hdr hdr;
3348 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3349 status = decode_compound_hdr(&xdr, &hdr);
3352 status = decode_putfh(&xdr);
3355 status = decode_setattr(&xdr, res);
3358 status = decode_getfattr(&xdr, res->fattr, res->server);
3364 * Decode LOCK response
3366 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3368 struct xdr_stream xdr;
3369 struct compound_hdr hdr;
3372 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3373 status = decode_compound_hdr(&xdr, &hdr);
3376 status = decode_putfh(&xdr);
3379 status = decode_lock(&xdr, res);
3385 * Decode LOCKT response
3387 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3389 struct xdr_stream xdr;
3390 struct compound_hdr hdr;
3393 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3394 status = decode_compound_hdr(&xdr, &hdr);
3397 status = decode_putfh(&xdr);
3400 status = decode_lockt(&xdr, res);
3406 * Decode LOCKU response
3408 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3410 struct xdr_stream xdr;
3411 struct compound_hdr hdr;
3414 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3415 status = decode_compound_hdr(&xdr, &hdr);
3418 status = decode_putfh(&xdr);
3421 status = decode_locku(&xdr, res);
3427 * Decode READLINK response
3429 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3431 struct xdr_stream xdr;
3432 struct compound_hdr hdr;
3435 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3436 status = decode_compound_hdr(&xdr, &hdr);
3439 status = decode_putfh(&xdr);
3442 status = decode_readlink(&xdr, rqstp);
3448 * Decode READDIR response
3450 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3452 struct xdr_stream xdr;
3453 struct compound_hdr hdr;
3456 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3457 status = decode_compound_hdr(&xdr, &hdr);
3460 status = decode_putfh(&xdr);
3463 status = decode_readdir(&xdr, rqstp, res);
3469 * Decode Read response
3471 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3473 struct xdr_stream xdr;
3474 struct compound_hdr hdr;
3477 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3478 status = decode_compound_hdr(&xdr, &hdr);
3481 status = decode_putfh(&xdr);
3484 status = decode_read(&xdr, rqstp, res);
3486 status = res->count;
3492 * Decode WRITE response
3494 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3496 struct xdr_stream xdr;
3497 struct compound_hdr hdr;
3500 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3501 status = decode_compound_hdr(&xdr, &hdr);
3504 status = decode_putfh(&xdr);
3507 status = decode_write(&xdr, res);
3509 status = res->count;
3515 * Decode COMMIT response
3517 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3519 struct xdr_stream xdr;
3520 struct compound_hdr hdr;
3523 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3524 status = decode_compound_hdr(&xdr, &hdr);
3527 status = decode_putfh(&xdr);
3530 status = decode_commit(&xdr, res);
3538 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3540 struct xdr_stream xdr;
3541 struct compound_hdr hdr;
3544 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3545 status = decode_compound_hdr(&xdr, &hdr);
3547 status = decode_putfh(&xdr);
3549 status = decode_fsinfo(&xdr, fsinfo);
3551 status = -nfs_stat_to_errno(hdr.status);
3558 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
3560 struct xdr_stream xdr;
3561 struct compound_hdr hdr;
3564 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3565 status = decode_compound_hdr(&xdr, &hdr);
3567 status = decode_putfh(&xdr);
3569 status = decode_pathconf(&xdr, pathconf);
3576 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
3578 struct xdr_stream xdr;
3579 struct compound_hdr hdr;
3582 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3583 status = decode_compound_hdr(&xdr, &hdr);
3585 status = decode_putfh(&xdr);
3587 status = decode_statfs(&xdr, fsstat);
3592 * GETATTR_BITMAP request
3594 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
3596 struct xdr_stream xdr;
3597 struct compound_hdr hdr;
3600 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3601 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3603 if ((status = decode_putfh(&xdr)) != 0)
3605 status = decode_server_caps(&xdr, res);
3611 * Decode RENEW response
3613 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3615 struct xdr_stream xdr;
3616 struct compound_hdr hdr;
3619 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3620 status = decode_compound_hdr(&xdr, &hdr);
3622 status = decode_renew(&xdr);
3627 * a SETCLIENTID request
3629 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
3630 struct nfs4_client *clp)
3632 struct xdr_stream xdr;
3633 struct compound_hdr hdr;
3636 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3637 status = decode_compound_hdr(&xdr, &hdr);
3639 status = decode_setclientid(&xdr, clp);
3641 status = -nfs_stat_to_errno(hdr.status);
3646 * a SETCLIENTID_CONFIRM request
3648 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3650 struct xdr_stream xdr;
3651 struct compound_hdr hdr;
3654 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3655 status = decode_compound_hdr(&xdr, &hdr);
3657 status = decode_setclientid_confirm(&xdr);
3659 status = decode_putrootfh(&xdr);
3661 status = decode_fsinfo(&xdr, fsinfo);
3663 status = -nfs_stat_to_errno(hdr.status);
3667 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
3673 return ERR_PTR(-EAGAIN);
3675 return ERR_PTR(-EBADCOOKIE);
3678 entry->prev_cookie = entry->cookie;
3679 p = xdr_decode_hyper(p, &entry->cookie);
3680 entry->len = ntohl(*p++);
3681 entry->name = (const char *) p;
3682 p += XDR_QUADLEN(entry->len);
3685 * In case the server doesn't return an inode number,
3686 * we fake one here. (We don't use inode number 0,
3687 * since glibc seems to choke on it...)
3691 len = ntohl(*p++); /* bitmap length */
3693 len = ntohl(*p++); /* attribute buffer length */
3695 p = xdr_decode_hyper(p, &entry->ino);
3697 entry->eof = !p[0] && p[1];
3702 * We need to translate between nfs status return values and
3703 * the local errno values which may not be the same.
3710 { NFS4ERR_PERM, EPERM },
3711 { NFS4ERR_NOENT, ENOENT },
3712 { NFS4ERR_IO, errno_NFSERR_IO },
3713 { NFS4ERR_NXIO, ENXIO },
3714 { NFS4ERR_ACCESS, EACCES },
3715 { NFS4ERR_EXIST, EEXIST },
3716 { NFS4ERR_XDEV, EXDEV },
3717 { NFS4ERR_NOTDIR, ENOTDIR },
3718 { NFS4ERR_ISDIR, EISDIR },
3719 { NFS4ERR_INVAL, EINVAL },
3720 { NFS4ERR_FBIG, EFBIG },
3721 { NFS4ERR_NOSPC, ENOSPC },
3722 { NFS4ERR_ROFS, EROFS },
3723 { NFS4ERR_MLINK, EMLINK },
3724 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
3725 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
3726 { NFS4ERR_DQUOT, EDQUOT },
3727 { NFS4ERR_STALE, ESTALE },
3728 { NFS4ERR_BADHANDLE, EBADHANDLE },
3729 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
3730 { NFS4ERR_NOTSUPP, ENOTSUPP },
3731 { NFS4ERR_TOOSMALL, ETOOSMALL },
3732 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
3733 { NFS4ERR_BADTYPE, EBADTYPE },
3734 { NFS4ERR_LOCKED, EAGAIN },
3735 { NFS4ERR_RESOURCE, EREMOTEIO },
3736 { NFS4ERR_SYMLINK, ELOOP },
3737 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
3738 { NFS4ERR_DEADLOCK, EDEADLK },
3739 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
3740 * to be handled by a
3747 * Convert an NFS error code to a local one.
3748 * This one is used jointly by NFSv2 and NFSv3.
3751 nfs_stat_to_errno(int stat)
3754 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
3755 if (nfs_errtbl[i].stat == stat)
3756 return nfs_errtbl[i].errno;
3759 /* The server is looney tunes. */
3760 return ESERVERFAULT;
3762 /* If we cannot translate the error, the recovery routines should
3764 * Note: remaining NFSv4 error codes have values > 10000, so should
3765 * not conflict with native Linux error codes.
3771 # define MAX(a, b) (((a) > (b))? (a) : (b))
3774 #define PROC(proc, argtype, restype) \
3775 [NFSPROC4_CLNT_##proc] = { \
3776 .p_proc = NFSPROC4_COMPOUND, \
3777 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
3778 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
3779 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
3782 struct rpc_procinfo nfs4_procedures[] = {
3783 PROC(READ, enc_read, dec_read),
3784 PROC(WRITE, enc_write, dec_write),
3785 PROC(COMMIT, enc_commit, dec_commit),
3786 PROC(OPEN, enc_open, dec_open),
3787 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
3788 PROC(OPEN_RECLAIM, enc_open_reclaim, dec_open_reclaim),
3789 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
3790 PROC(CLOSE, enc_close, dec_close),
3791 PROC(SETATTR, enc_setattr, dec_setattr),
3792 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
3793 PROC(RENEW, enc_renew, dec_renew),
3794 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
3795 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
3796 PROC(LOCK, enc_lock, dec_lock),
3797 PROC(LOCKT, enc_lockt, dec_lockt),
3798 PROC(LOCKU, enc_locku, dec_locku),
3799 PROC(ACCESS, enc_access, dec_access),
3800 PROC(GETATTR, enc_getattr, dec_getattr),
3801 PROC(LOOKUP, enc_lookup, dec_lookup),
3802 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
3803 PROC(REMOVE, enc_remove, dec_remove),
3804 PROC(RENAME, enc_rename, dec_rename),
3805 PROC(LINK, enc_link, dec_link),
3806 PROC(CREATE, enc_create, dec_create),
3807 PROC(PATHCONF, enc_pathconf, dec_pathconf),
3808 PROC(STATFS, enc_statfs, dec_statfs),
3809 PROC(READLINK, enc_readlink, dec_readlink),
3810 PROC(READDIR, enc_readdir, dec_readdir),
3811 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
3814 struct rpc_version nfs_version4 = {
3816 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
3817 .procs = nfs4_procedures