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 (op_encode_hdr_maxsz + 2)
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 4 /*server->ip_addr*/ + \
122 6 + (NFS4_VERIFIER_SIZE >> 2))
123 #define decode_setclientid_maxsz \
124 (op_decode_hdr_maxsz + \
126 1024) /* large value for CLID_INUSE */
127 #define encode_setclientid_confirm_maxsz \
128 (op_encode_hdr_maxsz + \
129 3 + (NFS4_VERIFIER_SIZE >> 2))
130 #define decode_setclientid_confirm_maxsz \
131 (op_decode_hdr_maxsz)
132 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
133 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
134 #define encode_share_access_maxsz \
136 #define encode_createmode_maxsz (1 + encode_attrs_maxsz)
137 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
138 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
139 #define encode_open_maxsz (op_encode_hdr_maxsz + \
140 2 + encode_share_access_maxsz + 2 + \
141 open_owner_id_maxsz + \
142 encode_opentype_maxsz + \
143 encode_claim_null_maxsz)
144 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
145 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
147 #define decode_change_info_maxsz (5)
148 #define decode_open_maxsz (op_decode_hdr_maxsz + \
149 decode_stateid_maxsz + \
150 decode_change_info_maxsz + 1 + \
151 nfs4_fattr_bitmap_maxsz + \
152 decode_delegation_maxsz)
153 #define encode_open_confirm_maxsz \
154 (op_encode_hdr_maxsz + \
155 encode_stateid_maxsz + 1)
156 #define decode_open_confirm_maxsz \
157 (op_decode_hdr_maxsz + \
158 decode_stateid_maxsz)
159 #define encode_open_downgrade_maxsz \
160 (op_encode_hdr_maxsz + \
161 encode_stateid_maxsz + 1 + \
162 encode_share_access_maxsz)
163 #define decode_open_downgrade_maxsz \
164 (op_decode_hdr_maxsz + \
165 decode_stateid_maxsz)
166 #define encode_close_maxsz (op_encode_hdr_maxsz + \
167 1 + encode_stateid_maxsz)
168 #define decode_close_maxsz (op_decode_hdr_maxsz + \
169 decode_stateid_maxsz)
170 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + \
173 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
174 nfs4_fattr_bitmap_maxsz)
175 #define encode_read_maxsz (op_encode_hdr_maxsz + \
176 encode_stateid_maxsz + 3)
177 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
178 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
179 2 + encode_verifier_maxsz + 5)
180 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
181 decode_verifier_maxsz)
182 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
183 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
184 #define encode_write_maxsz (op_encode_hdr_maxsz + \
185 encode_stateid_maxsz + 4)
186 #define decode_write_maxsz (op_decode_hdr_maxsz + \
187 2 + decode_verifier_maxsz)
188 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
189 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
190 decode_verifier_maxsz)
191 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
193 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
195 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
196 #define encode_link_maxsz (op_encode_hdr_maxsz + \
198 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
199 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
201 1 + encode_stateid_maxsz + 8)
202 #define decode_lock_denied_maxsz \
203 (8 + decode_lockowner_maxsz)
204 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
205 decode_lock_denied_maxsz)
206 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
207 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
208 decode_lock_denied_maxsz)
209 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
210 encode_stateid_maxsz + \
212 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
213 decode_stateid_maxsz)
214 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
215 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
216 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
217 1 + nfs4_name_maxsz + \
220 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
221 #define encode_create_maxsz (op_encode_hdr_maxsz + \
222 1 + 2 + nfs4_name_maxsz + \
224 #define decode_create_maxsz (op_decode_hdr_maxsz + \
225 decode_change_info_maxsz + \
226 nfs4_fattr_bitmap_maxsz)
227 #define encode_statfs_maxsz (encode_getattr_maxsz)
228 #define decode_statfs_maxsz (decode_getattr_maxsz)
229 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
230 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
231 #define encode_getacl_maxsz (encode_getattr_maxsz)
232 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
233 nfs4_fattr_bitmap_maxsz + 1)
234 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
235 encode_stateid_maxsz + 3)
236 #define decode_setacl_maxsz (decode_setattr_maxsz)
237 #define encode_fs_locations_maxsz \
238 (encode_getattr_maxsz)
239 #define decode_fs_locations_maxsz \
241 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
242 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
243 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
244 encode_putfh_maxsz + \
246 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
247 decode_putfh_maxsz + \
249 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
250 encode_putfh_maxsz + \
251 encode_readlink_maxsz)
252 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
253 decode_putfh_maxsz + \
254 decode_readlink_maxsz)
255 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
256 encode_putfh_maxsz + \
257 encode_readdir_maxsz)
258 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
259 decode_putfh_maxsz + \
260 decode_readdir_maxsz)
261 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
262 encode_putfh_maxsz + \
263 encode_write_maxsz + \
264 encode_getattr_maxsz)
265 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
266 decode_putfh_maxsz + \
267 decode_write_maxsz + \
268 decode_getattr_maxsz)
269 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
270 encode_putfh_maxsz + \
271 encode_commit_maxsz + \
272 encode_getattr_maxsz)
273 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
274 decode_putfh_maxsz + \
275 decode_commit_maxsz + \
276 decode_getattr_maxsz)
277 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
278 encode_putfh_maxsz + \
279 encode_savefh_maxsz + \
280 encode_open_maxsz + \
281 encode_getfh_maxsz + \
282 encode_getattr_maxsz + \
283 encode_restorefh_maxsz + \
284 encode_getattr_maxsz)
285 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
286 decode_putfh_maxsz + \
287 decode_savefh_maxsz + \
288 decode_open_maxsz + \
289 decode_getfh_maxsz + \
290 decode_getattr_maxsz + \
291 decode_restorefh_maxsz + \
292 decode_getattr_maxsz)
293 #define NFS4_enc_open_confirm_sz \
294 (compound_encode_hdr_maxsz + \
295 encode_putfh_maxsz + \
296 encode_open_confirm_maxsz)
297 #define NFS4_dec_open_confirm_sz \
298 (compound_decode_hdr_maxsz + \
299 decode_putfh_maxsz + \
300 decode_open_confirm_maxsz)
301 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
302 encode_putfh_maxsz + \
303 encode_open_maxsz + \
304 encode_getattr_maxsz)
305 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
306 decode_putfh_maxsz + \
307 decode_open_maxsz + \
308 decode_getattr_maxsz)
309 #define NFS4_enc_open_downgrade_sz \
310 (compound_encode_hdr_maxsz + \
311 encode_putfh_maxsz + \
312 encode_open_downgrade_maxsz + \
313 encode_getattr_maxsz)
314 #define NFS4_dec_open_downgrade_sz \
315 (compound_decode_hdr_maxsz + \
316 decode_putfh_maxsz + \
317 decode_open_downgrade_maxsz + \
318 decode_getattr_maxsz)
319 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
320 encode_putfh_maxsz + \
321 encode_close_maxsz + \
322 encode_getattr_maxsz)
323 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
324 decode_putfh_maxsz + \
325 decode_close_maxsz + \
326 decode_getattr_maxsz)
327 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
328 encode_putfh_maxsz + \
329 encode_setattr_maxsz + \
330 encode_getattr_maxsz)
331 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
332 decode_putfh_maxsz + \
333 decode_setattr_maxsz + \
334 decode_getattr_maxsz)
335 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
336 encode_putfh_maxsz + \
338 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
339 decode_putfh_maxsz + \
341 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
343 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
345 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
346 encode_setclientid_maxsz)
347 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
348 decode_setclientid_maxsz)
349 #define NFS4_enc_setclientid_confirm_sz \
350 (compound_encode_hdr_maxsz + \
351 encode_setclientid_confirm_maxsz + \
352 encode_putrootfh_maxsz + \
354 #define NFS4_dec_setclientid_confirm_sz \
355 (compound_decode_hdr_maxsz + \
356 decode_setclientid_confirm_maxsz + \
357 decode_putrootfh_maxsz + \
359 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
360 encode_putfh_maxsz + \
362 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
363 decode_putfh_maxsz + \
365 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
366 encode_putfh_maxsz + \
368 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
369 decode_putfh_maxsz + \
371 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
372 encode_putfh_maxsz + \
374 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
375 decode_putfh_maxsz + \
377 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
379 encode_access_maxsz + \
380 encode_getattr_maxsz)
381 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
382 decode_putfh_maxsz + \
383 decode_access_maxsz + \
384 decode_getattr_maxsz)
385 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
386 encode_putfh_maxsz + \
387 encode_getattr_maxsz)
388 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
389 decode_putfh_maxsz + \
390 decode_getattr_maxsz)
391 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
392 encode_putfh_maxsz + \
393 encode_lookup_maxsz + \
394 encode_getattr_maxsz + \
396 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
397 decode_putfh_maxsz + \
398 decode_lookup_maxsz + \
399 decode_getattr_maxsz + \
401 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
402 encode_putrootfh_maxsz + \
403 encode_getattr_maxsz + \
405 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
406 decode_putrootfh_maxsz + \
407 decode_getattr_maxsz + \
409 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
410 encode_putfh_maxsz + \
411 encode_remove_maxsz + \
412 encode_getattr_maxsz)
413 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
414 decode_putfh_maxsz + \
415 op_decode_hdr_maxsz + 5 + \
416 decode_getattr_maxsz)
417 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
418 encode_putfh_maxsz + \
419 encode_savefh_maxsz + \
420 encode_putfh_maxsz + \
421 encode_rename_maxsz + \
422 encode_getattr_maxsz + \
423 encode_restorefh_maxsz + \
424 encode_getattr_maxsz)
425 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
426 decode_putfh_maxsz + \
427 decode_savefh_maxsz + \
428 decode_putfh_maxsz + \
429 decode_rename_maxsz + \
430 decode_getattr_maxsz + \
431 decode_restorefh_maxsz + \
432 decode_getattr_maxsz)
433 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
434 encode_putfh_maxsz + \
435 encode_savefh_maxsz + \
436 encode_putfh_maxsz + \
437 encode_link_maxsz + \
438 decode_getattr_maxsz + \
439 encode_restorefh_maxsz + \
440 decode_getattr_maxsz)
441 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
442 decode_putfh_maxsz + \
443 decode_savefh_maxsz + \
444 decode_putfh_maxsz + \
445 decode_link_maxsz + \
446 decode_getattr_maxsz + \
447 decode_restorefh_maxsz + \
448 decode_getattr_maxsz)
449 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
450 encode_putfh_maxsz + \
451 encode_symlink_maxsz + \
452 encode_getattr_maxsz + \
454 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
455 decode_putfh_maxsz + \
456 decode_symlink_maxsz + \
457 decode_getattr_maxsz + \
459 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
460 encode_putfh_maxsz + \
461 encode_savefh_maxsz + \
462 encode_create_maxsz + \
463 encode_getfh_maxsz + \
464 encode_getattr_maxsz + \
465 encode_restorefh_maxsz + \
466 encode_getattr_maxsz)
467 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
468 decode_putfh_maxsz + \
469 decode_savefh_maxsz + \
470 decode_create_maxsz + \
471 decode_getfh_maxsz + \
472 decode_getattr_maxsz + \
473 decode_restorefh_maxsz + \
474 decode_getattr_maxsz)
475 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
476 encode_putfh_maxsz + \
477 encode_getattr_maxsz)
478 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
479 decode_putfh_maxsz + \
480 decode_getattr_maxsz)
481 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
482 encode_putfh_maxsz + \
484 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
485 decode_putfh_maxsz + \
487 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
488 encode_putfh_maxsz + \
489 encode_getattr_maxsz)
490 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
491 decode_putfh_maxsz + \
492 decode_getattr_maxsz)
493 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
494 encode_putfh_maxsz + \
495 encode_delegreturn_maxsz + \
496 encode_getattr_maxsz)
497 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
498 decode_delegreturn_maxsz + \
499 decode_getattr_maxsz)
500 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
501 encode_putfh_maxsz + \
503 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
504 decode_putfh_maxsz + \
506 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
507 encode_putfh_maxsz + \
509 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
510 decode_putfh_maxsz + \
512 #define NFS4_enc_fs_locations_sz \
513 (compound_encode_hdr_maxsz + \
514 encode_putfh_maxsz + \
515 encode_lookup_maxsz + \
516 encode_fs_locations_maxsz)
517 #define NFS4_dec_fs_locations_sz \
518 (compound_decode_hdr_maxsz + \
519 decode_putfh_maxsz + \
520 decode_lookup_maxsz + \
521 decode_fs_locations_maxsz)
525 unsigned int nfs2type;
533 { S_IFSOCK, NFSOCK },
539 struct compound_hdr {
547 * START OF "GENERIC" ENCODE ROUTINES.
548 * These may look a little ugly since they are imported from a "generic"
549 * set of XDR encode/decode routines which are intended to be shared by
550 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
552 * If the pain of reading these is too great, it should be a straightforward
553 * task to translate them into Linux-specific versions which are more
554 * consistent with the style used in NFSv2/v3...
556 #define WRITE32(n) *p++ = htonl(n)
557 #define WRITE64(n) do { \
558 *p++ = htonl((uint32_t)((n) >> 32)); \
559 *p++ = htonl((uint32_t)(n)); \
561 #define WRITEMEM(ptr,nbytes) do { \
562 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
565 #define RESERVE_SPACE(nbytes) do { \
566 p = xdr_reserve_space(xdr, nbytes); \
570 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
574 p = xdr_reserve_space(xdr, 4 + len);
576 xdr_encode_opaque(p, str, len);
579 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
583 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
584 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
585 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
586 WRITE32(hdr->taglen);
587 WRITEMEM(hdr->tag, hdr->taglen);
588 WRITE32(NFS4_MINOR_VERSION);
593 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
597 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
599 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
602 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
604 char owner_name[IDMAP_NAMESZ];
605 char owner_group[IDMAP_NAMESZ];
606 int owner_namelen = 0;
607 int owner_grouplen = 0;
616 * We reserve enough space to write the entire attribute buffer at once.
617 * In the worst-case, this would be
618 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
619 * = 36 bytes, plus any contribution from variable-length fields
620 * such as owner/group.
625 if (iap->ia_valid & ATTR_SIZE)
627 if (iap->ia_valid & ATTR_MODE)
629 if (iap->ia_valid & ATTR_UID) {
630 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
631 if (owner_namelen < 0) {
632 dprintk("nfs: couldn't resolve uid %d to string\n",
635 strcpy(owner_name, "nobody");
636 owner_namelen = sizeof("nobody") - 1;
639 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
641 if (iap->ia_valid & ATTR_GID) {
642 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
643 if (owner_grouplen < 0) {
644 dprintk("nfs: couldn't resolve gid %d to string\n",
646 strcpy(owner_group, "nobody");
647 owner_grouplen = sizeof("nobody") - 1;
650 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
652 if (iap->ia_valid & ATTR_ATIME_SET)
654 else if (iap->ia_valid & ATTR_ATIME)
656 if (iap->ia_valid & ATTR_MTIME_SET)
658 else if (iap->ia_valid & ATTR_MTIME)
663 * We write the bitmap length now, but leave the bitmap and the attribute
664 * buffer length to be backfilled at the end of this routine.
670 if (iap->ia_valid & ATTR_SIZE) {
671 bmval0 |= FATTR4_WORD0_SIZE;
672 WRITE64(iap->ia_size);
674 if (iap->ia_valid & ATTR_MODE) {
675 bmval1 |= FATTR4_WORD1_MODE;
676 WRITE32(iap->ia_mode & S_IALLUGO);
678 if (iap->ia_valid & ATTR_UID) {
679 bmval1 |= FATTR4_WORD1_OWNER;
680 WRITE32(owner_namelen);
681 WRITEMEM(owner_name, owner_namelen);
683 if (iap->ia_valid & ATTR_GID) {
684 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
685 WRITE32(owner_grouplen);
686 WRITEMEM(owner_group, owner_grouplen);
688 if (iap->ia_valid & ATTR_ATIME_SET) {
689 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
690 WRITE32(NFS4_SET_TO_CLIENT_TIME);
692 WRITE32(iap->ia_mtime.tv_sec);
693 WRITE32(iap->ia_mtime.tv_nsec);
695 else if (iap->ia_valid & ATTR_ATIME) {
696 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
697 WRITE32(NFS4_SET_TO_SERVER_TIME);
699 if (iap->ia_valid & ATTR_MTIME_SET) {
700 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
701 WRITE32(NFS4_SET_TO_CLIENT_TIME);
703 WRITE32(iap->ia_mtime.tv_sec);
704 WRITE32(iap->ia_mtime.tv_nsec);
706 else if (iap->ia_valid & ATTR_MTIME) {
707 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
708 WRITE32(NFS4_SET_TO_SERVER_TIME);
712 * Now we backfill the bitmap and the attribute buffer length.
714 if (len != ((char *)p - (char *)q) + 4) {
715 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
716 len, ((char *)p - (char *)q) + 4);
719 len = (char *)p - (char *)q - 12;
720 *q++ = htonl(bmval0);
721 *q++ = htonl(bmval1);
729 static int encode_access(struct xdr_stream *xdr, u32 access)
740 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
744 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
746 WRITE32(arg->seqid->sequence->counter);
747 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
752 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
758 WRITE64(args->offset);
759 WRITE32(args->count);
764 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
770 WRITE32(create->ftype);
772 switch (create->ftype) {
775 WRITE32(create->u.symlink.len);
776 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
779 case NF4BLK: case NF4CHR:
781 WRITE32(create->u.device.specdata1);
782 WRITE32(create->u.device.specdata2);
789 RESERVE_SPACE(4 + create->name->len);
790 WRITE32(create->name->len);
791 WRITEMEM(create->name->name, create->name->len);
793 return encode_attrs(xdr, create->attrs, create->server);
796 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
807 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
819 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
821 return encode_getattr_two(xdr,
822 bitmask[0] & nfs4_fattr_bitmap[0],
823 bitmask[1] & nfs4_fattr_bitmap[1]);
826 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
828 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
829 bitmask[1] & nfs4_fsinfo_bitmap[1]);
832 static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
834 return encode_getattr_two(xdr,
835 bitmask[0] & nfs4_fs_locations_bitmap[0],
836 bitmask[1] & nfs4_fs_locations_bitmap[1]);
839 static int encode_getfh(struct xdr_stream *xdr)
849 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
853 RESERVE_SPACE(8 + name->len);
856 WRITEMEM(name->name, name->len);
861 static inline int nfs4_lock_type(struct file_lock *fl, int block)
863 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
864 return block ? NFS4_READW_LT : NFS4_READ_LT;
865 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
868 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
870 if (fl->fl_end == OFFSET_MAX)
872 return fl->fl_end - fl->fl_start + 1;
876 * opcode,type,reclaim,offset,length,new_lock_owner = 32
877 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
879 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
885 WRITE32(nfs4_lock_type(args->fl, args->block));
886 WRITE32(args->reclaim);
887 WRITE64(args->fl->fl_start);
888 WRITE64(nfs4_lock_length(args->fl));
889 WRITE32(args->new_lock_owner);
890 if (args->new_lock_owner){
891 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
892 WRITE32(args->open_seqid->sequence->counter);
893 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
894 WRITE32(args->lock_seqid->sequence->counter);
895 WRITE64(args->lock_owner.clientid);
897 WRITEMEM("lock id:", 8);
898 WRITE64(args->lock_owner.id);
901 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
902 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
903 WRITE32(args->lock_seqid->sequence->counter);
909 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
915 WRITE32(nfs4_lock_type(args->fl, 0));
916 WRITE64(args->fl->fl_start);
917 WRITE64(nfs4_lock_length(args->fl));
918 WRITE64(args->lock_owner.clientid);
920 WRITEMEM("lock id:", 8);
921 WRITE64(args->lock_owner.id);
926 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
930 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
932 WRITE32(nfs4_lock_type(args->fl, 0));
933 WRITE32(args->seqid->sequence->counter);
934 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
935 WRITE64(args->fl->fl_start);
936 WRITE64(nfs4_lock_length(args->fl));
941 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
946 RESERVE_SPACE(8 + len);
949 WRITEMEM(name->name, len);
954 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
959 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
961 WRITE32(NFS4_SHARE_ACCESS_READ);
964 WRITE32(NFS4_SHARE_ACCESS_WRITE);
966 case FMODE_READ|FMODE_WRITE:
967 WRITE32(NFS4_SHARE_ACCESS_BOTH);
972 WRITE32(0); /* for linux, share_deny = 0 always */
975 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
979 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
984 WRITE32(arg->seqid->sequence->counter);
985 encode_share_access(xdr, arg->open_flags);
987 WRITE64(arg->clientid);
989 WRITEMEM("open id:", 8);
993 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
998 switch(arg->open_flags & O_EXCL) {
1000 WRITE32(NFS4_CREATE_UNCHECKED);
1001 encode_attrs(xdr, arg->u.attrs, arg->server);
1004 WRITE32(NFS4_CREATE_EXCLUSIVE);
1005 encode_nfs4_verifier(xdr, &arg->u.verifier);
1009 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1014 switch (arg->open_flags & O_CREAT) {
1016 WRITE32(NFS4_OPEN_NOCREATE);
1019 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1020 WRITE32(NFS4_OPEN_CREATE);
1021 encode_createmode(xdr, arg);
1025 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
1030 switch (delegation_type) {
1032 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1035 WRITE32(NFS4_OPEN_DELEGATE_READ);
1037 case FMODE_WRITE|FMODE_READ:
1038 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1045 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1050 WRITE32(NFS4_OPEN_CLAIM_NULL);
1051 encode_string(xdr, name->len, name->name);
1054 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
1059 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1060 encode_delegation_type(xdr, type);
1063 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1067 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1068 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1069 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1070 encode_string(xdr, name->len, name->name);
1073 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1075 encode_openhdr(xdr, arg);
1076 encode_opentype(xdr, arg);
1077 switch (arg->claim) {
1078 case NFS4_OPEN_CLAIM_NULL:
1079 encode_claim_null(xdr, arg->name);
1081 case NFS4_OPEN_CLAIM_PREVIOUS:
1082 encode_claim_previous(xdr, arg->u.delegation_type);
1084 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1085 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1093 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
1097 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1098 WRITE32(OP_OPEN_CONFIRM);
1099 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1100 WRITE32(arg->seqid->sequence->counter);
1105 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1109 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1110 WRITE32(OP_OPEN_DOWNGRADE);
1111 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1112 WRITE32(arg->seqid->sequence->counter);
1113 encode_share_access(xdr, arg->open_flags);
1118 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1123 RESERVE_SPACE(8 + len);
1126 WRITEMEM(fh->data, len);
1131 static int encode_putrootfh(struct xdr_stream *xdr)
1136 WRITE32(OP_PUTROOTFH);
1141 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1143 nfs4_stateid stateid;
1146 RESERVE_SPACE(NFS4_STATEID_SIZE);
1147 if (ctx->state != NULL) {
1148 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1149 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1151 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1154 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1161 encode_stateid(xdr, args->context);
1164 WRITE64(args->offset);
1165 WRITE32(args->count);
1170 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1172 uint32_t attrs[2] = {
1173 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1174 FATTR4_WORD1_MOUNTED_ON_FILEID,
1178 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1179 WRITE32(OP_READDIR);
1180 WRITE64(readdir->cookie);
1181 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1182 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1183 WRITE32(readdir->count);
1185 /* Switch to mounted_on_fileid if the server supports it */
1186 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1187 attrs[0] &= ~FATTR4_WORD0_FILEID;
1189 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1190 WRITE32(attrs[0] & readdir->bitmask[0]);
1191 WRITE32(attrs[1] & readdir->bitmask[1]);
1192 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1194 (unsigned long long)readdir->cookie,
1195 ((u32 *)readdir->verifier.data)[0],
1196 ((u32 *)readdir->verifier.data)[1],
1197 attrs[0] & readdir->bitmask[0],
1198 attrs[1] & readdir->bitmask[1]);
1203 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1208 WRITE32(OP_READLINK);
1213 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1217 RESERVE_SPACE(8 + name->len);
1220 WRITEMEM(name->name, name->len);
1225 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1229 RESERVE_SPACE(8 + oldname->len);
1231 WRITE32(oldname->len);
1232 WRITEMEM(oldname->name, oldname->len);
1234 RESERVE_SPACE(4 + newname->len);
1235 WRITE32(newname->len);
1236 WRITEMEM(newname->name, newname->len);
1241 static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
1247 WRITE64(client_stateid->cl_clientid);
1253 encode_restorefh(struct xdr_stream *xdr)
1258 WRITE32(OP_RESTOREFH);
1264 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1268 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1269 WRITE32(OP_SETATTR);
1270 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1273 WRITE32(FATTR4_WORD0_ACL);
1274 if (arg->acl_len % 4)
1277 WRITE32(arg->acl_len);
1278 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1283 encode_savefh(struct xdr_stream *xdr)
1293 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1298 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1299 WRITE32(OP_SETATTR);
1300 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1302 if ((status = encode_attrs(xdr, arg->iap, server)))
1308 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1312 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1313 WRITE32(OP_SETCLIENTID);
1314 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1316 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1318 WRITE32(setclientid->sc_prog);
1319 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1320 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1322 WRITE32(setclientid->sc_cb_ident);
1327 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
1331 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1332 WRITE32(OP_SETCLIENTID_CONFIRM);
1333 WRITE64(client_state->cl_clientid);
1334 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1339 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1346 encode_stateid(xdr, args->context);
1349 WRITE64(args->offset);
1350 WRITE32(args->stable);
1351 WRITE32(args->count);
1353 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1358 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1362 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1364 WRITE32(OP_DELEGRETURN);
1365 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1370 * END OF "GENERIC" ENCODE ROUTINES.
1374 * Encode an ACCESS request
1376 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1378 struct xdr_stream xdr;
1379 struct compound_hdr hdr = {
1384 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1385 encode_compound_hdr(&xdr, &hdr);
1386 status = encode_putfh(&xdr, args->fh);
1389 status = encode_access(&xdr, args->access);
1392 status = encode_getfattr(&xdr, args->bitmask);
1398 * Encode LOOKUP request
1400 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1402 struct xdr_stream xdr;
1403 struct compound_hdr hdr = {
1408 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1409 encode_compound_hdr(&xdr, &hdr);
1410 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1412 if ((status = encode_lookup(&xdr, args->name)) != 0)
1414 if ((status = encode_getfh(&xdr)) != 0)
1416 status = encode_getfattr(&xdr, args->bitmask);
1422 * Encode LOOKUP_ROOT request
1424 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1426 struct xdr_stream xdr;
1427 struct compound_hdr hdr = {
1432 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1433 encode_compound_hdr(&xdr, &hdr);
1434 if ((status = encode_putrootfh(&xdr)) != 0)
1436 if ((status = encode_getfh(&xdr)) == 0)
1437 status = encode_getfattr(&xdr, args->bitmask);
1443 * Encode REMOVE request
1445 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1447 struct xdr_stream xdr;
1448 struct compound_hdr hdr = {
1453 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1454 encode_compound_hdr(&xdr, &hdr);
1455 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1457 if ((status = encode_remove(&xdr, &args->name)) != 0)
1459 status = encode_getfattr(&xdr, args->bitmask);
1465 * Encode RENAME request
1467 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1469 struct xdr_stream xdr;
1470 struct compound_hdr hdr = {
1475 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1476 encode_compound_hdr(&xdr, &hdr);
1477 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1479 if ((status = encode_savefh(&xdr)) != 0)
1481 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1483 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1485 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1487 if ((status = encode_restorefh(&xdr)) != 0)
1489 status = encode_getfattr(&xdr, args->bitmask);
1495 * Encode LINK request
1497 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1499 struct xdr_stream xdr;
1500 struct compound_hdr hdr = {
1505 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1506 encode_compound_hdr(&xdr, &hdr);
1507 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1509 if ((status = encode_savefh(&xdr)) != 0)
1511 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1513 if ((status = encode_link(&xdr, args->name)) != 0)
1515 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1517 if ((status = encode_restorefh(&xdr)) != 0)
1519 status = encode_getfattr(&xdr, args->bitmask);
1525 * Encode CREATE request
1527 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1529 struct xdr_stream xdr;
1530 struct compound_hdr hdr = {
1535 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1536 encode_compound_hdr(&xdr, &hdr);
1537 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1539 if ((status = encode_savefh(&xdr)) != 0)
1541 if ((status = encode_create(&xdr, args)) != 0)
1543 if ((status = encode_getfh(&xdr)) != 0)
1545 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1547 if ((status = encode_restorefh(&xdr)) != 0)
1549 status = encode_getfattr(&xdr, args->bitmask);
1555 * Encode SYMLINK request
1557 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1559 return nfs4_xdr_enc_create(req, p, args);
1563 * Encode GETATTR request
1565 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1567 struct xdr_stream xdr;
1568 struct compound_hdr hdr = {
1573 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1574 encode_compound_hdr(&xdr, &hdr);
1575 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1576 status = encode_getfattr(&xdr, args->bitmask);
1581 * Encode a CLOSE request
1583 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1585 struct xdr_stream xdr;
1586 struct compound_hdr hdr = {
1591 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1592 encode_compound_hdr(&xdr, &hdr);
1593 status = encode_putfh(&xdr, args->fh);
1596 status = encode_close(&xdr, args);
1599 status = encode_getfattr(&xdr, args->bitmask);
1605 * Encode an OPEN request
1607 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1609 struct xdr_stream xdr;
1610 struct compound_hdr hdr = {
1615 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1616 encode_compound_hdr(&xdr, &hdr);
1617 status = encode_putfh(&xdr, args->fh);
1620 status = encode_savefh(&xdr);
1623 status = encode_open(&xdr, args);
1626 status = encode_getfh(&xdr);
1629 status = encode_getfattr(&xdr, args->bitmask);
1632 status = encode_restorefh(&xdr);
1635 status = encode_getfattr(&xdr, args->bitmask);
1641 * Encode an OPEN_CONFIRM request
1643 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1645 struct xdr_stream xdr;
1646 struct compound_hdr hdr = {
1651 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1652 encode_compound_hdr(&xdr, &hdr);
1653 status = encode_putfh(&xdr, args->fh);
1656 status = encode_open_confirm(&xdr, args);
1662 * Encode an OPEN request with no attributes.
1664 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1666 struct xdr_stream xdr;
1667 struct compound_hdr hdr = {
1672 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1673 encode_compound_hdr(&xdr, &hdr);
1674 status = encode_putfh(&xdr, args->fh);
1677 status = encode_open(&xdr, args);
1680 status = encode_getfattr(&xdr, args->bitmask);
1686 * Encode an OPEN_DOWNGRADE request
1688 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1690 struct xdr_stream xdr;
1691 struct compound_hdr hdr = {
1696 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1697 encode_compound_hdr(&xdr, &hdr);
1698 status = encode_putfh(&xdr, args->fh);
1701 status = encode_open_downgrade(&xdr, args);
1704 status = encode_getfattr(&xdr, args->bitmask);
1710 * Encode a LOCK request
1712 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1714 struct xdr_stream xdr;
1715 struct compound_hdr hdr = {
1720 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1721 encode_compound_hdr(&xdr, &hdr);
1722 status = encode_putfh(&xdr, args->fh);
1725 status = encode_lock(&xdr, args);
1731 * Encode a LOCKT request
1733 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1735 struct xdr_stream xdr;
1736 struct compound_hdr hdr = {
1741 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1742 encode_compound_hdr(&xdr, &hdr);
1743 status = encode_putfh(&xdr, args->fh);
1746 status = encode_lockt(&xdr, args);
1752 * Encode a LOCKU request
1754 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1756 struct xdr_stream xdr;
1757 struct compound_hdr hdr = {
1762 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1763 encode_compound_hdr(&xdr, &hdr);
1764 status = encode_putfh(&xdr, args->fh);
1767 status = encode_locku(&xdr, args);
1773 * Encode a READLINK request
1775 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1777 struct xdr_stream xdr;
1778 struct compound_hdr hdr = {
1781 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1782 unsigned int replen;
1785 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1786 encode_compound_hdr(&xdr, &hdr);
1787 status = encode_putfh(&xdr, args->fh);
1790 status = encode_readlink(&xdr, args, req);
1792 /* set up reply kvec
1793 * toplevel_status + taglen + rescount + OP_PUTFH + status
1794 * + OP_READLINK + status + string length = 8
1796 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readlink_sz) << 2;
1797 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1798 args->pgbase, args->pglen);
1805 * Encode a READDIR request
1807 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1809 struct xdr_stream xdr;
1810 struct compound_hdr hdr = {
1813 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1817 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1818 encode_compound_hdr(&xdr, &hdr);
1819 status = encode_putfh(&xdr, args->fh);
1822 status = encode_readdir(&xdr, args, req);
1824 /* set up reply kvec
1825 * toplevel_status + taglen + rescount + OP_PUTFH + status
1826 * + OP_READDIR + status + verifer(2) = 9
1828 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readdir_sz) << 2;
1829 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1830 args->pgbase, args->count);
1831 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1832 __FUNCTION__, replen, args->pages,
1833 args->pgbase, args->count);
1840 * Encode a READ request
1842 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1844 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1845 struct xdr_stream xdr;
1846 struct compound_hdr hdr = {
1851 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1852 encode_compound_hdr(&xdr, &hdr);
1853 status = encode_putfh(&xdr, args->fh);
1856 status = encode_read(&xdr, args);
1860 /* set up reply kvec
1861 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1862 * + OP_READ + status + eof + datalen = 9
1864 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1865 xdr_inline_pages(&req->rq_rcv_buf, replen,
1866 args->pages, args->pgbase, args->count);
1867 req->rq_rcv_buf.flags |= XDRBUF_READ;
1873 * Encode an SETATTR request
1875 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1878 struct xdr_stream xdr;
1879 struct compound_hdr hdr = {
1884 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1885 encode_compound_hdr(&xdr, &hdr);
1886 status = encode_putfh(&xdr, args->fh);
1889 status = encode_setattr(&xdr, args, args->server);
1892 status = encode_getfattr(&xdr, args->bitmask);
1898 * Encode a GETACL request
1901 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1902 struct nfs_getaclargs *args)
1904 struct xdr_stream xdr;
1905 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1906 struct compound_hdr hdr = {
1911 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1912 encode_compound_hdr(&xdr, &hdr);
1913 status = encode_putfh(&xdr, args->fh);
1916 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1917 /* set up reply buffer: */
1918 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1919 xdr_inline_pages(&req->rq_rcv_buf, replen,
1920 args->acl_pages, args->acl_pgbase, args->acl_len);
1926 * Encode a WRITE request
1928 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1930 struct xdr_stream xdr;
1931 struct compound_hdr hdr = {
1936 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1937 encode_compound_hdr(&xdr, &hdr);
1938 status = encode_putfh(&xdr, args->fh);
1941 status = encode_write(&xdr, args);
1944 req->rq_snd_buf.flags |= XDRBUF_WRITE;
1945 status = encode_getfattr(&xdr, args->bitmask);
1953 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1955 struct xdr_stream xdr;
1956 struct compound_hdr hdr = {
1961 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1962 encode_compound_hdr(&xdr, &hdr);
1963 status = encode_putfh(&xdr, args->fh);
1966 status = encode_commit(&xdr, args);
1969 status = encode_getfattr(&xdr, args->bitmask);
1977 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1979 struct xdr_stream xdr;
1980 struct compound_hdr hdr = {
1985 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1986 encode_compound_hdr(&xdr, &hdr);
1987 status = encode_putfh(&xdr, args->fh);
1989 status = encode_fsinfo(&xdr, args->bitmask);
1994 * a PATHCONF request
1996 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1998 struct xdr_stream xdr;
1999 struct compound_hdr hdr = {
2004 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2005 encode_compound_hdr(&xdr, &hdr);
2006 status = encode_putfh(&xdr, args->fh);
2008 status = encode_getattr_one(&xdr,
2009 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
2016 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
2018 struct xdr_stream xdr;
2019 struct compound_hdr hdr = {
2024 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2025 encode_compound_hdr(&xdr, &hdr);
2026 status = encode_putfh(&xdr, args->fh);
2028 status = encode_getattr_two(&xdr,
2029 args->bitmask[0] & nfs4_statfs_bitmap[0],
2030 args->bitmask[1] & nfs4_statfs_bitmap[1]);
2035 * GETATTR_BITMAP request
2037 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
2039 struct xdr_stream xdr;
2040 struct compound_hdr hdr = {
2045 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2046 encode_compound_hdr(&xdr, &hdr);
2047 status = encode_putfh(&xdr, fhandle);
2049 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2050 FATTR4_WORD0_LINK_SUPPORT|
2051 FATTR4_WORD0_SYMLINK_SUPPORT|
2052 FATTR4_WORD0_ACLSUPPORT);
2059 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2061 struct xdr_stream xdr;
2062 struct compound_hdr hdr = {
2066 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2067 encode_compound_hdr(&xdr, &hdr);
2068 return encode_renew(&xdr, clp);
2072 * a SETCLIENTID request
2074 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
2076 struct xdr_stream xdr;
2077 struct compound_hdr hdr = {
2081 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2082 encode_compound_hdr(&xdr, &hdr);
2083 return encode_setclientid(&xdr, sc);
2087 * a SETCLIENTID_CONFIRM request
2089 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2091 struct xdr_stream xdr;
2092 struct compound_hdr hdr = {
2095 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2098 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2099 encode_compound_hdr(&xdr, &hdr);
2100 status = encode_setclientid_confirm(&xdr, clp);
2102 status = encode_putrootfh(&xdr);
2104 status = encode_fsinfo(&xdr, lease_bitmap);
2109 * DELEGRETURN request
2111 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2113 struct xdr_stream xdr;
2114 struct compound_hdr hdr = {
2119 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2120 encode_compound_hdr(&xdr, &hdr);
2121 status = encode_putfh(&xdr, args->fhandle);
2124 status = encode_delegreturn(&xdr, args->stateid);
2127 status = encode_getfattr(&xdr, args->bitmask);
2133 * Encode FS_LOCATIONS request
2135 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2137 struct xdr_stream xdr;
2138 struct compound_hdr hdr = {
2141 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
2145 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2146 encode_compound_hdr(&xdr, &hdr);
2147 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2149 if ((status = encode_lookup(&xdr, args->name)) != 0)
2151 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
2154 * toplevel_status + OP_PUTFH + status
2155 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2157 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2158 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2165 * START OF "GENERIC" DECODE ROUTINES.
2166 * These may look a little ugly since they are imported from a "generic"
2167 * set of XDR encode/decode routines which are intended to be shared by
2168 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2170 * If the pain of reading these is too great, it should be a straightforward
2171 * task to translate them into Linux-specific versions which are more
2172 * consistent with the style used in NFSv2/v3...
2174 #define READ32(x) (x) = ntohl(*p++)
2175 #define READ64(x) do { \
2176 (x) = (u64)ntohl(*p++) << 32; \
2177 (x) |= ntohl(*p++); \
2179 #define READTIME(x) do { \
2181 (x.tv_sec) = ntohl(*p++); \
2182 (x.tv_nsec) = ntohl(*p++); \
2184 #define COPYMEM(x,nbytes) do { \
2185 memcpy((x), p, nbytes); \
2186 p += XDR_QUADLEN(nbytes); \
2189 #define READ_BUF(nbytes) do { \
2190 p = xdr_inline_decode(xdr, nbytes); \
2191 if (unlikely(!p)) { \
2192 dprintk("nfs: %s: prematurely hit end of receive" \
2193 " buffer\n", __FUNCTION__); \
2194 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2195 __FUNCTION__, xdr->p, nbytes, xdr->end); \
2200 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2207 *string = (char *)p;
2211 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2216 READ32(hdr->status);
2217 READ32(hdr->taglen);
2219 READ_BUF(hdr->taglen + 4);
2220 hdr->tag = (char *)p;
2221 p += XDR_QUADLEN(hdr->taglen);
2226 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2234 if (opnum != expected) {
2235 dprintk("nfs: Server returned operation"
2236 " %d but we issued a request for %d\n",
2241 if (nfserr != NFS_OK)
2242 return -nfs4_stat_to_errno(nfserr);
2247 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2250 unsigned int strlen;
2254 return decode_opaque_inline(xdr, &strlen, &str);
2257 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2265 bitmap[0] = bitmap[1] = 0;
2266 READ_BUF((bmlen << 2));
2275 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2285 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2287 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2288 decode_attr_bitmap(xdr, bitmask);
2289 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2291 bitmask[0] = bitmask[1] = 0;
2292 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2296 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2301 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2303 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2306 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2307 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2310 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2312 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2316 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2321 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2323 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2326 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2328 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2329 (unsigned long long)*change);
2333 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2338 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2340 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2343 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2345 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2349 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2354 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2356 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2359 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2361 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2365 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2370 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2372 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2375 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2377 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2381 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2387 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2389 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2391 READ64(fsid->major);
2392 READ64(fsid->minor);
2393 bitmap[0] &= ~FATTR4_WORD0_FSID;
2395 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2396 (unsigned long long)fsid->major,
2397 (unsigned long long)fsid->minor);
2401 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2406 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2408 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2411 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2413 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2417 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2421 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2422 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2424 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2427 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2429 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2433 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2438 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2440 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2443 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2445 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2449 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2454 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2456 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2459 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2461 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2465 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2471 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2473 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2476 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2478 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2482 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2488 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2490 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2493 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2495 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2499 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2505 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2507 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2510 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2512 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2516 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2529 path->ncomponents = 0;
2530 while (path->ncomponents < n) {
2531 struct nfs4_string *component = &path->components[path->ncomponents];
2532 status = decode_opaque_inline(xdr, &component->len, &component->data);
2533 if (unlikely(status != 0))
2535 if (path->ncomponents != n)
2537 dprintk("%s", component->data);
2538 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2539 path->ncomponents++;
2541 dprintk("cannot parse %d components in path\n", n);
2549 /* a root pathname is sent as a zero component4 */
2550 path->ncomponents = 1;
2551 path->components[0].len=0;
2552 path->components[0].data=NULL;
2553 dprintk("path /\n");
2556 dprintk(" status %d", status);
2561 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2567 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2570 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2572 dprintk("%s: fsroot ", __FUNCTION__);
2573 status = decode_pathname(xdr, &res->fs_path);
2574 if (unlikely(status != 0))
2580 res->nlocations = 0;
2581 while (res->nlocations < n) {
2583 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2591 dprintk("%s: servers ", __FUNCTION__);
2592 while (loc->nservers < m) {
2593 struct nfs4_string *server = &loc->servers[loc->nservers];
2594 status = decode_opaque_inline(xdr, &server->len, &server->data);
2595 if (unlikely(status != 0))
2597 dprintk("%s ", server->data);
2598 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2602 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2603 for (i = loc->nservers; i < m; i++) {
2606 status = decode_opaque_inline(xdr, &len, &data);
2607 if (unlikely(status != 0))
2612 status = decode_pathname(xdr, &loc->rootpath);
2613 if (unlikely(status != 0))
2615 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2619 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2626 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2632 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2634 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2637 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2639 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2643 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2649 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2651 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2654 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2656 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2660 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2666 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2668 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2671 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2673 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2677 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2683 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2685 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2689 if (maxread > 0x7FFFFFFF)
2690 maxread = 0x7FFFFFFF;
2691 *res = (uint32_t)maxread;
2692 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2694 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2698 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2704 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2706 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2710 if (maxwrite > 0x7FFFFFFF)
2711 maxwrite = 0x7FFFFFFF;
2712 *res = (uint32_t)maxwrite;
2713 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2715 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2719 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2724 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2726 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2730 bitmap[1] &= ~FATTR4_WORD1_MODE;
2732 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2736 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2741 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2743 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2746 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2748 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2752 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2758 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2760 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2764 if (len < XDR_MAX_NETOBJ) {
2765 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2766 dprintk("%s: nfs_map_name_to_uid failed!\n",
2769 dprintk("%s: name too long (%u)!\n",
2771 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2773 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2777 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2783 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2785 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2789 if (len < XDR_MAX_NETOBJ) {
2790 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2791 dprintk("%s: nfs_map_group_to_gid failed!\n",
2794 dprintk("%s: name too long (%u)!\n",
2796 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2798 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2802 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2804 uint32_t major = 0, minor = 0;
2808 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2810 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2816 tmp = MKDEV(major, minor);
2817 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2819 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2821 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2825 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2831 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2833 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2836 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2838 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2842 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2848 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2850 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2853 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2855 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2859 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2865 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2867 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2870 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2872 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2876 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2881 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2883 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2886 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2888 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2889 (unsigned long long)*used);
2893 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2902 time->tv_sec = (time_t)sec;
2903 time->tv_nsec = (long)nsec;
2907 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2913 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2915 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2916 status = decode_attr_time(xdr, time);
2917 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2919 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2923 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2929 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2931 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2932 status = decode_attr_time(xdr, time);
2933 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2935 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2939 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2945 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2947 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2948 status = decode_attr_time(xdr, time);
2949 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2951 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2955 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2957 unsigned int attrwords = XDR_QUADLEN(attrlen);
2958 unsigned int nwords = xdr->p - savep;
2960 if (unlikely(attrwords != nwords)) {
2961 dprintk("%s: server returned incorrect attribute length: "
2965 (attrwords < nwords) ? '<' : '>',
2972 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2977 READ32(cinfo->atomic);
2978 READ64(cinfo->before);
2979 READ64(cinfo->after);
2983 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2989 status = decode_op_hdr(xdr, OP_ACCESS);
2995 access->supported = supp;
2996 access->access = acc;
3000 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3005 status = decode_op_hdr(xdr, OP_CLOSE);
3008 READ_BUF(NFS4_STATEID_SIZE);
3009 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3013 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3018 status = decode_op_hdr(xdr, OP_COMMIT);
3022 COPYMEM(res->verf->verifier, 8);
3026 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3032 status = decode_op_hdr(xdr, OP_CREATE);
3035 if ((status = decode_change_info(xdr, cinfo)))
3039 READ_BUF(bmlen << 2);
3043 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3050 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3052 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3054 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3056 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3058 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3060 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3062 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3064 status = verify_attr_len(xdr, savep, attrlen);
3066 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3070 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3077 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3079 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3081 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3084 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3086 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3088 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3090 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3092 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3094 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3097 status = verify_attr_len(xdr, savep, attrlen);
3099 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3103 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3110 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3112 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3114 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3117 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3119 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3122 status = verify_attr_len(xdr, savep, attrlen);
3124 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3128 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3134 int status, fmode = 0;
3137 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3139 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3142 fattr->bitmap[0] = bitmap[0];
3143 fattr->bitmap[1] = bitmap[1];
3145 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3149 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3151 fattr->type = nfs_type2fmt[type].nfs2type;
3152 fmode = nfs_type2fmt[type].mode;
3154 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3156 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3158 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
3160 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3162 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3163 struct nfs4_fs_locations,
3166 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3168 fattr->mode |= fmode;
3169 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3171 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
3173 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
3175 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3177 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3179 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3181 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3183 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3185 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3187 if (fattr->fileid == 0 && fileid != 0)
3188 fattr->fileid = fileid;
3189 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
3190 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
3192 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
3197 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3200 uint32_t attrlen, bitmap[2];
3203 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3205 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3207 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3210 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3212 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3214 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3216 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3218 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3219 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3221 fsinfo->wtpref = fsinfo->wtmax;
3223 status = verify_attr_len(xdr, savep, attrlen);
3225 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3229 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3235 /* Zero handle first to allow comparisons */
3236 memset(fh, 0, sizeof(*fh));
3238 status = decode_op_hdr(xdr, OP_GETFH);
3244 if (len > NFS4_FHSIZE)
3248 COPYMEM(fh->data, len);
3252 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3256 status = decode_op_hdr(xdr, OP_LINK);
3259 return decode_change_info(xdr, cinfo);
3263 * We create the owner, so we know a proper owner.id length is 4.
3265 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3267 uint64_t offset, length, clientid;
3269 uint32_t namelen, type;
3276 fl->fl_start = (loff_t)offset;
3277 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3278 if (length == ~(uint64_t)0)
3279 fl->fl_end = OFFSET_MAX;
3280 fl->fl_type = F_WRLCK;
3282 fl->fl_type = F_RDLCK;
3288 return -NFS4ERR_DENIED;
3291 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3296 status = decode_op_hdr(xdr, OP_LOCK);
3298 READ_BUF(NFS4_STATEID_SIZE);
3299 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3300 } else if (status == -NFS4ERR_DENIED)
3301 return decode_lock_denied(xdr, NULL);
3305 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3308 status = decode_op_hdr(xdr, OP_LOCKT);
3309 if (status == -NFS4ERR_DENIED)
3310 return decode_lock_denied(xdr, res->denied);
3314 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3319 status = decode_op_hdr(xdr, OP_LOCKU);
3321 READ_BUF(NFS4_STATEID_SIZE);
3322 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3327 static int decode_lookup(struct xdr_stream *xdr)
3329 return decode_op_hdr(xdr, OP_LOOKUP);
3332 /* This is too sick! */
3333 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3336 uint32_t limit_type, nblocks, blocksize;
3340 switch (limit_type) {
3347 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3352 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3355 uint32_t delegation_type;
3358 READ32(delegation_type);
3359 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3360 res->delegation_type = 0;
3363 READ_BUF(NFS4_STATEID_SIZE+4);
3364 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3365 READ32(res->do_recall);
3366 switch (delegation_type) {
3367 case NFS4_OPEN_DELEGATE_READ:
3368 res->delegation_type = FMODE_READ;
3370 case NFS4_OPEN_DELEGATE_WRITE:
3371 res->delegation_type = FMODE_WRITE|FMODE_READ;
3372 if (decode_space_limit(xdr, &res->maxsize) < 0)
3375 return decode_ace(xdr, NULL, res->server->nfs_client);
3378 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3381 uint32_t savewords, bmlen, i;
3384 status = decode_op_hdr(xdr, OP_OPEN);
3387 READ_BUF(NFS4_STATEID_SIZE);
3388 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3390 decode_change_info(xdr, &res->cinfo);
3393 READ32(res->rflags);
3398 READ_BUF(bmlen << 2);
3399 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3400 for (i = 0; i < savewords; ++i)
3401 READ32(res->attrset[i]);
3402 for (; i < NFS4_BITMAP_SIZE; i++)
3403 res->attrset[i] = 0;
3405 return decode_delegation(xdr, res);
3407 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
3411 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3416 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3419 READ_BUF(NFS4_STATEID_SIZE);
3420 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3424 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3429 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3432 READ_BUF(NFS4_STATEID_SIZE);
3433 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3437 static int decode_putfh(struct xdr_stream *xdr)
3439 return decode_op_hdr(xdr, OP_PUTFH);
3442 static int decode_putrootfh(struct xdr_stream *xdr)
3444 return decode_op_hdr(xdr, OP_PUTROOTFH);
3447 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3449 struct kvec *iov = req->rq_rcv_buf.head;
3451 uint32_t count, eof, recvd, hdrlen;
3454 status = decode_op_hdr(xdr, OP_READ);
3460 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3461 recvd = req->rq_rcv_buf.len - hdrlen;
3462 if (count > recvd) {
3463 dprintk("NFS: server cheating in read reply: "
3464 "count %u > recvd %u\n", count, recvd);
3468 xdr_read_pages(xdr, count);
3474 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3476 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3477 struct page *page = *rcvbuf->pages;
3478 struct kvec *iov = rcvbuf->head;
3479 unsigned int nr, pglen = rcvbuf->page_len;
3480 __be32 *end, *entry, *p, *kaddr;
3481 uint32_t len, attrlen, xlen;
3482 int hdrlen, recvd, status;
3484 status = decode_op_hdr(xdr, OP_READDIR);
3488 COPYMEM(readdir->verifier.data, 8);
3489 dprintk("%s: verifier = 0x%x%x\n",
3491 ((u32 *)readdir->verifier.data)[0],
3492 ((u32 *)readdir->verifier.data)[1]);
3495 hdrlen = (char *) p - (char *) iov->iov_base;
3496 recvd = rcvbuf->len - hdrlen;
3499 xdr_read_pages(xdr, pglen);
3501 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3502 kaddr = p = kmap_atomic(page, KM_USER0);
3503 end = p + ((pglen + readdir->pgbase) >> 2);
3505 for (nr = 0; *p++; nr++) {
3508 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3509 p += 2; /* cookie */
3510 len = ntohl(*p++); /* filename length */
3511 if (len > NFS4_MAXNAMLEN) {
3512 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3516 xlen = XDR_QUADLEN(len);
3517 if (end - p < xlen + 1)
3519 dprintk("filename = %*s\n", len, (char *)p);
3521 len = ntohl(*p++); /* bitmap length */
3522 if (end - p < len + 1)
3525 attrlen = XDR_QUADLEN(ntohl(*p++));
3526 if (end - p < attrlen + 2)
3528 p += attrlen; /* attributes */
3531 if (!nr && (entry[0] != 0 || entry[1] == 0))
3534 kunmap_atomic(kaddr, KM_USER0);
3537 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3538 entry[0] = entry[1] = 0;
3539 /* truncate listing ? */
3541 dprintk("NFS: readdir reply truncated!\n");
3546 kunmap_atomic(kaddr, KM_USER0);
3547 return -errno_NFSERR_IO;
3550 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3552 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3553 struct kvec *iov = rcvbuf->head;
3554 int hdrlen, len, recvd;
3559 status = decode_op_hdr(xdr, OP_READLINK);
3563 /* Convert length of symlink */
3566 if (len >= rcvbuf->page_len || len <= 0) {
3567 dprintk("nfs: server returned giant symlink!\n");
3568 return -ENAMETOOLONG;
3570 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3571 recvd = req->rq_rcv_buf.len - hdrlen;
3573 dprintk("NFS: server cheating in readlink reply: "
3574 "count %u > recvd %u\n", len, recvd);
3577 xdr_read_pages(xdr, len);
3579 * The XDR encode routine has set things up so that
3580 * the link text will be copied directly into the
3581 * buffer. We just have to do overflow-checking,
3582 * and and null-terminate the text (the VFS expects
3583 * null-termination).
3585 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3586 kaddr[len+rcvbuf->page_base] = '\0';
3587 kunmap_atomic(kaddr, KM_USER0);
3591 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3595 status = decode_op_hdr(xdr, OP_REMOVE);
3598 status = decode_change_info(xdr, cinfo);
3603 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3604 struct nfs4_change_info *new_cinfo)
3608 status = decode_op_hdr(xdr, OP_RENAME);
3611 if ((status = decode_change_info(xdr, old_cinfo)))
3613 status = decode_change_info(xdr, new_cinfo);
3618 static int decode_renew(struct xdr_stream *xdr)
3620 return decode_op_hdr(xdr, OP_RENEW);
3624 decode_restorefh(struct xdr_stream *xdr)
3626 return decode_op_hdr(xdr, OP_RESTOREFH);
3629 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3635 struct kvec *iov = req->rq_rcv_buf.head;
3639 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3641 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3643 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3646 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3648 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3651 /* We ignore &savep and don't do consistency checks on
3652 * the attr length. Let userspace figure it out.... */
3653 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3654 recvd = req->rq_rcv_buf.len - hdrlen;
3655 if (attrlen > recvd) {
3656 dprintk("NFS: server cheating in getattr"
3657 " acl reply: attrlen %u > recvd %u\n",
3661 xdr_read_pages(xdr, attrlen);
3664 status = -EOPNOTSUPP;
3671 decode_savefh(struct xdr_stream *xdr)
3673 return decode_op_hdr(xdr, OP_SAVEFH);
3676 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3683 status = decode_op_hdr(xdr, OP_SETATTR);
3688 READ_BUF(bmlen << 2);
3692 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3700 if (opnum != OP_SETCLIENTID) {
3701 dprintk("nfs: decode_setclientid: Server returned operation"
3706 if (nfserr == NFS_OK) {
3707 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3708 READ64(clp->cl_clientid);
3709 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3710 } else if (nfserr == NFSERR_CLID_INUSE) {
3713 /* skip netid string */
3718 /* skip uaddr string */
3722 return -NFSERR_CLID_INUSE;
3724 return -nfs4_stat_to_errno(nfserr);
3729 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3731 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3734 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3739 status = decode_op_hdr(xdr, OP_WRITE);
3745 READ32(res->verf->committed);
3746 COPYMEM(res->verf->verifier, 8);
3750 static int decode_delegreturn(struct xdr_stream *xdr)
3752 return decode_op_hdr(xdr, OP_DELEGRETURN);
3756 * Decode OPEN_DOWNGRADE response
3758 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3760 struct xdr_stream xdr;
3761 struct compound_hdr hdr;
3764 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3765 status = decode_compound_hdr(&xdr, &hdr);
3768 status = decode_putfh(&xdr);
3771 status = decode_open_downgrade(&xdr, res);
3774 decode_getfattr(&xdr, res->fattr, res->server);
3780 * END OF "GENERIC" DECODE ROUTINES.
3784 * Decode ACCESS response
3786 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3788 struct xdr_stream xdr;
3789 struct compound_hdr hdr;
3792 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3793 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3795 status = decode_putfh(&xdr);
3798 status = decode_access(&xdr, res);
3801 decode_getfattr(&xdr, res->fattr, res->server);
3807 * Decode LOOKUP response
3809 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3811 struct xdr_stream xdr;
3812 struct compound_hdr hdr;
3815 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3816 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3818 if ((status = decode_putfh(&xdr)) != 0)
3820 if ((status = decode_lookup(&xdr)) != 0)
3822 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3824 status = decode_getfattr(&xdr, res->fattr, res->server);
3830 * Decode LOOKUP_ROOT response
3832 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3834 struct xdr_stream xdr;
3835 struct compound_hdr hdr;
3838 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3839 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3841 if ((status = decode_putrootfh(&xdr)) != 0)
3843 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3844 status = decode_getfattr(&xdr, res->fattr, res->server);
3850 * Decode REMOVE response
3852 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
3854 struct xdr_stream xdr;
3855 struct compound_hdr hdr;
3858 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3859 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3861 if ((status = decode_putfh(&xdr)) != 0)
3863 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3865 decode_getfattr(&xdr, &res->dir_attr, res->server);
3871 * Decode RENAME response
3873 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3875 struct xdr_stream xdr;
3876 struct compound_hdr hdr;
3879 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3880 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3882 if ((status = decode_putfh(&xdr)) != 0)
3884 if ((status = decode_savefh(&xdr)) != 0)
3886 if ((status = decode_putfh(&xdr)) != 0)
3888 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3890 /* Current FH is target directory */
3891 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3893 if ((status = decode_restorefh(&xdr)) != 0)
3895 decode_getfattr(&xdr, res->old_fattr, res->server);
3901 * Decode LINK response
3903 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3905 struct xdr_stream xdr;
3906 struct compound_hdr hdr;
3909 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3910 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3912 if ((status = decode_putfh(&xdr)) != 0)
3914 if ((status = decode_savefh(&xdr)) != 0)
3916 if ((status = decode_putfh(&xdr)) != 0)
3918 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3921 * Note order: OP_LINK leaves the directory as the current
3924 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3926 if ((status = decode_restorefh(&xdr)) != 0)
3928 decode_getfattr(&xdr, res->fattr, res->server);
3934 * Decode CREATE response
3936 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3938 struct xdr_stream xdr;
3939 struct compound_hdr hdr;
3942 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3943 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3945 if ((status = decode_putfh(&xdr)) != 0)
3947 if ((status = decode_savefh(&xdr)) != 0)
3949 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3951 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3953 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3955 if ((status = decode_restorefh(&xdr)) != 0)
3957 decode_getfattr(&xdr, res->dir_fattr, res->server);
3963 * Decode SYMLINK response
3965 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3967 return nfs4_xdr_dec_create(rqstp, p, res);
3971 * Decode GETATTR response
3973 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3975 struct xdr_stream xdr;
3976 struct compound_hdr hdr;
3979 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3980 status = decode_compound_hdr(&xdr, &hdr);
3983 status = decode_putfh(&xdr);
3986 status = decode_getfattr(&xdr, res->fattr, res->server);
3993 * Encode an SETACL request
3996 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3998 struct xdr_stream xdr;
3999 struct compound_hdr hdr = {
4004 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
4005 encode_compound_hdr(&xdr, &hdr);
4006 status = encode_putfh(&xdr, args->fh);
4009 status = encode_setacl(&xdr, args);
4014 * Decode SETACL response
4017 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
4019 struct xdr_stream xdr;
4020 struct compound_hdr hdr;
4023 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4024 status = decode_compound_hdr(&xdr, &hdr);
4027 status = decode_putfh(&xdr);
4030 status = decode_setattr(&xdr, res);
4036 * Decode GETACL response
4039 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
4041 struct xdr_stream xdr;
4042 struct compound_hdr hdr;
4045 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4046 status = decode_compound_hdr(&xdr, &hdr);
4049 status = decode_putfh(&xdr);
4052 status = decode_getacl(&xdr, rqstp, acl_len);
4059 * Decode CLOSE response
4061 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4063 struct xdr_stream xdr;
4064 struct compound_hdr hdr;
4067 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4068 status = decode_compound_hdr(&xdr, &hdr);
4071 status = decode_putfh(&xdr);
4074 status = decode_close(&xdr, res);
4078 * Note: Server may do delete on close for this file
4079 * in which case the getattr call will fail with
4080 * an ESTALE error. Shouldn't be a problem,
4081 * though, since fattr->valid will remain unset.
4083 decode_getfattr(&xdr, res->fattr, res->server);
4089 * Decode OPEN response
4091 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4093 struct xdr_stream xdr;
4094 struct compound_hdr hdr;
4097 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4098 status = decode_compound_hdr(&xdr, &hdr);
4101 status = decode_putfh(&xdr);
4104 status = decode_savefh(&xdr);
4107 status = decode_open(&xdr, res);
4110 if (decode_getfh(&xdr, &res->fh) != 0)
4112 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4114 if (decode_restorefh(&xdr) != 0)
4116 decode_getfattr(&xdr, res->dir_attr, res->server);
4122 * Decode OPEN_CONFIRM response
4124 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4126 struct xdr_stream xdr;
4127 struct compound_hdr hdr;
4130 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4131 status = decode_compound_hdr(&xdr, &hdr);
4134 status = decode_putfh(&xdr);
4137 status = decode_open_confirm(&xdr, res);
4143 * Decode OPEN response
4145 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4147 struct xdr_stream xdr;
4148 struct compound_hdr hdr;
4151 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4152 status = decode_compound_hdr(&xdr, &hdr);
4155 status = decode_putfh(&xdr);
4158 status = decode_open(&xdr, res);
4161 decode_getfattr(&xdr, res->f_attr, res->server);
4167 * Decode SETATTR response
4169 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4171 struct xdr_stream xdr;
4172 struct compound_hdr hdr;
4175 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4176 status = decode_compound_hdr(&xdr, &hdr);
4179 status = decode_putfh(&xdr);
4182 status = decode_setattr(&xdr, res);
4185 status = decode_getfattr(&xdr, res->fattr, res->server);
4186 if (status == NFS4ERR_DELAY)
4193 * Decode LOCK response
4195 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4197 struct xdr_stream xdr;
4198 struct compound_hdr hdr;
4201 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4202 status = decode_compound_hdr(&xdr, &hdr);
4205 status = decode_putfh(&xdr);
4208 status = decode_lock(&xdr, res);
4214 * Decode LOCKT response
4216 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4218 struct xdr_stream xdr;
4219 struct compound_hdr hdr;
4222 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4223 status = decode_compound_hdr(&xdr, &hdr);
4226 status = decode_putfh(&xdr);
4229 status = decode_lockt(&xdr, res);
4235 * Decode LOCKU response
4237 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4239 struct xdr_stream xdr;
4240 struct compound_hdr hdr;
4243 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4244 status = decode_compound_hdr(&xdr, &hdr);
4247 status = decode_putfh(&xdr);
4250 status = decode_locku(&xdr, res);
4256 * Decode READLINK response
4258 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
4260 struct xdr_stream xdr;
4261 struct compound_hdr hdr;
4264 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4265 status = decode_compound_hdr(&xdr, &hdr);
4268 status = decode_putfh(&xdr);
4271 status = decode_readlink(&xdr, rqstp);
4277 * Decode READDIR response
4279 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4281 struct xdr_stream xdr;
4282 struct compound_hdr hdr;
4285 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4286 status = decode_compound_hdr(&xdr, &hdr);
4289 status = decode_putfh(&xdr);
4292 status = decode_readdir(&xdr, rqstp, res);
4298 * Decode Read response
4300 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4302 struct xdr_stream xdr;
4303 struct compound_hdr hdr;
4306 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4307 status = decode_compound_hdr(&xdr, &hdr);
4310 status = decode_putfh(&xdr);
4313 status = decode_read(&xdr, rqstp, res);
4315 status = res->count;
4321 * Decode WRITE response
4323 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4325 struct xdr_stream xdr;
4326 struct compound_hdr hdr;
4329 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4330 status = decode_compound_hdr(&xdr, &hdr);
4333 status = decode_putfh(&xdr);
4336 status = decode_write(&xdr, res);
4339 decode_getfattr(&xdr, res->fattr, res->server);
4341 status = res->count;
4347 * Decode COMMIT response
4349 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4351 struct xdr_stream xdr;
4352 struct compound_hdr hdr;
4355 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4356 status = decode_compound_hdr(&xdr, &hdr);
4359 status = decode_putfh(&xdr);
4362 status = decode_commit(&xdr, res);
4365 decode_getfattr(&xdr, res->fattr, res->server);
4373 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4375 struct xdr_stream xdr;
4376 struct compound_hdr hdr;
4379 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4380 status = decode_compound_hdr(&xdr, &hdr);
4382 status = decode_putfh(&xdr);
4384 status = decode_fsinfo(&xdr, fsinfo);
4386 status = -nfs4_stat_to_errno(hdr.status);
4393 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
4395 struct xdr_stream xdr;
4396 struct compound_hdr hdr;
4399 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4400 status = decode_compound_hdr(&xdr, &hdr);
4402 status = decode_putfh(&xdr);
4404 status = decode_pathconf(&xdr, pathconf);
4411 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
4413 struct xdr_stream xdr;
4414 struct compound_hdr hdr;
4417 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4418 status = decode_compound_hdr(&xdr, &hdr);
4420 status = decode_putfh(&xdr);
4422 status = decode_statfs(&xdr, fsstat);
4427 * GETATTR_BITMAP request
4429 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4431 struct xdr_stream xdr;
4432 struct compound_hdr hdr;
4435 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4436 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4438 if ((status = decode_putfh(&xdr)) != 0)
4440 status = decode_server_caps(&xdr, res);
4446 * Decode RENEW response
4448 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4450 struct xdr_stream xdr;
4451 struct compound_hdr hdr;
4454 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4455 status = decode_compound_hdr(&xdr, &hdr);
4457 status = decode_renew(&xdr);
4462 * a SETCLIENTID request
4464 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4465 struct nfs_client *clp)
4467 struct xdr_stream xdr;
4468 struct compound_hdr hdr;
4471 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4472 status = decode_compound_hdr(&xdr, &hdr);
4474 status = decode_setclientid(&xdr, clp);
4476 status = -nfs4_stat_to_errno(hdr.status);
4481 * a SETCLIENTID_CONFIRM request
4483 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4485 struct xdr_stream xdr;
4486 struct compound_hdr hdr;
4489 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4490 status = decode_compound_hdr(&xdr, &hdr);
4492 status = decode_setclientid_confirm(&xdr);
4494 status = decode_putrootfh(&xdr);
4496 status = decode_fsinfo(&xdr, fsinfo);
4498 status = -nfs4_stat_to_errno(hdr.status);
4503 * DELEGRETURN request
4505 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4507 struct xdr_stream xdr;
4508 struct compound_hdr hdr;
4511 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4512 status = decode_compound_hdr(&xdr, &hdr);
4515 status = decode_putfh(&xdr);
4518 status = decode_delegreturn(&xdr);
4519 decode_getfattr(&xdr, res->fattr, res->server);
4525 * FS_LOCATIONS request
4527 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
4529 struct xdr_stream xdr;
4530 struct compound_hdr hdr;
4533 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4534 status = decode_compound_hdr(&xdr, &hdr);
4537 if ((status = decode_putfh(&xdr)) != 0)
4539 if ((status = decode_lookup(&xdr)) != 0)
4541 xdr_enter_page(&xdr, PAGE_SIZE);
4542 status = decode_getfattr(&xdr, &res->fattr, res->server);
4547 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4549 uint32_t bitmap[2] = {0};
4554 return ERR_PTR(-EAGAIN);
4556 return ERR_PTR(-EBADCOOKIE);
4559 entry->prev_cookie = entry->cookie;
4560 p = xdr_decode_hyper(p, &entry->cookie);
4561 entry->len = ntohl(*p++);
4562 entry->name = (const char *) p;
4563 p += XDR_QUADLEN(entry->len);
4566 * In case the server doesn't return an inode number,
4567 * we fake one here. (We don't use inode number 0,
4568 * since glibc seems to choke on it...)
4572 len = ntohl(*p++); /* bitmap length */
4574 bitmap[0] = ntohl(*p++);
4576 bitmap[1] = ntohl(*p++);
4580 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4582 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4583 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4584 /* Ignore the return value of rdattr_error for now */
4588 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4589 xdr_decode_hyper(p, &entry->ino);
4590 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4591 xdr_decode_hyper(p, &entry->ino);
4595 entry->eof = !p[0] && p[1];
4600 * We need to translate between nfs status return values and
4601 * the local errno values which may not be the same.
4608 { NFS4ERR_PERM, EPERM },
4609 { NFS4ERR_NOENT, ENOENT },
4610 { NFS4ERR_IO, errno_NFSERR_IO },
4611 { NFS4ERR_NXIO, ENXIO },
4612 { NFS4ERR_ACCESS, EACCES },
4613 { NFS4ERR_EXIST, EEXIST },
4614 { NFS4ERR_XDEV, EXDEV },
4615 { NFS4ERR_NOTDIR, ENOTDIR },
4616 { NFS4ERR_ISDIR, EISDIR },
4617 { NFS4ERR_INVAL, EINVAL },
4618 { NFS4ERR_FBIG, EFBIG },
4619 { NFS4ERR_NOSPC, ENOSPC },
4620 { NFS4ERR_ROFS, EROFS },
4621 { NFS4ERR_MLINK, EMLINK },
4622 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4623 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4624 { NFS4ERR_DQUOT, EDQUOT },
4625 { NFS4ERR_STALE, ESTALE },
4626 { NFS4ERR_BADHANDLE, EBADHANDLE },
4627 { NFS4ERR_BADOWNER, EINVAL },
4628 { NFS4ERR_BADNAME, EINVAL },
4629 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4630 { NFS4ERR_NOTSUPP, ENOTSUPP },
4631 { NFS4ERR_TOOSMALL, ETOOSMALL },
4632 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4633 { NFS4ERR_BADTYPE, EBADTYPE },
4634 { NFS4ERR_LOCKED, EAGAIN },
4635 { NFS4ERR_RESOURCE, EREMOTEIO },
4636 { NFS4ERR_SYMLINK, ELOOP },
4637 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4638 { NFS4ERR_DEADLOCK, EDEADLK },
4639 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4640 * to be handled by a
4647 * Convert an NFS error code to a local one.
4648 * This one is used jointly by NFSv2 and NFSv3.
4651 nfs4_stat_to_errno(int stat)
4654 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4655 if (nfs_errtbl[i].stat == stat)
4656 return nfs_errtbl[i].errno;
4658 if (stat <= 10000 || stat > 10100) {
4659 /* The server is looney tunes. */
4660 return ESERVERFAULT;
4662 /* If we cannot translate the error, the recovery routines should
4664 * Note: remaining NFSv4 error codes have values > 10000, so should
4665 * not conflict with native Linux error codes.
4670 #define PROC(proc, argtype, restype) \
4671 [NFSPROC4_CLNT_##proc] = { \
4672 .p_proc = NFSPROC4_COMPOUND, \
4673 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4674 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4675 .p_arglen = NFS4_##argtype##_sz, \
4676 .p_replen = NFS4_##restype##_sz, \
4677 .p_statidx = NFSPROC4_CLNT_##proc, \
4681 struct rpc_procinfo nfs4_procedures[] = {
4682 PROC(READ, enc_read, dec_read),
4683 PROC(WRITE, enc_write, dec_write),
4684 PROC(COMMIT, enc_commit, dec_commit),
4685 PROC(OPEN, enc_open, dec_open),
4686 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4687 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4688 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4689 PROC(CLOSE, enc_close, dec_close),
4690 PROC(SETATTR, enc_setattr, dec_setattr),
4691 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4692 PROC(RENEW, enc_renew, dec_renew),
4693 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4694 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4695 PROC(LOCK, enc_lock, dec_lock),
4696 PROC(LOCKT, enc_lockt, dec_lockt),
4697 PROC(LOCKU, enc_locku, dec_locku),
4698 PROC(ACCESS, enc_access, dec_access),
4699 PROC(GETATTR, enc_getattr, dec_getattr),
4700 PROC(LOOKUP, enc_lookup, dec_lookup),
4701 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4702 PROC(REMOVE, enc_remove, dec_remove),
4703 PROC(RENAME, enc_rename, dec_rename),
4704 PROC(LINK, enc_link, dec_link),
4705 PROC(SYMLINK, enc_symlink, dec_symlink),
4706 PROC(CREATE, enc_create, dec_create),
4707 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4708 PROC(STATFS, enc_statfs, dec_statfs),
4709 PROC(READLINK, enc_readlink, dec_readlink),
4710 PROC(READDIR, enc_readdir, dec_readdir),
4711 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4712 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4713 PROC(GETACL, enc_getacl, dec_getacl),
4714 PROC(SETACL, enc_setacl, dec_setacl),
4715 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4718 struct rpc_version nfs_version4 = {
4720 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4721 .procs = nfs4_procedures