4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 4)
74 #define lock_owner_id_maxsz (1 + 4)
75 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
76 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78 #define op_encode_hdr_maxsz (1)
79 #define op_decode_hdr_maxsz (2)
80 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
87 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
92 #define nfs4_fattr_bitmap_maxsz 3
93 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
94 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
96 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 /* This is based on getfattr, which uses the most attributes: */
99 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
101 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
104 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
110 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
111 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
114 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116 #define decode_renew_maxsz (op_decode_hdr_maxsz)
117 #define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
119 4 /*server->ip_addr*/ + \
122 6 + (NFS4_VERIFIER_SIZE >> 2))
123 #define decode_setclientid_maxsz \
124 (op_decode_hdr_maxsz + \
126 1024) /* large value for CLID_INUSE */
127 #define encode_setclientid_confirm_maxsz \
128 (op_encode_hdr_maxsz + \
129 3 + (NFS4_VERIFIER_SIZE >> 2))
130 #define decode_setclientid_confirm_maxsz \
131 (op_decode_hdr_maxsz)
132 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
133 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
134 #define encode_share_access_maxsz \
136 #define encode_createmode_maxsz (1 + encode_attrs_maxsz)
137 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
138 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
139 #define encode_open_maxsz (op_encode_hdr_maxsz + \
140 2 + encode_share_access_maxsz + 2 + \
141 open_owner_id_maxsz + \
142 encode_opentype_maxsz + \
143 encode_claim_null_maxsz)
144 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
145 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
147 #define decode_change_info_maxsz (5)
148 #define decode_open_maxsz (op_decode_hdr_maxsz + \
149 decode_stateid_maxsz + \
150 decode_change_info_maxsz + 1 + \
151 nfs4_fattr_bitmap_maxsz + \
152 decode_delegation_maxsz)
153 #define encode_open_confirm_maxsz \
154 (op_encode_hdr_maxsz + \
155 encode_stateid_maxsz + 1)
156 #define decode_open_confirm_maxsz \
157 (op_decode_hdr_maxsz + \
158 decode_stateid_maxsz)
159 #define encode_open_downgrade_maxsz \
160 (op_encode_hdr_maxsz + \
161 encode_stateid_maxsz + 1 + \
162 encode_share_access_maxsz)
163 #define decode_open_downgrade_maxsz \
164 (op_decode_hdr_maxsz + \
165 decode_stateid_maxsz)
166 #define encode_close_maxsz (op_encode_hdr_maxsz + \
167 1 + encode_stateid_maxsz)
168 #define decode_close_maxsz (op_decode_hdr_maxsz + \
169 decode_stateid_maxsz)
170 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + \
173 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
174 nfs4_fattr_bitmap_maxsz)
175 #define encode_read_maxsz (op_encode_hdr_maxsz + \
176 encode_stateid_maxsz + 3)
177 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
178 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
179 2 + encode_verifier_maxsz + 5)
180 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
181 decode_verifier_maxsz)
182 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
183 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
184 #define encode_write_maxsz (op_encode_hdr_maxsz + \
185 encode_stateid_maxsz + 4)
186 #define decode_write_maxsz (op_decode_hdr_maxsz + \
187 2 + decode_verifier_maxsz)
188 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
189 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
190 decode_verifier_maxsz)
191 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
193 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
195 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
196 #define encode_link_maxsz (op_encode_hdr_maxsz + \
198 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
199 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
201 1 + encode_stateid_maxsz + 8)
202 #define decode_lock_denied_maxsz \
203 (8 + decode_lockowner_maxsz)
204 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
205 decode_lock_denied_maxsz)
206 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
207 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
208 decode_lock_denied_maxsz)
209 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
210 encode_stateid_maxsz + \
212 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
213 decode_stateid_maxsz)
214 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
215 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
216 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
217 1 + nfs4_name_maxsz + \
220 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
221 #define encode_create_maxsz (op_encode_hdr_maxsz + \
222 1 + 2 + nfs4_name_maxsz + \
224 #define decode_create_maxsz (op_decode_hdr_maxsz + \
225 decode_change_info_maxsz + \
226 nfs4_fattr_bitmap_maxsz)
227 #define encode_statfs_maxsz (encode_getattr_maxsz)
228 #define decode_statfs_maxsz (decode_getattr_maxsz)
229 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
230 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
231 #define encode_getacl_maxsz (encode_getattr_maxsz)
232 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
233 nfs4_fattr_bitmap_maxsz + 1)
234 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
235 encode_stateid_maxsz + 3)
236 #define decode_setacl_maxsz (decode_setattr_maxsz)
237 #define encode_fs_locations_maxsz \
238 (encode_getattr_maxsz)
239 #define decode_fs_locations_maxsz \
241 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
242 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
243 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
244 encode_putfh_maxsz + \
246 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
247 decode_putfh_maxsz + \
249 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
250 encode_putfh_maxsz + \
251 encode_readlink_maxsz)
252 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
253 decode_putfh_maxsz + \
254 decode_readlink_maxsz)
255 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
256 encode_putfh_maxsz + \
257 encode_readdir_maxsz)
258 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
259 decode_putfh_maxsz + \
260 decode_readdir_maxsz)
261 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
262 encode_putfh_maxsz + \
263 encode_write_maxsz + \
264 encode_getattr_maxsz)
265 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
266 decode_putfh_maxsz + \
267 decode_write_maxsz + \
268 decode_getattr_maxsz)
269 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
270 encode_putfh_maxsz + \
271 encode_commit_maxsz + \
272 encode_getattr_maxsz)
273 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
274 decode_putfh_maxsz + \
275 decode_commit_maxsz + \
276 decode_getattr_maxsz)
277 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
278 encode_putfh_maxsz + \
279 encode_savefh_maxsz + \
280 encode_open_maxsz + \
281 encode_getfh_maxsz + \
282 encode_getattr_maxsz + \
283 encode_restorefh_maxsz + \
284 encode_getattr_maxsz)
285 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
286 decode_putfh_maxsz + \
287 decode_savefh_maxsz + \
288 decode_open_maxsz + \
289 decode_getfh_maxsz + \
290 decode_getattr_maxsz + \
291 decode_restorefh_maxsz + \
292 decode_getattr_maxsz)
293 #define NFS4_enc_open_confirm_sz \
294 (compound_encode_hdr_maxsz + \
295 encode_putfh_maxsz + \
296 encode_open_confirm_maxsz)
297 #define NFS4_dec_open_confirm_sz \
298 (compound_decode_hdr_maxsz + \
299 decode_putfh_maxsz + \
300 decode_open_confirm_maxsz)
301 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
302 encode_putfh_maxsz + \
303 encode_open_maxsz + \
304 encode_getattr_maxsz)
305 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
306 decode_putfh_maxsz + \
307 decode_open_maxsz + \
308 decode_getattr_maxsz)
309 #define NFS4_enc_open_downgrade_sz \
310 (compound_encode_hdr_maxsz + \
311 encode_putfh_maxsz + \
312 encode_open_downgrade_maxsz + \
313 encode_getattr_maxsz)
314 #define NFS4_dec_open_downgrade_sz \
315 (compound_decode_hdr_maxsz + \
316 decode_putfh_maxsz + \
317 decode_open_downgrade_maxsz + \
318 decode_getattr_maxsz)
319 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
320 encode_putfh_maxsz + \
321 encode_close_maxsz + \
322 encode_getattr_maxsz)
323 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
324 decode_putfh_maxsz + \
325 decode_close_maxsz + \
326 decode_getattr_maxsz)
327 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
328 encode_putfh_maxsz + \
329 encode_setattr_maxsz + \
330 encode_getattr_maxsz)
331 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
332 decode_putfh_maxsz + \
333 decode_setattr_maxsz + \
334 decode_getattr_maxsz)
335 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
336 encode_putfh_maxsz + \
338 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
339 decode_putfh_maxsz + \
341 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
343 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
345 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
346 encode_setclientid_maxsz)
347 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
348 decode_setclientid_maxsz)
349 #define NFS4_enc_setclientid_confirm_sz \
350 (compound_encode_hdr_maxsz + \
351 encode_setclientid_confirm_maxsz + \
352 encode_putrootfh_maxsz + \
354 #define NFS4_dec_setclientid_confirm_sz \
355 (compound_decode_hdr_maxsz + \
356 decode_setclientid_confirm_maxsz + \
357 decode_putrootfh_maxsz + \
359 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
360 encode_putfh_maxsz + \
362 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
363 decode_putfh_maxsz + \
365 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
366 encode_putfh_maxsz + \
368 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
369 decode_putfh_maxsz + \
371 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
372 encode_putfh_maxsz + \
374 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
375 decode_putfh_maxsz + \
377 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
380 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
381 decode_putfh_maxsz + \
383 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_getattr_maxsz)
386 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
387 decode_putfh_maxsz + \
388 decode_getattr_maxsz)
389 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
390 encode_putfh_maxsz + \
391 encode_lookup_maxsz + \
392 encode_getattr_maxsz + \
394 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
395 decode_putfh_maxsz + \
396 decode_lookup_maxsz + \
397 decode_getattr_maxsz + \
399 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
400 encode_putrootfh_maxsz + \
401 encode_getattr_maxsz + \
403 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
404 decode_putrootfh_maxsz + \
405 decode_getattr_maxsz + \
407 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
408 encode_putfh_maxsz + \
409 encode_remove_maxsz + \
410 encode_getattr_maxsz)
411 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
412 decode_putfh_maxsz + \
413 op_decode_hdr_maxsz + 5 + \
414 decode_getattr_maxsz)
415 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
416 encode_putfh_maxsz + \
417 encode_savefh_maxsz + \
418 encode_putfh_maxsz + \
419 encode_rename_maxsz + \
420 encode_getattr_maxsz + \
421 encode_restorefh_maxsz + \
422 encode_getattr_maxsz)
423 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
424 decode_putfh_maxsz + \
425 decode_savefh_maxsz + \
426 decode_putfh_maxsz + \
427 decode_rename_maxsz + \
428 decode_getattr_maxsz + \
429 decode_restorefh_maxsz + \
430 decode_getattr_maxsz)
431 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
432 encode_putfh_maxsz + \
433 encode_savefh_maxsz + \
434 encode_putfh_maxsz + \
435 encode_link_maxsz + \
436 decode_getattr_maxsz + \
437 encode_restorefh_maxsz + \
438 decode_getattr_maxsz)
439 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
440 decode_putfh_maxsz + \
441 decode_savefh_maxsz + \
442 decode_putfh_maxsz + \
443 decode_link_maxsz + \
444 decode_getattr_maxsz + \
445 decode_restorefh_maxsz + \
446 decode_getattr_maxsz)
447 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
448 encode_putfh_maxsz + \
449 encode_symlink_maxsz + \
450 encode_getattr_maxsz + \
452 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
453 decode_putfh_maxsz + \
454 decode_symlink_maxsz + \
455 decode_getattr_maxsz + \
457 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
458 encode_putfh_maxsz + \
459 encode_savefh_maxsz + \
460 encode_create_maxsz + \
461 encode_getfh_maxsz + \
462 encode_getattr_maxsz + \
463 encode_restorefh_maxsz + \
464 encode_getattr_maxsz)
465 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
466 decode_putfh_maxsz + \
467 decode_savefh_maxsz + \
468 decode_create_maxsz + \
469 decode_getfh_maxsz + \
470 decode_getattr_maxsz + \
471 decode_restorefh_maxsz + \
472 decode_getattr_maxsz)
473 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
474 encode_putfh_maxsz + \
475 encode_getattr_maxsz)
476 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
477 decode_putfh_maxsz + \
478 decode_getattr_maxsz)
479 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
480 encode_putfh_maxsz + \
482 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
483 decode_putfh_maxsz + \
485 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
486 encode_putfh_maxsz + \
487 encode_getattr_maxsz)
488 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
489 decode_putfh_maxsz + \
490 decode_getattr_maxsz)
491 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
492 encode_putfh_maxsz + \
493 encode_delegreturn_maxsz + \
494 encode_getattr_maxsz)
495 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
496 decode_delegreturn_maxsz + \
497 decode_getattr_maxsz)
498 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
499 encode_putfh_maxsz + \
501 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
502 decode_putfh_maxsz + \
504 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
505 encode_putfh_maxsz + \
507 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
508 decode_putfh_maxsz + \
510 #define NFS4_enc_fs_locations_sz \
511 (compound_encode_hdr_maxsz + \
512 encode_putfh_maxsz + \
513 encode_lookup_maxsz + \
514 encode_fs_locations_maxsz)
515 #define NFS4_dec_fs_locations_sz \
516 (compound_decode_hdr_maxsz + \
517 decode_putfh_maxsz + \
518 decode_lookup_maxsz + \
519 decode_fs_locations_maxsz)
523 unsigned int nfs2type;
531 { S_IFSOCK, NFSOCK },
537 struct compound_hdr {
545 * START OF "GENERIC" ENCODE ROUTINES.
546 * These may look a little ugly since they are imported from a "generic"
547 * set of XDR encode/decode routines which are intended to be shared by
548 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
550 * If the pain of reading these is too great, it should be a straightforward
551 * task to translate them into Linux-specific versions which are more
552 * consistent with the style used in NFSv2/v3...
554 #define WRITE32(n) *p++ = htonl(n)
555 #define WRITE64(n) do { \
556 *p++ = htonl((uint32_t)((n) >> 32)); \
557 *p++ = htonl((uint32_t)(n)); \
559 #define WRITEMEM(ptr,nbytes) do { \
560 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
563 #define RESERVE_SPACE(nbytes) do { \
564 p = xdr_reserve_space(xdr, nbytes); \
565 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
569 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
573 p = xdr_reserve_space(xdr, 4 + len);
575 xdr_encode_opaque(p, str, len);
578 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
582 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
583 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
584 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
585 WRITE32(hdr->taglen);
586 WRITEMEM(hdr->tag, hdr->taglen);
587 WRITE32(NFS4_MINOR_VERSION);
592 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
596 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
598 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
601 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
603 char owner_name[IDMAP_NAMESZ];
604 char owner_group[IDMAP_NAMESZ];
605 int owner_namelen = 0;
606 int owner_grouplen = 0;
615 * We reserve enough space to write the entire attribute buffer at once.
616 * In the worst-case, this would be
617 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
618 * = 36 bytes, plus any contribution from variable-length fields
619 * such as owner/group.
624 if (iap->ia_valid & ATTR_SIZE)
626 if (iap->ia_valid & ATTR_MODE)
628 if (iap->ia_valid & ATTR_UID) {
629 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
630 if (owner_namelen < 0) {
631 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
634 strcpy(owner_name, "nobody");
635 owner_namelen = sizeof("nobody") - 1;
638 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
640 if (iap->ia_valid & ATTR_GID) {
641 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
642 if (owner_grouplen < 0) {
643 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
645 strcpy(owner_group, "nobody");
646 owner_grouplen = sizeof("nobody") - 1;
649 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
651 if (iap->ia_valid & ATTR_ATIME_SET)
653 else if (iap->ia_valid & ATTR_ATIME)
655 if (iap->ia_valid & ATTR_MTIME_SET)
657 else if (iap->ia_valid & ATTR_MTIME)
662 * We write the bitmap length now, but leave the bitmap and the attribute
663 * buffer length to be backfilled at the end of this routine.
669 if (iap->ia_valid & ATTR_SIZE) {
670 bmval0 |= FATTR4_WORD0_SIZE;
671 WRITE64(iap->ia_size);
673 if (iap->ia_valid & ATTR_MODE) {
674 bmval1 |= FATTR4_WORD1_MODE;
675 WRITE32(iap->ia_mode & S_IALLUGO);
677 if (iap->ia_valid & ATTR_UID) {
678 bmval1 |= FATTR4_WORD1_OWNER;
679 WRITE32(owner_namelen);
680 WRITEMEM(owner_name, owner_namelen);
682 if (iap->ia_valid & ATTR_GID) {
683 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
684 WRITE32(owner_grouplen);
685 WRITEMEM(owner_group, owner_grouplen);
687 if (iap->ia_valid & ATTR_ATIME_SET) {
688 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
689 WRITE32(NFS4_SET_TO_CLIENT_TIME);
691 WRITE32(iap->ia_mtime.tv_sec);
692 WRITE32(iap->ia_mtime.tv_nsec);
694 else if (iap->ia_valid & ATTR_ATIME) {
695 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
696 WRITE32(NFS4_SET_TO_SERVER_TIME);
698 if (iap->ia_valid & ATTR_MTIME_SET) {
699 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
700 WRITE32(NFS4_SET_TO_CLIENT_TIME);
702 WRITE32(iap->ia_mtime.tv_sec);
703 WRITE32(iap->ia_mtime.tv_nsec);
705 else if (iap->ia_valid & ATTR_MTIME) {
706 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
707 WRITE32(NFS4_SET_TO_SERVER_TIME);
711 * Now we backfill the bitmap and the attribute buffer length.
713 if (len != ((char *)p - (char *)q) + 4) {
714 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
715 len, ((char *)p - (char *)q) + 4);
718 len = (char *)p - (char *)q - 12;
719 *q++ = htonl(bmval0);
720 *q++ = htonl(bmval1);
728 static int encode_access(struct xdr_stream *xdr, u32 access)
739 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
743 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
745 WRITE32(arg->seqid->sequence->counter);
746 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
751 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
757 WRITE64(args->offset);
758 WRITE32(args->count);
763 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
769 WRITE32(create->ftype);
771 switch (create->ftype) {
774 WRITE32(create->u.symlink.len);
775 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
778 case NF4BLK: case NF4CHR:
780 WRITE32(create->u.device.specdata1);
781 WRITE32(create->u.device.specdata2);
788 RESERVE_SPACE(4 + create->name->len);
789 WRITE32(create->name->len);
790 WRITEMEM(create->name->name, create->name->len);
792 return encode_attrs(xdr, create->attrs, create->server);
795 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
806 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
818 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
820 return encode_getattr_two(xdr,
821 bitmask[0] & nfs4_fattr_bitmap[0],
822 bitmask[1] & nfs4_fattr_bitmap[1]);
825 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
827 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
828 bitmask[1] & nfs4_fsinfo_bitmap[1]);
831 static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
833 return encode_getattr_two(xdr,
834 bitmask[0] & nfs4_fs_locations_bitmap[0],
835 bitmask[1] & nfs4_fs_locations_bitmap[1]);
838 static int encode_getfh(struct xdr_stream *xdr)
848 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
852 RESERVE_SPACE(8 + name->len);
855 WRITEMEM(name->name, name->len);
860 static inline int nfs4_lock_type(struct file_lock *fl, int block)
862 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
863 return block ? NFS4_READW_LT : NFS4_READ_LT;
864 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
867 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
869 if (fl->fl_end == OFFSET_MAX)
871 return fl->fl_end - fl->fl_start + 1;
875 * opcode,type,reclaim,offset,length,new_lock_owner = 32
876 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
878 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
884 WRITE32(nfs4_lock_type(args->fl, args->block));
885 WRITE32(args->reclaim);
886 WRITE64(args->fl->fl_start);
887 WRITE64(nfs4_lock_length(args->fl));
888 WRITE32(args->new_lock_owner);
889 if (args->new_lock_owner){
890 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
891 WRITE32(args->open_seqid->sequence->counter);
892 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
893 WRITE32(args->lock_seqid->sequence->counter);
894 WRITE64(args->lock_owner.clientid);
896 WRITEMEM("lock id:", 8);
897 WRITE64(args->lock_owner.id);
900 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
901 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
902 WRITE32(args->lock_seqid->sequence->counter);
908 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
914 WRITE32(nfs4_lock_type(args->fl, 0));
915 WRITE64(args->fl->fl_start);
916 WRITE64(nfs4_lock_length(args->fl));
917 WRITE64(args->lock_owner.clientid);
919 WRITEMEM("lock id:", 8);
920 WRITE64(args->lock_owner.id);
925 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
929 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
931 WRITE32(nfs4_lock_type(args->fl, 0));
932 WRITE32(args->seqid->sequence->counter);
933 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
934 WRITE64(args->fl->fl_start);
935 WRITE64(nfs4_lock_length(args->fl));
940 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
945 RESERVE_SPACE(8 + len);
948 WRITEMEM(name->name, len);
953 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
958 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
960 WRITE32(NFS4_SHARE_ACCESS_READ);
963 WRITE32(NFS4_SHARE_ACCESS_WRITE);
965 case FMODE_READ|FMODE_WRITE:
966 WRITE32(NFS4_SHARE_ACCESS_BOTH);
971 WRITE32(0); /* for linux, share_deny = 0 always */
974 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
978 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
983 WRITE32(arg->seqid->sequence->counter);
984 encode_share_access(xdr, arg->open_flags);
986 WRITE64(arg->clientid);
988 WRITEMEM("open id:", 8);
992 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
997 switch(arg->open_flags & O_EXCL) {
999 WRITE32(NFS4_CREATE_UNCHECKED);
1000 encode_attrs(xdr, arg->u.attrs, arg->server);
1003 WRITE32(NFS4_CREATE_EXCLUSIVE);
1004 encode_nfs4_verifier(xdr, &arg->u.verifier);
1008 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1013 switch (arg->open_flags & O_CREAT) {
1015 WRITE32(NFS4_OPEN_NOCREATE);
1018 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1019 WRITE32(NFS4_OPEN_CREATE);
1020 encode_createmode(xdr, arg);
1024 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
1029 switch (delegation_type) {
1031 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1034 WRITE32(NFS4_OPEN_DELEGATE_READ);
1036 case FMODE_WRITE|FMODE_READ:
1037 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1044 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1049 WRITE32(NFS4_OPEN_CLAIM_NULL);
1050 encode_string(xdr, name->len, name->name);
1053 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
1058 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1059 encode_delegation_type(xdr, type);
1062 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1066 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1067 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1068 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1069 encode_string(xdr, name->len, name->name);
1072 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1074 encode_openhdr(xdr, arg);
1075 encode_opentype(xdr, arg);
1076 switch (arg->claim) {
1077 case NFS4_OPEN_CLAIM_NULL:
1078 encode_claim_null(xdr, arg->name);
1080 case NFS4_OPEN_CLAIM_PREVIOUS:
1081 encode_claim_previous(xdr, arg->u.delegation_type);
1083 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1084 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1092 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
1096 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1097 WRITE32(OP_OPEN_CONFIRM);
1098 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1099 WRITE32(arg->seqid->sequence->counter);
1104 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1108 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1109 WRITE32(OP_OPEN_DOWNGRADE);
1110 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1111 WRITE32(arg->seqid->sequence->counter);
1112 encode_share_access(xdr, arg->open_flags);
1117 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1122 RESERVE_SPACE(8 + len);
1125 WRITEMEM(fh->data, len);
1130 static int encode_putrootfh(struct xdr_stream *xdr)
1135 WRITE32(OP_PUTROOTFH);
1140 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1142 nfs4_stateid stateid;
1145 RESERVE_SPACE(NFS4_STATEID_SIZE);
1146 if (ctx->state != NULL) {
1147 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1148 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1150 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1153 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1160 encode_stateid(xdr, args->context);
1163 WRITE64(args->offset);
1164 WRITE32(args->count);
1169 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1171 uint32_t attrs[2] = {
1172 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1173 FATTR4_WORD1_MOUNTED_ON_FILEID,
1177 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1178 WRITE32(OP_READDIR);
1179 WRITE64(readdir->cookie);
1180 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1181 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1182 WRITE32(readdir->count);
1184 /* Switch to mounted_on_fileid if the server supports it */
1185 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1186 attrs[0] &= ~FATTR4_WORD0_FILEID;
1188 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1189 WRITE32(attrs[0] & readdir->bitmask[0]);
1190 WRITE32(attrs[1] & readdir->bitmask[1]);
1191 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1193 (unsigned long long)readdir->cookie,
1194 ((u32 *)readdir->verifier.data)[0],
1195 ((u32 *)readdir->verifier.data)[1],
1196 attrs[0] & readdir->bitmask[0],
1197 attrs[1] & readdir->bitmask[1]);
1202 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1207 WRITE32(OP_READLINK);
1212 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1216 RESERVE_SPACE(8 + name->len);
1219 WRITEMEM(name->name, name->len);
1224 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1228 RESERVE_SPACE(8 + oldname->len);
1230 WRITE32(oldname->len);
1231 WRITEMEM(oldname->name, oldname->len);
1233 RESERVE_SPACE(4 + newname->len);
1234 WRITE32(newname->len);
1235 WRITEMEM(newname->name, newname->len);
1240 static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
1246 WRITE64(client_stateid->cl_clientid);
1252 encode_restorefh(struct xdr_stream *xdr)
1257 WRITE32(OP_RESTOREFH);
1263 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1267 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1268 WRITE32(OP_SETATTR);
1269 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1272 WRITE32(FATTR4_WORD0_ACL);
1273 if (arg->acl_len % 4)
1276 WRITE32(arg->acl_len);
1277 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1282 encode_savefh(struct xdr_stream *xdr)
1292 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1297 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1298 WRITE32(OP_SETATTR);
1299 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1301 if ((status = encode_attrs(xdr, arg->iap, server)))
1307 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1311 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1312 WRITE32(OP_SETCLIENTID);
1313 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1315 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1317 WRITE32(setclientid->sc_prog);
1318 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1319 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1321 WRITE32(setclientid->sc_cb_ident);
1326 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
1330 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1331 WRITE32(OP_SETCLIENTID_CONFIRM);
1332 WRITE64(client_state->cl_clientid);
1333 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1338 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1345 encode_stateid(xdr, args->context);
1348 WRITE64(args->offset);
1349 WRITE32(args->stable);
1350 WRITE32(args->count);
1352 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1357 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1361 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1363 WRITE32(OP_DELEGRETURN);
1364 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1369 * END OF "GENERIC" ENCODE ROUTINES.
1373 * Encode an ACCESS request
1375 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1377 struct xdr_stream xdr;
1378 struct compound_hdr hdr = {
1383 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1384 encode_compound_hdr(&xdr, &hdr);
1385 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1386 status = encode_access(&xdr, args->access);
1391 * Encode LOOKUP request
1393 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1395 struct xdr_stream xdr;
1396 struct compound_hdr hdr = {
1401 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1402 encode_compound_hdr(&xdr, &hdr);
1403 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1405 if ((status = encode_lookup(&xdr, args->name)) != 0)
1407 if ((status = encode_getfh(&xdr)) != 0)
1409 status = encode_getfattr(&xdr, args->bitmask);
1415 * Encode LOOKUP_ROOT request
1417 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1419 struct xdr_stream xdr;
1420 struct compound_hdr hdr = {
1425 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1426 encode_compound_hdr(&xdr, &hdr);
1427 if ((status = encode_putrootfh(&xdr)) != 0)
1429 if ((status = encode_getfh(&xdr)) == 0)
1430 status = encode_getfattr(&xdr, args->bitmask);
1436 * Encode REMOVE request
1438 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1440 struct xdr_stream xdr;
1441 struct compound_hdr hdr = {
1446 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1447 encode_compound_hdr(&xdr, &hdr);
1448 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1450 if ((status = encode_remove(&xdr, &args->name)) != 0)
1452 status = encode_getfattr(&xdr, args->bitmask);
1458 * Encode RENAME request
1460 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1462 struct xdr_stream xdr;
1463 struct compound_hdr hdr = {
1468 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1469 encode_compound_hdr(&xdr, &hdr);
1470 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1472 if ((status = encode_savefh(&xdr)) != 0)
1474 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1476 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1478 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1480 if ((status = encode_restorefh(&xdr)) != 0)
1482 status = encode_getfattr(&xdr, args->bitmask);
1488 * Encode LINK request
1490 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1492 struct xdr_stream xdr;
1493 struct compound_hdr hdr = {
1498 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1499 encode_compound_hdr(&xdr, &hdr);
1500 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1502 if ((status = encode_savefh(&xdr)) != 0)
1504 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1506 if ((status = encode_link(&xdr, args->name)) != 0)
1508 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1510 if ((status = encode_restorefh(&xdr)) != 0)
1512 status = encode_getfattr(&xdr, args->bitmask);
1518 * Encode CREATE request
1520 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1522 struct xdr_stream xdr;
1523 struct compound_hdr hdr = {
1528 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1529 encode_compound_hdr(&xdr, &hdr);
1530 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1532 if ((status = encode_savefh(&xdr)) != 0)
1534 if ((status = encode_create(&xdr, args)) != 0)
1536 if ((status = encode_getfh(&xdr)) != 0)
1538 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1540 if ((status = encode_restorefh(&xdr)) != 0)
1542 status = encode_getfattr(&xdr, args->bitmask);
1548 * Encode SYMLINK request
1550 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1552 return nfs4_xdr_enc_create(req, p, args);
1556 * Encode GETATTR request
1558 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1560 struct xdr_stream xdr;
1561 struct compound_hdr hdr = {
1566 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1567 encode_compound_hdr(&xdr, &hdr);
1568 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1569 status = encode_getfattr(&xdr, args->bitmask);
1574 * Encode a CLOSE request
1576 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1578 struct xdr_stream xdr;
1579 struct compound_hdr hdr = {
1584 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1585 encode_compound_hdr(&xdr, &hdr);
1586 status = encode_putfh(&xdr, args->fh);
1589 status = encode_close(&xdr, args);
1592 status = encode_getfattr(&xdr, args->bitmask);
1598 * Encode an OPEN request
1600 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1602 struct xdr_stream xdr;
1603 struct compound_hdr hdr = {
1608 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1609 encode_compound_hdr(&xdr, &hdr);
1610 status = encode_putfh(&xdr, args->fh);
1613 status = encode_savefh(&xdr);
1616 status = encode_open(&xdr, args);
1619 status = encode_getfh(&xdr);
1622 status = encode_getfattr(&xdr, args->bitmask);
1625 status = encode_restorefh(&xdr);
1628 status = encode_getfattr(&xdr, args->bitmask);
1634 * Encode an OPEN_CONFIRM request
1636 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1638 struct xdr_stream xdr;
1639 struct compound_hdr hdr = {
1644 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1645 encode_compound_hdr(&xdr, &hdr);
1646 status = encode_putfh(&xdr, args->fh);
1649 status = encode_open_confirm(&xdr, args);
1655 * Encode an OPEN request with no attributes.
1657 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1659 struct xdr_stream xdr;
1660 struct compound_hdr hdr = {
1665 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1666 encode_compound_hdr(&xdr, &hdr);
1667 status = encode_putfh(&xdr, args->fh);
1670 status = encode_open(&xdr, args);
1673 status = encode_getfattr(&xdr, args->bitmask);
1679 * Encode an OPEN_DOWNGRADE request
1681 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1683 struct xdr_stream xdr;
1684 struct compound_hdr hdr = {
1689 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1690 encode_compound_hdr(&xdr, &hdr);
1691 status = encode_putfh(&xdr, args->fh);
1694 status = encode_open_downgrade(&xdr, args);
1697 status = encode_getfattr(&xdr, args->bitmask);
1703 * Encode a LOCK request
1705 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1707 struct xdr_stream xdr;
1708 struct compound_hdr hdr = {
1713 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1714 encode_compound_hdr(&xdr, &hdr);
1715 status = encode_putfh(&xdr, args->fh);
1718 status = encode_lock(&xdr, args);
1724 * Encode a LOCKT request
1726 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1728 struct xdr_stream xdr;
1729 struct compound_hdr hdr = {
1734 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1735 encode_compound_hdr(&xdr, &hdr);
1736 status = encode_putfh(&xdr, args->fh);
1739 status = encode_lockt(&xdr, args);
1745 * Encode a LOCKU request
1747 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1749 struct xdr_stream xdr;
1750 struct compound_hdr hdr = {
1755 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1756 encode_compound_hdr(&xdr, &hdr);
1757 status = encode_putfh(&xdr, args->fh);
1760 status = encode_locku(&xdr, args);
1766 * Encode a READLINK request
1768 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1770 struct xdr_stream xdr;
1771 struct compound_hdr hdr = {
1774 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1775 unsigned int replen;
1778 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1779 encode_compound_hdr(&xdr, &hdr);
1780 status = encode_putfh(&xdr, args->fh);
1783 status = encode_readlink(&xdr, args, req);
1785 /* set up reply kvec
1786 * toplevel_status + taglen + rescount + OP_PUTFH + status
1787 * + OP_READLINK + status + string length = 8
1789 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readlink_sz) << 2;
1790 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1791 args->pgbase, args->pglen);
1798 * Encode a READDIR request
1800 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1802 struct xdr_stream xdr;
1803 struct compound_hdr hdr = {
1806 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1810 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1811 encode_compound_hdr(&xdr, &hdr);
1812 status = encode_putfh(&xdr, args->fh);
1815 status = encode_readdir(&xdr, args, req);
1817 /* set up reply kvec
1818 * toplevel_status + taglen + rescount + OP_PUTFH + status
1819 * + OP_READDIR + status + verifer(2) = 9
1821 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readdir_sz) << 2;
1822 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1823 args->pgbase, args->count);
1824 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1825 __FUNCTION__, replen, args->pages,
1826 args->pgbase, args->count);
1833 * Encode a READ request
1835 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1837 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1838 struct xdr_stream xdr;
1839 struct compound_hdr hdr = {
1844 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1845 encode_compound_hdr(&xdr, &hdr);
1846 status = encode_putfh(&xdr, args->fh);
1849 status = encode_read(&xdr, args);
1853 /* set up reply kvec
1854 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1855 * + OP_READ + status + eof + datalen = 9
1857 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1858 xdr_inline_pages(&req->rq_rcv_buf, replen,
1859 args->pages, args->pgbase, args->count);
1865 * Encode an SETATTR request
1867 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1870 struct xdr_stream xdr;
1871 struct compound_hdr hdr = {
1876 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1877 encode_compound_hdr(&xdr, &hdr);
1878 status = encode_putfh(&xdr, args->fh);
1881 status = encode_setattr(&xdr, args, args->server);
1884 status = encode_getfattr(&xdr, args->bitmask);
1890 * Encode a GETACL request
1893 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1894 struct nfs_getaclargs *args)
1896 struct xdr_stream xdr;
1897 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1898 struct compound_hdr hdr = {
1903 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1904 encode_compound_hdr(&xdr, &hdr);
1905 status = encode_putfh(&xdr, args->fh);
1908 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1909 /* set up reply buffer: */
1910 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1911 xdr_inline_pages(&req->rq_rcv_buf, replen,
1912 args->acl_pages, args->acl_pgbase, args->acl_len);
1918 * Encode a WRITE request
1920 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1922 struct xdr_stream xdr;
1923 struct compound_hdr hdr = {
1928 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1929 encode_compound_hdr(&xdr, &hdr);
1930 status = encode_putfh(&xdr, args->fh);
1933 status = encode_write(&xdr, args);
1936 status = encode_getfattr(&xdr, args->bitmask);
1944 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1946 struct xdr_stream xdr;
1947 struct compound_hdr hdr = {
1952 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1953 encode_compound_hdr(&xdr, &hdr);
1954 status = encode_putfh(&xdr, args->fh);
1957 status = encode_commit(&xdr, args);
1960 status = encode_getfattr(&xdr, args->bitmask);
1968 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1970 struct xdr_stream xdr;
1971 struct compound_hdr hdr = {
1976 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1977 encode_compound_hdr(&xdr, &hdr);
1978 status = encode_putfh(&xdr, args->fh);
1980 status = encode_fsinfo(&xdr, args->bitmask);
1985 * a PATHCONF request
1987 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1989 struct xdr_stream xdr;
1990 struct compound_hdr hdr = {
1995 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1996 encode_compound_hdr(&xdr, &hdr);
1997 status = encode_putfh(&xdr, args->fh);
1999 status = encode_getattr_one(&xdr,
2000 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
2007 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
2009 struct xdr_stream xdr;
2010 struct compound_hdr hdr = {
2015 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2016 encode_compound_hdr(&xdr, &hdr);
2017 status = encode_putfh(&xdr, args->fh);
2019 status = encode_getattr_two(&xdr,
2020 args->bitmask[0] & nfs4_statfs_bitmap[0],
2021 args->bitmask[1] & nfs4_statfs_bitmap[1]);
2026 * GETATTR_BITMAP request
2028 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
2030 struct xdr_stream xdr;
2031 struct compound_hdr hdr = {
2036 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2037 encode_compound_hdr(&xdr, &hdr);
2038 status = encode_putfh(&xdr, fhandle);
2040 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2041 FATTR4_WORD0_LINK_SUPPORT|
2042 FATTR4_WORD0_SYMLINK_SUPPORT|
2043 FATTR4_WORD0_ACLSUPPORT);
2050 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2052 struct xdr_stream xdr;
2053 struct compound_hdr hdr = {
2057 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2058 encode_compound_hdr(&xdr, &hdr);
2059 return encode_renew(&xdr, clp);
2063 * a SETCLIENTID request
2065 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
2067 struct xdr_stream xdr;
2068 struct compound_hdr hdr = {
2072 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2073 encode_compound_hdr(&xdr, &hdr);
2074 return encode_setclientid(&xdr, sc);
2078 * a SETCLIENTID_CONFIRM request
2080 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2082 struct xdr_stream xdr;
2083 struct compound_hdr hdr = {
2086 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2089 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2090 encode_compound_hdr(&xdr, &hdr);
2091 status = encode_setclientid_confirm(&xdr, clp);
2093 status = encode_putrootfh(&xdr);
2095 status = encode_fsinfo(&xdr, lease_bitmap);
2100 * DELEGRETURN request
2102 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2104 struct xdr_stream xdr;
2105 struct compound_hdr hdr = {
2110 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2111 encode_compound_hdr(&xdr, &hdr);
2112 status = encode_putfh(&xdr, args->fhandle);
2115 status = encode_delegreturn(&xdr, args->stateid);
2118 status = encode_getfattr(&xdr, args->bitmask);
2124 * Encode FS_LOCATIONS request
2126 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2128 struct xdr_stream xdr;
2129 struct compound_hdr hdr = {
2132 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
2136 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2137 encode_compound_hdr(&xdr, &hdr);
2138 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2140 if ((status = encode_lookup(&xdr, args->name)) != 0)
2142 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
2145 * toplevel_status + OP_PUTFH + status
2146 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2148 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2149 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2156 * START OF "GENERIC" DECODE ROUTINES.
2157 * These may look a little ugly since they are imported from a "generic"
2158 * set of XDR encode/decode routines which are intended to be shared by
2159 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2161 * If the pain of reading these is too great, it should be a straightforward
2162 * task to translate them into Linux-specific versions which are more
2163 * consistent with the style used in NFSv2/v3...
2165 #define READ32(x) (x) = ntohl(*p++)
2166 #define READ64(x) do { \
2167 (x) = (u64)ntohl(*p++) << 32; \
2168 (x) |= ntohl(*p++); \
2170 #define READTIME(x) do { \
2172 (x.tv_sec) = ntohl(*p++); \
2173 (x.tv_nsec) = ntohl(*p++); \
2175 #define COPYMEM(x,nbytes) do { \
2176 memcpy((x), p, nbytes); \
2177 p += XDR_QUADLEN(nbytes); \
2180 #define READ_BUF(nbytes) do { \
2181 p = xdr_inline_decode(xdr, nbytes); \
2182 if (unlikely(!p)) { \
2183 printk(KERN_INFO "%s: prematurely hit end of receive" \
2184 " buffer\n", __FUNCTION__); \
2185 printk(KERN_INFO "%s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2186 __FUNCTION__, xdr->p, nbytes, xdr->end); \
2191 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2198 *string = (char *)p;
2202 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2207 READ32(hdr->status);
2208 READ32(hdr->taglen);
2210 READ_BUF(hdr->taglen + 4);
2211 hdr->tag = (char *)p;
2212 p += XDR_QUADLEN(hdr->taglen);
2217 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2225 if (opnum != expected) {
2227 "nfs4_decode_op_hdr: Server returned operation"
2228 " %d but we issued a request for %d\n",
2233 if (nfserr != NFS_OK)
2234 return -nfs4_stat_to_errno(nfserr);
2239 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2242 unsigned int strlen;
2246 return decode_opaque_inline(xdr, &strlen, &str);
2249 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2257 bitmap[0] = bitmap[1] = 0;
2258 READ_BUF((bmlen << 2));
2267 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2277 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2279 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2280 decode_attr_bitmap(xdr, bitmask);
2281 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2283 bitmask[0] = bitmask[1] = 0;
2284 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2288 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2293 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2295 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2298 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2299 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2302 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2304 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2308 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2313 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2315 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2318 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2320 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2321 (unsigned long long)*change);
2325 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2330 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2332 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2335 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2337 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2341 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2346 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2348 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2351 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2353 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2357 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2362 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2364 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2367 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2369 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2373 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2379 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2381 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2383 READ64(fsid->major);
2384 READ64(fsid->minor);
2385 bitmap[0] &= ~FATTR4_WORD0_FSID;
2387 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2388 (unsigned long long)fsid->major,
2389 (unsigned long long)fsid->minor);
2393 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2398 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2400 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2403 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2405 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2409 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2413 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2414 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2416 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2419 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2421 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2425 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2430 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2432 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2435 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2437 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2441 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2446 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2448 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2451 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2453 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2457 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2463 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2465 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2468 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2470 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2474 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2480 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2482 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2485 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2487 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2491 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2497 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2499 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2502 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2504 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2508 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2521 path->ncomponents = 0;
2522 while (path->ncomponents < n) {
2523 struct nfs4_string *component = &path->components[path->ncomponents];
2524 status = decode_opaque_inline(xdr, &component->len, &component->data);
2525 if (unlikely(status != 0))
2527 if (path->ncomponents != n)
2529 dprintk("%s", component->data);
2530 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2531 path->ncomponents++;
2533 dprintk("cannot parse %d components in path\n", n);
2541 /* a root pathname is sent as a zero component4 */
2542 path->ncomponents = 1;
2543 path->components[0].len=0;
2544 path->components[0].data=NULL;
2545 dprintk("path /\n");
2548 dprintk(" status %d", status);
2553 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2559 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2562 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2564 dprintk("%s: fsroot ", __FUNCTION__);
2565 status = decode_pathname(xdr, &res->fs_path);
2566 if (unlikely(status != 0))
2572 res->nlocations = 0;
2573 while (res->nlocations < n) {
2575 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2583 dprintk("%s: servers ", __FUNCTION__);
2584 while (loc->nservers < m) {
2585 struct nfs4_string *server = &loc->servers[loc->nservers];
2586 status = decode_opaque_inline(xdr, &server->len, &server->data);
2587 if (unlikely(status != 0))
2589 dprintk("%s ", server->data);
2590 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2594 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2595 for (i = loc->nservers; i < m; i++) {
2598 status = decode_opaque_inline(xdr, &len, &data);
2599 if (unlikely(status != 0))
2604 status = decode_pathname(xdr, &loc->rootpath);
2605 if (unlikely(status != 0))
2607 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2611 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2618 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2624 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2626 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2629 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2631 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2635 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2641 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2643 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2646 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2648 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2652 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2658 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2660 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2663 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2665 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2669 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2675 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2677 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2681 if (maxread > 0x7FFFFFFF)
2682 maxread = 0x7FFFFFFF;
2683 *res = (uint32_t)maxread;
2684 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2686 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2690 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2696 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2698 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2702 if (maxwrite > 0x7FFFFFFF)
2703 maxwrite = 0x7FFFFFFF;
2704 *res = (uint32_t)maxwrite;
2705 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2707 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2711 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2716 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2718 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2722 bitmap[1] &= ~FATTR4_WORD1_MODE;
2724 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2728 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2733 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2735 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2738 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2740 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2744 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2750 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2752 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2756 if (len < XDR_MAX_NETOBJ) {
2757 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2758 dprintk("%s: nfs_map_name_to_uid failed!\n",
2761 printk(KERN_WARNING "%s: name too long (%u)!\n",
2763 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2765 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2769 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2775 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2777 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2781 if (len < XDR_MAX_NETOBJ) {
2782 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2783 dprintk("%s: nfs_map_group_to_gid failed!\n",
2786 printk(KERN_WARNING "%s: name too long (%u)!\n",
2788 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2790 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2794 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2796 uint32_t major = 0, minor = 0;
2800 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2802 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2808 tmp = MKDEV(major, minor);
2809 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2811 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2813 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2817 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2823 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2825 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2828 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2830 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2834 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2840 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2842 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2845 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2847 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2851 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2857 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2859 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2862 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2864 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2868 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2873 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2875 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2878 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2880 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2881 (unsigned long long)*used);
2885 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2894 time->tv_sec = (time_t)sec;
2895 time->tv_nsec = (long)nsec;
2899 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2905 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2907 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2908 status = decode_attr_time(xdr, time);
2909 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2911 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2915 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2921 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2923 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2924 status = decode_attr_time(xdr, time);
2925 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2927 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2931 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2937 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2939 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2940 status = decode_attr_time(xdr, time);
2941 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2943 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2947 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2949 unsigned int attrwords = XDR_QUADLEN(attrlen);
2950 unsigned int nwords = xdr->p - savep;
2952 if (unlikely(attrwords != nwords)) {
2953 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2956 (attrwords < nwords) ? '<' : '>',
2963 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2968 READ32(cinfo->atomic);
2969 READ64(cinfo->before);
2970 READ64(cinfo->after);
2974 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2980 status = decode_op_hdr(xdr, OP_ACCESS);
2986 access->supported = supp;
2987 access->access = acc;
2991 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2996 status = decode_op_hdr(xdr, OP_CLOSE);
2999 READ_BUF(NFS4_STATEID_SIZE);
3000 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3004 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3009 status = decode_op_hdr(xdr, OP_COMMIT);
3013 COPYMEM(res->verf->verifier, 8);
3017 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3023 status = decode_op_hdr(xdr, OP_CREATE);
3026 if ((status = decode_change_info(xdr, cinfo)))
3030 READ_BUF(bmlen << 2);
3034 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3041 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3043 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3045 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3047 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3049 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3051 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3053 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3055 status = verify_attr_len(xdr, savep, attrlen);
3057 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3061 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3068 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3070 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3072 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3075 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3077 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3079 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3081 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3083 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3085 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3088 status = verify_attr_len(xdr, savep, attrlen);
3090 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3094 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3101 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3103 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3105 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3108 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3110 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3113 status = verify_attr_len(xdr, savep, attrlen);
3115 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3119 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3125 int status, fmode = 0;
3128 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3130 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3133 fattr->bitmap[0] = bitmap[0];
3134 fattr->bitmap[1] = bitmap[1];
3136 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3140 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3142 fattr->type = nfs_type2fmt[type].nfs2type;
3143 fmode = nfs_type2fmt[type].mode;
3145 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3147 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3149 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
3151 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3153 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3154 struct nfs4_fs_locations,
3157 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3159 fattr->mode |= fmode;
3160 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3162 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
3164 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
3166 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3168 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3170 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3172 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3174 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3176 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3178 if (fattr->fileid == 0 && fileid != 0)
3179 fattr->fileid = fileid;
3180 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
3181 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
3183 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
3188 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3191 uint32_t attrlen, bitmap[2];
3194 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3196 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3198 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3201 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3203 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3205 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3207 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3209 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3210 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3212 fsinfo->wtpref = fsinfo->wtmax;
3214 status = verify_attr_len(xdr, savep, attrlen);
3216 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3220 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3226 /* Zero handle first to allow comparisons */
3227 memset(fh, 0, sizeof(*fh));
3229 status = decode_op_hdr(xdr, OP_GETFH);
3235 if (len > NFS4_FHSIZE)
3239 COPYMEM(fh->data, len);
3243 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3247 status = decode_op_hdr(xdr, OP_LINK);
3250 return decode_change_info(xdr, cinfo);
3254 * We create the owner, so we know a proper owner.id length is 4.
3256 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3258 uint64_t offset, length, clientid;
3260 uint32_t namelen, type;
3267 fl->fl_start = (loff_t)offset;
3268 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3269 if (length == ~(uint64_t)0)
3270 fl->fl_end = OFFSET_MAX;
3271 fl->fl_type = F_WRLCK;
3273 fl->fl_type = F_RDLCK;
3279 return -NFS4ERR_DENIED;
3282 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3287 status = decode_op_hdr(xdr, OP_LOCK);
3289 READ_BUF(NFS4_STATEID_SIZE);
3290 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3291 } else if (status == -NFS4ERR_DENIED)
3292 return decode_lock_denied(xdr, NULL);
3296 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3299 status = decode_op_hdr(xdr, OP_LOCKT);
3300 if (status == -NFS4ERR_DENIED)
3301 return decode_lock_denied(xdr, res->denied);
3305 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3310 status = decode_op_hdr(xdr, OP_LOCKU);
3312 READ_BUF(NFS4_STATEID_SIZE);
3313 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3318 static int decode_lookup(struct xdr_stream *xdr)
3320 return decode_op_hdr(xdr, OP_LOOKUP);
3323 /* This is too sick! */
3324 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3327 uint32_t limit_type, nblocks, blocksize;
3331 switch (limit_type) {
3338 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3343 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3346 uint32_t delegation_type;
3349 READ32(delegation_type);
3350 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3351 res->delegation_type = 0;
3354 READ_BUF(NFS4_STATEID_SIZE+4);
3355 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3356 READ32(res->do_recall);
3357 switch (delegation_type) {
3358 case NFS4_OPEN_DELEGATE_READ:
3359 res->delegation_type = FMODE_READ;
3361 case NFS4_OPEN_DELEGATE_WRITE:
3362 res->delegation_type = FMODE_WRITE|FMODE_READ;
3363 if (decode_space_limit(xdr, &res->maxsize) < 0)
3366 return decode_ace(xdr, NULL, res->server->nfs_client);
3369 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3372 uint32_t savewords, bmlen, i;
3375 status = decode_op_hdr(xdr, OP_OPEN);
3378 READ_BUF(NFS4_STATEID_SIZE);
3379 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3381 decode_change_info(xdr, &res->cinfo);
3384 READ32(res->rflags);
3389 READ_BUF(bmlen << 2);
3390 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3391 for (i = 0; i < savewords; ++i)
3392 READ32(res->attrset[i]);
3393 for (; i < NFS4_BITMAP_SIZE; i++)
3394 res->attrset[i] = 0;
3396 return decode_delegation(xdr, res);
3398 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
3402 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3407 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3410 READ_BUF(NFS4_STATEID_SIZE);
3411 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3415 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3420 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3423 READ_BUF(NFS4_STATEID_SIZE);
3424 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3428 static int decode_putfh(struct xdr_stream *xdr)
3430 return decode_op_hdr(xdr, OP_PUTFH);
3433 static int decode_putrootfh(struct xdr_stream *xdr)
3435 return decode_op_hdr(xdr, OP_PUTROOTFH);
3438 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3440 struct kvec *iov = req->rq_rcv_buf.head;
3442 uint32_t count, eof, recvd, hdrlen;
3445 status = decode_op_hdr(xdr, OP_READ);
3451 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3452 recvd = req->rq_rcv_buf.len - hdrlen;
3453 if (count > recvd) {
3454 printk(KERN_WARNING "NFS: server cheating in read reply: "
3455 "count %u > recvd %u\n", count, recvd);
3459 xdr_read_pages(xdr, count);
3465 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3467 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3468 struct page *page = *rcvbuf->pages;
3469 struct kvec *iov = rcvbuf->head;
3470 unsigned int nr, pglen = rcvbuf->page_len;
3471 __be32 *end, *entry, *p, *kaddr;
3472 uint32_t len, attrlen, xlen;
3473 int hdrlen, recvd, status;
3475 status = decode_op_hdr(xdr, OP_READDIR);
3479 COPYMEM(readdir->verifier.data, 8);
3480 dprintk("%s: verifier = 0x%x%x\n",
3482 ((u32 *)readdir->verifier.data)[0],
3483 ((u32 *)readdir->verifier.data)[1]);
3486 hdrlen = (char *) p - (char *) iov->iov_base;
3487 recvd = rcvbuf->len - hdrlen;
3490 xdr_read_pages(xdr, pglen);
3492 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3493 kaddr = p = kmap_atomic(page, KM_USER0);
3494 end = p + ((pglen + readdir->pgbase) >> 2);
3496 for (nr = 0; *p++; nr++) {
3499 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3500 p += 2; /* cookie */
3501 len = ntohl(*p++); /* filename length */
3502 if (len > NFS4_MAXNAMLEN) {
3503 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3506 xlen = XDR_QUADLEN(len);
3507 if (end - p < xlen + 1)
3509 dprintk("filename = %*s\n", len, (char *)p);
3511 len = ntohl(*p++); /* bitmap length */
3512 if (end - p < len + 1)
3515 attrlen = XDR_QUADLEN(ntohl(*p++));
3516 if (end - p < attrlen + 2)
3518 p += attrlen; /* attributes */
3521 if (!nr && (entry[0] != 0 || entry[1] == 0))
3524 kunmap_atomic(kaddr, KM_USER0);
3527 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3528 entry[0] = entry[1] = 0;
3529 /* truncate listing ? */
3531 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3536 kunmap_atomic(kaddr, KM_USER0);
3537 return -errno_NFSERR_IO;
3540 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3542 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3543 struct kvec *iov = rcvbuf->head;
3544 int hdrlen, len, recvd;
3549 status = decode_op_hdr(xdr, OP_READLINK);
3553 /* Convert length of symlink */
3556 if (len >= rcvbuf->page_len || len <= 0) {
3557 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3558 return -ENAMETOOLONG;
3560 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3561 recvd = req->rq_rcv_buf.len - hdrlen;
3563 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3564 "count %u > recvd %u\n", len, recvd);
3567 xdr_read_pages(xdr, len);
3569 * The XDR encode routine has set things up so that
3570 * the link text will be copied directly into the
3571 * buffer. We just have to do overflow-checking,
3572 * and and null-terminate the text (the VFS expects
3573 * null-termination).
3575 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3576 kaddr[len+rcvbuf->page_base] = '\0';
3577 kunmap_atomic(kaddr, KM_USER0);
3581 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3585 status = decode_op_hdr(xdr, OP_REMOVE);
3588 status = decode_change_info(xdr, cinfo);
3593 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3594 struct nfs4_change_info *new_cinfo)
3598 status = decode_op_hdr(xdr, OP_RENAME);
3601 if ((status = decode_change_info(xdr, old_cinfo)))
3603 status = decode_change_info(xdr, new_cinfo);
3608 static int decode_renew(struct xdr_stream *xdr)
3610 return decode_op_hdr(xdr, OP_RENEW);
3614 decode_restorefh(struct xdr_stream *xdr)
3616 return decode_op_hdr(xdr, OP_RESTOREFH);
3619 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3625 struct kvec *iov = req->rq_rcv_buf.head;
3629 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3631 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3633 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3636 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3638 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3641 /* We ignore &savep and don't do consistency checks on
3642 * the attr length. Let userspace figure it out.... */
3643 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3644 recvd = req->rq_rcv_buf.len - hdrlen;
3645 if (attrlen > recvd) {
3646 printk(KERN_WARNING "NFS: server cheating in getattr"
3647 " acl reply: attrlen %u > recvd %u\n",
3651 xdr_read_pages(xdr, attrlen);
3654 status = -EOPNOTSUPP;
3661 decode_savefh(struct xdr_stream *xdr)
3663 return decode_op_hdr(xdr, OP_SAVEFH);
3666 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3673 status = decode_op_hdr(xdr, OP_SETATTR);
3678 READ_BUF(bmlen << 2);
3682 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3690 if (opnum != OP_SETCLIENTID) {
3692 "nfs4_decode_setclientid: Server returned operation"
3697 if (nfserr == NFS_OK) {
3698 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3699 READ64(clp->cl_clientid);
3700 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3701 } else if (nfserr == NFSERR_CLID_INUSE) {
3704 /* skip netid string */
3709 /* skip uaddr string */
3713 return -NFSERR_CLID_INUSE;
3715 return -nfs4_stat_to_errno(nfserr);
3720 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3722 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3725 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3730 status = decode_op_hdr(xdr, OP_WRITE);
3736 READ32(res->verf->committed);
3737 COPYMEM(res->verf->verifier, 8);
3741 static int decode_delegreturn(struct xdr_stream *xdr)
3743 return decode_op_hdr(xdr, OP_DELEGRETURN);
3747 * Decode OPEN_DOWNGRADE response
3749 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3751 struct xdr_stream xdr;
3752 struct compound_hdr hdr;
3755 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3756 status = decode_compound_hdr(&xdr, &hdr);
3759 status = decode_putfh(&xdr);
3762 status = decode_open_downgrade(&xdr, res);
3765 decode_getfattr(&xdr, res->fattr, res->server);
3771 * END OF "GENERIC" DECODE ROUTINES.
3775 * Decode ACCESS response
3777 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3779 struct xdr_stream xdr;
3780 struct compound_hdr hdr;
3783 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3784 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3786 if ((status = decode_putfh(&xdr)) == 0)
3787 status = decode_access(&xdr, res);
3793 * Decode LOOKUP response
3795 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3797 struct xdr_stream xdr;
3798 struct compound_hdr hdr;
3801 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3802 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3804 if ((status = decode_putfh(&xdr)) != 0)
3806 if ((status = decode_lookup(&xdr)) != 0)
3808 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3810 status = decode_getfattr(&xdr, res->fattr, res->server);
3816 * Decode LOOKUP_ROOT response
3818 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3820 struct xdr_stream xdr;
3821 struct compound_hdr hdr;
3824 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3825 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3827 if ((status = decode_putrootfh(&xdr)) != 0)
3829 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3830 status = decode_getfattr(&xdr, res->fattr, res->server);
3836 * Decode REMOVE response
3838 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *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_putfh(&xdr)) != 0)
3849 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3851 decode_getfattr(&xdr, &res->dir_attr, res->server);
3857 * Decode RENAME response
3859 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3861 struct xdr_stream xdr;
3862 struct compound_hdr hdr;
3865 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3866 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3868 if ((status = decode_putfh(&xdr)) != 0)
3870 if ((status = decode_savefh(&xdr)) != 0)
3872 if ((status = decode_putfh(&xdr)) != 0)
3874 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3876 /* Current FH is target directory */
3877 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3879 if ((status = decode_restorefh(&xdr)) != 0)
3881 decode_getfattr(&xdr, res->old_fattr, res->server);
3887 * Decode LINK response
3889 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3891 struct xdr_stream xdr;
3892 struct compound_hdr hdr;
3895 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3896 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3898 if ((status = decode_putfh(&xdr)) != 0)
3900 if ((status = decode_savefh(&xdr)) != 0)
3902 if ((status = decode_putfh(&xdr)) != 0)
3904 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3907 * Note order: OP_LINK leaves the directory as the current
3910 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3912 if ((status = decode_restorefh(&xdr)) != 0)
3914 decode_getfattr(&xdr, res->fattr, res->server);
3920 * Decode CREATE response
3922 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3924 struct xdr_stream xdr;
3925 struct compound_hdr hdr;
3928 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3929 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3931 if ((status = decode_putfh(&xdr)) != 0)
3933 if ((status = decode_savefh(&xdr)) != 0)
3935 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3937 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3939 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3941 if ((status = decode_restorefh(&xdr)) != 0)
3943 decode_getfattr(&xdr, res->dir_fattr, res->server);
3949 * Decode SYMLINK response
3951 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3953 return nfs4_xdr_dec_create(rqstp, p, res);
3957 * Decode GETATTR response
3959 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3961 struct xdr_stream xdr;
3962 struct compound_hdr hdr;
3965 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3966 status = decode_compound_hdr(&xdr, &hdr);
3969 status = decode_putfh(&xdr);
3972 status = decode_getfattr(&xdr, res->fattr, res->server);
3979 * Encode an SETACL request
3982 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3984 struct xdr_stream xdr;
3985 struct compound_hdr hdr = {
3990 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3991 encode_compound_hdr(&xdr, &hdr);
3992 status = encode_putfh(&xdr, args->fh);
3995 status = encode_setacl(&xdr, args);
4000 * Decode SETACL response
4003 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
4005 struct xdr_stream xdr;
4006 struct compound_hdr hdr;
4009 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4010 status = decode_compound_hdr(&xdr, &hdr);
4013 status = decode_putfh(&xdr);
4016 status = decode_setattr(&xdr, res);
4022 * Decode GETACL response
4025 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
4027 struct xdr_stream xdr;
4028 struct compound_hdr hdr;
4031 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4032 status = decode_compound_hdr(&xdr, &hdr);
4035 status = decode_putfh(&xdr);
4038 status = decode_getacl(&xdr, rqstp, acl_len);
4045 * Decode CLOSE response
4047 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4049 struct xdr_stream xdr;
4050 struct compound_hdr hdr;
4053 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4054 status = decode_compound_hdr(&xdr, &hdr);
4057 status = decode_putfh(&xdr);
4060 status = decode_close(&xdr, res);
4064 * Note: Server may do delete on close for this file
4065 * in which case the getattr call will fail with
4066 * an ESTALE error. Shouldn't be a problem,
4067 * though, since fattr->valid will remain unset.
4069 decode_getfattr(&xdr, res->fattr, res->server);
4075 * Decode OPEN response
4077 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4079 struct xdr_stream xdr;
4080 struct compound_hdr hdr;
4083 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4084 status = decode_compound_hdr(&xdr, &hdr);
4087 status = decode_putfh(&xdr);
4090 status = decode_savefh(&xdr);
4093 status = decode_open(&xdr, res);
4096 if (decode_getfh(&xdr, &res->fh) != 0)
4098 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4100 if (decode_restorefh(&xdr) != 0)
4102 decode_getfattr(&xdr, res->dir_attr, res->server);
4108 * Decode OPEN_CONFIRM response
4110 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4112 struct xdr_stream xdr;
4113 struct compound_hdr hdr;
4116 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4117 status = decode_compound_hdr(&xdr, &hdr);
4120 status = decode_putfh(&xdr);
4123 status = decode_open_confirm(&xdr, res);
4129 * Decode OPEN response
4131 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4133 struct xdr_stream xdr;
4134 struct compound_hdr hdr;
4137 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4138 status = decode_compound_hdr(&xdr, &hdr);
4141 status = decode_putfh(&xdr);
4144 status = decode_open(&xdr, res);
4147 decode_getfattr(&xdr, res->f_attr, res->server);
4153 * Decode SETATTR response
4155 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4157 struct xdr_stream xdr;
4158 struct compound_hdr hdr;
4161 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4162 status = decode_compound_hdr(&xdr, &hdr);
4165 status = decode_putfh(&xdr);
4168 status = decode_setattr(&xdr, res);
4171 status = decode_getfattr(&xdr, res->fattr, res->server);
4172 if (status == NFS4ERR_DELAY)
4179 * Decode LOCK response
4181 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4183 struct xdr_stream xdr;
4184 struct compound_hdr hdr;
4187 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4188 status = decode_compound_hdr(&xdr, &hdr);
4191 status = decode_putfh(&xdr);
4194 status = decode_lock(&xdr, res);
4200 * Decode LOCKT response
4202 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4204 struct xdr_stream xdr;
4205 struct compound_hdr hdr;
4208 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4209 status = decode_compound_hdr(&xdr, &hdr);
4212 status = decode_putfh(&xdr);
4215 status = decode_lockt(&xdr, res);
4221 * Decode LOCKU response
4223 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4225 struct xdr_stream xdr;
4226 struct compound_hdr hdr;
4229 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4230 status = decode_compound_hdr(&xdr, &hdr);
4233 status = decode_putfh(&xdr);
4236 status = decode_locku(&xdr, res);
4242 * Decode READLINK response
4244 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
4246 struct xdr_stream xdr;
4247 struct compound_hdr hdr;
4250 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4251 status = decode_compound_hdr(&xdr, &hdr);
4254 status = decode_putfh(&xdr);
4257 status = decode_readlink(&xdr, rqstp);
4263 * Decode READDIR response
4265 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4267 struct xdr_stream xdr;
4268 struct compound_hdr hdr;
4271 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4272 status = decode_compound_hdr(&xdr, &hdr);
4275 status = decode_putfh(&xdr);
4278 status = decode_readdir(&xdr, rqstp, res);
4284 * Decode Read response
4286 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4288 struct xdr_stream xdr;
4289 struct compound_hdr hdr;
4292 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4293 status = decode_compound_hdr(&xdr, &hdr);
4296 status = decode_putfh(&xdr);
4299 status = decode_read(&xdr, rqstp, res);
4301 status = res->count;
4307 * Decode WRITE response
4309 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4311 struct xdr_stream xdr;
4312 struct compound_hdr hdr;
4315 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4316 status = decode_compound_hdr(&xdr, &hdr);
4319 status = decode_putfh(&xdr);
4322 status = decode_write(&xdr, res);
4325 decode_getfattr(&xdr, res->fattr, res->server);
4327 status = res->count;
4333 * Decode COMMIT response
4335 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4337 struct xdr_stream xdr;
4338 struct compound_hdr hdr;
4341 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4342 status = decode_compound_hdr(&xdr, &hdr);
4345 status = decode_putfh(&xdr);
4348 status = decode_commit(&xdr, res);
4351 decode_getfattr(&xdr, res->fattr, res->server);
4359 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4361 struct xdr_stream xdr;
4362 struct compound_hdr hdr;
4365 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4366 status = decode_compound_hdr(&xdr, &hdr);
4368 status = decode_putfh(&xdr);
4370 status = decode_fsinfo(&xdr, fsinfo);
4372 status = -nfs4_stat_to_errno(hdr.status);
4379 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
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_pathconf(&xdr, pathconf);
4397 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
4399 struct xdr_stream xdr;
4400 struct compound_hdr hdr;
4403 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4404 status = decode_compound_hdr(&xdr, &hdr);
4406 status = decode_putfh(&xdr);
4408 status = decode_statfs(&xdr, fsstat);
4413 * GETATTR_BITMAP request
4415 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4417 struct xdr_stream xdr;
4418 struct compound_hdr hdr;
4421 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4422 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4424 if ((status = decode_putfh(&xdr)) != 0)
4426 status = decode_server_caps(&xdr, res);
4432 * Decode RENEW response
4434 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4436 struct xdr_stream xdr;
4437 struct compound_hdr hdr;
4440 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4441 status = decode_compound_hdr(&xdr, &hdr);
4443 status = decode_renew(&xdr);
4448 * a SETCLIENTID request
4450 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4451 struct nfs_client *clp)
4453 struct xdr_stream xdr;
4454 struct compound_hdr hdr;
4457 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4458 status = decode_compound_hdr(&xdr, &hdr);
4460 status = decode_setclientid(&xdr, clp);
4462 status = -nfs4_stat_to_errno(hdr.status);
4467 * a SETCLIENTID_CONFIRM request
4469 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4471 struct xdr_stream xdr;
4472 struct compound_hdr hdr;
4475 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4476 status = decode_compound_hdr(&xdr, &hdr);
4478 status = decode_setclientid_confirm(&xdr);
4480 status = decode_putrootfh(&xdr);
4482 status = decode_fsinfo(&xdr, fsinfo);
4484 status = -nfs4_stat_to_errno(hdr.status);
4489 * DELEGRETURN request
4491 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4493 struct xdr_stream xdr;
4494 struct compound_hdr hdr;
4497 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4498 status = decode_compound_hdr(&xdr, &hdr);
4501 status = decode_putfh(&xdr);
4504 status = decode_delegreturn(&xdr);
4505 decode_getfattr(&xdr, res->fattr, res->server);
4511 * FS_LOCATIONS request
4513 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
4515 struct xdr_stream xdr;
4516 struct compound_hdr hdr;
4519 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4520 status = decode_compound_hdr(&xdr, &hdr);
4523 if ((status = decode_putfh(&xdr)) != 0)
4525 if ((status = decode_lookup(&xdr)) != 0)
4527 xdr_enter_page(&xdr, PAGE_SIZE);
4528 status = decode_getfattr(&xdr, &res->fattr, res->server);
4533 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4535 uint32_t bitmap[2] = {0};
4540 return ERR_PTR(-EAGAIN);
4542 return ERR_PTR(-EBADCOOKIE);
4545 entry->prev_cookie = entry->cookie;
4546 p = xdr_decode_hyper(p, &entry->cookie);
4547 entry->len = ntohl(*p++);
4548 entry->name = (const char *) p;
4549 p += XDR_QUADLEN(entry->len);
4552 * In case the server doesn't return an inode number,
4553 * we fake one here. (We don't use inode number 0,
4554 * since glibc seems to choke on it...)
4558 len = ntohl(*p++); /* bitmap length */
4560 bitmap[0] = ntohl(*p++);
4562 bitmap[1] = ntohl(*p++);
4566 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4568 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4569 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4570 /* Ignore the return value of rdattr_error for now */
4574 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4575 xdr_decode_hyper(p, &entry->ino);
4576 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4577 xdr_decode_hyper(p, &entry->ino);
4581 entry->eof = !p[0] && p[1];
4586 * We need to translate between nfs status return values and
4587 * the local errno values which may not be the same.
4594 { NFS4ERR_PERM, EPERM },
4595 { NFS4ERR_NOENT, ENOENT },
4596 { NFS4ERR_IO, errno_NFSERR_IO },
4597 { NFS4ERR_NXIO, ENXIO },
4598 { NFS4ERR_ACCESS, EACCES },
4599 { NFS4ERR_EXIST, EEXIST },
4600 { NFS4ERR_XDEV, EXDEV },
4601 { NFS4ERR_NOTDIR, ENOTDIR },
4602 { NFS4ERR_ISDIR, EISDIR },
4603 { NFS4ERR_INVAL, EINVAL },
4604 { NFS4ERR_FBIG, EFBIG },
4605 { NFS4ERR_NOSPC, ENOSPC },
4606 { NFS4ERR_ROFS, EROFS },
4607 { NFS4ERR_MLINK, EMLINK },
4608 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4609 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4610 { NFS4ERR_DQUOT, EDQUOT },
4611 { NFS4ERR_STALE, ESTALE },
4612 { NFS4ERR_BADHANDLE, EBADHANDLE },
4613 { NFS4ERR_BADOWNER, EINVAL },
4614 { NFS4ERR_BADNAME, EINVAL },
4615 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4616 { NFS4ERR_NOTSUPP, ENOTSUPP },
4617 { NFS4ERR_TOOSMALL, ETOOSMALL },
4618 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4619 { NFS4ERR_BADTYPE, EBADTYPE },
4620 { NFS4ERR_LOCKED, EAGAIN },
4621 { NFS4ERR_RESOURCE, EREMOTEIO },
4622 { NFS4ERR_SYMLINK, ELOOP },
4623 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4624 { NFS4ERR_DEADLOCK, EDEADLK },
4625 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4626 * to be handled by a
4633 * Convert an NFS error code to a local one.
4634 * This one is used jointly by NFSv2 and NFSv3.
4637 nfs4_stat_to_errno(int stat)
4640 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4641 if (nfs_errtbl[i].stat == stat)
4642 return nfs_errtbl[i].errno;
4644 if (stat <= 10000 || stat > 10100) {
4645 /* The server is looney tunes. */
4646 return ESERVERFAULT;
4648 /* If we cannot translate the error, the recovery routines should
4650 * Note: remaining NFSv4 error codes have values > 10000, so should
4651 * not conflict with native Linux error codes.
4656 #define PROC(proc, argtype, restype) \
4657 [NFSPROC4_CLNT_##proc] = { \
4658 .p_proc = NFSPROC4_COMPOUND, \
4659 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4660 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4661 .p_arglen = NFS4_##argtype##_sz, \
4662 .p_replen = NFS4_##restype##_sz, \
4663 .p_statidx = NFSPROC4_CLNT_##proc, \
4667 struct rpc_procinfo nfs4_procedures[] = {
4668 PROC(READ, enc_read, dec_read),
4669 PROC(WRITE, enc_write, dec_write),
4670 PROC(COMMIT, enc_commit, dec_commit),
4671 PROC(OPEN, enc_open, dec_open),
4672 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4673 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4674 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4675 PROC(CLOSE, enc_close, dec_close),
4676 PROC(SETATTR, enc_setattr, dec_setattr),
4677 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4678 PROC(RENEW, enc_renew, dec_renew),
4679 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4680 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4681 PROC(LOCK, enc_lock, dec_lock),
4682 PROC(LOCKT, enc_lockt, dec_lockt),
4683 PROC(LOCKU, enc_locku, dec_locku),
4684 PROC(ACCESS, enc_access, dec_access),
4685 PROC(GETATTR, enc_getattr, dec_getattr),
4686 PROC(LOOKUP, enc_lookup, dec_lookup),
4687 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4688 PROC(REMOVE, enc_remove, dec_remove),
4689 PROC(RENAME, enc_rename, dec_rename),
4690 PROC(LINK, enc_link, dec_link),
4691 PROC(SYMLINK, enc_symlink, dec_symlink),
4692 PROC(CREATE, enc_create, dec_create),
4693 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4694 PROC(STATFS, enc_statfs, dec_statfs),
4695 PROC(READLINK, enc_readlink, dec_readlink),
4696 PROC(READDIR, enc_readdir, dec_readdir),
4697 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4698 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4699 PROC(GETACL, enc_getacl, dec_getacl),
4700 PROC(SETACL, enc_setacl, dec_setacl),
4701 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4704 struct rpc_version nfs_version4 = {
4706 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4707 .procs = nfs4_procedures