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 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 4)
74 #define lock_owner_id_maxsz (1 + 4)
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 + nfs4_name_maxsz)
123 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
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 encode_fs_locations_maxsz \
165 (encode_getattr_maxsz)
166 #define decode_fs_locations_maxsz \
168 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
169 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
170 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
171 encode_putfh_maxsz + \
172 op_encode_hdr_maxsz + 7)
173 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
174 decode_putfh_maxsz + \
175 op_decode_hdr_maxsz + 2)
176 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
177 encode_putfh_maxsz + \
179 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
180 decode_putfh_maxsz + \
182 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
183 encode_putfh_maxsz + \
184 op_encode_hdr_maxsz + 9)
185 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
186 decode_putfh_maxsz + \
187 op_decode_hdr_maxsz + 2)
188 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
189 encode_putfh_maxsz + \
190 op_encode_hdr_maxsz + 8 + \
191 encode_getattr_maxsz)
192 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
193 decode_putfh_maxsz + \
194 op_decode_hdr_maxsz + 4 + \
195 decode_getattr_maxsz)
196 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
197 encode_putfh_maxsz + \
198 op_encode_hdr_maxsz + 3 + \
199 encode_getattr_maxsz)
200 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
201 decode_putfh_maxsz + \
202 op_decode_hdr_maxsz + 2 + \
203 decode_getattr_maxsz)
204 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
205 encode_putfh_maxsz + \
206 encode_savefh_maxsz + \
207 encode_open_maxsz + \
208 encode_getfh_maxsz + \
209 encode_getattr_maxsz + \
210 encode_restorefh_maxsz + \
211 encode_getattr_maxsz)
212 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
213 decode_putfh_maxsz + \
214 decode_savefh_maxsz + \
215 decode_open_maxsz + \
216 decode_getfh_maxsz + \
217 decode_getattr_maxsz + \
218 decode_restorefh_maxsz + \
219 decode_getattr_maxsz)
220 #define NFS4_enc_open_confirm_sz \
221 (compound_encode_hdr_maxsz + \
222 encode_putfh_maxsz + \
223 op_encode_hdr_maxsz + 5)
224 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
225 decode_putfh_maxsz + \
226 op_decode_hdr_maxsz + 4)
227 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
228 encode_putfh_maxsz + \
229 encode_open_maxsz + \
230 encode_getattr_maxsz)
231 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
232 decode_putfh_maxsz + \
233 decode_open_maxsz + \
234 decode_getattr_maxsz)
235 #define NFS4_enc_open_downgrade_sz \
236 (compound_encode_hdr_maxsz + \
237 encode_putfh_maxsz + \
238 op_encode_hdr_maxsz + 7 + \
239 encode_getattr_maxsz)
240 #define NFS4_dec_open_downgrade_sz \
241 (compound_decode_hdr_maxsz + \
242 decode_putfh_maxsz + \
243 op_decode_hdr_maxsz + 4 + \
244 decode_getattr_maxsz)
245 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
246 encode_putfh_maxsz + \
247 op_encode_hdr_maxsz + 5 + \
248 encode_getattr_maxsz)
249 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
250 decode_putfh_maxsz + \
251 op_decode_hdr_maxsz + 4 + \
252 decode_getattr_maxsz)
253 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
254 encode_putfh_maxsz + \
255 op_encode_hdr_maxsz + 4 + \
257 encode_getattr_maxsz)
258 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
259 decode_putfh_maxsz + \
260 op_decode_hdr_maxsz + 3 + \
262 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
263 encode_putfh_maxsz + \
265 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
266 decode_putfh_maxsz + \
268 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
270 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
272 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
273 encode_setclientid_maxsz)
274 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
275 decode_setclientid_maxsz)
276 #define NFS4_enc_setclientid_confirm_sz \
277 (compound_encode_hdr_maxsz + \
278 encode_setclientid_confirm_maxsz + \
279 encode_putrootfh_maxsz + \
281 #define NFS4_dec_setclientid_confirm_sz \
282 (compound_decode_hdr_maxsz + \
283 decode_setclientid_confirm_maxsz + \
284 decode_putrootfh_maxsz + \
286 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
287 encode_putfh_maxsz + \
288 encode_getattr_maxsz + \
289 op_encode_hdr_maxsz + \
293 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
294 decode_putfh_maxsz + \
295 decode_getattr_maxsz + \
296 op_decode_hdr_maxsz + \
299 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
300 encode_putfh_maxsz + \
301 encode_getattr_maxsz + \
302 op_encode_hdr_maxsz + \
305 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
306 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
307 encode_putfh_maxsz + \
308 encode_getattr_maxsz + \
309 op_encode_hdr_maxsz + \
311 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
312 decode_putfh_maxsz + \
313 decode_getattr_maxsz + \
314 op_decode_hdr_maxsz + 4)
315 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
316 encode_putfh_maxsz + \
317 op_encode_hdr_maxsz + 1)
318 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
319 decode_putfh_maxsz + \
320 op_decode_hdr_maxsz + 2)
321 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
322 encode_putfh_maxsz + \
323 encode_getattr_maxsz)
324 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
325 decode_putfh_maxsz + \
326 decode_getattr_maxsz)
327 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
328 encode_putfh_maxsz + \
329 encode_lookup_maxsz + \
330 encode_getattr_maxsz + \
332 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
333 decode_putfh_maxsz + \
334 decode_lookup_maxsz + \
335 decode_getattr_maxsz + \
337 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
338 encode_putrootfh_maxsz + \
339 encode_getattr_maxsz + \
341 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
342 decode_putrootfh_maxsz + \
343 decode_getattr_maxsz + \
345 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
346 encode_putfh_maxsz + \
347 encode_remove_maxsz + \
348 encode_getattr_maxsz)
349 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
350 decode_putfh_maxsz + \
351 op_decode_hdr_maxsz + 5 + \
352 decode_getattr_maxsz)
353 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
354 encode_putfh_maxsz + \
355 encode_savefh_maxsz + \
356 encode_putfh_maxsz + \
357 encode_rename_maxsz + \
358 encode_getattr_maxsz + \
359 encode_restorefh_maxsz + \
360 encode_getattr_maxsz)
361 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
362 decode_putfh_maxsz + \
363 decode_savefh_maxsz + \
364 decode_putfh_maxsz + \
365 decode_rename_maxsz + \
366 decode_getattr_maxsz + \
367 decode_restorefh_maxsz + \
368 decode_getattr_maxsz)
369 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
370 encode_putfh_maxsz + \
371 encode_savefh_maxsz + \
372 encode_putfh_maxsz + \
373 encode_link_maxsz + \
374 decode_getattr_maxsz + \
375 encode_restorefh_maxsz + \
376 decode_getattr_maxsz)
377 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
378 decode_putfh_maxsz + \
379 decode_savefh_maxsz + \
380 decode_putfh_maxsz + \
381 decode_link_maxsz + \
382 decode_getattr_maxsz + \
383 decode_restorefh_maxsz + \
384 decode_getattr_maxsz)
385 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
386 encode_putfh_maxsz + \
387 encode_symlink_maxsz + \
388 encode_getattr_maxsz + \
390 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
391 decode_putfh_maxsz + \
392 decode_symlink_maxsz + \
393 decode_getattr_maxsz + \
395 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
396 encode_putfh_maxsz + \
397 encode_savefh_maxsz + \
398 encode_create_maxsz + \
399 encode_getfh_maxsz + \
400 encode_getattr_maxsz + \
401 encode_restorefh_maxsz + \
402 encode_getattr_maxsz)
403 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
404 decode_putfh_maxsz + \
405 decode_savefh_maxsz + \
406 decode_create_maxsz + \
407 decode_getfh_maxsz + \
408 decode_getattr_maxsz + \
409 decode_restorefh_maxsz + \
410 decode_getattr_maxsz)
411 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
412 encode_putfh_maxsz + \
413 encode_getattr_maxsz)
414 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
415 decode_putfh_maxsz + \
416 decode_getattr_maxsz)
417 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
418 encode_putfh_maxsz + \
419 encode_getattr_maxsz)
420 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
421 decode_putfh_maxsz + \
422 op_decode_hdr_maxsz + 12)
423 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
424 encode_putfh_maxsz + \
425 encode_getattr_maxsz)
426 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
427 decode_putfh_maxsz + \
428 decode_getattr_maxsz)
429 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
430 encode_putfh_maxsz + \
431 encode_delegreturn_maxsz + \
432 encode_getattr_maxsz)
433 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
434 decode_delegreturn_maxsz + \
435 decode_getattr_maxsz)
436 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
437 encode_putfh_maxsz + \
438 encode_getattr_maxsz)
439 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
440 decode_putfh_maxsz + \
441 op_decode_hdr_maxsz + \
442 nfs4_fattr_bitmap_maxsz + 1)
443 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
444 encode_putfh_maxsz + \
445 op_encode_hdr_maxsz + 4 + \
446 nfs4_fattr_bitmap_maxsz + 1)
447 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
448 decode_putfh_maxsz + \
449 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
450 #define NFS4_enc_fs_locations_sz \
451 (compound_encode_hdr_maxsz + \
452 encode_putfh_maxsz + \
453 encode_lookup_maxsz + \
454 encode_fs_locations_maxsz)
455 #define NFS4_dec_fs_locations_sz \
456 (compound_decode_hdr_maxsz + \
457 decode_putfh_maxsz + \
458 decode_lookup_maxsz + \
459 decode_fs_locations_maxsz)
463 unsigned int nfs2type;
471 { S_IFSOCK, NFSOCK },
477 struct compound_hdr {
485 * START OF "GENERIC" ENCODE ROUTINES.
486 * These may look a little ugly since they are imported from a "generic"
487 * set of XDR encode/decode routines which are intended to be shared by
488 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
490 * If the pain of reading these is too great, it should be a straightforward
491 * task to translate them into Linux-specific versions which are more
492 * consistent with the style used in NFSv2/v3...
494 #define WRITE32(n) *p++ = htonl(n)
495 #define WRITE64(n) do { \
496 *p++ = htonl((uint32_t)((n) >> 32)); \
497 *p++ = htonl((uint32_t)(n)); \
499 #define WRITEMEM(ptr,nbytes) do { \
500 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
503 #define RESERVE_SPACE(nbytes) do { \
504 p = xdr_reserve_space(xdr, nbytes); \
505 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
509 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
513 p = xdr_reserve_space(xdr, 4 + len);
515 xdr_encode_opaque(p, str, len);
518 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
522 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
523 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
524 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
525 WRITE32(hdr->taglen);
526 WRITEMEM(hdr->tag, hdr->taglen);
527 WRITE32(NFS4_MINOR_VERSION);
532 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
536 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
538 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
541 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
543 char owner_name[IDMAP_NAMESZ];
544 char owner_group[IDMAP_NAMESZ];
545 int owner_namelen = 0;
546 int owner_grouplen = 0;
555 * We reserve enough space to write the entire attribute buffer at once.
556 * In the worst-case, this would be
557 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
558 * = 36 bytes, plus any contribution from variable-length fields
559 * such as owner/group.
564 if (iap->ia_valid & ATTR_SIZE)
566 if (iap->ia_valid & ATTR_MODE)
568 if (iap->ia_valid & ATTR_UID) {
569 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
570 if (owner_namelen < 0) {
571 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
574 strcpy(owner_name, "nobody");
575 owner_namelen = sizeof("nobody") - 1;
578 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
580 if (iap->ia_valid & ATTR_GID) {
581 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
582 if (owner_grouplen < 0) {
583 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
585 strcpy(owner_group, "nobody");
586 owner_grouplen = sizeof("nobody") - 1;
589 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
591 if (iap->ia_valid & ATTR_ATIME_SET)
593 else if (iap->ia_valid & ATTR_ATIME)
595 if (iap->ia_valid & ATTR_MTIME_SET)
597 else if (iap->ia_valid & ATTR_MTIME)
602 * We write the bitmap length now, but leave the bitmap and the attribute
603 * buffer length to be backfilled at the end of this routine.
609 if (iap->ia_valid & ATTR_SIZE) {
610 bmval0 |= FATTR4_WORD0_SIZE;
611 WRITE64(iap->ia_size);
613 if (iap->ia_valid & ATTR_MODE) {
614 bmval1 |= FATTR4_WORD1_MODE;
615 WRITE32(iap->ia_mode & S_IALLUGO);
617 if (iap->ia_valid & ATTR_UID) {
618 bmval1 |= FATTR4_WORD1_OWNER;
619 WRITE32(owner_namelen);
620 WRITEMEM(owner_name, owner_namelen);
622 if (iap->ia_valid & ATTR_GID) {
623 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
624 WRITE32(owner_grouplen);
625 WRITEMEM(owner_group, owner_grouplen);
627 if (iap->ia_valid & ATTR_ATIME_SET) {
628 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
629 WRITE32(NFS4_SET_TO_CLIENT_TIME);
631 WRITE32(iap->ia_mtime.tv_sec);
632 WRITE32(iap->ia_mtime.tv_nsec);
634 else if (iap->ia_valid & ATTR_ATIME) {
635 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
636 WRITE32(NFS4_SET_TO_SERVER_TIME);
638 if (iap->ia_valid & ATTR_MTIME_SET) {
639 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
640 WRITE32(NFS4_SET_TO_CLIENT_TIME);
642 WRITE32(iap->ia_mtime.tv_sec);
643 WRITE32(iap->ia_mtime.tv_nsec);
645 else if (iap->ia_valid & ATTR_MTIME) {
646 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
647 WRITE32(NFS4_SET_TO_SERVER_TIME);
651 * Now we backfill the bitmap and the attribute buffer length.
653 if (len != ((char *)p - (char *)q) + 4) {
654 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
655 len, ((char *)p - (char *)q) + 4);
658 len = (char *)p - (char *)q - 12;
659 *q++ = htonl(bmval0);
660 *q++ = htonl(bmval1);
668 static int encode_access(struct xdr_stream *xdr, u32 access)
679 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
683 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
685 WRITE32(arg->seqid->sequence->counter);
686 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
691 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
697 WRITE64(args->offset);
698 WRITE32(args->count);
703 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
709 WRITE32(create->ftype);
711 switch (create->ftype) {
714 WRITE32(create->u.symlink.len);
715 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
718 case NF4BLK: case NF4CHR:
720 WRITE32(create->u.device.specdata1);
721 WRITE32(create->u.device.specdata2);
728 RESERVE_SPACE(4 + create->name->len);
729 WRITE32(create->name->len);
730 WRITEMEM(create->name->name, create->name->len);
732 return encode_attrs(xdr, create->attrs, create->server);
735 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
746 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
758 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
760 return encode_getattr_two(xdr,
761 bitmask[0] & nfs4_fattr_bitmap[0],
762 bitmask[1] & nfs4_fattr_bitmap[1]);
765 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
767 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
768 bitmask[1] & nfs4_fsinfo_bitmap[1]);
771 static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
773 return encode_getattr_two(xdr,
774 bitmask[0] & nfs4_fs_locations_bitmap[0],
775 bitmask[1] & nfs4_fs_locations_bitmap[1]);
778 static int encode_getfh(struct xdr_stream *xdr)
788 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
792 RESERVE_SPACE(8 + name->len);
795 WRITEMEM(name->name, name->len);
800 static inline int nfs4_lock_type(struct file_lock *fl, int block)
802 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
803 return block ? NFS4_READW_LT : NFS4_READ_LT;
804 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
807 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
809 if (fl->fl_end == OFFSET_MAX)
811 return fl->fl_end - fl->fl_start + 1;
815 * opcode,type,reclaim,offset,length,new_lock_owner = 32
816 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
818 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
824 WRITE32(nfs4_lock_type(args->fl, args->block));
825 WRITE32(args->reclaim);
826 WRITE64(args->fl->fl_start);
827 WRITE64(nfs4_lock_length(args->fl));
828 WRITE32(args->new_lock_owner);
829 if (args->new_lock_owner){
830 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
831 WRITE32(args->open_seqid->sequence->counter);
832 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
833 WRITE32(args->lock_seqid->sequence->counter);
834 WRITE64(args->lock_owner.clientid);
836 WRITEMEM("lock id:", 8);
837 WRITE64(args->lock_owner.id);
840 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
841 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
842 WRITE32(args->lock_seqid->sequence->counter);
848 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
854 WRITE32(nfs4_lock_type(args->fl, 0));
855 WRITE64(args->fl->fl_start);
856 WRITE64(nfs4_lock_length(args->fl));
857 WRITE64(args->lock_owner.clientid);
859 WRITEMEM("lock id:", 8);
860 WRITE64(args->lock_owner.id);
865 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
869 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
871 WRITE32(nfs4_lock_type(args->fl, 0));
872 WRITE32(args->seqid->sequence->counter);
873 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
874 WRITE64(args->fl->fl_start);
875 WRITE64(nfs4_lock_length(args->fl));
880 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
885 RESERVE_SPACE(8 + len);
888 WRITEMEM(name->name, len);
893 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
898 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
900 WRITE32(NFS4_SHARE_ACCESS_READ);
903 WRITE32(NFS4_SHARE_ACCESS_WRITE);
905 case FMODE_READ|FMODE_WRITE:
906 WRITE32(NFS4_SHARE_ACCESS_BOTH);
911 WRITE32(0); /* for linux, share_deny = 0 always */
914 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
918 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
923 WRITE32(arg->seqid->sequence->counter);
924 encode_share_access(xdr, arg->open_flags);
926 WRITE64(arg->clientid);
928 WRITEMEM("open id:", 8);
932 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
937 switch(arg->open_flags & O_EXCL) {
939 WRITE32(NFS4_CREATE_UNCHECKED);
940 encode_attrs(xdr, arg->u.attrs, arg->server);
943 WRITE32(NFS4_CREATE_EXCLUSIVE);
944 encode_nfs4_verifier(xdr, &arg->u.verifier);
948 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
953 switch (arg->open_flags & O_CREAT) {
955 WRITE32(NFS4_OPEN_NOCREATE);
958 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
959 WRITE32(NFS4_OPEN_CREATE);
960 encode_createmode(xdr, arg);
964 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
969 switch (delegation_type) {
971 WRITE32(NFS4_OPEN_DELEGATE_NONE);
974 WRITE32(NFS4_OPEN_DELEGATE_READ);
976 case FMODE_WRITE|FMODE_READ:
977 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
984 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
989 WRITE32(NFS4_OPEN_CLAIM_NULL);
990 encode_string(xdr, name->len, name->name);
993 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
998 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
999 encode_delegation_type(xdr, type);
1002 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1006 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1007 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1008 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1009 encode_string(xdr, name->len, name->name);
1012 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1014 encode_openhdr(xdr, arg);
1015 encode_opentype(xdr, arg);
1016 switch (arg->claim) {
1017 case NFS4_OPEN_CLAIM_NULL:
1018 encode_claim_null(xdr, arg->name);
1020 case NFS4_OPEN_CLAIM_PREVIOUS:
1021 encode_claim_previous(xdr, arg->u.delegation_type);
1023 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1024 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1032 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
1036 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1037 WRITE32(OP_OPEN_CONFIRM);
1038 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1039 WRITE32(arg->seqid->sequence->counter);
1044 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1048 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1049 WRITE32(OP_OPEN_DOWNGRADE);
1050 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1051 WRITE32(arg->seqid->sequence->counter);
1052 encode_share_access(xdr, arg->open_flags);
1057 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1062 RESERVE_SPACE(8 + len);
1065 WRITEMEM(fh->data, len);
1070 static int encode_putrootfh(struct xdr_stream *xdr)
1075 WRITE32(OP_PUTROOTFH);
1080 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1082 nfs4_stateid stateid;
1085 RESERVE_SPACE(NFS4_STATEID_SIZE);
1086 if (ctx->state != NULL) {
1087 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1088 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1090 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1093 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1100 encode_stateid(xdr, args->context);
1103 WRITE64(args->offset);
1104 WRITE32(args->count);
1109 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1111 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1112 uint32_t attrs[2] = {
1113 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1114 FATTR4_WORD1_MOUNTED_ON_FILEID,
1119 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1120 WRITE32(OP_READDIR);
1121 WRITE64(readdir->cookie);
1122 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1123 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1124 WRITE32(readdir->count);
1126 /* Switch to mounted_on_fileid if the server supports it */
1127 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1128 attrs[0] &= ~FATTR4_WORD0_FILEID;
1130 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1131 WRITE32(attrs[0] & readdir->bitmask[0]);
1132 WRITE32(attrs[1] & readdir->bitmask[1]);
1133 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1135 (unsigned long long)readdir->cookie,
1136 ((u32 *)readdir->verifier.data)[0],
1137 ((u32 *)readdir->verifier.data)[1],
1138 attrs[0] & readdir->bitmask[0],
1139 attrs[1] & readdir->bitmask[1]);
1141 /* set up reply kvec
1142 * toplevel_status + taglen + rescount + OP_PUTFH + status
1143 * + OP_READDIR + status + verifer(2) = 9
1145 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1146 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1147 readdir->pgbase, readdir->count);
1148 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1149 __FUNCTION__, replen, readdir->pages,
1150 readdir->pgbase, readdir->count);
1155 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1157 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1158 unsigned int replen;
1162 WRITE32(OP_READLINK);
1164 /* set up reply kvec
1165 * toplevel_status + taglen + rescount + OP_PUTFH + status
1166 * + OP_READLINK + status + string length = 8
1168 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1169 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1170 readlink->pgbase, readlink->pglen);
1175 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1179 RESERVE_SPACE(8 + name->len);
1182 WRITEMEM(name->name, name->len);
1187 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1191 RESERVE_SPACE(8 + oldname->len);
1193 WRITE32(oldname->len);
1194 WRITEMEM(oldname->name, oldname->len);
1196 RESERVE_SPACE(4 + newname->len);
1197 WRITE32(newname->len);
1198 WRITEMEM(newname->name, newname->len);
1203 static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
1209 WRITE64(client_stateid->cl_clientid);
1215 encode_restorefh(struct xdr_stream *xdr)
1220 WRITE32(OP_RESTOREFH);
1226 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1230 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1231 WRITE32(OP_SETATTR);
1232 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1235 WRITE32(FATTR4_WORD0_ACL);
1236 if (arg->acl_len % 4)
1239 WRITE32(arg->acl_len);
1240 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1245 encode_savefh(struct xdr_stream *xdr)
1255 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1260 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1261 WRITE32(OP_SETATTR);
1262 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1264 if ((status = encode_attrs(xdr, arg->iap, server)))
1270 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1274 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1275 WRITE32(OP_SETCLIENTID);
1276 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1278 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1280 WRITE32(setclientid->sc_prog);
1281 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1282 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1284 WRITE32(setclientid->sc_cb_ident);
1289 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
1293 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1294 WRITE32(OP_SETCLIENTID_CONFIRM);
1295 WRITE64(client_state->cl_clientid);
1296 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1301 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1308 encode_stateid(xdr, args->context);
1311 WRITE64(args->offset);
1312 WRITE32(args->stable);
1313 WRITE32(args->count);
1315 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1320 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1324 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1326 WRITE32(OP_DELEGRETURN);
1327 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1332 * END OF "GENERIC" ENCODE ROUTINES.
1336 * Encode an ACCESS request
1338 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1340 struct xdr_stream xdr;
1341 struct compound_hdr hdr = {
1346 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1347 encode_compound_hdr(&xdr, &hdr);
1348 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1349 status = encode_access(&xdr, args->access);
1354 * Encode LOOKUP request
1356 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1358 struct xdr_stream xdr;
1359 struct compound_hdr hdr = {
1364 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1365 encode_compound_hdr(&xdr, &hdr);
1366 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1368 if ((status = encode_lookup(&xdr, args->name)) != 0)
1370 if ((status = encode_getfh(&xdr)) != 0)
1372 status = encode_getfattr(&xdr, args->bitmask);
1378 * Encode LOOKUP_ROOT request
1380 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1382 struct xdr_stream xdr;
1383 struct compound_hdr hdr = {
1388 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1389 encode_compound_hdr(&xdr, &hdr);
1390 if ((status = encode_putrootfh(&xdr)) != 0)
1392 if ((status = encode_getfh(&xdr)) == 0)
1393 status = encode_getfattr(&xdr, args->bitmask);
1399 * Encode REMOVE request
1401 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs4_remove_arg *args)
1403 struct xdr_stream xdr;
1404 struct compound_hdr hdr = {
1409 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1410 encode_compound_hdr(&xdr, &hdr);
1411 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1413 if ((status = encode_remove(&xdr, args->name)) != 0)
1415 status = encode_getfattr(&xdr, args->bitmask);
1421 * Encode RENAME request
1423 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1425 struct xdr_stream xdr;
1426 struct compound_hdr hdr = {
1431 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1432 encode_compound_hdr(&xdr, &hdr);
1433 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1435 if ((status = encode_savefh(&xdr)) != 0)
1437 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1439 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1441 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1443 if ((status = encode_restorefh(&xdr)) != 0)
1445 status = encode_getfattr(&xdr, args->bitmask);
1451 * Encode LINK request
1453 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1455 struct xdr_stream xdr;
1456 struct compound_hdr hdr = {
1461 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1462 encode_compound_hdr(&xdr, &hdr);
1463 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1465 if ((status = encode_savefh(&xdr)) != 0)
1467 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1469 if ((status = encode_link(&xdr, args->name)) != 0)
1471 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1473 if ((status = encode_restorefh(&xdr)) != 0)
1475 status = encode_getfattr(&xdr, args->bitmask);
1481 * Encode CREATE request
1483 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1485 struct xdr_stream xdr;
1486 struct compound_hdr hdr = {
1491 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1492 encode_compound_hdr(&xdr, &hdr);
1493 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1495 if ((status = encode_savefh(&xdr)) != 0)
1497 if ((status = encode_create(&xdr, args)) != 0)
1499 if ((status = encode_getfh(&xdr)) != 0)
1501 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1503 if ((status = encode_restorefh(&xdr)) != 0)
1505 status = encode_getfattr(&xdr, args->bitmask);
1511 * Encode SYMLINK request
1513 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1515 return nfs4_xdr_enc_create(req, p, args);
1519 * Encode GETATTR request
1521 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1523 struct xdr_stream xdr;
1524 struct compound_hdr hdr = {
1529 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1530 encode_compound_hdr(&xdr, &hdr);
1531 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1532 status = encode_getfattr(&xdr, args->bitmask);
1537 * Encode a CLOSE request
1539 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1541 struct xdr_stream xdr;
1542 struct compound_hdr hdr = {
1547 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1548 encode_compound_hdr(&xdr, &hdr);
1549 status = encode_putfh(&xdr, args->fh);
1552 status = encode_close(&xdr, args);
1555 status = encode_getfattr(&xdr, args->bitmask);
1561 * Encode an OPEN request
1563 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1565 struct xdr_stream xdr;
1566 struct compound_hdr hdr = {
1571 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1572 encode_compound_hdr(&xdr, &hdr);
1573 status = encode_putfh(&xdr, args->fh);
1576 status = encode_savefh(&xdr);
1579 status = encode_open(&xdr, args);
1582 status = encode_getfh(&xdr);
1585 status = encode_getfattr(&xdr, args->bitmask);
1588 status = encode_restorefh(&xdr);
1591 status = encode_getfattr(&xdr, args->bitmask);
1597 * Encode an OPEN_CONFIRM request
1599 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1601 struct xdr_stream xdr;
1602 struct compound_hdr hdr = {
1607 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1608 encode_compound_hdr(&xdr, &hdr);
1609 status = encode_putfh(&xdr, args->fh);
1612 status = encode_open_confirm(&xdr, args);
1618 * Encode an OPEN request with no attributes.
1620 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1622 struct xdr_stream xdr;
1623 struct compound_hdr hdr = {
1628 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1629 encode_compound_hdr(&xdr, &hdr);
1630 status = encode_putfh(&xdr, args->fh);
1633 status = encode_open(&xdr, args);
1636 status = encode_getfattr(&xdr, args->bitmask);
1642 * Encode an OPEN_DOWNGRADE request
1644 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1646 struct xdr_stream xdr;
1647 struct compound_hdr hdr = {
1652 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1653 encode_compound_hdr(&xdr, &hdr);
1654 status = encode_putfh(&xdr, args->fh);
1657 status = encode_open_downgrade(&xdr, args);
1660 status = encode_getfattr(&xdr, args->bitmask);
1666 * Encode a LOCK request
1668 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1670 struct xdr_stream xdr;
1671 struct compound_hdr hdr = {
1676 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1677 encode_compound_hdr(&xdr, &hdr);
1678 status = encode_putfh(&xdr, args->fh);
1681 status = encode_lock(&xdr, args);
1687 * Encode a LOCKT request
1689 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1691 struct xdr_stream xdr;
1692 struct compound_hdr hdr = {
1697 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1698 encode_compound_hdr(&xdr, &hdr);
1699 status = encode_putfh(&xdr, args->fh);
1702 status = encode_lockt(&xdr, args);
1708 * Encode a LOCKU request
1710 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1712 struct xdr_stream xdr;
1713 struct compound_hdr hdr = {
1718 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1719 encode_compound_hdr(&xdr, &hdr);
1720 status = encode_putfh(&xdr, args->fh);
1723 status = encode_locku(&xdr, args);
1729 * Encode a READLINK request
1731 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1733 struct xdr_stream xdr;
1734 struct compound_hdr hdr = {
1739 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1740 encode_compound_hdr(&xdr, &hdr);
1741 status = encode_putfh(&xdr, args->fh);
1744 status = encode_readlink(&xdr, args, req);
1750 * Encode a READDIR request
1752 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1754 struct xdr_stream xdr;
1755 struct compound_hdr hdr = {
1760 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1761 encode_compound_hdr(&xdr, &hdr);
1762 status = encode_putfh(&xdr, args->fh);
1765 status = encode_readdir(&xdr, args, req);
1771 * Encode a READ request
1773 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1775 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1776 struct xdr_stream xdr;
1777 struct compound_hdr hdr = {
1782 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1783 encode_compound_hdr(&xdr, &hdr);
1784 status = encode_putfh(&xdr, args->fh);
1787 status = encode_read(&xdr, args);
1791 /* set up reply kvec
1792 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1793 * + OP_READ + status + eof + datalen = 9
1795 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1796 xdr_inline_pages(&req->rq_rcv_buf, replen,
1797 args->pages, args->pgbase, args->count);
1803 * Encode an SETATTR request
1805 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1808 struct xdr_stream xdr;
1809 struct compound_hdr hdr = {
1814 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1815 encode_compound_hdr(&xdr, &hdr);
1816 status = encode_putfh(&xdr, args->fh);
1819 status = encode_setattr(&xdr, args, args->server);
1822 status = encode_getfattr(&xdr, args->bitmask);
1828 * Encode a GETACL request
1831 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1832 struct nfs_getaclargs *args)
1834 struct xdr_stream xdr;
1835 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1836 struct compound_hdr hdr = {
1841 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1842 encode_compound_hdr(&xdr, &hdr);
1843 status = encode_putfh(&xdr, args->fh);
1846 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1847 /* set up reply buffer: */
1848 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1849 xdr_inline_pages(&req->rq_rcv_buf, replen,
1850 args->acl_pages, args->acl_pgbase, args->acl_len);
1856 * Encode a WRITE request
1858 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1860 struct xdr_stream xdr;
1861 struct compound_hdr hdr = {
1866 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1867 encode_compound_hdr(&xdr, &hdr);
1868 status = encode_putfh(&xdr, args->fh);
1871 status = encode_write(&xdr, args);
1874 status = encode_getfattr(&xdr, args->bitmask);
1882 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1884 struct xdr_stream xdr;
1885 struct compound_hdr hdr = {
1890 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1891 encode_compound_hdr(&xdr, &hdr);
1892 status = encode_putfh(&xdr, args->fh);
1895 status = encode_commit(&xdr, args);
1898 status = encode_getfattr(&xdr, args->bitmask);
1906 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1908 struct xdr_stream xdr;
1909 struct compound_hdr hdr = {
1914 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1915 encode_compound_hdr(&xdr, &hdr);
1916 status = encode_putfh(&xdr, args->fh);
1918 status = encode_fsinfo(&xdr, args->bitmask);
1923 * a PATHCONF request
1925 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1927 struct xdr_stream xdr;
1928 struct compound_hdr hdr = {
1933 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1934 encode_compound_hdr(&xdr, &hdr);
1935 status = encode_putfh(&xdr, args->fh);
1937 status = encode_getattr_one(&xdr,
1938 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1945 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
1947 struct xdr_stream xdr;
1948 struct compound_hdr hdr = {
1953 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1954 encode_compound_hdr(&xdr, &hdr);
1955 status = encode_putfh(&xdr, args->fh);
1957 status = encode_getattr_two(&xdr,
1958 args->bitmask[0] & nfs4_statfs_bitmap[0],
1959 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1964 * GETATTR_BITMAP request
1966 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
1968 struct xdr_stream xdr;
1969 struct compound_hdr hdr = {
1974 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1975 encode_compound_hdr(&xdr, &hdr);
1976 status = encode_putfh(&xdr, fhandle);
1978 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1979 FATTR4_WORD0_LINK_SUPPORT|
1980 FATTR4_WORD0_SYMLINK_SUPPORT|
1981 FATTR4_WORD0_ACLSUPPORT);
1988 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1990 struct xdr_stream xdr;
1991 struct compound_hdr hdr = {
1995 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1996 encode_compound_hdr(&xdr, &hdr);
1997 return encode_renew(&xdr, clp);
2001 * a SETCLIENTID request
2003 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
2005 struct xdr_stream xdr;
2006 struct compound_hdr hdr = {
2010 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2011 encode_compound_hdr(&xdr, &hdr);
2012 return encode_setclientid(&xdr, sc);
2016 * a SETCLIENTID_CONFIRM request
2018 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2020 struct xdr_stream xdr;
2021 struct compound_hdr hdr = {
2024 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2027 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2028 encode_compound_hdr(&xdr, &hdr);
2029 status = encode_setclientid_confirm(&xdr, clp);
2031 status = encode_putrootfh(&xdr);
2033 status = encode_fsinfo(&xdr, lease_bitmap);
2038 * DELEGRETURN request
2040 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2042 struct xdr_stream xdr;
2043 struct compound_hdr hdr = {
2048 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2049 encode_compound_hdr(&xdr, &hdr);
2050 status = encode_putfh(&xdr, args->fhandle);
2053 status = encode_delegreturn(&xdr, args->stateid);
2056 status = encode_getfattr(&xdr, args->bitmask);
2062 * Encode FS_LOCATIONS request
2064 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2066 struct xdr_stream xdr;
2067 struct compound_hdr hdr = {
2070 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
2074 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2075 encode_compound_hdr(&xdr, &hdr);
2076 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2078 if ((status = encode_lookup(&xdr, args->name)) != 0)
2080 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
2083 * toplevel_status + OP_PUTFH + status
2084 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2086 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2087 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2094 * START OF "GENERIC" DECODE ROUTINES.
2095 * These may look a little ugly since they are imported from a "generic"
2096 * set of XDR encode/decode routines which are intended to be shared by
2097 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2099 * If the pain of reading these is too great, it should be a straightforward
2100 * task to translate them into Linux-specific versions which are more
2101 * consistent with the style used in NFSv2/v3...
2103 #define READ32(x) (x) = ntohl(*p++)
2104 #define READ64(x) do { \
2105 (x) = (u64)ntohl(*p++) << 32; \
2106 (x) |= ntohl(*p++); \
2108 #define READTIME(x) do { \
2110 (x.tv_sec) = ntohl(*p++); \
2111 (x.tv_nsec) = ntohl(*p++); \
2113 #define COPYMEM(x,nbytes) do { \
2114 memcpy((x), p, nbytes); \
2115 p += XDR_QUADLEN(nbytes); \
2118 #define READ_BUF(nbytes) do { \
2119 p = xdr_inline_decode(xdr, nbytes); \
2120 if (unlikely(!p)) { \
2121 printk(KERN_INFO "%s: prematurely hit end of receive" \
2122 " buffer\n", __FUNCTION__); \
2123 printk(KERN_INFO "%s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2124 __FUNCTION__, xdr->p, nbytes, xdr->end); \
2129 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2136 *string = (char *)p;
2140 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2145 READ32(hdr->status);
2146 READ32(hdr->taglen);
2148 READ_BUF(hdr->taglen + 4);
2149 hdr->tag = (char *)p;
2150 p += XDR_QUADLEN(hdr->taglen);
2155 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2163 if (opnum != expected) {
2165 "nfs4_decode_op_hdr: Server returned operation"
2166 " %d but we issued a request for %d\n",
2171 if (nfserr != NFS_OK)
2172 return -nfs4_stat_to_errno(nfserr);
2177 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2180 unsigned int strlen;
2184 return decode_opaque_inline(xdr, &strlen, &str);
2187 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2195 bitmap[0] = bitmap[1] = 0;
2196 READ_BUF((bmlen << 2));
2205 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2215 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2217 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2218 decode_attr_bitmap(xdr, bitmask);
2219 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2221 bitmask[0] = bitmask[1] = 0;
2222 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2226 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2231 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2233 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2236 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2237 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2240 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2242 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2246 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2251 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2253 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2256 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2258 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2259 (unsigned long long)*change);
2263 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2268 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2270 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2273 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2275 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2279 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2284 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2286 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2289 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2291 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2295 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2300 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2302 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2305 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2307 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2311 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2317 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2319 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2321 READ64(fsid->major);
2322 READ64(fsid->minor);
2323 bitmap[0] &= ~FATTR4_WORD0_FSID;
2325 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2326 (unsigned long long)fsid->major,
2327 (unsigned long long)fsid->minor);
2331 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2336 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2338 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2341 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2343 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2347 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2351 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2352 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2354 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2357 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2359 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2363 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2368 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2370 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2373 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2375 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2379 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2384 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2386 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2389 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2391 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2395 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2401 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2403 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2406 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2408 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2412 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2418 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2420 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2423 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2425 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2429 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2435 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2437 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2440 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2442 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2446 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2459 path->ncomponents = 0;
2460 while (path->ncomponents < n) {
2461 struct nfs4_string *component = &path->components[path->ncomponents];
2462 status = decode_opaque_inline(xdr, &component->len, &component->data);
2463 if (unlikely(status != 0))
2465 if (path->ncomponents != n)
2467 dprintk("%s", component->data);
2468 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2469 path->ncomponents++;
2471 dprintk("cannot parse %d components in path\n", n);
2479 /* a root pathname is sent as a zero component4 */
2480 path->ncomponents = 1;
2481 path->components[0].len=0;
2482 path->components[0].data=NULL;
2483 dprintk("path /\n");
2486 dprintk(" status %d", status);
2491 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2497 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2500 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2502 dprintk("%s: fsroot ", __FUNCTION__);
2503 status = decode_pathname(xdr, &res->fs_path);
2504 if (unlikely(status != 0))
2510 res->nlocations = 0;
2511 while (res->nlocations < n) {
2513 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2521 dprintk("%s: servers ", __FUNCTION__);
2522 while (loc->nservers < m) {
2523 struct nfs4_string *server = &loc->servers[loc->nservers];
2524 status = decode_opaque_inline(xdr, &server->len, &server->data);
2525 if (unlikely(status != 0))
2527 dprintk("%s ", server->data);
2528 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2532 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2533 for (i = loc->nservers; i < m; i++) {
2536 status = decode_opaque_inline(xdr, &len, &data);
2537 if (unlikely(status != 0))
2542 status = decode_pathname(xdr, &loc->rootpath);
2543 if (unlikely(status != 0))
2545 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2549 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2556 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2562 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2564 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2567 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2569 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2573 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2579 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2581 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2584 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2586 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2590 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2596 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2598 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2601 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2603 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2607 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2613 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2615 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2619 if (maxread > 0x7FFFFFFF)
2620 maxread = 0x7FFFFFFF;
2621 *res = (uint32_t)maxread;
2622 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2624 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2628 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2634 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2636 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2640 if (maxwrite > 0x7FFFFFFF)
2641 maxwrite = 0x7FFFFFFF;
2642 *res = (uint32_t)maxwrite;
2643 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2645 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2649 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2654 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2656 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2660 bitmap[1] &= ~FATTR4_WORD1_MODE;
2662 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2666 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2671 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2673 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2676 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2678 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2682 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2688 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2690 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2694 if (len < XDR_MAX_NETOBJ) {
2695 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2696 dprintk("%s: nfs_map_name_to_uid failed!\n",
2699 printk(KERN_WARNING "%s: name too long (%u)!\n",
2701 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2703 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2707 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2713 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2715 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2719 if (len < XDR_MAX_NETOBJ) {
2720 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2721 dprintk("%s: nfs_map_group_to_gid failed!\n",
2724 printk(KERN_WARNING "%s: name too long (%u)!\n",
2726 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2728 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2732 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2734 uint32_t major = 0, minor = 0;
2738 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2740 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2746 tmp = MKDEV(major, minor);
2747 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2749 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2751 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2755 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2761 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2763 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2766 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2768 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2772 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2778 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2780 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2783 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2785 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2789 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2795 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2797 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2800 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2802 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2806 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2811 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2813 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2816 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2818 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2819 (unsigned long long)*used);
2823 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2832 time->tv_sec = (time_t)sec;
2833 time->tv_nsec = (long)nsec;
2837 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2843 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2845 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2846 status = decode_attr_time(xdr, time);
2847 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2849 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2853 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2859 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2861 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2862 status = decode_attr_time(xdr, time);
2863 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2865 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2869 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2875 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2877 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2878 status = decode_attr_time(xdr, time);
2879 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2881 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2885 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2887 unsigned int attrwords = XDR_QUADLEN(attrlen);
2888 unsigned int nwords = xdr->p - savep;
2890 if (unlikely(attrwords != nwords)) {
2891 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2894 (attrwords < nwords) ? '<' : '>',
2901 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2906 READ32(cinfo->atomic);
2907 READ64(cinfo->before);
2908 READ64(cinfo->after);
2912 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2918 status = decode_op_hdr(xdr, OP_ACCESS);
2924 access->supported = supp;
2925 access->access = acc;
2929 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2934 status = decode_op_hdr(xdr, OP_CLOSE);
2937 READ_BUF(NFS4_STATEID_SIZE);
2938 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
2942 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2947 status = decode_op_hdr(xdr, OP_COMMIT);
2951 COPYMEM(res->verf->verifier, 8);
2955 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2961 status = decode_op_hdr(xdr, OP_CREATE);
2964 if ((status = decode_change_info(xdr, cinfo)))
2968 READ_BUF(bmlen << 2);
2972 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2979 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2981 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2983 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2985 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2987 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2989 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2991 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2993 status = verify_attr_len(xdr, savep, attrlen);
2995 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2999 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3006 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3008 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3010 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3013 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3015 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3017 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3019 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3021 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3023 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3026 status = verify_attr_len(xdr, savep, attrlen);
3028 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3032 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3039 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3041 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3043 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3046 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3048 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3051 status = verify_attr_len(xdr, savep, attrlen);
3053 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3057 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3063 int status, fmode = 0;
3066 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3068 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3071 fattr->bitmap[0] = bitmap[0];
3072 fattr->bitmap[1] = bitmap[1];
3074 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3078 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3080 fattr->type = nfs_type2fmt[type].nfs2type;
3081 fmode = nfs_type2fmt[type].mode;
3083 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3085 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3087 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
3089 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3091 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3092 struct nfs4_fs_locations,
3095 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3097 fattr->mode |= fmode;
3098 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3100 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
3102 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
3104 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3106 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3108 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3110 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3112 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3114 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3116 if (fattr->fileid == 0 && fileid != 0)
3117 fattr->fileid = fileid;
3118 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
3119 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
3121 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
3126 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3129 uint32_t attrlen, bitmap[2];
3132 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3134 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3136 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3139 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3141 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3143 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3145 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3147 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3148 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3150 fsinfo->wtpref = fsinfo->wtmax;
3152 status = verify_attr_len(xdr, savep, attrlen);
3154 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3158 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3164 status = decode_op_hdr(xdr, OP_GETFH);
3167 /* Zero handle first to allow comparisons */
3168 memset(fh, 0, sizeof(*fh));
3172 if (len > NFS4_FHSIZE)
3176 COPYMEM(fh->data, len);
3180 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3184 status = decode_op_hdr(xdr, OP_LINK);
3187 return decode_change_info(xdr, cinfo);
3191 * We create the owner, so we know a proper owner.id length is 4.
3193 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3195 uint64_t offset, length, clientid;
3197 uint32_t namelen, type;
3204 fl->fl_start = (loff_t)offset;
3205 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3206 if (length == ~(uint64_t)0)
3207 fl->fl_end = OFFSET_MAX;
3208 fl->fl_type = F_WRLCK;
3210 fl->fl_type = F_RDLCK;
3216 return -NFS4ERR_DENIED;
3219 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3224 status = decode_op_hdr(xdr, OP_LOCK);
3226 READ_BUF(NFS4_STATEID_SIZE);
3227 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3228 } else if (status == -NFS4ERR_DENIED)
3229 return decode_lock_denied(xdr, NULL);
3233 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3236 status = decode_op_hdr(xdr, OP_LOCKT);
3237 if (status == -NFS4ERR_DENIED)
3238 return decode_lock_denied(xdr, res->denied);
3242 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3247 status = decode_op_hdr(xdr, OP_LOCKU);
3249 READ_BUF(NFS4_STATEID_SIZE);
3250 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3255 static int decode_lookup(struct xdr_stream *xdr)
3257 return decode_op_hdr(xdr, OP_LOOKUP);
3260 /* This is too sick! */
3261 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3264 uint32_t limit_type, nblocks, blocksize;
3268 switch (limit_type) {
3275 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3280 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3283 uint32_t delegation_type;
3286 READ32(delegation_type);
3287 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3288 res->delegation_type = 0;
3291 READ_BUF(NFS4_STATEID_SIZE+4);
3292 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3293 READ32(res->do_recall);
3294 switch (delegation_type) {
3295 case NFS4_OPEN_DELEGATE_READ:
3296 res->delegation_type = FMODE_READ;
3298 case NFS4_OPEN_DELEGATE_WRITE:
3299 res->delegation_type = FMODE_WRITE|FMODE_READ;
3300 if (decode_space_limit(xdr, &res->maxsize) < 0)
3303 return decode_ace(xdr, NULL, res->server->nfs_client);
3306 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3309 uint32_t savewords, bmlen, i;
3312 status = decode_op_hdr(xdr, OP_OPEN);
3315 READ_BUF(NFS4_STATEID_SIZE);
3316 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3318 decode_change_info(xdr, &res->cinfo);
3321 READ32(res->rflags);
3326 READ_BUF(bmlen << 2);
3327 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3328 for (i = 0; i < savewords; ++i)
3329 READ32(res->attrset[i]);
3330 for (; i < NFS4_BITMAP_SIZE; i++)
3331 res->attrset[i] = 0;
3333 return decode_delegation(xdr, res);
3335 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
3339 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3344 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3347 READ_BUF(NFS4_STATEID_SIZE);
3348 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3352 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3357 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3360 READ_BUF(NFS4_STATEID_SIZE);
3361 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3365 static int decode_putfh(struct xdr_stream *xdr)
3367 return decode_op_hdr(xdr, OP_PUTFH);
3370 static int decode_putrootfh(struct xdr_stream *xdr)
3372 return decode_op_hdr(xdr, OP_PUTROOTFH);
3375 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3377 struct kvec *iov = req->rq_rcv_buf.head;
3379 uint32_t count, eof, recvd, hdrlen;
3382 status = decode_op_hdr(xdr, OP_READ);
3388 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3389 recvd = req->rq_rcv_buf.len - hdrlen;
3390 if (count > recvd) {
3391 printk(KERN_WARNING "NFS: server cheating in read reply: "
3392 "count %u > recvd %u\n", count, recvd);
3396 xdr_read_pages(xdr, count);
3402 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3404 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3405 struct page *page = *rcvbuf->pages;
3406 struct kvec *iov = rcvbuf->head;
3407 unsigned int nr, pglen = rcvbuf->page_len;
3408 __be32 *end, *entry, *p, *kaddr;
3409 uint32_t len, attrlen, xlen;
3410 int hdrlen, recvd, status;
3412 status = decode_op_hdr(xdr, OP_READDIR);
3416 COPYMEM(readdir->verifier.data, 8);
3417 dprintk("%s: verifier = 0x%x%x\n",
3419 ((u32 *)readdir->verifier.data)[0],
3420 ((u32 *)readdir->verifier.data)[1]);
3423 hdrlen = (char *) p - (char *) iov->iov_base;
3424 recvd = rcvbuf->len - hdrlen;
3427 xdr_read_pages(xdr, pglen);
3429 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3430 kaddr = p = kmap_atomic(page, KM_USER0);
3431 end = p + ((pglen + readdir->pgbase) >> 2);
3433 for (nr = 0; *p++; nr++) {
3436 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3437 p += 2; /* cookie */
3438 len = ntohl(*p++); /* filename length */
3439 if (len > NFS4_MAXNAMLEN) {
3440 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3443 xlen = XDR_QUADLEN(len);
3444 if (end - p < xlen + 1)
3446 dprintk("filename = %*s\n", len, (char *)p);
3448 len = ntohl(*p++); /* bitmap length */
3449 if (end - p < len + 1)
3452 attrlen = XDR_QUADLEN(ntohl(*p++));
3453 if (end - p < attrlen + 2)
3455 p += attrlen; /* attributes */
3458 if (!nr && (entry[0] != 0 || entry[1] == 0))
3461 kunmap_atomic(kaddr, KM_USER0);
3464 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3465 entry[0] = entry[1] = 0;
3466 /* truncate listing ? */
3468 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3473 kunmap_atomic(kaddr, KM_USER0);
3474 return -errno_NFSERR_IO;
3477 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3479 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3480 struct kvec *iov = rcvbuf->head;
3481 int hdrlen, len, recvd;
3486 status = decode_op_hdr(xdr, OP_READLINK);
3490 /* Convert length of symlink */
3493 if (len >= rcvbuf->page_len || len <= 0) {
3494 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3495 return -ENAMETOOLONG;
3497 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3498 recvd = req->rq_rcv_buf.len - hdrlen;
3500 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3501 "count %u > recvd %u\n", len, recvd);
3504 xdr_read_pages(xdr, len);
3506 * The XDR encode routine has set things up so that
3507 * the link text will be copied directly into the
3508 * buffer. We just have to do overflow-checking,
3509 * and and null-terminate the text (the VFS expects
3510 * null-termination).
3512 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3513 kaddr[len+rcvbuf->page_base] = '\0';
3514 kunmap_atomic(kaddr, KM_USER0);
3518 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3522 status = decode_op_hdr(xdr, OP_REMOVE);
3525 status = decode_change_info(xdr, cinfo);
3530 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3531 struct nfs4_change_info *new_cinfo)
3535 status = decode_op_hdr(xdr, OP_RENAME);
3538 if ((status = decode_change_info(xdr, old_cinfo)))
3540 status = decode_change_info(xdr, new_cinfo);
3545 static int decode_renew(struct xdr_stream *xdr)
3547 return decode_op_hdr(xdr, OP_RENEW);
3551 decode_restorefh(struct xdr_stream *xdr)
3553 return decode_op_hdr(xdr, OP_RESTOREFH);
3556 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3562 struct kvec *iov = req->rq_rcv_buf.head;
3566 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3568 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3570 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3573 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3575 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3578 /* We ignore &savep and don't do consistency checks on
3579 * the attr length. Let userspace figure it out.... */
3580 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3581 recvd = req->rq_rcv_buf.len - hdrlen;
3582 if (attrlen > recvd) {
3583 printk(KERN_WARNING "NFS: server cheating in getattr"
3584 " acl reply: attrlen %u > recvd %u\n",
3588 xdr_read_pages(xdr, attrlen);
3591 status = -EOPNOTSUPP;
3598 decode_savefh(struct xdr_stream *xdr)
3600 return decode_op_hdr(xdr, OP_SAVEFH);
3603 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3610 status = decode_op_hdr(xdr, OP_SETATTR);
3615 READ_BUF(bmlen << 2);
3619 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3627 if (opnum != OP_SETCLIENTID) {
3629 "nfs4_decode_setclientid: Server returned operation"
3634 if (nfserr == NFS_OK) {
3635 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3636 READ64(clp->cl_clientid);
3637 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3638 } else if (nfserr == NFSERR_CLID_INUSE) {
3641 /* skip netid string */
3646 /* skip uaddr string */
3650 return -NFSERR_CLID_INUSE;
3652 return -nfs4_stat_to_errno(nfserr);
3657 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3659 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3662 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3667 status = decode_op_hdr(xdr, OP_WRITE);
3673 READ32(res->verf->committed);
3674 COPYMEM(res->verf->verifier, 8);
3678 static int decode_delegreturn(struct xdr_stream *xdr)
3680 return decode_op_hdr(xdr, OP_DELEGRETURN);
3684 * Decode OPEN_DOWNGRADE response
3686 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3688 struct xdr_stream xdr;
3689 struct compound_hdr hdr;
3692 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3693 status = decode_compound_hdr(&xdr, &hdr);
3696 status = decode_putfh(&xdr);
3699 status = decode_open_downgrade(&xdr, res);
3702 decode_getfattr(&xdr, res->fattr, res->server);
3708 * END OF "GENERIC" DECODE ROUTINES.
3712 * Decode ACCESS response
3714 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3716 struct xdr_stream xdr;
3717 struct compound_hdr hdr;
3720 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3721 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3723 if ((status = decode_putfh(&xdr)) == 0)
3724 status = decode_access(&xdr, res);
3730 * Decode LOOKUP response
3732 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3734 struct xdr_stream xdr;
3735 struct compound_hdr hdr;
3738 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3739 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3741 if ((status = decode_putfh(&xdr)) != 0)
3743 if ((status = decode_lookup(&xdr)) != 0)
3745 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3747 status = decode_getfattr(&xdr, res->fattr, res->server);
3753 * Decode LOOKUP_ROOT response
3755 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3757 struct xdr_stream xdr;
3758 struct compound_hdr hdr;
3761 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3762 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3764 if ((status = decode_putrootfh(&xdr)) != 0)
3766 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3767 status = decode_getfattr(&xdr, res->fattr, res->server);
3773 * Decode REMOVE response
3775 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_remove_res *res)
3777 struct xdr_stream xdr;
3778 struct compound_hdr hdr;
3781 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3782 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3784 if ((status = decode_putfh(&xdr)) != 0)
3786 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3788 decode_getfattr(&xdr, res->dir_attr, res->server);
3794 * Decode RENAME response
3796 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3798 struct xdr_stream xdr;
3799 struct compound_hdr hdr;
3802 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3803 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3805 if ((status = decode_putfh(&xdr)) != 0)
3807 if ((status = decode_savefh(&xdr)) != 0)
3809 if ((status = decode_putfh(&xdr)) != 0)
3811 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3813 /* Current FH is target directory */
3814 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3816 if ((status = decode_restorefh(&xdr)) != 0)
3818 decode_getfattr(&xdr, res->old_fattr, res->server);
3824 * Decode LINK response
3826 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3828 struct xdr_stream xdr;
3829 struct compound_hdr hdr;
3832 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3833 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3835 if ((status = decode_putfh(&xdr)) != 0)
3837 if ((status = decode_savefh(&xdr)) != 0)
3839 if ((status = decode_putfh(&xdr)) != 0)
3841 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3844 * Note order: OP_LINK leaves the directory as the current
3847 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3849 if ((status = decode_restorefh(&xdr)) != 0)
3851 decode_getfattr(&xdr, res->fattr, res->server);
3857 * Decode CREATE response
3859 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3861 struct xdr_stream xdr;
3862 struct compound_hdr hdr;
3865 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3866 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3868 if ((status = decode_putfh(&xdr)) != 0)
3870 if ((status = decode_savefh(&xdr)) != 0)
3872 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3874 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3876 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3878 if ((status = decode_restorefh(&xdr)) != 0)
3880 decode_getfattr(&xdr, res->dir_fattr, res->server);
3886 * Decode SYMLINK response
3888 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3890 return nfs4_xdr_dec_create(rqstp, p, res);
3894 * Decode GETATTR response
3896 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3898 struct xdr_stream xdr;
3899 struct compound_hdr hdr;
3902 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3903 status = decode_compound_hdr(&xdr, &hdr);
3906 status = decode_putfh(&xdr);
3909 status = decode_getfattr(&xdr, res->fattr, res->server);
3916 * Encode an SETACL request
3919 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3921 struct xdr_stream xdr;
3922 struct compound_hdr hdr = {
3927 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3928 encode_compound_hdr(&xdr, &hdr);
3929 status = encode_putfh(&xdr, args->fh);
3932 status = encode_setacl(&xdr, args);
3937 * Decode SETACL response
3940 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
3942 struct xdr_stream xdr;
3943 struct compound_hdr hdr;
3946 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3947 status = decode_compound_hdr(&xdr, &hdr);
3950 status = decode_putfh(&xdr);
3953 status = decode_setattr(&xdr, res);
3959 * Decode GETACL response
3962 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
3964 struct xdr_stream xdr;
3965 struct compound_hdr hdr;
3968 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3969 status = decode_compound_hdr(&xdr, &hdr);
3972 status = decode_putfh(&xdr);
3975 status = decode_getacl(&xdr, rqstp, acl_len);
3982 * Decode CLOSE response
3984 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3986 struct xdr_stream xdr;
3987 struct compound_hdr hdr;
3990 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3991 status = decode_compound_hdr(&xdr, &hdr);
3994 status = decode_putfh(&xdr);
3997 status = decode_close(&xdr, res);
4001 * Note: Server may do delete on close for this file
4002 * in which case the getattr call will fail with
4003 * an ESTALE error. Shouldn't be a problem,
4004 * though, since fattr->valid will remain unset.
4006 decode_getfattr(&xdr, res->fattr, res->server);
4012 * Decode OPEN response
4014 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4016 struct xdr_stream xdr;
4017 struct compound_hdr hdr;
4020 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4021 status = decode_compound_hdr(&xdr, &hdr);
4024 status = decode_putfh(&xdr);
4027 status = decode_savefh(&xdr);
4030 status = decode_open(&xdr, res);
4033 status = decode_getfh(&xdr, &res->fh);
4036 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4038 if ((status = decode_restorefh(&xdr)) != 0)
4040 decode_getfattr(&xdr, res->dir_attr, res->server);
4046 * Decode OPEN_CONFIRM response
4048 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4050 struct xdr_stream xdr;
4051 struct compound_hdr hdr;
4054 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4055 status = decode_compound_hdr(&xdr, &hdr);
4058 status = decode_putfh(&xdr);
4061 status = decode_open_confirm(&xdr, res);
4067 * Decode OPEN response
4069 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4071 struct xdr_stream xdr;
4072 struct compound_hdr hdr;
4075 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4076 status = decode_compound_hdr(&xdr, &hdr);
4079 status = decode_putfh(&xdr);
4082 status = decode_open(&xdr, res);
4085 decode_getfattr(&xdr, res->f_attr, res->server);
4091 * Decode SETATTR response
4093 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4095 struct xdr_stream xdr;
4096 struct compound_hdr hdr;
4099 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4100 status = decode_compound_hdr(&xdr, &hdr);
4103 status = decode_putfh(&xdr);
4106 status = decode_setattr(&xdr, res);
4109 status = decode_getfattr(&xdr, res->fattr, res->server);
4110 if (status == NFS4ERR_DELAY)
4117 * Decode LOCK response
4119 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4121 struct xdr_stream xdr;
4122 struct compound_hdr hdr;
4125 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4126 status = decode_compound_hdr(&xdr, &hdr);
4129 status = decode_putfh(&xdr);
4132 status = decode_lock(&xdr, res);
4138 * Decode LOCKT response
4140 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4142 struct xdr_stream xdr;
4143 struct compound_hdr hdr;
4146 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4147 status = decode_compound_hdr(&xdr, &hdr);
4150 status = decode_putfh(&xdr);
4153 status = decode_lockt(&xdr, res);
4159 * Decode LOCKU response
4161 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4163 struct xdr_stream xdr;
4164 struct compound_hdr hdr;
4167 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4168 status = decode_compound_hdr(&xdr, &hdr);
4171 status = decode_putfh(&xdr);
4174 status = decode_locku(&xdr, res);
4180 * Decode READLINK response
4182 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
4184 struct xdr_stream xdr;
4185 struct compound_hdr hdr;
4188 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4189 status = decode_compound_hdr(&xdr, &hdr);
4192 status = decode_putfh(&xdr);
4195 status = decode_readlink(&xdr, rqstp);
4201 * Decode READDIR response
4203 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4205 struct xdr_stream xdr;
4206 struct compound_hdr hdr;
4209 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4210 status = decode_compound_hdr(&xdr, &hdr);
4213 status = decode_putfh(&xdr);
4216 status = decode_readdir(&xdr, rqstp, res);
4222 * Decode Read response
4224 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4226 struct xdr_stream xdr;
4227 struct compound_hdr hdr;
4230 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4231 status = decode_compound_hdr(&xdr, &hdr);
4234 status = decode_putfh(&xdr);
4237 status = decode_read(&xdr, rqstp, res);
4239 status = res->count;
4245 * Decode WRITE response
4247 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4249 struct xdr_stream xdr;
4250 struct compound_hdr hdr;
4253 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4254 status = decode_compound_hdr(&xdr, &hdr);
4257 status = decode_putfh(&xdr);
4260 status = decode_write(&xdr, res);
4263 decode_getfattr(&xdr, res->fattr, res->server);
4265 status = res->count;
4271 * Decode COMMIT response
4273 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4275 struct xdr_stream xdr;
4276 struct compound_hdr hdr;
4279 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4280 status = decode_compound_hdr(&xdr, &hdr);
4283 status = decode_putfh(&xdr);
4286 status = decode_commit(&xdr, res);
4289 decode_getfattr(&xdr, res->fattr, res->server);
4297 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4299 struct xdr_stream xdr;
4300 struct compound_hdr hdr;
4303 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4304 status = decode_compound_hdr(&xdr, &hdr);
4306 status = decode_putfh(&xdr);
4308 status = decode_fsinfo(&xdr, fsinfo);
4310 status = -nfs4_stat_to_errno(hdr.status);
4317 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
4319 struct xdr_stream xdr;
4320 struct compound_hdr hdr;
4323 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4324 status = decode_compound_hdr(&xdr, &hdr);
4326 status = decode_putfh(&xdr);
4328 status = decode_pathconf(&xdr, pathconf);
4335 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
4337 struct xdr_stream xdr;
4338 struct compound_hdr hdr;
4341 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4342 status = decode_compound_hdr(&xdr, &hdr);
4344 status = decode_putfh(&xdr);
4346 status = decode_statfs(&xdr, fsstat);
4351 * GETATTR_BITMAP request
4353 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4355 struct xdr_stream xdr;
4356 struct compound_hdr hdr;
4359 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4360 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4362 if ((status = decode_putfh(&xdr)) != 0)
4364 status = decode_server_caps(&xdr, res);
4370 * Decode RENEW response
4372 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4374 struct xdr_stream xdr;
4375 struct compound_hdr hdr;
4378 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4379 status = decode_compound_hdr(&xdr, &hdr);
4381 status = decode_renew(&xdr);
4386 * a SETCLIENTID request
4388 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4389 struct nfs_client *clp)
4391 struct xdr_stream xdr;
4392 struct compound_hdr hdr;
4395 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4396 status = decode_compound_hdr(&xdr, &hdr);
4398 status = decode_setclientid(&xdr, clp);
4400 status = -nfs4_stat_to_errno(hdr.status);
4405 * a SETCLIENTID_CONFIRM request
4407 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4409 struct xdr_stream xdr;
4410 struct compound_hdr hdr;
4413 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4414 status = decode_compound_hdr(&xdr, &hdr);
4416 status = decode_setclientid_confirm(&xdr);
4418 status = decode_putrootfh(&xdr);
4420 status = decode_fsinfo(&xdr, fsinfo);
4422 status = -nfs4_stat_to_errno(hdr.status);
4427 * DELEGRETURN request
4429 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4431 struct xdr_stream xdr;
4432 struct compound_hdr hdr;
4435 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4436 status = decode_compound_hdr(&xdr, &hdr);
4439 status = decode_putfh(&xdr);
4442 status = decode_delegreturn(&xdr);
4443 decode_getfattr(&xdr, res->fattr, res->server);
4449 * FS_LOCATIONS request
4451 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
4453 struct xdr_stream xdr;
4454 struct compound_hdr hdr;
4457 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4458 status = decode_compound_hdr(&xdr, &hdr);
4461 if ((status = decode_putfh(&xdr)) != 0)
4463 if ((status = decode_lookup(&xdr)) != 0)
4465 xdr_enter_page(&xdr, PAGE_SIZE);
4466 status = decode_getfattr(&xdr, &res->fattr, res->server);
4471 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4473 uint32_t bitmap[2] = {0};
4478 return ERR_PTR(-EAGAIN);
4480 return ERR_PTR(-EBADCOOKIE);
4483 entry->prev_cookie = entry->cookie;
4484 p = xdr_decode_hyper(p, &entry->cookie);
4485 entry->len = ntohl(*p++);
4486 entry->name = (const char *) p;
4487 p += XDR_QUADLEN(entry->len);
4490 * In case the server doesn't return an inode number,
4491 * we fake one here. (We don't use inode number 0,
4492 * since glibc seems to choke on it...)
4496 len = ntohl(*p++); /* bitmap length */
4498 bitmap[0] = ntohl(*p++);
4500 bitmap[1] = ntohl(*p++);
4504 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4506 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4507 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4508 /* Ignore the return value of rdattr_error for now */
4512 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4513 xdr_decode_hyper(p, &entry->ino);
4514 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4515 xdr_decode_hyper(p, &entry->ino);
4519 entry->eof = !p[0] && p[1];
4524 * We need to translate between nfs status return values and
4525 * the local errno values which may not be the same.
4532 { NFS4ERR_PERM, EPERM },
4533 { NFS4ERR_NOENT, ENOENT },
4534 { NFS4ERR_IO, errno_NFSERR_IO },
4535 { NFS4ERR_NXIO, ENXIO },
4536 { NFS4ERR_ACCESS, EACCES },
4537 { NFS4ERR_EXIST, EEXIST },
4538 { NFS4ERR_XDEV, EXDEV },
4539 { NFS4ERR_NOTDIR, ENOTDIR },
4540 { NFS4ERR_ISDIR, EISDIR },
4541 { NFS4ERR_INVAL, EINVAL },
4542 { NFS4ERR_FBIG, EFBIG },
4543 { NFS4ERR_NOSPC, ENOSPC },
4544 { NFS4ERR_ROFS, EROFS },
4545 { NFS4ERR_MLINK, EMLINK },
4546 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4547 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4548 { NFS4ERR_DQUOT, EDQUOT },
4549 { NFS4ERR_STALE, ESTALE },
4550 { NFS4ERR_BADHANDLE, EBADHANDLE },
4551 { NFS4ERR_BADOWNER, EINVAL },
4552 { NFS4ERR_BADNAME, EINVAL },
4553 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4554 { NFS4ERR_NOTSUPP, ENOTSUPP },
4555 { NFS4ERR_TOOSMALL, ETOOSMALL },
4556 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4557 { NFS4ERR_BADTYPE, EBADTYPE },
4558 { NFS4ERR_LOCKED, EAGAIN },
4559 { NFS4ERR_RESOURCE, EREMOTEIO },
4560 { NFS4ERR_SYMLINK, ELOOP },
4561 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4562 { NFS4ERR_DEADLOCK, EDEADLK },
4563 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4564 * to be handled by a
4571 * Convert an NFS error code to a local one.
4572 * This one is used jointly by NFSv2 and NFSv3.
4575 nfs4_stat_to_errno(int stat)
4578 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4579 if (nfs_errtbl[i].stat == stat)
4580 return nfs_errtbl[i].errno;
4582 if (stat <= 10000 || stat > 10100) {
4583 /* The server is looney tunes. */
4584 return ESERVERFAULT;
4586 /* If we cannot translate the error, the recovery routines should
4588 * Note: remaining NFSv4 error codes have values > 10000, so should
4589 * not conflict with native Linux error codes.
4594 #define PROC(proc, argtype, restype) \
4595 [NFSPROC4_CLNT_##proc] = { \
4596 .p_proc = NFSPROC4_COMPOUND, \
4597 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4598 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4599 .p_arglen = NFS4_##argtype##_sz, \
4600 .p_replen = NFS4_##restype##_sz, \
4601 .p_statidx = NFSPROC4_CLNT_##proc, \
4605 struct rpc_procinfo nfs4_procedures[] = {
4606 PROC(READ, enc_read, dec_read),
4607 PROC(WRITE, enc_write, dec_write),
4608 PROC(COMMIT, enc_commit, dec_commit),
4609 PROC(OPEN, enc_open, dec_open),
4610 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4611 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4612 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4613 PROC(CLOSE, enc_close, dec_close),
4614 PROC(SETATTR, enc_setattr, dec_setattr),
4615 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4616 PROC(RENEW, enc_renew, dec_renew),
4617 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4618 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4619 PROC(LOCK, enc_lock, dec_lock),
4620 PROC(LOCKT, enc_lockt, dec_lockt),
4621 PROC(LOCKU, enc_locku, dec_locku),
4622 PROC(ACCESS, enc_access, dec_access),
4623 PROC(GETATTR, enc_getattr, dec_getattr),
4624 PROC(LOOKUP, enc_lookup, dec_lookup),
4625 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4626 PROC(REMOVE, enc_remove, dec_remove),
4627 PROC(RENAME, enc_rename, dec_rename),
4628 PROC(LINK, enc_link, dec_link),
4629 PROC(SYMLINK, enc_symlink, dec_symlink),
4630 PROC(CREATE, enc_create, dec_create),
4631 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4632 PROC(STATFS, enc_statfs, dec_statfs),
4633 PROC(READLINK, enc_readlink, dec_readlink),
4634 PROC(READDIR, enc_readdir, dec_readdir),
4635 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4636 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4637 PROC(GETACL, enc_getacl, dec_getacl),
4638 PROC(SETACL, enc_setacl, dec_setacl),
4639 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4642 struct rpc_version nfs_version4 = {
4644 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4645 .procs = nfs4_procedures