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>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define owner_id_maxsz (1 + 1)
74 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
75 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
76 #define op_encode_hdr_maxsz (1)
77 #define op_decode_hdr_maxsz (2)
78 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
80 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
81 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
82 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
83 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
84 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
85 ((3+NFS4_FHSIZE) >> 2))
86 #define nfs4_fattr_bitmap_maxsz 3
87 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
88 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
89 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
90 /* This is based on getfattr, which uses the most attributes: */
91 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
92 3 + 3 + 3 + 2 * nfs4_name_maxsz))
93 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
94 nfs4_fattr_value_maxsz)
95 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
96 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
97 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
98 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
99 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
100 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
101 #define decode_renew_maxsz (op_decode_hdr_maxsz)
102 #define encode_setclientid_maxsz \
103 (op_encode_hdr_maxsz + \
104 4 /*server->ip_addr*/ + \
107 6 + (NFS4_VERIFIER_SIZE >> 2))
108 #define decode_setclientid_maxsz \
109 (op_decode_hdr_maxsz + \
111 1024) /* large value for CLID_INUSE */
112 #define encode_setclientid_confirm_maxsz \
113 (op_encode_hdr_maxsz + \
114 3 + (NFS4_VERIFIER_SIZE >> 2))
115 #define decode_setclientid_confirm_maxsz \
116 (op_decode_hdr_maxsz)
117 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
118 1 + ((3 + NFS4_FHSIZE) >> 2))
119 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
121 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
123 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
124 #define encode_link_maxsz (op_encode_hdr_maxsz + \
126 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
127 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
128 1 + nfs4_name_maxsz + \
131 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
132 #define encode_create_maxsz (op_encode_hdr_maxsz + \
133 2 + nfs4_name_maxsz + \
135 #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
136 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
137 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
138 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
139 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
140 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
141 encode_putfh_maxsz + \
142 op_encode_hdr_maxsz + 7)
143 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
144 decode_putfh_maxsz + \
145 op_decode_hdr_maxsz + 2)
146 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
147 encode_putfh_maxsz + \
149 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
150 decode_putfh_maxsz + \
152 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
153 encode_putfh_maxsz + \
154 op_encode_hdr_maxsz + 9)
155 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
156 decode_putfh_maxsz + \
157 op_decode_hdr_maxsz + 2)
158 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
159 encode_putfh_maxsz + \
160 op_encode_hdr_maxsz + 8)
161 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
162 decode_putfh_maxsz + \
163 op_decode_hdr_maxsz + 4)
164 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
165 encode_putfh_maxsz + \
166 op_encode_hdr_maxsz + 3)
167 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
168 decode_putfh_maxsz + \
169 op_decode_hdr_maxsz + 2)
170 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
171 encode_putfh_maxsz + \
172 op_encode_hdr_maxsz + \
174 encode_getattr_maxsz + \
176 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
177 decode_putfh_maxsz + \
178 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
179 decode_getattr_maxsz + \
181 #define NFS4_enc_open_confirm_sz \
182 (compound_encode_hdr_maxsz + \
183 encode_putfh_maxsz + \
184 op_encode_hdr_maxsz + 5)
185 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
186 decode_putfh_maxsz + \
187 op_decode_hdr_maxsz + 4)
188 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
189 encode_putfh_maxsz + \
190 op_encode_hdr_maxsz + \
192 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
193 decode_putfh_maxsz + \
194 op_decode_hdr_maxsz + \
196 #define NFS4_enc_open_downgrade_sz \
197 (compound_encode_hdr_maxsz + \
198 encode_putfh_maxsz + \
199 op_encode_hdr_maxsz + 7)
200 #define NFS4_dec_open_downgrade_sz \
201 (compound_decode_hdr_maxsz + \
202 decode_putfh_maxsz + \
203 op_decode_hdr_maxsz + 4)
204 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
205 encode_putfh_maxsz + \
206 op_encode_hdr_maxsz + 5)
207 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
208 decode_putfh_maxsz + \
209 op_decode_hdr_maxsz + 4)
210 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
211 encode_putfh_maxsz + \
212 op_encode_hdr_maxsz + 4 + \
214 encode_getattr_maxsz)
215 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
216 decode_putfh_maxsz + \
217 op_decode_hdr_maxsz + 3)
218 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
219 encode_putfh_maxsz + \
221 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
222 decode_putfh_maxsz + \
224 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
226 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
228 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
229 encode_setclientid_maxsz)
230 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
231 decode_setclientid_maxsz)
232 #define NFS4_enc_setclientid_confirm_sz \
233 (compound_encode_hdr_maxsz + \
234 encode_setclientid_confirm_maxsz + \
235 encode_putrootfh_maxsz + \
237 #define NFS4_dec_setclientid_confirm_sz \
238 (compound_decode_hdr_maxsz + \
239 decode_setclientid_confirm_maxsz + \
240 decode_putrootfh_maxsz + \
242 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
243 encode_putfh_maxsz + \
244 encode_getattr_maxsz + \
245 op_encode_hdr_maxsz + \
249 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
250 decode_putfh_maxsz + \
251 decode_getattr_maxsz + \
252 op_decode_hdr_maxsz + \
255 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
256 encode_putfh_maxsz + \
257 encode_getattr_maxsz + \
258 op_encode_hdr_maxsz + \
261 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
262 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
263 encode_putfh_maxsz + \
264 encode_getattr_maxsz + \
265 op_encode_hdr_maxsz + \
267 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
268 decode_putfh_maxsz + \
269 decode_getattr_maxsz + \
270 op_decode_hdr_maxsz + 4)
271 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
272 encode_putfh_maxsz + \
273 op_encode_hdr_maxsz + 1)
274 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
275 decode_putfh_maxsz + \
276 op_decode_hdr_maxsz + 2)
277 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
278 encode_putfh_maxsz + \
279 encode_getattr_maxsz)
280 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
281 decode_putfh_maxsz + \
282 decode_getattr_maxsz)
283 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
284 encode_putfh_maxsz + \
285 encode_lookup_maxsz + \
286 encode_getattr_maxsz + \
288 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
289 decode_putfh_maxsz + \
290 op_decode_hdr_maxsz + \
291 decode_getattr_maxsz + \
293 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
294 encode_putrootfh_maxsz + \
295 encode_getattr_maxsz + \
297 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
298 decode_putrootfh_maxsz + \
299 decode_getattr_maxsz + \
301 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
302 encode_putfh_maxsz + \
304 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
305 decode_putfh_maxsz + \
306 op_decode_hdr_maxsz + 5)
307 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
308 encode_putfh_maxsz + \
309 encode_savefh_maxsz + \
310 encode_putfh_maxsz + \
312 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
313 decode_putfh_maxsz + \
314 decode_savefh_maxsz + \
315 decode_putfh_maxsz + \
317 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
318 encode_putfh_maxsz + \
319 encode_savefh_maxsz + \
320 encode_putfh_maxsz + \
322 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
323 decode_putfh_maxsz + \
324 decode_savefh_maxsz + \
325 decode_putfh_maxsz + \
327 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
328 encode_putfh_maxsz + \
329 encode_symlink_maxsz + \
330 encode_getattr_maxsz + \
332 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
333 decode_putfh_maxsz + \
334 decode_symlink_maxsz + \
335 decode_getattr_maxsz + \
337 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
338 encode_putfh_maxsz + \
339 encode_create_maxsz + \
340 encode_getattr_maxsz + \
342 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
343 decode_putfh_maxsz + \
344 decode_create_maxsz + \
345 decode_getattr_maxsz + \
347 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
348 encode_putfh_maxsz + \
349 encode_getattr_maxsz)
350 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
351 decode_putfh_maxsz + \
352 decode_getattr_maxsz)
353 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
354 encode_putfh_maxsz + \
355 encode_getattr_maxsz)
356 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
357 decode_putfh_maxsz + \
358 op_decode_hdr_maxsz + 12)
359 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
360 encode_getattr_maxsz)
361 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
362 decode_getattr_maxsz)
363 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
364 encode_putfh_maxsz + \
365 encode_delegreturn_maxsz)
366 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
367 decode_delegreturn_maxsz)
371 unsigned int nfs2type;
379 { S_IFSOCK, NFSOCK },
385 struct compound_hdr {
393 * START OF "GENERIC" ENCODE ROUTINES.
394 * These may look a little ugly since they are imported from a "generic"
395 * set of XDR encode/decode routines which are intended to be shared by
396 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
398 * If the pain of reading these is too great, it should be a straightforward
399 * task to translate them into Linux-specific versions which are more
400 * consistent with the style used in NFSv2/v3...
402 #define WRITE32(n) *p++ = htonl(n)
403 #define WRITE64(n) do { \
404 *p++ = htonl((uint32_t)((n) >> 32)); \
405 *p++ = htonl((uint32_t)(n)); \
407 #define WRITEMEM(ptr,nbytes) do { \
408 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
411 #define RESERVE_SPACE(nbytes) do { \
412 p = xdr_reserve_space(xdr, nbytes); \
413 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
417 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
421 p = xdr_reserve_space(xdr, 4 + len);
423 xdr_encode_opaque(p, str, len);
426 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
430 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
431 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
432 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
433 WRITE32(hdr->taglen);
434 WRITEMEM(hdr->tag, hdr->taglen);
435 WRITE32(NFS4_MINOR_VERSION);
440 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
444 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
446 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
449 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
451 char owner_name[IDMAP_NAMESZ];
452 char owner_group[IDMAP_NAMESZ];
453 int owner_namelen = 0;
454 int owner_grouplen = 0;
463 * We reserve enough space to write the entire attribute buffer at once.
464 * In the worst-case, this would be
465 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
466 * = 36 bytes, plus any contribution from variable-length fields
467 * such as owner/group/acl's.
472 if (iap->ia_valid & ATTR_SIZE)
474 if (iap->ia_valid & ATTR_MODE)
476 if (iap->ia_valid & ATTR_UID) {
477 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
478 if (owner_namelen < 0) {
479 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
482 strcpy(owner_name, "nobody");
483 owner_namelen = sizeof("nobody") - 1;
486 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
488 if (iap->ia_valid & ATTR_GID) {
489 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
490 if (owner_grouplen < 0) {
491 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
493 strcpy(owner_group, "nobody");
494 owner_grouplen = sizeof("nobody") - 1;
497 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
499 if (iap->ia_valid & ATTR_ATIME_SET)
501 else if (iap->ia_valid & ATTR_ATIME)
503 if (iap->ia_valid & ATTR_MTIME_SET)
505 else if (iap->ia_valid & ATTR_MTIME)
510 * We write the bitmap length now, but leave the bitmap and the attribute
511 * buffer length to be backfilled at the end of this routine.
517 if (iap->ia_valid & ATTR_SIZE) {
518 bmval0 |= FATTR4_WORD0_SIZE;
519 WRITE64(iap->ia_size);
521 if (iap->ia_valid & ATTR_MODE) {
522 bmval1 |= FATTR4_WORD1_MODE;
523 WRITE32(iap->ia_mode);
525 if (iap->ia_valid & ATTR_UID) {
526 bmval1 |= FATTR4_WORD1_OWNER;
527 WRITE32(owner_namelen);
528 WRITEMEM(owner_name, owner_namelen);
530 if (iap->ia_valid & ATTR_GID) {
531 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
532 WRITE32(owner_grouplen);
533 WRITEMEM(owner_group, owner_grouplen);
535 if (iap->ia_valid & ATTR_ATIME_SET) {
536 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
537 WRITE32(NFS4_SET_TO_CLIENT_TIME);
539 WRITE32(iap->ia_mtime.tv_sec);
540 WRITE32(iap->ia_mtime.tv_nsec);
542 else if (iap->ia_valid & ATTR_ATIME) {
543 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
544 WRITE32(NFS4_SET_TO_SERVER_TIME);
546 if (iap->ia_valid & ATTR_MTIME_SET) {
547 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
548 WRITE32(NFS4_SET_TO_CLIENT_TIME);
550 WRITE32(iap->ia_mtime.tv_sec);
551 WRITE32(iap->ia_mtime.tv_nsec);
553 else if (iap->ia_valid & ATTR_MTIME) {
554 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
555 WRITE32(NFS4_SET_TO_SERVER_TIME);
559 * Now we backfill the bitmap and the attribute buffer length.
561 if (len != ((char *)p - (char *)q) + 4) {
562 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
563 len, ((char *)p - (char *)q) + 4);
566 len = (char *)p - (char *)q - 12;
567 *q++ = htonl(bmval0);
568 *q++ = htonl(bmval1);
576 static int encode_access(struct xdr_stream *xdr, u32 access)
587 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
591 RESERVE_SPACE(8+sizeof(arg->stateid.data));
594 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
599 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
605 WRITE64(args->offset);
606 WRITE32(args->count);
611 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
617 WRITE32(create->ftype);
619 switch (create->ftype) {
621 RESERVE_SPACE(4 + create->u.symlink->len);
622 WRITE32(create->u.symlink->len);
623 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
626 case NF4BLK: case NF4CHR:
628 WRITE32(create->u.device.specdata1);
629 WRITE32(create->u.device.specdata2);
636 RESERVE_SPACE(4 + create->name->len);
637 WRITE32(create->name->len);
638 WRITEMEM(create->name->name, create->name->len);
640 return encode_attrs(xdr, create->attrs, create->server);
643 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
654 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
666 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
668 return encode_getattr_two(xdr,
669 bitmask[0] & nfs4_fattr_bitmap[0],
670 bitmask[1] & nfs4_fattr_bitmap[1]);
673 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
675 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
676 bitmask[1] & nfs4_fsinfo_bitmap[1]);
679 static int encode_getfh(struct xdr_stream *xdr)
689 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
693 RESERVE_SPACE(8 + name->len);
696 WRITEMEM(name->name, name->len);
702 * opcode,type,reclaim,offset,length,new_lock_owner = 32
703 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
705 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
708 struct nfs_lock_opargs *opargs = arg->u.lock;
713 WRITE32(opargs->reclaim);
714 WRITE64(arg->offset);
715 WRITE64(arg->length);
716 WRITE32(opargs->new_lock_owner);
717 if (opargs->new_lock_owner){
718 struct nfs_open_to_lock *ol = opargs->u.open_lock;
721 WRITE32(ol->open_seqid);
722 WRITEMEM(&ol->open_stateid, sizeof(ol->open_stateid));
723 WRITE32(ol->lock_seqid);
724 WRITE64(ol->lock_owner.clientid);
726 WRITE32(ol->lock_owner.id);
729 struct nfs_exist_lock *el = opargs->u.exist_lock;
732 WRITEMEM(&el->stateid, sizeof(el->stateid));
739 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
742 struct nfs_lowner *opargs = arg->u.lockt;
747 WRITE64(arg->offset);
748 WRITE64(arg->length);
749 WRITE64(opargs->clientid);
756 static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
759 struct nfs_locku_opargs *opargs = arg->u.locku;
764 WRITE32(opargs->seqid);
765 WRITEMEM(&opargs->stateid, sizeof(opargs->stateid));
766 WRITE64(arg->offset);
767 WRITE64(arg->length);
772 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
777 RESERVE_SPACE(8 + len);
780 WRITEMEM(name->name, len);
785 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
790 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
792 WRITE32(NFS4_SHARE_ACCESS_READ);
795 WRITE32(NFS4_SHARE_ACCESS_WRITE);
797 case FMODE_READ|FMODE_WRITE:
798 WRITE32(NFS4_SHARE_ACCESS_BOTH);
803 WRITE32(0); /* for linux, share_deny = 0 always */
806 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
810 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
816 encode_share_access(xdr, arg->open_flags);
818 WRITE64(arg->clientid);
823 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
828 switch(arg->open_flags & O_EXCL) {
830 WRITE32(NFS4_CREATE_UNCHECKED);
831 encode_attrs(xdr, arg->u.attrs, arg->server);
834 WRITE32(NFS4_CREATE_EXCLUSIVE);
835 encode_nfs4_verifier(xdr, &arg->u.verifier);
839 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
844 switch (arg->open_flags & O_CREAT) {
846 WRITE32(NFS4_OPEN_NOCREATE);
849 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
850 WRITE32(NFS4_OPEN_CREATE);
851 encode_createmode(xdr, arg);
855 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
860 switch (delegation_type) {
862 WRITE32(NFS4_OPEN_DELEGATE_NONE);
865 WRITE32(NFS4_OPEN_DELEGATE_READ);
867 case FMODE_WRITE|FMODE_READ:
868 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
875 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
880 WRITE32(NFS4_OPEN_CLAIM_NULL);
881 encode_string(xdr, name->len, name->name);
884 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
889 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
890 encode_delegation_type(xdr, type);
893 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
897 RESERVE_SPACE(4+sizeof(stateid->data));
898 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
899 WRITEMEM(stateid->data, sizeof(stateid->data));
900 encode_string(xdr, name->len, name->name);
903 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
905 encode_openhdr(xdr, arg);
906 encode_opentype(xdr, arg);
907 switch (arg->claim) {
908 case NFS4_OPEN_CLAIM_NULL:
909 encode_claim_null(xdr, arg->name);
911 case NFS4_OPEN_CLAIM_PREVIOUS:
912 encode_claim_previous(xdr, arg->u.delegation_type);
914 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
915 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
923 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
927 RESERVE_SPACE(8+sizeof(arg->stateid.data));
928 WRITE32(OP_OPEN_CONFIRM);
929 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
935 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
939 RESERVE_SPACE(8+sizeof(arg->stateid.data));
940 WRITE32(OP_OPEN_DOWNGRADE);
941 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
943 encode_share_access(xdr, arg->open_flags);
948 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
953 RESERVE_SPACE(8 + len);
956 WRITEMEM(fh->data, len);
961 static int encode_putrootfh(struct xdr_stream *xdr)
966 WRITE32(OP_PUTROOTFH);
971 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
973 nfs4_stateid stateid;
977 if (ctx->state != NULL) {
978 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
979 WRITEMEM(stateid.data, sizeof(stateid.data));
981 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
984 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
991 encode_stateid(xdr, args->context);
994 WRITE64(args->offset);
995 WRITE32(args->count);
1000 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1002 struct rpc_auth *auth = req->rq_task->tk_auth;
1006 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1007 WRITE32(OP_READDIR);
1008 WRITE64(readdir->cookie);
1009 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1010 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1011 WRITE32(readdir->count);
1013 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) {
1015 WRITE32(FATTR4_WORD1_MOUNTED_ON_FILEID);
1017 WRITE32(FATTR4_WORD0_FILEID);
1021 /* set up reply kvec
1022 * toplevel_status + taglen + rescount + OP_PUTFH + status
1023 * + OP_READDIR + status + verifer(2) = 9
1025 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1026 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1027 readdir->pgbase, readdir->count);
1032 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1034 struct rpc_auth *auth = req->rq_task->tk_auth;
1035 unsigned int replen;
1039 WRITE32(OP_READLINK);
1041 /* set up reply kvec
1042 * toplevel_status + taglen + rescount + OP_PUTFH + status
1043 * + OP_READLINK + status + string length = 8
1045 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1046 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1047 readlink->pgbase, readlink->pglen);
1052 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1056 RESERVE_SPACE(8 + name->len);
1059 WRITEMEM(name->name, name->len);
1064 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1068 RESERVE_SPACE(8 + oldname->len);
1070 WRITE32(oldname->len);
1071 WRITEMEM(oldname->name, oldname->len);
1073 RESERVE_SPACE(4 + newname->len);
1074 WRITE32(newname->len);
1075 WRITEMEM(newname->name, newname->len);
1080 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1086 WRITE64(client_stateid->cl_clientid);
1092 encode_savefh(struct xdr_stream *xdr)
1102 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1107 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1108 WRITE32(OP_SETATTR);
1109 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1111 if ((status = encode_attrs(xdr, arg->iap, server)))
1117 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1121 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1122 WRITE32(OP_SETCLIENTID);
1123 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1125 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1127 WRITE32(setclientid->sc_prog);
1128 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1129 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1131 WRITE32(setclientid->sc_cb_ident);
1136 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1140 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1141 WRITE32(OP_SETCLIENTID_CONFIRM);
1142 WRITE64(client_state->cl_clientid);
1143 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1148 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1155 encode_stateid(xdr, args->context);
1158 WRITE64(args->offset);
1159 WRITE32(args->stable);
1160 WRITE32(args->count);
1162 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1167 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1173 WRITE32(OP_DELEGRETURN);
1174 WRITEMEM(stateid->data, sizeof(stateid->data));
1179 * END OF "GENERIC" ENCODE ROUTINES.
1183 * Encode an ACCESS request
1185 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1187 struct xdr_stream xdr;
1188 struct compound_hdr hdr = {
1193 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1194 encode_compound_hdr(&xdr, &hdr);
1195 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1196 status = encode_access(&xdr, args->access);
1201 * Encode LOOKUP request
1203 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1205 struct xdr_stream xdr;
1206 struct compound_hdr hdr = {
1211 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1212 encode_compound_hdr(&xdr, &hdr);
1213 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1215 if ((status = encode_lookup(&xdr, args->name)) != 0)
1217 if ((status = encode_getfh(&xdr)) != 0)
1219 status = encode_getfattr(&xdr, args->bitmask);
1225 * Encode LOOKUP_ROOT request
1227 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1229 struct xdr_stream xdr;
1230 struct compound_hdr hdr = {
1235 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1236 encode_compound_hdr(&xdr, &hdr);
1237 if ((status = encode_putrootfh(&xdr)) != 0)
1239 if ((status = encode_getfh(&xdr)) == 0)
1240 status = encode_getfattr(&xdr, args->bitmask);
1246 * Encode REMOVE request
1248 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_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_remove(&xdr, args->name);
1264 * Encode RENAME request
1266 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *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 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1278 if ((status = encode_savefh(&xdr)) != 0)
1280 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1282 status = encode_rename(&xdr, args->old_name, args->new_name);
1288 * Encode LINK request
1290 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1292 struct xdr_stream xdr;
1293 struct compound_hdr hdr = {
1298 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1299 encode_compound_hdr(&xdr, &hdr);
1300 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1302 if ((status = encode_savefh(&xdr)) != 0)
1304 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1306 status = encode_link(&xdr, args->name);
1312 * Encode CREATE request
1314 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *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 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1326 if ((status = encode_create(&xdr, args)) != 0)
1328 if ((status = encode_getfh(&xdr)) != 0)
1330 status = encode_getfattr(&xdr, args->bitmask);
1336 * Encode SYMLINK request
1338 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1340 return nfs4_xdr_enc_create(req, p, args);
1344 * Encode GETATTR request
1346 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1348 struct xdr_stream xdr;
1349 struct compound_hdr hdr = {
1354 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1355 encode_compound_hdr(&xdr, &hdr);
1356 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1357 status = encode_getfattr(&xdr, args->bitmask);
1362 * Encode a CLOSE request
1364 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1366 struct xdr_stream xdr;
1367 struct compound_hdr hdr = {
1372 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1373 encode_compound_hdr(&xdr, &hdr);
1374 status = encode_putfh(&xdr, args->fh);
1377 status = encode_close(&xdr, args);
1383 * Encode an OPEN request
1385 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1387 struct xdr_stream xdr;
1388 struct compound_hdr hdr = {
1393 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1394 encode_compound_hdr(&xdr, &hdr);
1395 status = encode_putfh(&xdr, args->fh);
1398 status = encode_open(&xdr, args);
1401 status = encode_getfh(&xdr);
1404 status = encode_getfattr(&xdr, args->bitmask);
1410 * Encode an OPEN_CONFIRM request
1412 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1414 struct xdr_stream xdr;
1415 struct compound_hdr hdr = {
1420 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1421 encode_compound_hdr(&xdr, &hdr);
1422 status = encode_putfh(&xdr, args->fh);
1425 status = encode_open_confirm(&xdr, args);
1431 * Encode an OPEN request with no attributes.
1433 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1435 struct xdr_stream xdr;
1436 struct compound_hdr hdr = {
1441 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1442 encode_compound_hdr(&xdr, &hdr);
1443 status = encode_putfh(&xdr, args->fh);
1446 status = encode_open(&xdr, args);
1452 * Encode an OPEN_DOWNGRADE request
1454 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1456 struct xdr_stream xdr;
1457 struct compound_hdr hdr = {
1462 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1463 encode_compound_hdr(&xdr, &hdr);
1464 status = encode_putfh(&xdr, args->fh);
1467 status = encode_open_downgrade(&xdr, args);
1473 * Encode a LOCK request
1475 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1477 struct xdr_stream xdr;
1478 struct compound_hdr hdr = {
1483 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1484 encode_compound_hdr(&xdr, &hdr);
1485 status = encode_putfh(&xdr, args->fh);
1488 status = encode_lock(&xdr, args);
1494 * Encode a LOCKT request
1496 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1498 struct xdr_stream xdr;
1499 struct compound_hdr hdr = {
1504 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1505 encode_compound_hdr(&xdr, &hdr);
1506 status = encode_putfh(&xdr, args->fh);
1509 status = encode_lockt(&xdr, args);
1515 * Encode a LOCKU request
1517 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1519 struct xdr_stream xdr;
1520 struct compound_hdr hdr = {
1525 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1526 encode_compound_hdr(&xdr, &hdr);
1527 status = encode_putfh(&xdr, args->fh);
1530 status = encode_locku(&xdr, args);
1536 * Encode a READLINK request
1538 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1540 struct xdr_stream xdr;
1541 struct compound_hdr hdr = {
1546 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1547 encode_compound_hdr(&xdr, &hdr);
1548 status = encode_putfh(&xdr, args->fh);
1551 status = encode_readlink(&xdr, args, req);
1557 * Encode a READDIR request
1559 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1561 struct xdr_stream xdr;
1562 struct compound_hdr hdr = {
1567 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1568 encode_compound_hdr(&xdr, &hdr);
1569 status = encode_putfh(&xdr, args->fh);
1572 status = encode_readdir(&xdr, args, req);
1578 * Encode a READ request
1580 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1582 struct rpc_auth *auth = req->rq_task->tk_auth;
1583 struct xdr_stream xdr;
1584 struct compound_hdr hdr = {
1589 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1590 encode_compound_hdr(&xdr, &hdr);
1591 status = encode_putfh(&xdr, args->fh);
1594 status = encode_read(&xdr, args);
1598 /* set up reply kvec
1599 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1600 * + OP_READ + status + eof + datalen = 9
1602 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1603 xdr_inline_pages(&req->rq_rcv_buf, replen,
1604 args->pages, args->pgbase, args->count);
1610 * Encode an SETATTR request
1612 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1615 struct xdr_stream xdr;
1616 struct compound_hdr hdr = {
1621 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1622 encode_compound_hdr(&xdr, &hdr);
1623 status = encode_putfh(&xdr, args->fh);
1626 status = encode_setattr(&xdr, args, args->server);
1629 status = encode_getfattr(&xdr, args->bitmask);
1635 * Encode a WRITE request
1637 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1639 struct xdr_stream xdr;
1640 struct compound_hdr hdr = {
1645 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1646 encode_compound_hdr(&xdr, &hdr);
1647 status = encode_putfh(&xdr, args->fh);
1650 status = encode_write(&xdr, args);
1658 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1660 struct xdr_stream xdr;
1661 struct compound_hdr hdr = {
1666 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1667 encode_compound_hdr(&xdr, &hdr);
1668 status = encode_putfh(&xdr, args->fh);
1671 status = encode_commit(&xdr, args);
1679 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1681 struct xdr_stream xdr;
1682 struct compound_hdr hdr = {
1687 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1688 encode_compound_hdr(&xdr, &hdr);
1689 status = encode_putfh(&xdr, args->fh);
1691 status = encode_fsinfo(&xdr, args->bitmask);
1696 * a PATHCONF request
1698 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1700 struct xdr_stream xdr;
1701 struct compound_hdr hdr = {
1706 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1707 encode_compound_hdr(&xdr, &hdr);
1708 status = encode_putfh(&xdr, args->fh);
1710 status = encode_getattr_one(&xdr,
1711 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1718 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1720 struct xdr_stream xdr;
1721 struct compound_hdr hdr = {
1726 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1727 encode_compound_hdr(&xdr, &hdr);
1728 status = encode_putfh(&xdr, args->fh);
1730 status = encode_getattr_two(&xdr,
1731 args->bitmask[0] & nfs4_statfs_bitmap[0],
1732 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1737 * GETATTR_BITMAP request
1739 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1741 struct xdr_stream xdr;
1742 struct compound_hdr hdr = {
1747 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1748 encode_compound_hdr(&xdr, &hdr);
1749 status = encode_putfh(&xdr, fhandle);
1751 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1752 FATTR4_WORD0_LINK_SUPPORT|
1753 FATTR4_WORD0_SYMLINK_SUPPORT|
1754 FATTR4_WORD0_ACLSUPPORT);
1761 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1763 struct xdr_stream xdr;
1764 struct compound_hdr hdr = {
1768 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1769 encode_compound_hdr(&xdr, &hdr);
1770 return encode_renew(&xdr, clp);
1774 * a SETCLIENTID request
1776 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1778 struct xdr_stream xdr;
1779 struct compound_hdr hdr = {
1783 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1784 encode_compound_hdr(&xdr, &hdr);
1785 return encode_setclientid(&xdr, sc);
1789 * a SETCLIENTID_CONFIRM request
1791 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1793 struct xdr_stream xdr;
1794 struct compound_hdr hdr = {
1797 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1800 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1801 encode_compound_hdr(&xdr, &hdr);
1802 status = encode_setclientid_confirm(&xdr, clp);
1804 status = encode_putrootfh(&xdr);
1806 status = encode_fsinfo(&xdr, lease_bitmap);
1811 * DELEGRETURN request
1813 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1815 struct xdr_stream xdr;
1816 struct compound_hdr hdr = {
1821 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1822 encode_compound_hdr(&xdr, &hdr);
1823 if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
1824 status = encode_delegreturn(&xdr, args->stateid);
1829 * START OF "GENERIC" DECODE ROUTINES.
1830 * These may look a little ugly since they are imported from a "generic"
1831 * set of XDR encode/decode routines which are intended to be shared by
1832 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1834 * If the pain of reading these is too great, it should be a straightforward
1835 * task to translate them into Linux-specific versions which are more
1836 * consistent with the style used in NFSv2/v3...
1838 #define READ32(x) (x) = ntohl(*p++)
1839 #define READ64(x) do { \
1840 (x) = (u64)ntohl(*p++) << 32; \
1841 (x) |= ntohl(*p++); \
1843 #define READTIME(x) do { \
1845 (x.tv_sec) = ntohl(*p++); \
1846 (x.tv_nsec) = ntohl(*p++); \
1848 #define COPYMEM(x,nbytes) do { \
1849 memcpy((x), p, nbytes); \
1850 p += XDR_QUADLEN(nbytes); \
1853 #define READ_BUF(nbytes) do { \
1854 p = xdr_inline_decode(xdr, nbytes); \
1856 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
1857 __FUNCTION__, __LINE__); \
1862 static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
1869 *string = (char *)p;
1873 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
1878 READ32(hdr->status);
1879 READ32(hdr->taglen);
1881 READ_BUF(hdr->taglen + 4);
1882 hdr->tag = (char *)p;
1883 p += XDR_QUADLEN(hdr->taglen);
1888 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
1896 if (opnum != expected) {
1898 "nfs4_decode_op_hdr: Server returned operation"
1899 " %d but we issued a request for %d\n",
1904 if (nfserr != NFS_OK)
1905 return -nfs_stat_to_errno(nfserr);
1910 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
1917 return decode_opaque_inline(xdr, &strlen, &str);
1920 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
1927 bitmap[0] = bitmap[1] = 0;
1928 READ_BUF((bmlen << 2));
1937 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
1947 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
1949 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
1950 decode_attr_bitmap(xdr, bitmask);
1951 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
1953 bitmask[0] = bitmask[1] = 0;
1954 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
1958 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
1963 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
1965 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
1968 if (*type < NF4REG || *type > NF4NAMEDATTR) {
1969 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
1972 bitmap[0] &= ~FATTR4_WORD0_TYPE;
1974 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
1978 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
1983 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
1985 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
1988 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
1990 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
1991 (unsigned long long)*change);
1995 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2000 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2002 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2005 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2007 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2011 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2016 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2018 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2021 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2023 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2027 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2032 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2034 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2037 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2039 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2043 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2049 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2051 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2053 READ64(fsid->major);
2054 READ64(fsid->minor);
2055 bitmap[0] &= ~FATTR4_WORD0_FSID;
2057 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2058 (unsigned long long)fsid->major,
2059 (unsigned long long)fsid->minor);
2063 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2068 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2070 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2073 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2075 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2079 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2083 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2084 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2086 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2089 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2091 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2095 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2100 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2102 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2105 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2107 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2111 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2117 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2119 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2122 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2124 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2128 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2134 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2136 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2139 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2141 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2145 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2151 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2153 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2156 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2158 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2162 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2168 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2170 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2173 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2175 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2179 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2185 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2187 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2190 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2192 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2196 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2202 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2204 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2207 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2209 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2213 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2219 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2221 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2225 if (maxread > 0x7FFFFFFF)
2226 maxread = 0x7FFFFFFF;
2227 *res = (uint32_t)maxread;
2228 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2230 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2234 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2240 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2242 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2246 if (maxwrite > 0x7FFFFFFF)
2247 maxwrite = 0x7FFFFFFF;
2248 *res = (uint32_t)maxwrite;
2249 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2251 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2255 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2260 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2262 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2266 bitmap[1] &= ~FATTR4_WORD1_MODE;
2268 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2272 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2277 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2279 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2282 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2284 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2288 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2293 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2295 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2299 if (len < XDR_MAX_NETOBJ) {
2300 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2301 dprintk("%s: nfs_map_name_to_uid failed!\n",
2304 printk(KERN_WARNING "%s: name too long (%u)!\n",
2306 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2308 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2312 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2317 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2319 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2323 if (len < XDR_MAX_NETOBJ) {
2324 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2325 dprintk("%s: nfs_map_group_to_gid failed!\n",
2328 printk(KERN_WARNING "%s: name too long (%u)!\n",
2330 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2332 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2336 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2338 uint32_t major = 0, minor = 0, *p;
2341 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2343 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2349 tmp = MKDEV(major, minor);
2350 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2352 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2354 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2358 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2364 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2366 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2369 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2371 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2375 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2381 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2383 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2386 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2388 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2392 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2398 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2400 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2403 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2405 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2409 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2414 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2416 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2419 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2421 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2422 (unsigned long long)*used);
2426 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2435 time->tv_sec = (time_t)sec;
2436 time->tv_nsec = (long)nsec;
2440 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2446 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2448 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2449 status = decode_attr_time(xdr, time);
2450 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2452 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2456 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2462 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2464 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2465 status = decode_attr_time(xdr, time);
2466 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2468 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2472 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2478 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2480 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2481 status = decode_attr_time(xdr, time);
2482 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2484 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2488 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2490 unsigned int attrwords = XDR_QUADLEN(attrlen);
2491 unsigned int nwords = xdr->p - savep;
2493 if (unlikely(attrwords != nwords)) {
2494 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2497 (attrwords < nwords) ? '<' : '>',
2504 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2509 READ32(cinfo->atomic);
2510 READ64(cinfo->before);
2511 READ64(cinfo->after);
2515 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2521 status = decode_op_hdr(xdr, OP_ACCESS);
2527 access->supported = supp;
2528 access->access = acc;
2532 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2537 status = decode_op_hdr(xdr, OP_CLOSE);
2540 READ_BUF(sizeof(res->stateid.data));
2541 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2545 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2550 status = decode_op_hdr(xdr, OP_COMMIT);
2554 COPYMEM(res->verf->verifier, 8);
2558 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2564 status = decode_op_hdr(xdr, OP_CREATE);
2567 if ((status = decode_change_info(xdr, cinfo)))
2571 READ_BUF(bmlen << 2);
2575 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2582 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2584 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2586 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2588 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2590 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2592 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2594 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2596 status = verify_attr_len(xdr, savep, attrlen);
2599 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2603 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2610 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2612 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2614 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2617 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2619 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2621 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2623 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2625 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2627 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2630 status = verify_attr_len(xdr, savep, attrlen);
2633 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2637 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2644 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2646 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2648 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2651 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2653 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2656 status = verify_attr_len(xdr, savep, attrlen);
2659 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2663 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2669 int status, fmode = 0;
2671 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2673 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2676 fattr->bitmap[0] = bitmap[0];
2677 fattr->bitmap[1] = bitmap[1];
2679 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2683 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2685 fattr->type = nfs_type2fmt[type].nfs2type;
2686 fmode = nfs_type2fmt[type].mode;
2688 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2690 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2692 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2694 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2696 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2698 fattr->mode |= fmode;
2699 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2701 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2703 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2705 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2707 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2709 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2711 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2713 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2715 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) {
2716 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2717 fattr->timestamp = jiffies;
2721 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2726 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2729 uint32_t attrlen, bitmap[2];
2732 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2734 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2736 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2739 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2741 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2743 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2745 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2747 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2748 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2750 fsinfo->wtpref = fsinfo->wtmax;
2752 status = verify_attr_len(xdr, savep, attrlen);
2755 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2759 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2765 status = decode_op_hdr(xdr, OP_GETFH);
2768 /* Zero handle first to allow comparisons */
2769 memset(fh, 0, sizeof(*fh));
2773 if (len > NFS4_FHSIZE)
2777 COPYMEM(fh->data, len);
2781 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2785 status = decode_op_hdr(xdr, OP_LINK);
2788 return decode_change_info(xdr, cinfo);
2792 * We create the owner, so we know a proper owner.id length is 4.
2794 static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2800 READ64(denied->offset);
2801 READ64(denied->length);
2802 READ32(denied->type);
2803 READ64(denied->owner.clientid);
2807 READ32(denied->owner.id);
2808 return -NFS4ERR_DENIED;
2811 static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2816 status = decode_op_hdr(xdr, OP_LOCK);
2818 READ_BUF(sizeof(nfs4_stateid));
2819 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2820 } else if (status == -NFS4ERR_DENIED)
2821 return decode_lock_denied(xdr, &res->u.denied);
2825 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2828 status = decode_op_hdr(xdr, OP_LOCKT);
2829 if (status == -NFS4ERR_DENIED)
2830 return decode_lock_denied(xdr, &res->u.denied);
2834 static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2839 status = decode_op_hdr(xdr, OP_LOCKU);
2841 READ_BUF(sizeof(nfs4_stateid));
2842 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2847 static int decode_lookup(struct xdr_stream *xdr)
2849 return decode_op_hdr(xdr, OP_LOOKUP);
2852 /* This is too sick! */
2853 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
2856 uint32_t limit_type, nblocks, blocksize;
2860 switch (limit_type) {
2867 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
2872 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
2875 uint32_t delegation_type;
2878 READ32(delegation_type);
2879 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
2880 res->delegation_type = 0;
2884 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
2885 READ32(res->do_recall);
2886 switch (delegation_type) {
2887 case NFS4_OPEN_DELEGATE_READ:
2888 res->delegation_type = FMODE_READ;
2890 case NFS4_OPEN_DELEGATE_WRITE:
2891 res->delegation_type = FMODE_WRITE|FMODE_READ;
2892 if (decode_space_limit(xdr, &res->maxsize) < 0)
2895 return decode_ace(xdr, NULL, res->server->nfs4_state);
2898 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
2904 status = decode_op_hdr(xdr, OP_OPEN);
2907 READ_BUF(sizeof(res->stateid.data));
2908 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2910 decode_change_info(xdr, &res->cinfo);
2913 READ32(res->rflags);
2918 READ_BUF(bmlen << 2);
2920 return decode_delegation(xdr, res);
2922 printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
2926 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
2931 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
2934 READ_BUF(sizeof(res->stateid.data));
2935 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2939 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
2944 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
2947 READ_BUF(sizeof(res->stateid.data));
2948 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2952 static int decode_putfh(struct xdr_stream *xdr)
2954 return decode_op_hdr(xdr, OP_PUTFH);
2957 static int decode_putrootfh(struct xdr_stream *xdr)
2959 return decode_op_hdr(xdr, OP_PUTROOTFH);
2962 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
2964 struct kvec *iov = req->rq_rcv_buf.head;
2966 uint32_t count, eof, recvd, hdrlen;
2969 status = decode_op_hdr(xdr, OP_READ);
2975 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
2976 recvd = req->rq_rcv_buf.len - hdrlen;
2977 if (count > recvd) {
2978 printk(KERN_WARNING "NFS: server cheating in read reply: "
2979 "count %u > recvd %u\n", count, recvd);
2983 xdr_read_pages(xdr, count);
2989 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
2991 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
2992 struct page *page = *rcvbuf->pages;
2993 struct kvec *iov = rcvbuf->head;
2994 unsigned int nr, pglen = rcvbuf->page_len;
2995 uint32_t *end, *entry, *p, *kaddr;
2996 uint32_t len, attrlen;
2997 int hdrlen, recvd, status;
2999 status = decode_op_hdr(xdr, OP_READDIR);
3003 COPYMEM(readdir->verifier.data, 8);
3005 hdrlen = (char *) p - (char *) iov->iov_base;
3006 recvd = rcvbuf->len - hdrlen;
3009 xdr_read_pages(xdr, pglen);
3011 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3012 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3013 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3015 for (nr = 0; *p++; nr++) {
3018 p += 2; /* cookie */
3019 len = ntohl(*p++); /* filename length */
3020 if (len > NFS4_MAXNAMLEN) {
3021 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3024 p += XDR_QUADLEN(len);
3027 len = ntohl(*p++); /* bitmap length */
3031 attrlen = XDR_QUADLEN(ntohl(*p++));
3032 p += attrlen; /* attributes */
3037 if (!nr && (entry[0] != 0 || entry[1] == 0))
3040 kunmap_atomic(kaddr, KM_USER0);
3043 entry[0] = entry[1] = 0;
3044 /* truncate listing ? */
3046 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3051 kunmap_atomic(kaddr, KM_USER0);
3052 return -errno_NFSERR_IO;
3055 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3057 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3058 struct kvec *iov = rcvbuf->head;
3059 int hdrlen, len, recvd;
3064 status = decode_op_hdr(xdr, OP_READLINK);
3068 /* Convert length of symlink */
3071 if (len >= rcvbuf->page_len || len <= 0) {
3072 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3073 return -ENAMETOOLONG;
3075 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3076 recvd = req->rq_rcv_buf.len - hdrlen;
3078 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3079 "count %u > recvd %u\n", len, recvd);
3082 xdr_read_pages(xdr, len);
3084 * The XDR encode routine has set things up so that
3085 * the link text will be copied directly into the
3086 * buffer. We just have to do overflow-checking,
3087 * and and null-terminate the text (the VFS expects
3088 * null-termination).
3090 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3091 kaddr[len+rcvbuf->page_base] = '\0';
3092 kunmap_atomic(kaddr, KM_USER0);
3096 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3100 status = decode_op_hdr(xdr, OP_REMOVE);
3103 status = decode_change_info(xdr, cinfo);
3108 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3109 struct nfs4_change_info *new_cinfo)
3113 status = decode_op_hdr(xdr, OP_RENAME);
3116 if ((status = decode_change_info(xdr, old_cinfo)))
3118 status = decode_change_info(xdr, new_cinfo);
3123 static int decode_renew(struct xdr_stream *xdr)
3125 return decode_op_hdr(xdr, OP_RENEW);
3129 decode_savefh(struct xdr_stream *xdr)
3131 return decode_op_hdr(xdr, OP_SAVEFH);
3134 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3141 status = decode_op_hdr(xdr, OP_SETATTR);
3146 READ_BUF(bmlen << 2);
3150 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3158 if (opnum != OP_SETCLIENTID) {
3160 "nfs4_decode_setclientid: Server returned operation"
3165 if (nfserr == NFS_OK) {
3166 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3167 READ64(clp->cl_clientid);
3168 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3169 } else if (nfserr == NFSERR_CLID_INUSE) {
3172 /* skip netid string */
3177 /* skip uaddr string */
3181 return -NFSERR_CLID_INUSE;
3183 return -nfs_stat_to_errno(nfserr);
3188 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3190 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3193 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3198 status = decode_op_hdr(xdr, OP_WRITE);
3204 READ32(res->verf->committed);
3205 COPYMEM(res->verf->verifier, 8);
3209 static int decode_delegreturn(struct xdr_stream *xdr)
3211 return decode_op_hdr(xdr, OP_DELEGRETURN);
3215 * Decode OPEN_DOWNGRADE response
3217 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3219 struct xdr_stream xdr;
3220 struct compound_hdr hdr;
3223 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3224 status = decode_compound_hdr(&xdr, &hdr);
3227 status = decode_putfh(&xdr);
3230 status = decode_open_downgrade(&xdr, res);
3236 * END OF "GENERIC" DECODE ROUTINES.
3240 * Decode ACCESS response
3242 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3244 struct xdr_stream xdr;
3245 struct compound_hdr hdr;
3248 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3249 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3251 if ((status = decode_putfh(&xdr)) == 0)
3252 status = decode_access(&xdr, res);
3258 * Decode LOOKUP response
3260 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3262 struct xdr_stream xdr;
3263 struct compound_hdr hdr;
3266 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3267 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3269 if ((status = decode_putfh(&xdr)) != 0)
3271 if ((status = decode_lookup(&xdr)) != 0)
3273 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3275 status = decode_getfattr(&xdr, res->fattr, res->server);
3281 * Decode LOOKUP_ROOT response
3283 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3285 struct xdr_stream xdr;
3286 struct compound_hdr hdr;
3289 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3290 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3292 if ((status = decode_putrootfh(&xdr)) != 0)
3294 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3295 status = decode_getfattr(&xdr, res->fattr, res->server);
3301 * Decode REMOVE response
3303 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3305 struct xdr_stream xdr;
3306 struct compound_hdr hdr;
3309 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3310 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3312 if ((status = decode_putfh(&xdr)) == 0)
3313 status = decode_remove(&xdr, cinfo);
3319 * Decode RENAME response
3321 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3323 struct xdr_stream xdr;
3324 struct compound_hdr hdr;
3327 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3328 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3330 if ((status = decode_putfh(&xdr)) != 0)
3332 if ((status = decode_savefh(&xdr)) != 0)
3334 if ((status = decode_putfh(&xdr)) != 0)
3336 status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
3342 * Decode LINK response
3344 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3346 struct xdr_stream xdr;
3347 struct compound_hdr hdr;
3350 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3351 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3353 if ((status = decode_putfh(&xdr)) != 0)
3355 if ((status = decode_savefh(&xdr)) != 0)
3357 if ((status = decode_putfh(&xdr)) != 0)
3359 status = decode_link(&xdr, cinfo);
3365 * Decode CREATE response
3367 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3369 struct xdr_stream xdr;
3370 struct compound_hdr hdr;
3373 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3374 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3376 if ((status = decode_putfh(&xdr)) != 0)
3378 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3380 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3382 status = decode_getfattr(&xdr, res->fattr, res->server);
3383 if (status == NFS4ERR_DELAY)
3390 * Decode SYMLINK response
3392 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3394 return nfs4_xdr_dec_create(rqstp, p, res);
3398 * Decode GETATTR response
3400 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3402 struct xdr_stream xdr;
3403 struct compound_hdr hdr;
3406 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3407 status = decode_compound_hdr(&xdr, &hdr);
3410 status = decode_putfh(&xdr);
3413 status = decode_getfattr(&xdr, res->fattr, res->server);
3421 * Decode CLOSE response
3423 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3425 struct xdr_stream xdr;
3426 struct compound_hdr hdr;
3429 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3430 status = decode_compound_hdr(&xdr, &hdr);
3433 status = decode_putfh(&xdr);
3436 status = decode_close(&xdr, res);
3442 * Decode OPEN response
3444 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3446 struct xdr_stream xdr;
3447 struct compound_hdr hdr;
3450 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3451 status = decode_compound_hdr(&xdr, &hdr);
3454 status = decode_putfh(&xdr);
3457 status = decode_open(&xdr, res);
3460 status = decode_getfh(&xdr, &res->fh);
3463 status = decode_getfattr(&xdr, res->f_attr, res->server);
3464 if (status == NFS4ERR_DELAY)
3471 * Decode OPEN_CONFIRM response
3473 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3475 struct xdr_stream xdr;
3476 struct compound_hdr hdr;
3479 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3480 status = decode_compound_hdr(&xdr, &hdr);
3483 status = decode_putfh(&xdr);
3486 status = decode_open_confirm(&xdr, res);
3492 * Decode OPEN response
3494 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *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_open(&xdr, res);
3513 * Decode SETATTR response
3515 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3517 struct xdr_stream xdr;
3518 struct compound_hdr hdr;
3521 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3522 status = decode_compound_hdr(&xdr, &hdr);
3525 status = decode_putfh(&xdr);
3528 status = decode_setattr(&xdr, res);
3531 status = decode_getfattr(&xdr, res->fattr, res->server);
3532 if (status == NFS4ERR_DELAY)
3539 * Decode LOCK response
3541 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3543 struct xdr_stream xdr;
3544 struct compound_hdr hdr;
3547 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3548 status = decode_compound_hdr(&xdr, &hdr);
3551 status = decode_putfh(&xdr);
3554 status = decode_lock(&xdr, res);
3560 * Decode LOCKT response
3562 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3564 struct xdr_stream xdr;
3565 struct compound_hdr hdr;
3568 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3569 status = decode_compound_hdr(&xdr, &hdr);
3572 status = decode_putfh(&xdr);
3575 status = decode_lockt(&xdr, res);
3581 * Decode LOCKU response
3583 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3585 struct xdr_stream xdr;
3586 struct compound_hdr hdr;
3589 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3590 status = decode_compound_hdr(&xdr, &hdr);
3593 status = decode_putfh(&xdr);
3596 status = decode_locku(&xdr, res);
3602 * Decode READLINK response
3604 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3606 struct xdr_stream xdr;
3607 struct compound_hdr hdr;
3610 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3611 status = decode_compound_hdr(&xdr, &hdr);
3614 status = decode_putfh(&xdr);
3617 status = decode_readlink(&xdr, rqstp);
3623 * Decode READDIR response
3625 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3627 struct xdr_stream xdr;
3628 struct compound_hdr hdr;
3631 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3632 status = decode_compound_hdr(&xdr, &hdr);
3635 status = decode_putfh(&xdr);
3638 status = decode_readdir(&xdr, rqstp, res);
3644 * Decode Read response
3646 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3648 struct xdr_stream xdr;
3649 struct compound_hdr hdr;
3652 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3653 status = decode_compound_hdr(&xdr, &hdr);
3656 status = decode_putfh(&xdr);
3659 status = decode_read(&xdr, rqstp, res);
3661 status = res->count;
3667 * Decode WRITE response
3669 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3671 struct xdr_stream xdr;
3672 struct compound_hdr hdr;
3675 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3676 status = decode_compound_hdr(&xdr, &hdr);
3679 status = decode_putfh(&xdr);
3682 status = decode_write(&xdr, res);
3684 status = res->count;
3690 * Decode COMMIT response
3692 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3694 struct xdr_stream xdr;
3695 struct compound_hdr hdr;
3698 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3699 status = decode_compound_hdr(&xdr, &hdr);
3702 status = decode_putfh(&xdr);
3705 status = decode_commit(&xdr, res);
3713 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3715 struct xdr_stream xdr;
3716 struct compound_hdr hdr;
3719 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3720 status = decode_compound_hdr(&xdr, &hdr);
3722 status = decode_putfh(&xdr);
3724 status = decode_fsinfo(&xdr, fsinfo);
3726 status = -nfs_stat_to_errno(hdr.status);
3733 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
3735 struct xdr_stream xdr;
3736 struct compound_hdr hdr;
3739 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3740 status = decode_compound_hdr(&xdr, &hdr);
3742 status = decode_putfh(&xdr);
3744 status = decode_pathconf(&xdr, pathconf);
3751 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
3753 struct xdr_stream xdr;
3754 struct compound_hdr hdr;
3757 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3758 status = decode_compound_hdr(&xdr, &hdr);
3760 status = decode_putfh(&xdr);
3762 status = decode_statfs(&xdr, fsstat);
3767 * GETATTR_BITMAP request
3769 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
3771 struct xdr_stream xdr;
3772 struct compound_hdr hdr;
3775 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3776 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3778 if ((status = decode_putfh(&xdr)) != 0)
3780 status = decode_server_caps(&xdr, res);
3786 * Decode RENEW response
3788 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3790 struct xdr_stream xdr;
3791 struct compound_hdr hdr;
3794 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3795 status = decode_compound_hdr(&xdr, &hdr);
3797 status = decode_renew(&xdr);
3802 * a SETCLIENTID request
3804 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
3805 struct nfs4_client *clp)
3807 struct xdr_stream xdr;
3808 struct compound_hdr hdr;
3811 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3812 status = decode_compound_hdr(&xdr, &hdr);
3814 status = decode_setclientid(&xdr, clp);
3816 status = -nfs_stat_to_errno(hdr.status);
3821 * a SETCLIENTID_CONFIRM request
3823 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3825 struct xdr_stream xdr;
3826 struct compound_hdr hdr;
3829 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3830 status = decode_compound_hdr(&xdr, &hdr);
3832 status = decode_setclientid_confirm(&xdr);
3834 status = decode_putrootfh(&xdr);
3836 status = decode_fsinfo(&xdr, fsinfo);
3838 status = -nfs_stat_to_errno(hdr.status);
3843 * DELEGRETURN request
3845 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3847 struct xdr_stream xdr;
3848 struct compound_hdr hdr;
3851 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3852 status = decode_compound_hdr(&xdr, &hdr);
3854 status = decode_putfh(&xdr);
3856 status = decode_delegreturn(&xdr);
3861 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
3863 uint32_t bitmap[2] = {0};
3868 return ERR_PTR(-EAGAIN);
3870 return ERR_PTR(-EBADCOOKIE);
3873 entry->prev_cookie = entry->cookie;
3874 p = xdr_decode_hyper(p, &entry->cookie);
3875 entry->len = ntohl(*p++);
3876 entry->name = (const char *) p;
3877 p += XDR_QUADLEN(entry->len);
3880 * In case the server doesn't return an inode number,
3881 * we fake one here. (We don't use inode number 0,
3882 * since glibc seems to choke on it...)
3886 len = ntohl(*p++); /* bitmap length */
3888 bitmap[0] = ntohl(*p++);
3890 bitmap[1] = ntohl(*p++);
3894 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
3896 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
3897 xdr_decode_hyper(p, &entry->ino);
3898 else if (bitmap[0] == FATTR4_WORD0_FILEID)
3899 xdr_decode_hyper(p, &entry->ino);
3903 entry->eof = !p[0] && p[1];
3908 * We need to translate between nfs status return values and
3909 * the local errno values which may not be the same.
3916 { NFS4ERR_PERM, EPERM },
3917 { NFS4ERR_NOENT, ENOENT },
3918 { NFS4ERR_IO, errno_NFSERR_IO },
3919 { NFS4ERR_NXIO, ENXIO },
3920 { NFS4ERR_ACCESS, EACCES },
3921 { NFS4ERR_EXIST, EEXIST },
3922 { NFS4ERR_XDEV, EXDEV },
3923 { NFS4ERR_NOTDIR, ENOTDIR },
3924 { NFS4ERR_ISDIR, EISDIR },
3925 { NFS4ERR_INVAL, EINVAL },
3926 { NFS4ERR_FBIG, EFBIG },
3927 { NFS4ERR_NOSPC, ENOSPC },
3928 { NFS4ERR_ROFS, EROFS },
3929 { NFS4ERR_MLINK, EMLINK },
3930 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
3931 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
3932 { NFS4ERR_DQUOT, EDQUOT },
3933 { NFS4ERR_STALE, ESTALE },
3934 { NFS4ERR_BADHANDLE, EBADHANDLE },
3935 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
3936 { NFS4ERR_NOTSUPP, ENOTSUPP },
3937 { NFS4ERR_TOOSMALL, ETOOSMALL },
3938 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
3939 { NFS4ERR_BADTYPE, EBADTYPE },
3940 { NFS4ERR_LOCKED, EAGAIN },
3941 { NFS4ERR_RESOURCE, EREMOTEIO },
3942 { NFS4ERR_SYMLINK, ELOOP },
3943 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
3944 { NFS4ERR_DEADLOCK, EDEADLK },
3945 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
3946 * to be handled by a
3953 * Convert an NFS error code to a local one.
3954 * This one is used jointly by NFSv2 and NFSv3.
3957 nfs_stat_to_errno(int stat)
3960 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
3961 if (nfs_errtbl[i].stat == stat)
3962 return nfs_errtbl[i].errno;
3964 if (stat <= 10000 || stat > 10100) {
3965 /* The server is looney tunes. */
3966 return ESERVERFAULT;
3968 /* If we cannot translate the error, the recovery routines should
3970 * Note: remaining NFSv4 error codes have values > 10000, so should
3971 * not conflict with native Linux error codes.
3977 # define MAX(a, b) (((a) > (b))? (a) : (b))
3980 #define PROC(proc, argtype, restype) \
3981 [NFSPROC4_CLNT_##proc] = { \
3982 .p_proc = NFSPROC4_COMPOUND, \
3983 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
3984 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
3985 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
3988 struct rpc_procinfo nfs4_procedures[] = {
3989 PROC(READ, enc_read, dec_read),
3990 PROC(WRITE, enc_write, dec_write),
3991 PROC(COMMIT, enc_commit, dec_commit),
3992 PROC(OPEN, enc_open, dec_open),
3993 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
3994 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
3995 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
3996 PROC(CLOSE, enc_close, dec_close),
3997 PROC(SETATTR, enc_setattr, dec_setattr),
3998 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
3999 PROC(RENEW, enc_renew, dec_renew),
4000 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4001 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4002 PROC(LOCK, enc_lock, dec_lock),
4003 PROC(LOCKT, enc_lockt, dec_lockt),
4004 PROC(LOCKU, enc_locku, dec_locku),
4005 PROC(ACCESS, enc_access, dec_access),
4006 PROC(GETATTR, enc_getattr, dec_getattr),
4007 PROC(LOOKUP, enc_lookup, dec_lookup),
4008 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4009 PROC(REMOVE, enc_remove, dec_remove),
4010 PROC(RENAME, enc_rename, dec_rename),
4011 PROC(LINK, enc_link, dec_link),
4012 PROC(SYMLINK, enc_symlink, dec_symlink),
4013 PROC(CREATE, enc_create, dec_create),
4014 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4015 PROC(STATFS, enc_statfs, dec_statfs),
4016 PROC(READLINK, enc_readlink, dec_readlink),
4017 PROC(READDIR, enc_readdir, dec_readdir),
4018 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4019 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4022 struct rpc_version nfs_version4 = {
4024 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
4025 .procs = nfs4_procedures