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); \
568 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
572 p = xdr_reserve_space(xdr, 4 + len);
574 xdr_encode_opaque(p, str, len);
577 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
581 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
582 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
583 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
584 WRITE32(hdr->taglen);
585 WRITEMEM(hdr->tag, hdr->taglen);
586 WRITE32(NFS4_MINOR_VERSION);
591 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
595 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
597 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
600 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
602 char owner_name[IDMAP_NAMESZ];
603 char owner_group[IDMAP_NAMESZ];
604 int owner_namelen = 0;
605 int owner_grouplen = 0;
614 * We reserve enough space to write the entire attribute buffer at once.
615 * In the worst-case, this would be
616 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
617 * = 36 bytes, plus any contribution from variable-length fields
618 * such as owner/group.
623 if (iap->ia_valid & ATTR_SIZE)
625 if (iap->ia_valid & ATTR_MODE)
627 if (iap->ia_valid & ATTR_UID) {
628 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
629 if (owner_namelen < 0) {
630 dprintk("nfs: couldn't resolve uid %d to string\n",
633 strcpy(owner_name, "nobody");
634 owner_namelen = sizeof("nobody") - 1;
637 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
639 if (iap->ia_valid & ATTR_GID) {
640 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
641 if (owner_grouplen < 0) {
642 dprintk("nfs: couldn't resolve gid %d to string\n",
644 strcpy(owner_group, "nobody");
645 owner_grouplen = sizeof("nobody") - 1;
648 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
650 if (iap->ia_valid & ATTR_ATIME_SET)
652 else if (iap->ia_valid & ATTR_ATIME)
654 if (iap->ia_valid & ATTR_MTIME_SET)
656 else if (iap->ia_valid & ATTR_MTIME)
661 * We write the bitmap length now, but leave the bitmap and the attribute
662 * buffer length to be backfilled at the end of this routine.
668 if (iap->ia_valid & ATTR_SIZE) {
669 bmval0 |= FATTR4_WORD0_SIZE;
670 WRITE64(iap->ia_size);
672 if (iap->ia_valid & ATTR_MODE) {
673 bmval1 |= FATTR4_WORD1_MODE;
674 WRITE32(iap->ia_mode & S_IALLUGO);
676 if (iap->ia_valid & ATTR_UID) {
677 bmval1 |= FATTR4_WORD1_OWNER;
678 WRITE32(owner_namelen);
679 WRITEMEM(owner_name, owner_namelen);
681 if (iap->ia_valid & ATTR_GID) {
682 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
683 WRITE32(owner_grouplen);
684 WRITEMEM(owner_group, owner_grouplen);
686 if (iap->ia_valid & ATTR_ATIME_SET) {
687 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
688 WRITE32(NFS4_SET_TO_CLIENT_TIME);
690 WRITE32(iap->ia_mtime.tv_sec);
691 WRITE32(iap->ia_mtime.tv_nsec);
693 else if (iap->ia_valid & ATTR_ATIME) {
694 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
695 WRITE32(NFS4_SET_TO_SERVER_TIME);
697 if (iap->ia_valid & ATTR_MTIME_SET) {
698 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
699 WRITE32(NFS4_SET_TO_CLIENT_TIME);
701 WRITE32(iap->ia_mtime.tv_sec);
702 WRITE32(iap->ia_mtime.tv_nsec);
704 else if (iap->ia_valid & ATTR_MTIME) {
705 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
706 WRITE32(NFS4_SET_TO_SERVER_TIME);
710 * Now we backfill the bitmap and the attribute buffer length.
712 if (len != ((char *)p - (char *)q) + 4) {
713 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
714 len, ((char *)p - (char *)q) + 4);
717 len = (char *)p - (char *)q - 12;
718 *q++ = htonl(bmval0);
719 *q++ = htonl(bmval1);
727 static int encode_access(struct xdr_stream *xdr, u32 access)
738 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
742 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
744 WRITE32(arg->seqid->sequence->counter);
745 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
750 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
756 WRITE64(args->offset);
757 WRITE32(args->count);
762 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
768 WRITE32(create->ftype);
770 switch (create->ftype) {
773 WRITE32(create->u.symlink.len);
774 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
777 case NF4BLK: case NF4CHR:
779 WRITE32(create->u.device.specdata1);
780 WRITE32(create->u.device.specdata2);
787 RESERVE_SPACE(4 + create->name->len);
788 WRITE32(create->name->len);
789 WRITEMEM(create->name->name, create->name->len);
791 return encode_attrs(xdr, create->attrs, create->server);
794 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
805 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
817 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
819 return encode_getattr_two(xdr,
820 bitmask[0] & nfs4_fattr_bitmap[0],
821 bitmask[1] & nfs4_fattr_bitmap[1]);
824 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
826 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
827 bitmask[1] & nfs4_fsinfo_bitmap[1]);
830 static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
832 return encode_getattr_two(xdr,
833 bitmask[0] & nfs4_fs_locations_bitmap[0],
834 bitmask[1] & nfs4_fs_locations_bitmap[1]);
837 static int encode_getfh(struct xdr_stream *xdr)
847 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
851 RESERVE_SPACE(8 + name->len);
854 WRITEMEM(name->name, name->len);
859 static inline int nfs4_lock_type(struct file_lock *fl, int block)
861 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
862 return block ? NFS4_READW_LT : NFS4_READ_LT;
863 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
866 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
868 if (fl->fl_end == OFFSET_MAX)
870 return fl->fl_end - fl->fl_start + 1;
874 * opcode,type,reclaim,offset,length,new_lock_owner = 32
875 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
877 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
883 WRITE32(nfs4_lock_type(args->fl, args->block));
884 WRITE32(args->reclaim);
885 WRITE64(args->fl->fl_start);
886 WRITE64(nfs4_lock_length(args->fl));
887 WRITE32(args->new_lock_owner);
888 if (args->new_lock_owner){
889 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
890 WRITE32(args->open_seqid->sequence->counter);
891 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
892 WRITE32(args->lock_seqid->sequence->counter);
893 WRITE64(args->lock_owner.clientid);
895 WRITEMEM("lock id:", 8);
896 WRITE64(args->lock_owner.id);
899 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
900 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
901 WRITE32(args->lock_seqid->sequence->counter);
907 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
913 WRITE32(nfs4_lock_type(args->fl, 0));
914 WRITE64(args->fl->fl_start);
915 WRITE64(nfs4_lock_length(args->fl));
916 WRITE64(args->lock_owner.clientid);
918 WRITEMEM("lock id:", 8);
919 WRITE64(args->lock_owner.id);
924 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
928 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
930 WRITE32(nfs4_lock_type(args->fl, 0));
931 WRITE32(args->seqid->sequence->counter);
932 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
933 WRITE64(args->fl->fl_start);
934 WRITE64(nfs4_lock_length(args->fl));
939 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
944 RESERVE_SPACE(8 + len);
947 WRITEMEM(name->name, len);
952 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
957 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
959 WRITE32(NFS4_SHARE_ACCESS_READ);
962 WRITE32(NFS4_SHARE_ACCESS_WRITE);
964 case FMODE_READ|FMODE_WRITE:
965 WRITE32(NFS4_SHARE_ACCESS_BOTH);
970 WRITE32(0); /* for linux, share_deny = 0 always */
973 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
977 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
982 WRITE32(arg->seqid->sequence->counter);
983 encode_share_access(xdr, arg->open_flags);
985 WRITE64(arg->clientid);
987 WRITEMEM("open id:", 8);
991 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
996 switch(arg->open_flags & O_EXCL) {
998 WRITE32(NFS4_CREATE_UNCHECKED);
999 encode_attrs(xdr, arg->u.attrs, arg->server);
1002 WRITE32(NFS4_CREATE_EXCLUSIVE);
1003 encode_nfs4_verifier(xdr, &arg->u.verifier);
1007 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1012 switch (arg->open_flags & O_CREAT) {
1014 WRITE32(NFS4_OPEN_NOCREATE);
1017 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1018 WRITE32(NFS4_OPEN_CREATE);
1019 encode_createmode(xdr, arg);
1023 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
1028 switch (delegation_type) {
1030 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1033 WRITE32(NFS4_OPEN_DELEGATE_READ);
1035 case FMODE_WRITE|FMODE_READ:
1036 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1043 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1048 WRITE32(NFS4_OPEN_CLAIM_NULL);
1049 encode_string(xdr, name->len, name->name);
1052 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
1057 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1058 encode_delegation_type(xdr, type);
1061 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1065 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1066 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1067 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1068 encode_string(xdr, name->len, name->name);
1071 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1073 encode_openhdr(xdr, arg);
1074 encode_opentype(xdr, arg);
1075 switch (arg->claim) {
1076 case NFS4_OPEN_CLAIM_NULL:
1077 encode_claim_null(xdr, arg->name);
1079 case NFS4_OPEN_CLAIM_PREVIOUS:
1080 encode_claim_previous(xdr, arg->u.delegation_type);
1082 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1083 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1091 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
1095 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1096 WRITE32(OP_OPEN_CONFIRM);
1097 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1098 WRITE32(arg->seqid->sequence->counter);
1103 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1107 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1108 WRITE32(OP_OPEN_DOWNGRADE);
1109 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1110 WRITE32(arg->seqid->sequence->counter);
1111 encode_share_access(xdr, arg->open_flags);
1116 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1121 RESERVE_SPACE(8 + len);
1124 WRITEMEM(fh->data, len);
1129 static int encode_putrootfh(struct xdr_stream *xdr)
1134 WRITE32(OP_PUTROOTFH);
1139 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1141 nfs4_stateid stateid;
1144 RESERVE_SPACE(NFS4_STATEID_SIZE);
1145 if (ctx->state != NULL) {
1146 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1147 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1149 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1152 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1159 encode_stateid(xdr, args->context);
1162 WRITE64(args->offset);
1163 WRITE32(args->count);
1168 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1170 uint32_t attrs[2] = {
1171 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1172 FATTR4_WORD1_MOUNTED_ON_FILEID,
1176 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1177 WRITE32(OP_READDIR);
1178 WRITE64(readdir->cookie);
1179 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1180 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1181 WRITE32(readdir->count);
1183 /* Switch to mounted_on_fileid if the server supports it */
1184 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1185 attrs[0] &= ~FATTR4_WORD0_FILEID;
1187 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1188 WRITE32(attrs[0] & readdir->bitmask[0]);
1189 WRITE32(attrs[1] & readdir->bitmask[1]);
1190 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1192 (unsigned long long)readdir->cookie,
1193 ((u32 *)readdir->verifier.data)[0],
1194 ((u32 *)readdir->verifier.data)[1],
1195 attrs[0] & readdir->bitmask[0],
1196 attrs[1] & readdir->bitmask[1]);
1201 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1206 WRITE32(OP_READLINK);
1211 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1215 RESERVE_SPACE(8 + name->len);
1218 WRITEMEM(name->name, name->len);
1223 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1227 RESERVE_SPACE(8 + oldname->len);
1229 WRITE32(oldname->len);
1230 WRITEMEM(oldname->name, oldname->len);
1232 RESERVE_SPACE(4 + newname->len);
1233 WRITE32(newname->len);
1234 WRITEMEM(newname->name, newname->len);
1239 static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
1245 WRITE64(client_stateid->cl_clientid);
1251 encode_restorefh(struct xdr_stream *xdr)
1256 WRITE32(OP_RESTOREFH);
1262 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1266 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1267 WRITE32(OP_SETATTR);
1268 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1271 WRITE32(FATTR4_WORD0_ACL);
1272 if (arg->acl_len % 4)
1275 WRITE32(arg->acl_len);
1276 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1281 encode_savefh(struct xdr_stream *xdr)
1291 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1296 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1297 WRITE32(OP_SETATTR);
1298 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1300 if ((status = encode_attrs(xdr, arg->iap, server)))
1306 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1310 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1311 WRITE32(OP_SETCLIENTID);
1312 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1314 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1316 WRITE32(setclientid->sc_prog);
1317 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1318 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1320 WRITE32(setclientid->sc_cb_ident);
1325 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
1329 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1330 WRITE32(OP_SETCLIENTID_CONFIRM);
1331 WRITE64(client_state->cl_clientid);
1332 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1337 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1344 encode_stateid(xdr, args->context);
1347 WRITE64(args->offset);
1348 WRITE32(args->stable);
1349 WRITE32(args->count);
1351 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1356 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1360 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1362 WRITE32(OP_DELEGRETURN);
1363 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1368 * END OF "GENERIC" ENCODE ROUTINES.
1372 * Encode an ACCESS request
1374 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1376 struct xdr_stream xdr;
1377 struct compound_hdr hdr = {
1382 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1383 encode_compound_hdr(&xdr, &hdr);
1384 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1385 status = encode_access(&xdr, args->access);
1390 * Encode LOOKUP request
1392 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1394 struct xdr_stream xdr;
1395 struct compound_hdr hdr = {
1400 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1401 encode_compound_hdr(&xdr, &hdr);
1402 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1404 if ((status = encode_lookup(&xdr, args->name)) != 0)
1406 if ((status = encode_getfh(&xdr)) != 0)
1408 status = encode_getfattr(&xdr, args->bitmask);
1414 * Encode LOOKUP_ROOT request
1416 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1418 struct xdr_stream xdr;
1419 struct compound_hdr hdr = {
1424 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1425 encode_compound_hdr(&xdr, &hdr);
1426 if ((status = encode_putrootfh(&xdr)) != 0)
1428 if ((status = encode_getfh(&xdr)) == 0)
1429 status = encode_getfattr(&xdr, args->bitmask);
1435 * Encode REMOVE request
1437 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1439 struct xdr_stream xdr;
1440 struct compound_hdr hdr = {
1445 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1446 encode_compound_hdr(&xdr, &hdr);
1447 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1449 if ((status = encode_remove(&xdr, &args->name)) != 0)
1451 status = encode_getfattr(&xdr, args->bitmask);
1457 * Encode RENAME request
1459 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1461 struct xdr_stream xdr;
1462 struct compound_hdr hdr = {
1467 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1468 encode_compound_hdr(&xdr, &hdr);
1469 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1471 if ((status = encode_savefh(&xdr)) != 0)
1473 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1475 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1477 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1479 if ((status = encode_restorefh(&xdr)) != 0)
1481 status = encode_getfattr(&xdr, args->bitmask);
1487 * Encode LINK request
1489 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1491 struct xdr_stream xdr;
1492 struct compound_hdr hdr = {
1497 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1498 encode_compound_hdr(&xdr, &hdr);
1499 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1501 if ((status = encode_savefh(&xdr)) != 0)
1503 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1505 if ((status = encode_link(&xdr, args->name)) != 0)
1507 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1509 if ((status = encode_restorefh(&xdr)) != 0)
1511 status = encode_getfattr(&xdr, args->bitmask);
1517 * Encode CREATE request
1519 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1521 struct xdr_stream xdr;
1522 struct compound_hdr hdr = {
1527 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1528 encode_compound_hdr(&xdr, &hdr);
1529 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1531 if ((status = encode_savefh(&xdr)) != 0)
1533 if ((status = encode_create(&xdr, args)) != 0)
1535 if ((status = encode_getfh(&xdr)) != 0)
1537 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1539 if ((status = encode_restorefh(&xdr)) != 0)
1541 status = encode_getfattr(&xdr, args->bitmask);
1547 * Encode SYMLINK request
1549 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1551 return nfs4_xdr_enc_create(req, p, args);
1555 * Encode GETATTR request
1557 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1559 struct xdr_stream xdr;
1560 struct compound_hdr hdr = {
1565 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1566 encode_compound_hdr(&xdr, &hdr);
1567 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1568 status = encode_getfattr(&xdr, args->bitmask);
1573 * Encode a CLOSE request
1575 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1577 struct xdr_stream xdr;
1578 struct compound_hdr hdr = {
1583 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1584 encode_compound_hdr(&xdr, &hdr);
1585 status = encode_putfh(&xdr, args->fh);
1588 status = encode_close(&xdr, args);
1591 status = encode_getfattr(&xdr, args->bitmask);
1597 * Encode an OPEN request
1599 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1601 struct xdr_stream xdr;
1602 struct compound_hdr hdr = {
1607 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1608 encode_compound_hdr(&xdr, &hdr);
1609 status = encode_putfh(&xdr, args->fh);
1612 status = encode_savefh(&xdr);
1615 status = encode_open(&xdr, args);
1618 status = encode_getfh(&xdr);
1621 status = encode_getfattr(&xdr, args->bitmask);
1624 status = encode_restorefh(&xdr);
1627 status = encode_getfattr(&xdr, args->bitmask);
1633 * Encode an OPEN_CONFIRM request
1635 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1637 struct xdr_stream xdr;
1638 struct compound_hdr hdr = {
1643 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1644 encode_compound_hdr(&xdr, &hdr);
1645 status = encode_putfh(&xdr, args->fh);
1648 status = encode_open_confirm(&xdr, args);
1654 * Encode an OPEN request with no attributes.
1656 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1658 struct xdr_stream xdr;
1659 struct compound_hdr hdr = {
1664 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1665 encode_compound_hdr(&xdr, &hdr);
1666 status = encode_putfh(&xdr, args->fh);
1669 status = encode_open(&xdr, args);
1672 status = encode_getfattr(&xdr, args->bitmask);
1678 * Encode an OPEN_DOWNGRADE request
1680 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1682 struct xdr_stream xdr;
1683 struct compound_hdr hdr = {
1688 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1689 encode_compound_hdr(&xdr, &hdr);
1690 status = encode_putfh(&xdr, args->fh);
1693 status = encode_open_downgrade(&xdr, args);
1696 status = encode_getfattr(&xdr, args->bitmask);
1702 * Encode a LOCK request
1704 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1706 struct xdr_stream xdr;
1707 struct compound_hdr hdr = {
1712 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1713 encode_compound_hdr(&xdr, &hdr);
1714 status = encode_putfh(&xdr, args->fh);
1717 status = encode_lock(&xdr, args);
1723 * Encode a LOCKT request
1725 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1727 struct xdr_stream xdr;
1728 struct compound_hdr hdr = {
1733 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1734 encode_compound_hdr(&xdr, &hdr);
1735 status = encode_putfh(&xdr, args->fh);
1738 status = encode_lockt(&xdr, args);
1744 * Encode a LOCKU request
1746 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1748 struct xdr_stream xdr;
1749 struct compound_hdr hdr = {
1754 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1755 encode_compound_hdr(&xdr, &hdr);
1756 status = encode_putfh(&xdr, args->fh);
1759 status = encode_locku(&xdr, args);
1765 * Encode a READLINK request
1767 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1769 struct xdr_stream xdr;
1770 struct compound_hdr hdr = {
1773 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1774 unsigned int replen;
1777 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1778 encode_compound_hdr(&xdr, &hdr);
1779 status = encode_putfh(&xdr, args->fh);
1782 status = encode_readlink(&xdr, args, req);
1784 /* set up reply kvec
1785 * toplevel_status + taglen + rescount + OP_PUTFH + status
1786 * + OP_READLINK + status + string length = 8
1788 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readlink_sz) << 2;
1789 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1790 args->pgbase, args->pglen);
1797 * Encode a READDIR request
1799 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1801 struct xdr_stream xdr;
1802 struct compound_hdr hdr = {
1805 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1809 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1810 encode_compound_hdr(&xdr, &hdr);
1811 status = encode_putfh(&xdr, args->fh);
1814 status = encode_readdir(&xdr, args, req);
1816 /* set up reply kvec
1817 * toplevel_status + taglen + rescount + OP_PUTFH + status
1818 * + OP_READDIR + status + verifer(2) = 9
1820 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readdir_sz) << 2;
1821 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1822 args->pgbase, args->count);
1823 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1824 __FUNCTION__, replen, args->pages,
1825 args->pgbase, args->count);
1832 * Encode a READ request
1834 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1836 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1837 struct xdr_stream xdr;
1838 struct compound_hdr hdr = {
1843 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1844 encode_compound_hdr(&xdr, &hdr);
1845 status = encode_putfh(&xdr, args->fh);
1848 status = encode_read(&xdr, args);
1852 /* set up reply kvec
1853 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1854 * + OP_READ + status + eof + datalen = 9
1856 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1857 xdr_inline_pages(&req->rq_rcv_buf, replen,
1858 args->pages, args->pgbase, args->count);
1864 * Encode an SETATTR request
1866 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1869 struct xdr_stream xdr;
1870 struct compound_hdr hdr = {
1875 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1876 encode_compound_hdr(&xdr, &hdr);
1877 status = encode_putfh(&xdr, args->fh);
1880 status = encode_setattr(&xdr, args, args->server);
1883 status = encode_getfattr(&xdr, args->bitmask);
1889 * Encode a GETACL request
1892 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1893 struct nfs_getaclargs *args)
1895 struct xdr_stream xdr;
1896 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1897 struct compound_hdr hdr = {
1902 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1903 encode_compound_hdr(&xdr, &hdr);
1904 status = encode_putfh(&xdr, args->fh);
1907 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1908 /* set up reply buffer: */
1909 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1910 xdr_inline_pages(&req->rq_rcv_buf, replen,
1911 args->acl_pages, args->acl_pgbase, args->acl_len);
1917 * Encode a WRITE request
1919 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1921 struct xdr_stream xdr;
1922 struct compound_hdr hdr = {
1927 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1928 encode_compound_hdr(&xdr, &hdr);
1929 status = encode_putfh(&xdr, args->fh);
1932 status = encode_write(&xdr, args);
1935 status = encode_getfattr(&xdr, args->bitmask);
1943 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1945 struct xdr_stream xdr;
1946 struct compound_hdr hdr = {
1951 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1952 encode_compound_hdr(&xdr, &hdr);
1953 status = encode_putfh(&xdr, args->fh);
1956 status = encode_commit(&xdr, args);
1959 status = encode_getfattr(&xdr, args->bitmask);
1967 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1969 struct xdr_stream xdr;
1970 struct compound_hdr hdr = {
1975 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1976 encode_compound_hdr(&xdr, &hdr);
1977 status = encode_putfh(&xdr, args->fh);
1979 status = encode_fsinfo(&xdr, args->bitmask);
1984 * a PATHCONF request
1986 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1988 struct xdr_stream xdr;
1989 struct compound_hdr hdr = {
1994 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1995 encode_compound_hdr(&xdr, &hdr);
1996 status = encode_putfh(&xdr, args->fh);
1998 status = encode_getattr_one(&xdr,
1999 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
2006 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
2008 struct xdr_stream xdr;
2009 struct compound_hdr hdr = {
2014 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2015 encode_compound_hdr(&xdr, &hdr);
2016 status = encode_putfh(&xdr, args->fh);
2018 status = encode_getattr_two(&xdr,
2019 args->bitmask[0] & nfs4_statfs_bitmap[0],
2020 args->bitmask[1] & nfs4_statfs_bitmap[1]);
2025 * GETATTR_BITMAP request
2027 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
2029 struct xdr_stream xdr;
2030 struct compound_hdr hdr = {
2035 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2036 encode_compound_hdr(&xdr, &hdr);
2037 status = encode_putfh(&xdr, fhandle);
2039 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2040 FATTR4_WORD0_LINK_SUPPORT|
2041 FATTR4_WORD0_SYMLINK_SUPPORT|
2042 FATTR4_WORD0_ACLSUPPORT);
2049 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2051 struct xdr_stream xdr;
2052 struct compound_hdr hdr = {
2056 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2057 encode_compound_hdr(&xdr, &hdr);
2058 return encode_renew(&xdr, clp);
2062 * a SETCLIENTID request
2064 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
2066 struct xdr_stream xdr;
2067 struct compound_hdr hdr = {
2071 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2072 encode_compound_hdr(&xdr, &hdr);
2073 return encode_setclientid(&xdr, sc);
2077 * a SETCLIENTID_CONFIRM request
2079 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2081 struct xdr_stream xdr;
2082 struct compound_hdr hdr = {
2085 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2088 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2089 encode_compound_hdr(&xdr, &hdr);
2090 status = encode_setclientid_confirm(&xdr, clp);
2092 status = encode_putrootfh(&xdr);
2094 status = encode_fsinfo(&xdr, lease_bitmap);
2099 * DELEGRETURN request
2101 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2103 struct xdr_stream xdr;
2104 struct compound_hdr hdr = {
2109 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2110 encode_compound_hdr(&xdr, &hdr);
2111 status = encode_putfh(&xdr, args->fhandle);
2114 status = encode_delegreturn(&xdr, args->stateid);
2117 status = encode_getfattr(&xdr, args->bitmask);
2123 * Encode FS_LOCATIONS request
2125 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2127 struct xdr_stream xdr;
2128 struct compound_hdr hdr = {
2131 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
2135 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2136 encode_compound_hdr(&xdr, &hdr);
2137 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2139 if ((status = encode_lookup(&xdr, args->name)) != 0)
2141 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
2144 * toplevel_status + OP_PUTFH + status
2145 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2147 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2148 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2155 * START OF "GENERIC" DECODE ROUTINES.
2156 * These may look a little ugly since they are imported from a "generic"
2157 * set of XDR encode/decode routines which are intended to be shared by
2158 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2160 * If the pain of reading these is too great, it should be a straightforward
2161 * task to translate them into Linux-specific versions which are more
2162 * consistent with the style used in NFSv2/v3...
2164 #define READ32(x) (x) = ntohl(*p++)
2165 #define READ64(x) do { \
2166 (x) = (u64)ntohl(*p++) << 32; \
2167 (x) |= ntohl(*p++); \
2169 #define READTIME(x) do { \
2171 (x.tv_sec) = ntohl(*p++); \
2172 (x.tv_nsec) = ntohl(*p++); \
2174 #define COPYMEM(x,nbytes) do { \
2175 memcpy((x), p, nbytes); \
2176 p += XDR_QUADLEN(nbytes); \
2179 #define READ_BUF(nbytes) do { \
2180 p = xdr_inline_decode(xdr, nbytes); \
2181 if (unlikely(!p)) { \
2182 dprintk("nfs: %s: prematurely hit end of receive" \
2183 " buffer\n", __FUNCTION__); \
2184 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2185 __FUNCTION__, xdr->p, nbytes, xdr->end); \
2190 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2197 *string = (char *)p;
2201 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2206 READ32(hdr->status);
2207 READ32(hdr->taglen);
2209 READ_BUF(hdr->taglen + 4);
2210 hdr->tag = (char *)p;
2211 p += XDR_QUADLEN(hdr->taglen);
2216 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2224 if (opnum != expected) {
2225 dprintk("nfs: Server returned operation"
2226 " %d but we issued a request for %d\n",
2231 if (nfserr != NFS_OK)
2232 return -nfs4_stat_to_errno(nfserr);
2237 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2240 unsigned int strlen;
2244 return decode_opaque_inline(xdr, &strlen, &str);
2247 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2255 bitmap[0] = bitmap[1] = 0;
2256 READ_BUF((bmlen << 2));
2265 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2275 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2277 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2278 decode_attr_bitmap(xdr, bitmask);
2279 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2281 bitmask[0] = bitmask[1] = 0;
2282 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2286 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2291 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2293 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2296 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2297 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2300 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2302 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2306 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2311 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2313 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2316 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2318 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2319 (unsigned long long)*change);
2323 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2328 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2330 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2333 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2335 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2339 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2344 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2346 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2349 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2351 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2355 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2360 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2362 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2365 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2367 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2371 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2377 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2379 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2381 READ64(fsid->major);
2382 READ64(fsid->minor);
2383 bitmap[0] &= ~FATTR4_WORD0_FSID;
2385 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2386 (unsigned long long)fsid->major,
2387 (unsigned long long)fsid->minor);
2391 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2396 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2398 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2401 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2403 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2407 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2411 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2412 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2414 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2417 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2419 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2423 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2428 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2430 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2433 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2435 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2439 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2444 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2446 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2449 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2451 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2455 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2461 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2463 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2466 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2468 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2472 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2478 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2480 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2483 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2485 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2489 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2495 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2497 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2500 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2502 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2506 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2519 path->ncomponents = 0;
2520 while (path->ncomponents < n) {
2521 struct nfs4_string *component = &path->components[path->ncomponents];
2522 status = decode_opaque_inline(xdr, &component->len, &component->data);
2523 if (unlikely(status != 0))
2525 if (path->ncomponents != n)
2527 dprintk("%s", component->data);
2528 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2529 path->ncomponents++;
2531 dprintk("cannot parse %d components in path\n", n);
2539 /* a root pathname is sent as a zero component4 */
2540 path->ncomponents = 1;
2541 path->components[0].len=0;
2542 path->components[0].data=NULL;
2543 dprintk("path /\n");
2546 dprintk(" status %d", status);
2551 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2557 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2560 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2562 dprintk("%s: fsroot ", __FUNCTION__);
2563 status = decode_pathname(xdr, &res->fs_path);
2564 if (unlikely(status != 0))
2570 res->nlocations = 0;
2571 while (res->nlocations < n) {
2573 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2581 dprintk("%s: servers ", __FUNCTION__);
2582 while (loc->nservers < m) {
2583 struct nfs4_string *server = &loc->servers[loc->nservers];
2584 status = decode_opaque_inline(xdr, &server->len, &server->data);
2585 if (unlikely(status != 0))
2587 dprintk("%s ", server->data);
2588 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2592 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2593 for (i = loc->nservers; i < m; i++) {
2596 status = decode_opaque_inline(xdr, &len, &data);
2597 if (unlikely(status != 0))
2602 status = decode_pathname(xdr, &loc->rootpath);
2603 if (unlikely(status != 0))
2605 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2609 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2616 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2622 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2624 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2627 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2629 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2633 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2639 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2641 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2644 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2646 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2650 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2656 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2658 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2661 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2663 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2667 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2673 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2675 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2679 if (maxread > 0x7FFFFFFF)
2680 maxread = 0x7FFFFFFF;
2681 *res = (uint32_t)maxread;
2682 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2684 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2688 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2694 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2696 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2700 if (maxwrite > 0x7FFFFFFF)
2701 maxwrite = 0x7FFFFFFF;
2702 *res = (uint32_t)maxwrite;
2703 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2705 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2709 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2714 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2716 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2720 bitmap[1] &= ~FATTR4_WORD1_MODE;
2722 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2726 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2731 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2733 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2736 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2738 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2742 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2748 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2750 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2754 if (len < XDR_MAX_NETOBJ) {
2755 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2756 dprintk("%s: nfs_map_name_to_uid failed!\n",
2759 dprintk("%s: name too long (%u)!\n",
2761 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2763 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2767 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2773 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2775 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2779 if (len < XDR_MAX_NETOBJ) {
2780 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2781 dprintk("%s: nfs_map_group_to_gid failed!\n",
2784 dprintk("%s: name too long (%u)!\n",
2786 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2788 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2792 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2794 uint32_t major = 0, minor = 0;
2798 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2800 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2806 tmp = MKDEV(major, minor);
2807 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2809 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2811 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2815 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2821 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2823 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2826 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2828 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2832 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2838 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2840 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2843 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2845 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2849 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2855 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2857 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2860 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2862 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2866 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2871 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2873 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2876 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2878 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2879 (unsigned long long)*used);
2883 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2892 time->tv_sec = (time_t)sec;
2893 time->tv_nsec = (long)nsec;
2897 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2903 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2905 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2906 status = decode_attr_time(xdr, time);
2907 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2909 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2913 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2919 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2921 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2922 status = decode_attr_time(xdr, time);
2923 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2925 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2929 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2935 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2937 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2938 status = decode_attr_time(xdr, time);
2939 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2941 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2945 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2947 unsigned int attrwords = XDR_QUADLEN(attrlen);
2948 unsigned int nwords = xdr->p - savep;
2950 if (unlikely(attrwords != nwords)) {
2951 dprintk("%s: server returned incorrect attribute length: "
2955 (attrwords < nwords) ? '<' : '>',
2962 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2967 READ32(cinfo->atomic);
2968 READ64(cinfo->before);
2969 READ64(cinfo->after);
2973 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2979 status = decode_op_hdr(xdr, OP_ACCESS);
2985 access->supported = supp;
2986 access->access = acc;
2990 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2995 status = decode_op_hdr(xdr, OP_CLOSE);
2998 READ_BUF(NFS4_STATEID_SIZE);
2999 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3003 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3008 status = decode_op_hdr(xdr, OP_COMMIT);
3012 COPYMEM(res->verf->verifier, 8);
3016 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3022 status = decode_op_hdr(xdr, OP_CREATE);
3025 if ((status = decode_change_info(xdr, cinfo)))
3029 READ_BUF(bmlen << 2);
3033 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3040 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3042 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3044 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3046 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3048 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3050 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3052 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3054 status = verify_attr_len(xdr, savep, attrlen);
3056 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3060 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3067 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3069 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3071 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3074 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3076 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3078 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3080 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3082 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3084 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3087 status = verify_attr_len(xdr, savep, attrlen);
3089 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3093 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3100 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3102 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3104 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3107 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3109 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3112 status = verify_attr_len(xdr, savep, attrlen);
3114 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3118 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3124 int status, fmode = 0;
3127 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3129 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3132 fattr->bitmap[0] = bitmap[0];
3133 fattr->bitmap[1] = bitmap[1];
3135 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3139 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3141 fattr->type = nfs_type2fmt[type].nfs2type;
3142 fmode = nfs_type2fmt[type].mode;
3144 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3146 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3148 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
3150 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3152 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3153 struct nfs4_fs_locations,
3156 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3158 fattr->mode |= fmode;
3159 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3161 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
3163 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
3165 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3167 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3169 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3171 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3173 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3175 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3177 if (fattr->fileid == 0 && fileid != 0)
3178 fattr->fileid = fileid;
3179 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
3180 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
3182 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
3187 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3190 uint32_t attrlen, bitmap[2];
3193 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3195 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3197 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3200 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3202 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3204 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3206 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3208 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3209 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3211 fsinfo->wtpref = fsinfo->wtmax;
3213 status = verify_attr_len(xdr, savep, attrlen);
3215 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
3219 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3225 /* Zero handle first to allow comparisons */
3226 memset(fh, 0, sizeof(*fh));
3228 status = decode_op_hdr(xdr, OP_GETFH);
3234 if (len > NFS4_FHSIZE)
3238 COPYMEM(fh->data, len);
3242 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3246 status = decode_op_hdr(xdr, OP_LINK);
3249 return decode_change_info(xdr, cinfo);
3253 * We create the owner, so we know a proper owner.id length is 4.
3255 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3257 uint64_t offset, length, clientid;
3259 uint32_t namelen, type;
3266 fl->fl_start = (loff_t)offset;
3267 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3268 if (length == ~(uint64_t)0)
3269 fl->fl_end = OFFSET_MAX;
3270 fl->fl_type = F_WRLCK;
3272 fl->fl_type = F_RDLCK;
3278 return -NFS4ERR_DENIED;
3281 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3286 status = decode_op_hdr(xdr, OP_LOCK);
3288 READ_BUF(NFS4_STATEID_SIZE);
3289 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3290 } else if (status == -NFS4ERR_DENIED)
3291 return decode_lock_denied(xdr, NULL);
3295 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3298 status = decode_op_hdr(xdr, OP_LOCKT);
3299 if (status == -NFS4ERR_DENIED)
3300 return decode_lock_denied(xdr, res->denied);
3304 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3309 status = decode_op_hdr(xdr, OP_LOCKU);
3311 READ_BUF(NFS4_STATEID_SIZE);
3312 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3317 static int decode_lookup(struct xdr_stream *xdr)
3319 return decode_op_hdr(xdr, OP_LOOKUP);
3322 /* This is too sick! */
3323 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3326 uint32_t limit_type, nblocks, blocksize;
3330 switch (limit_type) {
3337 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3342 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3345 uint32_t delegation_type;
3348 READ32(delegation_type);
3349 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3350 res->delegation_type = 0;
3353 READ_BUF(NFS4_STATEID_SIZE+4);
3354 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3355 READ32(res->do_recall);
3356 switch (delegation_type) {
3357 case NFS4_OPEN_DELEGATE_READ:
3358 res->delegation_type = FMODE_READ;
3360 case NFS4_OPEN_DELEGATE_WRITE:
3361 res->delegation_type = FMODE_WRITE|FMODE_READ;
3362 if (decode_space_limit(xdr, &res->maxsize) < 0)
3365 return decode_ace(xdr, NULL, res->server->nfs_client);
3368 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3371 uint32_t savewords, bmlen, i;
3374 status = decode_op_hdr(xdr, OP_OPEN);
3377 READ_BUF(NFS4_STATEID_SIZE);
3378 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3380 decode_change_info(xdr, &res->cinfo);
3383 READ32(res->rflags);
3388 READ_BUF(bmlen << 2);
3389 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3390 for (i = 0; i < savewords; ++i)
3391 READ32(res->attrset[i]);
3392 for (; i < NFS4_BITMAP_SIZE; i++)
3393 res->attrset[i] = 0;
3395 return decode_delegation(xdr, res);
3397 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
3401 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3406 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3409 READ_BUF(NFS4_STATEID_SIZE);
3410 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3414 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3419 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3422 READ_BUF(NFS4_STATEID_SIZE);
3423 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3427 static int decode_putfh(struct xdr_stream *xdr)
3429 return decode_op_hdr(xdr, OP_PUTFH);
3432 static int decode_putrootfh(struct xdr_stream *xdr)
3434 return decode_op_hdr(xdr, OP_PUTROOTFH);
3437 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3439 struct kvec *iov = req->rq_rcv_buf.head;
3441 uint32_t count, eof, recvd, hdrlen;
3444 status = decode_op_hdr(xdr, OP_READ);
3450 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3451 recvd = req->rq_rcv_buf.len - hdrlen;
3452 if (count > recvd) {
3453 dprintk("NFS: server cheating in read reply: "
3454 "count %u > recvd %u\n", count, recvd);
3458 xdr_read_pages(xdr, count);
3464 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3466 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3467 struct page *page = *rcvbuf->pages;
3468 struct kvec *iov = rcvbuf->head;
3469 unsigned int nr, pglen = rcvbuf->page_len;
3470 __be32 *end, *entry, *p, *kaddr;
3471 uint32_t len, attrlen, xlen;
3472 int hdrlen, recvd, status;
3474 status = decode_op_hdr(xdr, OP_READDIR);
3478 COPYMEM(readdir->verifier.data, 8);
3479 dprintk("%s: verifier = 0x%x%x\n",
3481 ((u32 *)readdir->verifier.data)[0],
3482 ((u32 *)readdir->verifier.data)[1]);
3485 hdrlen = (char *) p - (char *) iov->iov_base;
3486 recvd = rcvbuf->len - hdrlen;
3489 xdr_read_pages(xdr, pglen);
3491 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3492 kaddr = p = kmap_atomic(page, KM_USER0);
3493 end = p + ((pglen + readdir->pgbase) >> 2);
3495 for (nr = 0; *p++; nr++) {
3498 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3499 p += 2; /* cookie */
3500 len = ntohl(*p++); /* filename length */
3501 if (len > NFS4_MAXNAMLEN) {
3502 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
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 dprintk("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("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 dprintk("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 dprintk("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) {
3691 dprintk("nfs: decode_setclientid: Server returned operation"
3696 if (nfserr == NFS_OK) {
3697 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3698 READ64(clp->cl_clientid);
3699 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3700 } else if (nfserr == NFSERR_CLID_INUSE) {
3703 /* skip netid string */
3708 /* skip uaddr string */
3712 return -NFSERR_CLID_INUSE;
3714 return -nfs4_stat_to_errno(nfserr);
3719 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3721 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3724 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3729 status = decode_op_hdr(xdr, OP_WRITE);
3735 READ32(res->verf->committed);
3736 COPYMEM(res->verf->verifier, 8);
3740 static int decode_delegreturn(struct xdr_stream *xdr)
3742 return decode_op_hdr(xdr, OP_DELEGRETURN);
3746 * Decode OPEN_DOWNGRADE response
3748 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3750 struct xdr_stream xdr;
3751 struct compound_hdr hdr;
3754 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3755 status = decode_compound_hdr(&xdr, &hdr);
3758 status = decode_putfh(&xdr);
3761 status = decode_open_downgrade(&xdr, res);
3764 decode_getfattr(&xdr, res->fattr, res->server);
3770 * END OF "GENERIC" DECODE ROUTINES.
3774 * Decode ACCESS response
3776 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3778 struct xdr_stream xdr;
3779 struct compound_hdr hdr;
3782 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3783 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3785 if ((status = decode_putfh(&xdr)) == 0)
3786 status = decode_access(&xdr, res);
3792 * Decode LOOKUP response
3794 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3796 struct xdr_stream xdr;
3797 struct compound_hdr hdr;
3800 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3801 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3803 if ((status = decode_putfh(&xdr)) != 0)
3805 if ((status = decode_lookup(&xdr)) != 0)
3807 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3809 status = decode_getfattr(&xdr, res->fattr, res->server);
3815 * Decode LOOKUP_ROOT response
3817 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3819 struct xdr_stream xdr;
3820 struct compound_hdr hdr;
3823 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3824 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3826 if ((status = decode_putrootfh(&xdr)) != 0)
3828 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3829 status = decode_getfattr(&xdr, res->fattr, res->server);
3835 * Decode REMOVE response
3837 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
3839 struct xdr_stream xdr;
3840 struct compound_hdr hdr;
3843 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3844 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3846 if ((status = decode_putfh(&xdr)) != 0)
3848 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3850 decode_getfattr(&xdr, &res->dir_attr, res->server);
3856 * Decode RENAME response
3858 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3860 struct xdr_stream xdr;
3861 struct compound_hdr hdr;
3864 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3865 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3867 if ((status = decode_putfh(&xdr)) != 0)
3869 if ((status = decode_savefh(&xdr)) != 0)
3871 if ((status = decode_putfh(&xdr)) != 0)
3873 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3875 /* Current FH is target directory */
3876 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3878 if ((status = decode_restorefh(&xdr)) != 0)
3880 decode_getfattr(&xdr, res->old_fattr, res->server);
3886 * Decode LINK response
3888 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3890 struct xdr_stream xdr;
3891 struct compound_hdr hdr;
3894 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3895 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3897 if ((status = decode_putfh(&xdr)) != 0)
3899 if ((status = decode_savefh(&xdr)) != 0)
3901 if ((status = decode_putfh(&xdr)) != 0)
3903 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3906 * Note order: OP_LINK leaves the directory as the current
3909 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3911 if ((status = decode_restorefh(&xdr)) != 0)
3913 decode_getfattr(&xdr, res->fattr, res->server);
3919 * Decode CREATE response
3921 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3923 struct xdr_stream xdr;
3924 struct compound_hdr hdr;
3927 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3928 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3930 if ((status = decode_putfh(&xdr)) != 0)
3932 if ((status = decode_savefh(&xdr)) != 0)
3934 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3936 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3938 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3940 if ((status = decode_restorefh(&xdr)) != 0)
3942 decode_getfattr(&xdr, res->dir_fattr, res->server);
3948 * Decode SYMLINK response
3950 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3952 return nfs4_xdr_dec_create(rqstp, p, res);
3956 * Decode GETATTR response
3958 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3960 struct xdr_stream xdr;
3961 struct compound_hdr hdr;
3964 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3965 status = decode_compound_hdr(&xdr, &hdr);
3968 status = decode_putfh(&xdr);
3971 status = decode_getfattr(&xdr, res->fattr, res->server);
3978 * Encode an SETACL request
3981 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3983 struct xdr_stream xdr;
3984 struct compound_hdr hdr = {
3989 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3990 encode_compound_hdr(&xdr, &hdr);
3991 status = encode_putfh(&xdr, args->fh);
3994 status = encode_setacl(&xdr, args);
3999 * Decode SETACL response
4002 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
4004 struct xdr_stream xdr;
4005 struct compound_hdr hdr;
4008 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4009 status = decode_compound_hdr(&xdr, &hdr);
4012 status = decode_putfh(&xdr);
4015 status = decode_setattr(&xdr, res);
4021 * Decode GETACL response
4024 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
4026 struct xdr_stream xdr;
4027 struct compound_hdr hdr;
4030 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4031 status = decode_compound_hdr(&xdr, &hdr);
4034 status = decode_putfh(&xdr);
4037 status = decode_getacl(&xdr, rqstp, acl_len);
4044 * Decode CLOSE response
4046 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4048 struct xdr_stream xdr;
4049 struct compound_hdr hdr;
4052 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4053 status = decode_compound_hdr(&xdr, &hdr);
4056 status = decode_putfh(&xdr);
4059 status = decode_close(&xdr, res);
4063 * Note: Server may do delete on close for this file
4064 * in which case the getattr call will fail with
4065 * an ESTALE error. Shouldn't be a problem,
4066 * though, since fattr->valid will remain unset.
4068 decode_getfattr(&xdr, res->fattr, res->server);
4074 * Decode OPEN response
4076 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4078 struct xdr_stream xdr;
4079 struct compound_hdr hdr;
4082 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4083 status = decode_compound_hdr(&xdr, &hdr);
4086 status = decode_putfh(&xdr);
4089 status = decode_savefh(&xdr);
4092 status = decode_open(&xdr, res);
4095 if (decode_getfh(&xdr, &res->fh) != 0)
4097 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4099 if (decode_restorefh(&xdr) != 0)
4101 decode_getfattr(&xdr, res->dir_attr, res->server);
4107 * Decode OPEN_CONFIRM response
4109 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4111 struct xdr_stream xdr;
4112 struct compound_hdr hdr;
4115 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4116 status = decode_compound_hdr(&xdr, &hdr);
4119 status = decode_putfh(&xdr);
4122 status = decode_open_confirm(&xdr, res);
4128 * Decode OPEN response
4130 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4132 struct xdr_stream xdr;
4133 struct compound_hdr hdr;
4136 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4137 status = decode_compound_hdr(&xdr, &hdr);
4140 status = decode_putfh(&xdr);
4143 status = decode_open(&xdr, res);
4146 decode_getfattr(&xdr, res->f_attr, res->server);
4152 * Decode SETATTR response
4154 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4156 struct xdr_stream xdr;
4157 struct compound_hdr hdr;
4160 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4161 status = decode_compound_hdr(&xdr, &hdr);
4164 status = decode_putfh(&xdr);
4167 status = decode_setattr(&xdr, res);
4170 status = decode_getfattr(&xdr, res->fattr, res->server);
4171 if (status == NFS4ERR_DELAY)
4178 * Decode LOCK response
4180 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4182 struct xdr_stream xdr;
4183 struct compound_hdr hdr;
4186 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4187 status = decode_compound_hdr(&xdr, &hdr);
4190 status = decode_putfh(&xdr);
4193 status = decode_lock(&xdr, res);
4199 * Decode LOCKT response
4201 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4203 struct xdr_stream xdr;
4204 struct compound_hdr hdr;
4207 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4208 status = decode_compound_hdr(&xdr, &hdr);
4211 status = decode_putfh(&xdr);
4214 status = decode_lockt(&xdr, res);
4220 * Decode LOCKU response
4222 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4224 struct xdr_stream xdr;
4225 struct compound_hdr hdr;
4228 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4229 status = decode_compound_hdr(&xdr, &hdr);
4232 status = decode_putfh(&xdr);
4235 status = decode_locku(&xdr, res);
4241 * Decode READLINK response
4243 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
4245 struct xdr_stream xdr;
4246 struct compound_hdr hdr;
4249 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4250 status = decode_compound_hdr(&xdr, &hdr);
4253 status = decode_putfh(&xdr);
4256 status = decode_readlink(&xdr, rqstp);
4262 * Decode READDIR response
4264 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4266 struct xdr_stream xdr;
4267 struct compound_hdr hdr;
4270 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4271 status = decode_compound_hdr(&xdr, &hdr);
4274 status = decode_putfh(&xdr);
4277 status = decode_readdir(&xdr, rqstp, res);
4283 * Decode Read response
4285 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4287 struct xdr_stream xdr;
4288 struct compound_hdr hdr;
4291 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4292 status = decode_compound_hdr(&xdr, &hdr);
4295 status = decode_putfh(&xdr);
4298 status = decode_read(&xdr, rqstp, res);
4300 status = res->count;
4306 * Decode WRITE response
4308 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4310 struct xdr_stream xdr;
4311 struct compound_hdr hdr;
4314 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4315 status = decode_compound_hdr(&xdr, &hdr);
4318 status = decode_putfh(&xdr);
4321 status = decode_write(&xdr, res);
4324 decode_getfattr(&xdr, res->fattr, res->server);
4326 status = res->count;
4332 * Decode COMMIT response
4334 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4336 struct xdr_stream xdr;
4337 struct compound_hdr hdr;
4340 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4341 status = decode_compound_hdr(&xdr, &hdr);
4344 status = decode_putfh(&xdr);
4347 status = decode_commit(&xdr, res);
4350 decode_getfattr(&xdr, res->fattr, res->server);
4358 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4360 struct xdr_stream xdr;
4361 struct compound_hdr hdr;
4364 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4365 status = decode_compound_hdr(&xdr, &hdr);
4367 status = decode_putfh(&xdr);
4369 status = decode_fsinfo(&xdr, fsinfo);
4371 status = -nfs4_stat_to_errno(hdr.status);
4378 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
4380 struct xdr_stream xdr;
4381 struct compound_hdr hdr;
4384 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4385 status = decode_compound_hdr(&xdr, &hdr);
4387 status = decode_putfh(&xdr);
4389 status = decode_pathconf(&xdr, pathconf);
4396 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
4398 struct xdr_stream xdr;
4399 struct compound_hdr hdr;
4402 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4403 status = decode_compound_hdr(&xdr, &hdr);
4405 status = decode_putfh(&xdr);
4407 status = decode_statfs(&xdr, fsstat);
4412 * GETATTR_BITMAP request
4414 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4416 struct xdr_stream xdr;
4417 struct compound_hdr hdr;
4420 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4421 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4423 if ((status = decode_putfh(&xdr)) != 0)
4425 status = decode_server_caps(&xdr, res);
4431 * Decode RENEW response
4433 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4435 struct xdr_stream xdr;
4436 struct compound_hdr hdr;
4439 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4440 status = decode_compound_hdr(&xdr, &hdr);
4442 status = decode_renew(&xdr);
4447 * a SETCLIENTID request
4449 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4450 struct nfs_client *clp)
4452 struct xdr_stream xdr;
4453 struct compound_hdr hdr;
4456 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4457 status = decode_compound_hdr(&xdr, &hdr);
4459 status = decode_setclientid(&xdr, clp);
4461 status = -nfs4_stat_to_errno(hdr.status);
4466 * a SETCLIENTID_CONFIRM request
4468 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4470 struct xdr_stream xdr;
4471 struct compound_hdr hdr;
4474 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4475 status = decode_compound_hdr(&xdr, &hdr);
4477 status = decode_setclientid_confirm(&xdr);
4479 status = decode_putrootfh(&xdr);
4481 status = decode_fsinfo(&xdr, fsinfo);
4483 status = -nfs4_stat_to_errno(hdr.status);
4488 * DELEGRETURN request
4490 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4492 struct xdr_stream xdr;
4493 struct compound_hdr hdr;
4496 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4497 status = decode_compound_hdr(&xdr, &hdr);
4500 status = decode_putfh(&xdr);
4503 status = decode_delegreturn(&xdr);
4504 decode_getfattr(&xdr, res->fattr, res->server);
4510 * FS_LOCATIONS request
4512 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
4514 struct xdr_stream xdr;
4515 struct compound_hdr hdr;
4518 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4519 status = decode_compound_hdr(&xdr, &hdr);
4522 if ((status = decode_putfh(&xdr)) != 0)
4524 if ((status = decode_lookup(&xdr)) != 0)
4526 xdr_enter_page(&xdr, PAGE_SIZE);
4527 status = decode_getfattr(&xdr, &res->fattr, res->server);
4532 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4534 uint32_t bitmap[2] = {0};
4539 return ERR_PTR(-EAGAIN);
4541 return ERR_PTR(-EBADCOOKIE);
4544 entry->prev_cookie = entry->cookie;
4545 p = xdr_decode_hyper(p, &entry->cookie);
4546 entry->len = ntohl(*p++);
4547 entry->name = (const char *) p;
4548 p += XDR_QUADLEN(entry->len);
4551 * In case the server doesn't return an inode number,
4552 * we fake one here. (We don't use inode number 0,
4553 * since glibc seems to choke on it...)
4557 len = ntohl(*p++); /* bitmap length */
4559 bitmap[0] = ntohl(*p++);
4561 bitmap[1] = ntohl(*p++);
4565 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4567 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4568 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4569 /* Ignore the return value of rdattr_error for now */
4573 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4574 xdr_decode_hyper(p, &entry->ino);
4575 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4576 xdr_decode_hyper(p, &entry->ino);
4580 entry->eof = !p[0] && p[1];
4585 * We need to translate between nfs status return values and
4586 * the local errno values which may not be the same.
4593 { NFS4ERR_PERM, EPERM },
4594 { NFS4ERR_NOENT, ENOENT },
4595 { NFS4ERR_IO, errno_NFSERR_IO },
4596 { NFS4ERR_NXIO, ENXIO },
4597 { NFS4ERR_ACCESS, EACCES },
4598 { NFS4ERR_EXIST, EEXIST },
4599 { NFS4ERR_XDEV, EXDEV },
4600 { NFS4ERR_NOTDIR, ENOTDIR },
4601 { NFS4ERR_ISDIR, EISDIR },
4602 { NFS4ERR_INVAL, EINVAL },
4603 { NFS4ERR_FBIG, EFBIG },
4604 { NFS4ERR_NOSPC, ENOSPC },
4605 { NFS4ERR_ROFS, EROFS },
4606 { NFS4ERR_MLINK, EMLINK },
4607 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4608 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4609 { NFS4ERR_DQUOT, EDQUOT },
4610 { NFS4ERR_STALE, ESTALE },
4611 { NFS4ERR_BADHANDLE, EBADHANDLE },
4612 { NFS4ERR_BADOWNER, EINVAL },
4613 { NFS4ERR_BADNAME, EINVAL },
4614 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4615 { NFS4ERR_NOTSUPP, ENOTSUPP },
4616 { NFS4ERR_TOOSMALL, ETOOSMALL },
4617 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4618 { NFS4ERR_BADTYPE, EBADTYPE },
4619 { NFS4ERR_LOCKED, EAGAIN },
4620 { NFS4ERR_RESOURCE, EREMOTEIO },
4621 { NFS4ERR_SYMLINK, ELOOP },
4622 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4623 { NFS4ERR_DEADLOCK, EDEADLK },
4624 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4625 * to be handled by a
4632 * Convert an NFS error code to a local one.
4633 * This one is used jointly by NFSv2 and NFSv3.
4636 nfs4_stat_to_errno(int stat)
4639 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4640 if (nfs_errtbl[i].stat == stat)
4641 return nfs_errtbl[i].errno;
4643 if (stat <= 10000 || stat > 10100) {
4644 /* The server is looney tunes. */
4645 return ESERVERFAULT;
4647 /* If we cannot translate the error, the recovery routines should
4649 * Note: remaining NFSv4 error codes have values > 10000, so should
4650 * not conflict with native Linux error codes.
4655 #define PROC(proc, argtype, restype) \
4656 [NFSPROC4_CLNT_##proc] = { \
4657 .p_proc = NFSPROC4_COMPOUND, \
4658 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4659 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4660 .p_arglen = NFS4_##argtype##_sz, \
4661 .p_replen = NFS4_##restype##_sz, \
4662 .p_statidx = NFSPROC4_CLNT_##proc, \
4666 struct rpc_procinfo nfs4_procedures[] = {
4667 PROC(READ, enc_read, dec_read),
4668 PROC(WRITE, enc_write, dec_write),
4669 PROC(COMMIT, enc_commit, dec_commit),
4670 PROC(OPEN, enc_open, dec_open),
4671 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4672 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4673 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4674 PROC(CLOSE, enc_close, dec_close),
4675 PROC(SETATTR, enc_setattr, dec_setattr),
4676 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4677 PROC(RENEW, enc_renew, dec_renew),
4678 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4679 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4680 PROC(LOCK, enc_lock, dec_lock),
4681 PROC(LOCKT, enc_lockt, dec_lockt),
4682 PROC(LOCKU, enc_locku, dec_locku),
4683 PROC(ACCESS, enc_access, dec_access),
4684 PROC(GETATTR, enc_getattr, dec_getattr),
4685 PROC(LOOKUP, enc_lookup, dec_lookup),
4686 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4687 PROC(REMOVE, enc_remove, dec_remove),
4688 PROC(RENAME, enc_rename, dec_rename),
4689 PROC(LINK, enc_link, dec_link),
4690 PROC(SYMLINK, enc_symlink, dec_symlink),
4691 PROC(CREATE, enc_create, dec_create),
4692 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4693 PROC(STATFS, enc_statfs, dec_statfs),
4694 PROC(READLINK, enc_readlink, dec_readlink),
4695 PROC(READDIR, enc_readdir, dec_readdir),
4696 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4697 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4698 PROC(GETACL, enc_getacl, dec_getacl),
4699 PROC(SETACL, enc_setacl, dec_setacl),
4700 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4703 struct rpc_version nfs_version4 = {
4705 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4706 .procs = nfs4_procedures