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)
368 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
369 encode_putfh_maxsz + \
370 encode_getattr_maxsz)
371 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
372 decode_putfh_maxsz + \
373 op_decode_hdr_maxsz + \
374 nfs4_fattr_bitmap_maxsz + 1)
378 unsigned int nfs2type;
386 { S_IFSOCK, NFSOCK },
392 struct compound_hdr {
400 * START OF "GENERIC" ENCODE ROUTINES.
401 * These may look a little ugly since they are imported from a "generic"
402 * set of XDR encode/decode routines which are intended to be shared by
403 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
405 * If the pain of reading these is too great, it should be a straightforward
406 * task to translate them into Linux-specific versions which are more
407 * consistent with the style used in NFSv2/v3...
409 #define WRITE32(n) *p++ = htonl(n)
410 #define WRITE64(n) do { \
411 *p++ = htonl((uint32_t)((n) >> 32)); \
412 *p++ = htonl((uint32_t)(n)); \
414 #define WRITEMEM(ptr,nbytes) do { \
415 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
418 #define RESERVE_SPACE(nbytes) do { \
419 p = xdr_reserve_space(xdr, nbytes); \
420 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
424 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
428 p = xdr_reserve_space(xdr, 4 + len);
430 xdr_encode_opaque(p, str, len);
433 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
437 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
438 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
439 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
440 WRITE32(hdr->taglen);
441 WRITEMEM(hdr->tag, hdr->taglen);
442 WRITE32(NFS4_MINOR_VERSION);
447 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
451 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
453 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
456 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
458 char owner_name[IDMAP_NAMESZ];
459 char owner_group[IDMAP_NAMESZ];
460 int owner_namelen = 0;
461 int owner_grouplen = 0;
470 * We reserve enough space to write the entire attribute buffer at once.
471 * In the worst-case, this would be
472 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
473 * = 36 bytes, plus any contribution from variable-length fields
474 * such as owner/group/acl's.
479 if (iap->ia_valid & ATTR_SIZE)
481 if (iap->ia_valid & ATTR_MODE)
483 if (iap->ia_valid & ATTR_UID) {
484 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
485 if (owner_namelen < 0) {
486 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
489 strcpy(owner_name, "nobody");
490 owner_namelen = sizeof("nobody") - 1;
493 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
495 if (iap->ia_valid & ATTR_GID) {
496 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
497 if (owner_grouplen < 0) {
498 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
500 strcpy(owner_group, "nobody");
501 owner_grouplen = sizeof("nobody") - 1;
504 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
506 if (iap->ia_valid & ATTR_ATIME_SET)
508 else if (iap->ia_valid & ATTR_ATIME)
510 if (iap->ia_valid & ATTR_MTIME_SET)
512 else if (iap->ia_valid & ATTR_MTIME)
517 * We write the bitmap length now, but leave the bitmap and the attribute
518 * buffer length to be backfilled at the end of this routine.
524 if (iap->ia_valid & ATTR_SIZE) {
525 bmval0 |= FATTR4_WORD0_SIZE;
526 WRITE64(iap->ia_size);
528 if (iap->ia_valid & ATTR_MODE) {
529 bmval1 |= FATTR4_WORD1_MODE;
530 WRITE32(iap->ia_mode);
532 if (iap->ia_valid & ATTR_UID) {
533 bmval1 |= FATTR4_WORD1_OWNER;
534 WRITE32(owner_namelen);
535 WRITEMEM(owner_name, owner_namelen);
537 if (iap->ia_valid & ATTR_GID) {
538 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
539 WRITE32(owner_grouplen);
540 WRITEMEM(owner_group, owner_grouplen);
542 if (iap->ia_valid & ATTR_ATIME_SET) {
543 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
544 WRITE32(NFS4_SET_TO_CLIENT_TIME);
546 WRITE32(iap->ia_mtime.tv_sec);
547 WRITE32(iap->ia_mtime.tv_nsec);
549 else if (iap->ia_valid & ATTR_ATIME) {
550 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
551 WRITE32(NFS4_SET_TO_SERVER_TIME);
553 if (iap->ia_valid & ATTR_MTIME_SET) {
554 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
555 WRITE32(NFS4_SET_TO_CLIENT_TIME);
557 WRITE32(iap->ia_mtime.tv_sec);
558 WRITE32(iap->ia_mtime.tv_nsec);
560 else if (iap->ia_valid & ATTR_MTIME) {
561 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
562 WRITE32(NFS4_SET_TO_SERVER_TIME);
566 * Now we backfill the bitmap and the attribute buffer length.
568 if (len != ((char *)p - (char *)q) + 4) {
569 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
570 len, ((char *)p - (char *)q) + 4);
573 len = (char *)p - (char *)q - 12;
574 *q++ = htonl(bmval0);
575 *q++ = htonl(bmval1);
583 static int encode_access(struct xdr_stream *xdr, u32 access)
594 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
598 RESERVE_SPACE(8+sizeof(arg->stateid.data));
601 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
606 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
612 WRITE64(args->offset);
613 WRITE32(args->count);
618 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
624 WRITE32(create->ftype);
626 switch (create->ftype) {
628 RESERVE_SPACE(4 + create->u.symlink->len);
629 WRITE32(create->u.symlink->len);
630 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
633 case NF4BLK: case NF4CHR:
635 WRITE32(create->u.device.specdata1);
636 WRITE32(create->u.device.specdata2);
643 RESERVE_SPACE(4 + create->name->len);
644 WRITE32(create->name->len);
645 WRITEMEM(create->name->name, create->name->len);
647 return encode_attrs(xdr, create->attrs, create->server);
650 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
661 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
673 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
675 return encode_getattr_two(xdr,
676 bitmask[0] & nfs4_fattr_bitmap[0],
677 bitmask[1] & nfs4_fattr_bitmap[1]);
680 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
682 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
683 bitmask[1] & nfs4_fsinfo_bitmap[1]);
686 static int encode_getfh(struct xdr_stream *xdr)
696 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
700 RESERVE_SPACE(8 + name->len);
703 WRITEMEM(name->name, name->len);
709 * opcode,type,reclaim,offset,length,new_lock_owner = 32
710 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
712 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
715 struct nfs_lock_opargs *opargs = arg->u.lock;
720 WRITE32(opargs->reclaim);
721 WRITE64(arg->offset);
722 WRITE64(arg->length);
723 WRITE32(opargs->new_lock_owner);
724 if (opargs->new_lock_owner){
725 struct nfs_open_to_lock *ol = opargs->u.open_lock;
728 WRITE32(ol->open_seqid);
729 WRITEMEM(&ol->open_stateid, sizeof(ol->open_stateid));
730 WRITE32(ol->lock_seqid);
731 WRITE64(ol->lock_owner.clientid);
733 WRITE32(ol->lock_owner.id);
736 struct nfs_exist_lock *el = opargs->u.exist_lock;
739 WRITEMEM(&el->stateid, sizeof(el->stateid));
746 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
749 struct nfs_lowner *opargs = arg->u.lockt;
754 WRITE64(arg->offset);
755 WRITE64(arg->length);
756 WRITE64(opargs->clientid);
763 static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
766 struct nfs_locku_opargs *opargs = arg->u.locku;
771 WRITE32(opargs->seqid);
772 WRITEMEM(&opargs->stateid, sizeof(opargs->stateid));
773 WRITE64(arg->offset);
774 WRITE64(arg->length);
779 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
784 RESERVE_SPACE(8 + len);
787 WRITEMEM(name->name, len);
792 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
797 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
799 WRITE32(NFS4_SHARE_ACCESS_READ);
802 WRITE32(NFS4_SHARE_ACCESS_WRITE);
804 case FMODE_READ|FMODE_WRITE:
805 WRITE32(NFS4_SHARE_ACCESS_BOTH);
810 WRITE32(0); /* for linux, share_deny = 0 always */
813 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
817 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
823 encode_share_access(xdr, arg->open_flags);
825 WRITE64(arg->clientid);
830 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
835 switch(arg->open_flags & O_EXCL) {
837 WRITE32(NFS4_CREATE_UNCHECKED);
838 encode_attrs(xdr, arg->u.attrs, arg->server);
841 WRITE32(NFS4_CREATE_EXCLUSIVE);
842 encode_nfs4_verifier(xdr, &arg->u.verifier);
846 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
851 switch (arg->open_flags & O_CREAT) {
853 WRITE32(NFS4_OPEN_NOCREATE);
856 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
857 WRITE32(NFS4_OPEN_CREATE);
858 encode_createmode(xdr, arg);
862 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
867 switch (delegation_type) {
869 WRITE32(NFS4_OPEN_DELEGATE_NONE);
872 WRITE32(NFS4_OPEN_DELEGATE_READ);
874 case FMODE_WRITE|FMODE_READ:
875 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
882 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
887 WRITE32(NFS4_OPEN_CLAIM_NULL);
888 encode_string(xdr, name->len, name->name);
891 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
896 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
897 encode_delegation_type(xdr, type);
900 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
904 RESERVE_SPACE(4+sizeof(stateid->data));
905 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
906 WRITEMEM(stateid->data, sizeof(stateid->data));
907 encode_string(xdr, name->len, name->name);
910 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
912 encode_openhdr(xdr, arg);
913 encode_opentype(xdr, arg);
914 switch (arg->claim) {
915 case NFS4_OPEN_CLAIM_NULL:
916 encode_claim_null(xdr, arg->name);
918 case NFS4_OPEN_CLAIM_PREVIOUS:
919 encode_claim_previous(xdr, arg->u.delegation_type);
921 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
922 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
930 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
934 RESERVE_SPACE(8+sizeof(arg->stateid.data));
935 WRITE32(OP_OPEN_CONFIRM);
936 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
942 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
946 RESERVE_SPACE(8+sizeof(arg->stateid.data));
947 WRITE32(OP_OPEN_DOWNGRADE);
948 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
950 encode_share_access(xdr, arg->open_flags);
955 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
960 RESERVE_SPACE(8 + len);
963 WRITEMEM(fh->data, len);
968 static int encode_putrootfh(struct xdr_stream *xdr)
973 WRITE32(OP_PUTROOTFH);
978 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
980 nfs4_stateid stateid;
984 if (ctx->state != NULL) {
985 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
986 WRITEMEM(stateid.data, sizeof(stateid.data));
988 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
991 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
998 encode_stateid(xdr, args->context);
1001 WRITE64(args->offset);
1002 WRITE32(args->count);
1007 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1009 struct rpc_auth *auth = req->rq_task->tk_auth;
1013 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1014 WRITE32(OP_READDIR);
1015 WRITE64(readdir->cookie);
1016 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1017 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1018 WRITE32(readdir->count);
1020 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) {
1022 WRITE32(FATTR4_WORD1_MOUNTED_ON_FILEID);
1024 WRITE32(FATTR4_WORD0_FILEID);
1028 /* set up reply kvec
1029 * toplevel_status + taglen + rescount + OP_PUTFH + status
1030 * + OP_READDIR + status + verifer(2) = 9
1032 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1033 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1034 readdir->pgbase, readdir->count);
1039 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1041 struct rpc_auth *auth = req->rq_task->tk_auth;
1042 unsigned int replen;
1046 WRITE32(OP_READLINK);
1048 /* set up reply kvec
1049 * toplevel_status + taglen + rescount + OP_PUTFH + status
1050 * + OP_READLINK + status + string length = 8
1052 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1053 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1054 readlink->pgbase, readlink->pglen);
1059 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1063 RESERVE_SPACE(8 + name->len);
1066 WRITEMEM(name->name, name->len);
1071 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1075 RESERVE_SPACE(8 + oldname->len);
1077 WRITE32(oldname->len);
1078 WRITEMEM(oldname->name, oldname->len);
1080 RESERVE_SPACE(4 + newname->len);
1081 WRITE32(newname->len);
1082 WRITEMEM(newname->name, newname->len);
1087 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1093 WRITE64(client_stateid->cl_clientid);
1099 encode_savefh(struct xdr_stream *xdr)
1109 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1114 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1115 WRITE32(OP_SETATTR);
1116 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1118 if ((status = encode_attrs(xdr, arg->iap, server)))
1124 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1128 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1129 WRITE32(OP_SETCLIENTID);
1130 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1132 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1134 WRITE32(setclientid->sc_prog);
1135 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1136 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1138 WRITE32(setclientid->sc_cb_ident);
1143 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1147 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1148 WRITE32(OP_SETCLIENTID_CONFIRM);
1149 WRITE64(client_state->cl_clientid);
1150 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1155 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1162 encode_stateid(xdr, args->context);
1165 WRITE64(args->offset);
1166 WRITE32(args->stable);
1167 WRITE32(args->count);
1169 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1174 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1180 WRITE32(OP_DELEGRETURN);
1181 WRITEMEM(stateid->data, sizeof(stateid->data));
1186 * END OF "GENERIC" ENCODE ROUTINES.
1190 * Encode an ACCESS request
1192 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1194 struct xdr_stream xdr;
1195 struct compound_hdr hdr = {
1200 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1201 encode_compound_hdr(&xdr, &hdr);
1202 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1203 status = encode_access(&xdr, args->access);
1208 * Encode LOOKUP request
1210 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1212 struct xdr_stream xdr;
1213 struct compound_hdr hdr = {
1218 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1219 encode_compound_hdr(&xdr, &hdr);
1220 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1222 if ((status = encode_lookup(&xdr, args->name)) != 0)
1224 if ((status = encode_getfh(&xdr)) != 0)
1226 status = encode_getfattr(&xdr, args->bitmask);
1232 * Encode LOOKUP_ROOT request
1234 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1236 struct xdr_stream xdr;
1237 struct compound_hdr hdr = {
1242 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1243 encode_compound_hdr(&xdr, &hdr);
1244 if ((status = encode_putrootfh(&xdr)) != 0)
1246 if ((status = encode_getfh(&xdr)) == 0)
1247 status = encode_getfattr(&xdr, args->bitmask);
1253 * Encode REMOVE request
1255 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1257 struct xdr_stream xdr;
1258 struct compound_hdr hdr = {
1263 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1264 encode_compound_hdr(&xdr, &hdr);
1265 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1266 status = encode_remove(&xdr, args->name);
1271 * Encode RENAME request
1273 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1275 struct xdr_stream xdr;
1276 struct compound_hdr hdr = {
1281 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1282 encode_compound_hdr(&xdr, &hdr);
1283 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1285 if ((status = encode_savefh(&xdr)) != 0)
1287 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1289 status = encode_rename(&xdr, args->old_name, args->new_name);
1295 * Encode LINK request
1297 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1299 struct xdr_stream xdr;
1300 struct compound_hdr hdr = {
1305 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1306 encode_compound_hdr(&xdr, &hdr);
1307 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1309 if ((status = encode_savefh(&xdr)) != 0)
1311 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1313 status = encode_link(&xdr, args->name);
1319 * Encode CREATE request
1321 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1323 struct xdr_stream xdr;
1324 struct compound_hdr hdr = {
1329 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1330 encode_compound_hdr(&xdr, &hdr);
1331 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1333 if ((status = encode_create(&xdr, args)) != 0)
1335 if ((status = encode_getfh(&xdr)) != 0)
1337 status = encode_getfattr(&xdr, args->bitmask);
1343 * Encode SYMLINK request
1345 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1347 return nfs4_xdr_enc_create(req, p, args);
1351 * Encode GETATTR request
1353 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1355 struct xdr_stream xdr;
1356 struct compound_hdr hdr = {
1361 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1362 encode_compound_hdr(&xdr, &hdr);
1363 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1364 status = encode_getfattr(&xdr, args->bitmask);
1369 * Encode a CLOSE request
1371 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1373 struct xdr_stream xdr;
1374 struct compound_hdr hdr = {
1379 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1380 encode_compound_hdr(&xdr, &hdr);
1381 status = encode_putfh(&xdr, args->fh);
1384 status = encode_close(&xdr, args);
1390 * Encode an OPEN request
1392 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1394 struct xdr_stream xdr;
1395 struct compound_hdr hdr = {
1400 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1401 encode_compound_hdr(&xdr, &hdr);
1402 status = encode_putfh(&xdr, args->fh);
1405 status = encode_open(&xdr, args);
1408 status = encode_getfh(&xdr);
1411 status = encode_getfattr(&xdr, args->bitmask);
1417 * Encode an OPEN_CONFIRM request
1419 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1421 struct xdr_stream xdr;
1422 struct compound_hdr hdr = {
1427 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1428 encode_compound_hdr(&xdr, &hdr);
1429 status = encode_putfh(&xdr, args->fh);
1432 status = encode_open_confirm(&xdr, args);
1438 * Encode an OPEN request with no attributes.
1440 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1442 struct xdr_stream xdr;
1443 struct compound_hdr hdr = {
1448 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1449 encode_compound_hdr(&xdr, &hdr);
1450 status = encode_putfh(&xdr, args->fh);
1453 status = encode_open(&xdr, args);
1459 * Encode an OPEN_DOWNGRADE request
1461 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1463 struct xdr_stream xdr;
1464 struct compound_hdr hdr = {
1469 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1470 encode_compound_hdr(&xdr, &hdr);
1471 status = encode_putfh(&xdr, args->fh);
1474 status = encode_open_downgrade(&xdr, args);
1480 * Encode a LOCK request
1482 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1484 struct xdr_stream xdr;
1485 struct compound_hdr hdr = {
1490 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1491 encode_compound_hdr(&xdr, &hdr);
1492 status = encode_putfh(&xdr, args->fh);
1495 status = encode_lock(&xdr, args);
1501 * Encode a LOCKT request
1503 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1505 struct xdr_stream xdr;
1506 struct compound_hdr hdr = {
1511 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1512 encode_compound_hdr(&xdr, &hdr);
1513 status = encode_putfh(&xdr, args->fh);
1516 status = encode_lockt(&xdr, args);
1522 * Encode a LOCKU request
1524 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1526 struct xdr_stream xdr;
1527 struct compound_hdr hdr = {
1532 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1533 encode_compound_hdr(&xdr, &hdr);
1534 status = encode_putfh(&xdr, args->fh);
1537 status = encode_locku(&xdr, args);
1543 * Encode a READLINK request
1545 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1547 struct xdr_stream xdr;
1548 struct compound_hdr hdr = {
1553 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1554 encode_compound_hdr(&xdr, &hdr);
1555 status = encode_putfh(&xdr, args->fh);
1558 status = encode_readlink(&xdr, args, req);
1564 * Encode a READDIR request
1566 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1568 struct xdr_stream xdr;
1569 struct compound_hdr hdr = {
1574 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1575 encode_compound_hdr(&xdr, &hdr);
1576 status = encode_putfh(&xdr, args->fh);
1579 status = encode_readdir(&xdr, args, req);
1585 * Encode a READ request
1587 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1589 struct rpc_auth *auth = req->rq_task->tk_auth;
1590 struct xdr_stream xdr;
1591 struct compound_hdr hdr = {
1596 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1597 encode_compound_hdr(&xdr, &hdr);
1598 status = encode_putfh(&xdr, args->fh);
1601 status = encode_read(&xdr, args);
1605 /* set up reply kvec
1606 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1607 * + OP_READ + status + eof + datalen = 9
1609 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1610 xdr_inline_pages(&req->rq_rcv_buf, replen,
1611 args->pages, args->pgbase, args->count);
1617 * Encode an SETATTR request
1619 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1622 struct xdr_stream xdr;
1623 struct compound_hdr hdr = {
1628 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1629 encode_compound_hdr(&xdr, &hdr);
1630 status = encode_putfh(&xdr, args->fh);
1633 status = encode_setattr(&xdr, args, args->server);
1636 status = encode_getfattr(&xdr, args->bitmask);
1642 * Encode a GETACL request
1645 nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p,
1646 struct nfs_getaclargs *args)
1648 struct xdr_stream xdr;
1649 struct rpc_auth *auth = req->rq_task->tk_auth;
1650 struct compound_hdr hdr = {
1655 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1656 encode_compound_hdr(&xdr, &hdr);
1657 status = encode_putfh(&xdr, args->fh);
1660 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1661 /* set up reply buffer: */
1662 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1663 xdr_inline_pages(&req->rq_rcv_buf, replen,
1664 args->acl_pages, args->acl_pgbase, args->acl_len);
1670 * Encode a WRITE request
1672 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1674 struct xdr_stream xdr;
1675 struct compound_hdr hdr = {
1680 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1681 encode_compound_hdr(&xdr, &hdr);
1682 status = encode_putfh(&xdr, args->fh);
1685 status = encode_write(&xdr, args);
1693 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1695 struct xdr_stream xdr;
1696 struct compound_hdr hdr = {
1701 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1702 encode_compound_hdr(&xdr, &hdr);
1703 status = encode_putfh(&xdr, args->fh);
1706 status = encode_commit(&xdr, args);
1714 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1716 struct xdr_stream xdr;
1717 struct compound_hdr hdr = {
1722 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1723 encode_compound_hdr(&xdr, &hdr);
1724 status = encode_putfh(&xdr, args->fh);
1726 status = encode_fsinfo(&xdr, args->bitmask);
1731 * a PATHCONF request
1733 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1735 struct xdr_stream xdr;
1736 struct compound_hdr hdr = {
1741 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1742 encode_compound_hdr(&xdr, &hdr);
1743 status = encode_putfh(&xdr, args->fh);
1745 status = encode_getattr_one(&xdr,
1746 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1753 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1755 struct xdr_stream xdr;
1756 struct compound_hdr hdr = {
1761 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1762 encode_compound_hdr(&xdr, &hdr);
1763 status = encode_putfh(&xdr, args->fh);
1765 status = encode_getattr_two(&xdr,
1766 args->bitmask[0] & nfs4_statfs_bitmap[0],
1767 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1772 * GETATTR_BITMAP request
1774 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1776 struct xdr_stream xdr;
1777 struct compound_hdr hdr = {
1782 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1783 encode_compound_hdr(&xdr, &hdr);
1784 status = encode_putfh(&xdr, fhandle);
1786 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1787 FATTR4_WORD0_LINK_SUPPORT|
1788 FATTR4_WORD0_SYMLINK_SUPPORT|
1789 FATTR4_WORD0_ACLSUPPORT);
1796 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1798 struct xdr_stream xdr;
1799 struct compound_hdr hdr = {
1803 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1804 encode_compound_hdr(&xdr, &hdr);
1805 return encode_renew(&xdr, clp);
1809 * a SETCLIENTID request
1811 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1813 struct xdr_stream xdr;
1814 struct compound_hdr hdr = {
1818 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1819 encode_compound_hdr(&xdr, &hdr);
1820 return encode_setclientid(&xdr, sc);
1824 * a SETCLIENTID_CONFIRM request
1826 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1828 struct xdr_stream xdr;
1829 struct compound_hdr hdr = {
1832 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1835 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1836 encode_compound_hdr(&xdr, &hdr);
1837 status = encode_setclientid_confirm(&xdr, clp);
1839 status = encode_putrootfh(&xdr);
1841 status = encode_fsinfo(&xdr, lease_bitmap);
1846 * DELEGRETURN request
1848 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1850 struct xdr_stream xdr;
1851 struct compound_hdr hdr = {
1856 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1857 encode_compound_hdr(&xdr, &hdr);
1858 if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
1859 status = encode_delegreturn(&xdr, args->stateid);
1864 * START OF "GENERIC" DECODE ROUTINES.
1865 * These may look a little ugly since they are imported from a "generic"
1866 * set of XDR encode/decode routines which are intended to be shared by
1867 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1869 * If the pain of reading these is too great, it should be a straightforward
1870 * task to translate them into Linux-specific versions which are more
1871 * consistent with the style used in NFSv2/v3...
1873 #define READ32(x) (x) = ntohl(*p++)
1874 #define READ64(x) do { \
1875 (x) = (u64)ntohl(*p++) << 32; \
1876 (x) |= ntohl(*p++); \
1878 #define READTIME(x) do { \
1880 (x.tv_sec) = ntohl(*p++); \
1881 (x.tv_nsec) = ntohl(*p++); \
1883 #define COPYMEM(x,nbytes) do { \
1884 memcpy((x), p, nbytes); \
1885 p += XDR_QUADLEN(nbytes); \
1888 #define READ_BUF(nbytes) do { \
1889 p = xdr_inline_decode(xdr, nbytes); \
1891 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
1892 __FUNCTION__, __LINE__); \
1897 static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
1904 *string = (char *)p;
1908 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
1913 READ32(hdr->status);
1914 READ32(hdr->taglen);
1916 READ_BUF(hdr->taglen + 4);
1917 hdr->tag = (char *)p;
1918 p += XDR_QUADLEN(hdr->taglen);
1923 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
1931 if (opnum != expected) {
1933 "nfs4_decode_op_hdr: Server returned operation"
1934 " %d but we issued a request for %d\n",
1939 if (nfserr != NFS_OK)
1940 return -nfs_stat_to_errno(nfserr);
1945 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
1952 return decode_opaque_inline(xdr, &strlen, &str);
1955 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
1962 bitmap[0] = bitmap[1] = 0;
1963 READ_BUF((bmlen << 2));
1972 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
1982 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
1984 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
1985 decode_attr_bitmap(xdr, bitmask);
1986 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
1988 bitmask[0] = bitmask[1] = 0;
1989 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
1993 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
1998 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2000 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2003 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2004 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2007 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2009 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2013 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2018 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2020 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2023 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2025 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2026 (unsigned long long)*change);
2030 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2035 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2037 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2040 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2042 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2046 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2051 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2053 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2056 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2058 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2062 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2067 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2069 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2072 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2074 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2078 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2084 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2086 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2088 READ64(fsid->major);
2089 READ64(fsid->minor);
2090 bitmap[0] &= ~FATTR4_WORD0_FSID;
2092 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2093 (unsigned long long)fsid->major,
2094 (unsigned long long)fsid->minor);
2098 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2103 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2105 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2108 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2110 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2114 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2118 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2119 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2121 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2124 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2126 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2130 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2135 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2137 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2140 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2142 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2146 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2152 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2154 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2157 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2159 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2163 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2169 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2171 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2174 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2176 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2180 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2186 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2188 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2191 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2193 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2197 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2203 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2205 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2208 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2210 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2214 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2220 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2222 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2225 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2227 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2231 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2237 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2239 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2242 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2244 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2248 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2254 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2256 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2260 if (maxread > 0x7FFFFFFF)
2261 maxread = 0x7FFFFFFF;
2262 *res = (uint32_t)maxread;
2263 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2265 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2269 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2275 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2277 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2281 if (maxwrite > 0x7FFFFFFF)
2282 maxwrite = 0x7FFFFFFF;
2283 *res = (uint32_t)maxwrite;
2284 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2286 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2290 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2295 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2297 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2301 bitmap[1] &= ~FATTR4_WORD1_MODE;
2303 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2307 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2312 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2314 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2317 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2319 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2323 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2328 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2330 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2334 if (len < XDR_MAX_NETOBJ) {
2335 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2336 dprintk("%s: nfs_map_name_to_uid failed!\n",
2339 printk(KERN_WARNING "%s: name too long (%u)!\n",
2341 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2343 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2347 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2352 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2354 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2358 if (len < XDR_MAX_NETOBJ) {
2359 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2360 dprintk("%s: nfs_map_group_to_gid failed!\n",
2363 printk(KERN_WARNING "%s: name too long (%u)!\n",
2365 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2367 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2371 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2373 uint32_t major = 0, minor = 0, *p;
2376 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2378 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2384 tmp = MKDEV(major, minor);
2385 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2387 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2389 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2393 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2399 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2401 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2404 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2406 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2410 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2416 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2418 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2421 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2423 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2427 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2433 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2435 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2438 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2440 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2444 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2449 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2451 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2454 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2456 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2457 (unsigned long long)*used);
2461 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2470 time->tv_sec = (time_t)sec;
2471 time->tv_nsec = (long)nsec;
2475 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2481 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2483 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2484 status = decode_attr_time(xdr, time);
2485 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2487 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2491 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2497 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2499 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2500 status = decode_attr_time(xdr, time);
2501 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2503 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2507 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2513 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2515 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2516 status = decode_attr_time(xdr, time);
2517 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2519 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2523 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2525 unsigned int attrwords = XDR_QUADLEN(attrlen);
2526 unsigned int nwords = xdr->p - savep;
2528 if (unlikely(attrwords != nwords)) {
2529 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2532 (attrwords < nwords) ? '<' : '>',
2539 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2544 READ32(cinfo->atomic);
2545 READ64(cinfo->before);
2546 READ64(cinfo->after);
2550 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2556 status = decode_op_hdr(xdr, OP_ACCESS);
2562 access->supported = supp;
2563 access->access = acc;
2567 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2572 status = decode_op_hdr(xdr, OP_CLOSE);
2575 READ_BUF(sizeof(res->stateid.data));
2576 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2580 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2585 status = decode_op_hdr(xdr, OP_COMMIT);
2589 COPYMEM(res->verf->verifier, 8);
2593 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2599 status = decode_op_hdr(xdr, OP_CREATE);
2602 if ((status = decode_change_info(xdr, cinfo)))
2606 READ_BUF(bmlen << 2);
2610 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2617 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2619 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2621 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2623 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2625 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2627 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2629 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2631 status = verify_attr_len(xdr, savep, attrlen);
2634 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2638 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2645 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2647 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2649 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2652 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2654 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2656 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2658 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2660 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2662 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2665 status = verify_attr_len(xdr, savep, attrlen);
2668 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2672 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2679 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2681 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2683 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2686 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2688 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2691 status = verify_attr_len(xdr, savep, attrlen);
2694 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2698 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2704 int status, fmode = 0;
2706 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2708 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2711 fattr->bitmap[0] = bitmap[0];
2712 fattr->bitmap[1] = bitmap[1];
2714 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2718 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2720 fattr->type = nfs_type2fmt[type].nfs2type;
2721 fmode = nfs_type2fmt[type].mode;
2723 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2725 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2727 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2729 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2731 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2733 fattr->mode |= fmode;
2734 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2736 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2738 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2740 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2742 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2744 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2746 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2748 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2750 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) {
2751 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2752 fattr->timestamp = jiffies;
2756 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2761 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2764 uint32_t attrlen, bitmap[2];
2767 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2769 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2771 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2774 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2776 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2778 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2780 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2782 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2783 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2785 fsinfo->wtpref = fsinfo->wtmax;
2787 status = verify_attr_len(xdr, savep, attrlen);
2790 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2794 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2800 status = decode_op_hdr(xdr, OP_GETFH);
2803 /* Zero handle first to allow comparisons */
2804 memset(fh, 0, sizeof(*fh));
2808 if (len > NFS4_FHSIZE)
2812 COPYMEM(fh->data, len);
2816 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2820 status = decode_op_hdr(xdr, OP_LINK);
2823 return decode_change_info(xdr, cinfo);
2827 * We create the owner, so we know a proper owner.id length is 4.
2829 static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2835 READ64(denied->offset);
2836 READ64(denied->length);
2837 READ32(denied->type);
2838 READ64(denied->owner.clientid);
2842 READ32(denied->owner.id);
2843 return -NFS4ERR_DENIED;
2846 static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2851 status = decode_op_hdr(xdr, OP_LOCK);
2853 READ_BUF(sizeof(nfs4_stateid));
2854 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2855 } else if (status == -NFS4ERR_DENIED)
2856 return decode_lock_denied(xdr, &res->u.denied);
2860 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2863 status = decode_op_hdr(xdr, OP_LOCKT);
2864 if (status == -NFS4ERR_DENIED)
2865 return decode_lock_denied(xdr, &res->u.denied);
2869 static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2874 status = decode_op_hdr(xdr, OP_LOCKU);
2876 READ_BUF(sizeof(nfs4_stateid));
2877 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2882 static int decode_lookup(struct xdr_stream *xdr)
2884 return decode_op_hdr(xdr, OP_LOOKUP);
2887 /* This is too sick! */
2888 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
2891 uint32_t limit_type, nblocks, blocksize;
2895 switch (limit_type) {
2902 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
2907 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
2910 uint32_t delegation_type;
2913 READ32(delegation_type);
2914 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
2915 res->delegation_type = 0;
2919 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
2920 READ32(res->do_recall);
2921 switch (delegation_type) {
2922 case NFS4_OPEN_DELEGATE_READ:
2923 res->delegation_type = FMODE_READ;
2925 case NFS4_OPEN_DELEGATE_WRITE:
2926 res->delegation_type = FMODE_WRITE|FMODE_READ;
2927 if (decode_space_limit(xdr, &res->maxsize) < 0)
2930 return decode_ace(xdr, NULL, res->server->nfs4_state);
2933 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
2939 status = decode_op_hdr(xdr, OP_OPEN);
2942 READ_BUF(sizeof(res->stateid.data));
2943 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2945 decode_change_info(xdr, &res->cinfo);
2948 READ32(res->rflags);
2953 READ_BUF(bmlen << 2);
2955 return decode_delegation(xdr, res);
2957 printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
2961 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
2966 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
2969 READ_BUF(sizeof(res->stateid.data));
2970 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2974 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
2979 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
2982 READ_BUF(sizeof(res->stateid.data));
2983 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2987 static int decode_putfh(struct xdr_stream *xdr)
2989 return decode_op_hdr(xdr, OP_PUTFH);
2992 static int decode_putrootfh(struct xdr_stream *xdr)
2994 return decode_op_hdr(xdr, OP_PUTROOTFH);
2997 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
2999 struct kvec *iov = req->rq_rcv_buf.head;
3001 uint32_t count, eof, recvd, hdrlen;
3004 status = decode_op_hdr(xdr, OP_READ);
3010 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3011 recvd = req->rq_rcv_buf.len - hdrlen;
3012 if (count > recvd) {
3013 printk(KERN_WARNING "NFS: server cheating in read reply: "
3014 "count %u > recvd %u\n", count, recvd);
3018 xdr_read_pages(xdr, count);
3024 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3026 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3027 struct page *page = *rcvbuf->pages;
3028 struct kvec *iov = rcvbuf->head;
3029 unsigned int nr, pglen = rcvbuf->page_len;
3030 uint32_t *end, *entry, *p, *kaddr;
3031 uint32_t len, attrlen;
3032 int hdrlen, recvd, status;
3034 status = decode_op_hdr(xdr, OP_READDIR);
3038 COPYMEM(readdir->verifier.data, 8);
3040 hdrlen = (char *) p - (char *) iov->iov_base;
3041 recvd = rcvbuf->len - hdrlen;
3044 xdr_read_pages(xdr, pglen);
3046 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3047 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3048 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3050 for (nr = 0; *p++; nr++) {
3053 p += 2; /* cookie */
3054 len = ntohl(*p++); /* filename length */
3055 if (len > NFS4_MAXNAMLEN) {
3056 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3059 p += XDR_QUADLEN(len);
3062 len = ntohl(*p++); /* bitmap length */
3066 attrlen = XDR_QUADLEN(ntohl(*p++));
3067 p += attrlen; /* attributes */
3072 if (!nr && (entry[0] != 0 || entry[1] == 0))
3075 kunmap_atomic(kaddr, KM_USER0);
3078 entry[0] = entry[1] = 0;
3079 /* truncate listing ? */
3081 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3086 kunmap_atomic(kaddr, KM_USER0);
3087 return -errno_NFSERR_IO;
3090 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3092 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3093 struct kvec *iov = rcvbuf->head;
3094 int hdrlen, len, recvd;
3099 status = decode_op_hdr(xdr, OP_READLINK);
3103 /* Convert length of symlink */
3106 if (len >= rcvbuf->page_len || len <= 0) {
3107 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3108 return -ENAMETOOLONG;
3110 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3111 recvd = req->rq_rcv_buf.len - hdrlen;
3113 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3114 "count %u > recvd %u\n", len, recvd);
3117 xdr_read_pages(xdr, len);
3119 * The XDR encode routine has set things up so that
3120 * the link text will be copied directly into the
3121 * buffer. We just have to do overflow-checking,
3122 * and and null-terminate the text (the VFS expects
3123 * null-termination).
3125 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3126 kaddr[len+rcvbuf->page_base] = '\0';
3127 kunmap_atomic(kaddr, KM_USER0);
3131 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3135 status = decode_op_hdr(xdr, OP_REMOVE);
3138 status = decode_change_info(xdr, cinfo);
3143 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3144 struct nfs4_change_info *new_cinfo)
3148 status = decode_op_hdr(xdr, OP_RENAME);
3151 if ((status = decode_change_info(xdr, old_cinfo)))
3153 status = decode_change_info(xdr, new_cinfo);
3158 static int decode_renew(struct xdr_stream *xdr)
3160 return decode_op_hdr(xdr, OP_RENEW);
3163 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3169 struct kvec *iov = req->rq_rcv_buf.head;
3173 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3175 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3177 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3180 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3182 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3185 /* We ignore &savep and don't do consistency checks on
3186 * the attr length. Let userspace figure it out.... */
3187 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3188 recvd = req->rq_rcv_buf.len - hdrlen;
3189 if (attrlen > recvd) {
3190 printk(KERN_WARNING "NFS: server cheating in getattr"
3191 " acl reply: attrlen %u > recvd %u\n",
3195 if (attrlen <= *acl_len)
3196 xdr_read_pages(xdr, attrlen);
3205 decode_savefh(struct xdr_stream *xdr)
3207 return decode_op_hdr(xdr, OP_SAVEFH);
3210 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3217 status = decode_op_hdr(xdr, OP_SETATTR);
3222 READ_BUF(bmlen << 2);
3226 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3234 if (opnum != OP_SETCLIENTID) {
3236 "nfs4_decode_setclientid: Server returned operation"
3241 if (nfserr == NFS_OK) {
3242 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3243 READ64(clp->cl_clientid);
3244 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3245 } else if (nfserr == NFSERR_CLID_INUSE) {
3248 /* skip netid string */
3253 /* skip uaddr string */
3257 return -NFSERR_CLID_INUSE;
3259 return -nfs_stat_to_errno(nfserr);
3264 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3266 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3269 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3274 status = decode_op_hdr(xdr, OP_WRITE);
3280 READ32(res->verf->committed);
3281 COPYMEM(res->verf->verifier, 8);
3285 static int decode_delegreturn(struct xdr_stream *xdr)
3287 return decode_op_hdr(xdr, OP_DELEGRETURN);
3291 * Decode OPEN_DOWNGRADE response
3293 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3295 struct xdr_stream xdr;
3296 struct compound_hdr hdr;
3299 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3300 status = decode_compound_hdr(&xdr, &hdr);
3303 status = decode_putfh(&xdr);
3306 status = decode_open_downgrade(&xdr, res);
3312 * END OF "GENERIC" DECODE ROUTINES.
3316 * Decode ACCESS response
3318 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3320 struct xdr_stream xdr;
3321 struct compound_hdr hdr;
3324 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3325 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3327 if ((status = decode_putfh(&xdr)) == 0)
3328 status = decode_access(&xdr, res);
3334 * Decode LOOKUP response
3336 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3338 struct xdr_stream xdr;
3339 struct compound_hdr hdr;
3342 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3343 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3345 if ((status = decode_putfh(&xdr)) != 0)
3347 if ((status = decode_lookup(&xdr)) != 0)
3349 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3351 status = decode_getfattr(&xdr, res->fattr, res->server);
3357 * Decode LOOKUP_ROOT response
3359 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3361 struct xdr_stream xdr;
3362 struct compound_hdr hdr;
3365 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3366 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3368 if ((status = decode_putrootfh(&xdr)) != 0)
3370 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3371 status = decode_getfattr(&xdr, res->fattr, res->server);
3377 * Decode REMOVE response
3379 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3381 struct xdr_stream xdr;
3382 struct compound_hdr hdr;
3385 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3386 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3388 if ((status = decode_putfh(&xdr)) == 0)
3389 status = decode_remove(&xdr, cinfo);
3395 * Decode RENAME response
3397 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3399 struct xdr_stream xdr;
3400 struct compound_hdr hdr;
3403 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3404 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3406 if ((status = decode_putfh(&xdr)) != 0)
3408 if ((status = decode_savefh(&xdr)) != 0)
3410 if ((status = decode_putfh(&xdr)) != 0)
3412 status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
3418 * Decode LINK response
3420 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3422 struct xdr_stream xdr;
3423 struct compound_hdr hdr;
3426 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3427 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3429 if ((status = decode_putfh(&xdr)) != 0)
3431 if ((status = decode_savefh(&xdr)) != 0)
3433 if ((status = decode_putfh(&xdr)) != 0)
3435 status = decode_link(&xdr, cinfo);
3441 * Decode CREATE response
3443 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3445 struct xdr_stream xdr;
3446 struct compound_hdr hdr;
3449 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3450 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3452 if ((status = decode_putfh(&xdr)) != 0)
3454 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3456 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3458 status = decode_getfattr(&xdr, res->fattr, res->server);
3459 if (status == NFS4ERR_DELAY)
3466 * Decode SYMLINK response
3468 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3470 return nfs4_xdr_dec_create(rqstp, p, res);
3474 * Decode GETATTR response
3476 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3478 struct xdr_stream xdr;
3479 struct compound_hdr hdr;
3482 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3483 status = decode_compound_hdr(&xdr, &hdr);
3486 status = decode_putfh(&xdr);
3489 status = decode_getfattr(&xdr, res->fattr, res->server);
3497 * Decode GETACL response
3500 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len)
3502 struct xdr_stream xdr;
3503 struct compound_hdr hdr;
3506 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3507 status = decode_compound_hdr(&xdr, &hdr);
3510 status = decode_putfh(&xdr);
3513 status = decode_getacl(&xdr, rqstp, acl_len);
3520 * Decode CLOSE response
3522 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3524 struct xdr_stream xdr;
3525 struct compound_hdr hdr;
3528 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3529 status = decode_compound_hdr(&xdr, &hdr);
3532 status = decode_putfh(&xdr);
3535 status = decode_close(&xdr, res);
3541 * Decode OPEN response
3543 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3545 struct xdr_stream xdr;
3546 struct compound_hdr hdr;
3549 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3550 status = decode_compound_hdr(&xdr, &hdr);
3553 status = decode_putfh(&xdr);
3556 status = decode_open(&xdr, res);
3559 status = decode_getfh(&xdr, &res->fh);
3562 status = decode_getfattr(&xdr, res->f_attr, res->server);
3563 if (status == NFS4ERR_DELAY)
3570 * Decode OPEN_CONFIRM response
3572 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3574 struct xdr_stream xdr;
3575 struct compound_hdr hdr;
3578 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3579 status = decode_compound_hdr(&xdr, &hdr);
3582 status = decode_putfh(&xdr);
3585 status = decode_open_confirm(&xdr, res);
3591 * Decode OPEN response
3593 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3595 struct xdr_stream xdr;
3596 struct compound_hdr hdr;
3599 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3600 status = decode_compound_hdr(&xdr, &hdr);
3603 status = decode_putfh(&xdr);
3606 status = decode_open(&xdr, res);
3612 * Decode SETATTR response
3614 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3616 struct xdr_stream xdr;
3617 struct compound_hdr hdr;
3620 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3621 status = decode_compound_hdr(&xdr, &hdr);
3624 status = decode_putfh(&xdr);
3627 status = decode_setattr(&xdr, res);
3630 status = decode_getfattr(&xdr, res->fattr, res->server);
3631 if (status == NFS4ERR_DELAY)
3638 * Decode LOCK response
3640 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3642 struct xdr_stream xdr;
3643 struct compound_hdr hdr;
3646 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3647 status = decode_compound_hdr(&xdr, &hdr);
3650 status = decode_putfh(&xdr);
3653 status = decode_lock(&xdr, res);
3659 * Decode LOCKT response
3661 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3663 struct xdr_stream xdr;
3664 struct compound_hdr hdr;
3667 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3668 status = decode_compound_hdr(&xdr, &hdr);
3671 status = decode_putfh(&xdr);
3674 status = decode_lockt(&xdr, res);
3680 * Decode LOCKU response
3682 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3684 struct xdr_stream xdr;
3685 struct compound_hdr hdr;
3688 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3689 status = decode_compound_hdr(&xdr, &hdr);
3692 status = decode_putfh(&xdr);
3695 status = decode_locku(&xdr, res);
3701 * Decode READLINK response
3703 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3705 struct xdr_stream xdr;
3706 struct compound_hdr hdr;
3709 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3710 status = decode_compound_hdr(&xdr, &hdr);
3713 status = decode_putfh(&xdr);
3716 status = decode_readlink(&xdr, rqstp);
3722 * Decode READDIR response
3724 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3726 struct xdr_stream xdr;
3727 struct compound_hdr hdr;
3730 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3731 status = decode_compound_hdr(&xdr, &hdr);
3734 status = decode_putfh(&xdr);
3737 status = decode_readdir(&xdr, rqstp, res);
3743 * Decode Read response
3745 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3747 struct xdr_stream xdr;
3748 struct compound_hdr hdr;
3751 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3752 status = decode_compound_hdr(&xdr, &hdr);
3755 status = decode_putfh(&xdr);
3758 status = decode_read(&xdr, rqstp, res);
3760 status = res->count;
3766 * Decode WRITE response
3768 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3770 struct xdr_stream xdr;
3771 struct compound_hdr hdr;
3774 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3775 status = decode_compound_hdr(&xdr, &hdr);
3778 status = decode_putfh(&xdr);
3781 status = decode_write(&xdr, res);
3783 status = res->count;
3789 * Decode COMMIT response
3791 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3793 struct xdr_stream xdr;
3794 struct compound_hdr hdr;
3797 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3798 status = decode_compound_hdr(&xdr, &hdr);
3801 status = decode_putfh(&xdr);
3804 status = decode_commit(&xdr, res);
3812 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3814 struct xdr_stream xdr;
3815 struct compound_hdr hdr;
3818 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3819 status = decode_compound_hdr(&xdr, &hdr);
3821 status = decode_putfh(&xdr);
3823 status = decode_fsinfo(&xdr, fsinfo);
3825 status = -nfs_stat_to_errno(hdr.status);
3832 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
3834 struct xdr_stream xdr;
3835 struct compound_hdr hdr;
3838 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3839 status = decode_compound_hdr(&xdr, &hdr);
3841 status = decode_putfh(&xdr);
3843 status = decode_pathconf(&xdr, pathconf);
3850 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
3852 struct xdr_stream xdr;
3853 struct compound_hdr hdr;
3856 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3857 status = decode_compound_hdr(&xdr, &hdr);
3859 status = decode_putfh(&xdr);
3861 status = decode_statfs(&xdr, fsstat);
3866 * GETATTR_BITMAP request
3868 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
3870 struct xdr_stream xdr;
3871 struct compound_hdr hdr;
3874 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3875 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3877 if ((status = decode_putfh(&xdr)) != 0)
3879 status = decode_server_caps(&xdr, res);
3885 * Decode RENEW response
3887 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3889 struct xdr_stream xdr;
3890 struct compound_hdr hdr;
3893 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3894 status = decode_compound_hdr(&xdr, &hdr);
3896 status = decode_renew(&xdr);
3901 * a SETCLIENTID request
3903 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
3904 struct nfs4_client *clp)
3906 struct xdr_stream xdr;
3907 struct compound_hdr hdr;
3910 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3911 status = decode_compound_hdr(&xdr, &hdr);
3913 status = decode_setclientid(&xdr, clp);
3915 status = -nfs_stat_to_errno(hdr.status);
3920 * a SETCLIENTID_CONFIRM request
3922 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3924 struct xdr_stream xdr;
3925 struct compound_hdr hdr;
3928 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3929 status = decode_compound_hdr(&xdr, &hdr);
3931 status = decode_setclientid_confirm(&xdr);
3933 status = decode_putrootfh(&xdr);
3935 status = decode_fsinfo(&xdr, fsinfo);
3937 status = -nfs_stat_to_errno(hdr.status);
3942 * DELEGRETURN request
3944 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3946 struct xdr_stream xdr;
3947 struct compound_hdr hdr;
3950 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3951 status = decode_compound_hdr(&xdr, &hdr);
3953 status = decode_putfh(&xdr);
3955 status = decode_delegreturn(&xdr);
3960 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
3962 uint32_t bitmap[2] = {0};
3967 return ERR_PTR(-EAGAIN);
3969 return ERR_PTR(-EBADCOOKIE);
3972 entry->prev_cookie = entry->cookie;
3973 p = xdr_decode_hyper(p, &entry->cookie);
3974 entry->len = ntohl(*p++);
3975 entry->name = (const char *) p;
3976 p += XDR_QUADLEN(entry->len);
3979 * In case the server doesn't return an inode number,
3980 * we fake one here. (We don't use inode number 0,
3981 * since glibc seems to choke on it...)
3985 len = ntohl(*p++); /* bitmap length */
3987 bitmap[0] = ntohl(*p++);
3989 bitmap[1] = ntohl(*p++);
3993 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
3995 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
3996 xdr_decode_hyper(p, &entry->ino);
3997 else if (bitmap[0] == FATTR4_WORD0_FILEID)
3998 xdr_decode_hyper(p, &entry->ino);
4002 entry->eof = !p[0] && p[1];
4007 * We need to translate between nfs status return values and
4008 * the local errno values which may not be the same.
4015 { NFS4ERR_PERM, EPERM },
4016 { NFS4ERR_NOENT, ENOENT },
4017 { NFS4ERR_IO, errno_NFSERR_IO },
4018 { NFS4ERR_NXIO, ENXIO },
4019 { NFS4ERR_ACCESS, EACCES },
4020 { NFS4ERR_EXIST, EEXIST },
4021 { NFS4ERR_XDEV, EXDEV },
4022 { NFS4ERR_NOTDIR, ENOTDIR },
4023 { NFS4ERR_ISDIR, EISDIR },
4024 { NFS4ERR_INVAL, EINVAL },
4025 { NFS4ERR_FBIG, EFBIG },
4026 { NFS4ERR_NOSPC, ENOSPC },
4027 { NFS4ERR_ROFS, EROFS },
4028 { NFS4ERR_MLINK, EMLINK },
4029 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4030 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4031 { NFS4ERR_DQUOT, EDQUOT },
4032 { NFS4ERR_STALE, ESTALE },
4033 { NFS4ERR_BADHANDLE, EBADHANDLE },
4034 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4035 { NFS4ERR_NOTSUPP, ENOTSUPP },
4036 { NFS4ERR_TOOSMALL, ETOOSMALL },
4037 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4038 { NFS4ERR_BADTYPE, EBADTYPE },
4039 { NFS4ERR_LOCKED, EAGAIN },
4040 { NFS4ERR_RESOURCE, EREMOTEIO },
4041 { NFS4ERR_SYMLINK, ELOOP },
4042 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4043 { NFS4ERR_DEADLOCK, EDEADLK },
4044 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4045 * to be handled by a
4052 * Convert an NFS error code to a local one.
4053 * This one is used jointly by NFSv2 and NFSv3.
4056 nfs_stat_to_errno(int stat)
4059 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4060 if (nfs_errtbl[i].stat == stat)
4061 return nfs_errtbl[i].errno;
4063 if (stat <= 10000 || stat > 10100) {
4064 /* The server is looney tunes. */
4065 return ESERVERFAULT;
4067 /* If we cannot translate the error, the recovery routines should
4069 * Note: remaining NFSv4 error codes have values > 10000, so should
4070 * not conflict with native Linux error codes.
4076 # define MAX(a, b) (((a) > (b))? (a) : (b))
4079 #define PROC(proc, argtype, restype) \
4080 [NFSPROC4_CLNT_##proc] = { \
4081 .p_proc = NFSPROC4_COMPOUND, \
4082 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4083 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4084 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
4087 struct rpc_procinfo nfs4_procedures[] = {
4088 PROC(READ, enc_read, dec_read),
4089 PROC(WRITE, enc_write, dec_write),
4090 PROC(COMMIT, enc_commit, dec_commit),
4091 PROC(OPEN, enc_open, dec_open),
4092 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4093 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4094 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4095 PROC(CLOSE, enc_close, dec_close),
4096 PROC(SETATTR, enc_setattr, dec_setattr),
4097 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4098 PROC(RENEW, enc_renew, dec_renew),
4099 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4100 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4101 PROC(LOCK, enc_lock, dec_lock),
4102 PROC(LOCKT, enc_lockt, dec_lockt),
4103 PROC(LOCKU, enc_locku, dec_locku),
4104 PROC(ACCESS, enc_access, dec_access),
4105 PROC(GETATTR, enc_getattr, dec_getattr),
4106 PROC(LOOKUP, enc_lookup, dec_lookup),
4107 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4108 PROC(REMOVE, enc_remove, dec_remove),
4109 PROC(RENAME, enc_rename, dec_rename),
4110 PROC(LINK, enc_link, dec_link),
4111 PROC(SYMLINK, enc_symlink, dec_symlink),
4112 PROC(CREATE, enc_create, dec_create),
4113 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4114 PROC(STATFS, enc_statfs, dec_statfs),
4115 PROC(READLINK, enc_readlink, dec_readlink),
4116 PROC(READDIR, enc_readdir, dec_readdir),
4117 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4118 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4119 PROC(GETACL, enc_getacl, dec_getacl),
4122 struct rpc_version nfs_version4 = {
4124 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
4125 .procs = nfs4_procedures