4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 1)
74 #define lock_owner_id_maxsz (1 + 1)
75 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
76 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define op_encode_hdr_maxsz (1)
78 #define op_decode_hdr_maxsz (2)
79 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
81 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
82 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
83 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
84 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
85 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
86 ((3+NFS4_FHSIZE) >> 2))
87 #define nfs4_fattr_bitmap_maxsz 3
88 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
89 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
90 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
91 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
92 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
93 /* This is based on getfattr, which uses the most attributes: */
94 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
95 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
96 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
97 nfs4_fattr_value_maxsz)
98 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
99 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
100 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
101 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
102 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
103 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
104 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
105 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
106 #define decode_renew_maxsz (op_decode_hdr_maxsz)
107 #define encode_setclientid_maxsz \
108 (op_encode_hdr_maxsz + \
109 4 /*server->ip_addr*/ + \
112 6 + (NFS4_VERIFIER_SIZE >> 2))
113 #define decode_setclientid_maxsz \
114 (op_decode_hdr_maxsz + \
116 1024) /* large value for CLID_INUSE */
117 #define encode_setclientid_confirm_maxsz \
118 (op_encode_hdr_maxsz + \
119 3 + (NFS4_VERIFIER_SIZE >> 2))
120 #define decode_setclientid_confirm_maxsz \
121 (op_decode_hdr_maxsz)
122 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
123 1 + ((3 + NFS4_FHSIZE) >> 2))
124 #define encode_share_access_maxsz \
126 #define encode_createmode_maxsz (1 + nfs4_fattr_maxsz)
127 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
128 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
129 #define encode_open_maxsz (op_encode_hdr_maxsz + \
130 2 + encode_share_access_maxsz + 2 + \
131 open_owner_id_maxsz + \
132 encode_opentype_maxsz + \
133 encode_claim_null_maxsz)
134 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
135 #define decode_delegation_maxsz (1 + XDR_QUADLEN(NFS4_STATEID_SIZE) + 1 + \
137 #define decode_change_info_maxsz (5)
138 #define decode_open_maxsz (op_decode_hdr_maxsz + \
139 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
140 decode_change_info_maxsz + 1 + \
141 nfs4_fattr_bitmap_maxsz + \
142 decode_delegation_maxsz)
143 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
145 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
147 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
148 #define encode_link_maxsz (op_encode_hdr_maxsz + \
150 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
151 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
152 1 + nfs4_name_maxsz + \
155 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
156 #define encode_create_maxsz (op_encode_hdr_maxsz + \
157 2 + nfs4_name_maxsz + \
159 #define decode_create_maxsz (op_decode_hdr_maxsz + \
160 decode_change_info_maxsz + \
161 nfs4_fattr_bitmap_maxsz)
162 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
163 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
164 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
165 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
166 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
167 encode_putfh_maxsz + \
168 op_encode_hdr_maxsz + 7)
169 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
170 decode_putfh_maxsz + \
171 op_decode_hdr_maxsz + 2)
172 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
173 encode_putfh_maxsz + \
175 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
176 decode_putfh_maxsz + \
178 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
179 encode_putfh_maxsz + \
180 op_encode_hdr_maxsz + 9)
181 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
182 decode_putfh_maxsz + \
183 op_decode_hdr_maxsz + 2)
184 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
185 encode_putfh_maxsz + \
186 op_encode_hdr_maxsz + 8 + \
187 encode_getattr_maxsz)
188 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
189 decode_putfh_maxsz + \
190 op_decode_hdr_maxsz + 4 + \
191 decode_getattr_maxsz)
192 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
193 encode_putfh_maxsz + \
194 op_encode_hdr_maxsz + 3 + \
195 encode_getattr_maxsz)
196 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
197 decode_putfh_maxsz + \
198 op_decode_hdr_maxsz + 2 + \
199 decode_getattr_maxsz)
200 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
201 encode_putfh_maxsz + \
202 encode_savefh_maxsz + \
203 encode_open_maxsz + \
204 encode_getfh_maxsz + \
205 encode_getattr_maxsz + \
206 encode_restorefh_maxsz + \
207 encode_getattr_maxsz)
208 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
209 decode_putfh_maxsz + \
210 decode_savefh_maxsz + \
211 decode_open_maxsz + \
212 decode_getfh_maxsz + \
213 decode_getattr_maxsz + \
214 decode_restorefh_maxsz + \
215 decode_getattr_maxsz)
216 #define NFS4_enc_open_confirm_sz \
217 (compound_encode_hdr_maxsz + \
218 encode_putfh_maxsz + \
219 op_encode_hdr_maxsz + 5)
220 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
221 decode_putfh_maxsz + \
222 op_decode_hdr_maxsz + 4)
223 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
224 encode_putfh_maxsz + \
225 encode_open_maxsz + \
226 encode_getattr_maxsz)
227 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
228 decode_putfh_maxsz + \
229 decode_open_maxsz + \
230 decode_getattr_maxsz)
231 #define NFS4_enc_open_downgrade_sz \
232 (compound_encode_hdr_maxsz + \
233 encode_putfh_maxsz + \
234 op_encode_hdr_maxsz + 7 + \
235 encode_getattr_maxsz)
236 #define NFS4_dec_open_downgrade_sz \
237 (compound_decode_hdr_maxsz + \
238 decode_putfh_maxsz + \
239 op_decode_hdr_maxsz + 4 + \
240 decode_getattr_maxsz)
241 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
242 encode_putfh_maxsz + \
243 op_encode_hdr_maxsz + 5 + \
244 encode_getattr_maxsz)
245 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
246 decode_putfh_maxsz + \
247 op_decode_hdr_maxsz + 4 + \
248 decode_getattr_maxsz)
249 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
250 encode_putfh_maxsz + \
251 op_encode_hdr_maxsz + 4 + \
253 encode_getattr_maxsz)
254 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
255 decode_putfh_maxsz + \
256 op_decode_hdr_maxsz + 3 + \
258 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
259 encode_putfh_maxsz + \
261 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
262 decode_putfh_maxsz + \
264 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
266 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
268 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
269 encode_setclientid_maxsz)
270 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
271 decode_setclientid_maxsz)
272 #define NFS4_enc_setclientid_confirm_sz \
273 (compound_encode_hdr_maxsz + \
274 encode_setclientid_confirm_maxsz + \
275 encode_putrootfh_maxsz + \
277 #define NFS4_dec_setclientid_confirm_sz \
278 (compound_decode_hdr_maxsz + \
279 decode_setclientid_confirm_maxsz + \
280 decode_putrootfh_maxsz + \
282 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
283 encode_putfh_maxsz + \
284 encode_getattr_maxsz + \
285 op_encode_hdr_maxsz + \
289 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
290 decode_putfh_maxsz + \
291 decode_getattr_maxsz + \
292 op_decode_hdr_maxsz + \
295 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
296 encode_putfh_maxsz + \
297 encode_getattr_maxsz + \
298 op_encode_hdr_maxsz + \
301 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
302 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
303 encode_putfh_maxsz + \
304 encode_getattr_maxsz + \
305 op_encode_hdr_maxsz + \
307 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
308 decode_putfh_maxsz + \
309 decode_getattr_maxsz + \
310 op_decode_hdr_maxsz + 4)
311 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
312 encode_putfh_maxsz + \
313 op_encode_hdr_maxsz + 1)
314 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
315 decode_putfh_maxsz + \
316 op_decode_hdr_maxsz + 2)
317 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
318 encode_putfh_maxsz + \
319 encode_getattr_maxsz)
320 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
321 decode_putfh_maxsz + \
322 decode_getattr_maxsz)
323 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
324 encode_putfh_maxsz + \
325 encode_lookup_maxsz + \
326 encode_getattr_maxsz + \
328 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
329 decode_putfh_maxsz + \
330 op_decode_hdr_maxsz + \
331 decode_getattr_maxsz + \
333 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
334 encode_putrootfh_maxsz + \
335 encode_getattr_maxsz + \
337 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
338 decode_putrootfh_maxsz + \
339 decode_getattr_maxsz + \
341 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
342 encode_putfh_maxsz + \
343 encode_remove_maxsz + \
344 encode_getattr_maxsz)
345 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
346 decode_putfh_maxsz + \
347 op_decode_hdr_maxsz + 5 + \
348 decode_getattr_maxsz)
349 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
350 encode_putfh_maxsz + \
351 encode_savefh_maxsz + \
352 encode_putfh_maxsz + \
353 encode_rename_maxsz + \
354 encode_getattr_maxsz + \
355 encode_restorefh_maxsz + \
356 encode_getattr_maxsz)
357 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
358 decode_putfh_maxsz + \
359 decode_savefh_maxsz + \
360 decode_putfh_maxsz + \
361 decode_rename_maxsz + \
362 decode_getattr_maxsz + \
363 decode_restorefh_maxsz + \
364 decode_getattr_maxsz)
365 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
366 encode_putfh_maxsz + \
367 encode_savefh_maxsz + \
368 encode_putfh_maxsz + \
369 encode_link_maxsz + \
370 decode_getattr_maxsz + \
371 encode_restorefh_maxsz + \
372 decode_getattr_maxsz)
373 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
374 decode_putfh_maxsz + \
375 decode_savefh_maxsz + \
376 decode_putfh_maxsz + \
377 decode_link_maxsz + \
378 decode_getattr_maxsz + \
379 decode_restorefh_maxsz + \
380 decode_getattr_maxsz)
381 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
382 encode_putfh_maxsz + \
383 encode_symlink_maxsz + \
384 encode_getattr_maxsz + \
386 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
387 decode_putfh_maxsz + \
388 decode_symlink_maxsz + \
389 decode_getattr_maxsz + \
391 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
392 encode_putfh_maxsz + \
393 encode_savefh_maxsz + \
394 encode_create_maxsz + \
395 encode_getfh_maxsz + \
396 encode_getattr_maxsz + \
397 encode_restorefh_maxsz + \
398 encode_getattr_maxsz)
399 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
400 decode_putfh_maxsz + \
401 decode_savefh_maxsz + \
402 decode_create_maxsz + \
403 decode_getfh_maxsz + \
404 decode_getattr_maxsz + \
405 decode_restorefh_maxsz + \
406 decode_getattr_maxsz)
407 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
408 encode_putfh_maxsz + \
409 encode_getattr_maxsz)
410 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
411 decode_putfh_maxsz + \
412 decode_getattr_maxsz)
413 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
414 encode_putfh_maxsz + \
415 encode_getattr_maxsz)
416 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
417 decode_putfh_maxsz + \
418 op_decode_hdr_maxsz + 12)
419 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
420 encode_putfh_maxsz + \
421 encode_getattr_maxsz)
422 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
423 decode_putfh_maxsz + \
424 decode_getattr_maxsz)
425 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
426 encode_putfh_maxsz + \
427 encode_delegreturn_maxsz + \
428 encode_getattr_maxsz)
429 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
430 decode_delegreturn_maxsz + \
431 decode_getattr_maxsz)
432 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
433 encode_putfh_maxsz + \
434 encode_getattr_maxsz)
435 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
436 decode_putfh_maxsz + \
437 op_decode_hdr_maxsz + \
438 nfs4_fattr_bitmap_maxsz + 1)
439 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
440 encode_putfh_maxsz + \
441 op_encode_hdr_maxsz + 4 + \
442 nfs4_fattr_bitmap_maxsz + 1)
443 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
444 decode_putfh_maxsz + \
445 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
446 #define NFS4_enc_fs_locations_sz \
447 (compound_encode_hdr_maxsz + \
448 encode_putfh_maxsz + \
449 encode_getattr_maxsz)
450 #define NFS4_dec_fs_locations_sz \
451 (compound_decode_hdr_maxsz + \
452 decode_putfh_maxsz + \
453 op_decode_hdr_maxsz + \
454 nfs4_fattr_bitmap_maxsz)
458 unsigned int nfs2type;
466 { S_IFSOCK, NFSOCK },
472 struct compound_hdr {
480 * START OF "GENERIC" ENCODE ROUTINES.
481 * These may look a little ugly since they are imported from a "generic"
482 * set of XDR encode/decode routines which are intended to be shared by
483 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
485 * If the pain of reading these is too great, it should be a straightforward
486 * task to translate them into Linux-specific versions which are more
487 * consistent with the style used in NFSv2/v3...
489 #define WRITE32(n) *p++ = htonl(n)
490 #define WRITE64(n) do { \
491 *p++ = htonl((uint32_t)((n) >> 32)); \
492 *p++ = htonl((uint32_t)(n)); \
494 #define WRITEMEM(ptr,nbytes) do { \
495 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
498 #define RESERVE_SPACE(nbytes) do { \
499 p = xdr_reserve_space(xdr, nbytes); \
500 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
504 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
508 p = xdr_reserve_space(xdr, 4 + len);
510 xdr_encode_opaque(p, str, len);
513 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
517 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
518 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
519 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
520 WRITE32(hdr->taglen);
521 WRITEMEM(hdr->tag, hdr->taglen);
522 WRITE32(NFS4_MINOR_VERSION);
527 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
531 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
533 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
536 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
538 char owner_name[IDMAP_NAMESZ];
539 char owner_group[IDMAP_NAMESZ];
540 int owner_namelen = 0;
541 int owner_grouplen = 0;
550 * We reserve enough space to write the entire attribute buffer at once.
551 * In the worst-case, this would be
552 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
553 * = 36 bytes, plus any contribution from variable-length fields
554 * such as owner/group.
559 if (iap->ia_valid & ATTR_SIZE)
561 if (iap->ia_valid & ATTR_MODE)
563 if (iap->ia_valid & ATTR_UID) {
564 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
565 if (owner_namelen < 0) {
566 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
569 strcpy(owner_name, "nobody");
570 owner_namelen = sizeof("nobody") - 1;
573 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
575 if (iap->ia_valid & ATTR_GID) {
576 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
577 if (owner_grouplen < 0) {
578 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
580 strcpy(owner_group, "nobody");
581 owner_grouplen = sizeof("nobody") - 1;
584 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
586 if (iap->ia_valid & ATTR_ATIME_SET)
588 else if (iap->ia_valid & ATTR_ATIME)
590 if (iap->ia_valid & ATTR_MTIME_SET)
592 else if (iap->ia_valid & ATTR_MTIME)
597 * We write the bitmap length now, but leave the bitmap and the attribute
598 * buffer length to be backfilled at the end of this routine.
604 if (iap->ia_valid & ATTR_SIZE) {
605 bmval0 |= FATTR4_WORD0_SIZE;
606 WRITE64(iap->ia_size);
608 if (iap->ia_valid & ATTR_MODE) {
609 bmval1 |= FATTR4_WORD1_MODE;
610 WRITE32(iap->ia_mode & S_IALLUGO);
612 if (iap->ia_valid & ATTR_UID) {
613 bmval1 |= FATTR4_WORD1_OWNER;
614 WRITE32(owner_namelen);
615 WRITEMEM(owner_name, owner_namelen);
617 if (iap->ia_valid & ATTR_GID) {
618 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
619 WRITE32(owner_grouplen);
620 WRITEMEM(owner_group, owner_grouplen);
622 if (iap->ia_valid & ATTR_ATIME_SET) {
623 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
624 WRITE32(NFS4_SET_TO_CLIENT_TIME);
626 WRITE32(iap->ia_mtime.tv_sec);
627 WRITE32(iap->ia_mtime.tv_nsec);
629 else if (iap->ia_valid & ATTR_ATIME) {
630 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
631 WRITE32(NFS4_SET_TO_SERVER_TIME);
633 if (iap->ia_valid & ATTR_MTIME_SET) {
634 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
635 WRITE32(NFS4_SET_TO_CLIENT_TIME);
637 WRITE32(iap->ia_mtime.tv_sec);
638 WRITE32(iap->ia_mtime.tv_nsec);
640 else if (iap->ia_valid & ATTR_MTIME) {
641 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
642 WRITE32(NFS4_SET_TO_SERVER_TIME);
646 * Now we backfill the bitmap and the attribute buffer length.
648 if (len != ((char *)p - (char *)q) + 4) {
649 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
650 len, ((char *)p - (char *)q) + 4);
653 len = (char *)p - (char *)q - 12;
654 *q++ = htonl(bmval0);
655 *q++ = htonl(bmval1);
663 static int encode_access(struct xdr_stream *xdr, u32 access)
674 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
678 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
680 WRITE32(arg->seqid->sequence->counter);
681 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
686 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
692 WRITE64(args->offset);
693 WRITE32(args->count);
698 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
704 WRITE32(create->ftype);
706 switch (create->ftype) {
709 WRITE32(create->u.symlink.len);
710 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
713 case NF4BLK: case NF4CHR:
715 WRITE32(create->u.device.specdata1);
716 WRITE32(create->u.device.specdata2);
723 RESERVE_SPACE(4 + create->name->len);
724 WRITE32(create->name->len);
725 WRITEMEM(create->name->name, create->name->len);
727 return encode_attrs(xdr, create->attrs, create->server);
730 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
741 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
753 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
755 return encode_getattr_two(xdr,
756 bitmask[0] & nfs4_fattr_bitmap[0],
757 bitmask[1] & nfs4_fattr_bitmap[1]);
760 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
762 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
763 bitmask[1] & nfs4_fsinfo_bitmap[1]);
766 static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
768 return encode_getattr_two(xdr,
769 bitmask[0] & nfs4_fs_locations_bitmap[0],
770 bitmask[1] & nfs4_fs_locations_bitmap[1]);
773 static int encode_getfh(struct xdr_stream *xdr)
783 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
787 RESERVE_SPACE(8 + name->len);
790 WRITEMEM(name->name, name->len);
795 static inline int nfs4_lock_type(struct file_lock *fl, int block)
797 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
798 return block ? NFS4_READW_LT : NFS4_READ_LT;
799 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
802 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
804 if (fl->fl_end == OFFSET_MAX)
806 return fl->fl_end - fl->fl_start + 1;
810 * opcode,type,reclaim,offset,length,new_lock_owner = 32
811 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
813 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
819 WRITE32(nfs4_lock_type(args->fl, args->block));
820 WRITE32(args->reclaim);
821 WRITE64(args->fl->fl_start);
822 WRITE64(nfs4_lock_length(args->fl));
823 WRITE32(args->new_lock_owner);
824 if (args->new_lock_owner){
825 RESERVE_SPACE(4+NFS4_STATEID_SIZE+20);
826 WRITE32(args->open_seqid->sequence->counter);
827 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
828 WRITE32(args->lock_seqid->sequence->counter);
829 WRITE64(args->lock_owner.clientid);
831 WRITE32(args->lock_owner.id);
834 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
835 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
836 WRITE32(args->lock_seqid->sequence->counter);
842 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
848 WRITE32(nfs4_lock_type(args->fl, 0));
849 WRITE64(args->fl->fl_start);
850 WRITE64(nfs4_lock_length(args->fl));
851 WRITE64(args->lock_owner.clientid);
853 WRITE32(args->lock_owner.id);
858 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
862 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
864 WRITE32(nfs4_lock_type(args->fl, 0));
865 WRITE32(args->seqid->sequence->counter);
866 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
867 WRITE64(args->fl->fl_start);
868 WRITE64(nfs4_lock_length(args->fl));
873 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
878 RESERVE_SPACE(8 + len);
881 WRITEMEM(name->name, len);
886 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
891 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
893 WRITE32(NFS4_SHARE_ACCESS_READ);
896 WRITE32(NFS4_SHARE_ACCESS_WRITE);
898 case FMODE_READ|FMODE_WRITE:
899 WRITE32(NFS4_SHARE_ACCESS_BOTH);
904 WRITE32(0); /* for linux, share_deny = 0 always */
907 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
911 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
916 WRITE32(arg->seqid->sequence->counter);
917 encode_share_access(xdr, arg->open_flags);
919 WRITE64(arg->clientid);
924 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
929 switch(arg->open_flags & O_EXCL) {
931 WRITE32(NFS4_CREATE_UNCHECKED);
932 encode_attrs(xdr, arg->u.attrs, arg->server);
935 WRITE32(NFS4_CREATE_EXCLUSIVE);
936 encode_nfs4_verifier(xdr, &arg->u.verifier);
940 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
945 switch (arg->open_flags & O_CREAT) {
947 WRITE32(NFS4_OPEN_NOCREATE);
950 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
951 WRITE32(NFS4_OPEN_CREATE);
952 encode_createmode(xdr, arg);
956 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
961 switch (delegation_type) {
963 WRITE32(NFS4_OPEN_DELEGATE_NONE);
966 WRITE32(NFS4_OPEN_DELEGATE_READ);
968 case FMODE_WRITE|FMODE_READ:
969 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
976 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
981 WRITE32(NFS4_OPEN_CLAIM_NULL);
982 encode_string(xdr, name->len, name->name);
985 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
990 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
991 encode_delegation_type(xdr, type);
994 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
998 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
999 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1000 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1001 encode_string(xdr, name->len, name->name);
1004 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1006 encode_openhdr(xdr, arg);
1007 encode_opentype(xdr, arg);
1008 switch (arg->claim) {
1009 case NFS4_OPEN_CLAIM_NULL:
1010 encode_claim_null(xdr, arg->name);
1012 case NFS4_OPEN_CLAIM_PREVIOUS:
1013 encode_claim_previous(xdr, arg->u.delegation_type);
1015 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1016 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1024 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
1028 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1029 WRITE32(OP_OPEN_CONFIRM);
1030 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1031 WRITE32(arg->seqid->sequence->counter);
1036 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1040 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1041 WRITE32(OP_OPEN_DOWNGRADE);
1042 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1043 WRITE32(arg->seqid->sequence->counter);
1044 encode_share_access(xdr, arg->open_flags);
1049 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1054 RESERVE_SPACE(8 + len);
1057 WRITEMEM(fh->data, len);
1062 static int encode_putrootfh(struct xdr_stream *xdr)
1067 WRITE32(OP_PUTROOTFH);
1072 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1074 nfs4_stateid stateid;
1077 RESERVE_SPACE(NFS4_STATEID_SIZE);
1078 if (ctx->state != NULL) {
1079 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1080 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1082 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1085 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1092 encode_stateid(xdr, args->context);
1095 WRITE64(args->offset);
1096 WRITE32(args->count);
1101 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1103 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1104 uint32_t attrs[2] = {
1105 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1106 FATTR4_WORD1_MOUNTED_ON_FILEID,
1111 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1112 WRITE32(OP_READDIR);
1113 WRITE64(readdir->cookie);
1114 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1115 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1116 WRITE32(readdir->count);
1118 /* Switch to mounted_on_fileid if the server supports it */
1119 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1120 attrs[0] &= ~FATTR4_WORD0_FILEID;
1122 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1123 WRITE32(attrs[0] & readdir->bitmask[0]);
1124 WRITE32(attrs[1] & readdir->bitmask[1]);
1125 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1127 (unsigned long long)readdir->cookie,
1128 ((u32 *)readdir->verifier.data)[0],
1129 ((u32 *)readdir->verifier.data)[1],
1130 attrs[0] & readdir->bitmask[0],
1131 attrs[1] & readdir->bitmask[1]);
1133 /* set up reply kvec
1134 * toplevel_status + taglen + rescount + OP_PUTFH + status
1135 * + OP_READDIR + status + verifer(2) = 9
1137 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1138 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1139 readdir->pgbase, readdir->count);
1140 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1141 __FUNCTION__, replen, readdir->pages,
1142 readdir->pgbase, readdir->count);
1147 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1149 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1150 unsigned int replen;
1154 WRITE32(OP_READLINK);
1156 /* set up reply kvec
1157 * toplevel_status + taglen + rescount + OP_PUTFH + status
1158 * + OP_READLINK + status + string length = 8
1160 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1161 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1162 readlink->pgbase, readlink->pglen);
1167 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1171 RESERVE_SPACE(8 + name->len);
1174 WRITEMEM(name->name, name->len);
1179 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1183 RESERVE_SPACE(8 + oldname->len);
1185 WRITE32(oldname->len);
1186 WRITEMEM(oldname->name, oldname->len);
1188 RESERVE_SPACE(4 + newname->len);
1189 WRITE32(newname->len);
1190 WRITEMEM(newname->name, newname->len);
1195 static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
1201 WRITE64(client_stateid->cl_clientid);
1207 encode_restorefh(struct xdr_stream *xdr)
1212 WRITE32(OP_RESTOREFH);
1218 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1222 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1223 WRITE32(OP_SETATTR);
1224 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1227 WRITE32(FATTR4_WORD0_ACL);
1228 if (arg->acl_len % 4)
1231 WRITE32(arg->acl_len);
1232 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1237 encode_savefh(struct xdr_stream *xdr)
1247 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1252 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1253 WRITE32(OP_SETATTR);
1254 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1256 if ((status = encode_attrs(xdr, arg->iap, server)))
1262 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1266 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1267 WRITE32(OP_SETCLIENTID);
1268 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1270 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1272 WRITE32(setclientid->sc_prog);
1273 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1274 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1276 WRITE32(setclientid->sc_cb_ident);
1281 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
1285 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1286 WRITE32(OP_SETCLIENTID_CONFIRM);
1287 WRITE64(client_state->cl_clientid);
1288 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1293 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1300 encode_stateid(xdr, args->context);
1303 WRITE64(args->offset);
1304 WRITE32(args->stable);
1305 WRITE32(args->count);
1307 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1312 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1316 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1318 WRITE32(OP_DELEGRETURN);
1319 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1324 * END OF "GENERIC" ENCODE ROUTINES.
1328 * Encode an ACCESS request
1330 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1332 struct xdr_stream xdr;
1333 struct compound_hdr hdr = {
1338 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1339 encode_compound_hdr(&xdr, &hdr);
1340 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1341 status = encode_access(&xdr, args->access);
1346 * Encode LOOKUP request
1348 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1350 struct xdr_stream xdr;
1351 struct compound_hdr hdr = {
1356 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1357 encode_compound_hdr(&xdr, &hdr);
1358 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1360 if ((status = encode_lookup(&xdr, args->name)) != 0)
1362 if ((status = encode_getfh(&xdr)) != 0)
1364 status = encode_getfattr(&xdr, args->bitmask);
1370 * Encode LOOKUP_ROOT request
1372 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1374 struct xdr_stream xdr;
1375 struct compound_hdr hdr = {
1380 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1381 encode_compound_hdr(&xdr, &hdr);
1382 if ((status = encode_putrootfh(&xdr)) != 0)
1384 if ((status = encode_getfh(&xdr)) == 0)
1385 status = encode_getfattr(&xdr, args->bitmask);
1391 * Encode REMOVE request
1393 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs4_remove_arg *args)
1395 struct xdr_stream xdr;
1396 struct compound_hdr hdr = {
1401 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1402 encode_compound_hdr(&xdr, &hdr);
1403 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1405 if ((status = encode_remove(&xdr, args->name)) != 0)
1407 status = encode_getfattr(&xdr, args->bitmask);
1413 * Encode RENAME request
1415 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1417 struct xdr_stream xdr;
1418 struct compound_hdr hdr = {
1423 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1424 encode_compound_hdr(&xdr, &hdr);
1425 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1427 if ((status = encode_savefh(&xdr)) != 0)
1429 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1431 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1433 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1435 if ((status = encode_restorefh(&xdr)) != 0)
1437 status = encode_getfattr(&xdr, args->bitmask);
1443 * Encode LINK request
1445 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1447 struct xdr_stream xdr;
1448 struct compound_hdr hdr = {
1453 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1454 encode_compound_hdr(&xdr, &hdr);
1455 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1457 if ((status = encode_savefh(&xdr)) != 0)
1459 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1461 if ((status = encode_link(&xdr, args->name)) != 0)
1463 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1465 if ((status = encode_restorefh(&xdr)) != 0)
1467 status = encode_getfattr(&xdr, args->bitmask);
1473 * Encode CREATE request
1475 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1477 struct xdr_stream xdr;
1478 struct compound_hdr hdr = {
1483 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1484 encode_compound_hdr(&xdr, &hdr);
1485 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1487 if ((status = encode_savefh(&xdr)) != 0)
1489 if ((status = encode_create(&xdr, args)) != 0)
1491 if ((status = encode_getfh(&xdr)) != 0)
1493 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1495 if ((status = encode_restorefh(&xdr)) != 0)
1497 status = encode_getfattr(&xdr, args->bitmask);
1503 * Encode SYMLINK request
1505 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1507 return nfs4_xdr_enc_create(req, p, args);
1511 * Encode GETATTR request
1513 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1515 struct xdr_stream xdr;
1516 struct compound_hdr hdr = {
1521 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1522 encode_compound_hdr(&xdr, &hdr);
1523 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1524 status = encode_getfattr(&xdr, args->bitmask);
1529 * Encode a CLOSE request
1531 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1533 struct xdr_stream xdr;
1534 struct compound_hdr hdr = {
1539 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1540 encode_compound_hdr(&xdr, &hdr);
1541 status = encode_putfh(&xdr, args->fh);
1544 status = encode_close(&xdr, args);
1547 status = encode_getfattr(&xdr, args->bitmask);
1553 * Encode an OPEN request
1555 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1557 struct xdr_stream xdr;
1558 struct compound_hdr hdr = {
1563 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1564 encode_compound_hdr(&xdr, &hdr);
1565 status = encode_putfh(&xdr, args->fh);
1568 status = encode_savefh(&xdr);
1571 status = encode_open(&xdr, args);
1574 status = encode_getfh(&xdr);
1577 status = encode_getfattr(&xdr, args->bitmask);
1580 status = encode_restorefh(&xdr);
1583 status = encode_getfattr(&xdr, args->bitmask);
1589 * Encode an OPEN_CONFIRM request
1591 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1593 struct xdr_stream xdr;
1594 struct compound_hdr hdr = {
1599 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1600 encode_compound_hdr(&xdr, &hdr);
1601 status = encode_putfh(&xdr, args->fh);
1604 status = encode_open_confirm(&xdr, args);
1610 * Encode an OPEN request with no attributes.
1612 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1614 struct xdr_stream xdr;
1615 struct compound_hdr hdr = {
1620 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1621 encode_compound_hdr(&xdr, &hdr);
1622 status = encode_putfh(&xdr, args->fh);
1625 status = encode_open(&xdr, args);
1628 status = encode_getfattr(&xdr, args->bitmask);
1634 * Encode an OPEN_DOWNGRADE request
1636 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1638 struct xdr_stream xdr;
1639 struct compound_hdr hdr = {
1644 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1645 encode_compound_hdr(&xdr, &hdr);
1646 status = encode_putfh(&xdr, args->fh);
1649 status = encode_open_downgrade(&xdr, args);
1652 status = encode_getfattr(&xdr, args->bitmask);
1658 * Encode a LOCK request
1660 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1662 struct xdr_stream xdr;
1663 struct compound_hdr hdr = {
1668 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1669 encode_compound_hdr(&xdr, &hdr);
1670 status = encode_putfh(&xdr, args->fh);
1673 status = encode_lock(&xdr, args);
1679 * Encode a LOCKT request
1681 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1683 struct xdr_stream xdr;
1684 struct compound_hdr hdr = {
1689 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1690 encode_compound_hdr(&xdr, &hdr);
1691 status = encode_putfh(&xdr, args->fh);
1694 status = encode_lockt(&xdr, args);
1700 * Encode a LOCKU request
1702 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1704 struct xdr_stream xdr;
1705 struct compound_hdr hdr = {
1710 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1711 encode_compound_hdr(&xdr, &hdr);
1712 status = encode_putfh(&xdr, args->fh);
1715 status = encode_locku(&xdr, args);
1721 * Encode a READLINK request
1723 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1725 struct xdr_stream xdr;
1726 struct compound_hdr hdr = {
1731 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1732 encode_compound_hdr(&xdr, &hdr);
1733 status = encode_putfh(&xdr, args->fh);
1736 status = encode_readlink(&xdr, args, req);
1742 * Encode a READDIR request
1744 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1746 struct xdr_stream xdr;
1747 struct compound_hdr hdr = {
1752 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1753 encode_compound_hdr(&xdr, &hdr);
1754 status = encode_putfh(&xdr, args->fh);
1757 status = encode_readdir(&xdr, args, req);
1763 * Encode a READ request
1765 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1767 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1768 struct xdr_stream xdr;
1769 struct compound_hdr hdr = {
1774 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1775 encode_compound_hdr(&xdr, &hdr);
1776 status = encode_putfh(&xdr, args->fh);
1779 status = encode_read(&xdr, args);
1783 /* set up reply kvec
1784 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1785 * + OP_READ + status + eof + datalen = 9
1787 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1788 xdr_inline_pages(&req->rq_rcv_buf, replen,
1789 args->pages, args->pgbase, args->count);
1795 * Encode an SETATTR request
1797 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1800 struct xdr_stream xdr;
1801 struct compound_hdr hdr = {
1806 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1807 encode_compound_hdr(&xdr, &hdr);
1808 status = encode_putfh(&xdr, args->fh);
1811 status = encode_setattr(&xdr, args, args->server);
1814 status = encode_getfattr(&xdr, args->bitmask);
1820 * Encode a GETACL request
1823 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1824 struct nfs_getaclargs *args)
1826 struct xdr_stream xdr;
1827 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1828 struct compound_hdr hdr = {
1833 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1834 encode_compound_hdr(&xdr, &hdr);
1835 status = encode_putfh(&xdr, args->fh);
1838 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1839 /* set up reply buffer: */
1840 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1841 xdr_inline_pages(&req->rq_rcv_buf, replen,
1842 args->acl_pages, args->acl_pgbase, args->acl_len);
1848 * Encode a WRITE request
1850 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1852 struct xdr_stream xdr;
1853 struct compound_hdr hdr = {
1858 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1859 encode_compound_hdr(&xdr, &hdr);
1860 status = encode_putfh(&xdr, args->fh);
1863 status = encode_write(&xdr, args);
1866 status = encode_getfattr(&xdr, args->bitmask);
1874 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1876 struct xdr_stream xdr;
1877 struct compound_hdr hdr = {
1882 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1883 encode_compound_hdr(&xdr, &hdr);
1884 status = encode_putfh(&xdr, args->fh);
1887 status = encode_commit(&xdr, args);
1890 status = encode_getfattr(&xdr, args->bitmask);
1898 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_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_fsinfo(&xdr, args->bitmask);
1915 * a PATHCONF request
1917 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1919 struct xdr_stream xdr;
1920 struct compound_hdr hdr = {
1925 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1926 encode_compound_hdr(&xdr, &hdr);
1927 status = encode_putfh(&xdr, args->fh);
1929 status = encode_getattr_one(&xdr,
1930 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1937 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
1939 struct xdr_stream xdr;
1940 struct compound_hdr hdr = {
1945 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1946 encode_compound_hdr(&xdr, &hdr);
1947 status = encode_putfh(&xdr, args->fh);
1949 status = encode_getattr_two(&xdr,
1950 args->bitmask[0] & nfs4_statfs_bitmap[0],
1951 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1956 * GETATTR_BITMAP request
1958 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
1960 struct xdr_stream xdr;
1961 struct compound_hdr hdr = {
1966 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1967 encode_compound_hdr(&xdr, &hdr);
1968 status = encode_putfh(&xdr, fhandle);
1970 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1971 FATTR4_WORD0_LINK_SUPPORT|
1972 FATTR4_WORD0_SYMLINK_SUPPORT|
1973 FATTR4_WORD0_ACLSUPPORT);
1980 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1982 struct xdr_stream xdr;
1983 struct compound_hdr hdr = {
1987 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1988 encode_compound_hdr(&xdr, &hdr);
1989 return encode_renew(&xdr, clp);
1993 * a SETCLIENTID request
1995 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
1997 struct xdr_stream xdr;
1998 struct compound_hdr hdr = {
2002 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2003 encode_compound_hdr(&xdr, &hdr);
2004 return encode_setclientid(&xdr, sc);
2008 * a SETCLIENTID_CONFIRM request
2010 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2012 struct xdr_stream xdr;
2013 struct compound_hdr hdr = {
2016 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2019 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2020 encode_compound_hdr(&xdr, &hdr);
2021 status = encode_setclientid_confirm(&xdr, clp);
2023 status = encode_putrootfh(&xdr);
2025 status = encode_fsinfo(&xdr, lease_bitmap);
2030 * DELEGRETURN request
2032 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2034 struct xdr_stream xdr;
2035 struct compound_hdr hdr = {
2040 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2041 encode_compound_hdr(&xdr, &hdr);
2042 status = encode_putfh(&xdr, args->fhandle);
2045 status = encode_delegreturn(&xdr, args->stateid);
2048 status = encode_getfattr(&xdr, args->bitmask);
2054 * Encode FS_LOCATIONS request
2056 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2058 struct xdr_stream xdr;
2059 struct compound_hdr hdr = {
2062 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
2066 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2067 encode_compound_hdr(&xdr, &hdr);
2068 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2070 if ((status = encode_lookup(&xdr, args->name)) != 0)
2072 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
2075 * toplevel_status + OP_PUTFH + status
2076 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2078 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2079 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2086 * START OF "GENERIC" DECODE ROUTINES.
2087 * These may look a little ugly since they are imported from a "generic"
2088 * set of XDR encode/decode routines which are intended to be shared by
2089 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2091 * If the pain of reading these is too great, it should be a straightforward
2092 * task to translate them into Linux-specific versions which are more
2093 * consistent with the style used in NFSv2/v3...
2095 #define READ32(x) (x) = ntohl(*p++)
2096 #define READ64(x) do { \
2097 (x) = (u64)ntohl(*p++) << 32; \
2098 (x) |= ntohl(*p++); \
2100 #define READTIME(x) do { \
2102 (x.tv_sec) = ntohl(*p++); \
2103 (x.tv_nsec) = ntohl(*p++); \
2105 #define COPYMEM(x,nbytes) do { \
2106 memcpy((x), p, nbytes); \
2107 p += XDR_QUADLEN(nbytes); \
2110 #define READ_BUF(nbytes) do { \
2111 p = xdr_inline_decode(xdr, nbytes); \
2112 if (unlikely(!p)) { \
2113 printk(KERN_INFO "%s: prematurely hit end of receive" \
2114 " buffer\n", __FUNCTION__); \
2115 printk(KERN_INFO "%s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2116 __FUNCTION__, xdr->p, nbytes, xdr->end); \
2121 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2128 *string = (char *)p;
2132 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2137 READ32(hdr->status);
2138 READ32(hdr->taglen);
2140 READ_BUF(hdr->taglen + 4);
2141 hdr->tag = (char *)p;
2142 p += XDR_QUADLEN(hdr->taglen);
2147 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2155 if (opnum != expected) {
2157 "nfs4_decode_op_hdr: Server returned operation"
2158 " %d but we issued a request for %d\n",
2163 if (nfserr != NFS_OK)
2164 return -nfs4_stat_to_errno(nfserr);
2169 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2172 unsigned int strlen;
2176 return decode_opaque_inline(xdr, &strlen, &str);
2179 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2187 bitmap[0] = bitmap[1] = 0;
2188 READ_BUF((bmlen << 2));
2197 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2207 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2209 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2210 decode_attr_bitmap(xdr, bitmask);
2211 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2213 bitmask[0] = bitmask[1] = 0;
2214 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2218 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2223 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2225 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2228 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2229 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2232 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2234 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2238 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2243 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2245 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2248 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2250 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2251 (unsigned long long)*change);
2255 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2260 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2262 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2265 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2267 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2271 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2276 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2278 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2281 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2283 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2287 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2292 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2294 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2297 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2299 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2303 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2309 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2311 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2313 READ64(fsid->major);
2314 READ64(fsid->minor);
2315 bitmap[0] &= ~FATTR4_WORD0_FSID;
2317 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2318 (unsigned long long)fsid->major,
2319 (unsigned long long)fsid->minor);
2323 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2328 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2330 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2333 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2335 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2339 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2343 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2344 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2346 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2349 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2351 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2355 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2360 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2362 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2365 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2367 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2371 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2376 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2378 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2381 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2383 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2387 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2393 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2395 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2398 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2400 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2404 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2410 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2412 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2415 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2417 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2421 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2427 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2429 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2432 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2434 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2438 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2451 path->ncomponents = 0;
2452 while (path->ncomponents < n) {
2453 struct nfs4_string *component = &path->components[path->ncomponents];
2454 status = decode_opaque_inline(xdr, &component->len, &component->data);
2455 if (unlikely(status != 0))
2457 if (path->ncomponents != n)
2459 dprintk("%s", component->data);
2460 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2461 path->ncomponents++;
2463 dprintk("cannot parse %d components in path\n", n);
2471 /* a root pathname is sent as a zero component4 */
2472 path->ncomponents = 1;
2473 path->components[0].len=0;
2474 path->components[0].data=NULL;
2475 dprintk("path /\n");
2478 dprintk(" status %d", status);
2483 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2489 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2492 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2494 dprintk("%s: fsroot ", __FUNCTION__);
2495 status = decode_pathname(xdr, &res->fs_path);
2496 if (unlikely(status != 0))
2502 res->nlocations = 0;
2503 while (res->nlocations < n) {
2505 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2513 dprintk("%s: servers ", __FUNCTION__);
2514 while (loc->nservers < m) {
2515 struct nfs4_string *server = &loc->servers[loc->nservers];
2516 status = decode_opaque_inline(xdr, &server->len, &server->data);
2517 if (unlikely(status != 0))
2519 dprintk("%s ", server->data);
2520 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2524 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2525 for (i = loc->nservers; i < m; i++) {
2528 status = decode_opaque_inline(xdr, &len, &data);
2529 if (unlikely(status != 0))
2534 status = decode_pathname(xdr, &loc->rootpath);
2535 if (unlikely(status != 0))
2537 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2541 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2548 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2554 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2556 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2559 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2561 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2565 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2571 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2573 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2576 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2578 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2582 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2588 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2590 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2593 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2595 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2599 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2605 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2607 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2611 if (maxread > 0x7FFFFFFF)
2612 maxread = 0x7FFFFFFF;
2613 *res = (uint32_t)maxread;
2614 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2616 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2620 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2626 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2628 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2632 if (maxwrite > 0x7FFFFFFF)
2633 maxwrite = 0x7FFFFFFF;
2634 *res = (uint32_t)maxwrite;
2635 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2637 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2641 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2646 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2648 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2652 bitmap[1] &= ~FATTR4_WORD1_MODE;
2654 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2658 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2663 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2665 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2668 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2670 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2674 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2680 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2682 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2686 if (len < XDR_MAX_NETOBJ) {
2687 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2688 dprintk("%s: nfs_map_name_to_uid failed!\n",
2691 printk(KERN_WARNING "%s: name too long (%u)!\n",
2693 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2695 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2699 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2705 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2707 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2711 if (len < XDR_MAX_NETOBJ) {
2712 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2713 dprintk("%s: nfs_map_group_to_gid failed!\n",
2716 printk(KERN_WARNING "%s: name too long (%u)!\n",
2718 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2720 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2724 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2726 uint32_t major = 0, minor = 0;
2730 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2732 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2738 tmp = MKDEV(major, minor);
2739 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2741 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2743 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2747 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2753 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2755 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2758 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2760 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2764 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2770 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2772 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2775 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2777 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2781 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2787 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2789 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2792 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2794 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2798 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2803 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2805 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2808 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2810 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2811 (unsigned long long)*used);
2815 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2824 time->tv_sec = (time_t)sec;
2825 time->tv_nsec = (long)nsec;
2829 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2835 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2837 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2838 status = decode_attr_time(xdr, time);
2839 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2841 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2845 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2851 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2853 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2854 status = decode_attr_time(xdr, time);
2855 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2857 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2861 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2867 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2869 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2870 status = decode_attr_time(xdr, time);
2871 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2873 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2877 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2879 unsigned int attrwords = XDR_QUADLEN(attrlen);
2880 unsigned int nwords = xdr->p - savep;
2882 if (unlikely(attrwords != nwords)) {
2883 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2886 (attrwords < nwords) ? '<' : '>',
2893 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2898 READ32(cinfo->atomic);
2899 READ64(cinfo->before);
2900 READ64(cinfo->after);
2904 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2910 status = decode_op_hdr(xdr, OP_ACCESS);
2916 access->supported = supp;
2917 access->access = acc;
2921 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2926 status = decode_op_hdr(xdr, OP_CLOSE);
2929 READ_BUF(NFS4_STATEID_SIZE);
2930 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
2934 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2939 status = decode_op_hdr(xdr, OP_COMMIT);
2943 COPYMEM(res->verf->verifier, 8);
2947 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2953 status = decode_op_hdr(xdr, OP_CREATE);
2956 if ((status = decode_change_info(xdr, cinfo)))
2960 READ_BUF(bmlen << 2);
2964 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2971 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2973 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2975 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2977 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2979 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2981 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2983 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2985 status = verify_attr_len(xdr, savep, attrlen);
2987 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2991 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2998 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3000 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3002 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3005 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3007 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3009 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3011 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3013 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3015 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3018 status = verify_attr_len(xdr, savep, attrlen);
3020 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3024 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3031 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3033 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3035 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3038 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3040 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3043 status = verify_attr_len(xdr, savep, attrlen);
3045 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3049 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3055 int status, fmode = 0;
3058 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3060 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3063 fattr->bitmap[0] = bitmap[0];
3064 fattr->bitmap[1] = bitmap[1];
3066 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3070 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3072 fattr->type = nfs_type2fmt[type].nfs2type;
3073 fmode = nfs_type2fmt[type].mode;
3075 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3077 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3079 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
3081 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3083 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3084 struct nfs4_fs_locations,
3087 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3089 fattr->mode |= fmode;
3090 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3092 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
3094 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
3096 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3098 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3100 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3102 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3104 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3106 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3108 if (fattr->fileid == 0 && fileid != 0)
3109 fattr->fileid = fileid;
3110 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
3111 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
3113 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
3118 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3121 uint32_t attrlen, bitmap[2];
3124 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3126 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3128 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3131 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3133 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3135 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3137 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3139 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3140 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3142 fsinfo->wtpref = fsinfo->wtmax;
3144 status = verify_attr_len(xdr, savep, attrlen);
3146 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3150 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3156 status = decode_op_hdr(xdr, OP_GETFH);
3159 /* Zero handle first to allow comparisons */
3160 memset(fh, 0, sizeof(*fh));
3164 if (len > NFS4_FHSIZE)
3168 COPYMEM(fh->data, len);
3172 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3176 status = decode_op_hdr(xdr, OP_LINK);
3179 return decode_change_info(xdr, cinfo);
3183 * We create the owner, so we know a proper owner.id length is 4.
3185 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3187 uint64_t offset, length, clientid;
3189 uint32_t namelen, type;
3196 fl->fl_start = (loff_t)offset;
3197 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3198 if (length == ~(uint64_t)0)
3199 fl->fl_end = OFFSET_MAX;
3200 fl->fl_type = F_WRLCK;
3202 fl->fl_type = F_RDLCK;
3208 return -NFS4ERR_DENIED;
3211 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3216 status = decode_op_hdr(xdr, OP_LOCK);
3218 READ_BUF(NFS4_STATEID_SIZE);
3219 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3220 } else if (status == -NFS4ERR_DENIED)
3221 return decode_lock_denied(xdr, NULL);
3225 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3228 status = decode_op_hdr(xdr, OP_LOCKT);
3229 if (status == -NFS4ERR_DENIED)
3230 return decode_lock_denied(xdr, res->denied);
3234 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3239 status = decode_op_hdr(xdr, OP_LOCKU);
3241 READ_BUF(NFS4_STATEID_SIZE);
3242 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3247 static int decode_lookup(struct xdr_stream *xdr)
3249 return decode_op_hdr(xdr, OP_LOOKUP);
3252 /* This is too sick! */
3253 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3256 uint32_t limit_type, nblocks, blocksize;
3260 switch (limit_type) {
3267 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3272 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3275 uint32_t delegation_type;
3278 READ32(delegation_type);
3279 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3280 res->delegation_type = 0;
3283 READ_BUF(NFS4_STATEID_SIZE+4);
3284 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3285 READ32(res->do_recall);
3286 switch (delegation_type) {
3287 case NFS4_OPEN_DELEGATE_READ:
3288 res->delegation_type = FMODE_READ;
3290 case NFS4_OPEN_DELEGATE_WRITE:
3291 res->delegation_type = FMODE_WRITE|FMODE_READ;
3292 if (decode_space_limit(xdr, &res->maxsize) < 0)
3295 return decode_ace(xdr, NULL, res->server->nfs_client);
3298 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3301 uint32_t savewords, bmlen, i;
3304 status = decode_op_hdr(xdr, OP_OPEN);
3307 READ_BUF(NFS4_STATEID_SIZE);
3308 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3310 decode_change_info(xdr, &res->cinfo);
3313 READ32(res->rflags);
3318 READ_BUF(bmlen << 2);
3319 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3320 for (i = 0; i < savewords; ++i)
3321 READ32(res->attrset[i]);
3322 for (; i < NFS4_BITMAP_SIZE; i++)
3323 res->attrset[i] = 0;
3325 return decode_delegation(xdr, res);
3327 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
3331 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3336 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3339 READ_BUF(NFS4_STATEID_SIZE);
3340 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3344 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3349 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3352 READ_BUF(NFS4_STATEID_SIZE);
3353 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3357 static int decode_putfh(struct xdr_stream *xdr)
3359 return decode_op_hdr(xdr, OP_PUTFH);
3362 static int decode_putrootfh(struct xdr_stream *xdr)
3364 return decode_op_hdr(xdr, OP_PUTROOTFH);
3367 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3369 struct kvec *iov = req->rq_rcv_buf.head;
3371 uint32_t count, eof, recvd, hdrlen;
3374 status = decode_op_hdr(xdr, OP_READ);
3380 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3381 recvd = req->rq_rcv_buf.len - hdrlen;
3382 if (count > recvd) {
3383 printk(KERN_WARNING "NFS: server cheating in read reply: "
3384 "count %u > recvd %u\n", count, recvd);
3388 xdr_read_pages(xdr, count);
3394 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3396 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3397 struct page *page = *rcvbuf->pages;
3398 struct kvec *iov = rcvbuf->head;
3399 unsigned int nr, pglen = rcvbuf->page_len;
3400 __be32 *end, *entry, *p, *kaddr;
3401 uint32_t len, attrlen, xlen;
3402 int hdrlen, recvd, status;
3404 status = decode_op_hdr(xdr, OP_READDIR);
3408 COPYMEM(readdir->verifier.data, 8);
3409 dprintk("%s: verifier = 0x%x%x\n",
3411 ((u32 *)readdir->verifier.data)[0],
3412 ((u32 *)readdir->verifier.data)[1]);
3415 hdrlen = (char *) p - (char *) iov->iov_base;
3416 recvd = rcvbuf->len - hdrlen;
3419 xdr_read_pages(xdr, pglen);
3421 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3422 kaddr = p = kmap_atomic(page, KM_USER0);
3423 end = p + ((pglen + readdir->pgbase) >> 2);
3425 for (nr = 0; *p++; nr++) {
3428 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3429 p += 2; /* cookie */
3430 len = ntohl(*p++); /* filename length */
3431 if (len > NFS4_MAXNAMLEN) {
3432 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3435 xlen = XDR_QUADLEN(len);
3436 if (end - p < xlen + 1)
3438 dprintk("filename = %*s\n", len, (char *)p);
3440 len = ntohl(*p++); /* bitmap length */
3441 if (end - p < len + 1)
3444 attrlen = XDR_QUADLEN(ntohl(*p++));
3445 if (end - p < attrlen + 2)
3447 p += attrlen; /* attributes */
3450 if (!nr && (entry[0] != 0 || entry[1] == 0))
3453 kunmap_atomic(kaddr, KM_USER0);
3456 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3457 entry[0] = entry[1] = 0;
3458 /* truncate listing ? */
3460 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3465 kunmap_atomic(kaddr, KM_USER0);
3466 return -errno_NFSERR_IO;
3469 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3471 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3472 struct kvec *iov = rcvbuf->head;
3473 int hdrlen, len, recvd;
3478 status = decode_op_hdr(xdr, OP_READLINK);
3482 /* Convert length of symlink */
3485 if (len >= rcvbuf->page_len || len <= 0) {
3486 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3487 return -ENAMETOOLONG;
3489 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3490 recvd = req->rq_rcv_buf.len - hdrlen;
3492 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3493 "count %u > recvd %u\n", len, recvd);
3496 xdr_read_pages(xdr, len);
3498 * The XDR encode routine has set things up so that
3499 * the link text will be copied directly into the
3500 * buffer. We just have to do overflow-checking,
3501 * and and null-terminate the text (the VFS expects
3502 * null-termination).
3504 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3505 kaddr[len+rcvbuf->page_base] = '\0';
3506 kunmap_atomic(kaddr, KM_USER0);
3510 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3514 status = decode_op_hdr(xdr, OP_REMOVE);
3517 status = decode_change_info(xdr, cinfo);
3522 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3523 struct nfs4_change_info *new_cinfo)
3527 status = decode_op_hdr(xdr, OP_RENAME);
3530 if ((status = decode_change_info(xdr, old_cinfo)))
3532 status = decode_change_info(xdr, new_cinfo);
3537 static int decode_renew(struct xdr_stream *xdr)
3539 return decode_op_hdr(xdr, OP_RENEW);
3543 decode_restorefh(struct xdr_stream *xdr)
3545 return decode_op_hdr(xdr, OP_RESTOREFH);
3548 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3554 struct kvec *iov = req->rq_rcv_buf.head;
3558 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3560 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3562 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3565 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3567 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3570 /* We ignore &savep and don't do consistency checks on
3571 * the attr length. Let userspace figure it out.... */
3572 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3573 recvd = req->rq_rcv_buf.len - hdrlen;
3574 if (attrlen > recvd) {
3575 printk(KERN_WARNING "NFS: server cheating in getattr"
3576 " acl reply: attrlen %u > recvd %u\n",
3580 xdr_read_pages(xdr, attrlen);
3583 status = -EOPNOTSUPP;
3590 decode_savefh(struct xdr_stream *xdr)
3592 return decode_op_hdr(xdr, OP_SAVEFH);
3595 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3602 status = decode_op_hdr(xdr, OP_SETATTR);
3607 READ_BUF(bmlen << 2);
3611 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3619 if (opnum != OP_SETCLIENTID) {
3621 "nfs4_decode_setclientid: Server returned operation"
3626 if (nfserr == NFS_OK) {
3627 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3628 READ64(clp->cl_clientid);
3629 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3630 } else if (nfserr == NFSERR_CLID_INUSE) {
3633 /* skip netid string */
3638 /* skip uaddr string */
3642 return -NFSERR_CLID_INUSE;
3644 return -nfs4_stat_to_errno(nfserr);
3649 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3651 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3654 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3659 status = decode_op_hdr(xdr, OP_WRITE);
3665 READ32(res->verf->committed);
3666 COPYMEM(res->verf->verifier, 8);
3670 static int decode_delegreturn(struct xdr_stream *xdr)
3672 return decode_op_hdr(xdr, OP_DELEGRETURN);
3676 * Decode OPEN_DOWNGRADE response
3678 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3680 struct xdr_stream xdr;
3681 struct compound_hdr hdr;
3684 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3685 status = decode_compound_hdr(&xdr, &hdr);
3688 status = decode_putfh(&xdr);
3691 status = decode_open_downgrade(&xdr, res);
3694 decode_getfattr(&xdr, res->fattr, res->server);
3700 * END OF "GENERIC" DECODE ROUTINES.
3704 * Decode ACCESS response
3706 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3708 struct xdr_stream xdr;
3709 struct compound_hdr hdr;
3712 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3713 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3715 if ((status = decode_putfh(&xdr)) == 0)
3716 status = decode_access(&xdr, res);
3722 * Decode LOOKUP response
3724 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3726 struct xdr_stream xdr;
3727 struct compound_hdr hdr;
3730 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3731 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3733 if ((status = decode_putfh(&xdr)) != 0)
3735 if ((status = decode_lookup(&xdr)) != 0)
3737 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3739 status = decode_getfattr(&xdr, res->fattr, res->server);
3745 * Decode LOOKUP_ROOT response
3747 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3749 struct xdr_stream xdr;
3750 struct compound_hdr hdr;
3753 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3754 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3756 if ((status = decode_putrootfh(&xdr)) != 0)
3758 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3759 status = decode_getfattr(&xdr, res->fattr, res->server);
3765 * Decode REMOVE response
3767 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_remove_res *res)
3769 struct xdr_stream xdr;
3770 struct compound_hdr hdr;
3773 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3774 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3776 if ((status = decode_putfh(&xdr)) != 0)
3778 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3780 decode_getfattr(&xdr, res->dir_attr, res->server);
3786 * Decode RENAME response
3788 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3790 struct xdr_stream xdr;
3791 struct compound_hdr hdr;
3794 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3795 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3797 if ((status = decode_putfh(&xdr)) != 0)
3799 if ((status = decode_savefh(&xdr)) != 0)
3801 if ((status = decode_putfh(&xdr)) != 0)
3803 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3805 /* Current FH is target directory */
3806 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3808 if ((status = decode_restorefh(&xdr)) != 0)
3810 decode_getfattr(&xdr, res->old_fattr, res->server);
3816 * Decode LINK response
3818 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3820 struct xdr_stream xdr;
3821 struct compound_hdr hdr;
3824 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3825 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3827 if ((status = decode_putfh(&xdr)) != 0)
3829 if ((status = decode_savefh(&xdr)) != 0)
3831 if ((status = decode_putfh(&xdr)) != 0)
3833 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3836 * Note order: OP_LINK leaves the directory as the current
3839 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3841 if ((status = decode_restorefh(&xdr)) != 0)
3843 decode_getfattr(&xdr, res->fattr, res->server);
3849 * Decode CREATE response
3851 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3853 struct xdr_stream xdr;
3854 struct compound_hdr hdr;
3857 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3858 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3860 if ((status = decode_putfh(&xdr)) != 0)
3862 if ((status = decode_savefh(&xdr)) != 0)
3864 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3866 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3868 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3870 if ((status = decode_restorefh(&xdr)) != 0)
3872 decode_getfattr(&xdr, res->dir_fattr, res->server);
3878 * Decode SYMLINK response
3880 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3882 return nfs4_xdr_dec_create(rqstp, p, res);
3886 * Decode GETATTR response
3888 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3890 struct xdr_stream xdr;
3891 struct compound_hdr hdr;
3894 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3895 status = decode_compound_hdr(&xdr, &hdr);
3898 status = decode_putfh(&xdr);
3901 status = decode_getfattr(&xdr, res->fattr, res->server);
3908 * Encode an SETACL request
3911 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3913 struct xdr_stream xdr;
3914 struct compound_hdr hdr = {
3919 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3920 encode_compound_hdr(&xdr, &hdr);
3921 status = encode_putfh(&xdr, args->fh);
3924 status = encode_setacl(&xdr, args);
3929 * Decode SETACL response
3932 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
3934 struct xdr_stream xdr;
3935 struct compound_hdr hdr;
3938 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3939 status = decode_compound_hdr(&xdr, &hdr);
3942 status = decode_putfh(&xdr);
3945 status = decode_setattr(&xdr, res);
3951 * Decode GETACL response
3954 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
3956 struct xdr_stream xdr;
3957 struct compound_hdr hdr;
3960 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3961 status = decode_compound_hdr(&xdr, &hdr);
3964 status = decode_putfh(&xdr);
3967 status = decode_getacl(&xdr, rqstp, acl_len);
3974 * Decode CLOSE response
3976 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3978 struct xdr_stream xdr;
3979 struct compound_hdr hdr;
3982 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3983 status = decode_compound_hdr(&xdr, &hdr);
3986 status = decode_putfh(&xdr);
3989 status = decode_close(&xdr, res);
3993 * Note: Server may do delete on close for this file
3994 * in which case the getattr call will fail with
3995 * an ESTALE error. Shouldn't be a problem,
3996 * though, since fattr->valid will remain unset.
3998 decode_getfattr(&xdr, res->fattr, res->server);
4004 * Decode OPEN response
4006 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4008 struct xdr_stream xdr;
4009 struct compound_hdr hdr;
4012 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4013 status = decode_compound_hdr(&xdr, &hdr);
4016 status = decode_putfh(&xdr);
4019 status = decode_savefh(&xdr);
4022 status = decode_open(&xdr, res);
4025 status = decode_getfh(&xdr, &res->fh);
4028 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4030 if ((status = decode_restorefh(&xdr)) != 0)
4032 decode_getfattr(&xdr, res->dir_attr, res->server);
4038 * Decode OPEN_CONFIRM response
4040 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4042 struct xdr_stream xdr;
4043 struct compound_hdr hdr;
4046 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4047 status = decode_compound_hdr(&xdr, &hdr);
4050 status = decode_putfh(&xdr);
4053 status = decode_open_confirm(&xdr, res);
4059 * Decode OPEN response
4061 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4063 struct xdr_stream xdr;
4064 struct compound_hdr hdr;
4067 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4068 status = decode_compound_hdr(&xdr, &hdr);
4071 status = decode_putfh(&xdr);
4074 status = decode_open(&xdr, res);
4077 decode_getfattr(&xdr, res->f_attr, res->server);
4083 * Decode SETATTR response
4085 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4087 struct xdr_stream xdr;
4088 struct compound_hdr hdr;
4091 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4092 status = decode_compound_hdr(&xdr, &hdr);
4095 status = decode_putfh(&xdr);
4098 status = decode_setattr(&xdr, res);
4101 status = decode_getfattr(&xdr, res->fattr, res->server);
4102 if (status == NFS4ERR_DELAY)
4109 * Decode LOCK response
4111 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4113 struct xdr_stream xdr;
4114 struct compound_hdr hdr;
4117 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4118 status = decode_compound_hdr(&xdr, &hdr);
4121 status = decode_putfh(&xdr);
4124 status = decode_lock(&xdr, res);
4130 * Decode LOCKT response
4132 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4134 struct xdr_stream xdr;
4135 struct compound_hdr hdr;
4138 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4139 status = decode_compound_hdr(&xdr, &hdr);
4142 status = decode_putfh(&xdr);
4145 status = decode_lockt(&xdr, res);
4151 * Decode LOCKU response
4153 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4155 struct xdr_stream xdr;
4156 struct compound_hdr hdr;
4159 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4160 status = decode_compound_hdr(&xdr, &hdr);
4163 status = decode_putfh(&xdr);
4166 status = decode_locku(&xdr, res);
4172 * Decode READLINK response
4174 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
4176 struct xdr_stream xdr;
4177 struct compound_hdr hdr;
4180 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4181 status = decode_compound_hdr(&xdr, &hdr);
4184 status = decode_putfh(&xdr);
4187 status = decode_readlink(&xdr, rqstp);
4193 * Decode READDIR response
4195 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4197 struct xdr_stream xdr;
4198 struct compound_hdr hdr;
4201 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4202 status = decode_compound_hdr(&xdr, &hdr);
4205 status = decode_putfh(&xdr);
4208 status = decode_readdir(&xdr, rqstp, res);
4214 * Decode Read response
4216 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4218 struct xdr_stream xdr;
4219 struct compound_hdr hdr;
4222 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4223 status = decode_compound_hdr(&xdr, &hdr);
4226 status = decode_putfh(&xdr);
4229 status = decode_read(&xdr, rqstp, res);
4231 status = res->count;
4237 * Decode WRITE response
4239 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4241 struct xdr_stream xdr;
4242 struct compound_hdr hdr;
4245 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4246 status = decode_compound_hdr(&xdr, &hdr);
4249 status = decode_putfh(&xdr);
4252 status = decode_write(&xdr, res);
4255 decode_getfattr(&xdr, res->fattr, res->server);
4257 status = res->count;
4263 * Decode COMMIT response
4265 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4267 struct xdr_stream xdr;
4268 struct compound_hdr hdr;
4271 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4272 status = decode_compound_hdr(&xdr, &hdr);
4275 status = decode_putfh(&xdr);
4278 status = decode_commit(&xdr, res);
4281 decode_getfattr(&xdr, res->fattr, res->server);
4289 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4291 struct xdr_stream xdr;
4292 struct compound_hdr hdr;
4295 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4296 status = decode_compound_hdr(&xdr, &hdr);
4298 status = decode_putfh(&xdr);
4300 status = decode_fsinfo(&xdr, fsinfo);
4302 status = -nfs4_stat_to_errno(hdr.status);
4309 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
4311 struct xdr_stream xdr;
4312 struct compound_hdr hdr;
4315 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4316 status = decode_compound_hdr(&xdr, &hdr);
4318 status = decode_putfh(&xdr);
4320 status = decode_pathconf(&xdr, pathconf);
4327 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
4329 struct xdr_stream xdr;
4330 struct compound_hdr hdr;
4333 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4334 status = decode_compound_hdr(&xdr, &hdr);
4336 status = decode_putfh(&xdr);
4338 status = decode_statfs(&xdr, fsstat);
4343 * GETATTR_BITMAP request
4345 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4347 struct xdr_stream xdr;
4348 struct compound_hdr hdr;
4351 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4352 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4354 if ((status = decode_putfh(&xdr)) != 0)
4356 status = decode_server_caps(&xdr, res);
4362 * Decode RENEW response
4364 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4366 struct xdr_stream xdr;
4367 struct compound_hdr hdr;
4370 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4371 status = decode_compound_hdr(&xdr, &hdr);
4373 status = decode_renew(&xdr);
4378 * a SETCLIENTID request
4380 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4381 struct nfs_client *clp)
4383 struct xdr_stream xdr;
4384 struct compound_hdr hdr;
4387 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4388 status = decode_compound_hdr(&xdr, &hdr);
4390 status = decode_setclientid(&xdr, clp);
4392 status = -nfs4_stat_to_errno(hdr.status);
4397 * a SETCLIENTID_CONFIRM request
4399 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4401 struct xdr_stream xdr;
4402 struct compound_hdr hdr;
4405 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4406 status = decode_compound_hdr(&xdr, &hdr);
4408 status = decode_setclientid_confirm(&xdr);
4410 status = decode_putrootfh(&xdr);
4412 status = decode_fsinfo(&xdr, fsinfo);
4414 status = -nfs4_stat_to_errno(hdr.status);
4419 * DELEGRETURN request
4421 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4423 struct xdr_stream xdr;
4424 struct compound_hdr hdr;
4427 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4428 status = decode_compound_hdr(&xdr, &hdr);
4431 status = decode_putfh(&xdr);
4434 status = decode_delegreturn(&xdr);
4435 decode_getfattr(&xdr, res->fattr, res->server);
4441 * FS_LOCATIONS request
4443 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
4445 struct xdr_stream xdr;
4446 struct compound_hdr hdr;
4449 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4450 status = decode_compound_hdr(&xdr, &hdr);
4453 if ((status = decode_putfh(&xdr)) != 0)
4455 if ((status = decode_lookup(&xdr)) != 0)
4457 xdr_enter_page(&xdr, PAGE_SIZE);
4458 status = decode_getfattr(&xdr, &res->fattr, res->server);
4463 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4465 uint32_t bitmap[2] = {0};
4470 return ERR_PTR(-EAGAIN);
4472 return ERR_PTR(-EBADCOOKIE);
4475 entry->prev_cookie = entry->cookie;
4476 p = xdr_decode_hyper(p, &entry->cookie);
4477 entry->len = ntohl(*p++);
4478 entry->name = (const char *) p;
4479 p += XDR_QUADLEN(entry->len);
4482 * In case the server doesn't return an inode number,
4483 * we fake one here. (We don't use inode number 0,
4484 * since glibc seems to choke on it...)
4488 len = ntohl(*p++); /* bitmap length */
4490 bitmap[0] = ntohl(*p++);
4492 bitmap[1] = ntohl(*p++);
4496 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4498 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4499 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4500 /* Ignore the return value of rdattr_error for now */
4504 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4505 xdr_decode_hyper(p, &entry->ino);
4506 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4507 xdr_decode_hyper(p, &entry->ino);
4511 entry->eof = !p[0] && p[1];
4516 * We need to translate between nfs status return values and
4517 * the local errno values which may not be the same.
4524 { NFS4ERR_PERM, EPERM },
4525 { NFS4ERR_NOENT, ENOENT },
4526 { NFS4ERR_IO, errno_NFSERR_IO },
4527 { NFS4ERR_NXIO, ENXIO },
4528 { NFS4ERR_ACCESS, EACCES },
4529 { NFS4ERR_EXIST, EEXIST },
4530 { NFS4ERR_XDEV, EXDEV },
4531 { NFS4ERR_NOTDIR, ENOTDIR },
4532 { NFS4ERR_ISDIR, EISDIR },
4533 { NFS4ERR_INVAL, EINVAL },
4534 { NFS4ERR_FBIG, EFBIG },
4535 { NFS4ERR_NOSPC, ENOSPC },
4536 { NFS4ERR_ROFS, EROFS },
4537 { NFS4ERR_MLINK, EMLINK },
4538 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4539 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4540 { NFS4ERR_DQUOT, EDQUOT },
4541 { NFS4ERR_STALE, ESTALE },
4542 { NFS4ERR_BADHANDLE, EBADHANDLE },
4543 { NFS4ERR_BADOWNER, EINVAL },
4544 { NFS4ERR_BADNAME, EINVAL },
4545 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4546 { NFS4ERR_NOTSUPP, ENOTSUPP },
4547 { NFS4ERR_TOOSMALL, ETOOSMALL },
4548 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4549 { NFS4ERR_BADTYPE, EBADTYPE },
4550 { NFS4ERR_LOCKED, EAGAIN },
4551 { NFS4ERR_RESOURCE, EREMOTEIO },
4552 { NFS4ERR_SYMLINK, ELOOP },
4553 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4554 { NFS4ERR_DEADLOCK, EDEADLK },
4555 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4556 * to be handled by a
4563 * Convert an NFS error code to a local one.
4564 * This one is used jointly by NFSv2 and NFSv3.
4567 nfs4_stat_to_errno(int stat)
4570 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4571 if (nfs_errtbl[i].stat == stat)
4572 return nfs_errtbl[i].errno;
4574 if (stat <= 10000 || stat > 10100) {
4575 /* The server is looney tunes. */
4576 return ESERVERFAULT;
4578 /* If we cannot translate the error, the recovery routines should
4580 * Note: remaining NFSv4 error codes have values > 10000, so should
4581 * not conflict with native Linux error codes.
4586 #define PROC(proc, argtype, restype) \
4587 [NFSPROC4_CLNT_##proc] = { \
4588 .p_proc = NFSPROC4_COMPOUND, \
4589 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4590 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4591 .p_arglen = NFS4_##argtype##_sz, \
4592 .p_replen = NFS4_##restype##_sz, \
4593 .p_statidx = NFSPROC4_CLNT_##proc, \
4597 struct rpc_procinfo nfs4_procedures[] = {
4598 PROC(READ, enc_read, dec_read),
4599 PROC(WRITE, enc_write, dec_write),
4600 PROC(COMMIT, enc_commit, dec_commit),
4601 PROC(OPEN, enc_open, dec_open),
4602 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4603 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4604 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4605 PROC(CLOSE, enc_close, dec_close),
4606 PROC(SETATTR, enc_setattr, dec_setattr),
4607 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4608 PROC(RENEW, enc_renew, dec_renew),
4609 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4610 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4611 PROC(LOCK, enc_lock, dec_lock),
4612 PROC(LOCKT, enc_lockt, dec_lockt),
4613 PROC(LOCKU, enc_locku, dec_locku),
4614 PROC(ACCESS, enc_access, dec_access),
4615 PROC(GETATTR, enc_getattr, dec_getattr),
4616 PROC(LOOKUP, enc_lookup, dec_lookup),
4617 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4618 PROC(REMOVE, enc_remove, dec_remove),
4619 PROC(RENAME, enc_rename, dec_rename),
4620 PROC(LINK, enc_link, dec_link),
4621 PROC(SYMLINK, enc_symlink, dec_symlink),
4622 PROC(CREATE, enc_create, dec_create),
4623 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4624 PROC(STATFS, enc_statfs, dec_statfs),
4625 PROC(READLINK, enc_readlink, dec_readlink),
4626 PROC(READDIR, enc_readdir, dec_readdir),
4627 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4628 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4629 PROC(GETACL, enc_getacl, dec_getacl),
4630 PROC(SETACL, enc_setacl, dec_setacl),
4631 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4634 struct rpc_version nfs_version4 = {
4636 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4637 .procs = nfs4_procedures