4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 4)
74 #define lock_owner_id_maxsz (1 + 4)
75 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
76 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78 #define op_encode_hdr_maxsz (1)
79 #define op_decode_hdr_maxsz (2)
80 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
87 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
92 #define nfs4_fattr_bitmap_maxsz 3
93 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
94 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
96 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 /* This is based on getfattr, which uses the most attributes: */
99 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
101 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
104 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
110 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
111 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
114 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116 #define decode_renew_maxsz (op_decode_hdr_maxsz)
117 #define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
119 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 encode_rename_maxsz (op_encode_hdr_maxsz + \
197 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
198 #define encode_link_maxsz (op_encode_hdr_maxsz + \
200 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
201 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
203 1 + encode_stateid_maxsz + 8)
204 #define decode_lock_denied_maxsz \
205 (8 + decode_lockowner_maxsz)
206 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
207 decode_lock_denied_maxsz)
208 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
209 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
210 decode_lock_denied_maxsz)
211 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
212 encode_stateid_maxsz + \
214 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
215 decode_stateid_maxsz)
216 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
217 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
218 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
219 1 + nfs4_name_maxsz + \
222 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
223 #define encode_create_maxsz (op_encode_hdr_maxsz + \
224 1 + 2 + nfs4_name_maxsz + \
226 #define decode_create_maxsz (op_decode_hdr_maxsz + \
227 decode_change_info_maxsz + \
228 nfs4_fattr_bitmap_maxsz)
229 #define encode_statfs_maxsz (encode_getattr_maxsz)
230 #define decode_statfs_maxsz (decode_getattr_maxsz)
231 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
232 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
233 #define encode_getacl_maxsz (encode_getattr_maxsz)
234 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
235 nfs4_fattr_bitmap_maxsz + 1)
236 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
237 encode_stateid_maxsz + 3)
238 #define decode_setacl_maxsz (decode_setattr_maxsz)
239 #define encode_fs_locations_maxsz \
240 (encode_getattr_maxsz)
241 #define decode_fs_locations_maxsz \
243 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
244 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
245 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
246 encode_putfh_maxsz + \
248 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
249 decode_putfh_maxsz + \
251 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
252 encode_putfh_maxsz + \
253 encode_readlink_maxsz)
254 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
255 decode_putfh_maxsz + \
256 decode_readlink_maxsz)
257 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
258 encode_putfh_maxsz + \
259 encode_readdir_maxsz)
260 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
261 decode_putfh_maxsz + \
262 decode_readdir_maxsz)
263 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
264 encode_putfh_maxsz + \
265 encode_write_maxsz + \
266 encode_getattr_maxsz)
267 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
268 decode_putfh_maxsz + \
269 decode_write_maxsz + \
270 decode_getattr_maxsz)
271 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
272 encode_putfh_maxsz + \
273 encode_commit_maxsz + \
274 encode_getattr_maxsz)
275 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
276 decode_putfh_maxsz + \
277 decode_commit_maxsz + \
278 decode_getattr_maxsz)
279 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
280 encode_putfh_maxsz + \
281 encode_savefh_maxsz + \
282 encode_open_maxsz + \
283 encode_getfh_maxsz + \
284 encode_getattr_maxsz + \
285 encode_restorefh_maxsz + \
286 encode_getattr_maxsz)
287 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
288 decode_putfh_maxsz + \
289 decode_savefh_maxsz + \
290 decode_open_maxsz + \
291 decode_getfh_maxsz + \
292 decode_getattr_maxsz + \
293 decode_restorefh_maxsz + \
294 decode_getattr_maxsz)
295 #define NFS4_enc_open_confirm_sz \
296 (compound_encode_hdr_maxsz + \
297 encode_putfh_maxsz + \
298 encode_open_confirm_maxsz)
299 #define NFS4_dec_open_confirm_sz \
300 (compound_decode_hdr_maxsz + \
301 decode_putfh_maxsz + \
302 decode_open_confirm_maxsz)
303 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
304 encode_putfh_maxsz + \
305 encode_open_maxsz + \
306 encode_getattr_maxsz)
307 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
308 decode_putfh_maxsz + \
309 decode_open_maxsz + \
310 decode_getattr_maxsz)
311 #define NFS4_enc_open_downgrade_sz \
312 (compound_encode_hdr_maxsz + \
313 encode_putfh_maxsz + \
314 encode_open_downgrade_maxsz + \
315 encode_getattr_maxsz)
316 #define NFS4_dec_open_downgrade_sz \
317 (compound_decode_hdr_maxsz + \
318 decode_putfh_maxsz + \
319 decode_open_downgrade_maxsz + \
320 decode_getattr_maxsz)
321 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
322 encode_putfh_maxsz + \
323 encode_close_maxsz + \
324 encode_getattr_maxsz)
325 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
326 decode_putfh_maxsz + \
327 decode_close_maxsz + \
328 decode_getattr_maxsz)
329 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
330 encode_putfh_maxsz + \
331 encode_setattr_maxsz + \
332 encode_getattr_maxsz)
333 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
334 decode_putfh_maxsz + \
335 decode_setattr_maxsz + \
336 decode_getattr_maxsz)
337 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
338 encode_putfh_maxsz + \
340 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
341 decode_putfh_maxsz + \
343 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
345 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
347 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
348 encode_setclientid_maxsz)
349 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
350 decode_setclientid_maxsz)
351 #define NFS4_enc_setclientid_confirm_sz \
352 (compound_encode_hdr_maxsz + \
353 encode_setclientid_confirm_maxsz + \
354 encode_putrootfh_maxsz + \
356 #define NFS4_dec_setclientid_confirm_sz \
357 (compound_decode_hdr_maxsz + \
358 decode_setclientid_confirm_maxsz + \
359 decode_putrootfh_maxsz + \
361 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
362 encode_putfh_maxsz + \
364 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
365 decode_putfh_maxsz + \
367 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
368 encode_putfh_maxsz + \
370 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
371 decode_putfh_maxsz + \
373 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
374 encode_putfh_maxsz + \
376 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
377 decode_putfh_maxsz + \
379 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
380 encode_putfh_maxsz + \
381 encode_access_maxsz + \
382 encode_getattr_maxsz)
383 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
384 decode_putfh_maxsz + \
385 decode_access_maxsz + \
386 decode_getattr_maxsz)
387 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
388 encode_putfh_maxsz + \
389 encode_getattr_maxsz)
390 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
391 decode_putfh_maxsz + \
392 decode_getattr_maxsz)
393 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
394 encode_putfh_maxsz + \
395 encode_lookup_maxsz + \
396 encode_getattr_maxsz + \
398 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
399 decode_putfh_maxsz + \
400 decode_lookup_maxsz + \
401 decode_getattr_maxsz + \
403 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
404 encode_putrootfh_maxsz + \
405 encode_getattr_maxsz + \
407 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
408 decode_putrootfh_maxsz + \
409 decode_getattr_maxsz + \
411 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
412 encode_putfh_maxsz + \
413 encode_remove_maxsz + \
414 encode_getattr_maxsz)
415 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
416 decode_putfh_maxsz + \
417 op_decode_hdr_maxsz + 5 + \
418 decode_getattr_maxsz)
419 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
420 encode_putfh_maxsz + \
421 encode_savefh_maxsz + \
422 encode_putfh_maxsz + \
423 encode_rename_maxsz + \
424 encode_getattr_maxsz + \
425 encode_restorefh_maxsz + \
426 encode_getattr_maxsz)
427 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
428 decode_putfh_maxsz + \
429 decode_savefh_maxsz + \
430 decode_putfh_maxsz + \
431 decode_rename_maxsz + \
432 decode_getattr_maxsz + \
433 decode_restorefh_maxsz + \
434 decode_getattr_maxsz)
435 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
436 encode_putfh_maxsz + \
437 encode_savefh_maxsz + \
438 encode_putfh_maxsz + \
439 encode_link_maxsz + \
440 decode_getattr_maxsz + \
441 encode_restorefh_maxsz + \
442 decode_getattr_maxsz)
443 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
444 decode_putfh_maxsz + \
445 decode_savefh_maxsz + \
446 decode_putfh_maxsz + \
447 decode_link_maxsz + \
448 decode_getattr_maxsz + \
449 decode_restorefh_maxsz + \
450 decode_getattr_maxsz)
451 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
452 encode_putfh_maxsz + \
453 encode_symlink_maxsz + \
454 encode_getattr_maxsz + \
456 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
457 decode_putfh_maxsz + \
458 decode_symlink_maxsz + \
459 decode_getattr_maxsz + \
461 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
462 encode_putfh_maxsz + \
463 encode_savefh_maxsz + \
464 encode_create_maxsz + \
465 encode_getfh_maxsz + \
466 encode_getattr_maxsz + \
467 encode_restorefh_maxsz + \
468 encode_getattr_maxsz)
469 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
470 decode_putfh_maxsz + \
471 decode_savefh_maxsz + \
472 decode_create_maxsz + \
473 decode_getfh_maxsz + \
474 decode_getattr_maxsz + \
475 decode_restorefh_maxsz + \
476 decode_getattr_maxsz)
477 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
478 encode_putfh_maxsz + \
479 encode_getattr_maxsz)
480 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
481 decode_putfh_maxsz + \
482 decode_getattr_maxsz)
483 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
484 encode_putfh_maxsz + \
486 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
487 decode_putfh_maxsz + \
489 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
490 encode_putfh_maxsz + \
491 encode_getattr_maxsz)
492 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
493 decode_putfh_maxsz + \
494 decode_getattr_maxsz)
495 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
496 encode_putfh_maxsz + \
497 encode_delegreturn_maxsz + \
498 encode_getattr_maxsz)
499 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
500 decode_delegreturn_maxsz + \
501 decode_getattr_maxsz)
502 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
503 encode_putfh_maxsz + \
505 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
506 decode_putfh_maxsz + \
508 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
509 encode_putfh_maxsz + \
511 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
512 decode_putfh_maxsz + \
514 #define NFS4_enc_fs_locations_sz \
515 (compound_encode_hdr_maxsz + \
516 encode_putfh_maxsz + \
517 encode_lookup_maxsz + \
518 encode_fs_locations_maxsz)
519 #define NFS4_dec_fs_locations_sz \
520 (compound_decode_hdr_maxsz + \
521 decode_putfh_maxsz + \
522 decode_lookup_maxsz + \
523 decode_fs_locations_maxsz)
527 unsigned int nfs2type;
535 { S_IFSOCK, NFSOCK },
541 struct compound_hdr {
549 * START OF "GENERIC" ENCODE ROUTINES.
550 * These may look a little ugly since they are imported from a "generic"
551 * set of XDR encode/decode routines which are intended to be shared by
552 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
554 * If the pain of reading these is too great, it should be a straightforward
555 * task to translate them into Linux-specific versions which are more
556 * consistent with the style used in NFSv2/v3...
558 #define WRITE32(n) *p++ = htonl(n)
559 #define WRITE64(n) do { \
560 *p++ = htonl((uint32_t)((n) >> 32)); \
561 *p++ = htonl((uint32_t)(n)); \
563 #define WRITEMEM(ptr,nbytes) do { \
564 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
567 #define RESERVE_SPACE(nbytes) do { \
568 p = xdr_reserve_space(xdr, nbytes); \
572 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
576 p = xdr_reserve_space(xdr, 4 + len);
578 xdr_encode_opaque(p, str, len);
581 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
585 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
586 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
587 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
588 WRITE32(hdr->taglen);
589 WRITEMEM(hdr->tag, hdr->taglen);
590 WRITE32(NFS4_MINOR_VERSION);
595 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
599 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
601 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
604 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
606 char owner_name[IDMAP_NAMESZ];
607 char owner_group[IDMAP_NAMESZ];
608 int owner_namelen = 0;
609 int owner_grouplen = 0;
618 * We reserve enough space to write the entire attribute buffer at once.
619 * In the worst-case, this would be
620 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
621 * = 36 bytes, plus any contribution from variable-length fields
622 * such as owner/group.
627 if (iap->ia_valid & ATTR_SIZE)
629 if (iap->ia_valid & ATTR_MODE)
631 if (iap->ia_valid & ATTR_UID) {
632 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
633 if (owner_namelen < 0) {
634 dprintk("nfs: couldn't resolve uid %d to string\n",
637 strcpy(owner_name, "nobody");
638 owner_namelen = sizeof("nobody") - 1;
641 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
643 if (iap->ia_valid & ATTR_GID) {
644 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
645 if (owner_grouplen < 0) {
646 dprintk("nfs: couldn't resolve gid %d to string\n",
648 strcpy(owner_group, "nobody");
649 owner_grouplen = sizeof("nobody") - 1;
652 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
654 if (iap->ia_valid & ATTR_ATIME_SET)
656 else if (iap->ia_valid & ATTR_ATIME)
658 if (iap->ia_valid & ATTR_MTIME_SET)
660 else if (iap->ia_valid & ATTR_MTIME)
665 * We write the bitmap length now, but leave the bitmap and the attribute
666 * buffer length to be backfilled at the end of this routine.
672 if (iap->ia_valid & ATTR_SIZE) {
673 bmval0 |= FATTR4_WORD0_SIZE;
674 WRITE64(iap->ia_size);
676 if (iap->ia_valid & ATTR_MODE) {
677 bmval1 |= FATTR4_WORD1_MODE;
678 WRITE32(iap->ia_mode & S_IALLUGO);
680 if (iap->ia_valid & ATTR_UID) {
681 bmval1 |= FATTR4_WORD1_OWNER;
682 WRITE32(owner_namelen);
683 WRITEMEM(owner_name, owner_namelen);
685 if (iap->ia_valid & ATTR_GID) {
686 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
687 WRITE32(owner_grouplen);
688 WRITEMEM(owner_group, owner_grouplen);
690 if (iap->ia_valid & ATTR_ATIME_SET) {
691 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
692 WRITE32(NFS4_SET_TO_CLIENT_TIME);
694 WRITE32(iap->ia_mtime.tv_sec);
695 WRITE32(iap->ia_mtime.tv_nsec);
697 else if (iap->ia_valid & ATTR_ATIME) {
698 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
699 WRITE32(NFS4_SET_TO_SERVER_TIME);
701 if (iap->ia_valid & ATTR_MTIME_SET) {
702 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
703 WRITE32(NFS4_SET_TO_CLIENT_TIME);
705 WRITE32(iap->ia_mtime.tv_sec);
706 WRITE32(iap->ia_mtime.tv_nsec);
708 else if (iap->ia_valid & ATTR_MTIME) {
709 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
710 WRITE32(NFS4_SET_TO_SERVER_TIME);
714 * Now we backfill the bitmap and the attribute buffer length.
716 if (len != ((char *)p - (char *)q) + 4) {
717 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
718 len, ((char *)p - (char *)q) + 4);
721 len = (char *)p - (char *)q - 12;
722 *q++ = htonl(bmval0);
723 *q++ = htonl(bmval1);
731 static int encode_access(struct xdr_stream *xdr, u32 access)
742 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
746 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
748 WRITE32(arg->seqid->sequence->counter);
749 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
754 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
760 WRITE64(args->offset);
761 WRITE32(args->count);
766 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
772 WRITE32(create->ftype);
774 switch (create->ftype) {
777 WRITE32(create->u.symlink.len);
778 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
781 case NF4BLK: case NF4CHR:
783 WRITE32(create->u.device.specdata1);
784 WRITE32(create->u.device.specdata2);
791 RESERVE_SPACE(4 + create->name->len);
792 WRITE32(create->name->len);
793 WRITEMEM(create->name->name, create->name->len);
795 return encode_attrs(xdr, create->attrs, create->server);
798 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
809 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
821 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
823 return encode_getattr_two(xdr,
824 bitmask[0] & nfs4_fattr_bitmap[0],
825 bitmask[1] & nfs4_fattr_bitmap[1]);
828 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
830 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
831 bitmask[1] & nfs4_fsinfo_bitmap[1]);
834 static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
836 return encode_getattr_two(xdr,
837 bitmask[0] & nfs4_fs_locations_bitmap[0],
838 bitmask[1] & nfs4_fs_locations_bitmap[1]);
841 static int encode_getfh(struct xdr_stream *xdr)
851 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
855 RESERVE_SPACE(8 + name->len);
858 WRITEMEM(name->name, name->len);
863 static inline int nfs4_lock_type(struct file_lock *fl, int block)
865 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
866 return block ? NFS4_READW_LT : NFS4_READ_LT;
867 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
870 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
872 if (fl->fl_end == OFFSET_MAX)
874 return fl->fl_end - fl->fl_start + 1;
878 * opcode,type,reclaim,offset,length,new_lock_owner = 32
879 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
881 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
887 WRITE32(nfs4_lock_type(args->fl, args->block));
888 WRITE32(args->reclaim);
889 WRITE64(args->fl->fl_start);
890 WRITE64(nfs4_lock_length(args->fl));
891 WRITE32(args->new_lock_owner);
892 if (args->new_lock_owner){
893 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
894 WRITE32(args->open_seqid->sequence->counter);
895 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
896 WRITE32(args->lock_seqid->sequence->counter);
897 WRITE64(args->lock_owner.clientid);
899 WRITEMEM("lock id:", 8);
900 WRITE64(args->lock_owner.id);
903 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
904 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
905 WRITE32(args->lock_seqid->sequence->counter);
911 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
917 WRITE32(nfs4_lock_type(args->fl, 0));
918 WRITE64(args->fl->fl_start);
919 WRITE64(nfs4_lock_length(args->fl));
920 WRITE64(args->lock_owner.clientid);
922 WRITEMEM("lock id:", 8);
923 WRITE64(args->lock_owner.id);
928 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
932 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
934 WRITE32(nfs4_lock_type(args->fl, 0));
935 WRITE32(args->seqid->sequence->counter);
936 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
937 WRITE64(args->fl->fl_start);
938 WRITE64(nfs4_lock_length(args->fl));
943 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
948 RESERVE_SPACE(8 + len);
951 WRITEMEM(name->name, len);
956 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
961 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
963 WRITE32(NFS4_SHARE_ACCESS_READ);
966 WRITE32(NFS4_SHARE_ACCESS_WRITE);
968 case FMODE_READ|FMODE_WRITE:
969 WRITE32(NFS4_SHARE_ACCESS_BOTH);
974 WRITE32(0); /* for linux, share_deny = 0 always */
977 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
981 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
986 WRITE32(arg->seqid->sequence->counter);
987 encode_share_access(xdr, arg->open_flags);
989 WRITE64(arg->clientid);
991 WRITEMEM("open id:", 8);
995 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1000 switch(arg->open_flags & O_EXCL) {
1002 WRITE32(NFS4_CREATE_UNCHECKED);
1003 encode_attrs(xdr, arg->u.attrs, arg->server);
1006 WRITE32(NFS4_CREATE_EXCLUSIVE);
1007 encode_nfs4_verifier(xdr, &arg->u.verifier);
1011 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1016 switch (arg->open_flags & O_CREAT) {
1018 WRITE32(NFS4_OPEN_NOCREATE);
1021 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1022 WRITE32(NFS4_OPEN_CREATE);
1023 encode_createmode(xdr, arg);
1027 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
1032 switch (delegation_type) {
1034 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1037 WRITE32(NFS4_OPEN_DELEGATE_READ);
1039 case FMODE_WRITE|FMODE_READ:
1040 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1047 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1052 WRITE32(NFS4_OPEN_CLAIM_NULL);
1053 encode_string(xdr, name->len, name->name);
1056 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
1061 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1062 encode_delegation_type(xdr, type);
1065 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1069 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1070 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1071 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1072 encode_string(xdr, name->len, name->name);
1075 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1077 encode_openhdr(xdr, arg);
1078 encode_opentype(xdr, arg);
1079 switch (arg->claim) {
1080 case NFS4_OPEN_CLAIM_NULL:
1081 encode_claim_null(xdr, arg->name);
1083 case NFS4_OPEN_CLAIM_PREVIOUS:
1084 encode_claim_previous(xdr, arg->u.delegation_type);
1086 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1087 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1095 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
1099 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1100 WRITE32(OP_OPEN_CONFIRM);
1101 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1102 WRITE32(arg->seqid->sequence->counter);
1107 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1111 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1112 WRITE32(OP_OPEN_DOWNGRADE);
1113 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1114 WRITE32(arg->seqid->sequence->counter);
1115 encode_share_access(xdr, arg->open_flags);
1120 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1125 RESERVE_SPACE(8 + len);
1128 WRITEMEM(fh->data, len);
1133 static int encode_putrootfh(struct xdr_stream *xdr)
1138 WRITE32(OP_PUTROOTFH);
1143 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1145 nfs4_stateid stateid;
1148 RESERVE_SPACE(NFS4_STATEID_SIZE);
1149 if (ctx->state != NULL) {
1150 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1151 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1153 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1156 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1163 encode_stateid(xdr, args->context);
1166 WRITE64(args->offset);
1167 WRITE32(args->count);
1172 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1174 uint32_t attrs[2] = {
1175 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1176 FATTR4_WORD1_MOUNTED_ON_FILEID,
1180 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1181 WRITE32(OP_READDIR);
1182 WRITE64(readdir->cookie);
1183 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1184 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1185 WRITE32(readdir->count);
1187 /* Switch to mounted_on_fileid if the server supports it */
1188 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1189 attrs[0] &= ~FATTR4_WORD0_FILEID;
1191 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1192 WRITE32(attrs[0] & readdir->bitmask[0]);
1193 WRITE32(attrs[1] & readdir->bitmask[1]);
1194 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1196 (unsigned long long)readdir->cookie,
1197 ((u32 *)readdir->verifier.data)[0],
1198 ((u32 *)readdir->verifier.data)[1],
1199 attrs[0] & readdir->bitmask[0],
1200 attrs[1] & readdir->bitmask[1]);
1205 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1210 WRITE32(OP_READLINK);
1215 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1219 RESERVE_SPACE(8 + name->len);
1222 WRITEMEM(name->name, name->len);
1227 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1231 RESERVE_SPACE(8 + oldname->len);
1233 WRITE32(oldname->len);
1234 WRITEMEM(oldname->name, oldname->len);
1236 RESERVE_SPACE(4 + newname->len);
1237 WRITE32(newname->len);
1238 WRITEMEM(newname->name, newname->len);
1243 static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
1249 WRITE64(client_stateid->cl_clientid);
1255 encode_restorefh(struct xdr_stream *xdr)
1260 WRITE32(OP_RESTOREFH);
1266 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1270 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1271 WRITE32(OP_SETATTR);
1272 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1275 WRITE32(FATTR4_WORD0_ACL);
1276 if (arg->acl_len % 4)
1279 WRITE32(arg->acl_len);
1280 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1285 encode_savefh(struct xdr_stream *xdr)
1295 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1300 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1301 WRITE32(OP_SETATTR);
1302 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1304 if ((status = encode_attrs(xdr, arg->iap, server)))
1310 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1314 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1315 WRITE32(OP_SETCLIENTID);
1316 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1318 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1320 WRITE32(setclientid->sc_prog);
1321 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1322 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1324 WRITE32(setclientid->sc_cb_ident);
1329 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
1333 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1334 WRITE32(OP_SETCLIENTID_CONFIRM);
1335 WRITE64(client_state->cl_clientid);
1336 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1341 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1348 encode_stateid(xdr, args->context);
1351 WRITE64(args->offset);
1352 WRITE32(args->stable);
1353 WRITE32(args->count);
1355 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1360 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1364 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1366 WRITE32(OP_DELEGRETURN);
1367 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1372 * END OF "GENERIC" ENCODE ROUTINES.
1376 * Encode an ACCESS request
1378 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1380 struct xdr_stream xdr;
1381 struct compound_hdr hdr = {
1386 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1387 encode_compound_hdr(&xdr, &hdr);
1388 status = encode_putfh(&xdr, args->fh);
1391 status = encode_access(&xdr, args->access);
1394 status = encode_getfattr(&xdr, args->bitmask);
1400 * Encode LOOKUP request
1402 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1404 struct xdr_stream xdr;
1405 struct compound_hdr hdr = {
1410 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1411 encode_compound_hdr(&xdr, &hdr);
1412 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1414 if ((status = encode_lookup(&xdr, args->name)) != 0)
1416 if ((status = encode_getfh(&xdr)) != 0)
1418 status = encode_getfattr(&xdr, args->bitmask);
1424 * Encode LOOKUP_ROOT request
1426 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1428 struct xdr_stream xdr;
1429 struct compound_hdr hdr = {
1434 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1435 encode_compound_hdr(&xdr, &hdr);
1436 if ((status = encode_putrootfh(&xdr)) != 0)
1438 if ((status = encode_getfh(&xdr)) == 0)
1439 status = encode_getfattr(&xdr, args->bitmask);
1445 * Encode REMOVE request
1447 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1449 struct xdr_stream xdr;
1450 struct compound_hdr hdr = {
1455 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1456 encode_compound_hdr(&xdr, &hdr);
1457 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1459 if ((status = encode_remove(&xdr, &args->name)) != 0)
1461 status = encode_getfattr(&xdr, args->bitmask);
1467 * Encode RENAME request
1469 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1471 struct xdr_stream xdr;
1472 struct compound_hdr hdr = {
1477 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1478 encode_compound_hdr(&xdr, &hdr);
1479 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1481 if ((status = encode_savefh(&xdr)) != 0)
1483 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1485 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1487 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1489 if ((status = encode_restorefh(&xdr)) != 0)
1491 status = encode_getfattr(&xdr, args->bitmask);
1497 * Encode LINK request
1499 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1501 struct xdr_stream xdr;
1502 struct compound_hdr hdr = {
1507 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1508 encode_compound_hdr(&xdr, &hdr);
1509 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1511 if ((status = encode_savefh(&xdr)) != 0)
1513 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1515 if ((status = encode_link(&xdr, args->name)) != 0)
1517 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1519 if ((status = encode_restorefh(&xdr)) != 0)
1521 status = encode_getfattr(&xdr, args->bitmask);
1527 * Encode CREATE request
1529 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1531 struct xdr_stream xdr;
1532 struct compound_hdr hdr = {
1537 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1538 encode_compound_hdr(&xdr, &hdr);
1539 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1541 if ((status = encode_savefh(&xdr)) != 0)
1543 if ((status = encode_create(&xdr, args)) != 0)
1545 if ((status = encode_getfh(&xdr)) != 0)
1547 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1549 if ((status = encode_restorefh(&xdr)) != 0)
1551 status = encode_getfattr(&xdr, args->bitmask);
1557 * Encode SYMLINK request
1559 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1561 return nfs4_xdr_enc_create(req, p, args);
1565 * Encode GETATTR request
1567 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1569 struct xdr_stream xdr;
1570 struct compound_hdr hdr = {
1575 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1576 encode_compound_hdr(&xdr, &hdr);
1577 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1578 status = encode_getfattr(&xdr, args->bitmask);
1583 * Encode a CLOSE request
1585 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1587 struct xdr_stream xdr;
1588 struct compound_hdr hdr = {
1593 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1594 encode_compound_hdr(&xdr, &hdr);
1595 status = encode_putfh(&xdr, args->fh);
1598 status = encode_close(&xdr, args);
1601 status = encode_getfattr(&xdr, args->bitmask);
1607 * Encode an OPEN request
1609 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1611 struct xdr_stream xdr;
1612 struct compound_hdr hdr = {
1617 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1618 encode_compound_hdr(&xdr, &hdr);
1619 status = encode_putfh(&xdr, args->fh);
1622 status = encode_savefh(&xdr);
1625 status = encode_open(&xdr, args);
1628 status = encode_getfh(&xdr);
1631 status = encode_getfattr(&xdr, args->bitmask);
1634 status = encode_restorefh(&xdr);
1637 status = encode_getfattr(&xdr, args->bitmask);
1643 * Encode an OPEN_CONFIRM request
1645 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1647 struct xdr_stream xdr;
1648 struct compound_hdr hdr = {
1653 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1654 encode_compound_hdr(&xdr, &hdr);
1655 status = encode_putfh(&xdr, args->fh);
1658 status = encode_open_confirm(&xdr, args);
1664 * Encode an OPEN request with no attributes.
1666 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1668 struct xdr_stream xdr;
1669 struct compound_hdr hdr = {
1674 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1675 encode_compound_hdr(&xdr, &hdr);
1676 status = encode_putfh(&xdr, args->fh);
1679 status = encode_open(&xdr, args);
1682 status = encode_getfattr(&xdr, args->bitmask);
1688 * Encode an OPEN_DOWNGRADE request
1690 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1692 struct xdr_stream xdr;
1693 struct compound_hdr hdr = {
1698 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1699 encode_compound_hdr(&xdr, &hdr);
1700 status = encode_putfh(&xdr, args->fh);
1703 status = encode_open_downgrade(&xdr, args);
1706 status = encode_getfattr(&xdr, args->bitmask);
1712 * Encode a LOCK request
1714 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1716 struct xdr_stream xdr;
1717 struct compound_hdr hdr = {
1722 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1723 encode_compound_hdr(&xdr, &hdr);
1724 status = encode_putfh(&xdr, args->fh);
1727 status = encode_lock(&xdr, args);
1733 * Encode a LOCKT request
1735 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1737 struct xdr_stream xdr;
1738 struct compound_hdr hdr = {
1743 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1744 encode_compound_hdr(&xdr, &hdr);
1745 status = encode_putfh(&xdr, args->fh);
1748 status = encode_lockt(&xdr, args);
1754 * Encode a LOCKU request
1756 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1758 struct xdr_stream xdr;
1759 struct compound_hdr hdr = {
1764 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1765 encode_compound_hdr(&xdr, &hdr);
1766 status = encode_putfh(&xdr, args->fh);
1769 status = encode_locku(&xdr, args);
1775 * Encode a READLINK request
1777 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1779 struct xdr_stream xdr;
1780 struct compound_hdr hdr = {
1783 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1784 unsigned int replen;
1787 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1788 encode_compound_hdr(&xdr, &hdr);
1789 status = encode_putfh(&xdr, args->fh);
1792 status = encode_readlink(&xdr, args, req);
1794 /* set up reply kvec
1795 * toplevel_status + taglen + rescount + OP_PUTFH + status
1796 * + OP_READLINK + status + string length = 8
1798 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readlink_sz) << 2;
1799 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1800 args->pgbase, args->pglen);
1807 * Encode a READDIR request
1809 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1811 struct xdr_stream xdr;
1812 struct compound_hdr hdr = {
1815 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1819 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1820 encode_compound_hdr(&xdr, &hdr);
1821 status = encode_putfh(&xdr, args->fh);
1824 status = encode_readdir(&xdr, args, req);
1826 /* set up reply kvec
1827 * toplevel_status + taglen + rescount + OP_PUTFH + status
1828 * + OP_READDIR + status + verifer(2) = 9
1830 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readdir_sz) << 2;
1831 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1832 args->pgbase, args->count);
1833 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1834 __FUNCTION__, replen, args->pages,
1835 args->pgbase, args->count);
1842 * Encode a READ request
1844 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1846 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1847 struct xdr_stream xdr;
1848 struct compound_hdr hdr = {
1853 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1854 encode_compound_hdr(&xdr, &hdr);
1855 status = encode_putfh(&xdr, args->fh);
1858 status = encode_read(&xdr, args);
1862 /* set up reply kvec
1863 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1864 * + OP_READ + status + eof + datalen = 9
1866 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1867 xdr_inline_pages(&req->rq_rcv_buf, replen,
1868 args->pages, args->pgbase, args->count);
1869 req->rq_rcv_buf.flags |= XDRBUF_READ;
1875 * Encode an SETATTR request
1877 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1880 struct xdr_stream xdr;
1881 struct compound_hdr hdr = {
1886 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1887 encode_compound_hdr(&xdr, &hdr);
1888 status = encode_putfh(&xdr, args->fh);
1891 status = encode_setattr(&xdr, args, args->server);
1894 status = encode_getfattr(&xdr, args->bitmask);
1900 * Encode a GETACL request
1903 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1904 struct nfs_getaclargs *args)
1906 struct xdr_stream xdr;
1907 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1908 struct compound_hdr hdr = {
1913 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1914 encode_compound_hdr(&xdr, &hdr);
1915 status = encode_putfh(&xdr, args->fh);
1918 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1919 /* set up reply buffer: */
1920 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1921 xdr_inline_pages(&req->rq_rcv_buf, replen,
1922 args->acl_pages, args->acl_pgbase, args->acl_len);
1928 * Encode a WRITE request
1930 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1932 struct xdr_stream xdr;
1933 struct compound_hdr hdr = {
1938 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1939 encode_compound_hdr(&xdr, &hdr);
1940 status = encode_putfh(&xdr, args->fh);
1943 status = encode_write(&xdr, args);
1946 req->rq_snd_buf.flags |= XDRBUF_WRITE;
1947 status = encode_getfattr(&xdr, args->bitmask);
1955 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1957 struct xdr_stream xdr;
1958 struct compound_hdr hdr = {
1963 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1964 encode_compound_hdr(&xdr, &hdr);
1965 status = encode_putfh(&xdr, args->fh);
1968 status = encode_commit(&xdr, args);
1971 status = encode_getfattr(&xdr, args->bitmask);
1979 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1981 struct xdr_stream xdr;
1982 struct compound_hdr hdr = {
1987 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1988 encode_compound_hdr(&xdr, &hdr);
1989 status = encode_putfh(&xdr, args->fh);
1991 status = encode_fsinfo(&xdr, args->bitmask);
1996 * a PATHCONF request
1998 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
2000 struct xdr_stream xdr;
2001 struct compound_hdr hdr = {
2006 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2007 encode_compound_hdr(&xdr, &hdr);
2008 status = encode_putfh(&xdr, args->fh);
2010 status = encode_getattr_one(&xdr,
2011 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
2018 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
2020 struct xdr_stream xdr;
2021 struct compound_hdr hdr = {
2026 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2027 encode_compound_hdr(&xdr, &hdr);
2028 status = encode_putfh(&xdr, args->fh);
2030 status = encode_getattr_two(&xdr,
2031 args->bitmask[0] & nfs4_statfs_bitmap[0],
2032 args->bitmask[1] & nfs4_statfs_bitmap[1]);
2037 * GETATTR_BITMAP request
2039 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
2041 struct xdr_stream xdr;
2042 struct compound_hdr hdr = {
2047 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2048 encode_compound_hdr(&xdr, &hdr);
2049 status = encode_putfh(&xdr, fhandle);
2051 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2052 FATTR4_WORD0_LINK_SUPPORT|
2053 FATTR4_WORD0_SYMLINK_SUPPORT|
2054 FATTR4_WORD0_ACLSUPPORT);
2061 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2063 struct xdr_stream xdr;
2064 struct compound_hdr hdr = {
2068 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2069 encode_compound_hdr(&xdr, &hdr);
2070 return encode_renew(&xdr, clp);
2074 * a SETCLIENTID request
2076 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
2078 struct xdr_stream xdr;
2079 struct compound_hdr hdr = {
2083 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2084 encode_compound_hdr(&xdr, &hdr);
2085 return encode_setclientid(&xdr, sc);
2089 * a SETCLIENTID_CONFIRM request
2091 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2093 struct xdr_stream xdr;
2094 struct compound_hdr hdr = {
2097 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2100 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2101 encode_compound_hdr(&xdr, &hdr);
2102 status = encode_setclientid_confirm(&xdr, clp);
2104 status = encode_putrootfh(&xdr);
2106 status = encode_fsinfo(&xdr, lease_bitmap);
2111 * DELEGRETURN request
2113 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2115 struct xdr_stream xdr;
2116 struct compound_hdr hdr = {
2121 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2122 encode_compound_hdr(&xdr, &hdr);
2123 status = encode_putfh(&xdr, args->fhandle);
2126 status = encode_delegreturn(&xdr, args->stateid);
2129 status = encode_getfattr(&xdr, args->bitmask);
2135 * Encode FS_LOCATIONS request
2137 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2139 struct xdr_stream xdr;
2140 struct compound_hdr hdr = {
2143 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
2147 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2148 encode_compound_hdr(&xdr, &hdr);
2149 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2151 if ((status = encode_lookup(&xdr, args->name)) != 0)
2153 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
2156 * toplevel_status + OP_PUTFH + status
2157 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2159 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2160 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2167 * START OF "GENERIC" DECODE ROUTINES.
2168 * These may look a little ugly since they are imported from a "generic"
2169 * set of XDR encode/decode routines which are intended to be shared by
2170 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2172 * If the pain of reading these is too great, it should be a straightforward
2173 * task to translate them into Linux-specific versions which are more
2174 * consistent with the style used in NFSv2/v3...
2176 #define READ32(x) (x) = ntohl(*p++)
2177 #define READ64(x) do { \
2178 (x) = (u64)ntohl(*p++) << 32; \
2179 (x) |= ntohl(*p++); \
2181 #define READTIME(x) do { \
2183 (x.tv_sec) = ntohl(*p++); \
2184 (x.tv_nsec) = ntohl(*p++); \
2186 #define COPYMEM(x,nbytes) do { \
2187 memcpy((x), p, nbytes); \
2188 p += XDR_QUADLEN(nbytes); \
2191 #define READ_BUF(nbytes) do { \
2192 p = xdr_inline_decode(xdr, nbytes); \
2193 if (unlikely(!p)) { \
2194 dprintk("nfs: %s: prematurely hit end of receive" \
2195 " buffer\n", __FUNCTION__); \
2196 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2197 __FUNCTION__, xdr->p, nbytes, xdr->end); \
2202 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2209 *string = (char *)p;
2213 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2218 READ32(hdr->status);
2219 READ32(hdr->taglen);
2221 READ_BUF(hdr->taglen + 4);
2222 hdr->tag = (char *)p;
2223 p += XDR_QUADLEN(hdr->taglen);
2228 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2236 if (opnum != expected) {
2237 dprintk("nfs: Server returned operation"
2238 " %d but we issued a request for %d\n",
2243 if (nfserr != NFS_OK)
2244 return -nfs4_stat_to_errno(nfserr);
2249 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2252 unsigned int strlen;
2256 return decode_opaque_inline(xdr, &strlen, &str);
2259 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2267 bitmap[0] = bitmap[1] = 0;
2268 READ_BUF((bmlen << 2));
2277 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2287 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2289 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2290 decode_attr_bitmap(xdr, bitmask);
2291 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2293 bitmask[0] = bitmask[1] = 0;
2294 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2298 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2303 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2305 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2308 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2309 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2312 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2314 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2318 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2323 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2325 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2328 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2330 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2331 (unsigned long long)*change);
2335 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2340 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2342 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2345 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2347 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2351 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2356 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2358 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2361 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2363 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2367 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2372 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2374 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2377 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2379 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2383 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2389 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2391 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2393 READ64(fsid->major);
2394 READ64(fsid->minor);
2395 bitmap[0] &= ~FATTR4_WORD0_FSID;
2397 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2398 (unsigned long long)fsid->major,
2399 (unsigned long long)fsid->minor);
2403 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2408 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2410 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2413 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2415 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2419 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2423 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2424 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2426 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2429 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2431 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2435 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2440 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2442 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2445 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2447 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2451 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2456 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2458 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2461 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2463 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2467 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2473 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2475 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2478 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2480 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2484 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2490 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2492 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2495 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2497 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2501 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2507 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2509 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2512 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2514 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2518 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2529 path->ncomponents = 0;
2530 while (path->ncomponents < n) {
2531 struct nfs4_string *component = &path->components[path->ncomponents];
2532 status = decode_opaque_inline(xdr, &component->len, &component->data);
2533 if (unlikely(status != 0))
2535 if (path->ncomponents != n)
2537 dprintk("%s", component->data);
2538 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2539 path->ncomponents++;
2541 dprintk("cannot parse %d components in path\n", n);
2549 /* a root pathname is sent as a zero component4 */
2550 path->ncomponents = 1;
2551 path->components[0].len=0;
2552 path->components[0].data=NULL;
2553 dprintk("path /\n");
2556 dprintk(" status %d", status);
2561 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2567 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2570 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2572 dprintk("%s: fsroot ", __FUNCTION__);
2573 status = decode_pathname(xdr, &res->fs_path);
2574 if (unlikely(status != 0))
2580 res->nlocations = 0;
2581 while (res->nlocations < n) {
2583 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2589 dprintk("%s: servers ", __FUNCTION__);
2590 while (loc->nservers < m) {
2591 struct nfs4_string *server = &loc->servers[loc->nservers];
2592 status = decode_opaque_inline(xdr, &server->len, &server->data);
2593 if (unlikely(status != 0))
2595 dprintk("%s ", server->data);
2596 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2600 dprintk("%s: using first %u of %u servers "
2601 "returned for location %u\n",
2603 NFS4_FS_LOCATION_MAXSERVERS,
2604 m, res->nlocations);
2605 for (i = loc->nservers; i < m; i++) {
2608 status = decode_opaque_inline(xdr, &len, &data);
2609 if (unlikely(status != 0))
2614 status = decode_pathname(xdr, &loc->rootpath);
2615 if (unlikely(status != 0))
2617 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2621 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2628 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2634 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2636 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2639 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2641 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2645 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2651 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2653 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2656 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2658 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2662 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2668 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2670 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2673 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2675 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2679 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2685 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2687 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2691 if (maxread > 0x7FFFFFFF)
2692 maxread = 0x7FFFFFFF;
2693 *res = (uint32_t)maxread;
2694 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2696 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2700 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2706 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2708 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2712 if (maxwrite > 0x7FFFFFFF)
2713 maxwrite = 0x7FFFFFFF;
2714 *res = (uint32_t)maxwrite;
2715 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2717 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2721 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2726 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2728 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2732 bitmap[1] &= ~FATTR4_WORD1_MODE;
2734 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2738 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2743 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2745 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2748 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2750 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2754 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2760 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2762 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2766 if (len < XDR_MAX_NETOBJ) {
2767 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2768 dprintk("%s: nfs_map_name_to_uid failed!\n",
2771 dprintk("%s: name too long (%u)!\n",
2773 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2775 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2779 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2785 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2787 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2791 if (len < XDR_MAX_NETOBJ) {
2792 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2793 dprintk("%s: nfs_map_group_to_gid failed!\n",
2796 dprintk("%s: name too long (%u)!\n",
2798 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2800 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2804 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2806 uint32_t major = 0, minor = 0;
2810 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2812 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2818 tmp = MKDEV(major, minor);
2819 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2821 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2823 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2827 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2833 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2835 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2838 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2840 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2844 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2850 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2852 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2855 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2857 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2861 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2867 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2869 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2872 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2874 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2878 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2883 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2885 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2888 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2890 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2891 (unsigned long long)*used);
2895 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2904 time->tv_sec = (time_t)sec;
2905 time->tv_nsec = (long)nsec;
2909 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2915 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2917 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2918 status = decode_attr_time(xdr, time);
2919 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2921 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2925 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2931 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2933 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2934 status = decode_attr_time(xdr, time);
2935 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2937 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2941 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2947 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2949 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2950 status = decode_attr_time(xdr, time);
2951 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2953 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2957 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2959 unsigned int attrwords = XDR_QUADLEN(attrlen);
2960 unsigned int nwords = xdr->p - savep;
2962 if (unlikely(attrwords != nwords)) {
2963 dprintk("%s: server returned incorrect attribute length: "
2967 (attrwords < nwords) ? '<' : '>',
2974 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2979 READ32(cinfo->atomic);
2980 READ64(cinfo->before);
2981 READ64(cinfo->after);
2985 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2991 status = decode_op_hdr(xdr, OP_ACCESS);
2997 access->supported = supp;
2998 access->access = acc;
3002 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3007 status = decode_op_hdr(xdr, OP_CLOSE);
3010 READ_BUF(NFS4_STATEID_SIZE);
3011 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3015 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3020 status = decode_op_hdr(xdr, OP_COMMIT);
3024 COPYMEM(res->verf->verifier, 8);
3028 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3034 status = decode_op_hdr(xdr, OP_CREATE);
3037 if ((status = decode_change_info(xdr, cinfo)))
3041 READ_BUF(bmlen << 2);
3045 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3052 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3054 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3056 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3058 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3060 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3062 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3064 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3066 status = verify_attr_len(xdr, savep, attrlen);
3068 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3072 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3079 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3081 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3083 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3086 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3088 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3090 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3092 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3094 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3096 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3099 status = verify_attr_len(xdr, savep, attrlen);
3101 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3105 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3112 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3114 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3116 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3119 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3121 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3124 status = verify_attr_len(xdr, savep, attrlen);
3126 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3130 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3136 int status, fmode = 0;
3139 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3141 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3144 fattr->bitmap[0] = bitmap[0];
3145 fattr->bitmap[1] = bitmap[1];
3147 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3151 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3153 fattr->type = nfs_type2fmt[type].nfs2type;
3154 fmode = nfs_type2fmt[type].mode;
3156 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3158 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3160 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
3162 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3164 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3165 struct nfs4_fs_locations,
3168 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3170 fattr->mode |= fmode;
3171 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3173 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
3175 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
3177 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3179 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3181 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3183 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3185 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3187 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3189 if (fattr->fileid == 0 && fileid != 0)
3190 fattr->fileid = fileid;
3191 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
3192 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
3194 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
3199 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3202 uint32_t attrlen, bitmap[2];
3205 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3207 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3209 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3212 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3214 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3216 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3218 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3220 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3221 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3223 fsinfo->wtpref = fsinfo->wtmax;
3225 status = verify_attr_len(xdr, savep, attrlen);
3227 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3231 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3237 /* Zero handle first to allow comparisons */
3238 memset(fh, 0, sizeof(*fh));
3240 status = decode_op_hdr(xdr, OP_GETFH);
3246 if (len > NFS4_FHSIZE)
3250 COPYMEM(fh->data, len);
3254 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3258 status = decode_op_hdr(xdr, OP_LINK);
3261 return decode_change_info(xdr, cinfo);
3265 * We create the owner, so we know a proper owner.id length is 4.
3267 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3269 uint64_t offset, length, clientid;
3271 uint32_t namelen, type;
3278 fl->fl_start = (loff_t)offset;
3279 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3280 if (length == ~(uint64_t)0)
3281 fl->fl_end = OFFSET_MAX;
3282 fl->fl_type = F_WRLCK;
3284 fl->fl_type = F_RDLCK;
3290 return -NFS4ERR_DENIED;
3293 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3298 status = decode_op_hdr(xdr, OP_LOCK);
3300 READ_BUF(NFS4_STATEID_SIZE);
3301 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3302 } else if (status == -NFS4ERR_DENIED)
3303 return decode_lock_denied(xdr, NULL);
3307 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3310 status = decode_op_hdr(xdr, OP_LOCKT);
3311 if (status == -NFS4ERR_DENIED)
3312 return decode_lock_denied(xdr, res->denied);
3316 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3321 status = decode_op_hdr(xdr, OP_LOCKU);
3323 READ_BUF(NFS4_STATEID_SIZE);
3324 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3329 static int decode_lookup(struct xdr_stream *xdr)
3331 return decode_op_hdr(xdr, OP_LOOKUP);
3334 /* This is too sick! */
3335 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3338 uint32_t limit_type, nblocks, blocksize;
3342 switch (limit_type) {
3349 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3354 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3357 uint32_t delegation_type;
3360 READ32(delegation_type);
3361 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3362 res->delegation_type = 0;
3365 READ_BUF(NFS4_STATEID_SIZE+4);
3366 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3367 READ32(res->do_recall);
3368 switch (delegation_type) {
3369 case NFS4_OPEN_DELEGATE_READ:
3370 res->delegation_type = FMODE_READ;
3372 case NFS4_OPEN_DELEGATE_WRITE:
3373 res->delegation_type = FMODE_WRITE|FMODE_READ;
3374 if (decode_space_limit(xdr, &res->maxsize) < 0)
3377 return decode_ace(xdr, NULL, res->server->nfs_client);
3380 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3383 uint32_t savewords, bmlen, i;
3386 status = decode_op_hdr(xdr, OP_OPEN);
3389 READ_BUF(NFS4_STATEID_SIZE);
3390 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3392 decode_change_info(xdr, &res->cinfo);
3395 READ32(res->rflags);
3400 READ_BUF(bmlen << 2);
3401 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3402 for (i = 0; i < savewords; ++i)
3403 READ32(res->attrset[i]);
3404 for (; i < NFS4_BITMAP_SIZE; i++)
3405 res->attrset[i] = 0;
3407 return decode_delegation(xdr, res);
3409 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
3413 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3418 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3421 READ_BUF(NFS4_STATEID_SIZE);
3422 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3426 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3431 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3434 READ_BUF(NFS4_STATEID_SIZE);
3435 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3439 static int decode_putfh(struct xdr_stream *xdr)
3441 return decode_op_hdr(xdr, OP_PUTFH);
3444 static int decode_putrootfh(struct xdr_stream *xdr)
3446 return decode_op_hdr(xdr, OP_PUTROOTFH);
3449 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3451 struct kvec *iov = req->rq_rcv_buf.head;
3453 uint32_t count, eof, recvd, hdrlen;
3456 status = decode_op_hdr(xdr, OP_READ);
3462 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3463 recvd = req->rq_rcv_buf.len - hdrlen;
3464 if (count > recvd) {
3465 dprintk("NFS: server cheating in read reply: "
3466 "count %u > recvd %u\n", count, recvd);
3470 xdr_read_pages(xdr, count);
3476 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3478 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3479 struct page *page = *rcvbuf->pages;
3480 struct kvec *iov = rcvbuf->head;
3482 u32 recvd, pglen = rcvbuf->page_len;
3483 __be32 *end, *entry, *p, *kaddr;
3487 status = decode_op_hdr(xdr, OP_READDIR);
3491 COPYMEM(readdir->verifier.data, 8);
3492 dprintk("%s: verifier = 0x%x%x\n",
3494 ((u32 *)readdir->verifier.data)[0],
3495 ((u32 *)readdir->verifier.data)[1]);
3498 hdrlen = (char *) p - (char *) iov->iov_base;
3499 recvd = rcvbuf->len - hdrlen;
3502 xdr_read_pages(xdr, pglen);
3504 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3505 kaddr = p = kmap_atomic(page, KM_USER0);
3506 end = p + ((pglen + readdir->pgbase) >> 2);
3508 for (nr = 0; *p++; nr++) {
3509 u32 len, attrlen, xlen;
3512 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3513 p += 2; /* cookie */
3514 len = ntohl(*p++); /* filename length */
3515 if (len > NFS4_MAXNAMLEN) {
3516 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3520 xlen = XDR_QUADLEN(len);
3521 if (end - p < xlen + 1)
3523 dprintk("filename = %*s\n", len, (char *)p);
3525 len = ntohl(*p++); /* bitmap length */
3526 if (end - p < len + 1)
3529 attrlen = XDR_QUADLEN(ntohl(*p++));
3530 if (end - p < attrlen + 2)
3532 p += attrlen; /* attributes */
3535 if (!nr && (entry[0] != 0 || entry[1] == 0))
3538 kunmap_atomic(kaddr, KM_USER0);
3541 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3542 entry[0] = entry[1] = 0;
3543 /* truncate listing ? */
3545 dprintk("NFS: readdir reply truncated!\n");
3550 kunmap_atomic(kaddr, KM_USER0);
3551 return -errno_NFSERR_IO;
3554 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3556 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3557 struct kvec *iov = rcvbuf->head;
3564 status = decode_op_hdr(xdr, OP_READLINK);
3568 /* Convert length of symlink */
3571 if (len >= rcvbuf->page_len || len <= 0) {
3572 dprintk("nfs: server returned giant symlink!\n");
3573 return -ENAMETOOLONG;
3575 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3576 recvd = req->rq_rcv_buf.len - hdrlen;
3578 dprintk("NFS: server cheating in readlink reply: "
3579 "count %u > recvd %u\n", len, recvd);
3582 xdr_read_pages(xdr, len);
3584 * The XDR encode routine has set things up so that
3585 * the link text will be copied directly into the
3586 * buffer. We just have to do overflow-checking,
3587 * and and null-terminate the text (the VFS expects
3588 * null-termination).
3590 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3591 kaddr[len+rcvbuf->page_base] = '\0';
3592 kunmap_atomic(kaddr, KM_USER0);
3596 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3600 status = decode_op_hdr(xdr, OP_REMOVE);
3603 status = decode_change_info(xdr, cinfo);
3608 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3609 struct nfs4_change_info *new_cinfo)
3613 status = decode_op_hdr(xdr, OP_RENAME);
3616 if ((status = decode_change_info(xdr, old_cinfo)))
3618 status = decode_change_info(xdr, new_cinfo);
3623 static int decode_renew(struct xdr_stream *xdr)
3625 return decode_op_hdr(xdr, OP_RENEW);
3629 decode_restorefh(struct xdr_stream *xdr)
3631 return decode_op_hdr(xdr, OP_RESTOREFH);
3634 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3640 struct kvec *iov = req->rq_rcv_buf.head;
3644 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3646 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3648 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3651 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3653 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3657 /* We ignore &savep and don't do consistency checks on
3658 * the attr length. Let userspace figure it out.... */
3659 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3660 recvd = req->rq_rcv_buf.len - hdrlen;
3661 if (attrlen > recvd) {
3662 dprintk("NFS: server cheating in getattr"
3663 " acl reply: attrlen %u > recvd %u\n",
3667 xdr_read_pages(xdr, attrlen);
3670 status = -EOPNOTSUPP;
3677 decode_savefh(struct xdr_stream *xdr)
3679 return decode_op_hdr(xdr, OP_SAVEFH);
3682 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3689 status = decode_op_hdr(xdr, OP_SETATTR);
3694 READ_BUF(bmlen << 2);
3698 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3706 if (opnum != OP_SETCLIENTID) {
3707 dprintk("nfs: decode_setclientid: Server returned operation"
3712 if (nfserr == NFS_OK) {
3713 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3714 READ64(clp->cl_clientid);
3715 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3716 } else if (nfserr == NFSERR_CLID_INUSE) {
3719 /* skip netid string */
3724 /* skip uaddr string */
3728 return -NFSERR_CLID_INUSE;
3730 return -nfs4_stat_to_errno(nfserr);
3735 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3737 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3740 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3745 status = decode_op_hdr(xdr, OP_WRITE);
3751 READ32(res->verf->committed);
3752 COPYMEM(res->verf->verifier, 8);
3756 static int decode_delegreturn(struct xdr_stream *xdr)
3758 return decode_op_hdr(xdr, OP_DELEGRETURN);
3762 * Decode OPEN_DOWNGRADE response
3764 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3766 struct xdr_stream xdr;
3767 struct compound_hdr hdr;
3770 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3771 status = decode_compound_hdr(&xdr, &hdr);
3774 status = decode_putfh(&xdr);
3777 status = decode_open_downgrade(&xdr, res);
3780 decode_getfattr(&xdr, res->fattr, res->server);
3786 * END OF "GENERIC" DECODE ROUTINES.
3790 * Decode ACCESS response
3792 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3794 struct xdr_stream xdr;
3795 struct compound_hdr hdr;
3798 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3799 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3801 status = decode_putfh(&xdr);
3804 status = decode_access(&xdr, res);
3807 decode_getfattr(&xdr, res->fattr, res->server);
3813 * Decode LOOKUP response
3815 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3817 struct xdr_stream xdr;
3818 struct compound_hdr hdr;
3821 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3822 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3824 if ((status = decode_putfh(&xdr)) != 0)
3826 if ((status = decode_lookup(&xdr)) != 0)
3828 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3830 status = decode_getfattr(&xdr, res->fattr, res->server);
3836 * Decode LOOKUP_ROOT response
3838 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3840 struct xdr_stream xdr;
3841 struct compound_hdr hdr;
3844 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3845 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3847 if ((status = decode_putrootfh(&xdr)) != 0)
3849 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3850 status = decode_getfattr(&xdr, res->fattr, res->server);
3856 * Decode REMOVE response
3858 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
3860 struct xdr_stream xdr;
3861 struct compound_hdr hdr;
3864 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3865 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3867 if ((status = decode_putfh(&xdr)) != 0)
3869 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3871 decode_getfattr(&xdr, &res->dir_attr, res->server);
3877 * Decode RENAME response
3879 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3881 struct xdr_stream xdr;
3882 struct compound_hdr hdr;
3885 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3886 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3888 if ((status = decode_putfh(&xdr)) != 0)
3890 if ((status = decode_savefh(&xdr)) != 0)
3892 if ((status = decode_putfh(&xdr)) != 0)
3894 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3896 /* Current FH is target directory */
3897 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3899 if ((status = decode_restorefh(&xdr)) != 0)
3901 decode_getfattr(&xdr, res->old_fattr, res->server);
3907 * Decode LINK response
3909 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3911 struct xdr_stream xdr;
3912 struct compound_hdr hdr;
3915 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3916 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3918 if ((status = decode_putfh(&xdr)) != 0)
3920 if ((status = decode_savefh(&xdr)) != 0)
3922 if ((status = decode_putfh(&xdr)) != 0)
3924 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3927 * Note order: OP_LINK leaves the directory as the current
3930 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3932 if ((status = decode_restorefh(&xdr)) != 0)
3934 decode_getfattr(&xdr, res->fattr, res->server);
3940 * Decode CREATE response
3942 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3944 struct xdr_stream xdr;
3945 struct compound_hdr hdr;
3948 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3949 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3951 if ((status = decode_putfh(&xdr)) != 0)
3953 if ((status = decode_savefh(&xdr)) != 0)
3955 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3957 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3959 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3961 if ((status = decode_restorefh(&xdr)) != 0)
3963 decode_getfattr(&xdr, res->dir_fattr, res->server);
3969 * Decode SYMLINK response
3971 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3973 return nfs4_xdr_dec_create(rqstp, p, res);
3977 * Decode GETATTR response
3979 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3981 struct xdr_stream xdr;
3982 struct compound_hdr hdr;
3985 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3986 status = decode_compound_hdr(&xdr, &hdr);
3989 status = decode_putfh(&xdr);
3992 status = decode_getfattr(&xdr, res->fattr, res->server);
3999 * Encode an SETACL request
4002 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
4004 struct xdr_stream xdr;
4005 struct compound_hdr hdr = {
4010 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
4011 encode_compound_hdr(&xdr, &hdr);
4012 status = encode_putfh(&xdr, args->fh);
4015 status = encode_setacl(&xdr, args);
4020 * Decode SETACL response
4023 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
4025 struct xdr_stream xdr;
4026 struct compound_hdr hdr;
4029 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4030 status = decode_compound_hdr(&xdr, &hdr);
4033 status = decode_putfh(&xdr);
4036 status = decode_setattr(&xdr, res);
4042 * Decode GETACL response
4045 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
4047 struct xdr_stream xdr;
4048 struct compound_hdr hdr;
4051 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4052 status = decode_compound_hdr(&xdr, &hdr);
4055 status = decode_putfh(&xdr);
4058 status = decode_getacl(&xdr, rqstp, acl_len);
4065 * Decode CLOSE response
4067 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4069 struct xdr_stream xdr;
4070 struct compound_hdr hdr;
4073 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4074 status = decode_compound_hdr(&xdr, &hdr);
4077 status = decode_putfh(&xdr);
4080 status = decode_close(&xdr, res);
4084 * Note: Server may do delete on close for this file
4085 * in which case the getattr call will fail with
4086 * an ESTALE error. Shouldn't be a problem,
4087 * though, since fattr->valid will remain unset.
4089 decode_getfattr(&xdr, res->fattr, res->server);
4095 * Decode OPEN response
4097 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4099 struct xdr_stream xdr;
4100 struct compound_hdr hdr;
4103 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4104 status = decode_compound_hdr(&xdr, &hdr);
4107 status = decode_putfh(&xdr);
4110 status = decode_savefh(&xdr);
4113 status = decode_open(&xdr, res);
4116 if (decode_getfh(&xdr, &res->fh) != 0)
4118 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4120 if (decode_restorefh(&xdr) != 0)
4122 decode_getfattr(&xdr, res->dir_attr, res->server);
4128 * Decode OPEN_CONFIRM response
4130 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4132 struct xdr_stream xdr;
4133 struct compound_hdr hdr;
4136 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4137 status = decode_compound_hdr(&xdr, &hdr);
4140 status = decode_putfh(&xdr);
4143 status = decode_open_confirm(&xdr, res);
4149 * Decode OPEN response
4151 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4153 struct xdr_stream xdr;
4154 struct compound_hdr hdr;
4157 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4158 status = decode_compound_hdr(&xdr, &hdr);
4161 status = decode_putfh(&xdr);
4164 status = decode_open(&xdr, res);
4167 decode_getfattr(&xdr, res->f_attr, res->server);
4173 * Decode SETATTR response
4175 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4177 struct xdr_stream xdr;
4178 struct compound_hdr hdr;
4181 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4182 status = decode_compound_hdr(&xdr, &hdr);
4185 status = decode_putfh(&xdr);
4188 status = decode_setattr(&xdr, res);
4191 status = decode_getfattr(&xdr, res->fattr, res->server);
4192 if (status == NFS4ERR_DELAY)
4199 * Decode LOCK response
4201 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4203 struct xdr_stream xdr;
4204 struct compound_hdr hdr;
4207 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4208 status = decode_compound_hdr(&xdr, &hdr);
4211 status = decode_putfh(&xdr);
4214 status = decode_lock(&xdr, res);
4220 * Decode LOCKT response
4222 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4224 struct xdr_stream xdr;
4225 struct compound_hdr hdr;
4228 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4229 status = decode_compound_hdr(&xdr, &hdr);
4232 status = decode_putfh(&xdr);
4235 status = decode_lockt(&xdr, res);
4241 * Decode LOCKU response
4243 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4245 struct xdr_stream xdr;
4246 struct compound_hdr hdr;
4249 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4250 status = decode_compound_hdr(&xdr, &hdr);
4253 status = decode_putfh(&xdr);
4256 status = decode_locku(&xdr, res);
4262 * Decode READLINK response
4264 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
4266 struct xdr_stream xdr;
4267 struct compound_hdr hdr;
4270 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4271 status = decode_compound_hdr(&xdr, &hdr);
4274 status = decode_putfh(&xdr);
4277 status = decode_readlink(&xdr, rqstp);
4283 * Decode READDIR response
4285 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4287 struct xdr_stream xdr;
4288 struct compound_hdr hdr;
4291 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4292 status = decode_compound_hdr(&xdr, &hdr);
4295 status = decode_putfh(&xdr);
4298 status = decode_readdir(&xdr, rqstp, res);
4304 * Decode Read response
4306 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4308 struct xdr_stream xdr;
4309 struct compound_hdr hdr;
4312 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4313 status = decode_compound_hdr(&xdr, &hdr);
4316 status = decode_putfh(&xdr);
4319 status = decode_read(&xdr, rqstp, res);
4321 status = res->count;
4327 * Decode WRITE response
4329 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4331 struct xdr_stream xdr;
4332 struct compound_hdr hdr;
4335 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4336 status = decode_compound_hdr(&xdr, &hdr);
4339 status = decode_putfh(&xdr);
4342 status = decode_write(&xdr, res);
4345 decode_getfattr(&xdr, res->fattr, res->server);
4347 status = res->count;
4353 * Decode COMMIT response
4355 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4357 struct xdr_stream xdr;
4358 struct compound_hdr hdr;
4361 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4362 status = decode_compound_hdr(&xdr, &hdr);
4365 status = decode_putfh(&xdr);
4368 status = decode_commit(&xdr, res);
4371 decode_getfattr(&xdr, res->fattr, res->server);
4379 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4381 struct xdr_stream xdr;
4382 struct compound_hdr hdr;
4385 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4386 status = decode_compound_hdr(&xdr, &hdr);
4388 status = decode_putfh(&xdr);
4390 status = decode_fsinfo(&xdr, fsinfo);
4392 status = -nfs4_stat_to_errno(hdr.status);
4399 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
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_pathconf(&xdr, pathconf);
4417 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
4419 struct xdr_stream xdr;
4420 struct compound_hdr hdr;
4423 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4424 status = decode_compound_hdr(&xdr, &hdr);
4426 status = decode_putfh(&xdr);
4428 status = decode_statfs(&xdr, fsstat);
4433 * GETATTR_BITMAP request
4435 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4437 struct xdr_stream xdr;
4438 struct compound_hdr hdr;
4441 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4442 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4444 if ((status = decode_putfh(&xdr)) != 0)
4446 status = decode_server_caps(&xdr, res);
4452 * Decode RENEW response
4454 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4456 struct xdr_stream xdr;
4457 struct compound_hdr hdr;
4460 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4461 status = decode_compound_hdr(&xdr, &hdr);
4463 status = decode_renew(&xdr);
4468 * a SETCLIENTID request
4470 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4471 struct nfs_client *clp)
4473 struct xdr_stream xdr;
4474 struct compound_hdr hdr;
4477 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4478 status = decode_compound_hdr(&xdr, &hdr);
4480 status = decode_setclientid(&xdr, clp);
4482 status = -nfs4_stat_to_errno(hdr.status);
4487 * a SETCLIENTID_CONFIRM request
4489 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4491 struct xdr_stream xdr;
4492 struct compound_hdr hdr;
4495 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4496 status = decode_compound_hdr(&xdr, &hdr);
4498 status = decode_setclientid_confirm(&xdr);
4500 status = decode_putrootfh(&xdr);
4502 status = decode_fsinfo(&xdr, fsinfo);
4504 status = -nfs4_stat_to_errno(hdr.status);
4509 * DELEGRETURN request
4511 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4513 struct xdr_stream xdr;
4514 struct compound_hdr hdr;
4517 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4518 status = decode_compound_hdr(&xdr, &hdr);
4521 status = decode_putfh(&xdr);
4524 status = decode_delegreturn(&xdr);
4525 decode_getfattr(&xdr, res->fattr, res->server);
4531 * FS_LOCATIONS request
4533 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
4535 struct xdr_stream xdr;
4536 struct compound_hdr hdr;
4539 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4540 status = decode_compound_hdr(&xdr, &hdr);
4543 if ((status = decode_putfh(&xdr)) != 0)
4545 if ((status = decode_lookup(&xdr)) != 0)
4547 xdr_enter_page(&xdr, PAGE_SIZE);
4548 status = decode_getfattr(&xdr, &res->fattr, res->server);
4553 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4555 uint32_t bitmap[2] = {0};
4560 return ERR_PTR(-EAGAIN);
4562 return ERR_PTR(-EBADCOOKIE);
4565 entry->prev_cookie = entry->cookie;
4566 p = xdr_decode_hyper(p, &entry->cookie);
4567 entry->len = ntohl(*p++);
4568 entry->name = (const char *) p;
4569 p += XDR_QUADLEN(entry->len);
4572 * In case the server doesn't return an inode number,
4573 * we fake one here. (We don't use inode number 0,
4574 * since glibc seems to choke on it...)
4578 len = ntohl(*p++); /* bitmap length */
4580 bitmap[0] = ntohl(*p++);
4582 bitmap[1] = ntohl(*p++);
4586 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4588 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4589 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4590 /* Ignore the return value of rdattr_error for now */
4594 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4595 xdr_decode_hyper(p, &entry->ino);
4596 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4597 xdr_decode_hyper(p, &entry->ino);
4601 entry->eof = !p[0] && p[1];
4606 * We need to translate between nfs status return values and
4607 * the local errno values which may not be the same.
4614 { NFS4ERR_PERM, EPERM },
4615 { NFS4ERR_NOENT, ENOENT },
4616 { NFS4ERR_IO, errno_NFSERR_IO },
4617 { NFS4ERR_NXIO, ENXIO },
4618 { NFS4ERR_ACCESS, EACCES },
4619 { NFS4ERR_EXIST, EEXIST },
4620 { NFS4ERR_XDEV, EXDEV },
4621 { NFS4ERR_NOTDIR, ENOTDIR },
4622 { NFS4ERR_ISDIR, EISDIR },
4623 { NFS4ERR_INVAL, EINVAL },
4624 { NFS4ERR_FBIG, EFBIG },
4625 { NFS4ERR_NOSPC, ENOSPC },
4626 { NFS4ERR_ROFS, EROFS },
4627 { NFS4ERR_MLINK, EMLINK },
4628 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4629 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4630 { NFS4ERR_DQUOT, EDQUOT },
4631 { NFS4ERR_STALE, ESTALE },
4632 { NFS4ERR_BADHANDLE, EBADHANDLE },
4633 { NFS4ERR_BADOWNER, EINVAL },
4634 { NFS4ERR_BADNAME, EINVAL },
4635 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4636 { NFS4ERR_NOTSUPP, ENOTSUPP },
4637 { NFS4ERR_TOOSMALL, ETOOSMALL },
4638 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4639 { NFS4ERR_BADTYPE, EBADTYPE },
4640 { NFS4ERR_LOCKED, EAGAIN },
4641 { NFS4ERR_RESOURCE, EREMOTEIO },
4642 { NFS4ERR_SYMLINK, ELOOP },
4643 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4644 { NFS4ERR_DEADLOCK, EDEADLK },
4645 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4646 * to be handled by a
4653 * Convert an NFS error code to a local one.
4654 * This one is used jointly by NFSv2 and NFSv3.
4657 nfs4_stat_to_errno(int stat)
4660 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4661 if (nfs_errtbl[i].stat == stat)
4662 return nfs_errtbl[i].errno;
4664 if (stat <= 10000 || stat > 10100) {
4665 /* The server is looney tunes. */
4666 return ESERVERFAULT;
4668 /* If we cannot translate the error, the recovery routines should
4670 * Note: remaining NFSv4 error codes have values > 10000, so should
4671 * not conflict with native Linux error codes.
4676 #define PROC(proc, argtype, restype) \
4677 [NFSPROC4_CLNT_##proc] = { \
4678 .p_proc = NFSPROC4_COMPOUND, \
4679 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4680 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4681 .p_arglen = NFS4_##argtype##_sz, \
4682 .p_replen = NFS4_##restype##_sz, \
4683 .p_statidx = NFSPROC4_CLNT_##proc, \
4687 struct rpc_procinfo nfs4_procedures[] = {
4688 PROC(READ, enc_read, dec_read),
4689 PROC(WRITE, enc_write, dec_write),
4690 PROC(COMMIT, enc_commit, dec_commit),
4691 PROC(OPEN, enc_open, dec_open),
4692 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4693 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4694 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4695 PROC(CLOSE, enc_close, dec_close),
4696 PROC(SETATTR, enc_setattr, dec_setattr),
4697 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4698 PROC(RENEW, enc_renew, dec_renew),
4699 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4700 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4701 PROC(LOCK, enc_lock, dec_lock),
4702 PROC(LOCKT, enc_lockt, dec_lockt),
4703 PROC(LOCKU, enc_locku, dec_locku),
4704 PROC(ACCESS, enc_access, dec_access),
4705 PROC(GETATTR, enc_getattr, dec_getattr),
4706 PROC(LOOKUP, enc_lookup, dec_lookup),
4707 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4708 PROC(REMOVE, enc_remove, dec_remove),
4709 PROC(RENAME, enc_rename, dec_rename),
4710 PROC(LINK, enc_link, dec_link),
4711 PROC(SYMLINK, enc_symlink, dec_symlink),
4712 PROC(CREATE, enc_create, dec_create),
4713 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4714 PROC(STATFS, enc_statfs, dec_statfs),
4715 PROC(READLINK, enc_readlink, dec_readlink),
4716 PROC(READDIR, enc_readdir, dec_readdir),
4717 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4718 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4719 PROC(GETACL, enc_getacl, dec_getacl),
4720 PROC(SETACL, enc_setacl, dec_setacl),
4721 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4724 struct rpc_version nfs_version4 = {
4726 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4727 .procs = nfs4_procedures