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 /* This is based on getfattr, which uses the most attributes: */
91 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
92 3 + 3 + 3 + 2 * nfs4_name_maxsz))
93 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
94 nfs4_fattr_value_maxsz)
95 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
96 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
97 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
98 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
99 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
100 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
101 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
102 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
103 #define decode_renew_maxsz (op_decode_hdr_maxsz)
104 #define encode_setclientid_maxsz \
105 (op_encode_hdr_maxsz + \
106 4 /*server->ip_addr*/ + \
109 6 + (NFS4_VERIFIER_SIZE >> 2))
110 #define decode_setclientid_maxsz \
111 (op_decode_hdr_maxsz + \
113 1024) /* large value for CLID_INUSE */
114 #define encode_setclientid_confirm_maxsz \
115 (op_encode_hdr_maxsz + \
116 3 + (NFS4_VERIFIER_SIZE >> 2))
117 #define decode_setclientid_confirm_maxsz \
118 (op_decode_hdr_maxsz)
119 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
120 1 + ((3 + NFS4_FHSIZE) >> 2))
121 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
123 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
125 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
126 #define encode_link_maxsz (op_encode_hdr_maxsz + \
128 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
129 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
130 1 + nfs4_name_maxsz + \
133 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
134 #define encode_create_maxsz (op_encode_hdr_maxsz + \
135 2 + nfs4_name_maxsz + \
137 #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
138 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
139 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
140 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
141 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
142 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
143 encode_putfh_maxsz + \
144 op_encode_hdr_maxsz + 7)
145 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
146 decode_putfh_maxsz + \
147 op_decode_hdr_maxsz + 2)
148 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
149 encode_putfh_maxsz + \
151 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
152 decode_putfh_maxsz + \
154 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
155 encode_putfh_maxsz + \
156 op_encode_hdr_maxsz + 9)
157 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
158 decode_putfh_maxsz + \
159 op_decode_hdr_maxsz + 2)
160 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
161 encode_putfh_maxsz + \
162 op_encode_hdr_maxsz + 8 + \
163 encode_getattr_maxsz)
164 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
165 decode_putfh_maxsz + \
166 op_decode_hdr_maxsz + 4 + \
167 decode_getattr_maxsz)
168 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
169 encode_putfh_maxsz + \
170 op_encode_hdr_maxsz + 3 + \
171 encode_getattr_maxsz)
172 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
173 decode_putfh_maxsz + \
174 op_decode_hdr_maxsz + 2 + \
175 decode_getattr_maxsz)
176 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
177 encode_putfh_maxsz + \
178 op_encode_hdr_maxsz + \
180 encode_getattr_maxsz + \
182 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
183 decode_putfh_maxsz + \
184 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
185 decode_getattr_maxsz + \
187 #define NFS4_enc_open_confirm_sz \
188 (compound_encode_hdr_maxsz + \
189 encode_putfh_maxsz + \
190 op_encode_hdr_maxsz + 5)
191 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
192 decode_putfh_maxsz + \
193 op_decode_hdr_maxsz + 4)
194 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
195 encode_putfh_maxsz + \
196 op_encode_hdr_maxsz + \
198 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
199 decode_putfh_maxsz + \
200 op_decode_hdr_maxsz + \
202 #define NFS4_enc_open_downgrade_sz \
203 (compound_encode_hdr_maxsz + \
204 encode_putfh_maxsz + \
205 op_encode_hdr_maxsz + 7 + \
206 encode_getattr_maxsz)
207 #define NFS4_dec_open_downgrade_sz \
208 (compound_decode_hdr_maxsz + \
209 decode_putfh_maxsz + \
210 op_decode_hdr_maxsz + 4 + \
211 decode_getattr_maxsz)
212 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
213 encode_putfh_maxsz + \
214 op_encode_hdr_maxsz + 5 + \
215 encode_getattr_maxsz)
216 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
217 decode_putfh_maxsz + \
218 op_decode_hdr_maxsz + 4 + \
219 decode_getattr_maxsz)
220 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
221 encode_putfh_maxsz + \
222 op_encode_hdr_maxsz + 4 + \
224 encode_getattr_maxsz)
225 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
226 decode_putfh_maxsz + \
227 op_decode_hdr_maxsz + 3)
228 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
229 encode_putfh_maxsz + \
231 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
232 decode_putfh_maxsz + \
234 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
236 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
238 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
239 encode_setclientid_maxsz)
240 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
241 decode_setclientid_maxsz)
242 #define NFS4_enc_setclientid_confirm_sz \
243 (compound_encode_hdr_maxsz + \
244 encode_setclientid_confirm_maxsz + \
245 encode_putrootfh_maxsz + \
247 #define NFS4_dec_setclientid_confirm_sz \
248 (compound_decode_hdr_maxsz + \
249 decode_setclientid_confirm_maxsz + \
250 decode_putrootfh_maxsz + \
252 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
253 encode_putfh_maxsz + \
254 encode_getattr_maxsz + \
255 op_encode_hdr_maxsz + \
259 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
260 decode_putfh_maxsz + \
261 decode_getattr_maxsz + \
262 op_decode_hdr_maxsz + \
265 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
266 encode_putfh_maxsz + \
267 encode_getattr_maxsz + \
268 op_encode_hdr_maxsz + \
271 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
272 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
273 encode_putfh_maxsz + \
274 encode_getattr_maxsz + \
275 op_encode_hdr_maxsz + \
277 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
278 decode_putfh_maxsz + \
279 decode_getattr_maxsz + \
280 op_decode_hdr_maxsz + 4)
281 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
282 encode_putfh_maxsz + \
283 op_encode_hdr_maxsz + 1)
284 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
285 decode_putfh_maxsz + \
286 op_decode_hdr_maxsz + 2)
287 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
288 encode_putfh_maxsz + \
289 encode_getattr_maxsz)
290 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
291 decode_putfh_maxsz + \
292 decode_getattr_maxsz)
293 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
294 encode_putfh_maxsz + \
295 encode_lookup_maxsz + \
296 encode_getattr_maxsz + \
298 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
299 decode_putfh_maxsz + \
300 op_decode_hdr_maxsz + \
301 decode_getattr_maxsz + \
303 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
304 encode_putrootfh_maxsz + \
305 encode_getattr_maxsz + \
307 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
308 decode_putrootfh_maxsz + \
309 decode_getattr_maxsz + \
311 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
312 encode_putfh_maxsz + \
313 encode_remove_maxsz + \
314 encode_getattr_maxsz)
315 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
316 decode_putfh_maxsz + \
317 op_decode_hdr_maxsz + 5 + \
318 decode_getattr_maxsz)
319 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
320 encode_putfh_maxsz + \
321 encode_savefh_maxsz + \
322 encode_putfh_maxsz + \
323 encode_rename_maxsz + \
324 encode_getattr_maxsz + \
325 encode_restorefh_maxsz + \
326 encode_getattr_maxsz)
327 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
328 decode_putfh_maxsz + \
329 decode_savefh_maxsz + \
330 decode_putfh_maxsz + \
331 decode_rename_maxsz + \
332 decode_getattr_maxsz + \
333 decode_restorefh_maxsz + \
334 decode_getattr_maxsz)
335 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
336 encode_putfh_maxsz + \
337 encode_savefh_maxsz + \
338 encode_putfh_maxsz + \
339 encode_link_maxsz + \
340 decode_getattr_maxsz + \
341 encode_restorefh_maxsz + \
342 decode_getattr_maxsz)
343 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
344 decode_putfh_maxsz + \
345 decode_savefh_maxsz + \
346 decode_putfh_maxsz + \
347 decode_link_maxsz + \
348 decode_getattr_maxsz + \
349 decode_restorefh_maxsz + \
350 decode_getattr_maxsz)
351 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
352 encode_putfh_maxsz + \
353 encode_symlink_maxsz + \
354 encode_getattr_maxsz + \
356 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
357 decode_putfh_maxsz + \
358 decode_symlink_maxsz + \
359 decode_getattr_maxsz + \
361 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
362 encode_putfh_maxsz + \
363 encode_savefh_maxsz + \
364 encode_create_maxsz + \
365 encode_getfh_maxsz + \
366 encode_getattr_maxsz + \
367 encode_restorefh_maxsz + \
368 encode_getattr_maxsz)
369 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
370 decode_putfh_maxsz + \
371 decode_savefh_maxsz + \
372 decode_create_maxsz + \
373 decode_getfh_maxsz + \
374 decode_getattr_maxsz + \
375 decode_restorefh_maxsz + \
376 decode_getattr_maxsz)
377 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
379 encode_getattr_maxsz)
380 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
381 decode_putfh_maxsz + \
382 decode_getattr_maxsz)
383 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_getattr_maxsz)
386 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
387 decode_putfh_maxsz + \
388 op_decode_hdr_maxsz + 12)
389 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
390 encode_getattr_maxsz)
391 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
392 decode_getattr_maxsz)
393 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
394 encode_putfh_maxsz + \
395 encode_delegreturn_maxsz + \
396 encode_getattr_maxsz)
397 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
398 decode_delegreturn_maxsz + \
399 decode_getattr_maxsz)
400 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
401 encode_putfh_maxsz + \
402 encode_getattr_maxsz)
403 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
404 decode_putfh_maxsz + \
405 op_decode_hdr_maxsz + \
406 nfs4_fattr_bitmap_maxsz + 1)
407 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
408 encode_putfh_maxsz + \
409 op_encode_hdr_maxsz + 4 + \
410 nfs4_fattr_bitmap_maxsz + 1)
411 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
412 decode_putfh_maxsz + \
413 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
414 #define NFS4_enc_fs_locations_sz \
415 (compound_encode_hdr_maxsz + \
416 encode_putfh_maxsz + \
417 encode_getattr_maxsz)
418 #define NFS4_dec_fs_locations_sz \
419 (compound_decode_hdr_maxsz + \
420 decode_putfh_maxsz + \
421 op_decode_hdr_maxsz + \
422 nfs4_fattr_bitmap_maxsz)
426 unsigned int nfs2type;
434 { S_IFSOCK, NFSOCK },
440 struct compound_hdr {
448 * START OF "GENERIC" ENCODE ROUTINES.
449 * These may look a little ugly since they are imported from a "generic"
450 * set of XDR encode/decode routines which are intended to be shared by
451 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
453 * If the pain of reading these is too great, it should be a straightforward
454 * task to translate them into Linux-specific versions which are more
455 * consistent with the style used in NFSv2/v3...
457 #define WRITE32(n) *p++ = htonl(n)
458 #define WRITE64(n) do { \
459 *p++ = htonl((uint32_t)((n) >> 32)); \
460 *p++ = htonl((uint32_t)(n)); \
462 #define WRITEMEM(ptr,nbytes) do { \
463 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
466 #define RESERVE_SPACE(nbytes) do { \
467 p = xdr_reserve_space(xdr, nbytes); \
468 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
472 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
476 p = xdr_reserve_space(xdr, 4 + len);
478 xdr_encode_opaque(p, str, len);
481 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
485 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
486 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
487 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
488 WRITE32(hdr->taglen);
489 WRITEMEM(hdr->tag, hdr->taglen);
490 WRITE32(NFS4_MINOR_VERSION);
495 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
499 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
501 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
504 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
506 char owner_name[IDMAP_NAMESZ];
507 char owner_group[IDMAP_NAMESZ];
508 int owner_namelen = 0;
509 int owner_grouplen = 0;
518 * We reserve enough space to write the entire attribute buffer at once.
519 * In the worst-case, this would be
520 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
521 * = 36 bytes, plus any contribution from variable-length fields
522 * such as owner/group.
527 if (iap->ia_valid & ATTR_SIZE)
529 if (iap->ia_valid & ATTR_MODE)
531 if (iap->ia_valid & ATTR_UID) {
532 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
533 if (owner_namelen < 0) {
534 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
537 strcpy(owner_name, "nobody");
538 owner_namelen = sizeof("nobody") - 1;
541 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
543 if (iap->ia_valid & ATTR_GID) {
544 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
545 if (owner_grouplen < 0) {
546 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
548 strcpy(owner_group, "nobody");
549 owner_grouplen = sizeof("nobody") - 1;
552 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
554 if (iap->ia_valid & ATTR_ATIME_SET)
556 else if (iap->ia_valid & ATTR_ATIME)
558 if (iap->ia_valid & ATTR_MTIME_SET)
560 else if (iap->ia_valid & ATTR_MTIME)
565 * We write the bitmap length now, but leave the bitmap and the attribute
566 * buffer length to be backfilled at the end of this routine.
572 if (iap->ia_valid & ATTR_SIZE) {
573 bmval0 |= FATTR4_WORD0_SIZE;
574 WRITE64(iap->ia_size);
576 if (iap->ia_valid & ATTR_MODE) {
577 bmval1 |= FATTR4_WORD1_MODE;
578 WRITE32(iap->ia_mode & S_IALLUGO);
580 if (iap->ia_valid & ATTR_UID) {
581 bmval1 |= FATTR4_WORD1_OWNER;
582 WRITE32(owner_namelen);
583 WRITEMEM(owner_name, owner_namelen);
585 if (iap->ia_valid & ATTR_GID) {
586 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
587 WRITE32(owner_grouplen);
588 WRITEMEM(owner_group, owner_grouplen);
590 if (iap->ia_valid & ATTR_ATIME_SET) {
591 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
592 WRITE32(NFS4_SET_TO_CLIENT_TIME);
594 WRITE32(iap->ia_mtime.tv_sec);
595 WRITE32(iap->ia_mtime.tv_nsec);
597 else if (iap->ia_valid & ATTR_ATIME) {
598 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
599 WRITE32(NFS4_SET_TO_SERVER_TIME);
601 if (iap->ia_valid & ATTR_MTIME_SET) {
602 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
603 WRITE32(NFS4_SET_TO_CLIENT_TIME);
605 WRITE32(iap->ia_mtime.tv_sec);
606 WRITE32(iap->ia_mtime.tv_nsec);
608 else if (iap->ia_valid & ATTR_MTIME) {
609 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
610 WRITE32(NFS4_SET_TO_SERVER_TIME);
614 * Now we backfill the bitmap and the attribute buffer length.
616 if (len != ((char *)p - (char *)q) + 4) {
617 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
618 len, ((char *)p - (char *)q) + 4);
621 len = (char *)p - (char *)q - 12;
622 *q++ = htonl(bmval0);
623 *q++ = htonl(bmval1);
631 static int encode_access(struct xdr_stream *xdr, u32 access)
642 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
646 RESERVE_SPACE(8+sizeof(arg->stateid->data));
648 WRITE32(arg->seqid->sequence->counter);
649 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
654 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
660 WRITE64(args->offset);
661 WRITE32(args->count);
666 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
672 WRITE32(create->ftype);
674 switch (create->ftype) {
677 WRITE32(create->u.symlink.len);
678 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
681 case NF4BLK: case NF4CHR:
683 WRITE32(create->u.device.specdata1);
684 WRITE32(create->u.device.specdata2);
691 RESERVE_SPACE(4 + create->name->len);
692 WRITE32(create->name->len);
693 WRITEMEM(create->name->name, create->name->len);
695 return encode_attrs(xdr, create->attrs, create->server);
698 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
709 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
721 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
723 return encode_getattr_two(xdr,
724 bitmask[0] & nfs4_fattr_bitmap[0],
725 bitmask[1] & nfs4_fattr_bitmap[1]);
728 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
730 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
731 bitmask[1] & nfs4_fsinfo_bitmap[1]);
734 static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
736 return encode_getattr_two(xdr,
737 bitmask[0] & nfs4_fs_locations_bitmap[0],
738 bitmask[1] & nfs4_fs_locations_bitmap[1]);
741 static int encode_getfh(struct xdr_stream *xdr)
751 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
755 RESERVE_SPACE(8 + name->len);
758 WRITEMEM(name->name, name->len);
763 static inline int nfs4_lock_type(struct file_lock *fl, int block)
765 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
766 return block ? NFS4_READW_LT : NFS4_READ_LT;
767 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
770 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
772 if (fl->fl_end == OFFSET_MAX)
774 return fl->fl_end - fl->fl_start + 1;
778 * opcode,type,reclaim,offset,length,new_lock_owner = 32
779 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
781 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
787 WRITE32(nfs4_lock_type(args->fl, args->block));
788 WRITE32(args->reclaim);
789 WRITE64(args->fl->fl_start);
790 WRITE64(nfs4_lock_length(args->fl));
791 WRITE32(args->new_lock_owner);
792 if (args->new_lock_owner){
794 WRITE32(args->open_seqid->sequence->counter);
795 WRITEMEM(args->open_stateid->data, sizeof(args->open_stateid->data));
796 WRITE32(args->lock_seqid->sequence->counter);
797 WRITE64(args->lock_owner.clientid);
799 WRITE32(args->lock_owner.id);
803 WRITEMEM(args->lock_stateid->data, sizeof(args->lock_stateid->data));
804 WRITE32(args->lock_seqid->sequence->counter);
810 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
816 WRITE32(nfs4_lock_type(args->fl, 0));
817 WRITE64(args->fl->fl_start);
818 WRITE64(nfs4_lock_length(args->fl));
819 WRITE64(args->lock_owner.clientid);
821 WRITE32(args->lock_owner.id);
826 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
832 WRITE32(nfs4_lock_type(args->fl, 0));
833 WRITE32(args->seqid->sequence->counter);
834 WRITEMEM(args->stateid->data, sizeof(args->stateid->data));
835 WRITE64(args->fl->fl_start);
836 WRITE64(nfs4_lock_length(args->fl));
841 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
846 RESERVE_SPACE(8 + len);
849 WRITEMEM(name->name, len);
854 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
859 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
861 WRITE32(NFS4_SHARE_ACCESS_READ);
864 WRITE32(NFS4_SHARE_ACCESS_WRITE);
866 case FMODE_READ|FMODE_WRITE:
867 WRITE32(NFS4_SHARE_ACCESS_BOTH);
872 WRITE32(0); /* for linux, share_deny = 0 always */
875 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
879 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
884 WRITE32(arg->seqid->sequence->counter);
885 encode_share_access(xdr, arg->open_flags);
887 WRITE64(arg->clientid);
892 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
897 switch(arg->open_flags & O_EXCL) {
899 WRITE32(NFS4_CREATE_UNCHECKED);
900 encode_attrs(xdr, arg->u.attrs, arg->server);
903 WRITE32(NFS4_CREATE_EXCLUSIVE);
904 encode_nfs4_verifier(xdr, &arg->u.verifier);
908 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
913 switch (arg->open_flags & O_CREAT) {
915 WRITE32(NFS4_OPEN_NOCREATE);
918 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
919 WRITE32(NFS4_OPEN_CREATE);
920 encode_createmode(xdr, arg);
924 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
929 switch (delegation_type) {
931 WRITE32(NFS4_OPEN_DELEGATE_NONE);
934 WRITE32(NFS4_OPEN_DELEGATE_READ);
936 case FMODE_WRITE|FMODE_READ:
937 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
944 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
949 WRITE32(NFS4_OPEN_CLAIM_NULL);
950 encode_string(xdr, name->len, name->name);
953 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
958 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
959 encode_delegation_type(xdr, type);
962 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
966 RESERVE_SPACE(4+sizeof(stateid->data));
967 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
968 WRITEMEM(stateid->data, sizeof(stateid->data));
969 encode_string(xdr, name->len, name->name);
972 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
974 encode_openhdr(xdr, arg);
975 encode_opentype(xdr, arg);
976 switch (arg->claim) {
977 case NFS4_OPEN_CLAIM_NULL:
978 encode_claim_null(xdr, arg->name);
980 case NFS4_OPEN_CLAIM_PREVIOUS:
981 encode_claim_previous(xdr, arg->u.delegation_type);
983 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
984 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
992 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
996 RESERVE_SPACE(8+sizeof(arg->stateid->data));
997 WRITE32(OP_OPEN_CONFIRM);
998 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
999 WRITE32(arg->seqid->sequence->counter);
1004 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1008 RESERVE_SPACE(8+sizeof(arg->stateid->data));
1009 WRITE32(OP_OPEN_DOWNGRADE);
1010 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
1011 WRITE32(arg->seqid->sequence->counter);
1012 encode_share_access(xdr, arg->open_flags);
1017 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1022 RESERVE_SPACE(8 + len);
1025 WRITEMEM(fh->data, len);
1030 static int encode_putrootfh(struct xdr_stream *xdr)
1035 WRITE32(OP_PUTROOTFH);
1040 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1042 nfs4_stateid stateid;
1046 if (ctx->state != NULL) {
1047 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1048 WRITEMEM(stateid.data, sizeof(stateid.data));
1050 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1053 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1060 encode_stateid(xdr, args->context);
1063 WRITE64(args->offset);
1064 WRITE32(args->count);
1069 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1071 struct rpc_auth *auth = req->rq_task->tk_auth;
1072 uint32_t attrs[2] = {
1073 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1074 FATTR4_WORD1_MOUNTED_ON_FILEID,
1079 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1080 WRITE32(OP_READDIR);
1081 WRITE64(readdir->cookie);
1082 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1083 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1084 WRITE32(readdir->count);
1086 /* Switch to mounted_on_fileid if the server supports it */
1087 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1088 attrs[0] &= ~FATTR4_WORD0_FILEID;
1090 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1091 WRITE32(attrs[0] & readdir->bitmask[0]);
1092 WRITE32(attrs[1] & readdir->bitmask[1]);
1093 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1095 (unsigned long long)readdir->cookie,
1096 ((u32 *)readdir->verifier.data)[0],
1097 ((u32 *)readdir->verifier.data)[1],
1098 attrs[0] & readdir->bitmask[0],
1099 attrs[1] & readdir->bitmask[1]);
1101 /* set up reply kvec
1102 * toplevel_status + taglen + rescount + OP_PUTFH + status
1103 * + OP_READDIR + status + verifer(2) = 9
1105 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1106 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1107 readdir->pgbase, readdir->count);
1108 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1109 __FUNCTION__, replen, readdir->pages,
1110 readdir->pgbase, readdir->count);
1115 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1117 struct rpc_auth *auth = req->rq_task->tk_auth;
1118 unsigned int replen;
1122 WRITE32(OP_READLINK);
1124 /* set up reply kvec
1125 * toplevel_status + taglen + rescount + OP_PUTFH + status
1126 * + OP_READLINK + status + string length = 8
1128 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1129 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1130 readlink->pgbase, readlink->pglen);
1135 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1139 RESERVE_SPACE(8 + name->len);
1142 WRITEMEM(name->name, name->len);
1147 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1151 RESERVE_SPACE(8 + oldname->len);
1153 WRITE32(oldname->len);
1154 WRITEMEM(oldname->name, oldname->len);
1156 RESERVE_SPACE(4 + newname->len);
1157 WRITE32(newname->len);
1158 WRITEMEM(newname->name, newname->len);
1163 static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
1169 WRITE64(client_stateid->cl_clientid);
1175 encode_restorefh(struct xdr_stream *xdr)
1180 WRITE32(OP_RESTOREFH);
1186 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1190 RESERVE_SPACE(4+sizeof(zero_stateid.data));
1191 WRITE32(OP_SETATTR);
1192 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1195 WRITE32(FATTR4_WORD0_ACL);
1196 if (arg->acl_len % 4)
1199 WRITE32(arg->acl_len);
1200 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1205 encode_savefh(struct xdr_stream *xdr)
1215 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1220 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1221 WRITE32(OP_SETATTR);
1222 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1224 if ((status = encode_attrs(xdr, arg->iap, server)))
1230 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1234 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1235 WRITE32(OP_SETCLIENTID);
1236 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1238 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1240 WRITE32(setclientid->sc_prog);
1241 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1242 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1244 WRITE32(setclientid->sc_cb_ident);
1249 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
1253 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1254 WRITE32(OP_SETCLIENTID_CONFIRM);
1255 WRITE64(client_state->cl_clientid);
1256 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1261 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1268 encode_stateid(xdr, args->context);
1271 WRITE64(args->offset);
1272 WRITE32(args->stable);
1273 WRITE32(args->count);
1275 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1280 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1286 WRITE32(OP_DELEGRETURN);
1287 WRITEMEM(stateid->data, sizeof(stateid->data));
1292 * END OF "GENERIC" ENCODE ROUTINES.
1296 * Encode an ACCESS request
1298 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1300 struct xdr_stream xdr;
1301 struct compound_hdr hdr = {
1306 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1307 encode_compound_hdr(&xdr, &hdr);
1308 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1309 status = encode_access(&xdr, args->access);
1314 * Encode LOOKUP request
1316 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1318 struct xdr_stream xdr;
1319 struct compound_hdr hdr = {
1324 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1325 encode_compound_hdr(&xdr, &hdr);
1326 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1328 if ((status = encode_lookup(&xdr, args->name)) != 0)
1330 if ((status = encode_getfh(&xdr)) != 0)
1332 status = encode_getfattr(&xdr, args->bitmask);
1338 * Encode LOOKUP_ROOT request
1340 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1342 struct xdr_stream xdr;
1343 struct compound_hdr hdr = {
1348 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1349 encode_compound_hdr(&xdr, &hdr);
1350 if ((status = encode_putrootfh(&xdr)) != 0)
1352 if ((status = encode_getfh(&xdr)) == 0)
1353 status = encode_getfattr(&xdr, args->bitmask);
1359 * Encode REMOVE request
1361 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs4_remove_arg *args)
1363 struct xdr_stream xdr;
1364 struct compound_hdr hdr = {
1369 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1370 encode_compound_hdr(&xdr, &hdr);
1371 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1373 if ((status = encode_remove(&xdr, args->name)) != 0)
1375 status = encode_getfattr(&xdr, args->bitmask);
1381 * Encode RENAME request
1383 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1385 struct xdr_stream xdr;
1386 struct compound_hdr hdr = {
1391 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1392 encode_compound_hdr(&xdr, &hdr);
1393 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1395 if ((status = encode_savefh(&xdr)) != 0)
1397 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1399 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1401 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1403 if ((status = encode_restorefh(&xdr)) != 0)
1405 status = encode_getfattr(&xdr, args->bitmask);
1411 * Encode LINK request
1413 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1415 struct xdr_stream xdr;
1416 struct compound_hdr hdr = {
1421 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1422 encode_compound_hdr(&xdr, &hdr);
1423 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1425 if ((status = encode_savefh(&xdr)) != 0)
1427 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1429 if ((status = encode_link(&xdr, args->name)) != 0)
1431 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1433 if ((status = encode_restorefh(&xdr)) != 0)
1435 status = encode_getfattr(&xdr, args->bitmask);
1441 * Encode CREATE request
1443 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1445 struct xdr_stream xdr;
1446 struct compound_hdr hdr = {
1451 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1452 encode_compound_hdr(&xdr, &hdr);
1453 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1455 if ((status = encode_savefh(&xdr)) != 0)
1457 if ((status = encode_create(&xdr, args)) != 0)
1459 if ((status = encode_getfh(&xdr)) != 0)
1461 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1463 if ((status = encode_restorefh(&xdr)) != 0)
1465 status = encode_getfattr(&xdr, args->bitmask);
1471 * Encode SYMLINK request
1473 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1475 return nfs4_xdr_enc_create(req, p, args);
1479 * Encode GETATTR request
1481 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1483 struct xdr_stream xdr;
1484 struct compound_hdr hdr = {
1489 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1490 encode_compound_hdr(&xdr, &hdr);
1491 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1492 status = encode_getfattr(&xdr, args->bitmask);
1497 * Encode a CLOSE request
1499 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1501 struct xdr_stream xdr;
1502 struct compound_hdr hdr = {
1507 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1508 encode_compound_hdr(&xdr, &hdr);
1509 status = encode_putfh(&xdr, args->fh);
1512 status = encode_close(&xdr, args);
1515 status = encode_getfattr(&xdr, args->bitmask);
1521 * Encode an OPEN request
1523 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1525 struct xdr_stream xdr;
1526 struct compound_hdr hdr = {
1531 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1532 encode_compound_hdr(&xdr, &hdr);
1533 status = encode_putfh(&xdr, args->fh);
1536 status = encode_savefh(&xdr);
1539 status = encode_open(&xdr, args);
1542 status = encode_getfh(&xdr);
1545 status = encode_getfattr(&xdr, args->bitmask);
1548 status = encode_restorefh(&xdr);
1551 status = encode_getfattr(&xdr, args->bitmask);
1557 * Encode an OPEN_CONFIRM request
1559 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1561 struct xdr_stream xdr;
1562 struct compound_hdr hdr = {
1567 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1568 encode_compound_hdr(&xdr, &hdr);
1569 status = encode_putfh(&xdr, args->fh);
1572 status = encode_open_confirm(&xdr, args);
1578 * Encode an OPEN request with no attributes.
1580 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1582 struct xdr_stream xdr;
1583 struct compound_hdr hdr = {
1588 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1589 encode_compound_hdr(&xdr, &hdr);
1590 status = encode_putfh(&xdr, args->fh);
1593 status = encode_open(&xdr, args);
1596 status = encode_getfattr(&xdr, args->bitmask);
1602 * Encode an OPEN_DOWNGRADE request
1604 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1606 struct xdr_stream xdr;
1607 struct compound_hdr hdr = {
1612 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1613 encode_compound_hdr(&xdr, &hdr);
1614 status = encode_putfh(&xdr, args->fh);
1617 status = encode_open_downgrade(&xdr, args);
1620 status = encode_getfattr(&xdr, args->bitmask);
1626 * Encode a LOCK request
1628 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1630 struct xdr_stream xdr;
1631 struct compound_hdr hdr = {
1636 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1637 encode_compound_hdr(&xdr, &hdr);
1638 status = encode_putfh(&xdr, args->fh);
1641 status = encode_lock(&xdr, args);
1647 * Encode a LOCKT request
1649 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1651 struct xdr_stream xdr;
1652 struct compound_hdr hdr = {
1657 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1658 encode_compound_hdr(&xdr, &hdr);
1659 status = encode_putfh(&xdr, args->fh);
1662 status = encode_lockt(&xdr, args);
1668 * Encode a LOCKU request
1670 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1672 struct xdr_stream xdr;
1673 struct compound_hdr hdr = {
1678 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1679 encode_compound_hdr(&xdr, &hdr);
1680 status = encode_putfh(&xdr, args->fh);
1683 status = encode_locku(&xdr, args);
1689 * Encode a READLINK request
1691 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1693 struct xdr_stream xdr;
1694 struct compound_hdr hdr = {
1699 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1700 encode_compound_hdr(&xdr, &hdr);
1701 status = encode_putfh(&xdr, args->fh);
1704 status = encode_readlink(&xdr, args, req);
1710 * Encode a READDIR request
1712 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1714 struct xdr_stream xdr;
1715 struct compound_hdr hdr = {
1720 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1721 encode_compound_hdr(&xdr, &hdr);
1722 status = encode_putfh(&xdr, args->fh);
1725 status = encode_readdir(&xdr, args, req);
1731 * Encode a READ request
1733 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1735 struct rpc_auth *auth = req->rq_task->tk_auth;
1736 struct xdr_stream xdr;
1737 struct compound_hdr hdr = {
1742 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1743 encode_compound_hdr(&xdr, &hdr);
1744 status = encode_putfh(&xdr, args->fh);
1747 status = encode_read(&xdr, args);
1751 /* set up reply kvec
1752 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1753 * + OP_READ + status + eof + datalen = 9
1755 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1756 xdr_inline_pages(&req->rq_rcv_buf, replen,
1757 args->pages, args->pgbase, args->count);
1763 * Encode an SETATTR request
1765 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1768 struct xdr_stream xdr;
1769 struct compound_hdr hdr = {
1774 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1775 encode_compound_hdr(&xdr, &hdr);
1776 status = encode_putfh(&xdr, args->fh);
1779 status = encode_setattr(&xdr, args, args->server);
1782 status = encode_getfattr(&xdr, args->bitmask);
1788 * Encode a GETACL request
1791 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1792 struct nfs_getaclargs *args)
1794 struct xdr_stream xdr;
1795 struct rpc_auth *auth = req->rq_task->tk_auth;
1796 struct compound_hdr hdr = {
1801 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1802 encode_compound_hdr(&xdr, &hdr);
1803 status = encode_putfh(&xdr, args->fh);
1806 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1807 /* set up reply buffer: */
1808 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1809 xdr_inline_pages(&req->rq_rcv_buf, replen,
1810 args->acl_pages, args->acl_pgbase, args->acl_len);
1816 * Encode a WRITE request
1818 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1820 struct xdr_stream xdr;
1821 struct compound_hdr hdr = {
1826 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1827 encode_compound_hdr(&xdr, &hdr);
1828 status = encode_putfh(&xdr, args->fh);
1831 status = encode_write(&xdr, args);
1834 status = encode_getfattr(&xdr, args->bitmask);
1842 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1844 struct xdr_stream xdr;
1845 struct compound_hdr hdr = {
1850 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1851 encode_compound_hdr(&xdr, &hdr);
1852 status = encode_putfh(&xdr, args->fh);
1855 status = encode_commit(&xdr, args);
1858 status = encode_getfattr(&xdr, args->bitmask);
1866 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1868 struct xdr_stream xdr;
1869 struct compound_hdr hdr = {
1874 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1875 encode_compound_hdr(&xdr, &hdr);
1876 status = encode_putfh(&xdr, args->fh);
1878 status = encode_fsinfo(&xdr, args->bitmask);
1883 * a PATHCONF request
1885 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1887 struct xdr_stream xdr;
1888 struct compound_hdr hdr = {
1893 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1894 encode_compound_hdr(&xdr, &hdr);
1895 status = encode_putfh(&xdr, args->fh);
1897 status = encode_getattr_one(&xdr,
1898 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1905 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
1907 struct xdr_stream xdr;
1908 struct compound_hdr hdr = {
1913 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1914 encode_compound_hdr(&xdr, &hdr);
1915 status = encode_putfh(&xdr, args->fh);
1917 status = encode_getattr_two(&xdr,
1918 args->bitmask[0] & nfs4_statfs_bitmap[0],
1919 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1924 * GETATTR_BITMAP request
1926 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
1928 struct xdr_stream xdr;
1929 struct compound_hdr hdr = {
1934 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1935 encode_compound_hdr(&xdr, &hdr);
1936 status = encode_putfh(&xdr, fhandle);
1938 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1939 FATTR4_WORD0_LINK_SUPPORT|
1940 FATTR4_WORD0_SYMLINK_SUPPORT|
1941 FATTR4_WORD0_ACLSUPPORT);
1948 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1950 struct xdr_stream xdr;
1951 struct compound_hdr hdr = {
1955 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1956 encode_compound_hdr(&xdr, &hdr);
1957 return encode_renew(&xdr, clp);
1961 * a SETCLIENTID request
1963 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
1965 struct xdr_stream xdr;
1966 struct compound_hdr hdr = {
1970 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1971 encode_compound_hdr(&xdr, &hdr);
1972 return encode_setclientid(&xdr, sc);
1976 * a SETCLIENTID_CONFIRM request
1978 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1980 struct xdr_stream xdr;
1981 struct compound_hdr hdr = {
1984 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1987 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1988 encode_compound_hdr(&xdr, &hdr);
1989 status = encode_setclientid_confirm(&xdr, clp);
1991 status = encode_putrootfh(&xdr);
1993 status = encode_fsinfo(&xdr, lease_bitmap);
1998 * DELEGRETURN request
2000 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2002 struct xdr_stream xdr;
2003 struct compound_hdr hdr = {
2008 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2009 encode_compound_hdr(&xdr, &hdr);
2010 status = encode_putfh(&xdr, args->fhandle);
2013 status = encode_delegreturn(&xdr, args->stateid);
2016 status = encode_getfattr(&xdr, args->bitmask);
2022 * Encode FS_LOCATIONS request
2024 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2026 struct xdr_stream xdr;
2027 struct compound_hdr hdr = {
2030 struct rpc_auth *auth = req->rq_task->tk_auth;
2034 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2035 encode_compound_hdr(&xdr, &hdr);
2036 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2038 if ((status = encode_lookup(&xdr, args->name)) != 0)
2040 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
2043 * toplevel_status + OP_PUTFH + status
2044 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2046 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2047 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2054 * START OF "GENERIC" DECODE ROUTINES.
2055 * These may look a little ugly since they are imported from a "generic"
2056 * set of XDR encode/decode routines which are intended to be shared by
2057 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2059 * If the pain of reading these is too great, it should be a straightforward
2060 * task to translate them into Linux-specific versions which are more
2061 * consistent with the style used in NFSv2/v3...
2063 #define READ32(x) (x) = ntohl(*p++)
2064 #define READ64(x) do { \
2065 (x) = (u64)ntohl(*p++) << 32; \
2066 (x) |= ntohl(*p++); \
2068 #define READTIME(x) do { \
2070 (x.tv_sec) = ntohl(*p++); \
2071 (x.tv_nsec) = ntohl(*p++); \
2073 #define COPYMEM(x,nbytes) do { \
2074 memcpy((x), p, nbytes); \
2075 p += XDR_QUADLEN(nbytes); \
2078 #define READ_BUF(nbytes) do { \
2079 p = xdr_inline_decode(xdr, nbytes); \
2081 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
2082 __FUNCTION__, __LINE__); \
2087 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2094 *string = (char *)p;
2098 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2103 READ32(hdr->status);
2104 READ32(hdr->taglen);
2106 READ_BUF(hdr->taglen + 4);
2107 hdr->tag = (char *)p;
2108 p += XDR_QUADLEN(hdr->taglen);
2113 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2121 if (opnum != expected) {
2123 "nfs4_decode_op_hdr: Server returned operation"
2124 " %d but we issued a request for %d\n",
2129 if (nfserr != NFS_OK)
2130 return -nfs4_stat_to_errno(nfserr);
2135 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2138 unsigned int strlen;
2142 return decode_opaque_inline(xdr, &strlen, &str);
2145 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2153 bitmap[0] = bitmap[1] = 0;
2154 READ_BUF((bmlen << 2));
2163 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2173 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2175 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2176 decode_attr_bitmap(xdr, bitmask);
2177 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2179 bitmask[0] = bitmask[1] = 0;
2180 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2184 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2189 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2191 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2194 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2195 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2198 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2200 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2204 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2209 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2211 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2214 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2216 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2217 (unsigned long long)*change);
2221 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2226 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2228 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2231 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2233 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2237 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2242 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2244 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2247 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2249 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2253 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2258 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2260 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2263 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2265 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2269 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2275 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2277 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2279 READ64(fsid->major);
2280 READ64(fsid->minor);
2281 bitmap[0] &= ~FATTR4_WORD0_FSID;
2283 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2284 (unsigned long long)fsid->major,
2285 (unsigned long long)fsid->minor);
2289 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2294 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2296 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2299 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2301 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2305 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2309 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2310 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2312 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2315 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2317 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2321 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2326 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2328 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2331 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2333 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2337 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2342 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2344 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2347 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2349 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2353 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2359 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2361 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2364 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2366 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2370 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2376 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2378 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2381 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2383 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2387 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2393 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2395 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2398 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2400 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2404 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2417 path->ncomponents = 0;
2418 while (path->ncomponents < n) {
2419 struct nfs4_string *component = &path->components[path->ncomponents];
2420 status = decode_opaque_inline(xdr, &component->len, &component->data);
2421 if (unlikely(status != 0))
2423 if (path->ncomponents != n)
2425 dprintk("%s", component->data);
2426 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2427 path->ncomponents++;
2429 dprintk("cannot parse %d components in path\n", n);
2437 /* a root pathname is sent as a zero component4 */
2438 path->ncomponents = 1;
2439 path->components[0].len=0;
2440 path->components[0].data=NULL;
2441 dprintk("path /\n");
2444 dprintk(" status %d", status);
2449 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2455 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2458 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2460 dprintk("%s: fsroot ", __FUNCTION__);
2461 status = decode_pathname(xdr, &res->fs_path);
2462 if (unlikely(status != 0))
2468 res->nlocations = 0;
2469 while (res->nlocations < n) {
2471 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2479 dprintk("%s: servers ", __FUNCTION__);
2480 while (loc->nservers < m) {
2481 struct nfs4_string *server = &loc->servers[loc->nservers];
2482 status = decode_opaque_inline(xdr, &server->len, &server->data);
2483 if (unlikely(status != 0))
2485 dprintk("%s ", server->data);
2486 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2490 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2491 for (i = loc->nservers; i < m; i++) {
2494 status = decode_opaque_inline(xdr, &len, &data);
2495 if (unlikely(status != 0))
2500 status = decode_pathname(xdr, &loc->rootpath);
2501 if (unlikely(status != 0))
2503 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2507 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2514 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2520 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2522 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2525 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2527 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2531 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2537 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2539 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2542 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2544 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2548 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2554 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2556 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2559 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2561 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2565 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2571 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2573 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2577 if (maxread > 0x7FFFFFFF)
2578 maxread = 0x7FFFFFFF;
2579 *res = (uint32_t)maxread;
2580 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2582 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2586 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2592 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2594 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2598 if (maxwrite > 0x7FFFFFFF)
2599 maxwrite = 0x7FFFFFFF;
2600 *res = (uint32_t)maxwrite;
2601 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2603 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2607 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2612 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2614 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2618 bitmap[1] &= ~FATTR4_WORD1_MODE;
2620 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2624 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2629 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2631 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2634 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2636 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2640 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, int32_t *uid)
2646 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2648 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2652 if (len < XDR_MAX_NETOBJ) {
2653 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2654 dprintk("%s: nfs_map_name_to_uid failed!\n",
2657 printk(KERN_WARNING "%s: name too long (%u)!\n",
2659 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2661 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2665 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, int32_t *gid)
2671 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2673 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2677 if (len < XDR_MAX_NETOBJ) {
2678 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2679 dprintk("%s: nfs_map_group_to_gid failed!\n",
2682 printk(KERN_WARNING "%s: name too long (%u)!\n",
2684 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2686 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2690 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2692 uint32_t major = 0, minor = 0;
2696 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2698 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2704 tmp = MKDEV(major, minor);
2705 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2707 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2709 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2713 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2719 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2721 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2724 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2726 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2730 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2736 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2738 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2741 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2743 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2747 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2753 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2755 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2758 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2760 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2764 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2769 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2771 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2774 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2776 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2777 (unsigned long long)*used);
2781 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2790 time->tv_sec = (time_t)sec;
2791 time->tv_nsec = (long)nsec;
2795 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2801 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2803 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2804 status = decode_attr_time(xdr, time);
2805 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2807 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2811 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2817 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2819 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2820 status = decode_attr_time(xdr, time);
2821 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2823 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2827 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2833 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2835 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2836 status = decode_attr_time(xdr, time);
2837 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2839 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2843 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2845 unsigned int attrwords = XDR_QUADLEN(attrlen);
2846 unsigned int nwords = xdr->p - savep;
2848 if (unlikely(attrwords != nwords)) {
2849 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2852 (attrwords < nwords) ? '<' : '>',
2859 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2864 READ32(cinfo->atomic);
2865 READ64(cinfo->before);
2866 READ64(cinfo->after);
2870 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2876 status = decode_op_hdr(xdr, OP_ACCESS);
2882 access->supported = supp;
2883 access->access = acc;
2887 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2892 status = decode_op_hdr(xdr, OP_CLOSE);
2895 READ_BUF(sizeof(res->stateid.data));
2896 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2900 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2905 status = decode_op_hdr(xdr, OP_COMMIT);
2909 COPYMEM(res->verf->verifier, 8);
2913 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2919 status = decode_op_hdr(xdr, OP_CREATE);
2922 if ((status = decode_change_info(xdr, cinfo)))
2926 READ_BUF(bmlen << 2);
2930 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2937 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2939 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2941 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2943 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2945 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2947 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2949 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2951 status = verify_attr_len(xdr, savep, attrlen);
2953 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2957 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2964 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2966 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2968 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2971 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2973 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2975 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2977 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2979 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2981 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2984 status = verify_attr_len(xdr, savep, attrlen);
2986 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2990 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2997 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2999 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3001 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3004 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3006 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3009 status = verify_attr_len(xdr, savep, attrlen);
3011 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3015 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3021 int status, fmode = 0;
3024 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3026 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3029 fattr->bitmap[0] = bitmap[0];
3030 fattr->bitmap[1] = bitmap[1];
3032 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3036 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3038 fattr->type = nfs_type2fmt[type].nfs2type;
3039 fmode = nfs_type2fmt[type].mode;
3041 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3043 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3045 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
3047 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3049 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3050 struct nfs4_fs_locations,
3053 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3055 fattr->mode |= fmode;
3056 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3058 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
3060 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
3062 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3064 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3066 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3068 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3070 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3072 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3074 if (fattr->fileid == 0 && fileid != 0)
3075 fattr->fileid = fileid;
3076 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
3077 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
3079 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
3084 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3087 uint32_t attrlen, bitmap[2];
3090 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3092 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3094 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3097 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3099 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3101 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3103 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3105 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3106 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3108 fsinfo->wtpref = fsinfo->wtmax;
3110 status = verify_attr_len(xdr, savep, attrlen);
3112 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3116 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3122 status = decode_op_hdr(xdr, OP_GETFH);
3125 /* Zero handle first to allow comparisons */
3126 memset(fh, 0, sizeof(*fh));
3130 if (len > NFS4_FHSIZE)
3134 COPYMEM(fh->data, len);
3138 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3142 status = decode_op_hdr(xdr, OP_LINK);
3145 return decode_change_info(xdr, cinfo);
3149 * We create the owner, so we know a proper owner.id length is 4.
3151 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3153 uint64_t offset, length, clientid;
3155 uint32_t namelen, type;
3162 fl->fl_start = (loff_t)offset;
3163 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3164 if (length == ~(uint64_t)0)
3165 fl->fl_end = OFFSET_MAX;
3166 fl->fl_type = F_WRLCK;
3168 fl->fl_type = F_RDLCK;
3174 return -NFS4ERR_DENIED;
3177 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3182 status = decode_op_hdr(xdr, OP_LOCK);
3184 READ_BUF(sizeof(res->stateid.data));
3185 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3186 } else if (status == -NFS4ERR_DENIED)
3187 return decode_lock_denied(xdr, NULL);
3191 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3194 status = decode_op_hdr(xdr, OP_LOCKT);
3195 if (status == -NFS4ERR_DENIED)
3196 return decode_lock_denied(xdr, res->denied);
3200 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3205 status = decode_op_hdr(xdr, OP_LOCKU);
3207 READ_BUF(sizeof(res->stateid.data));
3208 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3213 static int decode_lookup(struct xdr_stream *xdr)
3215 return decode_op_hdr(xdr, OP_LOOKUP);
3218 /* This is too sick! */
3219 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3222 uint32_t limit_type, nblocks, blocksize;
3226 switch (limit_type) {
3233 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3238 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3241 uint32_t delegation_type;
3244 READ32(delegation_type);
3245 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3246 res->delegation_type = 0;
3250 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
3251 READ32(res->do_recall);
3252 switch (delegation_type) {
3253 case NFS4_OPEN_DELEGATE_READ:
3254 res->delegation_type = FMODE_READ;
3256 case NFS4_OPEN_DELEGATE_WRITE:
3257 res->delegation_type = FMODE_WRITE|FMODE_READ;
3258 if (decode_space_limit(xdr, &res->maxsize) < 0)
3261 return decode_ace(xdr, NULL, res->server->nfs_client);
3264 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3270 status = decode_op_hdr(xdr, OP_OPEN);
3273 READ_BUF(sizeof(res->stateid.data));
3274 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3276 decode_change_info(xdr, &res->cinfo);
3279 READ32(res->rflags);
3284 READ_BUF(bmlen << 2);
3286 return decode_delegation(xdr, res);
3288 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
3292 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3297 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3300 READ_BUF(sizeof(res->stateid.data));
3301 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3305 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3310 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3313 READ_BUF(sizeof(res->stateid.data));
3314 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3318 static int decode_putfh(struct xdr_stream *xdr)
3320 return decode_op_hdr(xdr, OP_PUTFH);
3323 static int decode_putrootfh(struct xdr_stream *xdr)
3325 return decode_op_hdr(xdr, OP_PUTROOTFH);
3328 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3330 struct kvec *iov = req->rq_rcv_buf.head;
3332 uint32_t count, eof, recvd, hdrlen;
3335 status = decode_op_hdr(xdr, OP_READ);
3341 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3342 recvd = req->rq_rcv_buf.len - hdrlen;
3343 if (count > recvd) {
3344 printk(KERN_WARNING "NFS: server cheating in read reply: "
3345 "count %u > recvd %u\n", count, recvd);
3349 xdr_read_pages(xdr, count);
3355 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3357 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3358 struct page *page = *rcvbuf->pages;
3359 struct kvec *iov = rcvbuf->head;
3360 unsigned int nr, pglen = rcvbuf->page_len;
3361 __be32 *end, *entry, *p, *kaddr;
3362 uint32_t len, attrlen, xlen;
3363 int hdrlen, recvd, status;
3365 status = decode_op_hdr(xdr, OP_READDIR);
3369 COPYMEM(readdir->verifier.data, 8);
3370 dprintk("%s: verifier = 0x%x%x\n",
3372 ((u32 *)readdir->verifier.data)[0],
3373 ((u32 *)readdir->verifier.data)[1]);
3376 hdrlen = (char *) p - (char *) iov->iov_base;
3377 recvd = rcvbuf->len - hdrlen;
3380 xdr_read_pages(xdr, pglen);
3382 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3383 kaddr = p = kmap_atomic(page, KM_USER0);
3384 end = p + ((pglen + readdir->pgbase) >> 2);
3386 for (nr = 0; *p++; nr++) {
3389 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3390 p += 2; /* cookie */
3391 len = ntohl(*p++); /* filename length */
3392 if (len > NFS4_MAXNAMLEN) {
3393 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3396 xlen = XDR_QUADLEN(len);
3397 if (end - p < xlen + 1)
3399 dprintk("filename = %*s\n", len, (char *)p);
3401 len = ntohl(*p++); /* bitmap length */
3402 if (end - p < len + 1)
3405 attrlen = XDR_QUADLEN(ntohl(*p++));
3406 if (end - p < attrlen + 2)
3408 p += attrlen; /* attributes */
3411 if (!nr && (entry[0] != 0 || entry[1] == 0))
3414 kunmap_atomic(kaddr, KM_USER0);
3417 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3418 entry[0] = entry[1] = 0;
3419 /* truncate listing ? */
3421 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3426 kunmap_atomic(kaddr, KM_USER0);
3427 return -errno_NFSERR_IO;
3430 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3432 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3433 struct kvec *iov = rcvbuf->head;
3434 int hdrlen, len, recvd;
3439 status = decode_op_hdr(xdr, OP_READLINK);
3443 /* Convert length of symlink */
3446 if (len >= rcvbuf->page_len || len <= 0) {
3447 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3448 return -ENAMETOOLONG;
3450 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3451 recvd = req->rq_rcv_buf.len - hdrlen;
3453 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3454 "count %u > recvd %u\n", len, recvd);
3457 xdr_read_pages(xdr, len);
3459 * The XDR encode routine has set things up so that
3460 * the link text will be copied directly into the
3461 * buffer. We just have to do overflow-checking,
3462 * and and null-terminate the text (the VFS expects
3463 * null-termination).
3465 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3466 kaddr[len+rcvbuf->page_base] = '\0';
3467 kunmap_atomic(kaddr, KM_USER0);
3471 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3475 status = decode_op_hdr(xdr, OP_REMOVE);
3478 status = decode_change_info(xdr, cinfo);
3483 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3484 struct nfs4_change_info *new_cinfo)
3488 status = decode_op_hdr(xdr, OP_RENAME);
3491 if ((status = decode_change_info(xdr, old_cinfo)))
3493 status = decode_change_info(xdr, new_cinfo);
3498 static int decode_renew(struct xdr_stream *xdr)
3500 return decode_op_hdr(xdr, OP_RENEW);
3504 decode_restorefh(struct xdr_stream *xdr)
3506 return decode_op_hdr(xdr, OP_RESTOREFH);
3509 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3515 struct kvec *iov = req->rq_rcv_buf.head;
3519 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3521 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3523 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3526 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3528 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3531 /* We ignore &savep and don't do consistency checks on
3532 * the attr length. Let userspace figure it out.... */
3533 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3534 recvd = req->rq_rcv_buf.len - hdrlen;
3535 if (attrlen > recvd) {
3536 printk(KERN_WARNING "NFS: server cheating in getattr"
3537 " acl reply: attrlen %u > recvd %u\n",
3541 xdr_read_pages(xdr, attrlen);
3544 status = -EOPNOTSUPP;
3551 decode_savefh(struct xdr_stream *xdr)
3553 return decode_op_hdr(xdr, OP_SAVEFH);
3556 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3563 status = decode_op_hdr(xdr, OP_SETATTR);
3568 READ_BUF(bmlen << 2);
3572 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3580 if (opnum != OP_SETCLIENTID) {
3582 "nfs4_decode_setclientid: Server returned operation"
3587 if (nfserr == NFS_OK) {
3588 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3589 READ64(clp->cl_clientid);
3590 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3591 } else if (nfserr == NFSERR_CLID_INUSE) {
3594 /* skip netid string */
3599 /* skip uaddr string */
3603 return -NFSERR_CLID_INUSE;
3605 return -nfs4_stat_to_errno(nfserr);
3610 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3612 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3615 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3620 status = decode_op_hdr(xdr, OP_WRITE);
3626 READ32(res->verf->committed);
3627 COPYMEM(res->verf->verifier, 8);
3631 static int decode_delegreturn(struct xdr_stream *xdr)
3633 return decode_op_hdr(xdr, OP_DELEGRETURN);
3637 * Decode OPEN_DOWNGRADE response
3639 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3641 struct xdr_stream xdr;
3642 struct compound_hdr hdr;
3645 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3646 status = decode_compound_hdr(&xdr, &hdr);
3649 status = decode_putfh(&xdr);
3652 status = decode_open_downgrade(&xdr, res);
3655 decode_getfattr(&xdr, res->fattr, res->server);
3661 * END OF "GENERIC" DECODE ROUTINES.
3665 * Decode ACCESS response
3667 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3669 struct xdr_stream xdr;
3670 struct compound_hdr hdr;
3673 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3674 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3676 if ((status = decode_putfh(&xdr)) == 0)
3677 status = decode_access(&xdr, res);
3683 * Decode LOOKUP response
3685 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3687 struct xdr_stream xdr;
3688 struct compound_hdr hdr;
3691 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3692 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3694 if ((status = decode_putfh(&xdr)) != 0)
3696 if ((status = decode_lookup(&xdr)) != 0)
3698 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3700 status = decode_getfattr(&xdr, res->fattr, res->server);
3706 * Decode LOOKUP_ROOT response
3708 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3710 struct xdr_stream xdr;
3711 struct compound_hdr hdr;
3714 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3715 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3717 if ((status = decode_putrootfh(&xdr)) != 0)
3719 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3720 status = decode_getfattr(&xdr, res->fattr, res->server);
3726 * Decode REMOVE response
3728 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_remove_res *res)
3730 struct xdr_stream xdr;
3731 struct compound_hdr hdr;
3734 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3735 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3737 if ((status = decode_putfh(&xdr)) != 0)
3739 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3741 decode_getfattr(&xdr, res->dir_attr, res->server);
3747 * Decode RENAME response
3749 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3751 struct xdr_stream xdr;
3752 struct compound_hdr hdr;
3755 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3756 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3758 if ((status = decode_putfh(&xdr)) != 0)
3760 if ((status = decode_savefh(&xdr)) != 0)
3762 if ((status = decode_putfh(&xdr)) != 0)
3764 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3766 /* Current FH is target directory */
3767 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3769 if ((status = decode_restorefh(&xdr)) != 0)
3771 decode_getfattr(&xdr, res->old_fattr, res->server);
3777 * Decode LINK response
3779 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3781 struct xdr_stream xdr;
3782 struct compound_hdr hdr;
3785 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3786 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3788 if ((status = decode_putfh(&xdr)) != 0)
3790 if ((status = decode_savefh(&xdr)) != 0)
3792 if ((status = decode_putfh(&xdr)) != 0)
3794 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3797 * Note order: OP_LINK leaves the directory as the current
3800 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3802 if ((status = decode_restorefh(&xdr)) != 0)
3804 decode_getfattr(&xdr, res->fattr, res->server);
3810 * Decode CREATE response
3812 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3814 struct xdr_stream xdr;
3815 struct compound_hdr hdr;
3818 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3819 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3821 if ((status = decode_putfh(&xdr)) != 0)
3823 if ((status = decode_savefh(&xdr)) != 0)
3825 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3827 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3829 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3831 if ((status = decode_restorefh(&xdr)) != 0)
3833 decode_getfattr(&xdr, res->dir_fattr, res->server);
3839 * Decode SYMLINK response
3841 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3843 return nfs4_xdr_dec_create(rqstp, p, res);
3847 * Decode GETATTR response
3849 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3851 struct xdr_stream xdr;
3852 struct compound_hdr hdr;
3855 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3856 status = decode_compound_hdr(&xdr, &hdr);
3859 status = decode_putfh(&xdr);
3862 status = decode_getfattr(&xdr, res->fattr, res->server);
3869 * Encode an SETACL request
3872 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3874 struct xdr_stream xdr;
3875 struct compound_hdr hdr = {
3880 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3881 encode_compound_hdr(&xdr, &hdr);
3882 status = encode_putfh(&xdr, args->fh);
3885 status = encode_setacl(&xdr, args);
3890 * Decode SETACL response
3893 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
3895 struct xdr_stream xdr;
3896 struct compound_hdr hdr;
3899 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3900 status = decode_compound_hdr(&xdr, &hdr);
3903 status = decode_putfh(&xdr);
3906 status = decode_setattr(&xdr, res);
3912 * Decode GETACL response
3915 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
3917 struct xdr_stream xdr;
3918 struct compound_hdr hdr;
3921 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3922 status = decode_compound_hdr(&xdr, &hdr);
3925 status = decode_putfh(&xdr);
3928 status = decode_getacl(&xdr, rqstp, acl_len);
3935 * Decode CLOSE response
3937 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3939 struct xdr_stream xdr;
3940 struct compound_hdr hdr;
3943 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3944 status = decode_compound_hdr(&xdr, &hdr);
3947 status = decode_putfh(&xdr);
3950 status = decode_close(&xdr, res);
3954 * Note: Server may do delete on close for this file
3955 * in which case the getattr call will fail with
3956 * an ESTALE error. Shouldn't be a problem,
3957 * though, since fattr->valid will remain unset.
3959 decode_getfattr(&xdr, res->fattr, res->server);
3965 * Decode OPEN response
3967 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
3969 struct xdr_stream xdr;
3970 struct compound_hdr hdr;
3973 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3974 status = decode_compound_hdr(&xdr, &hdr);
3977 status = decode_putfh(&xdr);
3980 status = decode_savefh(&xdr);
3983 status = decode_open(&xdr, res);
3986 status = decode_getfh(&xdr, &res->fh);
3989 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
3991 if ((status = decode_restorefh(&xdr)) != 0)
3993 decode_getfattr(&xdr, res->dir_attr, res->server);
3999 * Decode OPEN_CONFIRM response
4001 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4003 struct xdr_stream xdr;
4004 struct compound_hdr hdr;
4007 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4008 status = decode_compound_hdr(&xdr, &hdr);
4011 status = decode_putfh(&xdr);
4014 status = decode_open_confirm(&xdr, res);
4020 * Decode OPEN response
4022 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4024 struct xdr_stream xdr;
4025 struct compound_hdr hdr;
4028 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4029 status = decode_compound_hdr(&xdr, &hdr);
4032 status = decode_putfh(&xdr);
4035 status = decode_open(&xdr, res);
4038 decode_getfattr(&xdr, res->f_attr, res->server);
4044 * Decode SETATTR response
4046 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4048 struct xdr_stream xdr;
4049 struct compound_hdr hdr;
4052 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4053 status = decode_compound_hdr(&xdr, &hdr);
4056 status = decode_putfh(&xdr);
4059 status = decode_setattr(&xdr, res);
4062 status = decode_getfattr(&xdr, res->fattr, res->server);
4063 if (status == NFS4ERR_DELAY)
4070 * Decode LOCK response
4072 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4074 struct xdr_stream xdr;
4075 struct compound_hdr hdr;
4078 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4079 status = decode_compound_hdr(&xdr, &hdr);
4082 status = decode_putfh(&xdr);
4085 status = decode_lock(&xdr, res);
4091 * Decode LOCKT response
4093 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4095 struct xdr_stream xdr;
4096 struct compound_hdr hdr;
4099 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4100 status = decode_compound_hdr(&xdr, &hdr);
4103 status = decode_putfh(&xdr);
4106 status = decode_lockt(&xdr, res);
4112 * Decode LOCKU response
4114 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4116 struct xdr_stream xdr;
4117 struct compound_hdr hdr;
4120 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4121 status = decode_compound_hdr(&xdr, &hdr);
4124 status = decode_putfh(&xdr);
4127 status = decode_locku(&xdr, res);
4133 * Decode READLINK response
4135 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
4137 struct xdr_stream xdr;
4138 struct compound_hdr hdr;
4141 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4142 status = decode_compound_hdr(&xdr, &hdr);
4145 status = decode_putfh(&xdr);
4148 status = decode_readlink(&xdr, rqstp);
4154 * Decode READDIR response
4156 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4158 struct xdr_stream xdr;
4159 struct compound_hdr hdr;
4162 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4163 status = decode_compound_hdr(&xdr, &hdr);
4166 status = decode_putfh(&xdr);
4169 status = decode_readdir(&xdr, rqstp, res);
4175 * Decode Read response
4177 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4179 struct xdr_stream xdr;
4180 struct compound_hdr hdr;
4183 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4184 status = decode_compound_hdr(&xdr, &hdr);
4187 status = decode_putfh(&xdr);
4190 status = decode_read(&xdr, rqstp, res);
4192 status = res->count;
4198 * Decode WRITE response
4200 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4202 struct xdr_stream xdr;
4203 struct compound_hdr hdr;
4206 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4207 status = decode_compound_hdr(&xdr, &hdr);
4210 status = decode_putfh(&xdr);
4213 status = decode_write(&xdr, res);
4216 decode_getfattr(&xdr, res->fattr, res->server);
4218 status = res->count;
4224 * Decode COMMIT response
4226 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4228 struct xdr_stream xdr;
4229 struct compound_hdr hdr;
4232 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4233 status = decode_compound_hdr(&xdr, &hdr);
4236 status = decode_putfh(&xdr);
4239 status = decode_commit(&xdr, res);
4242 decode_getfattr(&xdr, res->fattr, res->server);
4250 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4252 struct xdr_stream xdr;
4253 struct compound_hdr hdr;
4256 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4257 status = decode_compound_hdr(&xdr, &hdr);
4259 status = decode_putfh(&xdr);
4261 status = decode_fsinfo(&xdr, fsinfo);
4263 status = -nfs4_stat_to_errno(hdr.status);
4270 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
4272 struct xdr_stream xdr;
4273 struct compound_hdr hdr;
4276 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4277 status = decode_compound_hdr(&xdr, &hdr);
4279 status = decode_putfh(&xdr);
4281 status = decode_pathconf(&xdr, pathconf);
4288 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
4290 struct xdr_stream xdr;
4291 struct compound_hdr hdr;
4294 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4295 status = decode_compound_hdr(&xdr, &hdr);
4297 status = decode_putfh(&xdr);
4299 status = decode_statfs(&xdr, fsstat);
4304 * GETATTR_BITMAP request
4306 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4308 struct xdr_stream xdr;
4309 struct compound_hdr hdr;
4312 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4313 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4315 if ((status = decode_putfh(&xdr)) != 0)
4317 status = decode_server_caps(&xdr, res);
4323 * Decode RENEW response
4325 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4327 struct xdr_stream xdr;
4328 struct compound_hdr hdr;
4331 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4332 status = decode_compound_hdr(&xdr, &hdr);
4334 status = decode_renew(&xdr);
4339 * a SETCLIENTID request
4341 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4342 struct nfs_client *clp)
4344 struct xdr_stream xdr;
4345 struct compound_hdr hdr;
4348 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4349 status = decode_compound_hdr(&xdr, &hdr);
4351 status = decode_setclientid(&xdr, clp);
4353 status = -nfs4_stat_to_errno(hdr.status);
4358 * a SETCLIENTID_CONFIRM request
4360 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4362 struct xdr_stream xdr;
4363 struct compound_hdr hdr;
4366 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4367 status = decode_compound_hdr(&xdr, &hdr);
4369 status = decode_setclientid_confirm(&xdr);
4371 status = decode_putrootfh(&xdr);
4373 status = decode_fsinfo(&xdr, fsinfo);
4375 status = -nfs4_stat_to_errno(hdr.status);
4380 * DELEGRETURN request
4382 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4384 struct xdr_stream xdr;
4385 struct compound_hdr hdr;
4388 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4389 status = decode_compound_hdr(&xdr, &hdr);
4392 status = decode_putfh(&xdr);
4395 status = decode_delegreturn(&xdr);
4396 decode_getfattr(&xdr, res->fattr, res->server);
4402 * FS_LOCATIONS request
4404 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
4406 struct xdr_stream xdr;
4407 struct compound_hdr hdr;
4410 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4411 status = decode_compound_hdr(&xdr, &hdr);
4414 if ((status = decode_putfh(&xdr)) != 0)
4416 if ((status = decode_lookup(&xdr)) != 0)
4418 xdr_enter_page(&xdr, PAGE_SIZE);
4419 status = decode_getfattr(&xdr, &res->fattr, res->server);
4424 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4426 uint32_t bitmap[2] = {0};
4431 return ERR_PTR(-EAGAIN);
4433 return ERR_PTR(-EBADCOOKIE);
4436 entry->prev_cookie = entry->cookie;
4437 p = xdr_decode_hyper(p, &entry->cookie);
4438 entry->len = ntohl(*p++);
4439 entry->name = (const char *) p;
4440 p += XDR_QUADLEN(entry->len);
4443 * In case the server doesn't return an inode number,
4444 * we fake one here. (We don't use inode number 0,
4445 * since glibc seems to choke on it...)
4449 len = ntohl(*p++); /* bitmap length */
4451 bitmap[0] = ntohl(*p++);
4453 bitmap[1] = ntohl(*p++);
4457 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4459 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4460 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4461 /* Ignore the return value of rdattr_error for now */
4465 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4466 xdr_decode_hyper(p, &entry->ino);
4467 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4468 xdr_decode_hyper(p, &entry->ino);
4472 entry->eof = !p[0] && p[1];
4477 * We need to translate between nfs status return values and
4478 * the local errno values which may not be the same.
4485 { NFS4ERR_PERM, EPERM },
4486 { NFS4ERR_NOENT, ENOENT },
4487 { NFS4ERR_IO, errno_NFSERR_IO },
4488 { NFS4ERR_NXIO, ENXIO },
4489 { NFS4ERR_ACCESS, EACCES },
4490 { NFS4ERR_EXIST, EEXIST },
4491 { NFS4ERR_XDEV, EXDEV },
4492 { NFS4ERR_NOTDIR, ENOTDIR },
4493 { NFS4ERR_ISDIR, EISDIR },
4494 { NFS4ERR_INVAL, EINVAL },
4495 { NFS4ERR_FBIG, EFBIG },
4496 { NFS4ERR_NOSPC, ENOSPC },
4497 { NFS4ERR_ROFS, EROFS },
4498 { NFS4ERR_MLINK, EMLINK },
4499 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4500 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4501 { NFS4ERR_DQUOT, EDQUOT },
4502 { NFS4ERR_STALE, ESTALE },
4503 { NFS4ERR_BADHANDLE, EBADHANDLE },
4504 { NFS4ERR_BADOWNER, EINVAL },
4505 { NFS4ERR_BADNAME, EINVAL },
4506 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4507 { NFS4ERR_NOTSUPP, ENOTSUPP },
4508 { NFS4ERR_TOOSMALL, ETOOSMALL },
4509 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4510 { NFS4ERR_BADTYPE, EBADTYPE },
4511 { NFS4ERR_LOCKED, EAGAIN },
4512 { NFS4ERR_RESOURCE, EREMOTEIO },
4513 { NFS4ERR_SYMLINK, ELOOP },
4514 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4515 { NFS4ERR_DEADLOCK, EDEADLK },
4516 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4517 * to be handled by a
4524 * Convert an NFS error code to a local one.
4525 * This one is used jointly by NFSv2 and NFSv3.
4528 nfs4_stat_to_errno(int stat)
4531 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4532 if (nfs_errtbl[i].stat == stat)
4533 return nfs_errtbl[i].errno;
4535 if (stat <= 10000 || stat > 10100) {
4536 /* The server is looney tunes. */
4537 return ESERVERFAULT;
4539 /* If we cannot translate the error, the recovery routines should
4541 * Note: remaining NFSv4 error codes have values > 10000, so should
4542 * not conflict with native Linux error codes.
4548 # define MAX(a, b) (((a) > (b))? (a) : (b))
4551 #define PROC(proc, argtype, restype) \
4552 [NFSPROC4_CLNT_##proc] = { \
4553 .p_proc = NFSPROC4_COMPOUND, \
4554 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4555 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4556 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
4557 .p_statidx = NFSPROC4_CLNT_##proc, \
4561 struct rpc_procinfo nfs4_procedures[] = {
4562 PROC(READ, enc_read, dec_read),
4563 PROC(WRITE, enc_write, dec_write),
4564 PROC(COMMIT, enc_commit, dec_commit),
4565 PROC(OPEN, enc_open, dec_open),
4566 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4567 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4568 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4569 PROC(CLOSE, enc_close, dec_close),
4570 PROC(SETATTR, enc_setattr, dec_setattr),
4571 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4572 PROC(RENEW, enc_renew, dec_renew),
4573 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4574 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4575 PROC(LOCK, enc_lock, dec_lock),
4576 PROC(LOCKT, enc_lockt, dec_lockt),
4577 PROC(LOCKU, enc_locku, dec_locku),
4578 PROC(ACCESS, enc_access, dec_access),
4579 PROC(GETATTR, enc_getattr, dec_getattr),
4580 PROC(LOOKUP, enc_lookup, dec_lookup),
4581 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4582 PROC(REMOVE, enc_remove, dec_remove),
4583 PROC(RENAME, enc_rename, dec_rename),
4584 PROC(LINK, enc_link, dec_link),
4585 PROC(SYMLINK, enc_symlink, dec_symlink),
4586 PROC(CREATE, enc_create, dec_create),
4587 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4588 PROC(STATFS, enc_statfs, dec_statfs),
4589 PROC(READLINK, enc_readlink, dec_readlink),
4590 PROC(READDIR, enc_readdir, dec_readdir),
4591 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4592 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4593 PROC(GETACL, enc_getacl, dec_getacl),
4594 PROC(SETACL, enc_setacl, dec_setacl),
4595 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4598 struct rpc_version nfs_version4 = {
4600 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4601 .procs = nfs4_procedures