4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 4)
74 #define lock_owner_id_maxsz (1 + 4)
75 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
76 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78 #define op_encode_hdr_maxsz (1)
79 #define op_decode_hdr_maxsz (2)
80 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
87 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
92 #define nfs4_fattr_bitmap_maxsz 3
93 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
94 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
96 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 /* This is based on getfattr, which uses the most attributes: */
99 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
101 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
104 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
110 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
111 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
114 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116 #define decode_renew_maxsz (op_decode_hdr_maxsz)
117 #define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
125 #define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
128 1024) /* large value for CLID_INUSE */
129 #define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132 #define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
134 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
136 #define encode_share_access_maxsz \
138 #define encode_createmode_maxsz (1 + encode_attrs_maxsz)
139 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141 #define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
147 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
149 #define decode_change_info_maxsz (5)
150 #define decode_open_maxsz (op_decode_hdr_maxsz + \
151 decode_stateid_maxsz + \
152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
155 #define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158 #define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161 #define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165 #define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168 #define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170 #define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
175 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177 #define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
185 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186 #define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188 #define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
193 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
197 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
199 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
202 #define encode_link_maxsz (op_encode_hdr_maxsz + \
204 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
205 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
207 1 + encode_stateid_maxsz + 8)
208 #define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz)
210 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz)
212 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
213 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
216 encode_stateid_maxsz + \
218 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz)
220 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
222 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
226 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227 #define encode_create_maxsz (op_encode_hdr_maxsz + \
228 1 + 2 + nfs4_name_maxsz + \
230 #define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
233 #define encode_statfs_maxsz (encode_getattr_maxsz)
234 #define decode_statfs_maxsz (decode_getattr_maxsz)
235 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
237 #define encode_getacl_maxsz (encode_getattr_maxsz)
238 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
239 nfs4_fattr_bitmap_maxsz + 1)
240 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
241 encode_stateid_maxsz + 3)
242 #define decode_setacl_maxsz (decode_setattr_maxsz)
243 #define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245 #define decode_fs_locations_maxsz \
248 #if defined(CONFIG_NFS_V4_1)
249 #define encode_sequence_maxsz 0 /* stub */
250 #define decode_sequence_maxsz 0 /* stub */
251 #else /* CONFIG_NFS_V4_1 */
252 #define encode_sequence_maxsz 0
253 #define decode_sequence_maxsz 0
254 #endif /* CONFIG_NFS_V4_1 */
256 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
257 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
258 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
259 encode_sequence_maxsz + \
260 encode_putfh_maxsz + \
262 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
263 decode_sequence_maxsz + \
264 decode_putfh_maxsz + \
266 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
267 encode_sequence_maxsz + \
268 encode_putfh_maxsz + \
269 encode_readlink_maxsz)
270 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
271 decode_sequence_maxsz + \
272 decode_putfh_maxsz + \
273 decode_readlink_maxsz)
274 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
275 encode_sequence_maxsz + \
276 encode_putfh_maxsz + \
277 encode_readdir_maxsz)
278 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
279 decode_sequence_maxsz + \
280 decode_putfh_maxsz + \
281 decode_readdir_maxsz)
282 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
283 encode_sequence_maxsz + \
284 encode_putfh_maxsz + \
285 encode_write_maxsz + \
286 encode_getattr_maxsz)
287 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
288 decode_sequence_maxsz + \
289 decode_putfh_maxsz + \
290 decode_write_maxsz + \
291 decode_getattr_maxsz)
292 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
293 encode_sequence_maxsz + \
294 encode_putfh_maxsz + \
295 encode_commit_maxsz + \
296 encode_getattr_maxsz)
297 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
298 decode_sequence_maxsz + \
299 decode_putfh_maxsz + \
300 decode_commit_maxsz + \
301 decode_getattr_maxsz)
302 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
303 encode_sequence_maxsz + \
304 encode_putfh_maxsz + \
305 encode_savefh_maxsz + \
306 encode_open_maxsz + \
307 encode_getfh_maxsz + \
308 encode_getattr_maxsz + \
309 encode_restorefh_maxsz + \
310 encode_getattr_maxsz)
311 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
312 decode_sequence_maxsz + \
313 decode_putfh_maxsz + \
314 decode_savefh_maxsz + \
315 decode_open_maxsz + \
316 decode_getfh_maxsz + \
317 decode_getattr_maxsz + \
318 decode_restorefh_maxsz + \
319 decode_getattr_maxsz)
320 #define NFS4_enc_open_confirm_sz \
321 (compound_encode_hdr_maxsz + \
322 encode_putfh_maxsz + \
323 encode_open_confirm_maxsz)
324 #define NFS4_dec_open_confirm_sz \
325 (compound_decode_hdr_maxsz + \
326 decode_putfh_maxsz + \
327 decode_open_confirm_maxsz)
328 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
329 encode_sequence_maxsz + \
330 encode_putfh_maxsz + \
331 encode_open_maxsz + \
332 encode_getattr_maxsz)
333 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
334 decode_sequence_maxsz + \
335 decode_putfh_maxsz + \
336 decode_open_maxsz + \
337 decode_getattr_maxsz)
338 #define NFS4_enc_open_downgrade_sz \
339 (compound_encode_hdr_maxsz + \
340 encode_sequence_maxsz + \
341 encode_putfh_maxsz + \
342 encode_open_downgrade_maxsz + \
343 encode_getattr_maxsz)
344 #define NFS4_dec_open_downgrade_sz \
345 (compound_decode_hdr_maxsz + \
346 decode_sequence_maxsz + \
347 decode_putfh_maxsz + \
348 decode_open_downgrade_maxsz + \
349 decode_getattr_maxsz)
350 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
351 encode_sequence_maxsz + \
352 encode_putfh_maxsz + \
353 encode_close_maxsz + \
354 encode_getattr_maxsz)
355 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
356 decode_sequence_maxsz + \
357 decode_putfh_maxsz + \
358 decode_close_maxsz + \
359 decode_getattr_maxsz)
360 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
361 encode_sequence_maxsz + \
362 encode_putfh_maxsz + \
363 encode_setattr_maxsz + \
364 encode_getattr_maxsz)
365 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
366 decode_sequence_maxsz + \
367 decode_putfh_maxsz + \
368 decode_setattr_maxsz + \
369 decode_getattr_maxsz)
370 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
371 encode_sequence_maxsz + \
372 encode_putfh_maxsz + \
374 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
375 decode_sequence_maxsz + \
376 decode_putfh_maxsz + \
378 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
380 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
382 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
383 encode_setclientid_maxsz)
384 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
385 decode_setclientid_maxsz)
386 #define NFS4_enc_setclientid_confirm_sz \
387 (compound_encode_hdr_maxsz + \
388 encode_setclientid_confirm_maxsz + \
389 encode_putrootfh_maxsz + \
391 #define NFS4_dec_setclientid_confirm_sz \
392 (compound_decode_hdr_maxsz + \
393 decode_setclientid_confirm_maxsz + \
394 decode_putrootfh_maxsz + \
396 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
397 encode_sequence_maxsz + \
398 encode_putfh_maxsz + \
400 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
401 decode_sequence_maxsz + \
402 decode_putfh_maxsz + \
404 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
405 encode_sequence_maxsz + \
406 encode_putfh_maxsz + \
408 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
409 decode_sequence_maxsz + \
410 decode_putfh_maxsz + \
412 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
413 encode_sequence_maxsz + \
414 encode_putfh_maxsz + \
416 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
417 decode_sequence_maxsz + \
418 decode_putfh_maxsz + \
420 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
421 encode_sequence_maxsz + \
422 encode_putfh_maxsz + \
423 encode_access_maxsz + \
424 encode_getattr_maxsz)
425 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
426 decode_sequence_maxsz + \
427 decode_putfh_maxsz + \
428 decode_access_maxsz + \
429 decode_getattr_maxsz)
430 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
431 encode_sequence_maxsz + \
432 encode_putfh_maxsz + \
433 encode_getattr_maxsz)
434 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
435 decode_sequence_maxsz + \
436 decode_putfh_maxsz + \
437 decode_getattr_maxsz)
438 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
439 encode_sequence_maxsz + \
440 encode_putfh_maxsz + \
441 encode_lookup_maxsz + \
442 encode_getattr_maxsz + \
444 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
445 decode_sequence_maxsz + \
446 decode_putfh_maxsz + \
447 decode_lookup_maxsz + \
448 decode_getattr_maxsz + \
450 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
451 encode_sequence_maxsz + \
452 encode_putrootfh_maxsz + \
453 encode_getattr_maxsz + \
455 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
456 decode_sequence_maxsz + \
457 decode_putrootfh_maxsz + \
458 decode_getattr_maxsz + \
460 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
461 encode_sequence_maxsz + \
462 encode_putfh_maxsz + \
463 encode_remove_maxsz + \
464 encode_getattr_maxsz)
465 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
466 decode_sequence_maxsz + \
467 decode_putfh_maxsz + \
468 decode_remove_maxsz + \
469 decode_getattr_maxsz)
470 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
471 encode_sequence_maxsz + \
472 encode_putfh_maxsz + \
473 encode_savefh_maxsz + \
474 encode_putfh_maxsz + \
475 encode_rename_maxsz + \
476 encode_getattr_maxsz + \
477 encode_restorefh_maxsz + \
478 encode_getattr_maxsz)
479 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
480 decode_sequence_maxsz + \
481 decode_putfh_maxsz + \
482 decode_savefh_maxsz + \
483 decode_putfh_maxsz + \
484 decode_rename_maxsz + \
485 decode_getattr_maxsz + \
486 decode_restorefh_maxsz + \
487 decode_getattr_maxsz)
488 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
489 encode_sequence_maxsz + \
490 encode_putfh_maxsz + \
491 encode_savefh_maxsz + \
492 encode_putfh_maxsz + \
493 encode_link_maxsz + \
494 decode_getattr_maxsz + \
495 encode_restorefh_maxsz + \
496 decode_getattr_maxsz)
497 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
498 decode_sequence_maxsz + \
499 decode_putfh_maxsz + \
500 decode_savefh_maxsz + \
501 decode_putfh_maxsz + \
502 decode_link_maxsz + \
503 decode_getattr_maxsz + \
504 decode_restorefh_maxsz + \
505 decode_getattr_maxsz)
506 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
507 encode_sequence_maxsz + \
508 encode_putfh_maxsz + \
509 encode_symlink_maxsz + \
510 encode_getattr_maxsz + \
512 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
513 decode_sequence_maxsz + \
514 decode_putfh_maxsz + \
515 decode_symlink_maxsz + \
516 decode_getattr_maxsz + \
518 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
519 encode_sequence_maxsz + \
520 encode_putfh_maxsz + \
521 encode_savefh_maxsz + \
522 encode_create_maxsz + \
523 encode_getfh_maxsz + \
524 encode_getattr_maxsz + \
525 encode_restorefh_maxsz + \
526 encode_getattr_maxsz)
527 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
528 decode_sequence_maxsz + \
529 decode_putfh_maxsz + \
530 decode_savefh_maxsz + \
531 decode_create_maxsz + \
532 decode_getfh_maxsz + \
533 decode_getattr_maxsz + \
534 decode_restorefh_maxsz + \
535 decode_getattr_maxsz)
536 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
537 encode_sequence_maxsz + \
538 encode_putfh_maxsz + \
539 encode_getattr_maxsz)
540 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
541 decode_sequence_maxsz + \
542 decode_putfh_maxsz + \
543 decode_getattr_maxsz)
544 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
545 encode_sequence_maxsz + \
546 encode_putfh_maxsz + \
548 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
549 decode_sequence_maxsz + \
550 decode_putfh_maxsz + \
552 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
553 encode_sequence_maxsz + \
554 encode_putfh_maxsz + \
555 encode_getattr_maxsz)
556 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
557 decode_sequence_maxsz + \
558 decode_putfh_maxsz + \
559 decode_getattr_maxsz)
560 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
561 encode_sequence_maxsz + \
562 encode_putfh_maxsz + \
563 encode_delegreturn_maxsz + \
564 encode_getattr_maxsz)
565 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
566 decode_sequence_maxsz + \
567 decode_delegreturn_maxsz + \
568 decode_getattr_maxsz)
569 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
570 encode_sequence_maxsz + \
571 encode_putfh_maxsz + \
573 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
574 decode_sequence_maxsz + \
575 decode_putfh_maxsz + \
577 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
578 encode_sequence_maxsz + \
579 encode_putfh_maxsz + \
581 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
582 decode_sequence_maxsz + \
583 decode_putfh_maxsz + \
585 #define NFS4_enc_fs_locations_sz \
586 (compound_encode_hdr_maxsz + \
587 encode_sequence_maxsz + \
588 encode_putfh_maxsz + \
589 encode_lookup_maxsz + \
590 encode_fs_locations_maxsz)
591 #define NFS4_dec_fs_locations_sz \
592 (compound_decode_hdr_maxsz + \
593 decode_sequence_maxsz + \
594 decode_putfh_maxsz + \
595 decode_lookup_maxsz + \
596 decode_fs_locations_maxsz)
598 static const umode_t nfs_type2fmt[] = {
605 [NF4SOCK] = S_IFSOCK,
611 struct compound_hdr {
617 uint32_t replen; /* expected reply words */
622 * START OF "GENERIC" ENCODE ROUTINES.
623 * These may look a little ugly since they are imported from a "generic"
624 * set of XDR encode/decode routines which are intended to be shared by
625 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
627 * If the pain of reading these is too great, it should be a straightforward
628 * task to translate them into Linux-specific versions which are more
629 * consistent with the style used in NFSv2/v3...
631 #define WRITE32(n) *p++ = htonl(n)
632 #define WRITE64(n) do { \
633 *p++ = htonl((uint32_t)((n) >> 32)); \
634 *p++ = htonl((uint32_t)(n)); \
636 #define WRITEMEM(ptr,nbytes) do { \
637 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
640 #define RESERVE_SPACE(nbytes) do { \
641 p = xdr_reserve_space(xdr, nbytes); \
645 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
649 p = xdr_reserve_space(xdr, 4 + len);
651 xdr_encode_opaque(p, str, len);
654 static void encode_compound_hdr(struct xdr_stream *xdr,
655 struct rpc_rqst *req,
656 struct compound_hdr *hdr)
659 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
661 /* initialize running count of expected bytes in reply.
662 * NOTE: the replied tag SHOULD be the same is the one sent,
663 * but this is not required as a MUST for the server to do so. */
664 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
666 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
667 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
668 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
669 WRITE32(hdr->taglen);
670 WRITEMEM(hdr->tag, hdr->taglen);
671 WRITE32(hdr->minorversion);
676 static void encode_nops(struct compound_hdr *hdr)
678 *hdr->nops_p = htonl(hdr->nops);
681 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
685 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
687 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
690 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
692 char owner_name[IDMAP_NAMESZ];
693 char owner_group[IDMAP_NAMESZ];
694 int owner_namelen = 0;
695 int owner_grouplen = 0;
703 * We reserve enough space to write the entire attribute buffer at once.
704 * In the worst-case, this would be
705 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
706 * = 36 bytes, plus any contribution from variable-length fields
707 * such as owner/group.
712 if (iap->ia_valid & ATTR_SIZE)
714 if (iap->ia_valid & ATTR_MODE)
716 if (iap->ia_valid & ATTR_UID) {
717 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
718 if (owner_namelen < 0) {
719 dprintk("nfs: couldn't resolve uid %d to string\n",
722 strcpy(owner_name, "nobody");
723 owner_namelen = sizeof("nobody") - 1;
726 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
728 if (iap->ia_valid & ATTR_GID) {
729 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
730 if (owner_grouplen < 0) {
731 dprintk("nfs: couldn't resolve gid %d to string\n",
733 strcpy(owner_group, "nobody");
734 owner_grouplen = sizeof("nobody") - 1;
737 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
739 if (iap->ia_valid & ATTR_ATIME_SET)
741 else if (iap->ia_valid & ATTR_ATIME)
743 if (iap->ia_valid & ATTR_MTIME_SET)
745 else if (iap->ia_valid & ATTR_MTIME)
750 * We write the bitmap length now, but leave the bitmap and the attribute
751 * buffer length to be backfilled at the end of this routine.
757 if (iap->ia_valid & ATTR_SIZE) {
758 bmval0 |= FATTR4_WORD0_SIZE;
759 WRITE64(iap->ia_size);
761 if (iap->ia_valid & ATTR_MODE) {
762 bmval1 |= FATTR4_WORD1_MODE;
763 WRITE32(iap->ia_mode & S_IALLUGO);
765 if (iap->ia_valid & ATTR_UID) {
766 bmval1 |= FATTR4_WORD1_OWNER;
767 WRITE32(owner_namelen);
768 WRITEMEM(owner_name, owner_namelen);
770 if (iap->ia_valid & ATTR_GID) {
771 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
772 WRITE32(owner_grouplen);
773 WRITEMEM(owner_group, owner_grouplen);
775 if (iap->ia_valid & ATTR_ATIME_SET) {
776 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
777 WRITE32(NFS4_SET_TO_CLIENT_TIME);
779 WRITE32(iap->ia_mtime.tv_sec);
780 WRITE32(iap->ia_mtime.tv_nsec);
782 else if (iap->ia_valid & ATTR_ATIME) {
783 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
784 WRITE32(NFS4_SET_TO_SERVER_TIME);
786 if (iap->ia_valid & ATTR_MTIME_SET) {
787 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
788 WRITE32(NFS4_SET_TO_CLIENT_TIME);
790 WRITE32(iap->ia_mtime.tv_sec);
791 WRITE32(iap->ia_mtime.tv_nsec);
793 else if (iap->ia_valid & ATTR_MTIME) {
794 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
795 WRITE32(NFS4_SET_TO_SERVER_TIME);
799 * Now we backfill the bitmap and the attribute buffer length.
801 if (len != ((char *)p - (char *)q) + 4) {
802 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
803 len, ((char *)p - (char *)q) + 4);
806 len = (char *)p - (char *)q - 12;
807 *q++ = htonl(bmval0);
808 *q++ = htonl(bmval1);
814 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
822 hdr->replen += decode_access_maxsz;
825 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
829 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
831 WRITE32(arg->seqid->sequence->counter);
832 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
834 hdr->replen += decode_close_maxsz;
837 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
843 WRITE64(args->offset);
844 WRITE32(args->count);
846 hdr->replen += decode_commit_maxsz;
849 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
855 WRITE32(create->ftype);
857 switch (create->ftype) {
860 WRITE32(create->u.symlink.len);
861 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
864 case NF4BLK: case NF4CHR:
866 WRITE32(create->u.device.specdata1);
867 WRITE32(create->u.device.specdata2);
874 RESERVE_SPACE(4 + create->name->len);
875 WRITE32(create->name->len);
876 WRITEMEM(create->name->name, create->name->len);
878 hdr->replen += decode_create_maxsz;
880 encode_attrs(xdr, create->attrs, create->server);
883 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
892 hdr->replen += decode_getattr_maxsz;
895 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
905 hdr->replen += decode_getattr_maxsz;
908 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
910 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
911 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
914 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
916 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
917 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
920 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
922 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
923 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
926 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
933 hdr->replen += decode_getfh_maxsz;
936 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
940 RESERVE_SPACE(8 + name->len);
943 WRITEMEM(name->name, name->len);
945 hdr->replen += decode_link_maxsz;
948 static inline int nfs4_lock_type(struct file_lock *fl, int block)
950 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
951 return block ? NFS4_READW_LT : NFS4_READ_LT;
952 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
955 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
957 if (fl->fl_end == OFFSET_MAX)
959 return fl->fl_end - fl->fl_start + 1;
963 * opcode,type,reclaim,offset,length,new_lock_owner = 32
964 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
966 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
972 WRITE32(nfs4_lock_type(args->fl, args->block));
973 WRITE32(args->reclaim);
974 WRITE64(args->fl->fl_start);
975 WRITE64(nfs4_lock_length(args->fl));
976 WRITE32(args->new_lock_owner);
977 if (args->new_lock_owner){
978 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
979 WRITE32(args->open_seqid->sequence->counter);
980 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
981 WRITE32(args->lock_seqid->sequence->counter);
982 WRITE64(args->lock_owner.clientid);
984 WRITEMEM("lock id:", 8);
985 WRITE64(args->lock_owner.id);
988 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
989 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
990 WRITE32(args->lock_seqid->sequence->counter);
993 hdr->replen += decode_lock_maxsz;
996 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1002 WRITE32(nfs4_lock_type(args->fl, 0));
1003 WRITE64(args->fl->fl_start);
1004 WRITE64(nfs4_lock_length(args->fl));
1005 WRITE64(args->lock_owner.clientid);
1007 WRITEMEM("lock id:", 8);
1008 WRITE64(args->lock_owner.id);
1010 hdr->replen += decode_lockt_maxsz;
1013 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1017 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
1019 WRITE32(nfs4_lock_type(args->fl, 0));
1020 WRITE32(args->seqid->sequence->counter);
1021 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
1022 WRITE64(args->fl->fl_start);
1023 WRITE64(nfs4_lock_length(args->fl));
1025 hdr->replen += decode_locku_maxsz;
1028 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1030 int len = name->len;
1033 RESERVE_SPACE(8 + len);
1036 WRITEMEM(name->name, len);
1038 hdr->replen += decode_lookup_maxsz;
1041 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1046 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1048 WRITE32(NFS4_SHARE_ACCESS_READ);
1051 WRITE32(NFS4_SHARE_ACCESS_WRITE);
1053 case FMODE_READ|FMODE_WRITE:
1054 WRITE32(NFS4_SHARE_ACCESS_BOTH);
1059 WRITE32(0); /* for linux, share_deny = 0 always */
1062 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1066 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1071 WRITE32(arg->seqid->sequence->counter);
1072 encode_share_access(xdr, arg->fmode);
1074 WRITE64(arg->clientid);
1076 WRITEMEM("open id:", 8);
1080 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1085 switch(arg->open_flags & O_EXCL) {
1087 WRITE32(NFS4_CREATE_UNCHECKED);
1088 encode_attrs(xdr, arg->u.attrs, arg->server);
1091 WRITE32(NFS4_CREATE_EXCLUSIVE);
1092 encode_nfs4_verifier(xdr, &arg->u.verifier);
1096 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1101 switch (arg->open_flags & O_CREAT) {
1103 WRITE32(NFS4_OPEN_NOCREATE);
1106 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1107 WRITE32(NFS4_OPEN_CREATE);
1108 encode_createmode(xdr, arg);
1112 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1117 switch (delegation_type) {
1119 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1122 WRITE32(NFS4_OPEN_DELEGATE_READ);
1124 case FMODE_WRITE|FMODE_READ:
1125 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1132 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1137 WRITE32(NFS4_OPEN_CLAIM_NULL);
1138 encode_string(xdr, name->len, name->name);
1141 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1146 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1147 encode_delegation_type(xdr, type);
1150 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1154 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1155 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1156 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1157 encode_string(xdr, name->len, name->name);
1160 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1162 encode_openhdr(xdr, arg);
1163 encode_opentype(xdr, arg);
1164 switch (arg->claim) {
1165 case NFS4_OPEN_CLAIM_NULL:
1166 encode_claim_null(xdr, arg->name);
1168 case NFS4_OPEN_CLAIM_PREVIOUS:
1169 encode_claim_previous(xdr, arg->u.delegation_type);
1171 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1172 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1178 hdr->replen += decode_open_maxsz;
1181 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1185 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1186 WRITE32(OP_OPEN_CONFIRM);
1187 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1188 WRITE32(arg->seqid->sequence->counter);
1190 hdr->replen += decode_open_confirm_maxsz;
1193 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1197 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1198 WRITE32(OP_OPEN_DOWNGRADE);
1199 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1200 WRITE32(arg->seqid->sequence->counter);
1201 encode_share_access(xdr, arg->fmode);
1203 hdr->replen += decode_open_downgrade_maxsz;
1207 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1212 RESERVE_SPACE(8 + len);
1215 WRITEMEM(fh->data, len);
1217 hdr->replen += decode_putfh_maxsz;
1220 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1225 WRITE32(OP_PUTROOTFH);
1227 hdr->replen += decode_putrootfh_maxsz;
1230 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1232 nfs4_stateid stateid;
1235 RESERVE_SPACE(NFS4_STATEID_SIZE);
1236 if (ctx->state != NULL) {
1237 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1238 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1240 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1243 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1250 encode_stateid(xdr, args->context);
1253 WRITE64(args->offset);
1254 WRITE32(args->count);
1256 hdr->replen += decode_read_maxsz;
1259 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1261 uint32_t attrs[2] = {
1262 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1263 FATTR4_WORD1_MOUNTED_ON_FILEID,
1267 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1268 WRITE32(OP_READDIR);
1269 WRITE64(readdir->cookie);
1270 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1271 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1272 WRITE32(readdir->count);
1274 /* Switch to mounted_on_fileid if the server supports it */
1275 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1276 attrs[0] &= ~FATTR4_WORD0_FILEID;
1278 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1279 WRITE32(attrs[0] & readdir->bitmask[0]);
1280 WRITE32(attrs[1] & readdir->bitmask[1]);
1282 hdr->replen += decode_readdir_maxsz;
1283 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1285 (unsigned long long)readdir->cookie,
1286 ((u32 *)readdir->verifier.data)[0],
1287 ((u32 *)readdir->verifier.data)[1],
1288 attrs[0] & readdir->bitmask[0],
1289 attrs[1] & readdir->bitmask[1]);
1292 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1297 WRITE32(OP_READLINK);
1299 hdr->replen += decode_readlink_maxsz;
1302 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1306 RESERVE_SPACE(8 + name->len);
1309 WRITEMEM(name->name, name->len);
1311 hdr->replen += decode_remove_maxsz;
1314 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1318 RESERVE_SPACE(8 + oldname->len);
1320 WRITE32(oldname->len);
1321 WRITEMEM(oldname->name, oldname->len);
1323 RESERVE_SPACE(4 + newname->len);
1324 WRITE32(newname->len);
1325 WRITEMEM(newname->name, newname->len);
1327 hdr->replen += decode_rename_maxsz;
1330 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1336 WRITE64(client_stateid->cl_clientid);
1338 hdr->replen += decode_renew_maxsz;
1342 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1347 WRITE32(OP_RESTOREFH);
1349 hdr->replen += decode_restorefh_maxsz;
1353 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1357 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1358 WRITE32(OP_SETATTR);
1359 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1362 WRITE32(FATTR4_WORD0_ACL);
1363 if (arg->acl_len % 4)
1366 WRITE32(arg->acl_len);
1367 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1369 hdr->replen += decode_setacl_maxsz;
1374 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1381 hdr->replen += decode_savefh_maxsz;
1384 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1388 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1389 WRITE32(OP_SETATTR);
1390 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1392 hdr->replen += decode_setattr_maxsz;
1393 encode_attrs(xdr, arg->iap, server);
1396 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1400 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1401 WRITE32(OP_SETCLIENTID);
1402 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1404 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1406 WRITE32(setclientid->sc_prog);
1407 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1408 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1410 WRITE32(setclientid->sc_cb_ident);
1412 hdr->replen += decode_setclientid_maxsz;
1415 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
1419 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1420 WRITE32(OP_SETCLIENTID_CONFIRM);
1421 WRITE64(client_state->cl_clientid);
1422 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1424 hdr->replen += decode_setclientid_confirm_maxsz;
1427 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1434 encode_stateid(xdr, args->context);
1437 WRITE64(args->offset);
1438 WRITE32(args->stable);
1439 WRITE32(args->count);
1441 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1443 hdr->replen += decode_write_maxsz;
1446 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1450 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1452 WRITE32(OP_DELEGRETURN);
1453 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1455 hdr->replen += decode_delegreturn_maxsz;
1458 /* NFSv4.1 operations */
1459 static void encode_sequence(struct xdr_stream *xdr,
1460 const struct nfs4_sequence_args *args,
1461 struct compound_hdr *hdr)
1463 #if defined(CONFIG_NFS_V4_1)
1464 struct nfs4_session *session = args->sa_session;
1471 hdr->replen += decode_sequence_maxsz;
1472 #endif /* CONFIG_NFS_V4_1 */
1476 * END OF "GENERIC" ENCODE ROUTINES.
1479 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1481 #if defined(CONFIG_NFS_V4_1)
1482 if (args->sa_session)
1483 return args->sa_session->clp->cl_minorversion;
1484 #endif /* CONFIG_NFS_V4_1 */
1489 * Encode an ACCESS request
1491 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1493 struct xdr_stream xdr;
1494 struct compound_hdr hdr = {
1495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1498 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1499 encode_compound_hdr(&xdr, req, &hdr);
1500 encode_sequence(&xdr, &args->seq_args, &hdr);
1501 encode_putfh(&xdr, args->fh, &hdr);
1502 encode_access(&xdr, args->access, &hdr);
1503 encode_getfattr(&xdr, args->bitmask, &hdr);
1509 * Encode LOOKUP request
1511 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1513 struct xdr_stream xdr;
1514 struct compound_hdr hdr = {
1515 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1518 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1519 encode_compound_hdr(&xdr, req, &hdr);
1520 encode_sequence(&xdr, &args->seq_args, &hdr);
1521 encode_putfh(&xdr, args->dir_fh, &hdr);
1522 encode_lookup(&xdr, args->name, &hdr);
1523 encode_getfh(&xdr, &hdr);
1524 encode_getfattr(&xdr, args->bitmask, &hdr);
1530 * Encode LOOKUP_ROOT request
1532 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1534 struct xdr_stream xdr;
1535 struct compound_hdr hdr = {
1536 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1539 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1540 encode_compound_hdr(&xdr, req, &hdr);
1541 encode_sequence(&xdr, &args->seq_args, &hdr);
1542 encode_putrootfh(&xdr, &hdr);
1543 encode_getfh(&xdr, &hdr);
1544 encode_getfattr(&xdr, args->bitmask, &hdr);
1550 * Encode REMOVE request
1552 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1554 struct xdr_stream xdr;
1555 struct compound_hdr hdr = {
1556 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1559 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1560 encode_compound_hdr(&xdr, req, &hdr);
1561 encode_sequence(&xdr, &args->seq_args, &hdr);
1562 encode_putfh(&xdr, args->fh, &hdr);
1563 encode_remove(&xdr, &args->name, &hdr);
1564 encode_getfattr(&xdr, args->bitmask, &hdr);
1570 * Encode RENAME request
1572 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1574 struct xdr_stream xdr;
1575 struct compound_hdr hdr = {
1576 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1579 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1580 encode_compound_hdr(&xdr, req, &hdr);
1581 encode_sequence(&xdr, &args->seq_args, &hdr);
1582 encode_putfh(&xdr, args->old_dir, &hdr);
1583 encode_savefh(&xdr, &hdr);
1584 encode_putfh(&xdr, args->new_dir, &hdr);
1585 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1586 encode_getfattr(&xdr, args->bitmask, &hdr);
1587 encode_restorefh(&xdr, &hdr);
1588 encode_getfattr(&xdr, args->bitmask, &hdr);
1594 * Encode LINK request
1596 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1598 struct xdr_stream xdr;
1599 struct compound_hdr hdr = {
1600 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1603 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1604 encode_compound_hdr(&xdr, req, &hdr);
1605 encode_sequence(&xdr, &args->seq_args, &hdr);
1606 encode_putfh(&xdr, args->fh, &hdr);
1607 encode_savefh(&xdr, &hdr);
1608 encode_putfh(&xdr, args->dir_fh, &hdr);
1609 encode_link(&xdr, args->name, &hdr);
1610 encode_getfattr(&xdr, args->bitmask, &hdr);
1611 encode_restorefh(&xdr, &hdr);
1612 encode_getfattr(&xdr, args->bitmask, &hdr);
1618 * Encode CREATE request
1620 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1622 struct xdr_stream xdr;
1623 struct compound_hdr hdr = {
1624 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1627 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1628 encode_compound_hdr(&xdr, req, &hdr);
1629 encode_sequence(&xdr, &args->seq_args, &hdr);
1630 encode_putfh(&xdr, args->dir_fh, &hdr);
1631 encode_savefh(&xdr, &hdr);
1632 encode_create(&xdr, args, &hdr);
1633 encode_getfh(&xdr, &hdr);
1634 encode_getfattr(&xdr, args->bitmask, &hdr);
1635 encode_restorefh(&xdr, &hdr);
1636 encode_getfattr(&xdr, args->bitmask, &hdr);
1642 * Encode SYMLINK request
1644 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1646 return nfs4_xdr_enc_create(req, p, args);
1650 * Encode GETATTR request
1652 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1654 struct xdr_stream xdr;
1655 struct compound_hdr hdr = {
1656 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1659 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1660 encode_compound_hdr(&xdr, req, &hdr);
1661 encode_sequence(&xdr, &args->seq_args, &hdr);
1662 encode_putfh(&xdr, args->fh, &hdr);
1663 encode_getfattr(&xdr, args->bitmask, &hdr);
1669 * Encode a CLOSE request
1671 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1673 struct xdr_stream xdr;
1674 struct compound_hdr hdr = {
1675 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1678 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1679 encode_compound_hdr(&xdr, req, &hdr);
1680 encode_sequence(&xdr, &args->seq_args, &hdr);
1681 encode_putfh(&xdr, args->fh, &hdr);
1682 encode_close(&xdr, args, &hdr);
1683 encode_getfattr(&xdr, args->bitmask, &hdr);
1689 * Encode an OPEN request
1691 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1693 struct xdr_stream xdr;
1694 struct compound_hdr hdr = {
1695 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1698 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1699 encode_compound_hdr(&xdr, req, &hdr);
1700 encode_sequence(&xdr, &args->seq_args, &hdr);
1701 encode_putfh(&xdr, args->fh, &hdr);
1702 encode_savefh(&xdr, &hdr);
1703 encode_open(&xdr, args, &hdr);
1704 encode_getfh(&xdr, &hdr);
1705 encode_getfattr(&xdr, args->bitmask, &hdr);
1706 encode_restorefh(&xdr, &hdr);
1707 encode_getfattr(&xdr, args->bitmask, &hdr);
1713 * Encode an OPEN_CONFIRM request
1715 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1717 struct xdr_stream xdr;
1718 struct compound_hdr hdr = {
1722 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1723 encode_compound_hdr(&xdr, req, &hdr);
1724 encode_putfh(&xdr, args->fh, &hdr);
1725 encode_open_confirm(&xdr, args, &hdr);
1731 * Encode an OPEN request with no attributes.
1733 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1735 struct xdr_stream xdr;
1736 struct compound_hdr hdr = {
1737 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1740 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1741 encode_compound_hdr(&xdr, req, &hdr);
1742 encode_sequence(&xdr, &args->seq_args, &hdr);
1743 encode_putfh(&xdr, args->fh, &hdr);
1744 encode_open(&xdr, args, &hdr);
1745 encode_getfattr(&xdr, args->bitmask, &hdr);
1751 * Encode an OPEN_DOWNGRADE request
1753 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1755 struct xdr_stream xdr;
1756 struct compound_hdr hdr = {
1757 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1760 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1761 encode_compound_hdr(&xdr, req, &hdr);
1762 encode_sequence(&xdr, &args->seq_args, &hdr);
1763 encode_putfh(&xdr, args->fh, &hdr);
1764 encode_open_downgrade(&xdr, args, &hdr);
1765 encode_getfattr(&xdr, args->bitmask, &hdr);
1771 * Encode a LOCK request
1773 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1775 struct xdr_stream xdr;
1776 struct compound_hdr hdr = {
1777 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1780 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1781 encode_compound_hdr(&xdr, req, &hdr);
1782 encode_sequence(&xdr, &args->seq_args, &hdr);
1783 encode_putfh(&xdr, args->fh, &hdr);
1784 encode_lock(&xdr, args, &hdr);
1790 * Encode a LOCKT request
1792 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1794 struct xdr_stream xdr;
1795 struct compound_hdr hdr = {
1796 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1799 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1800 encode_compound_hdr(&xdr, req, &hdr);
1801 encode_sequence(&xdr, &args->seq_args, &hdr);
1802 encode_putfh(&xdr, args->fh, &hdr);
1803 encode_lockt(&xdr, args, &hdr);
1809 * Encode a LOCKU request
1811 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1813 struct xdr_stream xdr;
1814 struct compound_hdr hdr = {
1815 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1818 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1819 encode_compound_hdr(&xdr, req, &hdr);
1820 encode_sequence(&xdr, &args->seq_args, &hdr);
1821 encode_putfh(&xdr, args->fh, &hdr);
1822 encode_locku(&xdr, args, &hdr);
1828 * Encode a READLINK request
1830 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1832 struct xdr_stream xdr;
1833 struct compound_hdr hdr = {
1834 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1837 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1838 encode_compound_hdr(&xdr, req, &hdr);
1839 encode_sequence(&xdr, &args->seq_args, &hdr);
1840 encode_putfh(&xdr, args->fh, &hdr);
1841 encode_readlink(&xdr, args, req, &hdr);
1843 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
1844 args->pgbase, args->pglen);
1850 * Encode a READDIR request
1852 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1854 struct xdr_stream xdr;
1855 struct compound_hdr hdr = {
1856 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1859 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1860 encode_compound_hdr(&xdr, req, &hdr);
1861 encode_sequence(&xdr, &args->seq_args, &hdr);
1862 encode_putfh(&xdr, args->fh, &hdr);
1863 encode_readdir(&xdr, args, req, &hdr);
1865 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
1866 args->pgbase, args->count);
1867 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1868 __func__, hdr.replen << 2, args->pages,
1869 args->pgbase, args->count);
1875 * Encode a READ request
1877 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1879 struct xdr_stream xdr;
1880 struct compound_hdr hdr = {
1881 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1884 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1885 encode_compound_hdr(&xdr, req, &hdr);
1886 encode_sequence(&xdr, &args->seq_args, &hdr);
1887 encode_putfh(&xdr, args->fh, &hdr);
1888 encode_read(&xdr, args, &hdr);
1890 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
1891 args->pages, args->pgbase, args->count);
1892 req->rq_rcv_buf.flags |= XDRBUF_READ;
1898 * Encode an SETATTR request
1900 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1902 struct xdr_stream xdr;
1903 struct compound_hdr hdr = {
1904 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1907 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1908 encode_compound_hdr(&xdr, req, &hdr);
1909 encode_sequence(&xdr, &args->seq_args, &hdr);
1910 encode_putfh(&xdr, args->fh, &hdr);
1911 encode_setattr(&xdr, args, args->server, &hdr);
1912 encode_getfattr(&xdr, args->bitmask, &hdr);
1918 * Encode a GETACL request
1921 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1922 struct nfs_getaclargs *args)
1924 struct xdr_stream xdr;
1925 struct compound_hdr hdr = {
1926 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1930 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1931 encode_compound_hdr(&xdr, req, &hdr);
1932 encode_sequence(&xdr, &args->seq_args, &hdr);
1933 encode_putfh(&xdr, args->fh, &hdr);
1934 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
1935 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1937 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
1938 args->acl_pages, args->acl_pgbase, args->acl_len);
1944 * Encode a WRITE request
1946 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1948 struct xdr_stream xdr;
1949 struct compound_hdr hdr = {
1950 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1953 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1954 encode_compound_hdr(&xdr, req, &hdr);
1955 encode_sequence(&xdr, &args->seq_args, &hdr);
1956 encode_putfh(&xdr, args->fh, &hdr);
1957 encode_write(&xdr, args, &hdr);
1958 req->rq_snd_buf.flags |= XDRBUF_WRITE;
1959 encode_getfattr(&xdr, args->bitmask, &hdr);
1967 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1969 struct xdr_stream xdr;
1970 struct compound_hdr hdr = {
1971 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1974 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1975 encode_compound_hdr(&xdr, req, &hdr);
1976 encode_sequence(&xdr, &args->seq_args, &hdr);
1977 encode_putfh(&xdr, args->fh, &hdr);
1978 encode_commit(&xdr, args, &hdr);
1979 encode_getfattr(&xdr, args->bitmask, &hdr);
1987 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1989 struct xdr_stream xdr;
1990 struct compound_hdr hdr = {
1991 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1994 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1995 encode_compound_hdr(&xdr, req, &hdr);
1996 encode_sequence(&xdr, &args->seq_args, &hdr);
1997 encode_putfh(&xdr, args->fh, &hdr);
1998 encode_fsinfo(&xdr, args->bitmask, &hdr);
2004 * a PATHCONF request
2006 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
2008 struct xdr_stream xdr;
2009 struct compound_hdr hdr = {
2010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2013 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2014 encode_compound_hdr(&xdr, req, &hdr);
2015 encode_sequence(&xdr, &args->seq_args, &hdr);
2016 encode_putfh(&xdr, args->fh, &hdr);
2017 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2026 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
2028 struct xdr_stream xdr;
2029 struct compound_hdr hdr = {
2030 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2033 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2034 encode_compound_hdr(&xdr, req, &hdr);
2035 encode_sequence(&xdr, &args->seq_args, &hdr);
2036 encode_putfh(&xdr, args->fh, &hdr);
2037 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2038 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2044 * GETATTR_BITMAP request
2046 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2047 struct nfs4_server_caps_arg *args)
2049 struct xdr_stream xdr;
2050 struct compound_hdr hdr = {
2051 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2054 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2055 encode_compound_hdr(&xdr, req, &hdr);
2056 encode_sequence(&xdr, &args->seq_args, &hdr);
2057 encode_putfh(&xdr, args->fhandle, &hdr);
2058 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2059 FATTR4_WORD0_LINK_SUPPORT|
2060 FATTR4_WORD0_SYMLINK_SUPPORT|
2061 FATTR4_WORD0_ACLSUPPORT, &hdr);
2069 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2071 struct xdr_stream xdr;
2072 struct compound_hdr hdr = {
2076 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2077 encode_compound_hdr(&xdr, req, &hdr);
2078 encode_renew(&xdr, clp, &hdr);
2084 * a SETCLIENTID request
2086 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
2088 struct xdr_stream xdr;
2089 struct compound_hdr hdr = {
2093 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2094 encode_compound_hdr(&xdr, req, &hdr);
2095 encode_setclientid(&xdr, sc, &hdr);
2101 * a SETCLIENTID_CONFIRM request
2103 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2105 struct xdr_stream xdr;
2106 struct compound_hdr hdr = {
2109 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2111 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2112 encode_compound_hdr(&xdr, req, &hdr);
2113 encode_setclientid_confirm(&xdr, clp, &hdr);
2114 encode_putrootfh(&xdr, &hdr);
2115 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2121 * DELEGRETURN request
2123 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2125 struct xdr_stream xdr;
2126 struct compound_hdr hdr = {
2127 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2130 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2131 encode_compound_hdr(&xdr, req, &hdr);
2132 encode_sequence(&xdr, &args->seq_args, &hdr);
2133 encode_putfh(&xdr, args->fhandle, &hdr);
2134 encode_delegreturn(&xdr, args->stateid, &hdr);
2135 encode_getfattr(&xdr, args->bitmask, &hdr);
2141 * Encode FS_LOCATIONS request
2143 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2145 struct xdr_stream xdr;
2146 struct compound_hdr hdr = {
2147 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2151 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2152 encode_compound_hdr(&xdr, req, &hdr);
2153 encode_sequence(&xdr, &args->seq_args, &hdr);
2154 encode_putfh(&xdr, args->dir_fh, &hdr);
2155 encode_lookup(&xdr, args->name, &hdr);
2156 replen = hdr.replen; /* get the attribute into args->page */
2157 encode_fs_locations(&xdr, args->bitmask, &hdr);
2159 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2166 * START OF "GENERIC" DECODE ROUTINES.
2167 * These may look a little ugly since they are imported from a "generic"
2168 * set of XDR encode/decode routines which are intended to be shared by
2169 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2171 * If the pain of reading these is too great, it should be a straightforward
2172 * task to translate them into Linux-specific versions which are more
2173 * consistent with the style used in NFSv2/v3...
2175 #define READ32(x) (x) = ntohl(*p++)
2176 #define READ64(x) do { \
2177 (x) = (u64)ntohl(*p++) << 32; \
2178 (x) |= ntohl(*p++); \
2180 #define READTIME(x) do { \
2182 (x.tv_sec) = ntohl(*p++); \
2183 (x.tv_nsec) = ntohl(*p++); \
2185 #define COPYMEM(x,nbytes) do { \
2186 memcpy((x), p, nbytes); \
2187 p += XDR_QUADLEN(nbytes); \
2190 #define READ_BUF(nbytes) do { \
2191 p = xdr_inline_decode(xdr, nbytes); \
2192 if (unlikely(!p)) { \
2193 dprintk("nfs: %s: prematurely hit end of receive" \
2194 " buffer\n", __func__); \
2195 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2196 __func__, xdr->p, nbytes, xdr->end); \
2201 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2208 *string = (char *)p;
2212 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2217 READ32(hdr->status);
2218 READ32(hdr->taglen);
2220 READ_BUF(hdr->taglen + 4);
2221 hdr->tag = (char *)p;
2222 p += XDR_QUADLEN(hdr->taglen);
2224 if (unlikely(hdr->nops < 1))
2225 return nfs4_stat_to_errno(hdr->status);
2229 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2237 if (opnum != expected) {
2238 dprintk("nfs: Server returned operation"
2239 " %d but we issued a request for %d\n",
2244 if (nfserr != NFS_OK)
2245 return nfs4_stat_to_errno(nfserr);
2250 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2253 unsigned int strlen;
2257 return decode_opaque_inline(xdr, &strlen, &str);
2260 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2268 bitmap[0] = bitmap[1] = 0;
2269 READ_BUF((bmlen << 2));
2278 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2288 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2290 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2291 decode_attr_bitmap(xdr, bitmask);
2292 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2294 bitmask[0] = bitmask[1] = 0;
2295 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2299 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2305 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2307 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2310 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2311 dprintk("%s: bad type %d\n", __func__, *type);
2314 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2315 ret = NFS_ATTR_FATTR_TYPE;
2317 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2321 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2327 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2329 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2332 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2333 ret = NFS_ATTR_FATTR_CHANGE;
2335 dprintk("%s: change attribute=%Lu\n", __func__,
2336 (unsigned long long)*change);
2340 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2346 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2348 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2351 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2352 ret = NFS_ATTR_FATTR_SIZE;
2354 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2358 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2363 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2365 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2368 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2370 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2374 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2379 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2381 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2384 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2386 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2390 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2397 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2399 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2401 READ64(fsid->major);
2402 READ64(fsid->minor);
2403 bitmap[0] &= ~FATTR4_WORD0_FSID;
2404 ret = NFS_ATTR_FATTR_FSID;
2406 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
2407 (unsigned long long)fsid->major,
2408 (unsigned long long)fsid->minor);
2412 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2417 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2419 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2422 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2424 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2428 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2432 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2433 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2435 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2438 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2440 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
2444 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2450 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2452 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2455 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2456 ret = NFS_ATTR_FATTR_FILEID;
2458 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2462 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2468 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2470 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2473 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2474 ret = NFS_ATTR_FATTR_FILEID;
2476 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2480 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2486 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2488 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2491 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2493 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
2497 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2503 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2505 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2508 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2510 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
2514 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2520 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2522 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2525 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2527 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
2531 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2542 path->ncomponents = 0;
2543 while (path->ncomponents < n) {
2544 struct nfs4_string *component = &path->components[path->ncomponents];
2545 status = decode_opaque_inline(xdr, &component->len, &component->data);
2546 if (unlikely(status != 0))
2548 if (path->ncomponents != n)
2550 dprintk("%s", component->data);
2551 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2552 path->ncomponents++;
2554 dprintk("cannot parse %d components in path\n", n);
2562 /* a root pathname is sent as a zero component4 */
2563 path->ncomponents = 1;
2564 path->components[0].len=0;
2565 path->components[0].data=NULL;
2566 dprintk("path /\n");
2569 dprintk(" status %d", status);
2574 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2580 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2583 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2585 dprintk("%s: fsroot ", __func__);
2586 status = decode_pathname(xdr, &res->fs_path);
2587 if (unlikely(status != 0))
2593 res->nlocations = 0;
2594 while (res->nlocations < n) {
2596 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2602 dprintk("%s: servers ", __func__);
2603 while (loc->nservers < m) {
2604 struct nfs4_string *server = &loc->servers[loc->nservers];
2605 status = decode_opaque_inline(xdr, &server->len, &server->data);
2606 if (unlikely(status != 0))
2608 dprintk("%s ", server->data);
2609 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2613 dprintk("%s: using first %u of %u servers "
2614 "returned for location %u\n",
2616 NFS4_FS_LOCATION_MAXSERVERS,
2617 m, res->nlocations);
2618 for (i = loc->nservers; i < m; i++) {
2621 status = decode_opaque_inline(xdr, &len, &data);
2622 if (unlikely(status != 0))
2627 status = decode_pathname(xdr, &loc->rootpath);
2628 if (unlikely(status != 0))
2630 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2633 if (res->nlocations != 0)
2634 status = NFS_ATTR_FATTR_V4_REFERRAL;
2636 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
2643 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2649 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2651 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2654 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2656 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
2660 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2666 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2668 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2671 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2673 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
2677 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2683 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2685 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2688 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2690 dprintk("%s: maxname=%u\n", __func__, *maxname);
2694 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2700 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2702 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2706 if (maxread > 0x7FFFFFFF)
2707 maxread = 0x7FFFFFFF;
2708 *res = (uint32_t)maxread;
2709 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2711 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
2715 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2721 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2723 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2727 if (maxwrite > 0x7FFFFFFF)
2728 maxwrite = 0x7FFFFFFF;
2729 *res = (uint32_t)maxwrite;
2730 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2732 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
2736 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
2743 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2745 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2748 *mode = tmp & ~S_IFMT;
2749 bitmap[1] &= ~FATTR4_WORD1_MODE;
2750 ret = NFS_ATTR_FATTR_MODE;
2752 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
2756 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2762 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2764 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2767 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2768 ret = NFS_ATTR_FATTR_NLINK;
2770 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
2774 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2781 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2783 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2787 if (len < XDR_MAX_NETOBJ) {
2788 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
2789 ret = NFS_ATTR_FATTR_OWNER;
2791 dprintk("%s: nfs_map_name_to_uid failed!\n",
2794 dprintk("%s: name too long (%u)!\n",
2796 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2798 dprintk("%s: uid=%d\n", __func__, (int)*uid);
2802 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2809 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2811 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2815 if (len < XDR_MAX_NETOBJ) {
2816 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
2817 ret = NFS_ATTR_FATTR_GROUP;
2819 dprintk("%s: nfs_map_group_to_gid failed!\n",
2822 dprintk("%s: name too long (%u)!\n",
2824 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2826 dprintk("%s: gid=%d\n", __func__, (int)*gid);
2830 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2832 uint32_t major = 0, minor = 0;
2837 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2839 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2845 tmp = MKDEV(major, minor);
2846 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2848 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2849 ret = NFS_ATTR_FATTR_RDEV;
2851 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
2855 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2861 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2863 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2866 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2868 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
2872 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2878 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2880 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2883 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2885 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
2889 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2895 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2897 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2900 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2902 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
2906 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2912 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2914 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2917 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2918 ret = NFS_ATTR_FATTR_SPACE_USED;
2920 dprintk("%s: space used=%Lu\n", __func__,
2921 (unsigned long long)*used);
2925 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2934 time->tv_sec = (time_t)sec;
2935 time->tv_nsec = (long)nsec;
2939 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2945 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2947 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2948 status = decode_attr_time(xdr, time);
2950 status = NFS_ATTR_FATTR_ATIME;
2951 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2953 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
2957 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2963 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2965 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2966 status = decode_attr_time(xdr, time);
2968 status = NFS_ATTR_FATTR_CTIME;
2969 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2971 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
2975 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2981 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2983 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2984 status = decode_attr_time(xdr, time);
2986 status = NFS_ATTR_FATTR_MTIME;
2987 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2989 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
2993 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2995 unsigned int attrwords = XDR_QUADLEN(attrlen);
2996 unsigned int nwords = xdr->p - savep;
2998 if (unlikely(attrwords != nwords)) {
2999 dprintk("%s: server returned incorrect attribute length: "
3003 (attrwords < nwords) ? '<' : '>',
3010 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3015 READ32(cinfo->atomic);
3016 READ64(cinfo->before);
3017 READ64(cinfo->after);
3021 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3027 status = decode_op_hdr(xdr, OP_ACCESS);
3033 access->supported = supp;
3034 access->access = acc;
3038 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3043 status = decode_op_hdr(xdr, OP_CLOSE);
3045 nfs_increment_open_seqid(status, res->seqid);
3048 READ_BUF(NFS4_STATEID_SIZE);
3049 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3053 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3058 status = decode_op_hdr(xdr, OP_COMMIT);
3062 COPYMEM(res->verf->verifier, 8);
3066 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3072 status = decode_op_hdr(xdr, OP_CREATE);
3075 if ((status = decode_change_info(xdr, cinfo)))
3079 READ_BUF(bmlen << 2);
3083 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3086 uint32_t attrlen, bitmap[2] = {0};
3089 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3091 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3093 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3095 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3097 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3099 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3101 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3103 status = verify_attr_len(xdr, savep, attrlen);
3105 dprintk("%s: xdr returned %d!\n", __func__, -status);
3109 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3112 uint32_t attrlen, bitmap[2] = {0};
3115 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3117 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3119 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3122 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3124 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3126 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3128 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3130 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3132 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3135 status = verify_attr_len(xdr, savep, attrlen);
3137 dprintk("%s: xdr returned %d!\n", __func__, -status);
3141 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3144 uint32_t attrlen, bitmap[2] = {0};
3147 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3149 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3151 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3154 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3156 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3159 status = verify_attr_len(xdr, savep, attrlen);
3161 dprintk("%s: xdr returned %d!\n", __func__, -status);
3165 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3175 status = decode_op_hdr(xdr, OP_GETATTR);
3179 status = decode_attr_bitmap(xdr, bitmap);
3183 status = decode_attr_length(xdr, &attrlen, &savep);
3188 status = decode_attr_type(xdr, bitmap, &type);
3193 fattr->mode |= nfs_type2fmt[type];
3194 fattr->valid |= status;
3197 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3200 fattr->valid |= status;
3202 status = decode_attr_size(xdr, bitmap, &fattr->size);
3205 fattr->valid |= status;
3207 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3210 fattr->valid |= status;
3212 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3215 fattr->valid |= status;
3217 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3218 struct nfs4_fs_locations,
3222 fattr->valid |= status;
3224 status = decode_attr_mode(xdr, bitmap, &fmode);
3228 fattr->mode |= fmode;
3229 fattr->valid |= status;
3232 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3235 fattr->valid |= status;
3237 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3240 fattr->valid |= status;
3242 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3245 fattr->valid |= status;
3247 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3250 fattr->valid |= status;
3252 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3255 fattr->valid |= status;
3257 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3260 fattr->valid |= status;
3262 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3265 fattr->valid |= status;
3267 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3270 fattr->valid |= status;
3272 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3275 if (status != 0 && !(fattr->valid & status)) {
3276 fattr->fileid = fileid;
3277 fattr->valid |= status;
3280 status = verify_attr_len(xdr, savep, attrlen);
3282 dprintk("%s: xdr returned %d\n", __func__, -status);
3287 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3290 uint32_t attrlen, bitmap[2];
3293 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3295 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3297 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3300 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3302 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3304 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3306 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3308 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3309 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3311 fsinfo->wtpref = fsinfo->wtmax;
3313 status = verify_attr_len(xdr, savep, attrlen);
3315 dprintk("%s: xdr returned %d!\n", __func__, -status);
3319 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3325 /* Zero handle first to allow comparisons */
3326 memset(fh, 0, sizeof(*fh));
3328 status = decode_op_hdr(xdr, OP_GETFH);
3334 if (len > NFS4_FHSIZE)
3338 COPYMEM(fh->data, len);
3342 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3346 status = decode_op_hdr(xdr, OP_LINK);
3349 return decode_change_info(xdr, cinfo);
3353 * We create the owner, so we know a proper owner.id length is 4.
3355 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3357 uint64_t offset, length, clientid;
3359 uint32_t namelen, type;
3366 fl->fl_start = (loff_t)offset;
3367 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3368 if (length == ~(uint64_t)0)
3369 fl->fl_end = OFFSET_MAX;
3370 fl->fl_type = F_WRLCK;
3372 fl->fl_type = F_RDLCK;
3378 return -NFS4ERR_DENIED;
3381 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3386 status = decode_op_hdr(xdr, OP_LOCK);
3390 READ_BUF(NFS4_STATEID_SIZE);
3391 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3392 } else if (status == -NFS4ERR_DENIED)
3393 status = decode_lock_denied(xdr, NULL);
3394 if (res->open_seqid != NULL)
3395 nfs_increment_open_seqid(status, res->open_seqid);
3396 nfs_increment_lock_seqid(status, res->lock_seqid);
3401 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3404 status = decode_op_hdr(xdr, OP_LOCKT);
3405 if (status == -NFS4ERR_DENIED)
3406 return decode_lock_denied(xdr, res->denied);
3410 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3415 status = decode_op_hdr(xdr, OP_LOCKU);
3417 nfs_increment_lock_seqid(status, res->seqid);
3419 READ_BUF(NFS4_STATEID_SIZE);
3420 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3425 static int decode_lookup(struct xdr_stream *xdr)
3427 return decode_op_hdr(xdr, OP_LOOKUP);
3430 /* This is too sick! */
3431 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3434 uint32_t limit_type, nblocks, blocksize;
3438 switch (limit_type) {
3445 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3450 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3453 uint32_t delegation_type;
3456 READ32(delegation_type);
3457 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3458 res->delegation_type = 0;
3461 READ_BUF(NFS4_STATEID_SIZE+4);
3462 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3463 READ32(res->do_recall);
3465 switch (delegation_type) {
3466 case NFS4_OPEN_DELEGATE_READ:
3467 res->delegation_type = FMODE_READ;
3469 case NFS4_OPEN_DELEGATE_WRITE:
3470 res->delegation_type = FMODE_WRITE|FMODE_READ;
3471 if (decode_space_limit(xdr, &res->maxsize) < 0)
3474 return decode_ace(xdr, NULL, res->server->nfs_client);
3477 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3480 uint32_t savewords, bmlen, i;
3483 status = decode_op_hdr(xdr, OP_OPEN);
3485 nfs_increment_open_seqid(status, res->seqid);
3488 READ_BUF(NFS4_STATEID_SIZE);
3489 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3491 decode_change_info(xdr, &res->cinfo);
3494 READ32(res->rflags);
3499 READ_BUF(bmlen << 2);
3500 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3501 for (i = 0; i < savewords; ++i)
3502 READ32(res->attrset[i]);
3503 for (; i < NFS4_BITMAP_SIZE; i++)
3504 res->attrset[i] = 0;
3506 return decode_delegation(xdr, res);
3508 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
3512 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3517 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3519 nfs_increment_open_seqid(status, res->seqid);
3522 READ_BUF(NFS4_STATEID_SIZE);
3523 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3527 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3532 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3534 nfs_increment_open_seqid(status, res->seqid);
3537 READ_BUF(NFS4_STATEID_SIZE);
3538 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3542 static int decode_putfh(struct xdr_stream *xdr)
3544 return decode_op_hdr(xdr, OP_PUTFH);
3547 static int decode_putrootfh(struct xdr_stream *xdr)
3549 return decode_op_hdr(xdr, OP_PUTROOTFH);
3552 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3554 struct kvec *iov = req->rq_rcv_buf.head;
3556 uint32_t count, eof, recvd, hdrlen;
3559 status = decode_op_hdr(xdr, OP_READ);
3565 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3566 recvd = req->rq_rcv_buf.len - hdrlen;
3567 if (count > recvd) {
3568 dprintk("NFS: server cheating in read reply: "
3569 "count %u > recvd %u\n", count, recvd);
3573 xdr_read_pages(xdr, count);
3579 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3581 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3582 struct page *page = *rcvbuf->pages;
3583 struct kvec *iov = rcvbuf->head;
3585 u32 recvd, pglen = rcvbuf->page_len;
3586 __be32 *end, *entry, *p, *kaddr;
3587 unsigned int nr = 0;
3590 status = decode_op_hdr(xdr, OP_READDIR);
3594 COPYMEM(readdir->verifier.data, 8);
3595 dprintk("%s: verifier = %08x:%08x\n",
3597 ((u32 *)readdir->verifier.data)[0],
3598 ((u32 *)readdir->verifier.data)[1]);
3601 hdrlen = (char *) p - (char *) iov->iov_base;
3602 recvd = rcvbuf->len - hdrlen;
3605 xdr_read_pages(xdr, pglen);
3607 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3608 kaddr = p = kmap_atomic(page, KM_USER0);
3609 end = p + ((pglen + readdir->pgbase) >> 2);
3612 /* Make sure the packet actually has a value_follows and EOF entry */
3613 if ((entry + 1) > end)
3616 for (; *p++; nr++) {
3617 u32 len, attrlen, xlen;
3620 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3621 p += 2; /* cookie */
3622 len = ntohl(*p++); /* filename length */
3623 if (len > NFS4_MAXNAMLEN) {
3624 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3628 xlen = XDR_QUADLEN(len);
3629 if (end - p < xlen + 1)
3631 dprintk("filename = %*s\n", len, (char *)p);
3633 len = ntohl(*p++); /* bitmap length */
3634 if (end - p < len + 1)
3637 attrlen = XDR_QUADLEN(ntohl(*p++));
3638 if (end - p < attrlen + 2)
3640 p += attrlen; /* attributes */
3644 * Apparently some server sends responses that are a valid size, but
3645 * contain no entries, and have value_follows==0 and EOF==0. For
3646 * those, just set the EOF marker.
3648 if (!nr && entry[1] == 0) {
3649 dprintk("NFS: readdir reply truncated!\n");
3653 kunmap_atomic(kaddr, KM_USER0);
3657 * When we get a short packet there are 2 possibilities. We can
3658 * return an error, or fix up the response to look like a valid
3659 * response and return what we have so far. If there are no
3660 * entries and the packet was short, then return -EIO. If there
3661 * are valid entries in the response, return them and pretend that
3662 * the call was successful, but incomplete. The caller can retry the
3663 * readdir starting at the last cookie.
3665 dprintk("%s: short packet at entry %d\n", __func__, nr);
3666 entry[0] = entry[1] = 0;
3670 kunmap_atomic(kaddr, KM_USER0);
3671 return -errno_NFSERR_IO;
3674 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3676 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3677 struct kvec *iov = rcvbuf->head;
3684 status = decode_op_hdr(xdr, OP_READLINK);
3688 /* Convert length of symlink */
3691 if (len >= rcvbuf->page_len || len <= 0) {
3692 dprintk("nfs: server returned giant symlink!\n");
3693 return -ENAMETOOLONG;
3695 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3696 recvd = req->rq_rcv_buf.len - hdrlen;
3698 dprintk("NFS: server cheating in readlink reply: "
3699 "count %u > recvd %u\n", len, recvd);
3702 xdr_read_pages(xdr, len);
3704 * The XDR encode routine has set things up so that
3705 * the link text will be copied directly into the
3706 * buffer. We just have to do overflow-checking,
3707 * and and null-terminate the text (the VFS expects
3708 * null-termination).
3710 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3711 kaddr[len+rcvbuf->page_base] = '\0';
3712 kunmap_atomic(kaddr, KM_USER0);
3716 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3720 status = decode_op_hdr(xdr, OP_REMOVE);
3723 status = decode_change_info(xdr, cinfo);
3728 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3729 struct nfs4_change_info *new_cinfo)
3733 status = decode_op_hdr(xdr, OP_RENAME);
3736 if ((status = decode_change_info(xdr, old_cinfo)))
3738 status = decode_change_info(xdr, new_cinfo);
3743 static int decode_renew(struct xdr_stream *xdr)
3745 return decode_op_hdr(xdr, OP_RENEW);
3749 decode_restorefh(struct xdr_stream *xdr)
3751 return decode_op_hdr(xdr, OP_RESTOREFH);
3754 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3760 struct kvec *iov = req->rq_rcv_buf.head;
3764 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3766 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3768 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3771 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3773 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3777 /* We ignore &savep and don't do consistency checks on
3778 * the attr length. Let userspace figure it out.... */
3779 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3780 recvd = req->rq_rcv_buf.len - hdrlen;
3781 if (attrlen > recvd) {
3782 dprintk("NFS: server cheating in getattr"
3783 " acl reply: attrlen %u > recvd %u\n",
3787 xdr_read_pages(xdr, attrlen);
3790 status = -EOPNOTSUPP;
3797 decode_savefh(struct xdr_stream *xdr)
3799 return decode_op_hdr(xdr, OP_SAVEFH);
3802 static int decode_setattr(struct xdr_stream *xdr)
3808 status = decode_op_hdr(xdr, OP_SETATTR);
3813 READ_BUF(bmlen << 2);
3817 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3825 if (opnum != OP_SETCLIENTID) {
3826 dprintk("nfs: decode_setclientid: Server returned operation"
3831 if (nfserr == NFS_OK) {
3832 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3833 READ64(clp->cl_clientid);
3834 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3835 } else if (nfserr == NFSERR_CLID_INUSE) {
3838 /* skip netid string */
3843 /* skip uaddr string */
3847 return -NFSERR_CLID_INUSE;
3849 return nfs4_stat_to_errno(nfserr);
3854 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3856 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3859 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3864 status = decode_op_hdr(xdr, OP_WRITE);
3870 READ32(res->verf->committed);
3871 COPYMEM(res->verf->verifier, 8);
3875 static int decode_delegreturn(struct xdr_stream *xdr)
3877 return decode_op_hdr(xdr, OP_DELEGRETURN);
3880 static int decode_sequence(struct xdr_stream *xdr,
3881 struct nfs4_sequence_res *res,
3882 struct rpc_rqst *rqstp)
3884 #if defined(CONFIG_NFS_V4_1)
3885 if (!res->sr_session)
3889 #endif /* CONFIG_NFS_V4_1 */
3895 * END OF "GENERIC" DECODE ROUTINES.
3899 * Decode OPEN_DOWNGRADE response
3901 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3903 struct xdr_stream xdr;
3904 struct compound_hdr hdr;
3907 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3908 status = decode_compound_hdr(&xdr, &hdr);
3911 status = decode_sequence(&xdr, &res->seq_res, rqstp);
3914 status = decode_putfh(&xdr);
3917 status = decode_open_downgrade(&xdr, res);
3920 decode_getfattr(&xdr, res->fattr, res->server);
3926 * Decode ACCESS response
3928 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3930 struct xdr_stream xdr;
3931 struct compound_hdr hdr;
3934 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3935 status = decode_compound_hdr(&xdr, &hdr);
3938 status = decode_sequence(&xdr, &res->seq_res, rqstp);
3941 status = decode_putfh(&xdr);
3944 status = decode_access(&xdr, res);
3947 decode_getfattr(&xdr, res->fattr, res->server);
3953 * Decode LOOKUP response
3955 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3957 struct xdr_stream xdr;
3958 struct compound_hdr hdr;
3961 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3962 status = decode_compound_hdr(&xdr, &hdr);
3965 status = decode_sequence(&xdr, &res->seq_res, rqstp);
3968 if ((status = decode_putfh(&xdr)) != 0)
3970 if ((status = decode_lookup(&xdr)) != 0)
3972 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3974 status = decode_getfattr(&xdr, res->fattr, res->server);
3980 * Decode LOOKUP_ROOT response
3982 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3984 struct xdr_stream xdr;
3985 struct compound_hdr hdr;
3988 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3989 status = decode_compound_hdr(&xdr, &hdr);
3992 status = decode_sequence(&xdr, &res->seq_res, rqstp);
3995 if ((status = decode_putrootfh(&xdr)) != 0)
3997 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3998 status = decode_getfattr(&xdr, res->fattr, res->server);
4004 * Decode REMOVE response
4006 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
4008 struct xdr_stream xdr;
4009 struct compound_hdr hdr;
4012 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4013 status = decode_compound_hdr(&xdr, &hdr);
4016 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4019 if ((status = decode_putfh(&xdr)) != 0)
4021 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4023 decode_getfattr(&xdr, &res->dir_attr, res->server);
4029 * Decode RENAME response
4031 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
4033 struct xdr_stream xdr;
4034 struct compound_hdr hdr;
4037 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4038 status = decode_compound_hdr(&xdr, &hdr);
4041 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4044 if ((status = decode_putfh(&xdr)) != 0)
4046 if ((status = decode_savefh(&xdr)) != 0)
4048 if ((status = decode_putfh(&xdr)) != 0)
4050 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4052 /* Current FH is target directory */
4053 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
4055 if ((status = decode_restorefh(&xdr)) != 0)
4057 decode_getfattr(&xdr, res->old_fattr, res->server);
4063 * Decode LINK response
4065 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
4067 struct xdr_stream xdr;
4068 struct compound_hdr hdr;
4071 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4072 status = decode_compound_hdr(&xdr, &hdr);
4075 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4078 if ((status = decode_putfh(&xdr)) != 0)
4080 if ((status = decode_savefh(&xdr)) != 0)
4082 if ((status = decode_putfh(&xdr)) != 0)
4084 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4087 * Note order: OP_LINK leaves the directory as the current
4090 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
4092 if ((status = decode_restorefh(&xdr)) != 0)
4094 decode_getfattr(&xdr, res->fattr, res->server);
4100 * Decode CREATE response
4102 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
4104 struct xdr_stream xdr;
4105 struct compound_hdr hdr;
4108 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4109 status = decode_compound_hdr(&xdr, &hdr);
4112 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4115 if ((status = decode_putfh(&xdr)) != 0)
4117 if ((status = decode_savefh(&xdr)) != 0)
4119 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4121 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4123 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
4125 if ((status = decode_restorefh(&xdr)) != 0)
4127 decode_getfattr(&xdr, res->dir_fattr, res->server);
4133 * Decode SYMLINK response
4135 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
4137 return nfs4_xdr_dec_create(rqstp, p, res);
4141 * Decode GETATTR response
4143 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
4145 struct xdr_stream xdr;
4146 struct compound_hdr hdr;
4149 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4150 status = decode_compound_hdr(&xdr, &hdr);
4153 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4156 status = decode_putfh(&xdr);
4159 status = decode_getfattr(&xdr, res->fattr, res->server);
4165 * Encode an SETACL request
4168 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
4170 struct xdr_stream xdr;
4171 struct compound_hdr hdr = {
4172 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
4176 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
4177 encode_compound_hdr(&xdr, req, &hdr);
4178 encode_sequence(&xdr, &args->seq_args, &hdr);
4179 encode_putfh(&xdr, args->fh, &hdr);
4180 status = encode_setacl(&xdr, args, &hdr);
4186 * Decode SETACL response
4189 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4190 struct nfs_setaclres *res)
4192 struct xdr_stream xdr;
4193 struct compound_hdr hdr;
4196 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4197 status = decode_compound_hdr(&xdr, &hdr);
4200 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4203 status = decode_putfh(&xdr);
4206 status = decode_setattr(&xdr);
4212 * Decode GETACL response
4215 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4216 struct nfs_getaclres *res)
4218 struct xdr_stream xdr;
4219 struct compound_hdr hdr;
4222 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4223 status = decode_compound_hdr(&xdr, &hdr);
4226 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4229 status = decode_putfh(&xdr);
4232 status = decode_getacl(&xdr, rqstp, &res->acl_len);
4239 * Decode CLOSE response
4241 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4243 struct xdr_stream xdr;
4244 struct compound_hdr hdr;
4247 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4248 status = decode_compound_hdr(&xdr, &hdr);
4251 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4254 status = decode_putfh(&xdr);
4257 status = decode_close(&xdr, res);
4261 * Note: Server may do delete on close for this file
4262 * in which case the getattr call will fail with
4263 * an ESTALE error. Shouldn't be a problem,
4264 * though, since fattr->valid will remain unset.
4266 decode_getfattr(&xdr, res->fattr, res->server);
4272 * Decode OPEN response
4274 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4276 struct xdr_stream xdr;
4277 struct compound_hdr hdr;
4280 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4281 status = decode_compound_hdr(&xdr, &hdr);
4284 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4287 status = decode_putfh(&xdr);
4290 status = decode_savefh(&xdr);
4293 status = decode_open(&xdr, res);
4296 if (decode_getfh(&xdr, &res->fh) != 0)
4298 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4300 if (decode_restorefh(&xdr) != 0)
4302 decode_getfattr(&xdr, res->dir_attr, res->server);
4308 * Decode OPEN_CONFIRM response
4310 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4312 struct xdr_stream xdr;
4313 struct compound_hdr hdr;
4316 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4317 status = decode_compound_hdr(&xdr, &hdr);
4320 status = decode_putfh(&xdr);
4323 status = decode_open_confirm(&xdr, res);
4329 * Decode OPEN response
4331 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4333 struct xdr_stream xdr;
4334 struct compound_hdr hdr;
4337 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4338 status = decode_compound_hdr(&xdr, &hdr);
4341 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4344 status = decode_putfh(&xdr);
4347 status = decode_open(&xdr, res);
4350 decode_getfattr(&xdr, res->f_attr, res->server);
4356 * Decode SETATTR response
4358 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4360 struct xdr_stream xdr;
4361 struct compound_hdr hdr;
4364 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4365 status = decode_compound_hdr(&xdr, &hdr);
4368 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4371 status = decode_putfh(&xdr);
4374 status = decode_setattr(&xdr);
4377 decode_getfattr(&xdr, res->fattr, res->server);
4383 * Decode LOCK response
4385 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4387 struct xdr_stream xdr;
4388 struct compound_hdr hdr;
4391 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4392 status = decode_compound_hdr(&xdr, &hdr);
4395 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4398 status = decode_putfh(&xdr);
4401 status = decode_lock(&xdr, res);
4407 * Decode LOCKT response
4409 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4411 struct xdr_stream xdr;
4412 struct compound_hdr hdr;
4415 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4416 status = decode_compound_hdr(&xdr, &hdr);
4419 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4422 status = decode_putfh(&xdr);
4425 status = decode_lockt(&xdr, res);
4431 * Decode LOCKU response
4433 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4435 struct xdr_stream xdr;
4436 struct compound_hdr hdr;
4439 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4440 status = decode_compound_hdr(&xdr, &hdr);
4443 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4446 status = decode_putfh(&xdr);
4449 status = decode_locku(&xdr, res);
4455 * Decode READLINK response
4457 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4458 struct nfs4_readlink_res *res)
4460 struct xdr_stream xdr;
4461 struct compound_hdr hdr;
4464 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4465 status = decode_compound_hdr(&xdr, &hdr);
4468 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4471 status = decode_putfh(&xdr);
4474 status = decode_readlink(&xdr, rqstp);
4480 * Decode READDIR response
4482 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4484 struct xdr_stream xdr;
4485 struct compound_hdr hdr;
4488 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4489 status = decode_compound_hdr(&xdr, &hdr);
4492 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4495 status = decode_putfh(&xdr);
4498 status = decode_readdir(&xdr, rqstp, res);
4504 * Decode Read response
4506 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4508 struct xdr_stream xdr;
4509 struct compound_hdr hdr;
4512 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4513 status = decode_compound_hdr(&xdr, &hdr);
4516 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4519 status = decode_putfh(&xdr);
4522 status = decode_read(&xdr, rqstp, res);
4524 status = res->count;
4530 * Decode WRITE response
4532 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4534 struct xdr_stream xdr;
4535 struct compound_hdr hdr;
4538 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4539 status = decode_compound_hdr(&xdr, &hdr);
4542 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4545 status = decode_putfh(&xdr);
4548 status = decode_write(&xdr, res);
4551 decode_getfattr(&xdr, res->fattr, res->server);
4553 status = res->count;
4559 * Decode COMMIT response
4561 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4563 struct xdr_stream xdr;
4564 struct compound_hdr hdr;
4567 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4568 status = decode_compound_hdr(&xdr, &hdr);
4571 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4574 status = decode_putfh(&xdr);
4577 status = decode_commit(&xdr, res);
4580 decode_getfattr(&xdr, res->fattr, res->server);
4588 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4589 struct nfs4_fsinfo_res *res)
4591 struct xdr_stream xdr;
4592 struct compound_hdr hdr;
4595 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4596 status = decode_compound_hdr(&xdr, &hdr);
4598 status = decode_sequence(&xdr, &res->seq_res, req);
4600 status = decode_putfh(&xdr);
4602 status = decode_fsinfo(&xdr, res->fsinfo);
4609 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4610 struct nfs4_pathconf_res *res)
4612 struct xdr_stream xdr;
4613 struct compound_hdr hdr;
4616 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4617 status = decode_compound_hdr(&xdr, &hdr);
4619 status = decode_sequence(&xdr, &res->seq_res, req);
4621 status = decode_putfh(&xdr);
4623 status = decode_pathconf(&xdr, res->pathconf);
4630 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4631 struct nfs4_statfs_res *res)
4633 struct xdr_stream xdr;
4634 struct compound_hdr hdr;
4637 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4638 status = decode_compound_hdr(&xdr, &hdr);
4640 status = decode_sequence(&xdr, &res->seq_res, req);
4642 status = decode_putfh(&xdr);
4644 status = decode_statfs(&xdr, res->fsstat);
4649 * GETATTR_BITMAP request
4651 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4653 struct xdr_stream xdr;
4654 struct compound_hdr hdr;
4657 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4658 status = decode_compound_hdr(&xdr, &hdr);
4661 status = decode_sequence(&xdr, &res->seq_res, req);
4664 if ((status = decode_putfh(&xdr)) != 0)
4666 status = decode_server_caps(&xdr, res);
4672 * Decode RENEW response
4674 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4676 struct xdr_stream xdr;
4677 struct compound_hdr hdr;
4680 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4681 status = decode_compound_hdr(&xdr, &hdr);
4683 status = decode_renew(&xdr);
4688 * a SETCLIENTID request
4690 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4691 struct nfs_client *clp)
4693 struct xdr_stream xdr;
4694 struct compound_hdr hdr;
4697 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4698 status = decode_compound_hdr(&xdr, &hdr);
4700 status = decode_setclientid(&xdr, clp);
4705 * a SETCLIENTID_CONFIRM request
4707 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4709 struct xdr_stream xdr;
4710 struct compound_hdr hdr;
4713 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4714 status = decode_compound_hdr(&xdr, &hdr);
4716 status = decode_setclientid_confirm(&xdr);
4718 status = decode_putrootfh(&xdr);
4720 status = decode_fsinfo(&xdr, fsinfo);
4725 * DELEGRETURN request
4727 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4729 struct xdr_stream xdr;
4730 struct compound_hdr hdr;
4733 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4734 status = decode_compound_hdr(&xdr, &hdr);
4737 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4740 status = decode_putfh(&xdr);
4743 status = decode_delegreturn(&xdr);
4744 decode_getfattr(&xdr, res->fattr, res->server);
4750 * FS_LOCATIONS request
4752 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
4753 struct nfs4_fs_locations_res *res)
4755 struct xdr_stream xdr;
4756 struct compound_hdr hdr;
4759 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4760 status = decode_compound_hdr(&xdr, &hdr);
4763 status = decode_sequence(&xdr, &res->seq_res, req);
4766 if ((status = decode_putfh(&xdr)) != 0)
4768 if ((status = decode_lookup(&xdr)) != 0)
4770 xdr_enter_page(&xdr, PAGE_SIZE);
4771 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
4772 res->fs_locations->server);
4777 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4779 uint32_t bitmap[2] = {0};
4784 return ERR_PTR(-EAGAIN);
4786 return ERR_PTR(-EBADCOOKIE);
4789 entry->prev_cookie = entry->cookie;
4790 p = xdr_decode_hyper(p, &entry->cookie);
4791 entry->len = ntohl(*p++);
4792 entry->name = (const char *) p;
4793 p += XDR_QUADLEN(entry->len);
4796 * In case the server doesn't return an inode number,
4797 * we fake one here. (We don't use inode number 0,
4798 * since glibc seems to choke on it...)
4802 len = ntohl(*p++); /* bitmap length */
4804 bitmap[0] = ntohl(*p++);
4806 bitmap[1] = ntohl(*p++);
4810 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4812 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4813 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4814 /* Ignore the return value of rdattr_error for now */
4818 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4819 xdr_decode_hyper(p, &entry->ino);
4820 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4821 xdr_decode_hyper(p, &entry->ino);
4825 entry->eof = !p[0] && p[1];
4830 * We need to translate between nfs status return values and
4831 * the local errno values which may not be the same.
4838 { NFS4ERR_PERM, -EPERM },
4839 { NFS4ERR_NOENT, -ENOENT },
4840 { NFS4ERR_IO, -errno_NFSERR_IO},
4841 { NFS4ERR_NXIO, -ENXIO },
4842 { NFS4ERR_ACCESS, -EACCES },
4843 { NFS4ERR_EXIST, -EEXIST },
4844 { NFS4ERR_XDEV, -EXDEV },
4845 { NFS4ERR_NOTDIR, -ENOTDIR },
4846 { NFS4ERR_ISDIR, -EISDIR },
4847 { NFS4ERR_INVAL, -EINVAL },
4848 { NFS4ERR_FBIG, -EFBIG },
4849 { NFS4ERR_NOSPC, -ENOSPC },
4850 { NFS4ERR_ROFS, -EROFS },
4851 { NFS4ERR_MLINK, -EMLINK },
4852 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4853 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4854 { NFS4ERR_DQUOT, -EDQUOT },
4855 { NFS4ERR_STALE, -ESTALE },
4856 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4857 { NFS4ERR_BADOWNER, -EINVAL },
4858 { NFS4ERR_BADNAME, -EINVAL },
4859 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4860 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4861 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4862 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4863 { NFS4ERR_BADTYPE, -EBADTYPE },
4864 { NFS4ERR_LOCKED, -EAGAIN },
4865 { NFS4ERR_RESOURCE, -EREMOTEIO },
4866 { NFS4ERR_SYMLINK, -ELOOP },
4867 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4868 { NFS4ERR_DEADLOCK, -EDEADLK },
4869 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
4870 * to be handled by a
4877 * Convert an NFS error code to a local one.
4878 * This one is used jointly by NFSv2 and NFSv3.
4881 nfs4_stat_to_errno(int stat)
4884 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4885 if (nfs_errtbl[i].stat == stat)
4886 return nfs_errtbl[i].errno;
4888 if (stat <= 10000 || stat > 10100) {
4889 /* The server is looney tunes. */
4890 return -ESERVERFAULT;
4892 /* If we cannot translate the error, the recovery routines should
4894 * Note: remaining NFSv4 error codes have values > 10000, so should
4895 * not conflict with native Linux error codes.
4900 #define PROC(proc, argtype, restype) \
4901 [NFSPROC4_CLNT_##proc] = { \
4902 .p_proc = NFSPROC4_COMPOUND, \
4903 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4904 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4905 .p_arglen = NFS4_##argtype##_sz, \
4906 .p_replen = NFS4_##restype##_sz, \
4907 .p_statidx = NFSPROC4_CLNT_##proc, \
4911 struct rpc_procinfo nfs4_procedures[] = {
4912 PROC(READ, enc_read, dec_read),
4913 PROC(WRITE, enc_write, dec_write),
4914 PROC(COMMIT, enc_commit, dec_commit),
4915 PROC(OPEN, enc_open, dec_open),
4916 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4917 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4918 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4919 PROC(CLOSE, enc_close, dec_close),
4920 PROC(SETATTR, enc_setattr, dec_setattr),
4921 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4922 PROC(RENEW, enc_renew, dec_renew),
4923 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4924 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4925 PROC(LOCK, enc_lock, dec_lock),
4926 PROC(LOCKT, enc_lockt, dec_lockt),
4927 PROC(LOCKU, enc_locku, dec_locku),
4928 PROC(ACCESS, enc_access, dec_access),
4929 PROC(GETATTR, enc_getattr, dec_getattr),
4930 PROC(LOOKUP, enc_lookup, dec_lookup),
4931 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4932 PROC(REMOVE, enc_remove, dec_remove),
4933 PROC(RENAME, enc_rename, dec_rename),
4934 PROC(LINK, enc_link, dec_link),
4935 PROC(SYMLINK, enc_symlink, dec_symlink),
4936 PROC(CREATE, enc_create, dec_create),
4937 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4938 PROC(STATFS, enc_statfs, dec_statfs),
4939 PROC(READLINK, enc_readlink, dec_readlink),
4940 PROC(READDIR, enc_readdir, dec_readdir),
4941 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4942 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4943 PROC(GETACL, enc_getacl, dec_getacl),
4944 PROC(SETACL, enc_setacl, dec_setacl),
4945 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4948 struct rpc_version nfs_version4 = {
4950 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4951 .procs = nfs4_procedures