4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define owner_id_maxsz (1 + 1)
74 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
75 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
76 #define op_encode_hdr_maxsz (1)
77 #define op_decode_hdr_maxsz (2)
78 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
80 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
81 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
82 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
83 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
84 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
85 ((3+NFS4_FHSIZE) >> 2))
86 #define nfs4_fattr_bitmap_maxsz 3
87 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
88 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
89 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
90 /* This is based on getfattr, which uses the most attributes: */
91 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
92 3 + 3 + 3 + 2 * nfs4_name_maxsz))
93 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
94 nfs4_fattr_value_maxsz)
95 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
96 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
97 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
98 #define encode_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->nfs4_state, 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->nfs4_state, 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) {
676 RESERVE_SPACE(4 + create->u.symlink->len);
677 WRITE32(create->u.symlink->len);
678 WRITEMEM(create->u.symlink->name, 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_getfh(struct xdr_stream *xdr)
744 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
748 RESERVE_SPACE(8 + name->len);
751 WRITEMEM(name->name, name->len);
756 static inline int nfs4_lock_type(struct file_lock *fl, int block)
758 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
759 return block ? NFS4_READW_LT : NFS4_READ_LT;
760 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
763 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
765 if (fl->fl_end == OFFSET_MAX)
767 return fl->fl_end - fl->fl_start + 1;
771 * opcode,type,reclaim,offset,length,new_lock_owner = 32
772 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
774 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
780 WRITE32(nfs4_lock_type(args->fl, args->block));
781 WRITE32(args->reclaim);
782 WRITE64(args->fl->fl_start);
783 WRITE64(nfs4_lock_length(args->fl));
784 WRITE32(args->new_lock_owner);
785 if (args->new_lock_owner){
787 WRITE32(args->open_seqid->sequence->counter);
788 WRITEMEM(args->open_stateid->data, sizeof(args->open_stateid->data));
789 WRITE32(args->lock_seqid->sequence->counter);
790 WRITE64(args->lock_owner.clientid);
792 WRITE32(args->lock_owner.id);
796 WRITEMEM(args->lock_stateid->data, sizeof(args->lock_stateid->data));
797 WRITE32(args->lock_seqid->sequence->counter);
803 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
809 WRITE32(nfs4_lock_type(args->fl, 0));
810 WRITE64(args->fl->fl_start);
811 WRITE64(nfs4_lock_length(args->fl));
812 WRITE64(args->lock_owner.clientid);
814 WRITE32(args->lock_owner.id);
819 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
825 WRITE32(nfs4_lock_type(args->fl, 0));
826 WRITE32(args->seqid->sequence->counter);
827 WRITEMEM(args->stateid->data, sizeof(args->stateid->data));
828 WRITE64(args->fl->fl_start);
829 WRITE64(nfs4_lock_length(args->fl));
834 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
839 RESERVE_SPACE(8 + len);
842 WRITEMEM(name->name, len);
847 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
852 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
854 WRITE32(NFS4_SHARE_ACCESS_READ);
857 WRITE32(NFS4_SHARE_ACCESS_WRITE);
859 case FMODE_READ|FMODE_WRITE:
860 WRITE32(NFS4_SHARE_ACCESS_BOTH);
865 WRITE32(0); /* for linux, share_deny = 0 always */
868 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
872 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
877 WRITE32(arg->seqid->sequence->counter);
878 encode_share_access(xdr, arg->open_flags);
880 WRITE64(arg->clientid);
885 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
890 switch(arg->open_flags & O_EXCL) {
892 WRITE32(NFS4_CREATE_UNCHECKED);
893 encode_attrs(xdr, arg->u.attrs, arg->server);
896 WRITE32(NFS4_CREATE_EXCLUSIVE);
897 encode_nfs4_verifier(xdr, &arg->u.verifier);
901 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
906 switch (arg->open_flags & O_CREAT) {
908 WRITE32(NFS4_OPEN_NOCREATE);
911 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
912 WRITE32(NFS4_OPEN_CREATE);
913 encode_createmode(xdr, arg);
917 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
922 switch (delegation_type) {
924 WRITE32(NFS4_OPEN_DELEGATE_NONE);
927 WRITE32(NFS4_OPEN_DELEGATE_READ);
929 case FMODE_WRITE|FMODE_READ:
930 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
937 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
942 WRITE32(NFS4_OPEN_CLAIM_NULL);
943 encode_string(xdr, name->len, name->name);
946 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
951 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
952 encode_delegation_type(xdr, type);
955 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
959 RESERVE_SPACE(4+sizeof(stateid->data));
960 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
961 WRITEMEM(stateid->data, sizeof(stateid->data));
962 encode_string(xdr, name->len, name->name);
965 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
967 encode_openhdr(xdr, arg);
968 encode_opentype(xdr, arg);
969 switch (arg->claim) {
970 case NFS4_OPEN_CLAIM_NULL:
971 encode_claim_null(xdr, arg->name);
973 case NFS4_OPEN_CLAIM_PREVIOUS:
974 encode_claim_previous(xdr, arg->u.delegation_type);
976 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
977 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
985 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
989 RESERVE_SPACE(8+sizeof(arg->stateid->data));
990 WRITE32(OP_OPEN_CONFIRM);
991 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
992 WRITE32(arg->seqid->sequence->counter);
997 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1001 RESERVE_SPACE(8+sizeof(arg->stateid->data));
1002 WRITE32(OP_OPEN_DOWNGRADE);
1003 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
1004 WRITE32(arg->seqid->sequence->counter);
1005 encode_share_access(xdr, arg->open_flags);
1010 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1015 RESERVE_SPACE(8 + len);
1018 WRITEMEM(fh->data, len);
1023 static int encode_putrootfh(struct xdr_stream *xdr)
1028 WRITE32(OP_PUTROOTFH);
1033 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1035 nfs4_stateid stateid;
1039 if (ctx->state != NULL) {
1040 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1041 WRITEMEM(stateid.data, sizeof(stateid.data));
1043 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1046 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1053 encode_stateid(xdr, args->context);
1056 WRITE64(args->offset);
1057 WRITE32(args->count);
1062 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1064 struct rpc_auth *auth = req->rq_task->tk_auth;
1065 uint32_t attrs[2] = {
1066 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1067 FATTR4_WORD1_MOUNTED_ON_FILEID,
1072 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1073 WRITE32(OP_READDIR);
1074 WRITE64(readdir->cookie);
1075 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1076 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1077 WRITE32(readdir->count);
1079 /* Switch to mounted_on_fileid if the server supports it */
1080 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1081 attrs[0] &= ~FATTR4_WORD0_FILEID;
1083 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1084 WRITE32(attrs[0] & readdir->bitmask[0]);
1085 WRITE32(attrs[1] & readdir->bitmask[1]);
1086 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1088 (unsigned long long)readdir->cookie,
1089 ((u32 *)readdir->verifier.data)[0],
1090 ((u32 *)readdir->verifier.data)[1],
1091 attrs[0] & readdir->bitmask[0],
1092 attrs[1] & readdir->bitmask[1]);
1094 /* set up reply kvec
1095 * toplevel_status + taglen + rescount + OP_PUTFH + status
1096 * + OP_READDIR + status + verifer(2) = 9
1098 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1099 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1100 readdir->pgbase, readdir->count);
1101 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1102 __FUNCTION__, replen, readdir->pages,
1103 readdir->pgbase, readdir->count);
1108 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1110 struct rpc_auth *auth = req->rq_task->tk_auth;
1111 unsigned int replen;
1115 WRITE32(OP_READLINK);
1117 /* set up reply kvec
1118 * toplevel_status + taglen + rescount + OP_PUTFH + status
1119 * + OP_READLINK + status + string length = 8
1121 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1122 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1123 readlink->pgbase, readlink->pglen);
1128 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1132 RESERVE_SPACE(8 + name->len);
1135 WRITEMEM(name->name, name->len);
1140 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1144 RESERVE_SPACE(8 + oldname->len);
1146 WRITE32(oldname->len);
1147 WRITEMEM(oldname->name, oldname->len);
1149 RESERVE_SPACE(4 + newname->len);
1150 WRITE32(newname->len);
1151 WRITEMEM(newname->name, newname->len);
1156 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1162 WRITE64(client_stateid->cl_clientid);
1168 encode_restorefh(struct xdr_stream *xdr)
1173 WRITE32(OP_RESTOREFH);
1179 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1183 RESERVE_SPACE(4+sizeof(zero_stateid.data));
1184 WRITE32(OP_SETATTR);
1185 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1188 WRITE32(FATTR4_WORD0_ACL);
1189 if (arg->acl_len % 4)
1192 WRITE32(arg->acl_len);
1193 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1198 encode_savefh(struct xdr_stream *xdr)
1208 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1213 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1214 WRITE32(OP_SETATTR);
1215 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1217 if ((status = encode_attrs(xdr, arg->iap, server)))
1223 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1227 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1228 WRITE32(OP_SETCLIENTID);
1229 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1231 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1233 WRITE32(setclientid->sc_prog);
1234 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1235 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1237 WRITE32(setclientid->sc_cb_ident);
1242 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1246 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1247 WRITE32(OP_SETCLIENTID_CONFIRM);
1248 WRITE64(client_state->cl_clientid);
1249 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1254 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1261 encode_stateid(xdr, args->context);
1264 WRITE64(args->offset);
1265 WRITE32(args->stable);
1266 WRITE32(args->count);
1268 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1273 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1279 WRITE32(OP_DELEGRETURN);
1280 WRITEMEM(stateid->data, sizeof(stateid->data));
1285 * END OF "GENERIC" ENCODE ROUTINES.
1289 * Encode an ACCESS request
1291 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1293 struct xdr_stream xdr;
1294 struct compound_hdr hdr = {
1299 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1300 encode_compound_hdr(&xdr, &hdr);
1301 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1302 status = encode_access(&xdr, args->access);
1307 * Encode LOOKUP request
1309 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1311 struct xdr_stream xdr;
1312 struct compound_hdr hdr = {
1317 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1318 encode_compound_hdr(&xdr, &hdr);
1319 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1321 if ((status = encode_lookup(&xdr, args->name)) != 0)
1323 if ((status = encode_getfh(&xdr)) != 0)
1325 status = encode_getfattr(&xdr, args->bitmask);
1331 * Encode LOOKUP_ROOT request
1333 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1335 struct xdr_stream xdr;
1336 struct compound_hdr hdr = {
1341 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1342 encode_compound_hdr(&xdr, &hdr);
1343 if ((status = encode_putrootfh(&xdr)) != 0)
1345 if ((status = encode_getfh(&xdr)) == 0)
1346 status = encode_getfattr(&xdr, args->bitmask);
1352 * Encode REMOVE request
1354 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1356 struct xdr_stream xdr;
1357 struct compound_hdr hdr = {
1362 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1363 encode_compound_hdr(&xdr, &hdr);
1364 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1366 if ((status = encode_remove(&xdr, args->name)) != 0)
1368 status = encode_getfattr(&xdr, args->bitmask);
1374 * Encode RENAME request
1376 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1378 struct xdr_stream xdr;
1379 struct compound_hdr hdr = {
1384 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1385 encode_compound_hdr(&xdr, &hdr);
1386 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1388 if ((status = encode_savefh(&xdr)) != 0)
1390 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1392 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1394 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1396 if ((status = encode_restorefh(&xdr)) != 0)
1398 status = encode_getfattr(&xdr, args->bitmask);
1404 * Encode LINK request
1406 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1408 struct xdr_stream xdr;
1409 struct compound_hdr hdr = {
1414 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1415 encode_compound_hdr(&xdr, &hdr);
1416 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1418 if ((status = encode_savefh(&xdr)) != 0)
1420 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1422 if ((status = encode_link(&xdr, args->name)) != 0)
1424 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1426 if ((status = encode_restorefh(&xdr)) != 0)
1428 status = encode_getfattr(&xdr, args->bitmask);
1434 * Encode CREATE request
1436 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1438 struct xdr_stream xdr;
1439 struct compound_hdr hdr = {
1444 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1445 encode_compound_hdr(&xdr, &hdr);
1446 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1448 if ((status = encode_savefh(&xdr)) != 0)
1450 if ((status = encode_create(&xdr, args)) != 0)
1452 if ((status = encode_getfh(&xdr)) != 0)
1454 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1456 if ((status = encode_restorefh(&xdr)) != 0)
1458 status = encode_getfattr(&xdr, args->bitmask);
1464 * Encode SYMLINK request
1466 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1468 return nfs4_xdr_enc_create(req, p, args);
1472 * Encode GETATTR request
1474 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1476 struct xdr_stream xdr;
1477 struct compound_hdr hdr = {
1482 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1483 encode_compound_hdr(&xdr, &hdr);
1484 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1485 status = encode_getfattr(&xdr, args->bitmask);
1490 * Encode a CLOSE request
1492 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1494 struct xdr_stream xdr;
1495 struct compound_hdr hdr = {
1500 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1501 encode_compound_hdr(&xdr, &hdr);
1502 status = encode_putfh(&xdr, args->fh);
1505 status = encode_close(&xdr, args);
1508 status = encode_getfattr(&xdr, args->bitmask);
1514 * Encode an OPEN request
1516 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1518 struct xdr_stream xdr;
1519 struct compound_hdr hdr = {
1524 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1525 encode_compound_hdr(&xdr, &hdr);
1526 status = encode_putfh(&xdr, args->fh);
1529 status = encode_savefh(&xdr);
1532 status = encode_open(&xdr, args);
1535 status = encode_getfh(&xdr);
1538 status = encode_getfattr(&xdr, args->bitmask);
1541 status = encode_restorefh(&xdr);
1544 status = encode_getfattr(&xdr, args->bitmask);
1550 * Encode an OPEN_CONFIRM request
1552 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1554 struct xdr_stream xdr;
1555 struct compound_hdr hdr = {
1560 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1561 encode_compound_hdr(&xdr, &hdr);
1562 status = encode_putfh(&xdr, args->fh);
1565 status = encode_open_confirm(&xdr, args);
1571 * Encode an OPEN request with no attributes.
1573 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1575 struct xdr_stream xdr;
1576 struct compound_hdr hdr = {
1581 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1582 encode_compound_hdr(&xdr, &hdr);
1583 status = encode_putfh(&xdr, args->fh);
1586 status = encode_open(&xdr, args);
1589 status = encode_getfattr(&xdr, args->bitmask);
1595 * Encode an OPEN_DOWNGRADE request
1597 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1599 struct xdr_stream xdr;
1600 struct compound_hdr hdr = {
1605 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1606 encode_compound_hdr(&xdr, &hdr);
1607 status = encode_putfh(&xdr, args->fh);
1610 status = encode_open_downgrade(&xdr, args);
1613 status = encode_getfattr(&xdr, args->bitmask);
1619 * Encode a LOCK request
1621 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lock_args *args)
1623 struct xdr_stream xdr;
1624 struct compound_hdr hdr = {
1629 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1630 encode_compound_hdr(&xdr, &hdr);
1631 status = encode_putfh(&xdr, args->fh);
1634 status = encode_lock(&xdr, args);
1640 * Encode a LOCKT request
1642 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockt_args *args)
1644 struct xdr_stream xdr;
1645 struct compound_hdr hdr = {
1650 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1651 encode_compound_hdr(&xdr, &hdr);
1652 status = encode_putfh(&xdr, args->fh);
1655 status = encode_lockt(&xdr, args);
1661 * Encode a LOCKU request
1663 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_locku_args *args)
1665 struct xdr_stream xdr;
1666 struct compound_hdr hdr = {
1671 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1672 encode_compound_hdr(&xdr, &hdr);
1673 status = encode_putfh(&xdr, args->fh);
1676 status = encode_locku(&xdr, args);
1682 * Encode a READLINK request
1684 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1686 struct xdr_stream xdr;
1687 struct compound_hdr hdr = {
1692 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1693 encode_compound_hdr(&xdr, &hdr);
1694 status = encode_putfh(&xdr, args->fh);
1697 status = encode_readlink(&xdr, args, req);
1703 * Encode a READDIR request
1705 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1707 struct xdr_stream xdr;
1708 struct compound_hdr hdr = {
1713 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1714 encode_compound_hdr(&xdr, &hdr);
1715 status = encode_putfh(&xdr, args->fh);
1718 status = encode_readdir(&xdr, args, req);
1724 * Encode a READ request
1726 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1728 struct rpc_auth *auth = req->rq_task->tk_auth;
1729 struct xdr_stream xdr;
1730 struct compound_hdr hdr = {
1735 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1736 encode_compound_hdr(&xdr, &hdr);
1737 status = encode_putfh(&xdr, args->fh);
1740 status = encode_read(&xdr, args);
1744 /* set up reply kvec
1745 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1746 * + OP_READ + status + eof + datalen = 9
1748 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1749 xdr_inline_pages(&req->rq_rcv_buf, replen,
1750 args->pages, args->pgbase, args->count);
1756 * Encode an SETATTR request
1758 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1761 struct xdr_stream xdr;
1762 struct compound_hdr hdr = {
1767 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1768 encode_compound_hdr(&xdr, &hdr);
1769 status = encode_putfh(&xdr, args->fh);
1772 status = encode_setattr(&xdr, args, args->server);
1775 status = encode_getfattr(&xdr, args->bitmask);
1781 * Encode a GETACL request
1784 nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p,
1785 struct nfs_getaclargs *args)
1787 struct xdr_stream xdr;
1788 struct rpc_auth *auth = req->rq_task->tk_auth;
1789 struct compound_hdr hdr = {
1794 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1795 encode_compound_hdr(&xdr, &hdr);
1796 status = encode_putfh(&xdr, args->fh);
1799 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1800 /* set up reply buffer: */
1801 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1802 xdr_inline_pages(&req->rq_rcv_buf, replen,
1803 args->acl_pages, args->acl_pgbase, args->acl_len);
1809 * Encode a WRITE request
1811 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1813 struct xdr_stream xdr;
1814 struct compound_hdr hdr = {
1819 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1820 encode_compound_hdr(&xdr, &hdr);
1821 status = encode_putfh(&xdr, args->fh);
1824 status = encode_write(&xdr, args);
1827 status = encode_getfattr(&xdr, args->bitmask);
1835 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1837 struct xdr_stream xdr;
1838 struct compound_hdr hdr = {
1843 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1844 encode_compound_hdr(&xdr, &hdr);
1845 status = encode_putfh(&xdr, args->fh);
1848 status = encode_commit(&xdr, args);
1851 status = encode_getfattr(&xdr, args->bitmask);
1859 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1861 struct xdr_stream xdr;
1862 struct compound_hdr hdr = {
1867 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1868 encode_compound_hdr(&xdr, &hdr);
1869 status = encode_putfh(&xdr, args->fh);
1871 status = encode_fsinfo(&xdr, args->bitmask);
1876 * a PATHCONF request
1878 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1880 struct xdr_stream xdr;
1881 struct compound_hdr hdr = {
1886 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1887 encode_compound_hdr(&xdr, &hdr);
1888 status = encode_putfh(&xdr, args->fh);
1890 status = encode_getattr_one(&xdr,
1891 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1898 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1900 struct xdr_stream xdr;
1901 struct compound_hdr hdr = {
1906 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1907 encode_compound_hdr(&xdr, &hdr);
1908 status = encode_putfh(&xdr, args->fh);
1910 status = encode_getattr_two(&xdr,
1911 args->bitmask[0] & nfs4_statfs_bitmap[0],
1912 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1917 * GETATTR_BITMAP request
1919 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1921 struct xdr_stream xdr;
1922 struct compound_hdr hdr = {
1927 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1928 encode_compound_hdr(&xdr, &hdr);
1929 status = encode_putfh(&xdr, fhandle);
1931 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1932 FATTR4_WORD0_LINK_SUPPORT|
1933 FATTR4_WORD0_SYMLINK_SUPPORT|
1934 FATTR4_WORD0_ACLSUPPORT);
1941 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1943 struct xdr_stream xdr;
1944 struct compound_hdr hdr = {
1948 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1949 encode_compound_hdr(&xdr, &hdr);
1950 return encode_renew(&xdr, clp);
1954 * a SETCLIENTID request
1956 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1958 struct xdr_stream xdr;
1959 struct compound_hdr hdr = {
1963 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1964 encode_compound_hdr(&xdr, &hdr);
1965 return encode_setclientid(&xdr, sc);
1969 * a SETCLIENTID_CONFIRM request
1971 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1973 struct xdr_stream xdr;
1974 struct compound_hdr hdr = {
1977 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1980 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1981 encode_compound_hdr(&xdr, &hdr);
1982 status = encode_setclientid_confirm(&xdr, clp);
1984 status = encode_putrootfh(&xdr);
1986 status = encode_fsinfo(&xdr, lease_bitmap);
1991 * DELEGRETURN request
1993 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1995 struct xdr_stream xdr;
1996 struct compound_hdr hdr = {
2001 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2002 encode_compound_hdr(&xdr, &hdr);
2003 status = encode_putfh(&xdr, args->fhandle);
2006 status = encode_delegreturn(&xdr, args->stateid);
2009 status = encode_getfattr(&xdr, args->bitmask);
2015 * Encode FS_LOCATIONS request
2017 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, uint32_t *p, struct nfs4_fs_locations_arg *args)
2019 struct xdr_stream xdr;
2020 struct compound_hdr hdr = {
2023 struct rpc_auth *auth = req->rq_task->tk_auth;
2027 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2028 encode_compound_hdr(&xdr, &hdr);
2029 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2031 if ((status = encode_lookup(&xdr, args->name)) != 0)
2033 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
2036 * toplevel_status + taglen + rescount + OP_PUTFH + status
2037 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2039 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2040 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2047 * START OF "GENERIC" DECODE ROUTINES.
2048 * These may look a little ugly since they are imported from a "generic"
2049 * set of XDR encode/decode routines which are intended to be shared by
2050 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2052 * If the pain of reading these is too great, it should be a straightforward
2053 * task to translate them into Linux-specific versions which are more
2054 * consistent with the style used in NFSv2/v3...
2056 #define READ32(x) (x) = ntohl(*p++)
2057 #define READ64(x) do { \
2058 (x) = (u64)ntohl(*p++) << 32; \
2059 (x) |= ntohl(*p++); \
2061 #define READTIME(x) do { \
2063 (x.tv_sec) = ntohl(*p++); \
2064 (x.tv_nsec) = ntohl(*p++); \
2066 #define COPYMEM(x,nbytes) do { \
2067 memcpy((x), p, nbytes); \
2068 p += XDR_QUADLEN(nbytes); \
2071 #define READ_BUF(nbytes) do { \
2072 p = xdr_inline_decode(xdr, nbytes); \
2074 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
2075 __FUNCTION__, __LINE__); \
2080 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2087 *string = (char *)p;
2091 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2096 READ32(hdr->status);
2097 READ32(hdr->taglen);
2099 READ_BUF(hdr->taglen + 4);
2100 hdr->tag = (char *)p;
2101 p += XDR_QUADLEN(hdr->taglen);
2106 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2114 if (opnum != expected) {
2116 "nfs4_decode_op_hdr: Server returned operation"
2117 " %d but we issued a request for %d\n",
2122 if (nfserr != NFS_OK)
2123 return -nfs_stat_to_errno(nfserr);
2128 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
2131 unsigned int strlen;
2135 return decode_opaque_inline(xdr, &strlen, &str);
2138 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2145 bitmap[0] = bitmap[1] = 0;
2146 READ_BUF((bmlen << 2));
2155 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
2165 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2167 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2168 decode_attr_bitmap(xdr, bitmask);
2169 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2171 bitmask[0] = bitmask[1] = 0;
2172 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2176 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2181 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2183 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2186 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2187 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2190 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2192 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2196 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2201 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2203 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2206 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2208 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2209 (unsigned long long)*change);
2213 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2218 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2220 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2223 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2225 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2229 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2234 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2236 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2239 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2241 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2245 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2250 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2252 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2255 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2257 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2261 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2267 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2269 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2271 READ64(fsid->major);
2272 READ64(fsid->minor);
2273 bitmap[0] &= ~FATTR4_WORD0_FSID;
2275 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2276 (unsigned long long)fsid->major,
2277 (unsigned long long)fsid->minor);
2281 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2286 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2288 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2291 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2293 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2297 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2301 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2302 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2304 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2307 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2309 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2313 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2318 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2320 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2323 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2325 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2329 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2335 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2337 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2340 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2342 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2346 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2352 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2354 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2357 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2359 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2363 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2369 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2371 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2374 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2376 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2380 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2391 path->ncomponents = 0;
2392 while (path->ncomponents < n) {
2393 struct nfs4_string *component = &path->components[path->ncomponents];
2394 status = decode_opaque_inline(xdr, &component->len, &component->data);
2395 if (unlikely(status != 0))
2397 if (path->ncomponents != n)
2399 dprintk("%s", component->data);
2400 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2401 path->ncomponents++;
2403 dprintk("cannot parse %d components in path\n", n);
2411 dprintk(" status %d", status);
2416 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2422 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2425 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2427 dprintk("%s: fsroot ", __FUNCTION__);
2428 status = decode_pathname(xdr, &res->fs_path);
2429 if (unlikely(status != 0))
2435 res->nlocations = 0;
2436 while (res->nlocations < n) {
2438 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2446 dprintk("%s: servers ", __FUNCTION__);
2447 while (loc->nservers < m) {
2448 struct nfs4_string *server = &loc->servers[loc->nservers];
2449 status = decode_opaque_inline(xdr, &server->len, &server->data);
2450 if (unlikely(status != 0))
2452 dprintk("%s ", server->data);
2453 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2457 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2458 for (i = loc->nservers; i < m; i++) {
2461 status = decode_opaque_inline(xdr, &len, &data);
2462 if (unlikely(status != 0))
2467 status = decode_pathname(xdr, &loc->rootpath);
2468 if (unlikely(status != 0))
2470 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2474 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2481 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2487 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2489 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2492 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2494 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2498 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2504 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2506 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2509 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2511 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2515 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2521 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2523 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2526 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2528 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2532 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2538 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2540 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2544 if (maxread > 0x7FFFFFFF)
2545 maxread = 0x7FFFFFFF;
2546 *res = (uint32_t)maxread;
2547 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2549 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2553 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2559 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2561 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2565 if (maxwrite > 0x7FFFFFFF)
2566 maxwrite = 0x7FFFFFFF;
2567 *res = (uint32_t)maxwrite;
2568 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2570 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2574 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2579 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2581 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2585 bitmap[1] &= ~FATTR4_WORD1_MODE;
2587 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2591 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2596 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2598 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2601 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2603 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2607 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2612 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2614 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2618 if (len < XDR_MAX_NETOBJ) {
2619 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2620 dprintk("%s: nfs_map_name_to_uid failed!\n",
2623 printk(KERN_WARNING "%s: name too long (%u)!\n",
2625 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2627 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2631 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2636 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2638 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2642 if (len < XDR_MAX_NETOBJ) {
2643 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2644 dprintk("%s: nfs_map_group_to_gid failed!\n",
2647 printk(KERN_WARNING "%s: name too long (%u)!\n",
2649 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2651 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2655 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2657 uint32_t major = 0, minor = 0, *p;
2660 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2662 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2668 tmp = MKDEV(major, minor);
2669 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2671 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2673 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2677 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2683 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2685 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2688 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2690 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2694 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2700 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2702 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2705 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2707 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2711 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2717 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2719 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2722 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2724 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2728 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2733 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2735 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2738 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2740 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2741 (unsigned long long)*used);
2745 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2754 time->tv_sec = (time_t)sec;
2755 time->tv_nsec = (long)nsec;
2759 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2765 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2767 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2768 status = decode_attr_time(xdr, time);
2769 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2771 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2775 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2781 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2783 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2784 status = decode_attr_time(xdr, time);
2785 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2787 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2791 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2797 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2799 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2800 status = decode_attr_time(xdr, time);
2801 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2803 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2807 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2809 unsigned int attrwords = XDR_QUADLEN(attrlen);
2810 unsigned int nwords = xdr->p - savep;
2812 if (unlikely(attrwords != nwords)) {
2813 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2816 (attrwords < nwords) ? '<' : '>',
2823 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2828 READ32(cinfo->atomic);
2829 READ64(cinfo->before);
2830 READ64(cinfo->after);
2834 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2840 status = decode_op_hdr(xdr, OP_ACCESS);
2846 access->supported = supp;
2847 access->access = acc;
2851 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2856 status = decode_op_hdr(xdr, OP_CLOSE);
2859 READ_BUF(sizeof(res->stateid.data));
2860 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2864 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2869 status = decode_op_hdr(xdr, OP_COMMIT);
2873 COPYMEM(res->verf->verifier, 8);
2877 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2883 status = decode_op_hdr(xdr, OP_CREATE);
2886 if ((status = decode_change_info(xdr, cinfo)))
2890 READ_BUF(bmlen << 2);
2894 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2901 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2903 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2905 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2907 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2909 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2911 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2913 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2915 status = verify_attr_len(xdr, savep, attrlen);
2917 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2921 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2928 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2930 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2932 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2935 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2937 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2939 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2941 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2943 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2945 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2948 status = verify_attr_len(xdr, savep, attrlen);
2950 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2954 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2961 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2963 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2965 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2968 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2970 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2973 status = verify_attr_len(xdr, savep, attrlen);
2975 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2979 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2985 int status, fmode = 0;
2987 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2989 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2992 fattr->bitmap[0] = bitmap[0];
2993 fattr->bitmap[1] = bitmap[1];
2995 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2999 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3001 fattr->type = nfs_type2fmt[type].nfs2type;
3002 fmode = nfs_type2fmt[type].mode;
3004 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3006 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3008 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
3010 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3012 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3013 struct nfs4_fs_locations,
3016 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3018 fattr->mode |= fmode;
3019 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3021 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
3023 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
3025 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3027 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3029 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3031 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3033 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3035 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
3036 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
3038 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
3043 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3046 uint32_t attrlen, bitmap[2];
3049 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3051 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3053 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3056 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3058 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3060 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3062 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3064 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3065 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3067 fsinfo->wtpref = fsinfo->wtmax;
3069 status = verify_attr_len(xdr, savep, attrlen);
3071 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3075 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3081 status = decode_op_hdr(xdr, OP_GETFH);
3084 /* Zero handle first to allow comparisons */
3085 memset(fh, 0, sizeof(*fh));
3089 if (len > NFS4_FHSIZE)
3093 COPYMEM(fh->data, len);
3097 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3101 status = decode_op_hdr(xdr, OP_LINK);
3104 return decode_change_info(xdr, cinfo);
3108 * We create the owner, so we know a proper owner.id length is 4.
3110 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3112 uint64_t offset, length, clientid;
3114 uint32_t namelen, type;
3121 fl->fl_start = (loff_t)offset;
3122 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3123 if (length == ~(uint64_t)0)
3124 fl->fl_end = OFFSET_MAX;
3125 fl->fl_type = F_WRLCK;
3127 fl->fl_type = F_RDLCK;
3133 return -NFS4ERR_DENIED;
3136 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3141 status = decode_op_hdr(xdr, OP_LOCK);
3143 READ_BUF(sizeof(res->stateid.data));
3144 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3145 } else if (status == -NFS4ERR_DENIED)
3146 return decode_lock_denied(xdr, NULL);
3150 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3153 status = decode_op_hdr(xdr, OP_LOCKT);
3154 if (status == -NFS4ERR_DENIED)
3155 return decode_lock_denied(xdr, res->denied);
3159 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3164 status = decode_op_hdr(xdr, OP_LOCKU);
3166 READ_BUF(sizeof(res->stateid.data));
3167 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3172 static int decode_lookup(struct xdr_stream *xdr)
3174 return decode_op_hdr(xdr, OP_LOOKUP);
3177 /* This is too sick! */
3178 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3181 uint32_t limit_type, nblocks, blocksize;
3185 switch (limit_type) {
3192 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3197 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3200 uint32_t delegation_type;
3203 READ32(delegation_type);
3204 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3205 res->delegation_type = 0;
3209 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
3210 READ32(res->do_recall);
3211 switch (delegation_type) {
3212 case NFS4_OPEN_DELEGATE_READ:
3213 res->delegation_type = FMODE_READ;
3215 case NFS4_OPEN_DELEGATE_WRITE:
3216 res->delegation_type = FMODE_WRITE|FMODE_READ;
3217 if (decode_space_limit(xdr, &res->maxsize) < 0)
3220 return decode_ace(xdr, NULL, res->server->nfs4_state);
3223 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3229 status = decode_op_hdr(xdr, OP_OPEN);
3232 READ_BUF(sizeof(res->stateid.data));
3233 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3235 decode_change_info(xdr, &res->cinfo);
3238 READ32(res->rflags);
3243 READ_BUF(bmlen << 2);
3245 return decode_delegation(xdr, res);
3247 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
3251 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3256 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3259 READ_BUF(sizeof(res->stateid.data));
3260 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3264 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3269 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3272 READ_BUF(sizeof(res->stateid.data));
3273 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3277 static int decode_putfh(struct xdr_stream *xdr)
3279 return decode_op_hdr(xdr, OP_PUTFH);
3282 static int decode_putrootfh(struct xdr_stream *xdr)
3284 return decode_op_hdr(xdr, OP_PUTROOTFH);
3287 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3289 struct kvec *iov = req->rq_rcv_buf.head;
3291 uint32_t count, eof, recvd, hdrlen;
3294 status = decode_op_hdr(xdr, OP_READ);
3300 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3301 recvd = req->rq_rcv_buf.len - hdrlen;
3302 if (count > recvd) {
3303 printk(KERN_WARNING "NFS: server cheating in read reply: "
3304 "count %u > recvd %u\n", count, recvd);
3308 xdr_read_pages(xdr, count);
3314 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3316 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3317 struct page *page = *rcvbuf->pages;
3318 struct kvec *iov = rcvbuf->head;
3319 unsigned int nr, pglen = rcvbuf->page_len;
3320 uint32_t *end, *entry, *p, *kaddr;
3321 uint32_t len, attrlen;
3322 int hdrlen, recvd, status;
3324 status = decode_op_hdr(xdr, OP_READDIR);
3328 COPYMEM(readdir->verifier.data, 8);
3329 dprintk("%s: verifier = 0x%x%x\n",
3331 ((u32 *)readdir->verifier.data)[0],
3332 ((u32 *)readdir->verifier.data)[1]);
3335 hdrlen = (char *) p - (char *) iov->iov_base;
3336 recvd = rcvbuf->len - hdrlen;
3339 xdr_read_pages(xdr, pglen);
3341 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3342 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3343 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3345 for (nr = 0; *p++; nr++) {
3348 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3349 p += 2; /* cookie */
3350 len = ntohl(*p++); /* filename length */
3351 if (len > NFS4_MAXNAMLEN) {
3352 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3355 dprintk("filename = %*s\n", len, (char *)p);
3356 p += XDR_QUADLEN(len);
3359 len = ntohl(*p++); /* bitmap length */
3363 attrlen = XDR_QUADLEN(ntohl(*p++));
3364 p += attrlen; /* attributes */
3369 if (!nr && (entry[0] != 0 || entry[1] == 0))
3372 kunmap_atomic(kaddr, KM_USER0);
3375 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3376 entry[0] = entry[1] = 0;
3377 /* truncate listing ? */
3379 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3384 kunmap_atomic(kaddr, KM_USER0);
3385 return -errno_NFSERR_IO;
3388 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3390 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3391 struct kvec *iov = rcvbuf->head;
3392 int hdrlen, len, recvd;
3397 status = decode_op_hdr(xdr, OP_READLINK);
3401 /* Convert length of symlink */
3404 if (len >= rcvbuf->page_len || len <= 0) {
3405 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3406 return -ENAMETOOLONG;
3408 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3409 recvd = req->rq_rcv_buf.len - hdrlen;
3411 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3412 "count %u > recvd %u\n", len, recvd);
3415 xdr_read_pages(xdr, len);
3417 * The XDR encode routine has set things up so that
3418 * the link text will be copied directly into the
3419 * buffer. We just have to do overflow-checking,
3420 * and and null-terminate the text (the VFS expects
3421 * null-termination).
3423 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3424 kaddr[len+rcvbuf->page_base] = '\0';
3425 kunmap_atomic(kaddr, KM_USER0);
3429 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3433 status = decode_op_hdr(xdr, OP_REMOVE);
3436 status = decode_change_info(xdr, cinfo);
3441 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3442 struct nfs4_change_info *new_cinfo)
3446 status = decode_op_hdr(xdr, OP_RENAME);
3449 if ((status = decode_change_info(xdr, old_cinfo)))
3451 status = decode_change_info(xdr, new_cinfo);
3456 static int decode_renew(struct xdr_stream *xdr)
3458 return decode_op_hdr(xdr, OP_RENEW);
3462 decode_restorefh(struct xdr_stream *xdr)
3464 return decode_op_hdr(xdr, OP_RESTOREFH);
3467 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3473 struct kvec *iov = req->rq_rcv_buf.head;
3477 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3479 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3481 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3484 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3486 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3489 /* We ignore &savep and don't do consistency checks on
3490 * the attr length. Let userspace figure it out.... */
3491 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3492 recvd = req->rq_rcv_buf.len - hdrlen;
3493 if (attrlen > recvd) {
3494 printk(KERN_WARNING "NFS: server cheating in getattr"
3495 " acl reply: attrlen %u > recvd %u\n",
3499 xdr_read_pages(xdr, attrlen);
3502 status = -EOPNOTSUPP;
3509 decode_savefh(struct xdr_stream *xdr)
3511 return decode_op_hdr(xdr, OP_SAVEFH);
3514 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3521 status = decode_op_hdr(xdr, OP_SETATTR);
3526 READ_BUF(bmlen << 2);
3530 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3538 if (opnum != OP_SETCLIENTID) {
3540 "nfs4_decode_setclientid: Server returned operation"
3545 if (nfserr == NFS_OK) {
3546 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3547 READ64(clp->cl_clientid);
3548 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3549 } else if (nfserr == NFSERR_CLID_INUSE) {
3552 /* skip netid string */
3557 /* skip uaddr string */
3561 return -NFSERR_CLID_INUSE;
3563 return -nfs_stat_to_errno(nfserr);
3568 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3570 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3573 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3578 status = decode_op_hdr(xdr, OP_WRITE);
3584 READ32(res->verf->committed);
3585 COPYMEM(res->verf->verifier, 8);
3589 static int decode_delegreturn(struct xdr_stream *xdr)
3591 return decode_op_hdr(xdr, OP_DELEGRETURN);
3595 * Decode OPEN_DOWNGRADE response
3597 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3599 struct xdr_stream xdr;
3600 struct compound_hdr hdr;
3603 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3604 status = decode_compound_hdr(&xdr, &hdr);
3607 status = decode_putfh(&xdr);
3610 status = decode_open_downgrade(&xdr, res);
3613 decode_getfattr(&xdr, res->fattr, res->server);
3619 * END OF "GENERIC" DECODE ROUTINES.
3623 * Decode ACCESS response
3625 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3627 struct xdr_stream xdr;
3628 struct compound_hdr hdr;
3631 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3632 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3634 if ((status = decode_putfh(&xdr)) == 0)
3635 status = decode_access(&xdr, res);
3641 * Decode LOOKUP response
3643 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3645 struct xdr_stream xdr;
3646 struct compound_hdr hdr;
3649 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3650 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3652 if ((status = decode_putfh(&xdr)) != 0)
3654 if ((status = decode_lookup(&xdr)) != 0)
3656 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3658 status = decode_getfattr(&xdr, res->fattr, res->server);
3664 * Decode LOOKUP_ROOT response
3666 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3668 struct xdr_stream xdr;
3669 struct compound_hdr hdr;
3672 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3673 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3675 if ((status = decode_putrootfh(&xdr)) != 0)
3677 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3678 status = decode_getfattr(&xdr, res->fattr, res->server);
3684 * Decode REMOVE response
3686 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_remove_res *res)
3688 struct xdr_stream xdr;
3689 struct compound_hdr hdr;
3692 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3693 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3695 if ((status = decode_putfh(&xdr)) != 0)
3697 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3699 decode_getfattr(&xdr, res->dir_attr, res->server);
3705 * Decode RENAME response
3707 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3709 struct xdr_stream xdr;
3710 struct compound_hdr hdr;
3713 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3714 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3716 if ((status = decode_putfh(&xdr)) != 0)
3718 if ((status = decode_savefh(&xdr)) != 0)
3720 if ((status = decode_putfh(&xdr)) != 0)
3722 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3724 /* Current FH is target directory */
3725 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3727 if ((status = decode_restorefh(&xdr)) != 0)
3729 decode_getfattr(&xdr, res->old_fattr, res->server);
3735 * Decode LINK response
3737 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_link_res *res)
3739 struct xdr_stream xdr;
3740 struct compound_hdr hdr;
3743 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3744 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3746 if ((status = decode_putfh(&xdr)) != 0)
3748 if ((status = decode_savefh(&xdr)) != 0)
3750 if ((status = decode_putfh(&xdr)) != 0)
3752 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3755 * Note order: OP_LINK leaves the directory as the current
3758 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3760 if ((status = decode_restorefh(&xdr)) != 0)
3762 decode_getfattr(&xdr, res->fattr, res->server);
3768 * Decode CREATE response
3770 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3772 struct xdr_stream xdr;
3773 struct compound_hdr hdr;
3776 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3777 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3779 if ((status = decode_putfh(&xdr)) != 0)
3781 if ((status = decode_savefh(&xdr)) != 0)
3783 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3785 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3787 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3789 if ((status = decode_restorefh(&xdr)) != 0)
3791 decode_getfattr(&xdr, res->dir_fattr, res->server);
3797 * Decode SYMLINK response
3799 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3801 return nfs4_xdr_dec_create(rqstp, p, res);
3805 * Decode GETATTR response
3807 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3809 struct xdr_stream xdr;
3810 struct compound_hdr hdr;
3813 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3814 status = decode_compound_hdr(&xdr, &hdr);
3817 status = decode_putfh(&xdr);
3820 status = decode_getfattr(&xdr, res->fattr, res->server);
3827 * Encode an SETACL request
3830 nfs4_xdr_enc_setacl(struct rpc_rqst *req, uint32_t *p, struct nfs_setaclargs *args)
3832 struct xdr_stream xdr;
3833 struct compound_hdr hdr = {
3838 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3839 encode_compound_hdr(&xdr, &hdr);
3840 status = encode_putfh(&xdr, args->fh);
3843 status = encode_setacl(&xdr, args);
3848 * Decode SETACL response
3851 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3853 struct xdr_stream xdr;
3854 struct compound_hdr hdr;
3857 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3858 status = decode_compound_hdr(&xdr, &hdr);
3861 status = decode_putfh(&xdr);
3864 status = decode_setattr(&xdr, res);
3870 * Decode GETACL response
3873 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len)
3875 struct xdr_stream xdr;
3876 struct compound_hdr hdr;
3879 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3880 status = decode_compound_hdr(&xdr, &hdr);
3883 status = decode_putfh(&xdr);
3886 status = decode_getacl(&xdr, rqstp, acl_len);
3893 * Decode CLOSE response
3895 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3897 struct xdr_stream xdr;
3898 struct compound_hdr hdr;
3901 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3902 status = decode_compound_hdr(&xdr, &hdr);
3905 status = decode_putfh(&xdr);
3908 status = decode_close(&xdr, res);
3912 * Note: Server may do delete on close for this file
3913 * in which case the getattr call will fail with
3914 * an ESTALE error. Shouldn't be a problem,
3915 * though, since fattr->valid will remain unset.
3917 decode_getfattr(&xdr, res->fattr, res->server);
3923 * Decode OPEN response
3925 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3927 struct xdr_stream xdr;
3928 struct compound_hdr hdr;
3931 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3932 status = decode_compound_hdr(&xdr, &hdr);
3935 status = decode_putfh(&xdr);
3938 status = decode_savefh(&xdr);
3941 status = decode_open(&xdr, res);
3944 status = decode_getfh(&xdr, &res->fh);
3947 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
3949 if ((status = decode_restorefh(&xdr)) != 0)
3951 decode_getfattr(&xdr, res->dir_attr, res->server);
3957 * Decode OPEN_CONFIRM response
3959 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3961 struct xdr_stream xdr;
3962 struct compound_hdr hdr;
3965 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3966 status = decode_compound_hdr(&xdr, &hdr);
3969 status = decode_putfh(&xdr);
3972 status = decode_open_confirm(&xdr, res);
3978 * Decode OPEN response
3980 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3982 struct xdr_stream xdr;
3983 struct compound_hdr hdr;
3986 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3987 status = decode_compound_hdr(&xdr, &hdr);
3990 status = decode_putfh(&xdr);
3993 status = decode_open(&xdr, res);
3996 decode_getfattr(&xdr, res->f_attr, res->server);
4002 * Decode SETATTR response
4004 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
4006 struct xdr_stream xdr;
4007 struct compound_hdr hdr;
4010 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4011 status = decode_compound_hdr(&xdr, &hdr);
4014 status = decode_putfh(&xdr);
4017 status = decode_setattr(&xdr, res);
4020 status = decode_getfattr(&xdr, res->fattr, res->server);
4021 if (status == NFS4ERR_DELAY)
4028 * Decode LOCK response
4030 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lock_res *res)
4032 struct xdr_stream xdr;
4033 struct compound_hdr hdr;
4036 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4037 status = decode_compound_hdr(&xdr, &hdr);
4040 status = decode_putfh(&xdr);
4043 status = decode_lock(&xdr, res);
4049 * Decode LOCKT response
4051 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockt_res *res)
4053 struct xdr_stream xdr;
4054 struct compound_hdr hdr;
4057 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4058 status = decode_compound_hdr(&xdr, &hdr);
4061 status = decode_putfh(&xdr);
4064 status = decode_lockt(&xdr, res);
4070 * Decode LOCKU response
4072 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_locku_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_locku(&xdr, res);
4091 * Decode READLINK response
4093 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *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_readlink(&xdr, rqstp);
4112 * Decode READDIR response
4114 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_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_readdir(&xdr, rqstp, res);
4133 * Decode Read response
4135 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *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_read(&xdr, rqstp, res);
4150 status = res->count;
4156 * Decode WRITE response
4158 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
4160 struct xdr_stream xdr;
4161 struct compound_hdr hdr;
4164 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4165 status = decode_compound_hdr(&xdr, &hdr);
4168 status = decode_putfh(&xdr);
4171 status = decode_write(&xdr, res);
4174 decode_getfattr(&xdr, res->fattr, res->server);
4176 status = res->count;
4182 * Decode COMMIT response
4184 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
4186 struct xdr_stream xdr;
4187 struct compound_hdr hdr;
4190 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4191 status = decode_compound_hdr(&xdr, &hdr);
4194 status = decode_putfh(&xdr);
4197 status = decode_commit(&xdr, res);
4200 decode_getfattr(&xdr, res->fattr, res->server);
4208 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
4210 struct xdr_stream xdr;
4211 struct compound_hdr hdr;
4214 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4215 status = decode_compound_hdr(&xdr, &hdr);
4217 status = decode_putfh(&xdr);
4219 status = decode_fsinfo(&xdr, fsinfo);
4221 status = -nfs_stat_to_errno(hdr.status);
4228 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
4230 struct xdr_stream xdr;
4231 struct compound_hdr hdr;
4234 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4235 status = decode_compound_hdr(&xdr, &hdr);
4237 status = decode_putfh(&xdr);
4239 status = decode_pathconf(&xdr, pathconf);
4246 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
4248 struct xdr_stream xdr;
4249 struct compound_hdr hdr;
4252 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4253 status = decode_compound_hdr(&xdr, &hdr);
4255 status = decode_putfh(&xdr);
4257 status = decode_statfs(&xdr, fsstat);
4262 * GETATTR_BITMAP request
4264 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
4266 struct xdr_stream xdr;
4267 struct compound_hdr hdr;
4270 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4271 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4273 if ((status = decode_putfh(&xdr)) != 0)
4275 status = decode_server_caps(&xdr, res);
4281 * Decode RENEW response
4283 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
4285 struct xdr_stream xdr;
4286 struct compound_hdr hdr;
4289 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4290 status = decode_compound_hdr(&xdr, &hdr);
4292 status = decode_renew(&xdr);
4297 * a SETCLIENTID request
4299 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
4300 struct nfs4_client *clp)
4302 struct xdr_stream xdr;
4303 struct compound_hdr hdr;
4306 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4307 status = decode_compound_hdr(&xdr, &hdr);
4309 status = decode_setclientid(&xdr, clp);
4311 status = -nfs_stat_to_errno(hdr.status);
4316 * a SETCLIENTID_CONFIRM request
4318 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
4320 struct xdr_stream xdr;
4321 struct compound_hdr hdr;
4324 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4325 status = decode_compound_hdr(&xdr, &hdr);
4327 status = decode_setclientid_confirm(&xdr);
4329 status = decode_putrootfh(&xdr);
4331 status = decode_fsinfo(&xdr, fsinfo);
4333 status = -nfs_stat_to_errno(hdr.status);
4338 * DELEGRETURN request
4340 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_delegreturnres *res)
4342 struct xdr_stream xdr;
4343 struct compound_hdr hdr;
4346 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4347 status = decode_compound_hdr(&xdr, &hdr);
4350 status = decode_putfh(&xdr);
4353 status = decode_delegreturn(&xdr);
4354 decode_getfattr(&xdr, res->fattr, res->server);
4360 * FS_LOCATIONS request
4362 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, uint32_t *p, struct nfs4_fs_locations *res)
4364 struct xdr_stream xdr;
4365 struct compound_hdr hdr;
4368 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4369 status = decode_compound_hdr(&xdr, &hdr);
4372 if ((status = decode_putfh(&xdr)) != 0)
4374 if ((status = decode_lookup(&xdr)) != 0)
4376 xdr_enter_page(&xdr, PAGE_SIZE);
4377 status = decode_getfattr(&xdr, &res->fattr, res->server);
4382 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
4384 uint32_t bitmap[2] = {0};
4389 return ERR_PTR(-EAGAIN);
4391 return ERR_PTR(-EBADCOOKIE);
4394 entry->prev_cookie = entry->cookie;
4395 p = xdr_decode_hyper(p, &entry->cookie);
4396 entry->len = ntohl(*p++);
4397 entry->name = (const char *) p;
4398 p += XDR_QUADLEN(entry->len);
4401 * In case the server doesn't return an inode number,
4402 * we fake one here. (We don't use inode number 0,
4403 * since glibc seems to choke on it...)
4407 len = ntohl(*p++); /* bitmap length */
4409 bitmap[0] = ntohl(*p++);
4411 bitmap[1] = ntohl(*p++);
4415 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4417 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4418 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4419 /* Ignore the return value of rdattr_error for now */
4423 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4424 xdr_decode_hyper(p, &entry->ino);
4425 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4426 xdr_decode_hyper(p, &entry->ino);
4430 entry->eof = !p[0] && p[1];
4435 * We need to translate between nfs status return values and
4436 * the local errno values which may not be the same.
4443 { NFS4ERR_PERM, EPERM },
4444 { NFS4ERR_NOENT, ENOENT },
4445 { NFS4ERR_IO, errno_NFSERR_IO },
4446 { NFS4ERR_NXIO, ENXIO },
4447 { NFS4ERR_ACCESS, EACCES },
4448 { NFS4ERR_EXIST, EEXIST },
4449 { NFS4ERR_XDEV, EXDEV },
4450 { NFS4ERR_NOTDIR, ENOTDIR },
4451 { NFS4ERR_ISDIR, EISDIR },
4452 { NFS4ERR_INVAL, EINVAL },
4453 { NFS4ERR_FBIG, EFBIG },
4454 { NFS4ERR_NOSPC, ENOSPC },
4455 { NFS4ERR_ROFS, EROFS },
4456 { NFS4ERR_MLINK, EMLINK },
4457 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4458 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4459 { NFS4ERR_DQUOT, EDQUOT },
4460 { NFS4ERR_STALE, ESTALE },
4461 { NFS4ERR_BADHANDLE, EBADHANDLE },
4462 { NFS4ERR_BADOWNER, EINVAL },
4463 { NFS4ERR_BADNAME, EINVAL },
4464 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4465 { NFS4ERR_NOTSUPP, ENOTSUPP },
4466 { NFS4ERR_TOOSMALL, ETOOSMALL },
4467 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4468 { NFS4ERR_BADTYPE, EBADTYPE },
4469 { NFS4ERR_LOCKED, EAGAIN },
4470 { NFS4ERR_RESOURCE, EREMOTEIO },
4471 { NFS4ERR_SYMLINK, ELOOP },
4472 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4473 { NFS4ERR_DEADLOCK, EDEADLK },
4474 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4475 * to be handled by a
4482 * Convert an NFS error code to a local one.
4483 * This one is used jointly by NFSv2 and NFSv3.
4486 nfs_stat_to_errno(int stat)
4489 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4490 if (nfs_errtbl[i].stat == stat)
4491 return nfs_errtbl[i].errno;
4493 if (stat <= 10000 || stat > 10100) {
4494 /* The server is looney tunes. */
4495 return ESERVERFAULT;
4497 /* If we cannot translate the error, the recovery routines should
4499 * Note: remaining NFSv4 error codes have values > 10000, so should
4500 * not conflict with native Linux error codes.
4506 # define MAX(a, b) (((a) > (b))? (a) : (b))
4509 #define PROC(proc, argtype, restype) \
4510 [NFSPROC4_CLNT_##proc] = { \
4511 .p_proc = NFSPROC4_COMPOUND, \
4512 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4513 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4514 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
4515 .p_statidx = NFSPROC4_CLNT_##proc, \
4519 struct rpc_procinfo nfs4_procedures[] = {
4520 PROC(READ, enc_read, dec_read),
4521 PROC(WRITE, enc_write, dec_write),
4522 PROC(COMMIT, enc_commit, dec_commit),
4523 PROC(OPEN, enc_open, dec_open),
4524 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4525 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4526 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4527 PROC(CLOSE, enc_close, dec_close),
4528 PROC(SETATTR, enc_setattr, dec_setattr),
4529 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4530 PROC(RENEW, enc_renew, dec_renew),
4531 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4532 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4533 PROC(LOCK, enc_lock, dec_lock),
4534 PROC(LOCKT, enc_lockt, dec_lockt),
4535 PROC(LOCKU, enc_locku, dec_locku),
4536 PROC(ACCESS, enc_access, dec_access),
4537 PROC(GETATTR, enc_getattr, dec_getattr),
4538 PROC(LOOKUP, enc_lookup, dec_lookup),
4539 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4540 PROC(REMOVE, enc_remove, dec_remove),
4541 PROC(RENAME, enc_rename, dec_rename),
4542 PROC(LINK, enc_link, dec_link),
4543 PROC(SYMLINK, enc_symlink, dec_symlink),
4544 PROC(CREATE, enc_create, dec_create),
4545 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4546 PROC(STATFS, enc_statfs, dec_statfs),
4547 PROC(READLINK, enc_readlink, dec_readlink),
4548 PROC(READDIR, enc_readdir, dec_readdir),
4549 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4550 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4551 PROC(GETACL, enc_getacl, dec_getacl),
4552 PROC(SETACL, enc_setacl, dec_setacl),
4553 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4556 struct rpc_version nfs_version4 = {
4558 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4559 .procs = nfs4_procedures