4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 4)
74 #define lock_owner_id_maxsz (1 + 4)
75 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
76 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78 #define op_encode_hdr_maxsz (1)
79 #define op_decode_hdr_maxsz (2)
80 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
87 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
92 #define nfs4_fattr_bitmap_maxsz 3
93 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
94 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
96 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 /* This is based on getfattr, which uses the most attributes: */
99 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
101 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
104 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
110 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
111 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
114 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116 #define decode_renew_maxsz (op_decode_hdr_maxsz)
117 #define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
125 #define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
128 1024) /* large value for CLID_INUSE */
129 #define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132 #define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
134 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
136 #define encode_share_access_maxsz \
138 #define encode_createmode_maxsz (1 + encode_attrs_maxsz)
139 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141 #define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
147 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
149 #define decode_change_info_maxsz (5)
150 #define decode_open_maxsz (op_decode_hdr_maxsz + \
151 decode_stateid_maxsz + \
152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
155 #define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158 #define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161 #define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165 #define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168 #define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170 #define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
175 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177 #define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
185 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186 #define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188 #define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
193 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
197 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
199 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
202 #define encode_link_maxsz (op_encode_hdr_maxsz + \
204 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
205 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
207 1 + encode_stateid_maxsz + 8)
208 #define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz)
210 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz)
212 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
213 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
216 encode_stateid_maxsz + \
218 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz)
220 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
222 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
226 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227 #define encode_create_maxsz (op_encode_hdr_maxsz + \
228 1 + 2 + nfs4_name_maxsz + \
230 #define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
233 #define encode_statfs_maxsz (encode_getattr_maxsz)
234 #define decode_statfs_maxsz (decode_getattr_maxsz)
235 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
237 #define encode_getacl_maxsz (encode_getattr_maxsz)
238 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
239 nfs4_fattr_bitmap_maxsz + 1)
240 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
241 encode_stateid_maxsz + 3)
242 #define decode_setacl_maxsz (decode_setattr_maxsz)
243 #define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245 #define decode_fs_locations_maxsz \
247 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
248 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
249 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
250 encode_putfh_maxsz + \
252 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
253 decode_putfh_maxsz + \
255 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
256 encode_putfh_maxsz + \
257 encode_readlink_maxsz)
258 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
259 decode_putfh_maxsz + \
260 decode_readlink_maxsz)
261 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
262 encode_putfh_maxsz + \
263 encode_readdir_maxsz)
264 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
265 decode_putfh_maxsz + \
266 decode_readdir_maxsz)
267 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
268 encode_putfh_maxsz + \
269 encode_write_maxsz + \
270 encode_getattr_maxsz)
271 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
272 decode_putfh_maxsz + \
273 decode_write_maxsz + \
274 decode_getattr_maxsz)
275 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
276 encode_putfh_maxsz + \
277 encode_commit_maxsz + \
278 encode_getattr_maxsz)
279 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
280 decode_putfh_maxsz + \
281 decode_commit_maxsz + \
282 decode_getattr_maxsz)
283 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
284 encode_putfh_maxsz + \
285 encode_savefh_maxsz + \
286 encode_open_maxsz + \
287 encode_getfh_maxsz + \
288 encode_getattr_maxsz + \
289 encode_restorefh_maxsz + \
290 encode_getattr_maxsz)
291 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
292 decode_putfh_maxsz + \
293 decode_savefh_maxsz + \
294 decode_open_maxsz + \
295 decode_getfh_maxsz + \
296 decode_getattr_maxsz + \
297 decode_restorefh_maxsz + \
298 decode_getattr_maxsz)
299 #define NFS4_enc_open_confirm_sz \
300 (compound_encode_hdr_maxsz + \
301 encode_putfh_maxsz + \
302 encode_open_confirm_maxsz)
303 #define NFS4_dec_open_confirm_sz \
304 (compound_decode_hdr_maxsz + \
305 decode_putfh_maxsz + \
306 decode_open_confirm_maxsz)
307 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
308 encode_putfh_maxsz + \
309 encode_open_maxsz + \
310 encode_getattr_maxsz)
311 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
312 decode_putfh_maxsz + \
313 decode_open_maxsz + \
314 decode_getattr_maxsz)
315 #define NFS4_enc_open_downgrade_sz \
316 (compound_encode_hdr_maxsz + \
317 encode_putfh_maxsz + \
318 encode_open_downgrade_maxsz + \
319 encode_getattr_maxsz)
320 #define NFS4_dec_open_downgrade_sz \
321 (compound_decode_hdr_maxsz + \
322 decode_putfh_maxsz + \
323 decode_open_downgrade_maxsz + \
324 decode_getattr_maxsz)
325 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
326 encode_putfh_maxsz + \
327 encode_close_maxsz + \
328 encode_getattr_maxsz)
329 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
330 decode_putfh_maxsz + \
331 decode_close_maxsz + \
332 decode_getattr_maxsz)
333 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
334 encode_putfh_maxsz + \
335 encode_setattr_maxsz + \
336 encode_getattr_maxsz)
337 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
338 decode_putfh_maxsz + \
339 decode_setattr_maxsz + \
340 decode_getattr_maxsz)
341 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
342 encode_putfh_maxsz + \
344 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
345 decode_putfh_maxsz + \
347 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
349 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
351 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
352 encode_setclientid_maxsz)
353 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
354 decode_setclientid_maxsz)
355 #define NFS4_enc_setclientid_confirm_sz \
356 (compound_encode_hdr_maxsz + \
357 encode_setclientid_confirm_maxsz + \
358 encode_putrootfh_maxsz + \
360 #define NFS4_dec_setclientid_confirm_sz \
361 (compound_decode_hdr_maxsz + \
362 decode_setclientid_confirm_maxsz + \
363 decode_putrootfh_maxsz + \
365 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
366 encode_putfh_maxsz + \
368 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
369 decode_putfh_maxsz + \
371 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
372 encode_putfh_maxsz + \
374 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
375 decode_putfh_maxsz + \
377 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
380 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
381 decode_putfh_maxsz + \
383 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_access_maxsz + \
386 encode_getattr_maxsz)
387 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
388 decode_putfh_maxsz + \
389 decode_access_maxsz + \
390 decode_getattr_maxsz)
391 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
392 encode_putfh_maxsz + \
393 encode_getattr_maxsz)
394 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
395 decode_putfh_maxsz + \
396 decode_getattr_maxsz)
397 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
398 encode_putfh_maxsz + \
399 encode_lookup_maxsz + \
400 encode_getattr_maxsz + \
402 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
403 decode_putfh_maxsz + \
404 decode_lookup_maxsz + \
405 decode_getattr_maxsz + \
407 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
408 encode_putrootfh_maxsz + \
409 encode_getattr_maxsz + \
411 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
412 decode_putrootfh_maxsz + \
413 decode_getattr_maxsz + \
415 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
416 encode_putfh_maxsz + \
417 encode_remove_maxsz + \
418 encode_getattr_maxsz)
419 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
420 decode_putfh_maxsz + \
421 decode_remove_maxsz + \
422 decode_getattr_maxsz)
423 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
424 encode_putfh_maxsz + \
425 encode_savefh_maxsz + \
426 encode_putfh_maxsz + \
427 encode_rename_maxsz + \
428 encode_getattr_maxsz + \
429 encode_restorefh_maxsz + \
430 encode_getattr_maxsz)
431 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
432 decode_putfh_maxsz + \
433 decode_savefh_maxsz + \
434 decode_putfh_maxsz + \
435 decode_rename_maxsz + \
436 decode_getattr_maxsz + \
437 decode_restorefh_maxsz + \
438 decode_getattr_maxsz)
439 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
440 encode_putfh_maxsz + \
441 encode_savefh_maxsz + \
442 encode_putfh_maxsz + \
443 encode_link_maxsz + \
444 decode_getattr_maxsz + \
445 encode_restorefh_maxsz + \
446 decode_getattr_maxsz)
447 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
448 decode_putfh_maxsz + \
449 decode_savefh_maxsz + \
450 decode_putfh_maxsz + \
451 decode_link_maxsz + \
452 decode_getattr_maxsz + \
453 decode_restorefh_maxsz + \
454 decode_getattr_maxsz)
455 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
456 encode_putfh_maxsz + \
457 encode_symlink_maxsz + \
458 encode_getattr_maxsz + \
460 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
461 decode_putfh_maxsz + \
462 decode_symlink_maxsz + \
463 decode_getattr_maxsz + \
465 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
466 encode_putfh_maxsz + \
467 encode_savefh_maxsz + \
468 encode_create_maxsz + \
469 encode_getfh_maxsz + \
470 encode_getattr_maxsz + \
471 encode_restorefh_maxsz + \
472 encode_getattr_maxsz)
473 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
474 decode_putfh_maxsz + \
475 decode_savefh_maxsz + \
476 decode_create_maxsz + \
477 decode_getfh_maxsz + \
478 decode_getattr_maxsz + \
479 decode_restorefh_maxsz + \
480 decode_getattr_maxsz)
481 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
482 encode_putfh_maxsz + \
483 encode_getattr_maxsz)
484 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
485 decode_putfh_maxsz + \
486 decode_getattr_maxsz)
487 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
488 encode_putfh_maxsz + \
490 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
491 decode_putfh_maxsz + \
493 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
494 encode_putfh_maxsz + \
495 encode_getattr_maxsz)
496 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
497 decode_putfh_maxsz + \
498 decode_getattr_maxsz)
499 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
500 encode_putfh_maxsz + \
501 encode_delegreturn_maxsz + \
502 encode_getattr_maxsz)
503 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
504 decode_delegreturn_maxsz + \
505 decode_getattr_maxsz)
506 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
507 encode_putfh_maxsz + \
509 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
510 decode_putfh_maxsz + \
512 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
513 encode_putfh_maxsz + \
515 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
516 decode_putfh_maxsz + \
518 #define NFS4_enc_fs_locations_sz \
519 (compound_encode_hdr_maxsz + \
520 encode_putfh_maxsz + \
521 encode_lookup_maxsz + \
522 encode_fs_locations_maxsz)
523 #define NFS4_dec_fs_locations_sz \
524 (compound_decode_hdr_maxsz + \
525 decode_putfh_maxsz + \
526 decode_lookup_maxsz + \
527 decode_fs_locations_maxsz)
529 static const umode_t nfs_type2fmt[] = {
536 [NF4SOCK] = S_IFSOCK,
542 struct compound_hdr {
551 * START OF "GENERIC" ENCODE ROUTINES.
552 * These may look a little ugly since they are imported from a "generic"
553 * set of XDR encode/decode routines which are intended to be shared by
554 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
556 * If the pain of reading these is too great, it should be a straightforward
557 * task to translate them into Linux-specific versions which are more
558 * consistent with the style used in NFSv2/v3...
560 #define WRITE32(n) *p++ = htonl(n)
561 #define WRITE64(n) do { \
562 *p++ = htonl((uint32_t)((n) >> 32)); \
563 *p++ = htonl((uint32_t)(n)); \
565 #define WRITEMEM(ptr,nbytes) do { \
566 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
569 #define RESERVE_SPACE(nbytes) do { \
570 p = xdr_reserve_space(xdr, nbytes); \
574 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
578 p = xdr_reserve_space(xdr, 4 + len);
580 xdr_encode_opaque(p, str, len);
583 static void encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
587 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
588 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
589 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
590 WRITE32(hdr->taglen);
591 WRITEMEM(hdr->tag, hdr->taglen);
592 WRITE32(NFS4_MINOR_VERSION);
597 static void encode_nops(struct compound_hdr *hdr)
599 *hdr->nops_p = htonl(hdr->nops);
602 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
606 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
608 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
611 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
613 char owner_name[IDMAP_NAMESZ];
614 char owner_group[IDMAP_NAMESZ];
615 int owner_namelen = 0;
616 int owner_grouplen = 0;
624 * We reserve enough space to write the entire attribute buffer at once.
625 * In the worst-case, this would be
626 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
627 * = 36 bytes, plus any contribution from variable-length fields
628 * such as owner/group.
633 if (iap->ia_valid & ATTR_SIZE)
635 if (iap->ia_valid & ATTR_MODE)
637 if (iap->ia_valid & ATTR_UID) {
638 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
639 if (owner_namelen < 0) {
640 dprintk("nfs: couldn't resolve uid %d to string\n",
643 strcpy(owner_name, "nobody");
644 owner_namelen = sizeof("nobody") - 1;
647 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
649 if (iap->ia_valid & ATTR_GID) {
650 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
651 if (owner_grouplen < 0) {
652 dprintk("nfs: couldn't resolve gid %d to string\n",
654 strcpy(owner_group, "nobody");
655 owner_grouplen = sizeof("nobody") - 1;
658 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
660 if (iap->ia_valid & ATTR_ATIME_SET)
662 else if (iap->ia_valid & ATTR_ATIME)
664 if (iap->ia_valid & ATTR_MTIME_SET)
666 else if (iap->ia_valid & ATTR_MTIME)
671 * We write the bitmap length now, but leave the bitmap and the attribute
672 * buffer length to be backfilled at the end of this routine.
678 if (iap->ia_valid & ATTR_SIZE) {
679 bmval0 |= FATTR4_WORD0_SIZE;
680 WRITE64(iap->ia_size);
682 if (iap->ia_valid & ATTR_MODE) {
683 bmval1 |= FATTR4_WORD1_MODE;
684 WRITE32(iap->ia_mode & S_IALLUGO);
686 if (iap->ia_valid & ATTR_UID) {
687 bmval1 |= FATTR4_WORD1_OWNER;
688 WRITE32(owner_namelen);
689 WRITEMEM(owner_name, owner_namelen);
691 if (iap->ia_valid & ATTR_GID) {
692 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
693 WRITE32(owner_grouplen);
694 WRITEMEM(owner_group, owner_grouplen);
696 if (iap->ia_valid & ATTR_ATIME_SET) {
697 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
698 WRITE32(NFS4_SET_TO_CLIENT_TIME);
700 WRITE32(iap->ia_mtime.tv_sec);
701 WRITE32(iap->ia_mtime.tv_nsec);
703 else if (iap->ia_valid & ATTR_ATIME) {
704 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
705 WRITE32(NFS4_SET_TO_SERVER_TIME);
707 if (iap->ia_valid & ATTR_MTIME_SET) {
708 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
709 WRITE32(NFS4_SET_TO_CLIENT_TIME);
711 WRITE32(iap->ia_mtime.tv_sec);
712 WRITE32(iap->ia_mtime.tv_nsec);
714 else if (iap->ia_valid & ATTR_MTIME) {
715 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
716 WRITE32(NFS4_SET_TO_SERVER_TIME);
720 * Now we backfill the bitmap and the attribute buffer length.
722 if (len != ((char *)p - (char *)q) + 4) {
723 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
724 len, ((char *)p - (char *)q) + 4);
727 len = (char *)p - (char *)q - 12;
728 *q++ = htonl(bmval0);
729 *q++ = htonl(bmval1);
735 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
745 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
749 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
751 WRITE32(arg->seqid->sequence->counter);
752 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
756 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
762 WRITE64(args->offset);
763 WRITE32(args->count);
767 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
773 WRITE32(create->ftype);
775 switch (create->ftype) {
778 WRITE32(create->u.symlink.len);
779 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
782 case NF4BLK: case NF4CHR:
784 WRITE32(create->u.device.specdata1);
785 WRITE32(create->u.device.specdata2);
792 RESERVE_SPACE(4 + create->name->len);
793 WRITE32(create->name->len);
794 WRITEMEM(create->name->name, create->name->len);
797 encode_attrs(xdr, create->attrs, create->server);
800 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
811 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
823 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
825 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
826 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
829 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
831 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
832 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
835 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
837 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
838 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
841 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
850 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
854 RESERVE_SPACE(8 + name->len);
857 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 void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
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);
908 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
914 WRITE32(nfs4_lock_type(args->fl, 0));
915 WRITE64(args->fl->fl_start);
916 WRITE64(nfs4_lock_length(args->fl));
917 WRITE64(args->lock_owner.clientid);
919 WRITEMEM("lock id:", 8);
920 WRITE64(args->lock_owner.id);
924 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
928 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
930 WRITE32(nfs4_lock_type(args->fl, 0));
931 WRITE32(args->seqid->sequence->counter);
932 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
933 WRITE64(args->fl->fl_start);
934 WRITE64(nfs4_lock_length(args->fl));
938 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
943 RESERVE_SPACE(8 + len);
946 WRITEMEM(name->name, len);
950 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
955 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
957 WRITE32(NFS4_SHARE_ACCESS_READ);
960 WRITE32(NFS4_SHARE_ACCESS_WRITE);
962 case FMODE_READ|FMODE_WRITE:
963 WRITE32(NFS4_SHARE_ACCESS_BOTH);
968 WRITE32(0); /* for linux, share_deny = 0 always */
971 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
975 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
980 WRITE32(arg->seqid->sequence->counter);
981 encode_share_access(xdr, arg->fmode);
983 WRITE64(arg->clientid);
985 WRITEMEM("open id:", 8);
989 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
994 switch(arg->open_flags & O_EXCL) {
996 WRITE32(NFS4_CREATE_UNCHECKED);
997 encode_attrs(xdr, arg->u.attrs, arg->server);
1000 WRITE32(NFS4_CREATE_EXCLUSIVE);
1001 encode_nfs4_verifier(xdr, &arg->u.verifier);
1005 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1010 switch (arg->open_flags & O_CREAT) {
1012 WRITE32(NFS4_OPEN_NOCREATE);
1015 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1016 WRITE32(NFS4_OPEN_CREATE);
1017 encode_createmode(xdr, arg);
1021 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1026 switch (delegation_type) {
1028 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1031 WRITE32(NFS4_OPEN_DELEGATE_READ);
1033 case FMODE_WRITE|FMODE_READ:
1034 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1041 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1046 WRITE32(NFS4_OPEN_CLAIM_NULL);
1047 encode_string(xdr, name->len, name->name);
1050 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1055 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1056 encode_delegation_type(xdr, type);
1059 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1063 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1064 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1065 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1066 encode_string(xdr, name->len, name->name);
1069 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1071 encode_openhdr(xdr, arg);
1072 encode_opentype(xdr, arg);
1073 switch (arg->claim) {
1074 case NFS4_OPEN_CLAIM_NULL:
1075 encode_claim_null(xdr, arg->name);
1077 case NFS4_OPEN_CLAIM_PREVIOUS:
1078 encode_claim_previous(xdr, arg->u.delegation_type);
1080 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1081 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1089 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1093 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1094 WRITE32(OP_OPEN_CONFIRM);
1095 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1096 WRITE32(arg->seqid->sequence->counter);
1100 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1104 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1105 WRITE32(OP_OPEN_DOWNGRADE);
1106 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1107 WRITE32(arg->seqid->sequence->counter);
1108 encode_share_access(xdr, arg->fmode);
1113 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1118 RESERVE_SPACE(8 + len);
1121 WRITEMEM(fh->data, len);
1125 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1130 WRITE32(OP_PUTROOTFH);
1134 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1136 nfs4_stateid stateid;
1139 RESERVE_SPACE(NFS4_STATEID_SIZE);
1140 if (ctx->state != NULL) {
1141 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1142 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1144 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1147 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1154 encode_stateid(xdr, args->context);
1157 WRITE64(args->offset);
1158 WRITE32(args->count);
1162 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1164 uint32_t attrs[2] = {
1165 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1166 FATTR4_WORD1_MOUNTED_ON_FILEID,
1170 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1171 WRITE32(OP_READDIR);
1172 WRITE64(readdir->cookie);
1173 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1174 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1175 WRITE32(readdir->count);
1177 /* Switch to mounted_on_fileid if the server supports it */
1178 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1179 attrs[0] &= ~FATTR4_WORD0_FILEID;
1181 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1182 WRITE32(attrs[0] & readdir->bitmask[0]);
1183 WRITE32(attrs[1] & readdir->bitmask[1]);
1185 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1187 (unsigned long long)readdir->cookie,
1188 ((u32 *)readdir->verifier.data)[0],
1189 ((u32 *)readdir->verifier.data)[1],
1190 attrs[0] & readdir->bitmask[0],
1191 attrs[1] & readdir->bitmask[1]);
1194 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1199 WRITE32(OP_READLINK);
1203 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1207 RESERVE_SPACE(8 + name->len);
1210 WRITEMEM(name->name, name->len);
1214 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1218 RESERVE_SPACE(8 + oldname->len);
1220 WRITE32(oldname->len);
1221 WRITEMEM(oldname->name, oldname->len);
1223 RESERVE_SPACE(4 + newname->len);
1224 WRITE32(newname->len);
1225 WRITEMEM(newname->name, newname->len);
1229 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1235 WRITE64(client_stateid->cl_clientid);
1240 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1245 WRITE32(OP_RESTOREFH);
1250 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1254 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1255 WRITE32(OP_SETATTR);
1256 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1259 WRITE32(FATTR4_WORD0_ACL);
1260 if (arg->acl_len % 4)
1263 WRITE32(arg->acl_len);
1264 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1270 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1279 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1283 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1284 WRITE32(OP_SETATTR);
1285 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1287 encode_attrs(xdr, arg->iap, server);
1290 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1294 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1295 WRITE32(OP_SETCLIENTID);
1296 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1298 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1300 WRITE32(setclientid->sc_prog);
1301 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1302 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1304 WRITE32(setclientid->sc_cb_ident);
1308 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
1312 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1313 WRITE32(OP_SETCLIENTID_CONFIRM);
1314 WRITE64(client_state->cl_clientid);
1315 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1319 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1326 encode_stateid(xdr, args->context);
1329 WRITE64(args->offset);
1330 WRITE32(args->stable);
1331 WRITE32(args->count);
1333 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1337 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1341 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1343 WRITE32(OP_DELEGRETURN);
1344 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1348 * END OF "GENERIC" ENCODE ROUTINES.
1352 * Encode an ACCESS request
1354 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1356 struct xdr_stream xdr;
1357 struct compound_hdr hdr = {
1361 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1362 encode_compound_hdr(&xdr, &hdr);
1363 encode_putfh(&xdr, args->fh, &hdr);
1364 encode_access(&xdr, args->access, &hdr);
1365 encode_getfattr(&xdr, args->bitmask, &hdr);
1371 * Encode LOOKUP request
1373 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1375 struct xdr_stream xdr;
1376 struct compound_hdr hdr = {
1380 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1381 encode_compound_hdr(&xdr, &hdr);
1382 encode_putfh(&xdr, args->dir_fh, &hdr);
1383 encode_lookup(&xdr, args->name, &hdr);
1384 encode_getfh(&xdr, &hdr);
1385 encode_getfattr(&xdr, args->bitmask, &hdr);
1391 * Encode LOOKUP_ROOT request
1393 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1395 struct xdr_stream xdr;
1396 struct compound_hdr hdr = {
1400 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1401 encode_compound_hdr(&xdr, &hdr);
1402 encode_putrootfh(&xdr, &hdr);
1403 encode_getfh(&xdr, &hdr);
1404 encode_getfattr(&xdr, args->bitmask, &hdr);
1410 * Encode REMOVE request
1412 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1414 struct xdr_stream xdr;
1415 struct compound_hdr hdr = {
1419 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1420 encode_compound_hdr(&xdr, &hdr);
1421 encode_putfh(&xdr, args->fh, &hdr);
1422 encode_remove(&xdr, &args->name, &hdr);
1423 encode_getfattr(&xdr, args->bitmask, &hdr);
1429 * Encode RENAME request
1431 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1433 struct xdr_stream xdr;
1434 struct compound_hdr hdr = {
1438 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1439 encode_compound_hdr(&xdr, &hdr);
1440 encode_putfh(&xdr, args->old_dir, &hdr);
1441 encode_savefh(&xdr, &hdr);
1442 encode_putfh(&xdr, args->new_dir, &hdr);
1443 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1444 encode_getfattr(&xdr, args->bitmask, &hdr);
1445 encode_restorefh(&xdr, &hdr);
1446 encode_getfattr(&xdr, args->bitmask, &hdr);
1452 * Encode LINK request
1454 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1456 struct xdr_stream xdr;
1457 struct compound_hdr hdr = {
1461 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1462 encode_compound_hdr(&xdr, &hdr);
1463 encode_putfh(&xdr, args->fh, &hdr);
1464 encode_savefh(&xdr, &hdr);
1465 encode_putfh(&xdr, args->dir_fh, &hdr);
1466 encode_link(&xdr, args->name, &hdr);
1467 encode_getfattr(&xdr, args->bitmask, &hdr);
1468 encode_restorefh(&xdr, &hdr);
1469 encode_getfattr(&xdr, args->bitmask, &hdr);
1475 * Encode CREATE request
1477 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1479 struct xdr_stream xdr;
1480 struct compound_hdr hdr = {
1484 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1485 encode_compound_hdr(&xdr, &hdr);
1486 encode_putfh(&xdr, args->dir_fh, &hdr);
1487 encode_savefh(&xdr, &hdr);
1488 encode_create(&xdr, args, &hdr);
1489 encode_getfh(&xdr, &hdr);
1490 encode_getfattr(&xdr, args->bitmask, &hdr);
1491 encode_restorefh(&xdr, &hdr);
1492 encode_getfattr(&xdr, args->bitmask, &hdr);
1498 * Encode SYMLINK request
1500 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1502 return nfs4_xdr_enc_create(req, p, args);
1506 * Encode GETATTR request
1508 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1510 struct xdr_stream xdr;
1511 struct compound_hdr hdr = {
1515 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1516 encode_compound_hdr(&xdr, &hdr);
1517 encode_putfh(&xdr, args->fh, &hdr);
1518 encode_getfattr(&xdr, args->bitmask, &hdr);
1524 * Encode a CLOSE request
1526 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1528 struct xdr_stream xdr;
1529 struct compound_hdr hdr = {
1533 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1534 encode_compound_hdr(&xdr, &hdr);
1535 encode_putfh(&xdr, args->fh, &hdr);
1536 encode_close(&xdr, args, &hdr);
1537 encode_getfattr(&xdr, args->bitmask, &hdr);
1543 * Encode an OPEN request
1545 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1547 struct xdr_stream xdr;
1548 struct compound_hdr hdr = {
1552 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1553 encode_compound_hdr(&xdr, &hdr);
1554 encode_putfh(&xdr, args->fh, &hdr);
1555 encode_savefh(&xdr, &hdr);
1556 encode_open(&xdr, args, &hdr);
1557 encode_getfh(&xdr, &hdr);
1558 encode_getfattr(&xdr, args->bitmask, &hdr);
1559 encode_restorefh(&xdr, &hdr);
1560 encode_getfattr(&xdr, args->bitmask, &hdr);
1566 * Encode an OPEN_CONFIRM request
1568 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1570 struct xdr_stream xdr;
1571 struct compound_hdr hdr = {
1575 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1576 encode_compound_hdr(&xdr, &hdr);
1577 encode_putfh(&xdr, args->fh, &hdr);
1578 encode_open_confirm(&xdr, args, &hdr);
1584 * Encode an OPEN request with no attributes.
1586 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1588 struct xdr_stream xdr;
1589 struct compound_hdr hdr = {
1593 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1594 encode_compound_hdr(&xdr, &hdr);
1595 encode_putfh(&xdr, args->fh, &hdr);
1596 encode_open(&xdr, args, &hdr);
1597 encode_getfattr(&xdr, args->bitmask, &hdr);
1603 * Encode an OPEN_DOWNGRADE request
1605 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1607 struct xdr_stream xdr;
1608 struct compound_hdr hdr = {
1612 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1613 encode_compound_hdr(&xdr, &hdr);
1614 encode_putfh(&xdr, args->fh, &hdr);
1615 encode_open_downgrade(&xdr, args, &hdr);
1616 encode_getfattr(&xdr, args->bitmask, &hdr);
1622 * Encode a LOCK request
1624 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1626 struct xdr_stream xdr;
1627 struct compound_hdr hdr = {
1631 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1632 encode_compound_hdr(&xdr, &hdr);
1633 encode_putfh(&xdr, args->fh, &hdr);
1634 encode_lock(&xdr, args, &hdr);
1640 * Encode a LOCKT request
1642 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1644 struct xdr_stream xdr;
1645 struct compound_hdr hdr = {
1649 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1650 encode_compound_hdr(&xdr, &hdr);
1651 encode_putfh(&xdr, args->fh, &hdr);
1652 encode_lockt(&xdr, args, &hdr);
1658 * Encode a LOCKU request
1660 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1662 struct xdr_stream xdr;
1663 struct compound_hdr hdr = {
1667 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1668 encode_compound_hdr(&xdr, &hdr);
1669 encode_putfh(&xdr, args->fh, &hdr);
1670 encode_locku(&xdr, args, &hdr);
1676 * Encode a READLINK request
1678 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1680 struct xdr_stream xdr;
1681 struct compound_hdr hdr = {
1684 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1685 unsigned int replen;
1687 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1688 encode_compound_hdr(&xdr, &hdr);
1689 encode_putfh(&xdr, args->fh, &hdr);
1690 encode_readlink(&xdr, args, req, &hdr);
1692 /* set up reply kvec
1693 * toplevel_status + taglen + rescount + OP_PUTFH + status
1694 * + OP_READLINK + status + string length = 8
1696 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readlink_sz) << 2;
1697 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1698 args->pgbase, args->pglen);
1704 * Encode a READDIR request
1706 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1708 struct xdr_stream xdr;
1709 struct compound_hdr hdr = {
1712 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1715 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1716 encode_compound_hdr(&xdr, &hdr);
1717 encode_putfh(&xdr, args->fh, &hdr);
1718 encode_readdir(&xdr, args, req, &hdr);
1720 /* set up reply kvec
1721 * toplevel_status + taglen + rescount + OP_PUTFH + status
1722 * + OP_READDIR + status + verifer(2) = 9
1724 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readdir_sz) << 2;
1725 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1726 args->pgbase, args->count);
1727 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1728 __func__, replen, args->pages,
1729 args->pgbase, args->count);
1735 * Encode a READ request
1737 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1739 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1740 struct xdr_stream xdr;
1741 struct compound_hdr hdr = {
1746 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1747 encode_compound_hdr(&xdr, &hdr);
1748 encode_putfh(&xdr, args->fh, &hdr);
1749 encode_read(&xdr, args, &hdr);
1751 /* set up reply kvec
1752 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1753 * + OP_READ + status + eof + datalen = 9
1755 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1756 xdr_inline_pages(&req->rq_rcv_buf, replen,
1757 args->pages, args->pgbase, args->count);
1758 req->rq_rcv_buf.flags |= XDRBUF_READ;
1764 * Encode an SETATTR request
1766 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1768 struct xdr_stream xdr;
1769 struct compound_hdr hdr = {
1773 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1774 encode_compound_hdr(&xdr, &hdr);
1775 encode_putfh(&xdr, args->fh, &hdr);
1776 encode_setattr(&xdr, args, args->server, &hdr);
1777 encode_getfattr(&xdr, args->bitmask, &hdr);
1783 * Encode a GETACL request
1786 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1787 struct nfs_getaclargs *args)
1789 struct xdr_stream xdr;
1790 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1791 struct compound_hdr hdr = {
1796 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1797 encode_compound_hdr(&xdr, &hdr);
1798 encode_putfh(&xdr, args->fh, &hdr);
1799 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1801 /* set up reply buffer: */
1802 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1803 xdr_inline_pages(&req->rq_rcv_buf, replen,
1804 args->acl_pages, args->acl_pgbase, args->acl_len);
1810 * Encode a WRITE request
1812 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1814 struct xdr_stream xdr;
1815 struct compound_hdr hdr = {
1819 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1820 encode_compound_hdr(&xdr, &hdr);
1821 encode_putfh(&xdr, args->fh, &hdr);
1822 encode_write(&xdr, args, &hdr);
1823 req->rq_snd_buf.flags |= XDRBUF_WRITE;
1824 encode_getfattr(&xdr, args->bitmask, &hdr);
1832 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1834 struct xdr_stream xdr;
1835 struct compound_hdr hdr = {
1839 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1840 encode_compound_hdr(&xdr, &hdr);
1841 encode_putfh(&xdr, args->fh, &hdr);
1842 encode_commit(&xdr, args, &hdr);
1843 encode_getfattr(&xdr, args->bitmask, &hdr);
1851 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1853 struct xdr_stream xdr;
1854 struct compound_hdr hdr = {
1858 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1859 encode_compound_hdr(&xdr, &hdr);
1860 encode_putfh(&xdr, args->fh, &hdr);
1861 encode_fsinfo(&xdr, args->bitmask, &hdr);
1867 * a PATHCONF request
1869 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1871 struct xdr_stream xdr;
1872 struct compound_hdr hdr = {
1876 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1877 encode_compound_hdr(&xdr, &hdr);
1878 encode_putfh(&xdr, args->fh, &hdr);
1879 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
1888 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
1890 struct xdr_stream xdr;
1891 struct compound_hdr hdr = {
1895 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1896 encode_compound_hdr(&xdr, &hdr);
1897 encode_putfh(&xdr, args->fh, &hdr);
1898 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
1899 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
1905 * GETATTR_BITMAP request
1907 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
1908 struct nfs4_server_caps_arg *args)
1910 struct xdr_stream xdr;
1911 struct compound_hdr hdr = {
1915 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1916 encode_compound_hdr(&xdr, &hdr);
1917 encode_putfh(&xdr, args->fhandle, &hdr);
1918 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1919 FATTR4_WORD0_LINK_SUPPORT|
1920 FATTR4_WORD0_SYMLINK_SUPPORT|
1921 FATTR4_WORD0_ACLSUPPORT, &hdr);
1929 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1931 struct xdr_stream xdr;
1932 struct compound_hdr hdr = {
1936 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1937 encode_compound_hdr(&xdr, &hdr);
1938 encode_renew(&xdr, clp, &hdr);
1944 * a SETCLIENTID request
1946 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
1948 struct xdr_stream xdr;
1949 struct compound_hdr hdr = {
1953 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1954 encode_compound_hdr(&xdr, &hdr);
1955 encode_setclientid(&xdr, sc, &hdr);
1961 * a SETCLIENTID_CONFIRM request
1963 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1965 struct xdr_stream xdr;
1966 struct compound_hdr hdr = {
1969 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1971 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1972 encode_compound_hdr(&xdr, &hdr);
1973 encode_setclientid_confirm(&xdr, clp, &hdr);
1974 encode_putrootfh(&xdr, &hdr);
1975 encode_fsinfo(&xdr, lease_bitmap, &hdr);
1981 * DELEGRETURN request
1983 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
1985 struct xdr_stream xdr;
1986 struct compound_hdr hdr = {
1990 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1991 encode_compound_hdr(&xdr, &hdr);
1992 encode_putfh(&xdr, args->fhandle, &hdr);
1993 encode_delegreturn(&xdr, args->stateid, &hdr);
1994 encode_getfattr(&xdr, args->bitmask, &hdr);
2000 * Encode FS_LOCATIONS request
2002 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2004 struct xdr_stream xdr;
2005 struct compound_hdr hdr = {
2008 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
2011 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2012 encode_compound_hdr(&xdr, &hdr);
2013 encode_putfh(&xdr, args->dir_fh, &hdr);
2014 encode_lookup(&xdr, args->name, &hdr);
2015 encode_fs_locations(&xdr, args->bitmask, &hdr);
2018 * toplevel_status + OP_PUTFH + status
2019 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2021 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2022 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2029 * START OF "GENERIC" DECODE ROUTINES.
2030 * These may look a little ugly since they are imported from a "generic"
2031 * set of XDR encode/decode routines which are intended to be shared by
2032 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2034 * If the pain of reading these is too great, it should be a straightforward
2035 * task to translate them into Linux-specific versions which are more
2036 * consistent with the style used in NFSv2/v3...
2038 #define READ32(x) (x) = ntohl(*p++)
2039 #define READ64(x) do { \
2040 (x) = (u64)ntohl(*p++) << 32; \
2041 (x) |= ntohl(*p++); \
2043 #define READTIME(x) do { \
2045 (x.tv_sec) = ntohl(*p++); \
2046 (x.tv_nsec) = ntohl(*p++); \
2048 #define COPYMEM(x,nbytes) do { \
2049 memcpy((x), p, nbytes); \
2050 p += XDR_QUADLEN(nbytes); \
2053 #define READ_BUF(nbytes) do { \
2054 p = xdr_inline_decode(xdr, nbytes); \
2055 if (unlikely(!p)) { \
2056 dprintk("nfs: %s: prematurely hit end of receive" \
2057 " buffer\n", __func__); \
2058 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2059 __func__, xdr->p, nbytes, xdr->end); \
2064 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2071 *string = (char *)p;
2075 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2080 READ32(hdr->status);
2081 READ32(hdr->taglen);
2083 READ_BUF(hdr->taglen + 4);
2084 hdr->tag = (char *)p;
2085 p += XDR_QUADLEN(hdr->taglen);
2087 if (unlikely(hdr->nops < 1))
2088 return nfs4_stat_to_errno(hdr->status);
2092 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2100 if (opnum != expected) {
2101 dprintk("nfs: Server returned operation"
2102 " %d but we issued a request for %d\n",
2107 if (nfserr != NFS_OK)
2108 return nfs4_stat_to_errno(nfserr);
2113 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2116 unsigned int strlen;
2120 return decode_opaque_inline(xdr, &strlen, &str);
2123 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2131 bitmap[0] = bitmap[1] = 0;
2132 READ_BUF((bmlen << 2));
2141 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2151 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2153 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2154 decode_attr_bitmap(xdr, bitmask);
2155 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2157 bitmask[0] = bitmask[1] = 0;
2158 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2162 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2168 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2170 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2173 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2174 dprintk("%s: bad type %d\n", __func__, *type);
2177 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2178 ret = NFS_ATTR_FATTR_TYPE;
2180 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2184 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2190 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2192 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2195 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2196 ret = NFS_ATTR_FATTR_CHANGE;
2198 dprintk("%s: change attribute=%Lu\n", __func__,
2199 (unsigned long long)*change);
2203 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2209 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2211 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2214 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2215 ret = NFS_ATTR_FATTR_SIZE;
2217 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2221 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2226 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2228 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2231 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2233 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2237 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2242 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2244 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2247 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2249 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2253 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2260 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2262 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2264 READ64(fsid->major);
2265 READ64(fsid->minor);
2266 bitmap[0] &= ~FATTR4_WORD0_FSID;
2267 ret = NFS_ATTR_FATTR_FSID;
2269 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
2270 (unsigned long long)fsid->major,
2271 (unsigned long long)fsid->minor);
2275 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2280 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2282 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2285 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2287 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2291 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2295 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2296 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2298 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2301 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2303 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
2307 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2313 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2315 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2318 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2319 ret = NFS_ATTR_FATTR_FILEID;
2321 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2325 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2331 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2333 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2336 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2337 ret = NFS_ATTR_FATTR_FILEID;
2339 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2343 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2349 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2351 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2354 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2356 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
2360 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2366 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2368 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2371 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2373 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
2377 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2383 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2385 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2388 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2390 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
2394 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2405 path->ncomponents = 0;
2406 while (path->ncomponents < n) {
2407 struct nfs4_string *component = &path->components[path->ncomponents];
2408 status = decode_opaque_inline(xdr, &component->len, &component->data);
2409 if (unlikely(status != 0))
2411 if (path->ncomponents != n)
2413 dprintk("%s", component->data);
2414 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2415 path->ncomponents++;
2417 dprintk("cannot parse %d components in path\n", n);
2425 /* a root pathname is sent as a zero component4 */
2426 path->ncomponents = 1;
2427 path->components[0].len=0;
2428 path->components[0].data=NULL;
2429 dprintk("path /\n");
2432 dprintk(" status %d", status);
2437 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2443 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2446 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2448 dprintk("%s: fsroot ", __func__);
2449 status = decode_pathname(xdr, &res->fs_path);
2450 if (unlikely(status != 0))
2456 res->nlocations = 0;
2457 while (res->nlocations < n) {
2459 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2465 dprintk("%s: servers ", __func__);
2466 while (loc->nservers < m) {
2467 struct nfs4_string *server = &loc->servers[loc->nservers];
2468 status = decode_opaque_inline(xdr, &server->len, &server->data);
2469 if (unlikely(status != 0))
2471 dprintk("%s ", server->data);
2472 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2476 dprintk("%s: using first %u of %u servers "
2477 "returned for location %u\n",
2479 NFS4_FS_LOCATION_MAXSERVERS,
2480 m, res->nlocations);
2481 for (i = loc->nservers; i < m; i++) {
2484 status = decode_opaque_inline(xdr, &len, &data);
2485 if (unlikely(status != 0))
2490 status = decode_pathname(xdr, &loc->rootpath);
2491 if (unlikely(status != 0))
2493 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2496 if (res->nlocations != 0)
2497 status = NFS_ATTR_FATTR_V4_REFERRAL;
2499 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
2506 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2512 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2514 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2517 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2519 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
2523 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2529 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2531 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2534 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2536 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
2540 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2546 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2548 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2551 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2553 dprintk("%s: maxname=%u\n", __func__, *maxname);
2557 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2563 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2565 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2569 if (maxread > 0x7FFFFFFF)
2570 maxread = 0x7FFFFFFF;
2571 *res = (uint32_t)maxread;
2572 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2574 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
2578 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2584 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2586 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2590 if (maxwrite > 0x7FFFFFFF)
2591 maxwrite = 0x7FFFFFFF;
2592 *res = (uint32_t)maxwrite;
2593 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2595 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
2599 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
2606 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2608 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2611 *mode = tmp & ~S_IFMT;
2612 bitmap[1] &= ~FATTR4_WORD1_MODE;
2613 ret = NFS_ATTR_FATTR_MODE;
2615 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
2619 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2625 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2627 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2630 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2631 ret = NFS_ATTR_FATTR_NLINK;
2633 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
2637 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2644 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2646 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2650 if (len < XDR_MAX_NETOBJ) {
2651 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
2652 ret = NFS_ATTR_FATTR_OWNER;
2654 dprintk("%s: nfs_map_name_to_uid failed!\n",
2657 dprintk("%s: name too long (%u)!\n",
2659 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2661 dprintk("%s: uid=%d\n", __func__, (int)*uid);
2665 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2672 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2674 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2678 if (len < XDR_MAX_NETOBJ) {
2679 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
2680 ret = NFS_ATTR_FATTR_GROUP;
2682 dprintk("%s: nfs_map_group_to_gid failed!\n",
2685 dprintk("%s: name too long (%u)!\n",
2687 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2689 dprintk("%s: gid=%d\n", __func__, (int)*gid);
2693 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2695 uint32_t major = 0, minor = 0;
2700 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2702 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2708 tmp = MKDEV(major, minor);
2709 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2711 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2712 ret = NFS_ATTR_FATTR_RDEV;
2714 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
2718 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2724 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2726 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2729 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2731 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
2735 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2741 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2743 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2746 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2748 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
2752 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2758 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2760 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2763 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2765 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
2769 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2775 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2777 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2780 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2781 ret = NFS_ATTR_FATTR_SPACE_USED;
2783 dprintk("%s: space used=%Lu\n", __func__,
2784 (unsigned long long)*used);
2788 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2797 time->tv_sec = (time_t)sec;
2798 time->tv_nsec = (long)nsec;
2802 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2808 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2810 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2811 status = decode_attr_time(xdr, time);
2813 status = NFS_ATTR_FATTR_ATIME;
2814 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2816 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
2820 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2826 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2828 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2829 status = decode_attr_time(xdr, time);
2831 status = NFS_ATTR_FATTR_CTIME;
2832 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2834 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
2838 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2844 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2846 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2847 status = decode_attr_time(xdr, time);
2849 status = NFS_ATTR_FATTR_MTIME;
2850 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2852 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
2856 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2858 unsigned int attrwords = XDR_QUADLEN(attrlen);
2859 unsigned int nwords = xdr->p - savep;
2861 if (unlikely(attrwords != nwords)) {
2862 dprintk("%s: server returned incorrect attribute length: "
2866 (attrwords < nwords) ? '<' : '>',
2873 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2878 READ32(cinfo->atomic);
2879 READ64(cinfo->before);
2880 READ64(cinfo->after);
2884 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2890 status = decode_op_hdr(xdr, OP_ACCESS);
2896 access->supported = supp;
2897 access->access = acc;
2901 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2906 status = decode_op_hdr(xdr, OP_CLOSE);
2908 nfs_increment_open_seqid(status, res->seqid);
2911 READ_BUF(NFS4_STATEID_SIZE);
2912 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
2916 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2921 status = decode_op_hdr(xdr, OP_COMMIT);
2925 COPYMEM(res->verf->verifier, 8);
2929 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2935 status = decode_op_hdr(xdr, OP_CREATE);
2938 if ((status = decode_change_info(xdr, cinfo)))
2942 READ_BUF(bmlen << 2);
2946 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2949 uint32_t attrlen, bitmap[2] = {0};
2952 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2954 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2956 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2958 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2960 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2962 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2964 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2966 status = verify_attr_len(xdr, savep, attrlen);
2968 dprintk("%s: xdr returned %d!\n", __func__, -status);
2972 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2975 uint32_t attrlen, bitmap[2] = {0};
2978 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2980 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2982 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2985 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2987 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2989 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2991 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2993 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2995 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2998 status = verify_attr_len(xdr, savep, attrlen);
3000 dprintk("%s: xdr returned %d!\n", __func__, -status);
3004 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3007 uint32_t attrlen, bitmap[2] = {0};
3010 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3012 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3014 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3017 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3019 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3022 status = verify_attr_len(xdr, savep, attrlen);
3024 dprintk("%s: xdr returned %d!\n", __func__, -status);
3028 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3038 status = decode_op_hdr(xdr, OP_GETATTR);
3042 status = decode_attr_bitmap(xdr, bitmap);
3046 status = decode_attr_length(xdr, &attrlen, &savep);
3051 status = decode_attr_type(xdr, bitmap, &type);
3056 fattr->mode |= nfs_type2fmt[type];
3057 fattr->valid |= status;
3060 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3063 fattr->valid |= status;
3065 status = decode_attr_size(xdr, bitmap, &fattr->size);
3068 fattr->valid |= status;
3070 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3073 fattr->valid |= status;
3075 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3078 fattr->valid |= status;
3080 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3081 struct nfs4_fs_locations,
3085 fattr->valid |= status;
3087 status = decode_attr_mode(xdr, bitmap, &fmode);
3091 fattr->mode |= fmode;
3092 fattr->valid |= status;
3095 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3098 fattr->valid |= status;
3100 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3103 fattr->valid |= status;
3105 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3108 fattr->valid |= status;
3110 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3113 fattr->valid |= status;
3115 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3118 fattr->valid |= status;
3120 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3123 fattr->valid |= status;
3125 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3128 fattr->valid |= status;
3130 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3133 fattr->valid |= status;
3135 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3138 if (status != 0 && !(fattr->valid & status)) {
3139 fattr->fileid = fileid;
3140 fattr->valid |= status;
3143 status = verify_attr_len(xdr, savep, attrlen);
3145 dprintk("%s: xdr returned %d\n", __func__, -status);
3150 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3153 uint32_t attrlen, bitmap[2];
3156 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3158 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3160 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3163 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3165 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3167 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3169 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3171 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3172 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3174 fsinfo->wtpref = fsinfo->wtmax;
3176 status = verify_attr_len(xdr, savep, attrlen);
3178 dprintk("%s: xdr returned %d!\n", __func__, -status);
3182 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3188 /* Zero handle first to allow comparisons */
3189 memset(fh, 0, sizeof(*fh));
3191 status = decode_op_hdr(xdr, OP_GETFH);
3197 if (len > NFS4_FHSIZE)
3201 COPYMEM(fh->data, len);
3205 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3209 status = decode_op_hdr(xdr, OP_LINK);
3212 return decode_change_info(xdr, cinfo);
3216 * We create the owner, so we know a proper owner.id length is 4.
3218 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3220 uint64_t offset, length, clientid;
3222 uint32_t namelen, type;
3229 fl->fl_start = (loff_t)offset;
3230 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3231 if (length == ~(uint64_t)0)
3232 fl->fl_end = OFFSET_MAX;
3233 fl->fl_type = F_WRLCK;
3235 fl->fl_type = F_RDLCK;
3241 return -NFS4ERR_DENIED;
3244 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3249 status = decode_op_hdr(xdr, OP_LOCK);
3253 READ_BUF(NFS4_STATEID_SIZE);
3254 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3255 } else if (status == -NFS4ERR_DENIED)
3256 status = decode_lock_denied(xdr, NULL);
3257 if (res->open_seqid != NULL)
3258 nfs_increment_open_seqid(status, res->open_seqid);
3259 nfs_increment_lock_seqid(status, res->lock_seqid);
3264 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3267 status = decode_op_hdr(xdr, OP_LOCKT);
3268 if (status == -NFS4ERR_DENIED)
3269 return decode_lock_denied(xdr, res->denied);
3273 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3278 status = decode_op_hdr(xdr, OP_LOCKU);
3280 nfs_increment_lock_seqid(status, res->seqid);
3282 READ_BUF(NFS4_STATEID_SIZE);
3283 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3288 static int decode_lookup(struct xdr_stream *xdr)
3290 return decode_op_hdr(xdr, OP_LOOKUP);
3293 /* This is too sick! */
3294 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3297 uint32_t limit_type, nblocks, blocksize;
3301 switch (limit_type) {
3308 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3313 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3316 uint32_t delegation_type;
3319 READ32(delegation_type);
3320 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3321 res->delegation_type = 0;
3324 READ_BUF(NFS4_STATEID_SIZE+4);
3325 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3326 READ32(res->do_recall);
3328 switch (delegation_type) {
3329 case NFS4_OPEN_DELEGATE_READ:
3330 res->delegation_type = FMODE_READ;
3332 case NFS4_OPEN_DELEGATE_WRITE:
3333 res->delegation_type = FMODE_WRITE|FMODE_READ;
3334 if (decode_space_limit(xdr, &res->maxsize) < 0)
3337 return decode_ace(xdr, NULL, res->server->nfs_client);
3340 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3343 uint32_t savewords, bmlen, i;
3346 status = decode_op_hdr(xdr, OP_OPEN);
3348 nfs_increment_open_seqid(status, res->seqid);
3351 READ_BUF(NFS4_STATEID_SIZE);
3352 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3354 decode_change_info(xdr, &res->cinfo);
3357 READ32(res->rflags);
3362 READ_BUF(bmlen << 2);
3363 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3364 for (i = 0; i < savewords; ++i)
3365 READ32(res->attrset[i]);
3366 for (; i < NFS4_BITMAP_SIZE; i++)
3367 res->attrset[i] = 0;
3369 return decode_delegation(xdr, res);
3371 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
3375 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3380 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3382 nfs_increment_open_seqid(status, res->seqid);
3385 READ_BUF(NFS4_STATEID_SIZE);
3386 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3390 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3395 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3397 nfs_increment_open_seqid(status, res->seqid);
3400 READ_BUF(NFS4_STATEID_SIZE);
3401 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3405 static int decode_putfh(struct xdr_stream *xdr)
3407 return decode_op_hdr(xdr, OP_PUTFH);
3410 static int decode_putrootfh(struct xdr_stream *xdr)
3412 return decode_op_hdr(xdr, OP_PUTROOTFH);
3415 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3417 struct kvec *iov = req->rq_rcv_buf.head;
3419 uint32_t count, eof, recvd, hdrlen;
3422 status = decode_op_hdr(xdr, OP_READ);
3428 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3429 recvd = req->rq_rcv_buf.len - hdrlen;
3430 if (count > recvd) {
3431 dprintk("NFS: server cheating in read reply: "
3432 "count %u > recvd %u\n", count, recvd);
3436 xdr_read_pages(xdr, count);
3442 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3444 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3445 struct page *page = *rcvbuf->pages;
3446 struct kvec *iov = rcvbuf->head;
3448 u32 recvd, pglen = rcvbuf->page_len;
3449 __be32 *end, *entry, *p, *kaddr;
3450 unsigned int nr = 0;
3453 status = decode_op_hdr(xdr, OP_READDIR);
3457 COPYMEM(readdir->verifier.data, 8);
3458 dprintk("%s: verifier = %08x:%08x\n",
3460 ((u32 *)readdir->verifier.data)[0],
3461 ((u32 *)readdir->verifier.data)[1]);
3464 hdrlen = (char *) p - (char *) iov->iov_base;
3465 recvd = rcvbuf->len - hdrlen;
3468 xdr_read_pages(xdr, pglen);
3470 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3471 kaddr = p = kmap_atomic(page, KM_USER0);
3472 end = p + ((pglen + readdir->pgbase) >> 2);
3475 /* Make sure the packet actually has a value_follows and EOF entry */
3476 if ((entry + 1) > end)
3479 for (; *p++; nr++) {
3480 u32 len, attrlen, xlen;
3483 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3484 p += 2; /* cookie */
3485 len = ntohl(*p++); /* filename length */
3486 if (len > NFS4_MAXNAMLEN) {
3487 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3491 xlen = XDR_QUADLEN(len);
3492 if (end - p < xlen + 1)
3494 dprintk("filename = %*s\n", len, (char *)p);
3496 len = ntohl(*p++); /* bitmap length */
3497 if (end - p < len + 1)
3500 attrlen = XDR_QUADLEN(ntohl(*p++));
3501 if (end - p < attrlen + 2)
3503 p += attrlen; /* attributes */
3507 * Apparently some server sends responses that are a valid size, but
3508 * contain no entries, and have value_follows==0 and EOF==0. For
3509 * those, just set the EOF marker.
3511 if (!nr && entry[1] == 0) {
3512 dprintk("NFS: readdir reply truncated!\n");
3516 kunmap_atomic(kaddr, KM_USER0);
3520 * When we get a short packet there are 2 possibilities. We can
3521 * return an error, or fix up the response to look like a valid
3522 * response and return what we have so far. If there are no
3523 * entries and the packet was short, then return -EIO. If there
3524 * are valid entries in the response, return them and pretend that
3525 * the call was successful, but incomplete. The caller can retry the
3526 * readdir starting at the last cookie.
3528 dprintk("%s: short packet at entry %d\n", __func__, nr);
3529 entry[0] = entry[1] = 0;
3533 kunmap_atomic(kaddr, KM_USER0);
3534 return -errno_NFSERR_IO;
3537 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3539 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3540 struct kvec *iov = rcvbuf->head;
3547 status = decode_op_hdr(xdr, OP_READLINK);
3551 /* Convert length of symlink */
3554 if (len >= rcvbuf->page_len || len <= 0) {
3555 dprintk("nfs: server returned giant symlink!\n");
3556 return -ENAMETOOLONG;
3558 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3559 recvd = req->rq_rcv_buf.len - hdrlen;
3561 dprintk("NFS: server cheating in readlink reply: "
3562 "count %u > recvd %u\n", len, recvd);
3565 xdr_read_pages(xdr, len);
3567 * The XDR encode routine has set things up so that
3568 * the link text will be copied directly into the
3569 * buffer. We just have to do overflow-checking,
3570 * and and null-terminate the text (the VFS expects
3571 * null-termination).
3573 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3574 kaddr[len+rcvbuf->page_base] = '\0';
3575 kunmap_atomic(kaddr, KM_USER0);
3579 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3583 status = decode_op_hdr(xdr, OP_REMOVE);
3586 status = decode_change_info(xdr, cinfo);
3591 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3592 struct nfs4_change_info *new_cinfo)
3596 status = decode_op_hdr(xdr, OP_RENAME);
3599 if ((status = decode_change_info(xdr, old_cinfo)))
3601 status = decode_change_info(xdr, new_cinfo);
3606 static int decode_renew(struct xdr_stream *xdr)
3608 return decode_op_hdr(xdr, OP_RENEW);
3612 decode_restorefh(struct xdr_stream *xdr)
3614 return decode_op_hdr(xdr, OP_RESTOREFH);
3617 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3623 struct kvec *iov = req->rq_rcv_buf.head;
3627 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3629 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3631 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3634 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3636 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3640 /* We ignore &savep and don't do consistency checks on
3641 * the attr length. Let userspace figure it out.... */
3642 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3643 recvd = req->rq_rcv_buf.len - hdrlen;
3644 if (attrlen > recvd) {
3645 dprintk("NFS: server cheating in getattr"
3646 " acl reply: attrlen %u > recvd %u\n",
3650 xdr_read_pages(xdr, attrlen);
3653 status = -EOPNOTSUPP;
3660 decode_savefh(struct xdr_stream *xdr)
3662 return decode_op_hdr(xdr, OP_SAVEFH);
3665 static int decode_setattr(struct xdr_stream *xdr)
3671 status = decode_op_hdr(xdr, OP_SETATTR);
3676 READ_BUF(bmlen << 2);
3680 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3688 if (opnum != OP_SETCLIENTID) {
3689 dprintk("nfs: decode_setclientid: Server returned operation"
3694 if (nfserr == NFS_OK) {
3695 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3696 READ64(clp->cl_clientid);
3697 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3698 } else if (nfserr == NFSERR_CLID_INUSE) {
3701 /* skip netid string */
3706 /* skip uaddr string */
3710 return -NFSERR_CLID_INUSE;
3712 return nfs4_stat_to_errno(nfserr);
3717 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3719 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3722 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3727 status = decode_op_hdr(xdr, OP_WRITE);
3733 READ32(res->verf->committed);
3734 COPYMEM(res->verf->verifier, 8);
3738 static int decode_delegreturn(struct xdr_stream *xdr)
3740 return decode_op_hdr(xdr, OP_DELEGRETURN);
3744 * END OF "GENERIC" DECODE ROUTINES.
3748 * Decode OPEN_DOWNGRADE response
3750 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3752 struct xdr_stream xdr;
3753 struct compound_hdr hdr;
3756 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3757 status = decode_compound_hdr(&xdr, &hdr);
3760 status = decode_putfh(&xdr);
3763 status = decode_open_downgrade(&xdr, res);
3766 decode_getfattr(&xdr, res->fattr, res->server);
3772 * Decode ACCESS response
3774 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3776 struct xdr_stream xdr;
3777 struct compound_hdr hdr;
3780 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3781 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3783 status = decode_putfh(&xdr);
3786 status = decode_access(&xdr, res);
3789 decode_getfattr(&xdr, res->fattr, res->server);
3795 * Decode LOOKUP response
3797 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3799 struct xdr_stream xdr;
3800 struct compound_hdr hdr;
3803 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3804 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3806 if ((status = decode_putfh(&xdr)) != 0)
3808 if ((status = decode_lookup(&xdr)) != 0)
3810 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3812 status = decode_getfattr(&xdr, res->fattr, res->server);
3818 * Decode LOOKUP_ROOT response
3820 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3822 struct xdr_stream xdr;
3823 struct compound_hdr hdr;
3826 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3827 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3829 if ((status = decode_putrootfh(&xdr)) != 0)
3831 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3832 status = decode_getfattr(&xdr, res->fattr, res->server);
3838 * Decode REMOVE response
3840 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
3842 struct xdr_stream xdr;
3843 struct compound_hdr hdr;
3846 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3847 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3849 if ((status = decode_putfh(&xdr)) != 0)
3851 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3853 decode_getfattr(&xdr, &res->dir_attr, res->server);
3859 * Decode RENAME response
3861 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3863 struct xdr_stream xdr;
3864 struct compound_hdr hdr;
3867 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3868 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3870 if ((status = decode_putfh(&xdr)) != 0)
3872 if ((status = decode_savefh(&xdr)) != 0)
3874 if ((status = decode_putfh(&xdr)) != 0)
3876 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3878 /* Current FH is target directory */
3879 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3881 if ((status = decode_restorefh(&xdr)) != 0)
3883 decode_getfattr(&xdr, res->old_fattr, res->server);
3889 * Decode LINK response
3891 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3893 struct xdr_stream xdr;
3894 struct compound_hdr hdr;
3897 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3898 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3900 if ((status = decode_putfh(&xdr)) != 0)
3902 if ((status = decode_savefh(&xdr)) != 0)
3904 if ((status = decode_putfh(&xdr)) != 0)
3906 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3909 * Note order: OP_LINK leaves the directory as the current
3912 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3914 if ((status = decode_restorefh(&xdr)) != 0)
3916 decode_getfattr(&xdr, res->fattr, res->server);
3922 * Decode CREATE response
3924 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3926 struct xdr_stream xdr;
3927 struct compound_hdr hdr;
3930 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3931 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3933 if ((status = decode_putfh(&xdr)) != 0)
3935 if ((status = decode_savefh(&xdr)) != 0)
3937 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3939 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3941 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3943 if ((status = decode_restorefh(&xdr)) != 0)
3945 decode_getfattr(&xdr, res->dir_fattr, res->server);
3951 * Decode SYMLINK response
3953 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3955 return nfs4_xdr_dec_create(rqstp, p, res);
3959 * Decode GETATTR response
3961 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3963 struct xdr_stream xdr;
3964 struct compound_hdr hdr;
3967 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3968 status = decode_compound_hdr(&xdr, &hdr);
3971 status = decode_putfh(&xdr);
3974 status = decode_getfattr(&xdr, res->fattr, res->server);
3980 * Encode an SETACL request
3983 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3985 struct xdr_stream xdr;
3986 struct compound_hdr hdr = {
3991 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3992 encode_compound_hdr(&xdr, &hdr);
3993 encode_putfh(&xdr, args->fh, &hdr);
3994 status = encode_setacl(&xdr, args, &hdr);
4000 * Decode SETACL response
4003 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4004 struct nfs_setaclres *res)
4006 struct xdr_stream xdr;
4007 struct compound_hdr hdr;
4010 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4011 status = decode_compound_hdr(&xdr, &hdr);
4014 status = decode_putfh(&xdr);
4017 status = decode_setattr(&xdr);
4023 * Decode GETACL response
4026 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4027 struct nfs_getaclres *res)
4029 struct xdr_stream xdr;
4030 struct compound_hdr hdr;
4033 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4034 status = decode_compound_hdr(&xdr, &hdr);
4037 status = decode_putfh(&xdr);
4040 status = decode_getacl(&xdr, rqstp, &res->acl_len);
4047 * Decode CLOSE response
4049 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4051 struct xdr_stream xdr;
4052 struct compound_hdr hdr;
4055 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4056 status = decode_compound_hdr(&xdr, &hdr);
4059 status = decode_putfh(&xdr);
4062 status = decode_close(&xdr, res);
4066 * Note: Server may do delete on close for this file
4067 * in which case the getattr call will fail with
4068 * an ESTALE error. Shouldn't be a problem,
4069 * though, since fattr->valid will remain unset.
4071 decode_getfattr(&xdr, res->fattr, res->server);
4077 * Decode OPEN response
4079 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4081 struct xdr_stream xdr;
4082 struct compound_hdr hdr;
4085 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4086 status = decode_compound_hdr(&xdr, &hdr);
4089 status = decode_putfh(&xdr);
4092 status = decode_savefh(&xdr);
4095 status = decode_open(&xdr, res);
4098 if (decode_getfh(&xdr, &res->fh) != 0)
4100 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4102 if (decode_restorefh(&xdr) != 0)
4104 decode_getfattr(&xdr, res->dir_attr, res->server);
4110 * Decode OPEN_CONFIRM response
4112 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4114 struct xdr_stream xdr;
4115 struct compound_hdr hdr;
4118 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4119 status = decode_compound_hdr(&xdr, &hdr);
4122 status = decode_putfh(&xdr);
4125 status = decode_open_confirm(&xdr, res);
4131 * Decode OPEN response
4133 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4135 struct xdr_stream xdr;
4136 struct compound_hdr hdr;
4139 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4140 status = decode_compound_hdr(&xdr, &hdr);
4143 status = decode_putfh(&xdr);
4146 status = decode_open(&xdr, res);
4149 decode_getfattr(&xdr, res->f_attr, res->server);
4155 * Decode SETATTR response
4157 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4159 struct xdr_stream xdr;
4160 struct compound_hdr hdr;
4163 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4164 status = decode_compound_hdr(&xdr, &hdr);
4167 status = decode_putfh(&xdr);
4170 status = decode_setattr(&xdr);
4173 decode_getfattr(&xdr, res->fattr, res->server);
4179 * Decode LOCK response
4181 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4183 struct xdr_stream xdr;
4184 struct compound_hdr hdr;
4187 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4188 status = decode_compound_hdr(&xdr, &hdr);
4191 status = decode_putfh(&xdr);
4194 status = decode_lock(&xdr, res);
4200 * Decode LOCKT response
4202 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4204 struct xdr_stream xdr;
4205 struct compound_hdr hdr;
4208 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4209 status = decode_compound_hdr(&xdr, &hdr);
4212 status = decode_putfh(&xdr);
4215 status = decode_lockt(&xdr, res);
4221 * Decode LOCKU response
4223 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4225 struct xdr_stream xdr;
4226 struct compound_hdr hdr;
4229 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4230 status = decode_compound_hdr(&xdr, &hdr);
4233 status = decode_putfh(&xdr);
4236 status = decode_locku(&xdr, res);
4242 * Decode READLINK response
4244 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4245 struct nfs4_readlink_res *res)
4247 struct xdr_stream xdr;
4248 struct compound_hdr hdr;
4251 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4252 status = decode_compound_hdr(&xdr, &hdr);
4255 status = decode_putfh(&xdr);
4258 status = decode_readlink(&xdr, rqstp);
4264 * Decode READDIR response
4266 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4268 struct xdr_stream xdr;
4269 struct compound_hdr hdr;
4272 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4273 status = decode_compound_hdr(&xdr, &hdr);
4276 status = decode_putfh(&xdr);
4279 status = decode_readdir(&xdr, rqstp, res);
4285 * Decode Read response
4287 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4289 struct xdr_stream xdr;
4290 struct compound_hdr hdr;
4293 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4294 status = decode_compound_hdr(&xdr, &hdr);
4297 status = decode_putfh(&xdr);
4300 status = decode_read(&xdr, rqstp, res);
4302 status = res->count;
4308 * Decode WRITE response
4310 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4312 struct xdr_stream xdr;
4313 struct compound_hdr hdr;
4316 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4317 status = decode_compound_hdr(&xdr, &hdr);
4320 status = decode_putfh(&xdr);
4323 status = decode_write(&xdr, res);
4326 decode_getfattr(&xdr, res->fattr, res->server);
4328 status = res->count;
4334 * Decode COMMIT response
4336 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4338 struct xdr_stream xdr;
4339 struct compound_hdr hdr;
4342 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4343 status = decode_compound_hdr(&xdr, &hdr);
4346 status = decode_putfh(&xdr);
4349 status = decode_commit(&xdr, res);
4352 decode_getfattr(&xdr, res->fattr, res->server);
4360 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4361 struct nfs4_fsinfo_res *res)
4363 struct xdr_stream xdr;
4364 struct compound_hdr hdr;
4367 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4368 status = decode_compound_hdr(&xdr, &hdr);
4370 status = decode_putfh(&xdr);
4372 status = decode_fsinfo(&xdr, res->fsinfo);
4379 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4380 struct nfs4_pathconf_res *res)
4382 struct xdr_stream xdr;
4383 struct compound_hdr hdr;
4386 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4387 status = decode_compound_hdr(&xdr, &hdr);
4389 status = decode_putfh(&xdr);
4391 status = decode_pathconf(&xdr, res->pathconf);
4398 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4399 struct nfs4_statfs_res *res)
4401 struct xdr_stream xdr;
4402 struct compound_hdr hdr;
4405 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4406 status = decode_compound_hdr(&xdr, &hdr);
4408 status = decode_putfh(&xdr);
4410 status = decode_statfs(&xdr, res->fsstat);
4415 * GETATTR_BITMAP request
4417 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4419 struct xdr_stream xdr;
4420 struct compound_hdr hdr;
4423 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4424 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4426 if ((status = decode_putfh(&xdr)) != 0)
4428 status = decode_server_caps(&xdr, res);
4434 * Decode RENEW response
4436 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4438 struct xdr_stream xdr;
4439 struct compound_hdr hdr;
4442 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4443 status = decode_compound_hdr(&xdr, &hdr);
4445 status = decode_renew(&xdr);
4450 * a SETCLIENTID request
4452 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4453 struct nfs_client *clp)
4455 struct xdr_stream xdr;
4456 struct compound_hdr hdr;
4459 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4460 status = decode_compound_hdr(&xdr, &hdr);
4462 status = decode_setclientid(&xdr, clp);
4467 * a SETCLIENTID_CONFIRM request
4469 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4471 struct xdr_stream xdr;
4472 struct compound_hdr hdr;
4475 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4476 status = decode_compound_hdr(&xdr, &hdr);
4478 status = decode_setclientid_confirm(&xdr);
4480 status = decode_putrootfh(&xdr);
4482 status = decode_fsinfo(&xdr, fsinfo);
4487 * DELEGRETURN request
4489 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4491 struct xdr_stream xdr;
4492 struct compound_hdr hdr;
4495 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4496 status = decode_compound_hdr(&xdr, &hdr);
4499 status = decode_putfh(&xdr);
4502 status = decode_delegreturn(&xdr);
4503 decode_getfattr(&xdr, res->fattr, res->server);
4509 * FS_LOCATIONS request
4511 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
4512 struct nfs4_fs_locations_res *res)
4514 struct xdr_stream xdr;
4515 struct compound_hdr hdr;
4518 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4519 status = decode_compound_hdr(&xdr, &hdr);
4522 if ((status = decode_putfh(&xdr)) != 0)
4524 if ((status = decode_lookup(&xdr)) != 0)
4526 xdr_enter_page(&xdr, PAGE_SIZE);
4527 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
4528 res->fs_locations->server);
4533 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4535 uint32_t bitmap[2] = {0};
4540 return ERR_PTR(-EAGAIN);
4542 return ERR_PTR(-EBADCOOKIE);
4545 entry->prev_cookie = entry->cookie;
4546 p = xdr_decode_hyper(p, &entry->cookie);
4547 entry->len = ntohl(*p++);
4548 entry->name = (const char *) p;
4549 p += XDR_QUADLEN(entry->len);
4552 * In case the server doesn't return an inode number,
4553 * we fake one here. (We don't use inode number 0,
4554 * since glibc seems to choke on it...)
4558 len = ntohl(*p++); /* bitmap length */
4560 bitmap[0] = ntohl(*p++);
4562 bitmap[1] = ntohl(*p++);
4566 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4568 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4569 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4570 /* Ignore the return value of rdattr_error for now */
4574 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4575 xdr_decode_hyper(p, &entry->ino);
4576 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4577 xdr_decode_hyper(p, &entry->ino);
4581 entry->eof = !p[0] && p[1];
4586 * We need to translate between nfs status return values and
4587 * the local errno values which may not be the same.
4594 { NFS4ERR_PERM, -EPERM },
4595 { NFS4ERR_NOENT, -ENOENT },
4596 { NFS4ERR_IO, -errno_NFSERR_IO},
4597 { NFS4ERR_NXIO, -ENXIO },
4598 { NFS4ERR_ACCESS, -EACCES },
4599 { NFS4ERR_EXIST, -EEXIST },
4600 { NFS4ERR_XDEV, -EXDEV },
4601 { NFS4ERR_NOTDIR, -ENOTDIR },
4602 { NFS4ERR_ISDIR, -EISDIR },
4603 { NFS4ERR_INVAL, -EINVAL },
4604 { NFS4ERR_FBIG, -EFBIG },
4605 { NFS4ERR_NOSPC, -ENOSPC },
4606 { NFS4ERR_ROFS, -EROFS },
4607 { NFS4ERR_MLINK, -EMLINK },
4608 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4609 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4610 { NFS4ERR_DQUOT, -EDQUOT },
4611 { NFS4ERR_STALE, -ESTALE },
4612 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4613 { NFS4ERR_BADOWNER, -EINVAL },
4614 { NFS4ERR_BADNAME, -EINVAL },
4615 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4616 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4617 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4618 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4619 { NFS4ERR_BADTYPE, -EBADTYPE },
4620 { NFS4ERR_LOCKED, -EAGAIN },
4621 { NFS4ERR_RESOURCE, -EREMOTEIO },
4622 { NFS4ERR_SYMLINK, -ELOOP },
4623 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4624 { NFS4ERR_DEADLOCK, -EDEADLK },
4625 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
4626 * to be handled by a
4633 * Convert an NFS error code to a local one.
4634 * This one is used jointly by NFSv2 and NFSv3.
4637 nfs4_stat_to_errno(int stat)
4640 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4641 if (nfs_errtbl[i].stat == stat)
4642 return nfs_errtbl[i].errno;
4644 if (stat <= 10000 || stat > 10100) {
4645 /* The server is looney tunes. */
4646 return -ESERVERFAULT;
4648 /* If we cannot translate the error, the recovery routines should
4650 * Note: remaining NFSv4 error codes have values > 10000, so should
4651 * not conflict with native Linux error codes.
4656 #define PROC(proc, argtype, restype) \
4657 [NFSPROC4_CLNT_##proc] = { \
4658 .p_proc = NFSPROC4_COMPOUND, \
4659 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4660 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4661 .p_arglen = NFS4_##argtype##_sz, \
4662 .p_replen = NFS4_##restype##_sz, \
4663 .p_statidx = NFSPROC4_CLNT_##proc, \
4667 struct rpc_procinfo nfs4_procedures[] = {
4668 PROC(READ, enc_read, dec_read),
4669 PROC(WRITE, enc_write, dec_write),
4670 PROC(COMMIT, enc_commit, dec_commit),
4671 PROC(OPEN, enc_open, dec_open),
4672 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4673 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4674 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4675 PROC(CLOSE, enc_close, dec_close),
4676 PROC(SETATTR, enc_setattr, dec_setattr),
4677 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4678 PROC(RENEW, enc_renew, dec_renew),
4679 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4680 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4681 PROC(LOCK, enc_lock, dec_lock),
4682 PROC(LOCKT, enc_lockt, dec_lockt),
4683 PROC(LOCKU, enc_locku, dec_locku),
4684 PROC(ACCESS, enc_access, dec_access),
4685 PROC(GETATTR, enc_getattr, dec_getattr),
4686 PROC(LOOKUP, enc_lookup, dec_lookup),
4687 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4688 PROC(REMOVE, enc_remove, dec_remove),
4689 PROC(RENAME, enc_rename, dec_rename),
4690 PROC(LINK, enc_link, dec_link),
4691 PROC(SYMLINK, enc_symlink, dec_symlink),
4692 PROC(CREATE, enc_create, dec_create),
4693 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4694 PROC(STATFS, enc_statfs, dec_statfs),
4695 PROC(READLINK, enc_readlink, dec_readlink),
4696 PROC(READDIR, enc_readdir, dec_readdir),
4697 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4698 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4699 PROC(GETACL, enc_getacl, dec_getacl),
4700 PROC(SETACL, enc_setacl, dec_setacl),
4701 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4704 struct rpc_version nfs_version4 = {
4706 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4707 .procs = nfs4_procedures