4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 1)
74 #define lock_owner_id_maxsz (1 + 1)
75 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
76 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define op_encode_hdr_maxsz (1)
78 #define op_decode_hdr_maxsz (2)
79 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
81 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
82 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
83 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
84 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
85 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
86 ((3+NFS4_FHSIZE) >> 2))
87 #define nfs4_fattr_bitmap_maxsz 3
88 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
89 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
90 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
91 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
92 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
93 /* This is based on getfattr, which uses the most attributes: */
94 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
95 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
96 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
97 nfs4_fattr_value_maxsz)
98 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
99 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
100 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
101 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
102 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
103 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
104 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
105 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
106 #define decode_renew_maxsz (op_decode_hdr_maxsz)
107 #define encode_setclientid_maxsz \
108 (op_encode_hdr_maxsz + \
109 4 /*server->ip_addr*/ + \
112 6 + (NFS4_VERIFIER_SIZE >> 2))
113 #define decode_setclientid_maxsz \
114 (op_decode_hdr_maxsz + \
116 1024) /* large value for CLID_INUSE */
117 #define encode_setclientid_confirm_maxsz \
118 (op_encode_hdr_maxsz + \
119 3 + (NFS4_VERIFIER_SIZE >> 2))
120 #define decode_setclientid_confirm_maxsz \
121 (op_decode_hdr_maxsz)
122 #define encode_lookup_maxsz (op_encode_hdr_maxsz + 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+20);
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 WRITE32(args->lock_owner.id);
839 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
840 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
841 WRITE32(args->lock_seqid->sequence->counter);
847 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
853 WRITE32(nfs4_lock_type(args->fl, 0));
854 WRITE64(args->fl->fl_start);
855 WRITE64(nfs4_lock_length(args->fl));
856 WRITE64(args->lock_owner.clientid);
858 WRITE32(args->lock_owner.id);
863 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
867 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
869 WRITE32(nfs4_lock_type(args->fl, 0));
870 WRITE32(args->seqid->sequence->counter);
871 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
872 WRITE64(args->fl->fl_start);
873 WRITE64(nfs4_lock_length(args->fl));
878 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
883 RESERVE_SPACE(8 + len);
886 WRITEMEM(name->name, len);
891 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
896 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
898 WRITE32(NFS4_SHARE_ACCESS_READ);
901 WRITE32(NFS4_SHARE_ACCESS_WRITE);
903 case FMODE_READ|FMODE_WRITE:
904 WRITE32(NFS4_SHARE_ACCESS_BOTH);
909 WRITE32(0); /* for linux, share_deny = 0 always */
912 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
916 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
921 WRITE32(arg->seqid->sequence->counter);
922 encode_share_access(xdr, arg->open_flags);
924 WRITE64(arg->clientid);
929 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
934 switch(arg->open_flags & O_EXCL) {
936 WRITE32(NFS4_CREATE_UNCHECKED);
937 encode_attrs(xdr, arg->u.attrs, arg->server);
940 WRITE32(NFS4_CREATE_EXCLUSIVE);
941 encode_nfs4_verifier(xdr, &arg->u.verifier);
945 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
950 switch (arg->open_flags & O_CREAT) {
952 WRITE32(NFS4_OPEN_NOCREATE);
955 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
956 WRITE32(NFS4_OPEN_CREATE);
957 encode_createmode(xdr, arg);
961 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
966 switch (delegation_type) {
968 WRITE32(NFS4_OPEN_DELEGATE_NONE);
971 WRITE32(NFS4_OPEN_DELEGATE_READ);
973 case FMODE_WRITE|FMODE_READ:
974 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
981 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
986 WRITE32(NFS4_OPEN_CLAIM_NULL);
987 encode_string(xdr, name->len, name->name);
990 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
995 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
996 encode_delegation_type(xdr, type);
999 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1003 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1004 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1005 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1006 encode_string(xdr, name->len, name->name);
1009 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1011 encode_openhdr(xdr, arg);
1012 encode_opentype(xdr, arg);
1013 switch (arg->claim) {
1014 case NFS4_OPEN_CLAIM_NULL:
1015 encode_claim_null(xdr, arg->name);
1017 case NFS4_OPEN_CLAIM_PREVIOUS:
1018 encode_claim_previous(xdr, arg->u.delegation_type);
1020 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1021 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1029 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
1033 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1034 WRITE32(OP_OPEN_CONFIRM);
1035 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1036 WRITE32(arg->seqid->sequence->counter);
1041 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1045 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1046 WRITE32(OP_OPEN_DOWNGRADE);
1047 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1048 WRITE32(arg->seqid->sequence->counter);
1049 encode_share_access(xdr, arg->open_flags);
1054 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1059 RESERVE_SPACE(8 + len);
1062 WRITEMEM(fh->data, len);
1067 static int encode_putrootfh(struct xdr_stream *xdr)
1072 WRITE32(OP_PUTROOTFH);
1077 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1079 nfs4_stateid stateid;
1082 RESERVE_SPACE(NFS4_STATEID_SIZE);
1083 if (ctx->state != NULL) {
1084 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1085 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1087 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1090 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1097 encode_stateid(xdr, args->context);
1100 WRITE64(args->offset);
1101 WRITE32(args->count);
1106 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1108 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1109 uint32_t attrs[2] = {
1110 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1111 FATTR4_WORD1_MOUNTED_ON_FILEID,
1116 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1117 WRITE32(OP_READDIR);
1118 WRITE64(readdir->cookie);
1119 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1120 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1121 WRITE32(readdir->count);
1123 /* Switch to mounted_on_fileid if the server supports it */
1124 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1125 attrs[0] &= ~FATTR4_WORD0_FILEID;
1127 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1128 WRITE32(attrs[0] & readdir->bitmask[0]);
1129 WRITE32(attrs[1] & readdir->bitmask[1]);
1130 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1132 (unsigned long long)readdir->cookie,
1133 ((u32 *)readdir->verifier.data)[0],
1134 ((u32 *)readdir->verifier.data)[1],
1135 attrs[0] & readdir->bitmask[0],
1136 attrs[1] & readdir->bitmask[1]);
1138 /* set up reply kvec
1139 * toplevel_status + taglen + rescount + OP_PUTFH + status
1140 * + OP_READDIR + status + verifer(2) = 9
1142 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1143 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1144 readdir->pgbase, readdir->count);
1145 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1146 __FUNCTION__, replen, readdir->pages,
1147 readdir->pgbase, readdir->count);
1152 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1154 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1155 unsigned int replen;
1159 WRITE32(OP_READLINK);
1161 /* set up reply kvec
1162 * toplevel_status + taglen + rescount + OP_PUTFH + status
1163 * + OP_READLINK + status + string length = 8
1165 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1166 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1167 readlink->pgbase, readlink->pglen);
1172 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1176 RESERVE_SPACE(8 + name->len);
1179 WRITEMEM(name->name, name->len);
1184 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1188 RESERVE_SPACE(8 + oldname->len);
1190 WRITE32(oldname->len);
1191 WRITEMEM(oldname->name, oldname->len);
1193 RESERVE_SPACE(4 + newname->len);
1194 WRITE32(newname->len);
1195 WRITEMEM(newname->name, newname->len);
1200 static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
1206 WRITE64(client_stateid->cl_clientid);
1212 encode_restorefh(struct xdr_stream *xdr)
1217 WRITE32(OP_RESTOREFH);
1223 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1227 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1228 WRITE32(OP_SETATTR);
1229 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1232 WRITE32(FATTR4_WORD0_ACL);
1233 if (arg->acl_len % 4)
1236 WRITE32(arg->acl_len);
1237 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1242 encode_savefh(struct xdr_stream *xdr)
1252 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1257 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1258 WRITE32(OP_SETATTR);
1259 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1261 if ((status = encode_attrs(xdr, arg->iap, server)))
1267 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1271 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1272 WRITE32(OP_SETCLIENTID);
1273 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1275 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1277 WRITE32(setclientid->sc_prog);
1278 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1279 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1281 WRITE32(setclientid->sc_cb_ident);
1286 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
1290 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1291 WRITE32(OP_SETCLIENTID_CONFIRM);
1292 WRITE64(client_state->cl_clientid);
1293 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1298 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1305 encode_stateid(xdr, args->context);
1308 WRITE64(args->offset);
1309 WRITE32(args->stable);
1310 WRITE32(args->count);
1312 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1317 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1321 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1323 WRITE32(OP_DELEGRETURN);
1324 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1329 * END OF "GENERIC" ENCODE ROUTINES.
1333 * Encode an ACCESS request
1335 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1337 struct xdr_stream xdr;
1338 struct compound_hdr hdr = {
1343 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1344 encode_compound_hdr(&xdr, &hdr);
1345 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1346 status = encode_access(&xdr, args->access);
1351 * Encode LOOKUP request
1353 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1355 struct xdr_stream xdr;
1356 struct compound_hdr hdr = {
1361 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1362 encode_compound_hdr(&xdr, &hdr);
1363 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1365 if ((status = encode_lookup(&xdr, args->name)) != 0)
1367 if ((status = encode_getfh(&xdr)) != 0)
1369 status = encode_getfattr(&xdr, args->bitmask);
1375 * Encode LOOKUP_ROOT request
1377 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1379 struct xdr_stream xdr;
1380 struct compound_hdr hdr = {
1385 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1386 encode_compound_hdr(&xdr, &hdr);
1387 if ((status = encode_putrootfh(&xdr)) != 0)
1389 if ((status = encode_getfh(&xdr)) == 0)
1390 status = encode_getfattr(&xdr, args->bitmask);
1396 * Encode REMOVE request
1398 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs4_remove_arg *args)
1400 struct xdr_stream xdr;
1401 struct compound_hdr hdr = {
1406 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1407 encode_compound_hdr(&xdr, &hdr);
1408 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1410 if ((status = encode_remove(&xdr, args->name)) != 0)
1412 status = encode_getfattr(&xdr, args->bitmask);
1418 * Encode RENAME request
1420 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1422 struct xdr_stream xdr;
1423 struct compound_hdr hdr = {
1428 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1429 encode_compound_hdr(&xdr, &hdr);
1430 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1432 if ((status = encode_savefh(&xdr)) != 0)
1434 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1436 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1438 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1440 if ((status = encode_restorefh(&xdr)) != 0)
1442 status = encode_getfattr(&xdr, args->bitmask);
1448 * Encode LINK request
1450 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1452 struct xdr_stream xdr;
1453 struct compound_hdr hdr = {
1458 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1459 encode_compound_hdr(&xdr, &hdr);
1460 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1462 if ((status = encode_savefh(&xdr)) != 0)
1464 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1466 if ((status = encode_link(&xdr, args->name)) != 0)
1468 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1470 if ((status = encode_restorefh(&xdr)) != 0)
1472 status = encode_getfattr(&xdr, args->bitmask);
1478 * Encode CREATE request
1480 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1482 struct xdr_stream xdr;
1483 struct compound_hdr hdr = {
1488 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1489 encode_compound_hdr(&xdr, &hdr);
1490 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1492 if ((status = encode_savefh(&xdr)) != 0)
1494 if ((status = encode_create(&xdr, args)) != 0)
1496 if ((status = encode_getfh(&xdr)) != 0)
1498 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1500 if ((status = encode_restorefh(&xdr)) != 0)
1502 status = encode_getfattr(&xdr, args->bitmask);
1508 * Encode SYMLINK request
1510 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1512 return nfs4_xdr_enc_create(req, p, args);
1516 * Encode GETATTR request
1518 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1520 struct xdr_stream xdr;
1521 struct compound_hdr hdr = {
1526 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1527 encode_compound_hdr(&xdr, &hdr);
1528 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1529 status = encode_getfattr(&xdr, args->bitmask);
1534 * Encode a CLOSE request
1536 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1538 struct xdr_stream xdr;
1539 struct compound_hdr hdr = {
1544 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1545 encode_compound_hdr(&xdr, &hdr);
1546 status = encode_putfh(&xdr, args->fh);
1549 status = encode_close(&xdr, args);
1552 status = encode_getfattr(&xdr, args->bitmask);
1558 * Encode an OPEN request
1560 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1562 struct xdr_stream xdr;
1563 struct compound_hdr hdr = {
1568 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1569 encode_compound_hdr(&xdr, &hdr);
1570 status = encode_putfh(&xdr, args->fh);
1573 status = encode_savefh(&xdr);
1576 status = encode_open(&xdr, args);
1579 status = encode_getfh(&xdr);
1582 status = encode_getfattr(&xdr, args->bitmask);
1585 status = encode_restorefh(&xdr);
1588 status = encode_getfattr(&xdr, args->bitmask);
1594 * Encode an OPEN_CONFIRM request
1596 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1598 struct xdr_stream xdr;
1599 struct compound_hdr hdr = {
1604 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1605 encode_compound_hdr(&xdr, &hdr);
1606 status = encode_putfh(&xdr, args->fh);
1609 status = encode_open_confirm(&xdr, args);
1615 * Encode an OPEN request with no attributes.
1617 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1619 struct xdr_stream xdr;
1620 struct compound_hdr hdr = {
1625 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1626 encode_compound_hdr(&xdr, &hdr);
1627 status = encode_putfh(&xdr, args->fh);
1630 status = encode_open(&xdr, args);
1633 status = encode_getfattr(&xdr, args->bitmask);
1639 * Encode an OPEN_DOWNGRADE request
1641 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1643 struct xdr_stream xdr;
1644 struct compound_hdr hdr = {
1649 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1650 encode_compound_hdr(&xdr, &hdr);
1651 status = encode_putfh(&xdr, args->fh);
1654 status = encode_open_downgrade(&xdr, args);
1657 status = encode_getfattr(&xdr, args->bitmask);
1663 * Encode a LOCK request
1665 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1667 struct xdr_stream xdr;
1668 struct compound_hdr hdr = {
1673 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1674 encode_compound_hdr(&xdr, &hdr);
1675 status = encode_putfh(&xdr, args->fh);
1678 status = encode_lock(&xdr, args);
1684 * Encode a LOCKT request
1686 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1688 struct xdr_stream xdr;
1689 struct compound_hdr hdr = {
1694 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1695 encode_compound_hdr(&xdr, &hdr);
1696 status = encode_putfh(&xdr, args->fh);
1699 status = encode_lockt(&xdr, args);
1705 * Encode a LOCKU request
1707 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1709 struct xdr_stream xdr;
1710 struct compound_hdr hdr = {
1715 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1716 encode_compound_hdr(&xdr, &hdr);
1717 status = encode_putfh(&xdr, args->fh);
1720 status = encode_locku(&xdr, args);
1726 * Encode a READLINK request
1728 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1730 struct xdr_stream xdr;
1731 struct compound_hdr hdr = {
1736 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1737 encode_compound_hdr(&xdr, &hdr);
1738 status = encode_putfh(&xdr, args->fh);
1741 status = encode_readlink(&xdr, args, req);
1747 * Encode a READDIR request
1749 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1751 struct xdr_stream xdr;
1752 struct compound_hdr hdr = {
1757 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1758 encode_compound_hdr(&xdr, &hdr);
1759 status = encode_putfh(&xdr, args->fh);
1762 status = encode_readdir(&xdr, args, req);
1768 * Encode a READ request
1770 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1772 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1773 struct xdr_stream xdr;
1774 struct compound_hdr hdr = {
1779 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1780 encode_compound_hdr(&xdr, &hdr);
1781 status = encode_putfh(&xdr, args->fh);
1784 status = encode_read(&xdr, args);
1788 /* set up reply kvec
1789 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1790 * + OP_READ + status + eof + datalen = 9
1792 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1793 xdr_inline_pages(&req->rq_rcv_buf, replen,
1794 args->pages, args->pgbase, args->count);
1800 * Encode an SETATTR request
1802 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1805 struct xdr_stream xdr;
1806 struct compound_hdr hdr = {
1811 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1812 encode_compound_hdr(&xdr, &hdr);
1813 status = encode_putfh(&xdr, args->fh);
1816 status = encode_setattr(&xdr, args, args->server);
1819 status = encode_getfattr(&xdr, args->bitmask);
1825 * Encode a GETACL request
1828 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1829 struct nfs_getaclargs *args)
1831 struct xdr_stream xdr;
1832 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1833 struct compound_hdr hdr = {
1838 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1839 encode_compound_hdr(&xdr, &hdr);
1840 status = encode_putfh(&xdr, args->fh);
1843 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1844 /* set up reply buffer: */
1845 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1846 xdr_inline_pages(&req->rq_rcv_buf, replen,
1847 args->acl_pages, args->acl_pgbase, args->acl_len);
1853 * Encode a WRITE request
1855 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1857 struct xdr_stream xdr;
1858 struct compound_hdr hdr = {
1863 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1864 encode_compound_hdr(&xdr, &hdr);
1865 status = encode_putfh(&xdr, args->fh);
1868 status = encode_write(&xdr, args);
1871 status = encode_getfattr(&xdr, args->bitmask);
1879 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1881 struct xdr_stream xdr;
1882 struct compound_hdr hdr = {
1887 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1888 encode_compound_hdr(&xdr, &hdr);
1889 status = encode_putfh(&xdr, args->fh);
1892 status = encode_commit(&xdr, args);
1895 status = encode_getfattr(&xdr, args->bitmask);
1903 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1905 struct xdr_stream xdr;
1906 struct compound_hdr hdr = {
1911 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1912 encode_compound_hdr(&xdr, &hdr);
1913 status = encode_putfh(&xdr, args->fh);
1915 status = encode_fsinfo(&xdr, args->bitmask);
1920 * a PATHCONF request
1922 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1924 struct xdr_stream xdr;
1925 struct compound_hdr hdr = {
1930 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1931 encode_compound_hdr(&xdr, &hdr);
1932 status = encode_putfh(&xdr, args->fh);
1934 status = encode_getattr_one(&xdr,
1935 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1942 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
1944 struct xdr_stream xdr;
1945 struct compound_hdr hdr = {
1950 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1951 encode_compound_hdr(&xdr, &hdr);
1952 status = encode_putfh(&xdr, args->fh);
1954 status = encode_getattr_two(&xdr,
1955 args->bitmask[0] & nfs4_statfs_bitmap[0],
1956 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1961 * GETATTR_BITMAP request
1963 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
1965 struct xdr_stream xdr;
1966 struct compound_hdr hdr = {
1971 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1972 encode_compound_hdr(&xdr, &hdr);
1973 status = encode_putfh(&xdr, fhandle);
1975 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1976 FATTR4_WORD0_LINK_SUPPORT|
1977 FATTR4_WORD0_SYMLINK_SUPPORT|
1978 FATTR4_WORD0_ACLSUPPORT);
1985 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1987 struct xdr_stream xdr;
1988 struct compound_hdr hdr = {
1992 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1993 encode_compound_hdr(&xdr, &hdr);
1994 return encode_renew(&xdr, clp);
1998 * a SETCLIENTID request
2000 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
2002 struct xdr_stream xdr;
2003 struct compound_hdr hdr = {
2007 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2008 encode_compound_hdr(&xdr, &hdr);
2009 return encode_setclientid(&xdr, sc);
2013 * a SETCLIENTID_CONFIRM request
2015 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2017 struct xdr_stream xdr;
2018 struct compound_hdr hdr = {
2021 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2024 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2025 encode_compound_hdr(&xdr, &hdr);
2026 status = encode_setclientid_confirm(&xdr, clp);
2028 status = encode_putrootfh(&xdr);
2030 status = encode_fsinfo(&xdr, lease_bitmap);
2035 * DELEGRETURN request
2037 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2039 struct xdr_stream xdr;
2040 struct compound_hdr hdr = {
2045 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2046 encode_compound_hdr(&xdr, &hdr);
2047 status = encode_putfh(&xdr, args->fhandle);
2050 status = encode_delegreturn(&xdr, args->stateid);
2053 status = encode_getfattr(&xdr, args->bitmask);
2059 * Encode FS_LOCATIONS request
2061 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2063 struct xdr_stream xdr;
2064 struct compound_hdr hdr = {
2067 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
2071 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2072 encode_compound_hdr(&xdr, &hdr);
2073 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2075 if ((status = encode_lookup(&xdr, args->name)) != 0)
2077 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
2080 * toplevel_status + OP_PUTFH + status
2081 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2083 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2084 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2091 * START OF "GENERIC" DECODE ROUTINES.
2092 * These may look a little ugly since they are imported from a "generic"
2093 * set of XDR encode/decode routines which are intended to be shared by
2094 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2096 * If the pain of reading these is too great, it should be a straightforward
2097 * task to translate them into Linux-specific versions which are more
2098 * consistent with the style used in NFSv2/v3...
2100 #define READ32(x) (x) = ntohl(*p++)
2101 #define READ64(x) do { \
2102 (x) = (u64)ntohl(*p++) << 32; \
2103 (x) |= ntohl(*p++); \
2105 #define READTIME(x) do { \
2107 (x.tv_sec) = ntohl(*p++); \
2108 (x.tv_nsec) = ntohl(*p++); \
2110 #define COPYMEM(x,nbytes) do { \
2111 memcpy((x), p, nbytes); \
2112 p += XDR_QUADLEN(nbytes); \
2115 #define READ_BUF(nbytes) do { \
2116 p = xdr_inline_decode(xdr, nbytes); \
2117 if (unlikely(!p)) { \
2118 printk(KERN_INFO "%s: prematurely hit end of receive" \
2119 " buffer\n", __FUNCTION__); \
2120 printk(KERN_INFO "%s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2121 __FUNCTION__, xdr->p, nbytes, xdr->end); \
2126 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2133 *string = (char *)p;
2137 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2142 READ32(hdr->status);
2143 READ32(hdr->taglen);
2145 READ_BUF(hdr->taglen + 4);
2146 hdr->tag = (char *)p;
2147 p += XDR_QUADLEN(hdr->taglen);
2152 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2160 if (opnum != expected) {
2162 "nfs4_decode_op_hdr: Server returned operation"
2163 " %d but we issued a request for %d\n",
2168 if (nfserr != NFS_OK)
2169 return -nfs4_stat_to_errno(nfserr);
2174 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2177 unsigned int strlen;
2181 return decode_opaque_inline(xdr, &strlen, &str);
2184 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2192 bitmap[0] = bitmap[1] = 0;
2193 READ_BUF((bmlen << 2));
2202 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2212 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2214 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2215 decode_attr_bitmap(xdr, bitmask);
2216 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2218 bitmask[0] = bitmask[1] = 0;
2219 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2223 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2228 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2230 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2233 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2234 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2237 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2239 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2243 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2248 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2250 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2253 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2255 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2256 (unsigned long long)*change);
2260 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2265 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2267 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2270 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2272 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2276 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2281 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2283 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2286 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2288 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2292 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2297 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2299 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2302 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2304 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2308 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2314 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2316 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2318 READ64(fsid->major);
2319 READ64(fsid->minor);
2320 bitmap[0] &= ~FATTR4_WORD0_FSID;
2322 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2323 (unsigned long long)fsid->major,
2324 (unsigned long long)fsid->minor);
2328 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2333 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2335 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2338 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2340 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2344 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2348 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2349 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2351 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2354 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2356 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2360 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2365 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2367 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2370 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2372 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2376 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2381 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2383 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2386 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2388 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2392 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2398 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2400 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2403 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2405 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2409 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2415 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2417 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2420 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2422 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2426 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2432 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2434 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2437 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2439 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2443 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2456 path->ncomponents = 0;
2457 while (path->ncomponents < n) {
2458 struct nfs4_string *component = &path->components[path->ncomponents];
2459 status = decode_opaque_inline(xdr, &component->len, &component->data);
2460 if (unlikely(status != 0))
2462 if (path->ncomponents != n)
2464 dprintk("%s", component->data);
2465 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2466 path->ncomponents++;
2468 dprintk("cannot parse %d components in path\n", n);
2476 /* a root pathname is sent as a zero component4 */
2477 path->ncomponents = 1;
2478 path->components[0].len=0;
2479 path->components[0].data=NULL;
2480 dprintk("path /\n");
2483 dprintk(" status %d", status);
2488 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2494 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2497 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2499 dprintk("%s: fsroot ", __FUNCTION__);
2500 status = decode_pathname(xdr, &res->fs_path);
2501 if (unlikely(status != 0))
2507 res->nlocations = 0;
2508 while (res->nlocations < n) {
2510 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2518 dprintk("%s: servers ", __FUNCTION__);
2519 while (loc->nservers < m) {
2520 struct nfs4_string *server = &loc->servers[loc->nservers];
2521 status = decode_opaque_inline(xdr, &server->len, &server->data);
2522 if (unlikely(status != 0))
2524 dprintk("%s ", server->data);
2525 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2529 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2530 for (i = loc->nservers; i < m; i++) {
2533 status = decode_opaque_inline(xdr, &len, &data);
2534 if (unlikely(status != 0))
2539 status = decode_pathname(xdr, &loc->rootpath);
2540 if (unlikely(status != 0))
2542 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2546 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2553 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2559 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2561 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2564 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2566 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2570 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2576 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2578 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2581 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2583 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2587 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2593 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2595 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2598 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2600 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2604 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2610 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2612 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2616 if (maxread > 0x7FFFFFFF)
2617 maxread = 0x7FFFFFFF;
2618 *res = (uint32_t)maxread;
2619 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2621 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2625 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2631 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2633 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2637 if (maxwrite > 0x7FFFFFFF)
2638 maxwrite = 0x7FFFFFFF;
2639 *res = (uint32_t)maxwrite;
2640 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2642 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2646 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2651 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2653 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2657 bitmap[1] &= ~FATTR4_WORD1_MODE;
2659 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2663 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2668 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2670 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2673 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2675 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2679 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2685 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2687 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2691 if (len < XDR_MAX_NETOBJ) {
2692 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2693 dprintk("%s: nfs_map_name_to_uid failed!\n",
2696 printk(KERN_WARNING "%s: name too long (%u)!\n",
2698 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2700 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2704 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2710 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2712 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2716 if (len < XDR_MAX_NETOBJ) {
2717 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2718 dprintk("%s: nfs_map_group_to_gid failed!\n",
2721 printk(KERN_WARNING "%s: name too long (%u)!\n",
2723 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2725 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2729 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2731 uint32_t major = 0, minor = 0;
2735 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2737 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2743 tmp = MKDEV(major, minor);
2744 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2746 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2748 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2752 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2758 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2760 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2763 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2765 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2769 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2775 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2777 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2780 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2782 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2786 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2792 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2794 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2797 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2799 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2803 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2808 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2810 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2813 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2815 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2816 (unsigned long long)*used);
2820 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2829 time->tv_sec = (time_t)sec;
2830 time->tv_nsec = (long)nsec;
2834 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2840 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2842 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2843 status = decode_attr_time(xdr, time);
2844 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2846 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2850 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2856 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2858 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2859 status = decode_attr_time(xdr, time);
2860 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2862 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2866 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2872 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2874 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2875 status = decode_attr_time(xdr, time);
2876 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2878 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2882 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2884 unsigned int attrwords = XDR_QUADLEN(attrlen);
2885 unsigned int nwords = xdr->p - savep;
2887 if (unlikely(attrwords != nwords)) {
2888 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2891 (attrwords < nwords) ? '<' : '>',
2898 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2903 READ32(cinfo->atomic);
2904 READ64(cinfo->before);
2905 READ64(cinfo->after);
2909 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2915 status = decode_op_hdr(xdr, OP_ACCESS);
2921 access->supported = supp;
2922 access->access = acc;
2926 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2931 status = decode_op_hdr(xdr, OP_CLOSE);
2934 READ_BUF(NFS4_STATEID_SIZE);
2935 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
2939 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2944 status = decode_op_hdr(xdr, OP_COMMIT);
2948 COPYMEM(res->verf->verifier, 8);
2952 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2958 status = decode_op_hdr(xdr, OP_CREATE);
2961 if ((status = decode_change_info(xdr, cinfo)))
2965 READ_BUF(bmlen << 2);
2969 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2976 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2978 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2980 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2982 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2984 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2986 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2988 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2990 status = verify_attr_len(xdr, savep, attrlen);
2992 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2996 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3003 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3005 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3007 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3010 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3012 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3014 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3016 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3018 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3020 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3023 status = verify_attr_len(xdr, savep, attrlen);
3025 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3029 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3036 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3038 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3040 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3043 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3045 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3048 status = verify_attr_len(xdr, savep, attrlen);
3050 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3054 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3060 int status, fmode = 0;
3063 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3065 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3068 fattr->bitmap[0] = bitmap[0];
3069 fattr->bitmap[1] = bitmap[1];
3071 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3075 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3077 fattr->type = nfs_type2fmt[type].nfs2type;
3078 fmode = nfs_type2fmt[type].mode;
3080 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3082 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3084 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
3086 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3088 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3089 struct nfs4_fs_locations,
3092 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3094 fattr->mode |= fmode;
3095 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3097 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
3099 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
3101 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3103 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3105 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3107 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3109 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3111 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3113 if (fattr->fileid == 0 && fileid != 0)
3114 fattr->fileid = fileid;
3115 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
3116 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
3118 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
3123 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3126 uint32_t attrlen, bitmap[2];
3129 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3131 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3133 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3136 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3138 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3140 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3142 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3144 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3145 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3147 fsinfo->wtpref = fsinfo->wtmax;
3149 status = verify_attr_len(xdr, savep, attrlen);
3151 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3155 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3161 status = decode_op_hdr(xdr, OP_GETFH);
3164 /* Zero handle first to allow comparisons */
3165 memset(fh, 0, sizeof(*fh));
3169 if (len > NFS4_FHSIZE)
3173 COPYMEM(fh->data, len);
3177 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3181 status = decode_op_hdr(xdr, OP_LINK);
3184 return decode_change_info(xdr, cinfo);
3188 * We create the owner, so we know a proper owner.id length is 4.
3190 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3192 uint64_t offset, length, clientid;
3194 uint32_t namelen, type;
3201 fl->fl_start = (loff_t)offset;
3202 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3203 if (length == ~(uint64_t)0)
3204 fl->fl_end = OFFSET_MAX;
3205 fl->fl_type = F_WRLCK;
3207 fl->fl_type = F_RDLCK;
3213 return -NFS4ERR_DENIED;
3216 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3221 status = decode_op_hdr(xdr, OP_LOCK);
3223 READ_BUF(NFS4_STATEID_SIZE);
3224 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3225 } else if (status == -NFS4ERR_DENIED)
3226 return decode_lock_denied(xdr, NULL);
3230 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3233 status = decode_op_hdr(xdr, OP_LOCKT);
3234 if (status == -NFS4ERR_DENIED)
3235 return decode_lock_denied(xdr, res->denied);
3239 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3244 status = decode_op_hdr(xdr, OP_LOCKU);
3246 READ_BUF(NFS4_STATEID_SIZE);
3247 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3252 static int decode_lookup(struct xdr_stream *xdr)
3254 return decode_op_hdr(xdr, OP_LOOKUP);
3257 /* This is too sick! */
3258 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3261 uint32_t limit_type, nblocks, blocksize;
3265 switch (limit_type) {
3272 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3277 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3280 uint32_t delegation_type;
3283 READ32(delegation_type);
3284 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3285 res->delegation_type = 0;
3288 READ_BUF(NFS4_STATEID_SIZE+4);
3289 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3290 READ32(res->do_recall);
3291 switch (delegation_type) {
3292 case NFS4_OPEN_DELEGATE_READ:
3293 res->delegation_type = FMODE_READ;
3295 case NFS4_OPEN_DELEGATE_WRITE:
3296 res->delegation_type = FMODE_WRITE|FMODE_READ;
3297 if (decode_space_limit(xdr, &res->maxsize) < 0)
3300 return decode_ace(xdr, NULL, res->server->nfs_client);
3303 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3306 uint32_t savewords, bmlen, i;
3309 status = decode_op_hdr(xdr, OP_OPEN);
3312 READ_BUF(NFS4_STATEID_SIZE);
3313 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3315 decode_change_info(xdr, &res->cinfo);
3318 READ32(res->rflags);
3323 READ_BUF(bmlen << 2);
3324 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3325 for (i = 0; i < savewords; ++i)
3326 READ32(res->attrset[i]);
3327 for (; i < NFS4_BITMAP_SIZE; i++)
3328 res->attrset[i] = 0;
3330 return decode_delegation(xdr, res);
3332 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
3336 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3341 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3344 READ_BUF(NFS4_STATEID_SIZE);
3345 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3349 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3354 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3357 READ_BUF(NFS4_STATEID_SIZE);
3358 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3362 static int decode_putfh(struct xdr_stream *xdr)
3364 return decode_op_hdr(xdr, OP_PUTFH);
3367 static int decode_putrootfh(struct xdr_stream *xdr)
3369 return decode_op_hdr(xdr, OP_PUTROOTFH);
3372 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3374 struct kvec *iov = req->rq_rcv_buf.head;
3376 uint32_t count, eof, recvd, hdrlen;
3379 status = decode_op_hdr(xdr, OP_READ);
3385 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3386 recvd = req->rq_rcv_buf.len - hdrlen;
3387 if (count > recvd) {
3388 printk(KERN_WARNING "NFS: server cheating in read reply: "
3389 "count %u > recvd %u\n", count, recvd);
3393 xdr_read_pages(xdr, count);
3399 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3401 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3402 struct page *page = *rcvbuf->pages;
3403 struct kvec *iov = rcvbuf->head;
3404 unsigned int nr, pglen = rcvbuf->page_len;
3405 __be32 *end, *entry, *p, *kaddr;
3406 uint32_t len, attrlen, xlen;
3407 int hdrlen, recvd, status;
3409 status = decode_op_hdr(xdr, OP_READDIR);
3413 COPYMEM(readdir->verifier.data, 8);
3414 dprintk("%s: verifier = 0x%x%x\n",
3416 ((u32 *)readdir->verifier.data)[0],
3417 ((u32 *)readdir->verifier.data)[1]);
3420 hdrlen = (char *) p - (char *) iov->iov_base;
3421 recvd = rcvbuf->len - hdrlen;
3424 xdr_read_pages(xdr, pglen);
3426 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3427 kaddr = p = kmap_atomic(page, KM_USER0);
3428 end = p + ((pglen + readdir->pgbase) >> 2);
3430 for (nr = 0; *p++; nr++) {
3433 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3434 p += 2; /* cookie */
3435 len = ntohl(*p++); /* filename length */
3436 if (len > NFS4_MAXNAMLEN) {
3437 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3440 xlen = XDR_QUADLEN(len);
3441 if (end - p < xlen + 1)
3443 dprintk("filename = %*s\n", len, (char *)p);
3445 len = ntohl(*p++); /* bitmap length */
3446 if (end - p < len + 1)
3449 attrlen = XDR_QUADLEN(ntohl(*p++));
3450 if (end - p < attrlen + 2)
3452 p += attrlen; /* attributes */
3455 if (!nr && (entry[0] != 0 || entry[1] == 0))
3458 kunmap_atomic(kaddr, KM_USER0);
3461 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3462 entry[0] = entry[1] = 0;
3463 /* truncate listing ? */
3465 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3470 kunmap_atomic(kaddr, KM_USER0);
3471 return -errno_NFSERR_IO;
3474 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3476 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3477 struct kvec *iov = rcvbuf->head;
3478 int hdrlen, len, recvd;
3483 status = decode_op_hdr(xdr, OP_READLINK);
3487 /* Convert length of symlink */
3490 if (len >= rcvbuf->page_len || len <= 0) {
3491 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3492 return -ENAMETOOLONG;
3494 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3495 recvd = req->rq_rcv_buf.len - hdrlen;
3497 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3498 "count %u > recvd %u\n", len, recvd);
3501 xdr_read_pages(xdr, len);
3503 * The XDR encode routine has set things up so that
3504 * the link text will be copied directly into the
3505 * buffer. We just have to do overflow-checking,
3506 * and and null-terminate the text (the VFS expects
3507 * null-termination).
3509 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3510 kaddr[len+rcvbuf->page_base] = '\0';
3511 kunmap_atomic(kaddr, KM_USER0);
3515 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3519 status = decode_op_hdr(xdr, OP_REMOVE);
3522 status = decode_change_info(xdr, cinfo);
3527 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3528 struct nfs4_change_info *new_cinfo)
3532 status = decode_op_hdr(xdr, OP_RENAME);
3535 if ((status = decode_change_info(xdr, old_cinfo)))
3537 status = decode_change_info(xdr, new_cinfo);
3542 static int decode_renew(struct xdr_stream *xdr)
3544 return decode_op_hdr(xdr, OP_RENEW);
3548 decode_restorefh(struct xdr_stream *xdr)
3550 return decode_op_hdr(xdr, OP_RESTOREFH);
3553 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3559 struct kvec *iov = req->rq_rcv_buf.head;
3563 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3565 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3567 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3570 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3572 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3575 /* We ignore &savep and don't do consistency checks on
3576 * the attr length. Let userspace figure it out.... */
3577 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3578 recvd = req->rq_rcv_buf.len - hdrlen;
3579 if (attrlen > recvd) {
3580 printk(KERN_WARNING "NFS: server cheating in getattr"
3581 " acl reply: attrlen %u > recvd %u\n",
3585 xdr_read_pages(xdr, attrlen);
3588 status = -EOPNOTSUPP;
3595 decode_savefh(struct xdr_stream *xdr)
3597 return decode_op_hdr(xdr, OP_SAVEFH);
3600 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3607 status = decode_op_hdr(xdr, OP_SETATTR);
3612 READ_BUF(bmlen << 2);
3616 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3624 if (opnum != OP_SETCLIENTID) {
3626 "nfs4_decode_setclientid: Server returned operation"
3631 if (nfserr == NFS_OK) {
3632 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3633 READ64(clp->cl_clientid);
3634 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3635 } else if (nfserr == NFSERR_CLID_INUSE) {
3638 /* skip netid string */
3643 /* skip uaddr string */
3647 return -NFSERR_CLID_INUSE;
3649 return -nfs4_stat_to_errno(nfserr);
3654 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3656 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3659 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3664 status = decode_op_hdr(xdr, OP_WRITE);
3670 READ32(res->verf->committed);
3671 COPYMEM(res->verf->verifier, 8);
3675 static int decode_delegreturn(struct xdr_stream *xdr)
3677 return decode_op_hdr(xdr, OP_DELEGRETURN);
3681 * Decode OPEN_DOWNGRADE response
3683 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3685 struct xdr_stream xdr;
3686 struct compound_hdr hdr;
3689 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3690 status = decode_compound_hdr(&xdr, &hdr);
3693 status = decode_putfh(&xdr);
3696 status = decode_open_downgrade(&xdr, res);
3699 decode_getfattr(&xdr, res->fattr, res->server);
3705 * END OF "GENERIC" DECODE ROUTINES.
3709 * Decode ACCESS response
3711 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3713 struct xdr_stream xdr;
3714 struct compound_hdr hdr;
3717 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3718 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3720 if ((status = decode_putfh(&xdr)) == 0)
3721 status = decode_access(&xdr, res);
3727 * Decode LOOKUP response
3729 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3731 struct xdr_stream xdr;
3732 struct compound_hdr hdr;
3735 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3736 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3738 if ((status = decode_putfh(&xdr)) != 0)
3740 if ((status = decode_lookup(&xdr)) != 0)
3742 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3744 status = decode_getfattr(&xdr, res->fattr, res->server);
3750 * Decode LOOKUP_ROOT response
3752 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3754 struct xdr_stream xdr;
3755 struct compound_hdr hdr;
3758 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3759 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3761 if ((status = decode_putrootfh(&xdr)) != 0)
3763 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3764 status = decode_getfattr(&xdr, res->fattr, res->server);
3770 * Decode REMOVE response
3772 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_remove_res *res)
3774 struct xdr_stream xdr;
3775 struct compound_hdr hdr;
3778 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3779 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3781 if ((status = decode_putfh(&xdr)) != 0)
3783 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3785 decode_getfattr(&xdr, res->dir_attr, res->server);
3791 * Decode RENAME response
3793 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3795 struct xdr_stream xdr;
3796 struct compound_hdr hdr;
3799 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3800 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3802 if ((status = decode_putfh(&xdr)) != 0)
3804 if ((status = decode_savefh(&xdr)) != 0)
3806 if ((status = decode_putfh(&xdr)) != 0)
3808 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3810 /* Current FH is target directory */
3811 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3813 if ((status = decode_restorefh(&xdr)) != 0)
3815 decode_getfattr(&xdr, res->old_fattr, res->server);
3821 * Decode LINK response
3823 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3825 struct xdr_stream xdr;
3826 struct compound_hdr hdr;
3829 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3830 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3832 if ((status = decode_putfh(&xdr)) != 0)
3834 if ((status = decode_savefh(&xdr)) != 0)
3836 if ((status = decode_putfh(&xdr)) != 0)
3838 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3841 * Note order: OP_LINK leaves the directory as the current
3844 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3846 if ((status = decode_restorefh(&xdr)) != 0)
3848 decode_getfattr(&xdr, res->fattr, res->server);
3854 * Decode CREATE response
3856 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3858 struct xdr_stream xdr;
3859 struct compound_hdr hdr;
3862 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3863 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3865 if ((status = decode_putfh(&xdr)) != 0)
3867 if ((status = decode_savefh(&xdr)) != 0)
3869 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3871 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3873 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3875 if ((status = decode_restorefh(&xdr)) != 0)
3877 decode_getfattr(&xdr, res->dir_fattr, res->server);
3883 * Decode SYMLINK response
3885 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3887 return nfs4_xdr_dec_create(rqstp, p, res);
3891 * Decode GETATTR response
3893 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3895 struct xdr_stream xdr;
3896 struct compound_hdr hdr;
3899 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3900 status = decode_compound_hdr(&xdr, &hdr);
3903 status = decode_putfh(&xdr);
3906 status = decode_getfattr(&xdr, res->fattr, res->server);
3913 * Encode an SETACL request
3916 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3918 struct xdr_stream xdr;
3919 struct compound_hdr hdr = {
3924 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3925 encode_compound_hdr(&xdr, &hdr);
3926 status = encode_putfh(&xdr, args->fh);
3929 status = encode_setacl(&xdr, args);
3934 * Decode SETACL response
3937 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
3939 struct xdr_stream xdr;
3940 struct compound_hdr hdr;
3943 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3944 status = decode_compound_hdr(&xdr, &hdr);
3947 status = decode_putfh(&xdr);
3950 status = decode_setattr(&xdr, res);
3956 * Decode GETACL response
3959 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
3961 struct xdr_stream xdr;
3962 struct compound_hdr hdr;
3965 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3966 status = decode_compound_hdr(&xdr, &hdr);
3969 status = decode_putfh(&xdr);
3972 status = decode_getacl(&xdr, rqstp, acl_len);
3979 * Decode CLOSE response
3981 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3983 struct xdr_stream xdr;
3984 struct compound_hdr hdr;
3987 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3988 status = decode_compound_hdr(&xdr, &hdr);
3991 status = decode_putfh(&xdr);
3994 status = decode_close(&xdr, res);
3998 * Note: Server may do delete on close for this file
3999 * in which case the getattr call will fail with
4000 * an ESTALE error. Shouldn't be a problem,
4001 * though, since fattr->valid will remain unset.
4003 decode_getfattr(&xdr, res->fattr, res->server);
4009 * Decode OPEN response
4011 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4013 struct xdr_stream xdr;
4014 struct compound_hdr hdr;
4017 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4018 status = decode_compound_hdr(&xdr, &hdr);
4021 status = decode_putfh(&xdr);
4024 status = decode_savefh(&xdr);
4027 status = decode_open(&xdr, res);
4030 status = decode_getfh(&xdr, &res->fh);
4033 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4035 if ((status = decode_restorefh(&xdr)) != 0)
4037 decode_getfattr(&xdr, res->dir_attr, res->server);
4043 * Decode OPEN_CONFIRM response
4045 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4047 struct xdr_stream xdr;
4048 struct compound_hdr hdr;
4051 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4052 status = decode_compound_hdr(&xdr, &hdr);
4055 status = decode_putfh(&xdr);
4058 status = decode_open_confirm(&xdr, res);
4064 * Decode OPEN response
4066 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4068 struct xdr_stream xdr;
4069 struct compound_hdr hdr;
4072 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4073 status = decode_compound_hdr(&xdr, &hdr);
4076 status = decode_putfh(&xdr);
4079 status = decode_open(&xdr, res);
4082 decode_getfattr(&xdr, res->f_attr, res->server);
4088 * Decode SETATTR response
4090 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4092 struct xdr_stream xdr;
4093 struct compound_hdr hdr;
4096 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4097 status = decode_compound_hdr(&xdr, &hdr);
4100 status = decode_putfh(&xdr);
4103 status = decode_setattr(&xdr, res);
4106 status = decode_getfattr(&xdr, res->fattr, res->server);
4107 if (status == NFS4ERR_DELAY)
4114 * Decode LOCK response
4116 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4118 struct xdr_stream xdr;
4119 struct compound_hdr hdr;
4122 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4123 status = decode_compound_hdr(&xdr, &hdr);
4126 status = decode_putfh(&xdr);
4129 status = decode_lock(&xdr, res);
4135 * Decode LOCKT response
4137 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4139 struct xdr_stream xdr;
4140 struct compound_hdr hdr;
4143 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4144 status = decode_compound_hdr(&xdr, &hdr);
4147 status = decode_putfh(&xdr);
4150 status = decode_lockt(&xdr, res);
4156 * Decode LOCKU response
4158 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4160 struct xdr_stream xdr;
4161 struct compound_hdr hdr;
4164 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4165 status = decode_compound_hdr(&xdr, &hdr);
4168 status = decode_putfh(&xdr);
4171 status = decode_locku(&xdr, res);
4177 * Decode READLINK response
4179 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
4181 struct xdr_stream xdr;
4182 struct compound_hdr hdr;
4185 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4186 status = decode_compound_hdr(&xdr, &hdr);
4189 status = decode_putfh(&xdr);
4192 status = decode_readlink(&xdr, rqstp);
4198 * Decode READDIR response
4200 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4202 struct xdr_stream xdr;
4203 struct compound_hdr hdr;
4206 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4207 status = decode_compound_hdr(&xdr, &hdr);
4210 status = decode_putfh(&xdr);
4213 status = decode_readdir(&xdr, rqstp, res);
4219 * Decode Read response
4221 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4223 struct xdr_stream xdr;
4224 struct compound_hdr hdr;
4227 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4228 status = decode_compound_hdr(&xdr, &hdr);
4231 status = decode_putfh(&xdr);
4234 status = decode_read(&xdr, rqstp, res);
4236 status = res->count;
4242 * Decode WRITE response
4244 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4246 struct xdr_stream xdr;
4247 struct compound_hdr hdr;
4250 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4251 status = decode_compound_hdr(&xdr, &hdr);
4254 status = decode_putfh(&xdr);
4257 status = decode_write(&xdr, res);
4260 decode_getfattr(&xdr, res->fattr, res->server);
4262 status = res->count;
4268 * Decode COMMIT response
4270 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4272 struct xdr_stream xdr;
4273 struct compound_hdr hdr;
4276 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4277 status = decode_compound_hdr(&xdr, &hdr);
4280 status = decode_putfh(&xdr);
4283 status = decode_commit(&xdr, res);
4286 decode_getfattr(&xdr, res->fattr, res->server);
4294 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4296 struct xdr_stream xdr;
4297 struct compound_hdr hdr;
4300 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4301 status = decode_compound_hdr(&xdr, &hdr);
4303 status = decode_putfh(&xdr);
4305 status = decode_fsinfo(&xdr, fsinfo);
4307 status = -nfs4_stat_to_errno(hdr.status);
4314 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
4316 struct xdr_stream xdr;
4317 struct compound_hdr hdr;
4320 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4321 status = decode_compound_hdr(&xdr, &hdr);
4323 status = decode_putfh(&xdr);
4325 status = decode_pathconf(&xdr, pathconf);
4332 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
4334 struct xdr_stream xdr;
4335 struct compound_hdr hdr;
4338 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4339 status = decode_compound_hdr(&xdr, &hdr);
4341 status = decode_putfh(&xdr);
4343 status = decode_statfs(&xdr, fsstat);
4348 * GETATTR_BITMAP request
4350 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4352 struct xdr_stream xdr;
4353 struct compound_hdr hdr;
4356 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4357 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4359 if ((status = decode_putfh(&xdr)) != 0)
4361 status = decode_server_caps(&xdr, res);
4367 * Decode RENEW response
4369 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4371 struct xdr_stream xdr;
4372 struct compound_hdr hdr;
4375 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4376 status = decode_compound_hdr(&xdr, &hdr);
4378 status = decode_renew(&xdr);
4383 * a SETCLIENTID request
4385 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4386 struct nfs_client *clp)
4388 struct xdr_stream xdr;
4389 struct compound_hdr hdr;
4392 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4393 status = decode_compound_hdr(&xdr, &hdr);
4395 status = decode_setclientid(&xdr, clp);
4397 status = -nfs4_stat_to_errno(hdr.status);
4402 * a SETCLIENTID_CONFIRM request
4404 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4406 struct xdr_stream xdr;
4407 struct compound_hdr hdr;
4410 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4411 status = decode_compound_hdr(&xdr, &hdr);
4413 status = decode_setclientid_confirm(&xdr);
4415 status = decode_putrootfh(&xdr);
4417 status = decode_fsinfo(&xdr, fsinfo);
4419 status = -nfs4_stat_to_errno(hdr.status);
4424 * DELEGRETURN request
4426 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4428 struct xdr_stream xdr;
4429 struct compound_hdr hdr;
4432 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4433 status = decode_compound_hdr(&xdr, &hdr);
4436 status = decode_putfh(&xdr);
4439 status = decode_delegreturn(&xdr);
4440 decode_getfattr(&xdr, res->fattr, res->server);
4446 * FS_LOCATIONS request
4448 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
4450 struct xdr_stream xdr;
4451 struct compound_hdr hdr;
4454 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4455 status = decode_compound_hdr(&xdr, &hdr);
4458 if ((status = decode_putfh(&xdr)) != 0)
4460 if ((status = decode_lookup(&xdr)) != 0)
4462 xdr_enter_page(&xdr, PAGE_SIZE);
4463 status = decode_getfattr(&xdr, &res->fattr, res->server);
4468 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4470 uint32_t bitmap[2] = {0};
4475 return ERR_PTR(-EAGAIN);
4477 return ERR_PTR(-EBADCOOKIE);
4480 entry->prev_cookie = entry->cookie;
4481 p = xdr_decode_hyper(p, &entry->cookie);
4482 entry->len = ntohl(*p++);
4483 entry->name = (const char *) p;
4484 p += XDR_QUADLEN(entry->len);
4487 * In case the server doesn't return an inode number,
4488 * we fake one here. (We don't use inode number 0,
4489 * since glibc seems to choke on it...)
4493 len = ntohl(*p++); /* bitmap length */
4495 bitmap[0] = ntohl(*p++);
4497 bitmap[1] = ntohl(*p++);
4501 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4503 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4504 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4505 /* Ignore the return value of rdattr_error for now */
4509 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4510 xdr_decode_hyper(p, &entry->ino);
4511 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4512 xdr_decode_hyper(p, &entry->ino);
4516 entry->eof = !p[0] && p[1];
4521 * We need to translate between nfs status return values and
4522 * the local errno values which may not be the same.
4529 { NFS4ERR_PERM, EPERM },
4530 { NFS4ERR_NOENT, ENOENT },
4531 { NFS4ERR_IO, errno_NFSERR_IO },
4532 { NFS4ERR_NXIO, ENXIO },
4533 { NFS4ERR_ACCESS, EACCES },
4534 { NFS4ERR_EXIST, EEXIST },
4535 { NFS4ERR_XDEV, EXDEV },
4536 { NFS4ERR_NOTDIR, ENOTDIR },
4537 { NFS4ERR_ISDIR, EISDIR },
4538 { NFS4ERR_INVAL, EINVAL },
4539 { NFS4ERR_FBIG, EFBIG },
4540 { NFS4ERR_NOSPC, ENOSPC },
4541 { NFS4ERR_ROFS, EROFS },
4542 { NFS4ERR_MLINK, EMLINK },
4543 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4544 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4545 { NFS4ERR_DQUOT, EDQUOT },
4546 { NFS4ERR_STALE, ESTALE },
4547 { NFS4ERR_BADHANDLE, EBADHANDLE },
4548 { NFS4ERR_BADOWNER, EINVAL },
4549 { NFS4ERR_BADNAME, EINVAL },
4550 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4551 { NFS4ERR_NOTSUPP, ENOTSUPP },
4552 { NFS4ERR_TOOSMALL, ETOOSMALL },
4553 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4554 { NFS4ERR_BADTYPE, EBADTYPE },
4555 { NFS4ERR_LOCKED, EAGAIN },
4556 { NFS4ERR_RESOURCE, EREMOTEIO },
4557 { NFS4ERR_SYMLINK, ELOOP },
4558 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4559 { NFS4ERR_DEADLOCK, EDEADLK },
4560 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4561 * to be handled by a
4568 * Convert an NFS error code to a local one.
4569 * This one is used jointly by NFSv2 and NFSv3.
4572 nfs4_stat_to_errno(int stat)
4575 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4576 if (nfs_errtbl[i].stat == stat)
4577 return nfs_errtbl[i].errno;
4579 if (stat <= 10000 || stat > 10100) {
4580 /* The server is looney tunes. */
4581 return ESERVERFAULT;
4583 /* If we cannot translate the error, the recovery routines should
4585 * Note: remaining NFSv4 error codes have values > 10000, so should
4586 * not conflict with native Linux error codes.
4591 #define PROC(proc, argtype, restype) \
4592 [NFSPROC4_CLNT_##proc] = { \
4593 .p_proc = NFSPROC4_COMPOUND, \
4594 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4595 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4596 .p_arglen = NFS4_##argtype##_sz, \
4597 .p_replen = NFS4_##restype##_sz, \
4598 .p_statidx = NFSPROC4_CLNT_##proc, \
4602 struct rpc_procinfo nfs4_procedures[] = {
4603 PROC(READ, enc_read, dec_read),
4604 PROC(WRITE, enc_write, dec_write),
4605 PROC(COMMIT, enc_commit, dec_commit),
4606 PROC(OPEN, enc_open, dec_open),
4607 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4608 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4609 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4610 PROC(CLOSE, enc_close, dec_close),
4611 PROC(SETATTR, enc_setattr, dec_setattr),
4612 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4613 PROC(RENEW, enc_renew, dec_renew),
4614 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4615 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4616 PROC(LOCK, enc_lock, dec_lock),
4617 PROC(LOCKT, enc_lockt, dec_lockt),
4618 PROC(LOCKU, enc_locku, dec_locku),
4619 PROC(ACCESS, enc_access, dec_access),
4620 PROC(GETATTR, enc_getattr, dec_getattr),
4621 PROC(LOOKUP, enc_lookup, dec_lookup),
4622 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4623 PROC(REMOVE, enc_remove, dec_remove),
4624 PROC(RENAME, enc_rename, dec_rename),
4625 PROC(LINK, enc_link, dec_link),
4626 PROC(SYMLINK, enc_symlink, dec_symlink),
4627 PROC(CREATE, enc_create, dec_create),
4628 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4629 PROC(STATFS, enc_statfs, dec_statfs),
4630 PROC(READLINK, enc_readlink, dec_readlink),
4631 PROC(READDIR, enc_readdir, dec_readdir),
4632 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4633 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4634 PROC(GETACL, enc_getacl, dec_getacl),
4635 PROC(SETACL, enc_setacl, dec_setacl),
4636 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4639 struct rpc_version nfs_version4 = {
4641 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4642 .procs = nfs4_procedures