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 nfs4_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 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
91 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
92 /* This is based on getfattr, which uses the most attributes: */
93 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
94 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
95 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
96 nfs4_fattr_value_maxsz)
97 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
98 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
99 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
100 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
101 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
102 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
103 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
104 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
105 #define decode_renew_maxsz (op_decode_hdr_maxsz)
106 #define encode_setclientid_maxsz \
107 (op_encode_hdr_maxsz + \
108 4 /*server->ip_addr*/ + \
111 6 + (NFS4_VERIFIER_SIZE >> 2))
112 #define decode_setclientid_maxsz \
113 (op_decode_hdr_maxsz + \
115 1024) /* large value for CLID_INUSE */
116 #define encode_setclientid_confirm_maxsz \
117 (op_encode_hdr_maxsz + \
118 3 + (NFS4_VERIFIER_SIZE >> 2))
119 #define decode_setclientid_confirm_maxsz \
120 (op_decode_hdr_maxsz)
121 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
122 1 + ((3 + NFS4_FHSIZE) >> 2))
123 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
125 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
127 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
128 #define encode_link_maxsz (op_encode_hdr_maxsz + \
130 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
131 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
132 1 + nfs4_name_maxsz + \
135 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
136 #define encode_create_maxsz (op_encode_hdr_maxsz + \
137 2 + nfs4_name_maxsz + \
139 #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
140 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
141 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
142 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
143 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
144 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
145 encode_putfh_maxsz + \
146 op_encode_hdr_maxsz + 7)
147 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
148 decode_putfh_maxsz + \
149 op_decode_hdr_maxsz + 2)
150 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
151 encode_putfh_maxsz + \
153 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
154 decode_putfh_maxsz + \
156 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
157 encode_putfh_maxsz + \
158 op_encode_hdr_maxsz + 9)
159 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
160 decode_putfh_maxsz + \
161 op_decode_hdr_maxsz + 2)
162 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
163 encode_putfh_maxsz + \
164 op_encode_hdr_maxsz + 8 + \
165 encode_getattr_maxsz)
166 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
167 decode_putfh_maxsz + \
168 op_decode_hdr_maxsz + 4 + \
169 decode_getattr_maxsz)
170 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
171 encode_putfh_maxsz + \
172 op_encode_hdr_maxsz + 3 + \
173 encode_getattr_maxsz)
174 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
175 decode_putfh_maxsz + \
176 op_decode_hdr_maxsz + 2 + \
177 decode_getattr_maxsz)
178 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
179 encode_putfh_maxsz + \
180 op_encode_hdr_maxsz + \
182 encode_getattr_maxsz + \
184 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
185 decode_putfh_maxsz + \
186 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
187 decode_getattr_maxsz + \
189 #define NFS4_enc_open_confirm_sz \
190 (compound_encode_hdr_maxsz + \
191 encode_putfh_maxsz + \
192 op_encode_hdr_maxsz + 5)
193 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
194 decode_putfh_maxsz + \
195 op_decode_hdr_maxsz + 4)
196 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
197 encode_putfh_maxsz + \
198 op_encode_hdr_maxsz + \
200 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
201 decode_putfh_maxsz + \
202 op_decode_hdr_maxsz + \
204 #define NFS4_enc_open_downgrade_sz \
205 (compound_encode_hdr_maxsz + \
206 encode_putfh_maxsz + \
207 op_encode_hdr_maxsz + 7 + \
208 encode_getattr_maxsz)
209 #define NFS4_dec_open_downgrade_sz \
210 (compound_decode_hdr_maxsz + \
211 decode_putfh_maxsz + \
212 op_decode_hdr_maxsz + 4 + \
213 decode_getattr_maxsz)
214 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
215 encode_putfh_maxsz + \
216 op_encode_hdr_maxsz + 5 + \
217 encode_getattr_maxsz)
218 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
219 decode_putfh_maxsz + \
220 op_decode_hdr_maxsz + 4 + \
221 decode_getattr_maxsz)
222 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
223 encode_putfh_maxsz + \
224 op_encode_hdr_maxsz + 4 + \
226 encode_getattr_maxsz)
227 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
228 decode_putfh_maxsz + \
229 op_decode_hdr_maxsz + 3 + \
231 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
232 encode_putfh_maxsz + \
234 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
235 decode_putfh_maxsz + \
237 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
239 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
241 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
242 encode_setclientid_maxsz)
243 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
244 decode_setclientid_maxsz)
245 #define NFS4_enc_setclientid_confirm_sz \
246 (compound_encode_hdr_maxsz + \
247 encode_setclientid_confirm_maxsz + \
248 encode_putrootfh_maxsz + \
250 #define NFS4_dec_setclientid_confirm_sz \
251 (compound_decode_hdr_maxsz + \
252 decode_setclientid_confirm_maxsz + \
253 decode_putrootfh_maxsz + \
255 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
256 encode_putfh_maxsz + \
257 encode_getattr_maxsz + \
258 op_encode_hdr_maxsz + \
262 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
263 decode_putfh_maxsz + \
264 decode_getattr_maxsz + \
265 op_decode_hdr_maxsz + \
268 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
269 encode_putfh_maxsz + \
270 encode_getattr_maxsz + \
271 op_encode_hdr_maxsz + \
274 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
275 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
276 encode_putfh_maxsz + \
277 encode_getattr_maxsz + \
278 op_encode_hdr_maxsz + \
280 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
281 decode_putfh_maxsz + \
282 decode_getattr_maxsz + \
283 op_decode_hdr_maxsz + 4)
284 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
285 encode_putfh_maxsz + \
286 op_encode_hdr_maxsz + 1)
287 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
288 decode_putfh_maxsz + \
289 op_decode_hdr_maxsz + 2)
290 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
291 encode_putfh_maxsz + \
292 encode_getattr_maxsz)
293 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
294 decode_putfh_maxsz + \
295 decode_getattr_maxsz)
296 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
297 encode_putfh_maxsz + \
298 encode_lookup_maxsz + \
299 encode_getattr_maxsz + \
301 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
302 decode_putfh_maxsz + \
303 op_decode_hdr_maxsz + \
304 decode_getattr_maxsz + \
306 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
307 encode_putrootfh_maxsz + \
308 encode_getattr_maxsz + \
310 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
311 decode_putrootfh_maxsz + \
312 decode_getattr_maxsz + \
314 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
315 encode_putfh_maxsz + \
316 encode_remove_maxsz + \
317 encode_getattr_maxsz)
318 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
319 decode_putfh_maxsz + \
320 op_decode_hdr_maxsz + 5 + \
321 decode_getattr_maxsz)
322 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
323 encode_putfh_maxsz + \
324 encode_savefh_maxsz + \
325 encode_putfh_maxsz + \
326 encode_rename_maxsz + \
327 encode_getattr_maxsz + \
328 encode_restorefh_maxsz + \
329 encode_getattr_maxsz)
330 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
331 decode_putfh_maxsz + \
332 decode_savefh_maxsz + \
333 decode_putfh_maxsz + \
334 decode_rename_maxsz + \
335 decode_getattr_maxsz + \
336 decode_restorefh_maxsz + \
337 decode_getattr_maxsz)
338 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
339 encode_putfh_maxsz + \
340 encode_savefh_maxsz + \
341 encode_putfh_maxsz + \
342 encode_link_maxsz + \
343 decode_getattr_maxsz + \
344 encode_restorefh_maxsz + \
345 decode_getattr_maxsz)
346 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
347 decode_putfh_maxsz + \
348 decode_savefh_maxsz + \
349 decode_putfh_maxsz + \
350 decode_link_maxsz + \
351 decode_getattr_maxsz + \
352 decode_restorefh_maxsz + \
353 decode_getattr_maxsz)
354 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
355 encode_putfh_maxsz + \
356 encode_symlink_maxsz + \
357 encode_getattr_maxsz + \
359 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
360 decode_putfh_maxsz + \
361 decode_symlink_maxsz + \
362 decode_getattr_maxsz + \
364 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
365 encode_putfh_maxsz + \
366 encode_savefh_maxsz + \
367 encode_create_maxsz + \
368 encode_getfh_maxsz + \
369 encode_getattr_maxsz + \
370 encode_restorefh_maxsz + \
371 encode_getattr_maxsz)
372 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
373 decode_putfh_maxsz + \
374 decode_savefh_maxsz + \
375 decode_create_maxsz + \
376 decode_getfh_maxsz + \
377 decode_getattr_maxsz + \
378 decode_restorefh_maxsz + \
379 decode_getattr_maxsz)
380 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
381 encode_putfh_maxsz + \
382 encode_getattr_maxsz)
383 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
384 decode_putfh_maxsz + \
385 decode_getattr_maxsz)
386 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
387 encode_putfh_maxsz + \
388 encode_getattr_maxsz)
389 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
390 decode_putfh_maxsz + \
391 op_decode_hdr_maxsz + 12)
392 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
393 encode_putfh_maxsz + \
394 encode_getattr_maxsz)
395 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
396 decode_putfh_maxsz + \
397 decode_getattr_maxsz)
398 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
399 encode_putfh_maxsz + \
400 encode_delegreturn_maxsz + \
401 encode_getattr_maxsz)
402 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
403 decode_delegreturn_maxsz + \
404 decode_getattr_maxsz)
405 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
406 encode_putfh_maxsz + \
407 encode_getattr_maxsz)
408 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
409 decode_putfh_maxsz + \
410 op_decode_hdr_maxsz + \
411 nfs4_fattr_bitmap_maxsz + 1)
412 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
413 encode_putfh_maxsz + \
414 op_encode_hdr_maxsz + 4 + \
415 nfs4_fattr_bitmap_maxsz + 1)
416 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
417 decode_putfh_maxsz + \
418 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
419 #define NFS4_enc_fs_locations_sz \
420 (compound_encode_hdr_maxsz + \
421 encode_putfh_maxsz + \
422 encode_getattr_maxsz)
423 #define NFS4_dec_fs_locations_sz \
424 (compound_decode_hdr_maxsz + \
425 decode_putfh_maxsz + \
426 op_decode_hdr_maxsz + \
427 nfs4_fattr_bitmap_maxsz)
431 unsigned int nfs2type;
439 { S_IFSOCK, NFSOCK },
445 struct compound_hdr {
453 * START OF "GENERIC" ENCODE ROUTINES.
454 * These may look a little ugly since they are imported from a "generic"
455 * set of XDR encode/decode routines which are intended to be shared by
456 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
458 * If the pain of reading these is too great, it should be a straightforward
459 * task to translate them into Linux-specific versions which are more
460 * consistent with the style used in NFSv2/v3...
462 #define WRITE32(n) *p++ = htonl(n)
463 #define WRITE64(n) do { \
464 *p++ = htonl((uint32_t)((n) >> 32)); \
465 *p++ = htonl((uint32_t)(n)); \
467 #define WRITEMEM(ptr,nbytes) do { \
468 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
471 #define RESERVE_SPACE(nbytes) do { \
472 p = xdr_reserve_space(xdr, nbytes); \
473 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
477 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
481 p = xdr_reserve_space(xdr, 4 + len);
483 xdr_encode_opaque(p, str, len);
486 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
490 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
491 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
492 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
493 WRITE32(hdr->taglen);
494 WRITEMEM(hdr->tag, hdr->taglen);
495 WRITE32(NFS4_MINOR_VERSION);
500 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
504 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
506 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
509 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
511 char owner_name[IDMAP_NAMESZ];
512 char owner_group[IDMAP_NAMESZ];
513 int owner_namelen = 0;
514 int owner_grouplen = 0;
523 * We reserve enough space to write the entire attribute buffer at once.
524 * In the worst-case, this would be
525 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
526 * = 36 bytes, plus any contribution from variable-length fields
527 * such as owner/group.
532 if (iap->ia_valid & ATTR_SIZE)
534 if (iap->ia_valid & ATTR_MODE)
536 if (iap->ia_valid & ATTR_UID) {
537 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
538 if (owner_namelen < 0) {
539 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
542 strcpy(owner_name, "nobody");
543 owner_namelen = sizeof("nobody") - 1;
546 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
548 if (iap->ia_valid & ATTR_GID) {
549 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
550 if (owner_grouplen < 0) {
551 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
553 strcpy(owner_group, "nobody");
554 owner_grouplen = sizeof("nobody") - 1;
557 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
559 if (iap->ia_valid & ATTR_ATIME_SET)
561 else if (iap->ia_valid & ATTR_ATIME)
563 if (iap->ia_valid & ATTR_MTIME_SET)
565 else if (iap->ia_valid & ATTR_MTIME)
570 * We write the bitmap length now, but leave the bitmap and the attribute
571 * buffer length to be backfilled at the end of this routine.
577 if (iap->ia_valid & ATTR_SIZE) {
578 bmval0 |= FATTR4_WORD0_SIZE;
579 WRITE64(iap->ia_size);
581 if (iap->ia_valid & ATTR_MODE) {
582 bmval1 |= FATTR4_WORD1_MODE;
583 WRITE32(iap->ia_mode & S_IALLUGO);
585 if (iap->ia_valid & ATTR_UID) {
586 bmval1 |= FATTR4_WORD1_OWNER;
587 WRITE32(owner_namelen);
588 WRITEMEM(owner_name, owner_namelen);
590 if (iap->ia_valid & ATTR_GID) {
591 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
592 WRITE32(owner_grouplen);
593 WRITEMEM(owner_group, owner_grouplen);
595 if (iap->ia_valid & ATTR_ATIME_SET) {
596 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
597 WRITE32(NFS4_SET_TO_CLIENT_TIME);
599 WRITE32(iap->ia_mtime.tv_sec);
600 WRITE32(iap->ia_mtime.tv_nsec);
602 else if (iap->ia_valid & ATTR_ATIME) {
603 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
604 WRITE32(NFS4_SET_TO_SERVER_TIME);
606 if (iap->ia_valid & ATTR_MTIME_SET) {
607 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
608 WRITE32(NFS4_SET_TO_CLIENT_TIME);
610 WRITE32(iap->ia_mtime.tv_sec);
611 WRITE32(iap->ia_mtime.tv_nsec);
613 else if (iap->ia_valid & ATTR_MTIME) {
614 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
615 WRITE32(NFS4_SET_TO_SERVER_TIME);
619 * Now we backfill the bitmap and the attribute buffer length.
621 if (len != ((char *)p - (char *)q) + 4) {
622 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
623 len, ((char *)p - (char *)q) + 4);
626 len = (char *)p - (char *)q - 12;
627 *q++ = htonl(bmval0);
628 *q++ = htonl(bmval1);
636 static int encode_access(struct xdr_stream *xdr, u32 access)
647 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
651 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
653 WRITE32(arg->seqid->sequence->counter);
654 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
659 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
665 WRITE64(args->offset);
666 WRITE32(args->count);
671 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
677 WRITE32(create->ftype);
679 switch (create->ftype) {
682 WRITE32(create->u.symlink.len);
683 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
686 case NF4BLK: case NF4CHR:
688 WRITE32(create->u.device.specdata1);
689 WRITE32(create->u.device.specdata2);
696 RESERVE_SPACE(4 + create->name->len);
697 WRITE32(create->name->len);
698 WRITEMEM(create->name->name, create->name->len);
700 return encode_attrs(xdr, create->attrs, create->server);
703 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
714 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
726 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
728 return encode_getattr_two(xdr,
729 bitmask[0] & nfs4_fattr_bitmap[0],
730 bitmask[1] & nfs4_fattr_bitmap[1]);
733 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
735 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
736 bitmask[1] & nfs4_fsinfo_bitmap[1]);
739 static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
741 return encode_getattr_two(xdr,
742 bitmask[0] & nfs4_fs_locations_bitmap[0],
743 bitmask[1] & nfs4_fs_locations_bitmap[1]);
746 static int encode_getfh(struct xdr_stream *xdr)
756 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
760 RESERVE_SPACE(8 + name->len);
763 WRITEMEM(name->name, name->len);
768 static inline int nfs4_lock_type(struct file_lock *fl, int block)
770 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
771 return block ? NFS4_READW_LT : NFS4_READ_LT;
772 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
775 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
777 if (fl->fl_end == OFFSET_MAX)
779 return fl->fl_end - fl->fl_start + 1;
783 * opcode,type,reclaim,offset,length,new_lock_owner = 32
784 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
786 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
792 WRITE32(nfs4_lock_type(args->fl, args->block));
793 WRITE32(args->reclaim);
794 WRITE64(args->fl->fl_start);
795 WRITE64(nfs4_lock_length(args->fl));
796 WRITE32(args->new_lock_owner);
797 if (args->new_lock_owner){
798 RESERVE_SPACE(4+NFS4_STATEID_SIZE+20);
799 WRITE32(args->open_seqid->sequence->counter);
800 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
801 WRITE32(args->lock_seqid->sequence->counter);
802 WRITE64(args->lock_owner.clientid);
804 WRITE32(args->lock_owner.id);
807 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
808 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
809 WRITE32(args->lock_seqid->sequence->counter);
815 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
821 WRITE32(nfs4_lock_type(args->fl, 0));
822 WRITE64(args->fl->fl_start);
823 WRITE64(nfs4_lock_length(args->fl));
824 WRITE64(args->lock_owner.clientid);
826 WRITE32(args->lock_owner.id);
831 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
835 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
837 WRITE32(nfs4_lock_type(args->fl, 0));
838 WRITE32(args->seqid->sequence->counter);
839 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
840 WRITE64(args->fl->fl_start);
841 WRITE64(nfs4_lock_length(args->fl));
846 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
851 RESERVE_SPACE(8 + len);
854 WRITEMEM(name->name, len);
859 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
864 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
866 WRITE32(NFS4_SHARE_ACCESS_READ);
869 WRITE32(NFS4_SHARE_ACCESS_WRITE);
871 case FMODE_READ|FMODE_WRITE:
872 WRITE32(NFS4_SHARE_ACCESS_BOTH);
877 WRITE32(0); /* for linux, share_deny = 0 always */
880 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
884 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
889 WRITE32(arg->seqid->sequence->counter);
890 encode_share_access(xdr, arg->open_flags);
892 WRITE64(arg->clientid);
897 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
902 switch(arg->open_flags & O_EXCL) {
904 WRITE32(NFS4_CREATE_UNCHECKED);
905 encode_attrs(xdr, arg->u.attrs, arg->server);
908 WRITE32(NFS4_CREATE_EXCLUSIVE);
909 encode_nfs4_verifier(xdr, &arg->u.verifier);
913 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
918 switch (arg->open_flags & O_CREAT) {
920 WRITE32(NFS4_OPEN_NOCREATE);
923 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
924 WRITE32(NFS4_OPEN_CREATE);
925 encode_createmode(xdr, arg);
929 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
934 switch (delegation_type) {
936 WRITE32(NFS4_OPEN_DELEGATE_NONE);
939 WRITE32(NFS4_OPEN_DELEGATE_READ);
941 case FMODE_WRITE|FMODE_READ:
942 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
949 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
954 WRITE32(NFS4_OPEN_CLAIM_NULL);
955 encode_string(xdr, name->len, name->name);
958 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
963 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
964 encode_delegation_type(xdr, type);
967 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
971 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
972 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
973 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
974 encode_string(xdr, name->len, name->name);
977 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
979 encode_openhdr(xdr, arg);
980 encode_opentype(xdr, arg);
981 switch (arg->claim) {
982 case NFS4_OPEN_CLAIM_NULL:
983 encode_claim_null(xdr, arg->name);
985 case NFS4_OPEN_CLAIM_PREVIOUS:
986 encode_claim_previous(xdr, arg->u.delegation_type);
988 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
989 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
997 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
1001 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1002 WRITE32(OP_OPEN_CONFIRM);
1003 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1004 WRITE32(arg->seqid->sequence->counter);
1009 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1013 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1014 WRITE32(OP_OPEN_DOWNGRADE);
1015 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1016 WRITE32(arg->seqid->sequence->counter);
1017 encode_share_access(xdr, arg->open_flags);
1022 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1027 RESERVE_SPACE(8 + len);
1030 WRITEMEM(fh->data, len);
1035 static int encode_putrootfh(struct xdr_stream *xdr)
1040 WRITE32(OP_PUTROOTFH);
1045 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1047 nfs4_stateid stateid;
1050 RESERVE_SPACE(NFS4_STATEID_SIZE);
1051 if (ctx->state != NULL) {
1052 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1053 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1055 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1058 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1065 encode_stateid(xdr, args->context);
1068 WRITE64(args->offset);
1069 WRITE32(args->count);
1074 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1076 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1077 uint32_t attrs[2] = {
1078 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1079 FATTR4_WORD1_MOUNTED_ON_FILEID,
1084 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1085 WRITE32(OP_READDIR);
1086 WRITE64(readdir->cookie);
1087 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1088 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1089 WRITE32(readdir->count);
1091 /* Switch to mounted_on_fileid if the server supports it */
1092 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1093 attrs[0] &= ~FATTR4_WORD0_FILEID;
1095 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1096 WRITE32(attrs[0] & readdir->bitmask[0]);
1097 WRITE32(attrs[1] & readdir->bitmask[1]);
1098 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1100 (unsigned long long)readdir->cookie,
1101 ((u32 *)readdir->verifier.data)[0],
1102 ((u32 *)readdir->verifier.data)[1],
1103 attrs[0] & readdir->bitmask[0],
1104 attrs[1] & readdir->bitmask[1]);
1106 /* set up reply kvec
1107 * toplevel_status + taglen + rescount + OP_PUTFH + status
1108 * + OP_READDIR + status + verifer(2) = 9
1110 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1111 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1112 readdir->pgbase, readdir->count);
1113 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1114 __FUNCTION__, replen, readdir->pages,
1115 readdir->pgbase, readdir->count);
1120 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1122 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1123 unsigned int replen;
1127 WRITE32(OP_READLINK);
1129 /* set up reply kvec
1130 * toplevel_status + taglen + rescount + OP_PUTFH + status
1131 * + OP_READLINK + status + string length = 8
1133 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1134 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1135 readlink->pgbase, readlink->pglen);
1140 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1144 RESERVE_SPACE(8 + name->len);
1147 WRITEMEM(name->name, name->len);
1152 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1156 RESERVE_SPACE(8 + oldname->len);
1158 WRITE32(oldname->len);
1159 WRITEMEM(oldname->name, oldname->len);
1161 RESERVE_SPACE(4 + newname->len);
1162 WRITE32(newname->len);
1163 WRITEMEM(newname->name, newname->len);
1168 static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
1174 WRITE64(client_stateid->cl_clientid);
1180 encode_restorefh(struct xdr_stream *xdr)
1185 WRITE32(OP_RESTOREFH);
1191 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1195 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1196 WRITE32(OP_SETATTR);
1197 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1200 WRITE32(FATTR4_WORD0_ACL);
1201 if (arg->acl_len % 4)
1204 WRITE32(arg->acl_len);
1205 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1210 encode_savefh(struct xdr_stream *xdr)
1220 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1225 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1226 WRITE32(OP_SETATTR);
1227 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1229 if ((status = encode_attrs(xdr, arg->iap, server)))
1235 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1239 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1240 WRITE32(OP_SETCLIENTID);
1241 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1243 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1245 WRITE32(setclientid->sc_prog);
1246 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1247 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1249 WRITE32(setclientid->sc_cb_ident);
1254 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
1258 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1259 WRITE32(OP_SETCLIENTID_CONFIRM);
1260 WRITE64(client_state->cl_clientid);
1261 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1266 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1273 encode_stateid(xdr, args->context);
1276 WRITE64(args->offset);
1277 WRITE32(args->stable);
1278 WRITE32(args->count);
1280 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1285 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1289 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1291 WRITE32(OP_DELEGRETURN);
1292 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1297 * END OF "GENERIC" ENCODE ROUTINES.
1301 * Encode an ACCESS request
1303 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1305 struct xdr_stream xdr;
1306 struct compound_hdr hdr = {
1311 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1312 encode_compound_hdr(&xdr, &hdr);
1313 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1314 status = encode_access(&xdr, args->access);
1319 * Encode LOOKUP request
1321 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_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_lookup(&xdr, args->name)) != 0)
1335 if ((status = encode_getfh(&xdr)) != 0)
1337 status = encode_getfattr(&xdr, args->bitmask);
1343 * Encode LOOKUP_ROOT request
1345 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1347 struct xdr_stream xdr;
1348 struct compound_hdr hdr = {
1353 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1354 encode_compound_hdr(&xdr, &hdr);
1355 if ((status = encode_putrootfh(&xdr)) != 0)
1357 if ((status = encode_getfh(&xdr)) == 0)
1358 status = encode_getfattr(&xdr, args->bitmask);
1364 * Encode REMOVE request
1366 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs4_remove_arg *args)
1368 struct xdr_stream xdr;
1369 struct compound_hdr hdr = {
1374 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1375 encode_compound_hdr(&xdr, &hdr);
1376 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1378 if ((status = encode_remove(&xdr, args->name)) != 0)
1380 status = encode_getfattr(&xdr, args->bitmask);
1386 * Encode RENAME request
1388 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1390 struct xdr_stream xdr;
1391 struct compound_hdr hdr = {
1396 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1397 encode_compound_hdr(&xdr, &hdr);
1398 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1400 if ((status = encode_savefh(&xdr)) != 0)
1402 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1404 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1406 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1408 if ((status = encode_restorefh(&xdr)) != 0)
1410 status = encode_getfattr(&xdr, args->bitmask);
1416 * Encode LINK request
1418 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1420 struct xdr_stream xdr;
1421 struct compound_hdr hdr = {
1426 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1427 encode_compound_hdr(&xdr, &hdr);
1428 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1430 if ((status = encode_savefh(&xdr)) != 0)
1432 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1434 if ((status = encode_link(&xdr, args->name)) != 0)
1436 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1438 if ((status = encode_restorefh(&xdr)) != 0)
1440 status = encode_getfattr(&xdr, args->bitmask);
1446 * Encode CREATE request
1448 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1450 struct xdr_stream xdr;
1451 struct compound_hdr hdr = {
1456 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1457 encode_compound_hdr(&xdr, &hdr);
1458 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1460 if ((status = encode_savefh(&xdr)) != 0)
1462 if ((status = encode_create(&xdr, args)) != 0)
1464 if ((status = encode_getfh(&xdr)) != 0)
1466 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1468 if ((status = encode_restorefh(&xdr)) != 0)
1470 status = encode_getfattr(&xdr, args->bitmask);
1476 * Encode SYMLINK request
1478 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1480 return nfs4_xdr_enc_create(req, p, args);
1484 * Encode GETATTR request
1486 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1488 struct xdr_stream xdr;
1489 struct compound_hdr hdr = {
1494 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1495 encode_compound_hdr(&xdr, &hdr);
1496 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1497 status = encode_getfattr(&xdr, args->bitmask);
1502 * Encode a CLOSE request
1504 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1506 struct xdr_stream xdr;
1507 struct compound_hdr hdr = {
1512 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1513 encode_compound_hdr(&xdr, &hdr);
1514 status = encode_putfh(&xdr, args->fh);
1517 status = encode_close(&xdr, args);
1520 status = encode_getfattr(&xdr, args->bitmask);
1526 * Encode an OPEN request
1528 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1530 struct xdr_stream xdr;
1531 struct compound_hdr hdr = {
1536 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1537 encode_compound_hdr(&xdr, &hdr);
1538 status = encode_putfh(&xdr, args->fh);
1541 status = encode_savefh(&xdr);
1544 status = encode_open(&xdr, args);
1547 status = encode_getfh(&xdr);
1550 status = encode_getfattr(&xdr, args->bitmask);
1553 status = encode_restorefh(&xdr);
1556 status = encode_getfattr(&xdr, args->bitmask);
1562 * Encode an OPEN_CONFIRM request
1564 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1566 struct xdr_stream xdr;
1567 struct compound_hdr hdr = {
1572 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1573 encode_compound_hdr(&xdr, &hdr);
1574 status = encode_putfh(&xdr, args->fh);
1577 status = encode_open_confirm(&xdr, args);
1583 * Encode an OPEN request with no attributes.
1585 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1587 struct xdr_stream xdr;
1588 struct compound_hdr hdr = {
1593 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1594 encode_compound_hdr(&xdr, &hdr);
1595 status = encode_putfh(&xdr, args->fh);
1598 status = encode_open(&xdr, args);
1601 status = encode_getfattr(&xdr, args->bitmask);
1607 * Encode an OPEN_DOWNGRADE request
1609 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1611 struct xdr_stream xdr;
1612 struct compound_hdr hdr = {
1617 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1618 encode_compound_hdr(&xdr, &hdr);
1619 status = encode_putfh(&xdr, args->fh);
1622 status = encode_open_downgrade(&xdr, args);
1625 status = encode_getfattr(&xdr, args->bitmask);
1631 * Encode a LOCK request
1633 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1635 struct xdr_stream xdr;
1636 struct compound_hdr hdr = {
1641 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1642 encode_compound_hdr(&xdr, &hdr);
1643 status = encode_putfh(&xdr, args->fh);
1646 status = encode_lock(&xdr, args);
1652 * Encode a LOCKT request
1654 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1656 struct xdr_stream xdr;
1657 struct compound_hdr hdr = {
1662 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1663 encode_compound_hdr(&xdr, &hdr);
1664 status = encode_putfh(&xdr, args->fh);
1667 status = encode_lockt(&xdr, args);
1673 * Encode a LOCKU request
1675 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1677 struct xdr_stream xdr;
1678 struct compound_hdr hdr = {
1683 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1684 encode_compound_hdr(&xdr, &hdr);
1685 status = encode_putfh(&xdr, args->fh);
1688 status = encode_locku(&xdr, args);
1694 * Encode a READLINK request
1696 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1698 struct xdr_stream xdr;
1699 struct compound_hdr hdr = {
1704 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1705 encode_compound_hdr(&xdr, &hdr);
1706 status = encode_putfh(&xdr, args->fh);
1709 status = encode_readlink(&xdr, args, req);
1715 * Encode a READDIR request
1717 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1719 struct xdr_stream xdr;
1720 struct compound_hdr hdr = {
1725 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1726 encode_compound_hdr(&xdr, &hdr);
1727 status = encode_putfh(&xdr, args->fh);
1730 status = encode_readdir(&xdr, args, req);
1736 * Encode a READ request
1738 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1740 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
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, args->fh);
1752 status = encode_read(&xdr, args);
1756 /* set up reply kvec
1757 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1758 * + OP_READ + status + eof + datalen = 9
1760 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1761 xdr_inline_pages(&req->rq_rcv_buf, replen,
1762 args->pages, args->pgbase, args->count);
1768 * Encode an SETATTR request
1770 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1773 struct xdr_stream xdr;
1774 struct compound_hdr hdr = {
1779 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1780 encode_compound_hdr(&xdr, &hdr);
1781 status = encode_putfh(&xdr, args->fh);
1784 status = encode_setattr(&xdr, args, args->server);
1787 status = encode_getfattr(&xdr, args->bitmask);
1793 * Encode a GETACL request
1796 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1797 struct nfs_getaclargs *args)
1799 struct xdr_stream xdr;
1800 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1801 struct compound_hdr hdr = {
1806 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1807 encode_compound_hdr(&xdr, &hdr);
1808 status = encode_putfh(&xdr, args->fh);
1811 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1812 /* set up reply buffer: */
1813 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1814 xdr_inline_pages(&req->rq_rcv_buf, replen,
1815 args->acl_pages, args->acl_pgbase, args->acl_len);
1821 * Encode a WRITE request
1823 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1825 struct xdr_stream xdr;
1826 struct compound_hdr hdr = {
1831 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1832 encode_compound_hdr(&xdr, &hdr);
1833 status = encode_putfh(&xdr, args->fh);
1836 status = encode_write(&xdr, args);
1839 status = encode_getfattr(&xdr, args->bitmask);
1847 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1849 struct xdr_stream xdr;
1850 struct compound_hdr hdr = {
1855 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1856 encode_compound_hdr(&xdr, &hdr);
1857 status = encode_putfh(&xdr, args->fh);
1860 status = encode_commit(&xdr, args);
1863 status = encode_getfattr(&xdr, args->bitmask);
1871 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1873 struct xdr_stream xdr;
1874 struct compound_hdr hdr = {
1879 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1880 encode_compound_hdr(&xdr, &hdr);
1881 status = encode_putfh(&xdr, args->fh);
1883 status = encode_fsinfo(&xdr, args->bitmask);
1888 * a PATHCONF request
1890 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1892 struct xdr_stream xdr;
1893 struct compound_hdr hdr = {
1898 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1899 encode_compound_hdr(&xdr, &hdr);
1900 status = encode_putfh(&xdr, args->fh);
1902 status = encode_getattr_one(&xdr,
1903 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1910 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
1912 struct xdr_stream xdr;
1913 struct compound_hdr hdr = {
1918 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1919 encode_compound_hdr(&xdr, &hdr);
1920 status = encode_putfh(&xdr, args->fh);
1922 status = encode_getattr_two(&xdr,
1923 args->bitmask[0] & nfs4_statfs_bitmap[0],
1924 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1929 * GETATTR_BITMAP request
1931 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
1933 struct xdr_stream xdr;
1934 struct compound_hdr hdr = {
1939 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1940 encode_compound_hdr(&xdr, &hdr);
1941 status = encode_putfh(&xdr, fhandle);
1943 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1944 FATTR4_WORD0_LINK_SUPPORT|
1945 FATTR4_WORD0_SYMLINK_SUPPORT|
1946 FATTR4_WORD0_ACLSUPPORT);
1953 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1955 struct xdr_stream xdr;
1956 struct compound_hdr hdr = {
1960 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1961 encode_compound_hdr(&xdr, &hdr);
1962 return encode_renew(&xdr, clp);
1966 * a SETCLIENTID request
1968 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
1970 struct xdr_stream xdr;
1971 struct compound_hdr hdr = {
1975 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1976 encode_compound_hdr(&xdr, &hdr);
1977 return encode_setclientid(&xdr, sc);
1981 * a SETCLIENTID_CONFIRM request
1983 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1985 struct xdr_stream xdr;
1986 struct compound_hdr hdr = {
1989 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1992 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1993 encode_compound_hdr(&xdr, &hdr);
1994 status = encode_setclientid_confirm(&xdr, clp);
1996 status = encode_putrootfh(&xdr);
1998 status = encode_fsinfo(&xdr, lease_bitmap);
2003 * DELEGRETURN request
2005 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2007 struct xdr_stream xdr;
2008 struct compound_hdr hdr = {
2013 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2014 encode_compound_hdr(&xdr, &hdr);
2015 status = encode_putfh(&xdr, args->fhandle);
2018 status = encode_delegreturn(&xdr, args->stateid);
2021 status = encode_getfattr(&xdr, args->bitmask);
2027 * Encode FS_LOCATIONS request
2029 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2031 struct xdr_stream xdr;
2032 struct compound_hdr hdr = {
2035 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
2039 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2040 encode_compound_hdr(&xdr, &hdr);
2041 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2043 if ((status = encode_lookup(&xdr, args->name)) != 0)
2045 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
2048 * toplevel_status + OP_PUTFH + status
2049 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2051 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2052 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2059 * START OF "GENERIC" DECODE ROUTINES.
2060 * These may look a little ugly since they are imported from a "generic"
2061 * set of XDR encode/decode routines which are intended to be shared by
2062 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2064 * If the pain of reading these is too great, it should be a straightforward
2065 * task to translate them into Linux-specific versions which are more
2066 * consistent with the style used in NFSv2/v3...
2068 #define READ32(x) (x) = ntohl(*p++)
2069 #define READ64(x) do { \
2070 (x) = (u64)ntohl(*p++) << 32; \
2071 (x) |= ntohl(*p++); \
2073 #define READTIME(x) do { \
2075 (x.tv_sec) = ntohl(*p++); \
2076 (x.tv_nsec) = ntohl(*p++); \
2078 #define COPYMEM(x,nbytes) do { \
2079 memcpy((x), p, nbytes); \
2080 p += XDR_QUADLEN(nbytes); \
2083 #define READ_BUF(nbytes) do { \
2084 p = xdr_inline_decode(xdr, nbytes); \
2085 if (unlikely(!p)) { \
2086 printk(KERN_INFO "%s: prematurely hit end of receive" \
2087 " buffer\n", __FUNCTION__); \
2088 printk(KERN_INFO "%s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2089 __FUNCTION__, xdr->p, nbytes, xdr->end); \
2094 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2101 *string = (char *)p;
2105 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2110 READ32(hdr->status);
2111 READ32(hdr->taglen);
2113 READ_BUF(hdr->taglen + 4);
2114 hdr->tag = (char *)p;
2115 p += XDR_QUADLEN(hdr->taglen);
2120 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2128 if (opnum != expected) {
2130 "nfs4_decode_op_hdr: Server returned operation"
2131 " %d but we issued a request for %d\n",
2136 if (nfserr != NFS_OK)
2137 return -nfs4_stat_to_errno(nfserr);
2142 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2145 unsigned int strlen;
2149 return decode_opaque_inline(xdr, &strlen, &str);
2152 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2160 bitmap[0] = bitmap[1] = 0;
2161 READ_BUF((bmlen << 2));
2170 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2180 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2182 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2183 decode_attr_bitmap(xdr, bitmask);
2184 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2186 bitmask[0] = bitmask[1] = 0;
2187 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2191 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2196 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2198 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2201 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2202 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2205 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2207 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2211 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2216 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2218 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2221 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2223 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2224 (unsigned long long)*change);
2228 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2233 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2235 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2238 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2240 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2244 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2249 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2251 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2254 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2256 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2260 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2265 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2267 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2270 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2272 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2276 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2282 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2284 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2286 READ64(fsid->major);
2287 READ64(fsid->minor);
2288 bitmap[0] &= ~FATTR4_WORD0_FSID;
2290 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2291 (unsigned long long)fsid->major,
2292 (unsigned long long)fsid->minor);
2296 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2301 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2303 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2306 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2308 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2312 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2316 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2317 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2319 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2322 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2324 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2328 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2333 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2335 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2338 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2340 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2344 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2349 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2351 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2354 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2356 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2360 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2366 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2368 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2371 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2373 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2377 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2383 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2385 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2388 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2390 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2394 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2400 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2402 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2405 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2407 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2411 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2424 path->ncomponents = 0;
2425 while (path->ncomponents < n) {
2426 struct nfs4_string *component = &path->components[path->ncomponents];
2427 status = decode_opaque_inline(xdr, &component->len, &component->data);
2428 if (unlikely(status != 0))
2430 if (path->ncomponents != n)
2432 dprintk("%s", component->data);
2433 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2434 path->ncomponents++;
2436 dprintk("cannot parse %d components in path\n", n);
2444 /* a root pathname is sent as a zero component4 */
2445 path->ncomponents = 1;
2446 path->components[0].len=0;
2447 path->components[0].data=NULL;
2448 dprintk("path /\n");
2451 dprintk(" status %d", status);
2456 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2462 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2465 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2467 dprintk("%s: fsroot ", __FUNCTION__);
2468 status = decode_pathname(xdr, &res->fs_path);
2469 if (unlikely(status != 0))
2475 res->nlocations = 0;
2476 while (res->nlocations < n) {
2478 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2486 dprintk("%s: servers ", __FUNCTION__);
2487 while (loc->nservers < m) {
2488 struct nfs4_string *server = &loc->servers[loc->nservers];
2489 status = decode_opaque_inline(xdr, &server->len, &server->data);
2490 if (unlikely(status != 0))
2492 dprintk("%s ", server->data);
2493 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2497 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2498 for (i = loc->nservers; i < m; i++) {
2501 status = decode_opaque_inline(xdr, &len, &data);
2502 if (unlikely(status != 0))
2507 status = decode_pathname(xdr, &loc->rootpath);
2508 if (unlikely(status != 0))
2510 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2514 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2521 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2527 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2529 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2532 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2534 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2538 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2544 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2546 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2549 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2551 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2555 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2561 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2563 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2566 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2568 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2572 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2578 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2580 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2584 if (maxread > 0x7FFFFFFF)
2585 maxread = 0x7FFFFFFF;
2586 *res = (uint32_t)maxread;
2587 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2589 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2593 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2599 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2601 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2605 if (maxwrite > 0x7FFFFFFF)
2606 maxwrite = 0x7FFFFFFF;
2607 *res = (uint32_t)maxwrite;
2608 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2610 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2614 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2619 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2621 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2625 bitmap[1] &= ~FATTR4_WORD1_MODE;
2627 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2631 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2636 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2638 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2641 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2643 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2647 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2653 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2655 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2659 if (len < XDR_MAX_NETOBJ) {
2660 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2661 dprintk("%s: nfs_map_name_to_uid failed!\n",
2664 printk(KERN_WARNING "%s: name too long (%u)!\n",
2666 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2668 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2672 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2678 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2680 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2684 if (len < XDR_MAX_NETOBJ) {
2685 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2686 dprintk("%s: nfs_map_group_to_gid failed!\n",
2689 printk(KERN_WARNING "%s: name too long (%u)!\n",
2691 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2693 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2697 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2699 uint32_t major = 0, minor = 0;
2703 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2705 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2711 tmp = MKDEV(major, minor);
2712 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2714 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2716 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2720 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2726 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2728 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2731 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2733 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2737 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2743 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2745 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2748 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2750 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2754 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2760 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2762 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2765 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2767 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2771 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2776 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2778 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2781 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2783 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2784 (unsigned long long)*used);
2788 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2797 time->tv_sec = (time_t)sec;
2798 time->tv_nsec = (long)nsec;
2802 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2808 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2810 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2811 status = decode_attr_time(xdr, time);
2812 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2814 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2818 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2824 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2826 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2827 status = decode_attr_time(xdr, time);
2828 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2830 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2834 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2840 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2842 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2843 status = decode_attr_time(xdr, time);
2844 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2846 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2850 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2852 unsigned int attrwords = XDR_QUADLEN(attrlen);
2853 unsigned int nwords = xdr->p - savep;
2855 if (unlikely(attrwords != nwords)) {
2856 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2859 (attrwords < nwords) ? '<' : '>',
2866 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2871 READ32(cinfo->atomic);
2872 READ64(cinfo->before);
2873 READ64(cinfo->after);
2877 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2883 status = decode_op_hdr(xdr, OP_ACCESS);
2889 access->supported = supp;
2890 access->access = acc;
2894 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2899 status = decode_op_hdr(xdr, OP_CLOSE);
2902 READ_BUF(NFS4_STATEID_SIZE);
2903 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
2907 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2912 status = decode_op_hdr(xdr, OP_COMMIT);
2916 COPYMEM(res->verf->verifier, 8);
2920 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2926 status = decode_op_hdr(xdr, OP_CREATE);
2929 if ((status = decode_change_info(xdr, cinfo)))
2933 READ_BUF(bmlen << 2);
2937 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2944 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2946 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2948 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2950 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2952 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2954 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2956 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2958 status = verify_attr_len(xdr, savep, attrlen);
2960 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2964 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2971 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2973 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2975 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2978 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2980 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2982 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2984 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2986 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2988 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2991 status = verify_attr_len(xdr, savep, attrlen);
2993 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2997 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3004 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3006 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3008 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3011 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3013 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3016 status = verify_attr_len(xdr, savep, attrlen);
3018 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3022 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3028 int status, fmode = 0;
3031 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3033 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3036 fattr->bitmap[0] = bitmap[0];
3037 fattr->bitmap[1] = bitmap[1];
3039 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3043 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3045 fattr->type = nfs_type2fmt[type].nfs2type;
3046 fmode = nfs_type2fmt[type].mode;
3048 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3050 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3052 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
3054 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3056 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3057 struct nfs4_fs_locations,
3060 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3062 fattr->mode |= fmode;
3063 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3065 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
3067 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
3069 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3071 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3073 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3075 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3077 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3079 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3081 if (fattr->fileid == 0 && fileid != 0)
3082 fattr->fileid = fileid;
3083 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
3084 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
3086 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
3091 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3094 uint32_t attrlen, bitmap[2];
3097 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3099 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3101 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3104 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3106 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3108 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3110 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3112 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3113 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3115 fsinfo->wtpref = fsinfo->wtmax;
3117 status = verify_attr_len(xdr, savep, attrlen);
3119 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3123 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3129 status = decode_op_hdr(xdr, OP_GETFH);
3132 /* Zero handle first to allow comparisons */
3133 memset(fh, 0, sizeof(*fh));
3137 if (len > NFS4_FHSIZE)
3141 COPYMEM(fh->data, len);
3145 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3149 status = decode_op_hdr(xdr, OP_LINK);
3152 return decode_change_info(xdr, cinfo);
3156 * We create the owner, so we know a proper owner.id length is 4.
3158 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3160 uint64_t offset, length, clientid;
3162 uint32_t namelen, type;
3169 fl->fl_start = (loff_t)offset;
3170 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3171 if (length == ~(uint64_t)0)
3172 fl->fl_end = OFFSET_MAX;
3173 fl->fl_type = F_WRLCK;
3175 fl->fl_type = F_RDLCK;
3181 return -NFS4ERR_DENIED;
3184 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3189 status = decode_op_hdr(xdr, OP_LOCK);
3191 READ_BUF(NFS4_STATEID_SIZE);
3192 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3193 } else if (status == -NFS4ERR_DENIED)
3194 return decode_lock_denied(xdr, NULL);
3198 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3201 status = decode_op_hdr(xdr, OP_LOCKT);
3202 if (status == -NFS4ERR_DENIED)
3203 return decode_lock_denied(xdr, res->denied);
3207 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3212 status = decode_op_hdr(xdr, OP_LOCKU);
3214 READ_BUF(NFS4_STATEID_SIZE);
3215 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3220 static int decode_lookup(struct xdr_stream *xdr)
3222 return decode_op_hdr(xdr, OP_LOOKUP);
3225 /* This is too sick! */
3226 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3229 uint32_t limit_type, nblocks, blocksize;
3233 switch (limit_type) {
3240 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3245 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3248 uint32_t delegation_type;
3251 READ32(delegation_type);
3252 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3253 res->delegation_type = 0;
3256 READ_BUF(NFS4_STATEID_SIZE+4);
3257 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3258 READ32(res->do_recall);
3259 switch (delegation_type) {
3260 case NFS4_OPEN_DELEGATE_READ:
3261 res->delegation_type = FMODE_READ;
3263 case NFS4_OPEN_DELEGATE_WRITE:
3264 res->delegation_type = FMODE_WRITE|FMODE_READ;
3265 if (decode_space_limit(xdr, &res->maxsize) < 0)
3268 return decode_ace(xdr, NULL, res->server->nfs_client);
3271 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3274 uint32_t savewords, bmlen, i;
3277 status = decode_op_hdr(xdr, OP_OPEN);
3280 READ_BUF(NFS4_STATEID_SIZE);
3281 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3283 decode_change_info(xdr, &res->cinfo);
3286 READ32(res->rflags);
3291 READ_BUF(bmlen << 2);
3292 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3293 for (i = 0; i < savewords; ++i)
3294 READ32(res->attrset[i]);
3295 for (; i < NFS4_BITMAP_SIZE; i++)
3296 res->attrset[i] = 0;
3298 return decode_delegation(xdr, res);
3300 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
3304 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3309 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3312 READ_BUF(NFS4_STATEID_SIZE);
3313 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3317 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3322 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3325 READ_BUF(NFS4_STATEID_SIZE);
3326 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3330 static int decode_putfh(struct xdr_stream *xdr)
3332 return decode_op_hdr(xdr, OP_PUTFH);
3335 static int decode_putrootfh(struct xdr_stream *xdr)
3337 return decode_op_hdr(xdr, OP_PUTROOTFH);
3340 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3342 struct kvec *iov = req->rq_rcv_buf.head;
3344 uint32_t count, eof, recvd, hdrlen;
3347 status = decode_op_hdr(xdr, OP_READ);
3353 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3354 recvd = req->rq_rcv_buf.len - hdrlen;
3355 if (count > recvd) {
3356 printk(KERN_WARNING "NFS: server cheating in read reply: "
3357 "count %u > recvd %u\n", count, recvd);
3361 xdr_read_pages(xdr, count);
3367 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3369 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3370 struct page *page = *rcvbuf->pages;
3371 struct kvec *iov = rcvbuf->head;
3372 unsigned int nr, pglen = rcvbuf->page_len;
3373 __be32 *end, *entry, *p, *kaddr;
3374 uint32_t len, attrlen, xlen;
3375 int hdrlen, recvd, status;
3377 status = decode_op_hdr(xdr, OP_READDIR);
3381 COPYMEM(readdir->verifier.data, 8);
3382 dprintk("%s: verifier = 0x%x%x\n",
3384 ((u32 *)readdir->verifier.data)[0],
3385 ((u32 *)readdir->verifier.data)[1]);
3388 hdrlen = (char *) p - (char *) iov->iov_base;
3389 recvd = rcvbuf->len - hdrlen;
3392 xdr_read_pages(xdr, pglen);
3394 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3395 kaddr = p = kmap_atomic(page, KM_USER0);
3396 end = p + ((pglen + readdir->pgbase) >> 2);
3398 for (nr = 0; *p++; nr++) {
3401 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3402 p += 2; /* cookie */
3403 len = ntohl(*p++); /* filename length */
3404 if (len > NFS4_MAXNAMLEN) {
3405 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3408 xlen = XDR_QUADLEN(len);
3409 if (end - p < xlen + 1)
3411 dprintk("filename = %*s\n", len, (char *)p);
3413 len = ntohl(*p++); /* bitmap length */
3414 if (end - p < len + 1)
3417 attrlen = XDR_QUADLEN(ntohl(*p++));
3418 if (end - p < attrlen + 2)
3420 p += attrlen; /* attributes */
3423 if (!nr && (entry[0] != 0 || entry[1] == 0))
3426 kunmap_atomic(kaddr, KM_USER0);
3429 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3430 entry[0] = entry[1] = 0;
3431 /* truncate listing ? */
3433 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3438 kunmap_atomic(kaddr, KM_USER0);
3439 return -errno_NFSERR_IO;
3442 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3444 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3445 struct kvec *iov = rcvbuf->head;
3446 int hdrlen, len, recvd;
3451 status = decode_op_hdr(xdr, OP_READLINK);
3455 /* Convert length of symlink */
3458 if (len >= rcvbuf->page_len || len <= 0) {
3459 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3460 return -ENAMETOOLONG;
3462 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3463 recvd = req->rq_rcv_buf.len - hdrlen;
3465 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3466 "count %u > recvd %u\n", len, recvd);
3469 xdr_read_pages(xdr, len);
3471 * The XDR encode routine has set things up so that
3472 * the link text will be copied directly into the
3473 * buffer. We just have to do overflow-checking,
3474 * and and null-terminate the text (the VFS expects
3475 * null-termination).
3477 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3478 kaddr[len+rcvbuf->page_base] = '\0';
3479 kunmap_atomic(kaddr, KM_USER0);
3483 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3487 status = decode_op_hdr(xdr, OP_REMOVE);
3490 status = decode_change_info(xdr, cinfo);
3495 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3496 struct nfs4_change_info *new_cinfo)
3500 status = decode_op_hdr(xdr, OP_RENAME);
3503 if ((status = decode_change_info(xdr, old_cinfo)))
3505 status = decode_change_info(xdr, new_cinfo);
3510 static int decode_renew(struct xdr_stream *xdr)
3512 return decode_op_hdr(xdr, OP_RENEW);
3516 decode_restorefh(struct xdr_stream *xdr)
3518 return decode_op_hdr(xdr, OP_RESTOREFH);
3521 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3527 struct kvec *iov = req->rq_rcv_buf.head;
3531 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3533 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3535 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3538 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3540 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3543 /* We ignore &savep and don't do consistency checks on
3544 * the attr length. Let userspace figure it out.... */
3545 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3546 recvd = req->rq_rcv_buf.len - hdrlen;
3547 if (attrlen > recvd) {
3548 printk(KERN_WARNING "NFS: server cheating in getattr"
3549 " acl reply: attrlen %u > recvd %u\n",
3553 xdr_read_pages(xdr, attrlen);
3556 status = -EOPNOTSUPP;
3563 decode_savefh(struct xdr_stream *xdr)
3565 return decode_op_hdr(xdr, OP_SAVEFH);
3568 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3575 status = decode_op_hdr(xdr, OP_SETATTR);
3580 READ_BUF(bmlen << 2);
3584 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3592 if (opnum != OP_SETCLIENTID) {
3594 "nfs4_decode_setclientid: Server returned operation"
3599 if (nfserr == NFS_OK) {
3600 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3601 READ64(clp->cl_clientid);
3602 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3603 } else if (nfserr == NFSERR_CLID_INUSE) {
3606 /* skip netid string */
3611 /* skip uaddr string */
3615 return -NFSERR_CLID_INUSE;
3617 return -nfs4_stat_to_errno(nfserr);
3622 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3624 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3627 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3632 status = decode_op_hdr(xdr, OP_WRITE);
3638 READ32(res->verf->committed);
3639 COPYMEM(res->verf->verifier, 8);
3643 static int decode_delegreturn(struct xdr_stream *xdr)
3645 return decode_op_hdr(xdr, OP_DELEGRETURN);
3649 * Decode OPEN_DOWNGRADE response
3651 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3653 struct xdr_stream xdr;
3654 struct compound_hdr hdr;
3657 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3658 status = decode_compound_hdr(&xdr, &hdr);
3661 status = decode_putfh(&xdr);
3664 status = decode_open_downgrade(&xdr, res);
3667 decode_getfattr(&xdr, res->fattr, res->server);
3673 * END OF "GENERIC" DECODE ROUTINES.
3677 * Decode ACCESS response
3679 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3681 struct xdr_stream xdr;
3682 struct compound_hdr hdr;
3685 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3686 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3688 if ((status = decode_putfh(&xdr)) == 0)
3689 status = decode_access(&xdr, res);
3695 * Decode LOOKUP response
3697 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3699 struct xdr_stream xdr;
3700 struct compound_hdr hdr;
3703 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3704 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3706 if ((status = decode_putfh(&xdr)) != 0)
3708 if ((status = decode_lookup(&xdr)) != 0)
3710 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3712 status = decode_getfattr(&xdr, res->fattr, res->server);
3718 * Decode LOOKUP_ROOT response
3720 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3722 struct xdr_stream xdr;
3723 struct compound_hdr hdr;
3726 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3727 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3729 if ((status = decode_putrootfh(&xdr)) != 0)
3731 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3732 status = decode_getfattr(&xdr, res->fattr, res->server);
3738 * Decode REMOVE response
3740 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_remove_res *res)
3742 struct xdr_stream xdr;
3743 struct compound_hdr hdr;
3746 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3747 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3749 if ((status = decode_putfh(&xdr)) != 0)
3751 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3753 decode_getfattr(&xdr, res->dir_attr, res->server);
3759 * Decode RENAME response
3761 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3763 struct xdr_stream xdr;
3764 struct compound_hdr hdr;
3767 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3768 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3770 if ((status = decode_putfh(&xdr)) != 0)
3772 if ((status = decode_savefh(&xdr)) != 0)
3774 if ((status = decode_putfh(&xdr)) != 0)
3776 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3778 /* Current FH is target directory */
3779 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3781 if ((status = decode_restorefh(&xdr)) != 0)
3783 decode_getfattr(&xdr, res->old_fattr, res->server);
3789 * Decode LINK response
3791 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3793 struct xdr_stream xdr;
3794 struct compound_hdr hdr;
3797 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3798 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3800 if ((status = decode_putfh(&xdr)) != 0)
3802 if ((status = decode_savefh(&xdr)) != 0)
3804 if ((status = decode_putfh(&xdr)) != 0)
3806 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3809 * Note order: OP_LINK leaves the directory as the current
3812 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3814 if ((status = decode_restorefh(&xdr)) != 0)
3816 decode_getfattr(&xdr, res->fattr, res->server);
3822 * Decode CREATE response
3824 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3826 struct xdr_stream xdr;
3827 struct compound_hdr hdr;
3830 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3831 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3833 if ((status = decode_putfh(&xdr)) != 0)
3835 if ((status = decode_savefh(&xdr)) != 0)
3837 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3839 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3841 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3843 if ((status = decode_restorefh(&xdr)) != 0)
3845 decode_getfattr(&xdr, res->dir_fattr, res->server);
3851 * Decode SYMLINK response
3853 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3855 return nfs4_xdr_dec_create(rqstp, p, res);
3859 * Decode GETATTR response
3861 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3863 struct xdr_stream xdr;
3864 struct compound_hdr hdr;
3867 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3868 status = decode_compound_hdr(&xdr, &hdr);
3871 status = decode_putfh(&xdr);
3874 status = decode_getfattr(&xdr, res->fattr, res->server);
3881 * Encode an SETACL request
3884 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3886 struct xdr_stream xdr;
3887 struct compound_hdr hdr = {
3892 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3893 encode_compound_hdr(&xdr, &hdr);
3894 status = encode_putfh(&xdr, args->fh);
3897 status = encode_setacl(&xdr, args);
3902 * Decode SETACL response
3905 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
3907 struct xdr_stream xdr;
3908 struct compound_hdr hdr;
3911 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3912 status = decode_compound_hdr(&xdr, &hdr);
3915 status = decode_putfh(&xdr);
3918 status = decode_setattr(&xdr, res);
3924 * Decode GETACL response
3927 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
3929 struct xdr_stream xdr;
3930 struct compound_hdr hdr;
3933 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3934 status = decode_compound_hdr(&xdr, &hdr);
3937 status = decode_putfh(&xdr);
3940 status = decode_getacl(&xdr, rqstp, acl_len);
3947 * Decode CLOSE response
3949 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3951 struct xdr_stream xdr;
3952 struct compound_hdr hdr;
3955 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3956 status = decode_compound_hdr(&xdr, &hdr);
3959 status = decode_putfh(&xdr);
3962 status = decode_close(&xdr, res);
3966 * Note: Server may do delete on close for this file
3967 * in which case the getattr call will fail with
3968 * an ESTALE error. Shouldn't be a problem,
3969 * though, since fattr->valid will remain unset.
3971 decode_getfattr(&xdr, res->fattr, res->server);
3977 * Decode OPEN response
3979 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
3981 struct xdr_stream xdr;
3982 struct compound_hdr hdr;
3985 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3986 status = decode_compound_hdr(&xdr, &hdr);
3989 status = decode_putfh(&xdr);
3992 status = decode_savefh(&xdr);
3995 status = decode_open(&xdr, res);
3998 status = decode_getfh(&xdr, &res->fh);
4001 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4003 if ((status = decode_restorefh(&xdr)) != 0)
4005 decode_getfattr(&xdr, res->dir_attr, res->server);
4011 * Decode OPEN_CONFIRM response
4013 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4015 struct xdr_stream xdr;
4016 struct compound_hdr hdr;
4019 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4020 status = decode_compound_hdr(&xdr, &hdr);
4023 status = decode_putfh(&xdr);
4026 status = decode_open_confirm(&xdr, res);
4032 * Decode OPEN response
4034 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4036 struct xdr_stream xdr;
4037 struct compound_hdr hdr;
4040 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4041 status = decode_compound_hdr(&xdr, &hdr);
4044 status = decode_putfh(&xdr);
4047 status = decode_open(&xdr, res);
4050 decode_getfattr(&xdr, res->f_attr, res->server);
4056 * Decode SETATTR response
4058 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4060 struct xdr_stream xdr;
4061 struct compound_hdr hdr;
4064 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4065 status = decode_compound_hdr(&xdr, &hdr);
4068 status = decode_putfh(&xdr);
4071 status = decode_setattr(&xdr, res);
4074 status = decode_getfattr(&xdr, res->fattr, res->server);
4075 if (status == NFS4ERR_DELAY)
4082 * Decode LOCK response
4084 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4086 struct xdr_stream xdr;
4087 struct compound_hdr hdr;
4090 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4091 status = decode_compound_hdr(&xdr, &hdr);
4094 status = decode_putfh(&xdr);
4097 status = decode_lock(&xdr, res);
4103 * Decode LOCKT response
4105 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4107 struct xdr_stream xdr;
4108 struct compound_hdr hdr;
4111 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4112 status = decode_compound_hdr(&xdr, &hdr);
4115 status = decode_putfh(&xdr);
4118 status = decode_lockt(&xdr, res);
4124 * Decode LOCKU response
4126 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4128 struct xdr_stream xdr;
4129 struct compound_hdr hdr;
4132 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4133 status = decode_compound_hdr(&xdr, &hdr);
4136 status = decode_putfh(&xdr);
4139 status = decode_locku(&xdr, res);
4145 * Decode READLINK response
4147 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
4149 struct xdr_stream xdr;
4150 struct compound_hdr hdr;
4153 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4154 status = decode_compound_hdr(&xdr, &hdr);
4157 status = decode_putfh(&xdr);
4160 status = decode_readlink(&xdr, rqstp);
4166 * Decode READDIR response
4168 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4170 struct xdr_stream xdr;
4171 struct compound_hdr hdr;
4174 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4175 status = decode_compound_hdr(&xdr, &hdr);
4178 status = decode_putfh(&xdr);
4181 status = decode_readdir(&xdr, rqstp, res);
4187 * Decode Read response
4189 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4191 struct xdr_stream xdr;
4192 struct compound_hdr hdr;
4195 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4196 status = decode_compound_hdr(&xdr, &hdr);
4199 status = decode_putfh(&xdr);
4202 status = decode_read(&xdr, rqstp, res);
4204 status = res->count;
4210 * Decode WRITE response
4212 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4214 struct xdr_stream xdr;
4215 struct compound_hdr hdr;
4218 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4219 status = decode_compound_hdr(&xdr, &hdr);
4222 status = decode_putfh(&xdr);
4225 status = decode_write(&xdr, res);
4228 decode_getfattr(&xdr, res->fattr, res->server);
4230 status = res->count;
4236 * Decode COMMIT response
4238 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4240 struct xdr_stream xdr;
4241 struct compound_hdr hdr;
4244 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4245 status = decode_compound_hdr(&xdr, &hdr);
4248 status = decode_putfh(&xdr);
4251 status = decode_commit(&xdr, res);
4254 decode_getfattr(&xdr, res->fattr, res->server);
4262 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4264 struct xdr_stream xdr;
4265 struct compound_hdr hdr;
4268 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4269 status = decode_compound_hdr(&xdr, &hdr);
4271 status = decode_putfh(&xdr);
4273 status = decode_fsinfo(&xdr, fsinfo);
4275 status = -nfs4_stat_to_errno(hdr.status);
4282 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
4284 struct xdr_stream xdr;
4285 struct compound_hdr hdr;
4288 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4289 status = decode_compound_hdr(&xdr, &hdr);
4291 status = decode_putfh(&xdr);
4293 status = decode_pathconf(&xdr, pathconf);
4300 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
4302 struct xdr_stream xdr;
4303 struct compound_hdr hdr;
4306 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4307 status = decode_compound_hdr(&xdr, &hdr);
4309 status = decode_putfh(&xdr);
4311 status = decode_statfs(&xdr, fsstat);
4316 * GETATTR_BITMAP request
4318 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4320 struct xdr_stream xdr;
4321 struct compound_hdr hdr;
4324 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4325 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4327 if ((status = decode_putfh(&xdr)) != 0)
4329 status = decode_server_caps(&xdr, res);
4335 * Decode RENEW response
4337 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4339 struct xdr_stream xdr;
4340 struct compound_hdr hdr;
4343 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4344 status = decode_compound_hdr(&xdr, &hdr);
4346 status = decode_renew(&xdr);
4351 * a SETCLIENTID request
4353 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4354 struct nfs_client *clp)
4356 struct xdr_stream xdr;
4357 struct compound_hdr hdr;
4360 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4361 status = decode_compound_hdr(&xdr, &hdr);
4363 status = decode_setclientid(&xdr, clp);
4365 status = -nfs4_stat_to_errno(hdr.status);
4370 * a SETCLIENTID_CONFIRM request
4372 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4374 struct xdr_stream xdr;
4375 struct compound_hdr hdr;
4378 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4379 status = decode_compound_hdr(&xdr, &hdr);
4381 status = decode_setclientid_confirm(&xdr);
4383 status = decode_putrootfh(&xdr);
4385 status = decode_fsinfo(&xdr, fsinfo);
4387 status = -nfs4_stat_to_errno(hdr.status);
4392 * DELEGRETURN request
4394 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4396 struct xdr_stream xdr;
4397 struct compound_hdr hdr;
4400 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4401 status = decode_compound_hdr(&xdr, &hdr);
4404 status = decode_putfh(&xdr);
4407 status = decode_delegreturn(&xdr);
4408 decode_getfattr(&xdr, res->fattr, res->server);
4414 * FS_LOCATIONS request
4416 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
4418 struct xdr_stream xdr;
4419 struct compound_hdr hdr;
4422 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4423 status = decode_compound_hdr(&xdr, &hdr);
4426 if ((status = decode_putfh(&xdr)) != 0)
4428 if ((status = decode_lookup(&xdr)) != 0)
4430 xdr_enter_page(&xdr, PAGE_SIZE);
4431 status = decode_getfattr(&xdr, &res->fattr, res->server);
4436 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4438 uint32_t bitmap[2] = {0};
4443 return ERR_PTR(-EAGAIN);
4445 return ERR_PTR(-EBADCOOKIE);
4448 entry->prev_cookie = entry->cookie;
4449 p = xdr_decode_hyper(p, &entry->cookie);
4450 entry->len = ntohl(*p++);
4451 entry->name = (const char *) p;
4452 p += XDR_QUADLEN(entry->len);
4455 * In case the server doesn't return an inode number,
4456 * we fake one here. (We don't use inode number 0,
4457 * since glibc seems to choke on it...)
4461 len = ntohl(*p++); /* bitmap length */
4463 bitmap[0] = ntohl(*p++);
4465 bitmap[1] = ntohl(*p++);
4469 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4471 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4472 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4473 /* Ignore the return value of rdattr_error for now */
4477 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4478 xdr_decode_hyper(p, &entry->ino);
4479 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4480 xdr_decode_hyper(p, &entry->ino);
4484 entry->eof = !p[0] && p[1];
4489 * We need to translate between nfs status return values and
4490 * the local errno values which may not be the same.
4497 { NFS4ERR_PERM, EPERM },
4498 { NFS4ERR_NOENT, ENOENT },
4499 { NFS4ERR_IO, errno_NFSERR_IO },
4500 { NFS4ERR_NXIO, ENXIO },
4501 { NFS4ERR_ACCESS, EACCES },
4502 { NFS4ERR_EXIST, EEXIST },
4503 { NFS4ERR_XDEV, EXDEV },
4504 { NFS4ERR_NOTDIR, ENOTDIR },
4505 { NFS4ERR_ISDIR, EISDIR },
4506 { NFS4ERR_INVAL, EINVAL },
4507 { NFS4ERR_FBIG, EFBIG },
4508 { NFS4ERR_NOSPC, ENOSPC },
4509 { NFS4ERR_ROFS, EROFS },
4510 { NFS4ERR_MLINK, EMLINK },
4511 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4512 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4513 { NFS4ERR_DQUOT, EDQUOT },
4514 { NFS4ERR_STALE, ESTALE },
4515 { NFS4ERR_BADHANDLE, EBADHANDLE },
4516 { NFS4ERR_BADOWNER, EINVAL },
4517 { NFS4ERR_BADNAME, EINVAL },
4518 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4519 { NFS4ERR_NOTSUPP, ENOTSUPP },
4520 { NFS4ERR_TOOSMALL, ETOOSMALL },
4521 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4522 { NFS4ERR_BADTYPE, EBADTYPE },
4523 { NFS4ERR_LOCKED, EAGAIN },
4524 { NFS4ERR_RESOURCE, EREMOTEIO },
4525 { NFS4ERR_SYMLINK, ELOOP },
4526 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4527 { NFS4ERR_DEADLOCK, EDEADLK },
4528 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4529 * to be handled by a
4536 * Convert an NFS error code to a local one.
4537 * This one is used jointly by NFSv2 and NFSv3.
4540 nfs4_stat_to_errno(int stat)
4543 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4544 if (nfs_errtbl[i].stat == stat)
4545 return nfs_errtbl[i].errno;
4547 if (stat <= 10000 || stat > 10100) {
4548 /* The server is looney tunes. */
4549 return ESERVERFAULT;
4551 /* If we cannot translate the error, the recovery routines should
4553 * Note: remaining NFSv4 error codes have values > 10000, so should
4554 * not conflict with native Linux error codes.
4559 #define PROC(proc, argtype, restype) \
4560 [NFSPROC4_CLNT_##proc] = { \
4561 .p_proc = NFSPROC4_COMPOUND, \
4562 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4563 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4564 .p_arglen = NFS4_##argtype##_sz, \
4565 .p_replen = NFS4_##restype##_sz, \
4566 .p_statidx = NFSPROC4_CLNT_##proc, \
4570 struct rpc_procinfo nfs4_procedures[] = {
4571 PROC(READ, enc_read, dec_read),
4572 PROC(WRITE, enc_write, dec_write),
4573 PROC(COMMIT, enc_commit, dec_commit),
4574 PROC(OPEN, enc_open, dec_open),
4575 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4576 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4577 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4578 PROC(CLOSE, enc_close, dec_close),
4579 PROC(SETATTR, enc_setattr, dec_setattr),
4580 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4581 PROC(RENEW, enc_renew, dec_renew),
4582 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4583 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4584 PROC(LOCK, enc_lock, dec_lock),
4585 PROC(LOCKT, enc_lockt, dec_lockt),
4586 PROC(LOCKU, enc_locku, dec_locku),
4587 PROC(ACCESS, enc_access, dec_access),
4588 PROC(GETATTR, enc_getattr, dec_getattr),
4589 PROC(LOOKUP, enc_lookup, dec_lookup),
4590 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4591 PROC(REMOVE, enc_remove, dec_remove),
4592 PROC(RENAME, enc_rename, dec_rename),
4593 PROC(LINK, enc_link, dec_link),
4594 PROC(SYMLINK, enc_symlink, dec_symlink),
4595 PROC(CREATE, enc_create, dec_create),
4596 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4597 PROC(STATFS, enc_statfs, dec_statfs),
4598 PROC(READLINK, enc_readlink, dec_readlink),
4599 PROC(READDIR, enc_readdir, dec_readdir),
4600 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4601 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4602 PROC(GETACL, enc_getacl, dec_getacl),
4603 PROC(SETACL, enc_setacl, dec_setacl),
4604 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4607 struct rpc_version nfs_version4 = {
4609 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4610 .procs = nfs4_procedures