nfs41: use nfs4_server_caps_arg
[linux-2.6/libata-dev.git] / fs / nfs / nfs4xdr.c
blob91305861037a749352fd020ef520c22af541f722
1 /*
2 * fs/nfs/nfs4xdr.c
4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
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
14 * are met:
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>
40 #include <linux/mm.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
45 #include <linux/in.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>
54 #include "nfs4_fs.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 */
64 #ifdef DEBUG
65 #define NFS4_MAXTAGLEN 20
66 #else
67 #define NFS4_MAXTAGLEN 0
68 #endif
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 + \
85 (NFS4_FHSIZE >> 2))
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 + \
105 1 + 2 + 1 + \
106 nfs4_owner_maxsz + \
107 nfs4_group_maxsz + \
108 4 + 4)
109 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
110 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
111 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
114 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116 #define decode_renew_maxsz (op_decode_hdr_maxsz)
117 #define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
121 1 /* sc_prog */ + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
124 1) /* sc_cb_ident */
125 #define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
127 2 + \
128 1024) /* large value for CLID_INUSE */
129 #define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132 #define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
134 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
136 #define encode_share_access_maxsz \
138 #define encode_createmode_maxsz (1 + encode_attrs_maxsz)
139 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141 #define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
147 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
148 decode_ace_maxsz)
149 #define decode_change_info_maxsz (5)
150 #define decode_open_maxsz (op_decode_hdr_maxsz + \
151 decode_stateid_maxsz + \
152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
155 #define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158 #define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161 #define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165 #define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168 #define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170 #define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
174 encode_attrs_maxsz)
175 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177 #define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
185 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186 #define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188 #define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
193 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
194 nfs4_name_maxsz)
195 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
196 2 * nfs4_name_maxsz)
197 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
198 #define encode_link_maxsz (op_encode_hdr_maxsz + \
199 nfs4_name_maxsz)
200 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
201 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
202 7 + \
203 1 + encode_stateid_maxsz + 8)
204 #define decode_lock_denied_maxsz \
205 (8 + decode_lockowner_maxsz)
206 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
207 decode_lock_denied_maxsz)
208 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
209 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
210 decode_lock_denied_maxsz)
211 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
212 encode_stateid_maxsz + \
214 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
215 decode_stateid_maxsz)
216 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
217 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
218 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
219 1 + nfs4_name_maxsz + \
220 1 + \
221 nfs4_fattr_maxsz)
222 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
223 #define encode_create_maxsz (op_encode_hdr_maxsz + \
224 1 + 2 + nfs4_name_maxsz + \
225 encode_attrs_maxsz)
226 #define decode_create_maxsz (op_decode_hdr_maxsz + \
227 decode_change_info_maxsz + \
228 nfs4_fattr_bitmap_maxsz)
229 #define encode_statfs_maxsz (encode_getattr_maxsz)
230 #define decode_statfs_maxsz (decode_getattr_maxsz)
231 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
232 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
233 #define encode_getacl_maxsz (encode_getattr_maxsz)
234 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
235 nfs4_fattr_bitmap_maxsz + 1)
236 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
237 encode_stateid_maxsz + 3)
238 #define decode_setacl_maxsz (decode_setattr_maxsz)
239 #define encode_fs_locations_maxsz \
240 (encode_getattr_maxsz)
241 #define decode_fs_locations_maxsz \
243 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
244 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
245 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
246 encode_putfh_maxsz + \
247 encode_read_maxsz)
248 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
249 decode_putfh_maxsz + \
250 decode_read_maxsz)
251 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
252 encode_putfh_maxsz + \
253 encode_readlink_maxsz)
254 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
255 decode_putfh_maxsz + \
256 decode_readlink_maxsz)
257 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
258 encode_putfh_maxsz + \
259 encode_readdir_maxsz)
260 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
261 decode_putfh_maxsz + \
262 decode_readdir_maxsz)
263 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
264 encode_putfh_maxsz + \
265 encode_write_maxsz + \
266 encode_getattr_maxsz)
267 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
268 decode_putfh_maxsz + \
269 decode_write_maxsz + \
270 decode_getattr_maxsz)
271 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
272 encode_putfh_maxsz + \
273 encode_commit_maxsz + \
274 encode_getattr_maxsz)
275 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
276 decode_putfh_maxsz + \
277 decode_commit_maxsz + \
278 decode_getattr_maxsz)
279 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
280 encode_putfh_maxsz + \
281 encode_savefh_maxsz + \
282 encode_open_maxsz + \
283 encode_getfh_maxsz + \
284 encode_getattr_maxsz + \
285 encode_restorefh_maxsz + \
286 encode_getattr_maxsz)
287 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
288 decode_putfh_maxsz + \
289 decode_savefh_maxsz + \
290 decode_open_maxsz + \
291 decode_getfh_maxsz + \
292 decode_getattr_maxsz + \
293 decode_restorefh_maxsz + \
294 decode_getattr_maxsz)
295 #define NFS4_enc_open_confirm_sz \
296 (compound_encode_hdr_maxsz + \
297 encode_putfh_maxsz + \
298 encode_open_confirm_maxsz)
299 #define NFS4_dec_open_confirm_sz \
300 (compound_decode_hdr_maxsz + \
301 decode_putfh_maxsz + \
302 decode_open_confirm_maxsz)
303 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
304 encode_putfh_maxsz + \
305 encode_open_maxsz + \
306 encode_getattr_maxsz)
307 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
308 decode_putfh_maxsz + \
309 decode_open_maxsz + \
310 decode_getattr_maxsz)
311 #define NFS4_enc_open_downgrade_sz \
312 (compound_encode_hdr_maxsz + \
313 encode_putfh_maxsz + \
314 encode_open_downgrade_maxsz + \
315 encode_getattr_maxsz)
316 #define NFS4_dec_open_downgrade_sz \
317 (compound_decode_hdr_maxsz + \
318 decode_putfh_maxsz + \
319 decode_open_downgrade_maxsz + \
320 decode_getattr_maxsz)
321 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
322 encode_putfh_maxsz + \
323 encode_close_maxsz + \
324 encode_getattr_maxsz)
325 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
326 decode_putfh_maxsz + \
327 decode_close_maxsz + \
328 decode_getattr_maxsz)
329 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
330 encode_putfh_maxsz + \
331 encode_setattr_maxsz + \
332 encode_getattr_maxsz)
333 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
334 decode_putfh_maxsz + \
335 decode_setattr_maxsz + \
336 decode_getattr_maxsz)
337 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
338 encode_putfh_maxsz + \
339 encode_fsinfo_maxsz)
340 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
341 decode_putfh_maxsz + \
342 decode_fsinfo_maxsz)
343 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
344 encode_renew_maxsz)
345 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
346 decode_renew_maxsz)
347 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
348 encode_setclientid_maxsz)
349 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
350 decode_setclientid_maxsz)
351 #define NFS4_enc_setclientid_confirm_sz \
352 (compound_encode_hdr_maxsz + \
353 encode_setclientid_confirm_maxsz + \
354 encode_putrootfh_maxsz + \
355 encode_fsinfo_maxsz)
356 #define NFS4_dec_setclientid_confirm_sz \
357 (compound_decode_hdr_maxsz + \
358 decode_setclientid_confirm_maxsz + \
359 decode_putrootfh_maxsz + \
360 decode_fsinfo_maxsz)
361 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
362 encode_putfh_maxsz + \
363 encode_lock_maxsz)
364 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
365 decode_putfh_maxsz + \
366 decode_lock_maxsz)
367 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
368 encode_putfh_maxsz + \
369 encode_lockt_maxsz)
370 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
371 decode_putfh_maxsz + \
372 decode_lockt_maxsz)
373 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
374 encode_putfh_maxsz + \
375 encode_locku_maxsz)
376 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
377 decode_putfh_maxsz + \
378 decode_locku_maxsz)
379 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
380 encode_putfh_maxsz + \
381 encode_access_maxsz + \
382 encode_getattr_maxsz)
383 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
384 decode_putfh_maxsz + \
385 decode_access_maxsz + \
386 decode_getattr_maxsz)
387 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
388 encode_putfh_maxsz + \
389 encode_getattr_maxsz)
390 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
391 decode_putfh_maxsz + \
392 decode_getattr_maxsz)
393 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
394 encode_putfh_maxsz + \
395 encode_lookup_maxsz + \
396 encode_getattr_maxsz + \
397 encode_getfh_maxsz)
398 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
399 decode_putfh_maxsz + \
400 decode_lookup_maxsz + \
401 decode_getattr_maxsz + \
402 decode_getfh_maxsz)
403 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
404 encode_putrootfh_maxsz + \
405 encode_getattr_maxsz + \
406 encode_getfh_maxsz)
407 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
408 decode_putrootfh_maxsz + \
409 decode_getattr_maxsz + \
410 decode_getfh_maxsz)
411 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
412 encode_putfh_maxsz + \
413 encode_remove_maxsz + \
414 encode_getattr_maxsz)
415 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
416 decode_putfh_maxsz + \
417 op_decode_hdr_maxsz + 5 + \
418 decode_getattr_maxsz)
419 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
420 encode_putfh_maxsz + \
421 encode_savefh_maxsz + \
422 encode_putfh_maxsz + \
423 encode_rename_maxsz + \
424 encode_getattr_maxsz + \
425 encode_restorefh_maxsz + \
426 encode_getattr_maxsz)
427 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
428 decode_putfh_maxsz + \
429 decode_savefh_maxsz + \
430 decode_putfh_maxsz + \
431 decode_rename_maxsz + \
432 decode_getattr_maxsz + \
433 decode_restorefh_maxsz + \
434 decode_getattr_maxsz)
435 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
436 encode_putfh_maxsz + \
437 encode_savefh_maxsz + \
438 encode_putfh_maxsz + \
439 encode_link_maxsz + \
440 decode_getattr_maxsz + \
441 encode_restorefh_maxsz + \
442 decode_getattr_maxsz)
443 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
444 decode_putfh_maxsz + \
445 decode_savefh_maxsz + \
446 decode_putfh_maxsz + \
447 decode_link_maxsz + \
448 decode_getattr_maxsz + \
449 decode_restorefh_maxsz + \
450 decode_getattr_maxsz)
451 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
452 encode_putfh_maxsz + \
453 encode_symlink_maxsz + \
454 encode_getattr_maxsz + \
455 encode_getfh_maxsz)
456 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
457 decode_putfh_maxsz + \
458 decode_symlink_maxsz + \
459 decode_getattr_maxsz + \
460 decode_getfh_maxsz)
461 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
462 encode_putfh_maxsz + \
463 encode_savefh_maxsz + \
464 encode_create_maxsz + \
465 encode_getfh_maxsz + \
466 encode_getattr_maxsz + \
467 encode_restorefh_maxsz + \
468 encode_getattr_maxsz)
469 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
470 decode_putfh_maxsz + \
471 decode_savefh_maxsz + \
472 decode_create_maxsz + \
473 decode_getfh_maxsz + \
474 decode_getattr_maxsz + \
475 decode_restorefh_maxsz + \
476 decode_getattr_maxsz)
477 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
478 encode_putfh_maxsz + \
479 encode_getattr_maxsz)
480 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
481 decode_putfh_maxsz + \
482 decode_getattr_maxsz)
483 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
484 encode_putfh_maxsz + \
485 encode_statfs_maxsz)
486 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
487 decode_putfh_maxsz + \
488 decode_statfs_maxsz)
489 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
490 encode_putfh_maxsz + \
491 encode_getattr_maxsz)
492 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
493 decode_putfh_maxsz + \
494 decode_getattr_maxsz)
495 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
496 encode_putfh_maxsz + \
497 encode_delegreturn_maxsz + \
498 encode_getattr_maxsz)
499 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
500 decode_delegreturn_maxsz + \
501 decode_getattr_maxsz)
502 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
503 encode_putfh_maxsz + \
504 encode_getacl_maxsz)
505 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
506 decode_putfh_maxsz + \
507 decode_getacl_maxsz)
508 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
509 encode_putfh_maxsz + \
510 encode_setacl_maxsz)
511 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
512 decode_putfh_maxsz + \
513 decode_setacl_maxsz)
514 #define NFS4_enc_fs_locations_sz \
515 (compound_encode_hdr_maxsz + \
516 encode_putfh_maxsz + \
517 encode_lookup_maxsz + \
518 encode_fs_locations_maxsz)
519 #define NFS4_dec_fs_locations_sz \
520 (compound_decode_hdr_maxsz + \
521 decode_putfh_maxsz + \
522 decode_lookup_maxsz + \
523 decode_fs_locations_maxsz)
525 static const umode_t nfs_type2fmt[] = {
526 [NF4BAD] = 0,
527 [NF4REG] = S_IFREG,
528 [NF4DIR] = S_IFDIR,
529 [NF4BLK] = S_IFBLK,
530 [NF4CHR] = S_IFCHR,
531 [NF4LNK] = S_IFLNK,
532 [NF4SOCK] = S_IFSOCK,
533 [NF4FIFO] = S_IFIFO,
534 [NF4ATTRDIR] = 0,
535 [NF4NAMEDATTR] = 0,
538 struct compound_hdr {
539 int32_t status;
540 uint32_t nops;
541 __be32 * nops_p;
542 uint32_t taglen;
543 char * tag;
547 * START OF "GENERIC" ENCODE ROUTINES.
548 * These may look a little ugly since they are imported from a "generic"
549 * set of XDR encode/decode routines which are intended to be shared by
550 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
552 * If the pain of reading these is too great, it should be a straightforward
553 * task to translate them into Linux-specific versions which are more
554 * consistent with the style used in NFSv2/v3...
556 #define WRITE32(n) *p++ = htonl(n)
557 #define WRITE64(n) do { \
558 *p++ = htonl((uint32_t)((n) >> 32)); \
559 *p++ = htonl((uint32_t)(n)); \
560 } while (0)
561 #define WRITEMEM(ptr,nbytes) do { \
562 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
563 } while (0)
565 #define RESERVE_SPACE(nbytes) do { \
566 p = xdr_reserve_space(xdr, nbytes); \
567 BUG_ON(!p); \
568 } while (0)
570 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
572 __be32 *p;
574 p = xdr_reserve_space(xdr, 4 + len);
575 BUG_ON(p == NULL);
576 xdr_encode_opaque(p, str, len);
579 static void encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
581 __be32 *p;
583 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
584 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
585 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
586 WRITE32(hdr->taglen);
587 WRITEMEM(hdr->tag, hdr->taglen);
588 WRITE32(NFS4_MINOR_VERSION);
589 hdr->nops_p = p;
590 WRITE32(hdr->nops);
593 static void encode_nops(struct compound_hdr *hdr)
595 *hdr->nops_p = htonl(hdr->nops);
598 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
600 __be32 *p;
602 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
603 BUG_ON(p == NULL);
604 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
607 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
609 char owner_name[IDMAP_NAMESZ];
610 char owner_group[IDMAP_NAMESZ];
611 int owner_namelen = 0;
612 int owner_grouplen = 0;
613 __be32 *p;
614 __be32 *q;
615 int len;
616 uint32_t bmval0 = 0;
617 uint32_t bmval1 = 0;
620 * We reserve enough space to write the entire attribute buffer at once.
621 * In the worst-case, this would be
622 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
623 * = 36 bytes, plus any contribution from variable-length fields
624 * such as owner/group.
626 len = 16;
628 /* Sigh */
629 if (iap->ia_valid & ATTR_SIZE)
630 len += 8;
631 if (iap->ia_valid & ATTR_MODE)
632 len += 4;
633 if (iap->ia_valid & ATTR_UID) {
634 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
635 if (owner_namelen < 0) {
636 dprintk("nfs: couldn't resolve uid %d to string\n",
637 iap->ia_uid);
638 /* XXX */
639 strcpy(owner_name, "nobody");
640 owner_namelen = sizeof("nobody") - 1;
641 /* goto out; */
643 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
645 if (iap->ia_valid & ATTR_GID) {
646 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
647 if (owner_grouplen < 0) {
648 dprintk("nfs: couldn't resolve gid %d to string\n",
649 iap->ia_gid);
650 strcpy(owner_group, "nobody");
651 owner_grouplen = sizeof("nobody") - 1;
652 /* goto out; */
654 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
656 if (iap->ia_valid & ATTR_ATIME_SET)
657 len += 16;
658 else if (iap->ia_valid & ATTR_ATIME)
659 len += 4;
660 if (iap->ia_valid & ATTR_MTIME_SET)
661 len += 16;
662 else if (iap->ia_valid & ATTR_MTIME)
663 len += 4;
664 RESERVE_SPACE(len);
667 * We write the bitmap length now, but leave the bitmap and the attribute
668 * buffer length to be backfilled at the end of this routine.
670 WRITE32(2);
671 q = p;
672 p += 3;
674 if (iap->ia_valid & ATTR_SIZE) {
675 bmval0 |= FATTR4_WORD0_SIZE;
676 WRITE64(iap->ia_size);
678 if (iap->ia_valid & ATTR_MODE) {
679 bmval1 |= FATTR4_WORD1_MODE;
680 WRITE32(iap->ia_mode & S_IALLUGO);
682 if (iap->ia_valid & ATTR_UID) {
683 bmval1 |= FATTR4_WORD1_OWNER;
684 WRITE32(owner_namelen);
685 WRITEMEM(owner_name, owner_namelen);
687 if (iap->ia_valid & ATTR_GID) {
688 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
689 WRITE32(owner_grouplen);
690 WRITEMEM(owner_group, owner_grouplen);
692 if (iap->ia_valid & ATTR_ATIME_SET) {
693 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
694 WRITE32(NFS4_SET_TO_CLIENT_TIME);
695 WRITE32(0);
696 WRITE32(iap->ia_mtime.tv_sec);
697 WRITE32(iap->ia_mtime.tv_nsec);
699 else if (iap->ia_valid & ATTR_ATIME) {
700 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
701 WRITE32(NFS4_SET_TO_SERVER_TIME);
703 if (iap->ia_valid & ATTR_MTIME_SET) {
704 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
705 WRITE32(NFS4_SET_TO_CLIENT_TIME);
706 WRITE32(0);
707 WRITE32(iap->ia_mtime.tv_sec);
708 WRITE32(iap->ia_mtime.tv_nsec);
710 else if (iap->ia_valid & ATTR_MTIME) {
711 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
712 WRITE32(NFS4_SET_TO_SERVER_TIME);
716 * Now we backfill the bitmap and the attribute buffer length.
718 if (len != ((char *)p - (char *)q) + 4) {
719 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
720 len, ((char *)p - (char *)q) + 4);
721 BUG();
723 len = (char *)p - (char *)q - 12;
724 *q++ = htonl(bmval0);
725 *q++ = htonl(bmval1);
726 *q++ = htonl(len);
728 /* out: */
731 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
733 __be32 *p;
735 RESERVE_SPACE(8);
736 WRITE32(OP_ACCESS);
737 WRITE32(access);
738 hdr->nops++;
741 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
743 __be32 *p;
745 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
746 WRITE32(OP_CLOSE);
747 WRITE32(arg->seqid->sequence->counter);
748 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
749 hdr->nops++;
752 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
754 __be32 *p;
756 RESERVE_SPACE(16);
757 WRITE32(OP_COMMIT);
758 WRITE64(args->offset);
759 WRITE32(args->count);
760 hdr->nops++;
763 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
765 __be32 *p;
767 RESERVE_SPACE(8);
768 WRITE32(OP_CREATE);
769 WRITE32(create->ftype);
771 switch (create->ftype) {
772 case NF4LNK:
773 RESERVE_SPACE(4);
774 WRITE32(create->u.symlink.len);
775 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
776 break;
778 case NF4BLK: case NF4CHR:
779 RESERVE_SPACE(8);
780 WRITE32(create->u.device.specdata1);
781 WRITE32(create->u.device.specdata2);
782 break;
784 default:
785 break;
788 RESERVE_SPACE(4 + create->name->len);
789 WRITE32(create->name->len);
790 WRITEMEM(create->name->name, create->name->len);
791 hdr->nops++;
793 encode_attrs(xdr, create->attrs, create->server);
796 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
798 __be32 *p;
800 RESERVE_SPACE(12);
801 WRITE32(OP_GETATTR);
802 WRITE32(1);
803 WRITE32(bitmap);
804 hdr->nops++;
807 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
809 __be32 *p;
811 RESERVE_SPACE(16);
812 WRITE32(OP_GETATTR);
813 WRITE32(2);
814 WRITE32(bm0);
815 WRITE32(bm1);
816 hdr->nops++;
819 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
821 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
822 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
825 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
827 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
828 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
831 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
833 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
834 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
837 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
839 __be32 *p;
841 RESERVE_SPACE(4);
842 WRITE32(OP_GETFH);
843 hdr->nops++;
846 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
848 __be32 *p;
850 RESERVE_SPACE(8 + name->len);
851 WRITE32(OP_LINK);
852 WRITE32(name->len);
853 WRITEMEM(name->name, name->len);
854 hdr->nops++;
857 static inline int nfs4_lock_type(struct file_lock *fl, int block)
859 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
860 return block ? NFS4_READW_LT : NFS4_READ_LT;
861 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
864 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
866 if (fl->fl_end == OFFSET_MAX)
867 return ~(uint64_t)0;
868 return fl->fl_end - fl->fl_start + 1;
872 * opcode,type,reclaim,offset,length,new_lock_owner = 32
873 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
875 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
877 __be32 *p;
879 RESERVE_SPACE(32);
880 WRITE32(OP_LOCK);
881 WRITE32(nfs4_lock_type(args->fl, args->block));
882 WRITE32(args->reclaim);
883 WRITE64(args->fl->fl_start);
884 WRITE64(nfs4_lock_length(args->fl));
885 WRITE32(args->new_lock_owner);
886 if (args->new_lock_owner){
887 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
888 WRITE32(args->open_seqid->sequence->counter);
889 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
890 WRITE32(args->lock_seqid->sequence->counter);
891 WRITE64(args->lock_owner.clientid);
892 WRITE32(16);
893 WRITEMEM("lock id:", 8);
894 WRITE64(args->lock_owner.id);
896 else {
897 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
898 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
899 WRITE32(args->lock_seqid->sequence->counter);
901 hdr->nops++;
904 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
906 __be32 *p;
908 RESERVE_SPACE(52);
909 WRITE32(OP_LOCKT);
910 WRITE32(nfs4_lock_type(args->fl, 0));
911 WRITE64(args->fl->fl_start);
912 WRITE64(nfs4_lock_length(args->fl));
913 WRITE64(args->lock_owner.clientid);
914 WRITE32(16);
915 WRITEMEM("lock id:", 8);
916 WRITE64(args->lock_owner.id);
917 hdr->nops++;
920 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
922 __be32 *p;
924 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
925 WRITE32(OP_LOCKU);
926 WRITE32(nfs4_lock_type(args->fl, 0));
927 WRITE32(args->seqid->sequence->counter);
928 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
929 WRITE64(args->fl->fl_start);
930 WRITE64(nfs4_lock_length(args->fl));
931 hdr->nops++;
934 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
936 int len = name->len;
937 __be32 *p;
939 RESERVE_SPACE(8 + len);
940 WRITE32(OP_LOOKUP);
941 WRITE32(len);
942 WRITEMEM(name->name, len);
943 hdr->nops++;
946 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
948 __be32 *p;
950 RESERVE_SPACE(8);
951 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
952 case FMODE_READ:
953 WRITE32(NFS4_SHARE_ACCESS_READ);
954 break;
955 case FMODE_WRITE:
956 WRITE32(NFS4_SHARE_ACCESS_WRITE);
957 break;
958 case FMODE_READ|FMODE_WRITE:
959 WRITE32(NFS4_SHARE_ACCESS_BOTH);
960 break;
961 default:
962 WRITE32(0);
964 WRITE32(0); /* for linux, share_deny = 0 always */
967 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
969 __be32 *p;
971 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
972 * owner 4 = 32
974 RESERVE_SPACE(8);
975 WRITE32(OP_OPEN);
976 WRITE32(arg->seqid->sequence->counter);
977 encode_share_access(xdr, arg->fmode);
978 RESERVE_SPACE(28);
979 WRITE64(arg->clientid);
980 WRITE32(16);
981 WRITEMEM("open id:", 8);
982 WRITE64(arg->id);
985 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
987 __be32 *p;
989 RESERVE_SPACE(4);
990 switch(arg->open_flags & O_EXCL) {
991 case 0:
992 WRITE32(NFS4_CREATE_UNCHECKED);
993 encode_attrs(xdr, arg->u.attrs, arg->server);
994 break;
995 default:
996 WRITE32(NFS4_CREATE_EXCLUSIVE);
997 encode_nfs4_verifier(xdr, &arg->u.verifier);
1001 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1003 __be32 *p;
1005 RESERVE_SPACE(4);
1006 switch (arg->open_flags & O_CREAT) {
1007 case 0:
1008 WRITE32(NFS4_OPEN_NOCREATE);
1009 break;
1010 default:
1011 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1012 WRITE32(NFS4_OPEN_CREATE);
1013 encode_createmode(xdr, arg);
1017 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1019 __be32 *p;
1021 RESERVE_SPACE(4);
1022 switch (delegation_type) {
1023 case 0:
1024 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1025 break;
1026 case FMODE_READ:
1027 WRITE32(NFS4_OPEN_DELEGATE_READ);
1028 break;
1029 case FMODE_WRITE|FMODE_READ:
1030 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1031 break;
1032 default:
1033 BUG();
1037 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1039 __be32 *p;
1041 RESERVE_SPACE(4);
1042 WRITE32(NFS4_OPEN_CLAIM_NULL);
1043 encode_string(xdr, name->len, name->name);
1046 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1048 __be32 *p;
1050 RESERVE_SPACE(4);
1051 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1052 encode_delegation_type(xdr, type);
1055 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1057 __be32 *p;
1059 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1060 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1061 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1062 encode_string(xdr, name->len, name->name);
1065 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1067 encode_openhdr(xdr, arg);
1068 encode_opentype(xdr, arg);
1069 switch (arg->claim) {
1070 case NFS4_OPEN_CLAIM_NULL:
1071 encode_claim_null(xdr, arg->name);
1072 break;
1073 case NFS4_OPEN_CLAIM_PREVIOUS:
1074 encode_claim_previous(xdr, arg->u.delegation_type);
1075 break;
1076 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1077 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1078 break;
1079 default:
1080 BUG();
1082 hdr->nops++;
1085 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1087 __be32 *p;
1089 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1090 WRITE32(OP_OPEN_CONFIRM);
1091 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1092 WRITE32(arg->seqid->sequence->counter);
1093 hdr->nops++;
1096 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1098 __be32 *p;
1100 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1101 WRITE32(OP_OPEN_DOWNGRADE);
1102 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1103 WRITE32(arg->seqid->sequence->counter);
1104 encode_share_access(xdr, arg->fmode);
1105 hdr->nops++;
1108 static void
1109 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1111 int len = fh->size;
1112 __be32 *p;
1114 RESERVE_SPACE(8 + len);
1115 WRITE32(OP_PUTFH);
1116 WRITE32(len);
1117 WRITEMEM(fh->data, len);
1118 hdr->nops++;
1121 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1123 __be32 *p;
1125 RESERVE_SPACE(4);
1126 WRITE32(OP_PUTROOTFH);
1127 hdr->nops++;
1130 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1132 nfs4_stateid stateid;
1133 __be32 *p;
1135 RESERVE_SPACE(NFS4_STATEID_SIZE);
1136 if (ctx->state != NULL) {
1137 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1138 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1139 } else
1140 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1143 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1145 __be32 *p;
1147 RESERVE_SPACE(4);
1148 WRITE32(OP_READ);
1150 encode_stateid(xdr, args->context);
1152 RESERVE_SPACE(12);
1153 WRITE64(args->offset);
1154 WRITE32(args->count);
1155 hdr->nops++;
1158 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1160 uint32_t attrs[2] = {
1161 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1162 FATTR4_WORD1_MOUNTED_ON_FILEID,
1164 __be32 *p;
1166 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1167 WRITE32(OP_READDIR);
1168 WRITE64(readdir->cookie);
1169 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1170 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1171 WRITE32(readdir->count);
1172 WRITE32(2);
1173 /* Switch to mounted_on_fileid if the server supports it */
1174 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1175 attrs[0] &= ~FATTR4_WORD0_FILEID;
1176 else
1177 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1178 WRITE32(attrs[0] & readdir->bitmask[0]);
1179 WRITE32(attrs[1] & readdir->bitmask[1]);
1180 hdr->nops++;
1181 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1182 __func__,
1183 (unsigned long long)readdir->cookie,
1184 ((u32 *)readdir->verifier.data)[0],
1185 ((u32 *)readdir->verifier.data)[1],
1186 attrs[0] & readdir->bitmask[0],
1187 attrs[1] & readdir->bitmask[1]);
1190 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1192 __be32 *p;
1194 RESERVE_SPACE(4);
1195 WRITE32(OP_READLINK);
1196 hdr->nops++;
1199 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1201 __be32 *p;
1203 RESERVE_SPACE(8 + name->len);
1204 WRITE32(OP_REMOVE);
1205 WRITE32(name->len);
1206 WRITEMEM(name->name, name->len);
1207 hdr->nops++;
1210 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1212 __be32 *p;
1214 RESERVE_SPACE(8 + oldname->len);
1215 WRITE32(OP_RENAME);
1216 WRITE32(oldname->len);
1217 WRITEMEM(oldname->name, oldname->len);
1219 RESERVE_SPACE(4 + newname->len);
1220 WRITE32(newname->len);
1221 WRITEMEM(newname->name, newname->len);
1222 hdr->nops++;
1225 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1227 __be32 *p;
1229 RESERVE_SPACE(12);
1230 WRITE32(OP_RENEW);
1231 WRITE64(client_stateid->cl_clientid);
1232 hdr->nops++;
1235 static void
1236 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1238 __be32 *p;
1240 RESERVE_SPACE(4);
1241 WRITE32(OP_RESTOREFH);
1242 hdr->nops++;
1245 static int
1246 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1248 __be32 *p;
1250 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1251 WRITE32(OP_SETATTR);
1252 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1253 RESERVE_SPACE(2*4);
1254 WRITE32(1);
1255 WRITE32(FATTR4_WORD0_ACL);
1256 if (arg->acl_len % 4)
1257 return -EINVAL;
1258 RESERVE_SPACE(4);
1259 WRITE32(arg->acl_len);
1260 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1261 hdr->nops++;
1262 return 0;
1265 static void
1266 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1268 __be32 *p;
1270 RESERVE_SPACE(4);
1271 WRITE32(OP_SAVEFH);
1272 hdr->nops++;
1275 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1277 __be32 *p;
1279 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1280 WRITE32(OP_SETATTR);
1281 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1282 hdr->nops++;
1283 encode_attrs(xdr, arg->iap, server);
1286 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1288 __be32 *p;
1290 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1291 WRITE32(OP_SETCLIENTID);
1292 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1294 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1295 RESERVE_SPACE(4);
1296 WRITE32(setclientid->sc_prog);
1297 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1298 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1299 RESERVE_SPACE(4);
1300 WRITE32(setclientid->sc_cb_ident);
1301 hdr->nops++;
1304 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
1306 __be32 *p;
1308 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1309 WRITE32(OP_SETCLIENTID_CONFIRM);
1310 WRITE64(client_state->cl_clientid);
1311 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1312 hdr->nops++;
1315 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1317 __be32 *p;
1319 RESERVE_SPACE(4);
1320 WRITE32(OP_WRITE);
1322 encode_stateid(xdr, args->context);
1324 RESERVE_SPACE(16);
1325 WRITE64(args->offset);
1326 WRITE32(args->stable);
1327 WRITE32(args->count);
1329 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1330 hdr->nops++;
1333 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1335 __be32 *p;
1337 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1339 WRITE32(OP_DELEGRETURN);
1340 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1341 hdr->nops++;
1344 * END OF "GENERIC" ENCODE ROUTINES.
1348 * Encode an ACCESS request
1350 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1352 struct xdr_stream xdr;
1353 struct compound_hdr hdr = {
1354 .nops = 0,
1357 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1358 encode_compound_hdr(&xdr, &hdr);
1359 encode_putfh(&xdr, args->fh, &hdr);
1360 encode_access(&xdr, args->access, &hdr);
1361 encode_getfattr(&xdr, args->bitmask, &hdr);
1362 encode_nops(&hdr);
1363 return 0;
1367 * Encode LOOKUP request
1369 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1371 struct xdr_stream xdr;
1372 struct compound_hdr hdr = {
1373 .nops = 0,
1376 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1377 encode_compound_hdr(&xdr, &hdr);
1378 encode_putfh(&xdr, args->dir_fh, &hdr);
1379 encode_lookup(&xdr, args->name, &hdr);
1380 encode_getfh(&xdr, &hdr);
1381 encode_getfattr(&xdr, args->bitmask, &hdr);
1382 encode_nops(&hdr);
1383 return 0;
1387 * Encode LOOKUP_ROOT request
1389 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1391 struct xdr_stream xdr;
1392 struct compound_hdr hdr = {
1393 .nops = 0,
1396 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1397 encode_compound_hdr(&xdr, &hdr);
1398 encode_putrootfh(&xdr, &hdr);
1399 encode_getfh(&xdr, &hdr);
1400 encode_getfattr(&xdr, args->bitmask, &hdr);
1401 encode_nops(&hdr);
1402 return 0;
1406 * Encode REMOVE request
1408 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1410 struct xdr_stream xdr;
1411 struct compound_hdr hdr = {
1412 .nops = 0,
1415 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1416 encode_compound_hdr(&xdr, &hdr);
1417 encode_putfh(&xdr, args->fh, &hdr);
1418 encode_remove(&xdr, &args->name, &hdr);
1419 encode_getfattr(&xdr, args->bitmask, &hdr);
1420 encode_nops(&hdr);
1421 return 0;
1425 * Encode RENAME request
1427 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1429 struct xdr_stream xdr;
1430 struct compound_hdr hdr = {
1431 .nops = 0,
1434 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1435 encode_compound_hdr(&xdr, &hdr);
1436 encode_putfh(&xdr, args->old_dir, &hdr);
1437 encode_savefh(&xdr, &hdr);
1438 encode_putfh(&xdr, args->new_dir, &hdr);
1439 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1440 encode_getfattr(&xdr, args->bitmask, &hdr);
1441 encode_restorefh(&xdr, &hdr);
1442 encode_getfattr(&xdr, args->bitmask, &hdr);
1443 encode_nops(&hdr);
1444 return 0;
1448 * Encode LINK request
1450 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1452 struct xdr_stream xdr;
1453 struct compound_hdr hdr = {
1454 .nops = 0,
1457 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1458 encode_compound_hdr(&xdr, &hdr);
1459 encode_putfh(&xdr, args->fh, &hdr);
1460 encode_savefh(&xdr, &hdr);
1461 encode_putfh(&xdr, args->dir_fh, &hdr);
1462 encode_link(&xdr, args->name, &hdr);
1463 encode_getfattr(&xdr, args->bitmask, &hdr);
1464 encode_restorefh(&xdr, &hdr);
1465 encode_getfattr(&xdr, args->bitmask, &hdr);
1466 encode_nops(&hdr);
1467 return 0;
1471 * Encode CREATE request
1473 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1475 struct xdr_stream xdr;
1476 struct compound_hdr hdr = {
1477 .nops = 0,
1480 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1481 encode_compound_hdr(&xdr, &hdr);
1482 encode_putfh(&xdr, args->dir_fh, &hdr);
1483 encode_savefh(&xdr, &hdr);
1484 encode_create(&xdr, args, &hdr);
1485 encode_getfh(&xdr, &hdr);
1486 encode_getfattr(&xdr, args->bitmask, &hdr);
1487 encode_restorefh(&xdr, &hdr);
1488 encode_getfattr(&xdr, args->bitmask, &hdr);
1489 encode_nops(&hdr);
1490 return 0;
1494 * Encode SYMLINK request
1496 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1498 return nfs4_xdr_enc_create(req, p, args);
1502 * Encode GETATTR request
1504 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1506 struct xdr_stream xdr;
1507 struct compound_hdr hdr = {
1508 .nops = 0,
1511 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1512 encode_compound_hdr(&xdr, &hdr);
1513 encode_putfh(&xdr, args->fh, &hdr);
1514 encode_getfattr(&xdr, args->bitmask, &hdr);
1515 encode_nops(&hdr);
1516 return 0;
1520 * Encode a CLOSE request
1522 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1524 struct xdr_stream xdr;
1525 struct compound_hdr hdr = {
1526 .nops = 0,
1529 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1530 encode_compound_hdr(&xdr, &hdr);
1531 encode_putfh(&xdr, args->fh, &hdr);
1532 encode_close(&xdr, args, &hdr);
1533 encode_getfattr(&xdr, args->bitmask, &hdr);
1534 encode_nops(&hdr);
1535 return 0;
1539 * Encode an OPEN request
1541 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1543 struct xdr_stream xdr;
1544 struct compound_hdr hdr = {
1545 .nops = 0,
1548 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1549 encode_compound_hdr(&xdr, &hdr);
1550 encode_putfh(&xdr, args->fh, &hdr);
1551 encode_savefh(&xdr, &hdr);
1552 encode_open(&xdr, args, &hdr);
1553 encode_getfh(&xdr, &hdr);
1554 encode_getfattr(&xdr, args->bitmask, &hdr);
1555 encode_restorefh(&xdr, &hdr);
1556 encode_getfattr(&xdr, args->bitmask, &hdr);
1557 encode_nops(&hdr);
1558 return 0;
1562 * Encode an OPEN_CONFIRM request
1564 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1566 struct xdr_stream xdr;
1567 struct compound_hdr hdr = {
1568 .nops = 0,
1571 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1572 encode_compound_hdr(&xdr, &hdr);
1573 encode_putfh(&xdr, args->fh, &hdr);
1574 encode_open_confirm(&xdr, args, &hdr);
1575 encode_nops(&hdr);
1576 return 0;
1580 * Encode an OPEN request with no attributes.
1582 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1584 struct xdr_stream xdr;
1585 struct compound_hdr hdr = {
1586 .nops = 0,
1589 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1590 encode_compound_hdr(&xdr, &hdr);
1591 encode_putfh(&xdr, args->fh, &hdr);
1592 encode_open(&xdr, args, &hdr);
1593 encode_getfattr(&xdr, args->bitmask, &hdr);
1594 encode_nops(&hdr);
1595 return 0;
1599 * Encode an OPEN_DOWNGRADE request
1601 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1603 struct xdr_stream xdr;
1604 struct compound_hdr hdr = {
1605 .nops = 0,
1608 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1609 encode_compound_hdr(&xdr, &hdr);
1610 encode_putfh(&xdr, args->fh, &hdr);
1611 encode_open_downgrade(&xdr, args, &hdr);
1612 encode_getfattr(&xdr, args->bitmask, &hdr);
1613 encode_nops(&hdr);
1614 return 0;
1618 * Encode a LOCK request
1620 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1622 struct xdr_stream xdr;
1623 struct compound_hdr hdr = {
1624 .nops = 0,
1627 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1628 encode_compound_hdr(&xdr, &hdr);
1629 encode_putfh(&xdr, args->fh, &hdr);
1630 encode_lock(&xdr, args, &hdr);
1631 encode_nops(&hdr);
1632 return 0;
1636 * Encode a LOCKT request
1638 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1640 struct xdr_stream xdr;
1641 struct compound_hdr hdr = {
1642 .nops = 0,
1645 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1646 encode_compound_hdr(&xdr, &hdr);
1647 encode_putfh(&xdr, args->fh, &hdr);
1648 encode_lockt(&xdr, args, &hdr);
1649 encode_nops(&hdr);
1650 return 0;
1654 * Encode a LOCKU request
1656 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1658 struct xdr_stream xdr;
1659 struct compound_hdr hdr = {
1660 .nops = 0,
1663 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1664 encode_compound_hdr(&xdr, &hdr);
1665 encode_putfh(&xdr, args->fh, &hdr);
1666 encode_locku(&xdr, args, &hdr);
1667 encode_nops(&hdr);
1668 return 0;
1672 * Encode a READLINK request
1674 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1676 struct xdr_stream xdr;
1677 struct compound_hdr hdr = {
1678 .nops = 0,
1680 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1681 unsigned int replen;
1683 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1684 encode_compound_hdr(&xdr, &hdr);
1685 encode_putfh(&xdr, args->fh, &hdr);
1686 encode_readlink(&xdr, args, req, &hdr);
1688 /* set up reply kvec
1689 * toplevel_status + taglen + rescount + OP_PUTFH + status
1690 * + OP_READLINK + status + string length = 8
1692 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readlink_sz) << 2;
1693 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1694 args->pgbase, args->pglen);
1695 encode_nops(&hdr);
1696 return 0;
1700 * Encode a READDIR request
1702 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1704 struct xdr_stream xdr;
1705 struct compound_hdr hdr = {
1706 .nops = 0,
1708 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1709 int replen;
1711 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1712 encode_compound_hdr(&xdr, &hdr);
1713 encode_putfh(&xdr, args->fh, &hdr);
1714 encode_readdir(&xdr, args, req, &hdr);
1716 /* set up reply kvec
1717 * toplevel_status + taglen + rescount + OP_PUTFH + status
1718 * + OP_READDIR + status + verifer(2) = 9
1720 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readdir_sz) << 2;
1721 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1722 args->pgbase, args->count);
1723 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1724 __func__, replen, args->pages,
1725 args->pgbase, args->count);
1726 encode_nops(&hdr);
1727 return 0;
1731 * Encode a READ request
1733 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1735 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1736 struct xdr_stream xdr;
1737 struct compound_hdr hdr = {
1738 .nops = 0,
1740 int replen;
1742 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1743 encode_compound_hdr(&xdr, &hdr);
1744 encode_putfh(&xdr, args->fh, &hdr);
1745 encode_read(&xdr, args, &hdr);
1747 /* set up reply kvec
1748 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1749 * + OP_READ + status + eof + datalen = 9
1751 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1752 xdr_inline_pages(&req->rq_rcv_buf, replen,
1753 args->pages, args->pgbase, args->count);
1754 req->rq_rcv_buf.flags |= XDRBUF_READ;
1755 encode_nops(&hdr);
1756 return 0;
1760 * Encode an SETATTR request
1762 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1764 struct xdr_stream xdr;
1765 struct compound_hdr hdr = {
1766 .nops = 0,
1769 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1770 encode_compound_hdr(&xdr, &hdr);
1771 encode_putfh(&xdr, args->fh, &hdr);
1772 encode_setattr(&xdr, args, args->server, &hdr);
1773 encode_getfattr(&xdr, args->bitmask, &hdr);
1774 encode_nops(&hdr);
1775 return 0;
1779 * Encode a GETACL request
1781 static int
1782 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1783 struct nfs_getaclargs *args)
1785 struct xdr_stream xdr;
1786 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1787 struct compound_hdr hdr = {
1788 .nops = 0,
1790 int replen;
1792 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1793 encode_compound_hdr(&xdr, &hdr);
1794 encode_putfh(&xdr, args->fh, &hdr);
1795 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1797 /* set up reply buffer: */
1798 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1799 xdr_inline_pages(&req->rq_rcv_buf, replen,
1800 args->acl_pages, args->acl_pgbase, args->acl_len);
1801 encode_nops(&hdr);
1802 return 0;
1806 * Encode a WRITE request
1808 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1810 struct xdr_stream xdr;
1811 struct compound_hdr hdr = {
1812 .nops = 0,
1815 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1816 encode_compound_hdr(&xdr, &hdr);
1817 encode_putfh(&xdr, args->fh, &hdr);
1818 encode_write(&xdr, args, &hdr);
1819 req->rq_snd_buf.flags |= XDRBUF_WRITE;
1820 encode_getfattr(&xdr, args->bitmask, &hdr);
1821 encode_nops(&hdr);
1822 return 0;
1826 * a COMMIT request
1828 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1830 struct xdr_stream xdr;
1831 struct compound_hdr hdr = {
1832 .nops = 0,
1835 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1836 encode_compound_hdr(&xdr, &hdr);
1837 encode_putfh(&xdr, args->fh, &hdr);
1838 encode_commit(&xdr, args, &hdr);
1839 encode_getfattr(&xdr, args->bitmask, &hdr);
1840 encode_nops(&hdr);
1841 return 0;
1845 * FSINFO request
1847 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1849 struct xdr_stream xdr;
1850 struct compound_hdr hdr = {
1851 .nops = 0,
1854 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1855 encode_compound_hdr(&xdr, &hdr);
1856 encode_putfh(&xdr, args->fh, &hdr);
1857 encode_fsinfo(&xdr, args->bitmask, &hdr);
1858 encode_nops(&hdr);
1859 return 0;
1863 * a PATHCONF request
1865 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1867 struct xdr_stream xdr;
1868 struct compound_hdr hdr = {
1869 .nops = 0,
1872 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1873 encode_compound_hdr(&xdr, &hdr);
1874 encode_putfh(&xdr, args->fh, &hdr);
1875 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
1876 &hdr);
1877 encode_nops(&hdr);
1878 return 0;
1882 * a STATFS request
1884 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
1886 struct xdr_stream xdr;
1887 struct compound_hdr hdr = {
1888 .nops = 0,
1891 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1892 encode_compound_hdr(&xdr, &hdr);
1893 encode_putfh(&xdr, args->fh, &hdr);
1894 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
1895 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
1896 encode_nops(&hdr);
1897 return 0;
1901 * GETATTR_BITMAP request
1903 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
1904 struct nfs4_server_caps_arg *args)
1906 struct xdr_stream xdr;
1907 struct compound_hdr hdr = {
1908 .nops = 0,
1911 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1912 encode_compound_hdr(&xdr, &hdr);
1913 encode_putfh(&xdr, args->fhandle, &hdr);
1914 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1915 FATTR4_WORD0_LINK_SUPPORT|
1916 FATTR4_WORD0_SYMLINK_SUPPORT|
1917 FATTR4_WORD0_ACLSUPPORT, &hdr);
1918 encode_nops(&hdr);
1919 return 0;
1923 * a RENEW request
1925 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1927 struct xdr_stream xdr;
1928 struct compound_hdr hdr = {
1929 .nops = 0,
1932 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1933 encode_compound_hdr(&xdr, &hdr);
1934 encode_renew(&xdr, clp, &hdr);
1935 encode_nops(&hdr);
1936 return 0;
1940 * a SETCLIENTID request
1942 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
1944 struct xdr_stream xdr;
1945 struct compound_hdr hdr = {
1946 .nops = 0,
1949 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1950 encode_compound_hdr(&xdr, &hdr);
1951 encode_setclientid(&xdr, sc, &hdr);
1952 encode_nops(&hdr);
1953 return 0;
1957 * a SETCLIENTID_CONFIRM request
1959 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1961 struct xdr_stream xdr;
1962 struct compound_hdr hdr = {
1963 .nops = 0,
1965 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1967 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1968 encode_compound_hdr(&xdr, &hdr);
1969 encode_setclientid_confirm(&xdr, clp, &hdr);
1970 encode_putrootfh(&xdr, &hdr);
1971 encode_fsinfo(&xdr, lease_bitmap, &hdr);
1972 encode_nops(&hdr);
1973 return 0;
1977 * DELEGRETURN request
1979 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
1981 struct xdr_stream xdr;
1982 struct compound_hdr hdr = {
1983 .nops = 0,
1986 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1987 encode_compound_hdr(&xdr, &hdr);
1988 encode_putfh(&xdr, args->fhandle, &hdr);
1989 encode_delegreturn(&xdr, args->stateid, &hdr);
1990 encode_getfattr(&xdr, args->bitmask, &hdr);
1991 encode_nops(&hdr);
1992 return 0;
1996 * Encode FS_LOCATIONS request
1998 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2000 struct xdr_stream xdr;
2001 struct compound_hdr hdr = {
2002 .nops = 0,
2004 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
2005 int replen;
2007 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2008 encode_compound_hdr(&xdr, &hdr);
2009 encode_putfh(&xdr, args->dir_fh, &hdr);
2010 encode_lookup(&xdr, args->name, &hdr);
2011 encode_fs_locations(&xdr, args->bitmask, &hdr);
2013 /* set up reply
2014 * toplevel_status + OP_PUTFH + status
2015 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2017 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2018 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2019 0, PAGE_SIZE);
2020 encode_nops(&hdr);
2021 return 0;
2025 * START OF "GENERIC" DECODE ROUTINES.
2026 * These may look a little ugly since they are imported from a "generic"
2027 * set of XDR encode/decode routines which are intended to be shared by
2028 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2030 * If the pain of reading these is too great, it should be a straightforward
2031 * task to translate them into Linux-specific versions which are more
2032 * consistent with the style used in NFSv2/v3...
2034 #define READ32(x) (x) = ntohl(*p++)
2035 #define READ64(x) do { \
2036 (x) = (u64)ntohl(*p++) << 32; \
2037 (x) |= ntohl(*p++); \
2038 } while (0)
2039 #define READTIME(x) do { \
2040 p++; \
2041 (x.tv_sec) = ntohl(*p++); \
2042 (x.tv_nsec) = ntohl(*p++); \
2043 } while (0)
2044 #define COPYMEM(x,nbytes) do { \
2045 memcpy((x), p, nbytes); \
2046 p += XDR_QUADLEN(nbytes); \
2047 } while (0)
2049 #define READ_BUF(nbytes) do { \
2050 p = xdr_inline_decode(xdr, nbytes); \
2051 if (unlikely(!p)) { \
2052 dprintk("nfs: %s: prematurely hit end of receive" \
2053 " buffer\n", __func__); \
2054 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2055 __func__, xdr->p, nbytes, xdr->end); \
2056 return -EIO; \
2058 } while (0)
2060 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2062 __be32 *p;
2064 READ_BUF(4);
2065 READ32(*len);
2066 READ_BUF(*len);
2067 *string = (char *)p;
2068 return 0;
2071 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2073 __be32 *p;
2075 READ_BUF(8);
2076 READ32(hdr->status);
2077 READ32(hdr->taglen);
2079 READ_BUF(hdr->taglen + 4);
2080 hdr->tag = (char *)p;
2081 p += XDR_QUADLEN(hdr->taglen);
2082 READ32(hdr->nops);
2083 if (unlikely(hdr->nops < 1))
2084 return nfs4_stat_to_errno(hdr->status);
2085 return 0;
2088 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2090 __be32 *p;
2091 uint32_t opnum;
2092 int32_t nfserr;
2094 READ_BUF(8);
2095 READ32(opnum);
2096 if (opnum != expected) {
2097 dprintk("nfs: Server returned operation"
2098 " %d but we issued a request for %d\n",
2099 opnum, expected);
2100 return -EIO;
2102 READ32(nfserr);
2103 if (nfserr != NFS_OK)
2104 return nfs4_stat_to_errno(nfserr);
2105 return 0;
2108 /* Dummy routine */
2109 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2111 __be32 *p;
2112 unsigned int strlen;
2113 char *str;
2115 READ_BUF(12);
2116 return decode_opaque_inline(xdr, &strlen, &str);
2119 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2121 uint32_t bmlen;
2122 __be32 *p;
2124 READ_BUF(4);
2125 READ32(bmlen);
2127 bitmap[0] = bitmap[1] = 0;
2128 READ_BUF((bmlen << 2));
2129 if (bmlen > 0) {
2130 READ32(bitmap[0]);
2131 if (bmlen > 1)
2132 READ32(bitmap[1]);
2134 return 0;
2137 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2139 __be32 *p;
2141 READ_BUF(4);
2142 READ32(*attrlen);
2143 *savep = xdr->p;
2144 return 0;
2147 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2149 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2150 decode_attr_bitmap(xdr, bitmask);
2151 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2152 } else
2153 bitmask[0] = bitmask[1] = 0;
2154 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2155 return 0;
2158 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2160 __be32 *p;
2161 int ret = 0;
2163 *type = 0;
2164 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2165 return -EIO;
2166 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2167 READ_BUF(4);
2168 READ32(*type);
2169 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2170 dprintk("%s: bad type %d\n", __func__, *type);
2171 return -EIO;
2173 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2174 ret = NFS_ATTR_FATTR_TYPE;
2176 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2177 return ret;
2180 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2182 __be32 *p;
2183 int ret = 0;
2185 *change = 0;
2186 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2187 return -EIO;
2188 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2189 READ_BUF(8);
2190 READ64(*change);
2191 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2192 ret = NFS_ATTR_FATTR_CHANGE;
2194 dprintk("%s: change attribute=%Lu\n", __func__,
2195 (unsigned long long)*change);
2196 return ret;
2199 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2201 __be32 *p;
2202 int ret = 0;
2204 *size = 0;
2205 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2206 return -EIO;
2207 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2208 READ_BUF(8);
2209 READ64(*size);
2210 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2211 ret = NFS_ATTR_FATTR_SIZE;
2213 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2214 return ret;
2217 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2219 __be32 *p;
2221 *res = 0;
2222 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2223 return -EIO;
2224 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2225 READ_BUF(4);
2226 READ32(*res);
2227 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2229 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2230 return 0;
2233 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2235 __be32 *p;
2237 *res = 0;
2238 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2239 return -EIO;
2240 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2241 READ_BUF(4);
2242 READ32(*res);
2243 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2245 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2246 return 0;
2249 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2251 __be32 *p;
2252 int ret = 0;
2254 fsid->major = 0;
2255 fsid->minor = 0;
2256 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2257 return -EIO;
2258 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2259 READ_BUF(16);
2260 READ64(fsid->major);
2261 READ64(fsid->minor);
2262 bitmap[0] &= ~FATTR4_WORD0_FSID;
2263 ret = NFS_ATTR_FATTR_FSID;
2265 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
2266 (unsigned long long)fsid->major,
2267 (unsigned long long)fsid->minor);
2268 return ret;
2271 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2273 __be32 *p;
2275 *res = 60;
2276 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2277 return -EIO;
2278 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2279 READ_BUF(4);
2280 READ32(*res);
2281 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2283 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2284 return 0;
2287 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2289 __be32 *p;
2291 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2292 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2293 return -EIO;
2294 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2295 READ_BUF(4);
2296 READ32(*res);
2297 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2299 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
2300 return 0;
2303 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2305 __be32 *p;
2306 int ret = 0;
2308 *fileid = 0;
2309 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2310 return -EIO;
2311 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2312 READ_BUF(8);
2313 READ64(*fileid);
2314 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2315 ret = NFS_ATTR_FATTR_FILEID;
2317 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2318 return ret;
2321 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2323 __be32 *p;
2324 int ret = 0;
2326 *fileid = 0;
2327 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2328 return -EIO;
2329 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2330 READ_BUF(8);
2331 READ64(*fileid);
2332 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2333 ret = NFS_ATTR_FATTR_FILEID;
2335 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2336 return ret;
2339 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2341 __be32 *p;
2342 int status = 0;
2344 *res = 0;
2345 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2346 return -EIO;
2347 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2348 READ_BUF(8);
2349 READ64(*res);
2350 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2352 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
2353 return status;
2356 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2358 __be32 *p;
2359 int status = 0;
2361 *res = 0;
2362 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2363 return -EIO;
2364 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2365 READ_BUF(8);
2366 READ64(*res);
2367 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2369 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
2370 return status;
2373 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2375 __be32 *p;
2376 int status = 0;
2378 *res = 0;
2379 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2380 return -EIO;
2381 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2382 READ_BUF(8);
2383 READ64(*res);
2384 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2386 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
2387 return status;
2390 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2392 u32 n;
2393 __be32 *p;
2394 int status = 0;
2396 READ_BUF(4);
2397 READ32(n);
2398 if (n == 0)
2399 goto root_path;
2400 dprintk("path ");
2401 path->ncomponents = 0;
2402 while (path->ncomponents < n) {
2403 struct nfs4_string *component = &path->components[path->ncomponents];
2404 status = decode_opaque_inline(xdr, &component->len, &component->data);
2405 if (unlikely(status != 0))
2406 goto out_eio;
2407 if (path->ncomponents != n)
2408 dprintk("/");
2409 dprintk("%s", component->data);
2410 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2411 path->ncomponents++;
2412 else {
2413 dprintk("cannot parse %d components in path\n", n);
2414 goto out_eio;
2417 out:
2418 dprintk("\n");
2419 return status;
2420 root_path:
2421 /* a root pathname is sent as a zero component4 */
2422 path->ncomponents = 1;
2423 path->components[0].len=0;
2424 path->components[0].data=NULL;
2425 dprintk("path /\n");
2426 goto out;
2427 out_eio:
2428 dprintk(" status %d", status);
2429 status = -EIO;
2430 goto out;
2433 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2435 int n;
2436 __be32 *p;
2437 int status = -EIO;
2439 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2440 goto out;
2441 status = 0;
2442 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2443 goto out;
2444 dprintk("%s: fsroot ", __func__);
2445 status = decode_pathname(xdr, &res->fs_path);
2446 if (unlikely(status != 0))
2447 goto out;
2448 READ_BUF(4);
2449 READ32(n);
2450 if (n <= 0)
2451 goto out_eio;
2452 res->nlocations = 0;
2453 while (res->nlocations < n) {
2454 u32 m;
2455 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2457 READ_BUF(4);
2458 READ32(m);
2460 loc->nservers = 0;
2461 dprintk("%s: servers ", __func__);
2462 while (loc->nservers < m) {
2463 struct nfs4_string *server = &loc->servers[loc->nservers];
2464 status = decode_opaque_inline(xdr, &server->len, &server->data);
2465 if (unlikely(status != 0))
2466 goto out_eio;
2467 dprintk("%s ", server->data);
2468 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2469 loc->nservers++;
2470 else {
2471 unsigned int i;
2472 dprintk("%s: using first %u of %u servers "
2473 "returned for location %u\n",
2474 __func__,
2475 NFS4_FS_LOCATION_MAXSERVERS,
2476 m, res->nlocations);
2477 for (i = loc->nservers; i < m; i++) {
2478 unsigned int len;
2479 char *data;
2480 status = decode_opaque_inline(xdr, &len, &data);
2481 if (unlikely(status != 0))
2482 goto out_eio;
2486 status = decode_pathname(xdr, &loc->rootpath);
2487 if (unlikely(status != 0))
2488 goto out_eio;
2489 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2490 res->nlocations++;
2492 if (res->nlocations != 0)
2493 status = NFS_ATTR_FATTR_V4_REFERRAL;
2494 out:
2495 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
2496 return status;
2497 out_eio:
2498 status = -EIO;
2499 goto out;
2502 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2504 __be32 *p;
2505 int status = 0;
2507 *res = 0;
2508 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2509 return -EIO;
2510 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2511 READ_BUF(8);
2512 READ64(*res);
2513 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2515 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
2516 return status;
2519 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2521 __be32 *p;
2522 int status = 0;
2524 *maxlink = 1;
2525 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2526 return -EIO;
2527 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2528 READ_BUF(4);
2529 READ32(*maxlink);
2530 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2532 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
2533 return status;
2536 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2538 __be32 *p;
2539 int status = 0;
2541 *maxname = 1024;
2542 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2543 return -EIO;
2544 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2545 READ_BUF(4);
2546 READ32(*maxname);
2547 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2549 dprintk("%s: maxname=%u\n", __func__, *maxname);
2550 return status;
2553 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2555 __be32 *p;
2556 int status = 0;
2558 *res = 1024;
2559 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2560 return -EIO;
2561 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2562 uint64_t maxread;
2563 READ_BUF(8);
2564 READ64(maxread);
2565 if (maxread > 0x7FFFFFFF)
2566 maxread = 0x7FFFFFFF;
2567 *res = (uint32_t)maxread;
2568 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2570 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
2571 return status;
2574 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2576 __be32 *p;
2577 int status = 0;
2579 *res = 1024;
2580 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2581 return -EIO;
2582 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2583 uint64_t maxwrite;
2584 READ_BUF(8);
2585 READ64(maxwrite);
2586 if (maxwrite > 0x7FFFFFFF)
2587 maxwrite = 0x7FFFFFFF;
2588 *res = (uint32_t)maxwrite;
2589 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2591 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
2592 return status;
2595 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
2597 uint32_t tmp;
2598 __be32 *p;
2599 int ret = 0;
2601 *mode = 0;
2602 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2603 return -EIO;
2604 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2605 READ_BUF(4);
2606 READ32(tmp);
2607 *mode = tmp & ~S_IFMT;
2608 bitmap[1] &= ~FATTR4_WORD1_MODE;
2609 ret = NFS_ATTR_FATTR_MODE;
2611 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
2612 return ret;
2615 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2617 __be32 *p;
2618 int ret = 0;
2620 *nlink = 1;
2621 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2622 return -EIO;
2623 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2624 READ_BUF(4);
2625 READ32(*nlink);
2626 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2627 ret = NFS_ATTR_FATTR_NLINK;
2629 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
2630 return ret;
2633 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2635 uint32_t len;
2636 __be32 *p;
2637 int ret = 0;
2639 *uid = -2;
2640 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2641 return -EIO;
2642 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2643 READ_BUF(4);
2644 READ32(len);
2645 READ_BUF(len);
2646 if (len < XDR_MAX_NETOBJ) {
2647 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
2648 ret = NFS_ATTR_FATTR_OWNER;
2649 else
2650 dprintk("%s: nfs_map_name_to_uid failed!\n",
2651 __func__);
2652 } else
2653 dprintk("%s: name too long (%u)!\n",
2654 __func__, len);
2655 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2657 dprintk("%s: uid=%d\n", __func__, (int)*uid);
2658 return ret;
2661 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2663 uint32_t len;
2664 __be32 *p;
2665 int ret = 0;
2667 *gid = -2;
2668 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2669 return -EIO;
2670 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2671 READ_BUF(4);
2672 READ32(len);
2673 READ_BUF(len);
2674 if (len < XDR_MAX_NETOBJ) {
2675 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
2676 ret = NFS_ATTR_FATTR_GROUP;
2677 else
2678 dprintk("%s: nfs_map_group_to_gid failed!\n",
2679 __func__);
2680 } else
2681 dprintk("%s: name too long (%u)!\n",
2682 __func__, len);
2683 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2685 dprintk("%s: gid=%d\n", __func__, (int)*gid);
2686 return ret;
2689 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2691 uint32_t major = 0, minor = 0;
2692 __be32 *p;
2693 int ret = 0;
2695 *rdev = MKDEV(0,0);
2696 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2697 return -EIO;
2698 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2699 dev_t tmp;
2701 READ_BUF(8);
2702 READ32(major);
2703 READ32(minor);
2704 tmp = MKDEV(major, minor);
2705 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2706 *rdev = tmp;
2707 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2708 ret = NFS_ATTR_FATTR_RDEV;
2710 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
2711 return ret;
2714 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2716 __be32 *p;
2717 int status = 0;
2719 *res = 0;
2720 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2721 return -EIO;
2722 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2723 READ_BUF(8);
2724 READ64(*res);
2725 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2727 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
2728 return status;
2731 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2733 __be32 *p;
2734 int status = 0;
2736 *res = 0;
2737 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2738 return -EIO;
2739 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2740 READ_BUF(8);
2741 READ64(*res);
2742 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2744 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
2745 return status;
2748 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2750 __be32 *p;
2751 int status = 0;
2753 *res = 0;
2754 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2755 return -EIO;
2756 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2757 READ_BUF(8);
2758 READ64(*res);
2759 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2761 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
2762 return status;
2765 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2767 __be32 *p;
2768 int ret = 0;
2770 *used = 0;
2771 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2772 return -EIO;
2773 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2774 READ_BUF(8);
2775 READ64(*used);
2776 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2777 ret = NFS_ATTR_FATTR_SPACE_USED;
2779 dprintk("%s: space used=%Lu\n", __func__,
2780 (unsigned long long)*used);
2781 return ret;
2784 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2786 __be32 *p;
2787 uint64_t sec;
2788 uint32_t nsec;
2790 READ_BUF(12);
2791 READ64(sec);
2792 READ32(nsec);
2793 time->tv_sec = (time_t)sec;
2794 time->tv_nsec = (long)nsec;
2795 return 0;
2798 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2800 int status = 0;
2802 time->tv_sec = 0;
2803 time->tv_nsec = 0;
2804 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2805 return -EIO;
2806 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2807 status = decode_attr_time(xdr, time);
2808 if (status == 0)
2809 status = NFS_ATTR_FATTR_ATIME;
2810 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2812 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
2813 return status;
2816 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2818 int status = 0;
2820 time->tv_sec = 0;
2821 time->tv_nsec = 0;
2822 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2823 return -EIO;
2824 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2825 status = decode_attr_time(xdr, time);
2826 if (status == 0)
2827 status = NFS_ATTR_FATTR_CTIME;
2828 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2830 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
2831 return status;
2834 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2836 int status = 0;
2838 time->tv_sec = 0;
2839 time->tv_nsec = 0;
2840 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2841 return -EIO;
2842 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2843 status = decode_attr_time(xdr, time);
2844 if (status == 0)
2845 status = NFS_ATTR_FATTR_MTIME;
2846 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2848 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
2849 return status;
2852 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2854 unsigned int attrwords = XDR_QUADLEN(attrlen);
2855 unsigned int nwords = xdr->p - savep;
2857 if (unlikely(attrwords != nwords)) {
2858 dprintk("%s: server returned incorrect attribute length: "
2859 "%u %c %u\n",
2860 __func__,
2861 attrwords << 2,
2862 (attrwords < nwords) ? '<' : '>',
2863 nwords << 2);
2864 return -EIO;
2866 return 0;
2869 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2871 __be32 *p;
2873 READ_BUF(20);
2874 READ32(cinfo->atomic);
2875 READ64(cinfo->before);
2876 READ64(cinfo->after);
2877 return 0;
2880 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2882 __be32 *p;
2883 uint32_t supp, acc;
2884 int status;
2886 status = decode_op_hdr(xdr, OP_ACCESS);
2887 if (status)
2888 return status;
2889 READ_BUF(8);
2890 READ32(supp);
2891 READ32(acc);
2892 access->supported = supp;
2893 access->access = acc;
2894 return 0;
2897 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2899 __be32 *p;
2900 int status;
2902 status = decode_op_hdr(xdr, OP_CLOSE);
2903 if (status != -EIO)
2904 nfs_increment_open_seqid(status, res->seqid);
2905 if (status)
2906 return status;
2907 READ_BUF(NFS4_STATEID_SIZE);
2908 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
2909 return 0;
2912 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2914 __be32 *p;
2915 int status;
2917 status = decode_op_hdr(xdr, OP_COMMIT);
2918 if (status)
2919 return status;
2920 READ_BUF(8);
2921 COPYMEM(res->verf->verifier, 8);
2922 return 0;
2925 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2927 __be32 *p;
2928 uint32_t bmlen;
2929 int status;
2931 status = decode_op_hdr(xdr, OP_CREATE);
2932 if (status)
2933 return status;
2934 if ((status = decode_change_info(xdr, cinfo)))
2935 return status;
2936 READ_BUF(4);
2937 READ32(bmlen);
2938 READ_BUF(bmlen << 2);
2939 return 0;
2942 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2944 __be32 *savep;
2945 uint32_t attrlen, bitmap[2] = {0};
2946 int status;
2948 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2949 goto xdr_error;
2950 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2951 goto xdr_error;
2952 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2953 goto xdr_error;
2954 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2955 goto xdr_error;
2956 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2957 goto xdr_error;
2958 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2959 goto xdr_error;
2960 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2961 goto xdr_error;
2962 status = verify_attr_len(xdr, savep, attrlen);
2963 xdr_error:
2964 dprintk("%s: xdr returned %d!\n", __func__, -status);
2965 return status;
2968 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2970 __be32 *savep;
2971 uint32_t attrlen, bitmap[2] = {0};
2972 int status;
2974 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2975 goto xdr_error;
2976 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2977 goto xdr_error;
2978 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2979 goto xdr_error;
2981 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2982 goto xdr_error;
2983 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2984 goto xdr_error;
2985 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2986 goto xdr_error;
2987 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2988 goto xdr_error;
2989 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2990 goto xdr_error;
2991 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2992 goto xdr_error;
2994 status = verify_attr_len(xdr, savep, attrlen);
2995 xdr_error:
2996 dprintk("%s: xdr returned %d!\n", __func__, -status);
2997 return status;
3000 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3002 __be32 *savep;
3003 uint32_t attrlen, bitmap[2] = {0};
3004 int status;
3006 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3007 goto xdr_error;
3008 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3009 goto xdr_error;
3010 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3011 goto xdr_error;
3013 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3014 goto xdr_error;
3015 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3016 goto xdr_error;
3018 status = verify_attr_len(xdr, savep, attrlen);
3019 xdr_error:
3020 dprintk("%s: xdr returned %d!\n", __func__, -status);
3021 return status;
3024 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3026 __be32 *savep;
3027 uint32_t attrlen,
3028 bitmap[2] = {0},
3029 type;
3030 int status;
3031 umode_t fmode = 0;
3032 uint64_t fileid;
3034 status = decode_op_hdr(xdr, OP_GETATTR);
3035 if (status < 0)
3036 goto xdr_error;
3038 status = decode_attr_bitmap(xdr, bitmap);
3039 if (status < 0)
3040 goto xdr_error;
3042 status = decode_attr_length(xdr, &attrlen, &savep);
3043 if (status < 0)
3044 goto xdr_error;
3047 status = decode_attr_type(xdr, bitmap, &type);
3048 if (status < 0)
3049 goto xdr_error;
3050 fattr->mode = 0;
3051 if (status != 0) {
3052 fattr->mode |= nfs_type2fmt[type];
3053 fattr->valid |= status;
3056 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3057 if (status < 0)
3058 goto xdr_error;
3059 fattr->valid |= status;
3061 status = decode_attr_size(xdr, bitmap, &fattr->size);
3062 if (status < 0)
3063 goto xdr_error;
3064 fattr->valid |= status;
3066 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3067 if (status < 0)
3068 goto xdr_error;
3069 fattr->valid |= status;
3071 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3072 if (status < 0)
3073 goto xdr_error;
3074 fattr->valid |= status;
3076 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3077 struct nfs4_fs_locations,
3078 fattr));
3079 if (status < 0)
3080 goto xdr_error;
3081 fattr->valid |= status;
3083 status = decode_attr_mode(xdr, bitmap, &fmode);
3084 if (status < 0)
3085 goto xdr_error;
3086 if (status != 0) {
3087 fattr->mode |= fmode;
3088 fattr->valid |= status;
3091 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3092 if (status < 0)
3093 goto xdr_error;
3094 fattr->valid |= status;
3096 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3097 if (status < 0)
3098 goto xdr_error;
3099 fattr->valid |= status;
3101 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3102 if (status < 0)
3103 goto xdr_error;
3104 fattr->valid |= status;
3106 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3107 if (status < 0)
3108 goto xdr_error;
3109 fattr->valid |= status;
3111 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3112 if (status < 0)
3113 goto xdr_error;
3114 fattr->valid |= status;
3116 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3117 if (status < 0)
3118 goto xdr_error;
3119 fattr->valid |= status;
3121 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3122 if (status < 0)
3123 goto xdr_error;
3124 fattr->valid |= status;
3126 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3127 if (status < 0)
3128 goto xdr_error;
3129 fattr->valid |= status;
3131 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3132 if (status < 0)
3133 goto xdr_error;
3134 if (status != 0 && !(fattr->valid & status)) {
3135 fattr->fileid = fileid;
3136 fattr->valid |= status;
3139 status = verify_attr_len(xdr, savep, attrlen);
3140 xdr_error:
3141 dprintk("%s: xdr returned %d\n", __func__, -status);
3142 return status;
3146 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3148 __be32 *savep;
3149 uint32_t attrlen, bitmap[2];
3150 int status;
3152 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3153 goto xdr_error;
3154 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3155 goto xdr_error;
3156 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3157 goto xdr_error;
3159 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3161 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3162 goto xdr_error;
3163 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3164 goto xdr_error;
3165 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3166 goto xdr_error;
3167 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3168 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3169 goto xdr_error;
3170 fsinfo->wtpref = fsinfo->wtmax;
3172 status = verify_attr_len(xdr, savep, attrlen);
3173 xdr_error:
3174 dprintk("%s: xdr returned %d!\n", __func__, -status);
3175 return status;
3178 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3180 __be32 *p;
3181 uint32_t len;
3182 int status;
3184 /* Zero handle first to allow comparisons */
3185 memset(fh, 0, sizeof(*fh));
3187 status = decode_op_hdr(xdr, OP_GETFH);
3188 if (status)
3189 return status;
3191 READ_BUF(4);
3192 READ32(len);
3193 if (len > NFS4_FHSIZE)
3194 return -EIO;
3195 fh->size = len;
3196 READ_BUF(len);
3197 COPYMEM(fh->data, len);
3198 return 0;
3201 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3203 int status;
3205 status = decode_op_hdr(xdr, OP_LINK);
3206 if (status)
3207 return status;
3208 return decode_change_info(xdr, cinfo);
3212 * We create the owner, so we know a proper owner.id length is 4.
3214 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3216 uint64_t offset, length, clientid;
3217 __be32 *p;
3218 uint32_t namelen, type;
3220 READ_BUF(32);
3221 READ64(offset);
3222 READ64(length);
3223 READ32(type);
3224 if (fl != NULL) {
3225 fl->fl_start = (loff_t)offset;
3226 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3227 if (length == ~(uint64_t)0)
3228 fl->fl_end = OFFSET_MAX;
3229 fl->fl_type = F_WRLCK;
3230 if (type & 1)
3231 fl->fl_type = F_RDLCK;
3232 fl->fl_pid = 0;
3234 READ64(clientid);
3235 READ32(namelen);
3236 READ_BUF(namelen);
3237 return -NFS4ERR_DENIED;
3240 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3242 __be32 *p;
3243 int status;
3245 status = decode_op_hdr(xdr, OP_LOCK);
3246 if (status == -EIO)
3247 goto out;
3248 if (status == 0) {
3249 READ_BUF(NFS4_STATEID_SIZE);
3250 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3251 } else if (status == -NFS4ERR_DENIED)
3252 status = decode_lock_denied(xdr, NULL);
3253 if (res->open_seqid != NULL)
3254 nfs_increment_open_seqid(status, res->open_seqid);
3255 nfs_increment_lock_seqid(status, res->lock_seqid);
3256 out:
3257 return status;
3260 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3262 int status;
3263 status = decode_op_hdr(xdr, OP_LOCKT);
3264 if (status == -NFS4ERR_DENIED)
3265 return decode_lock_denied(xdr, res->denied);
3266 return status;
3269 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3271 __be32 *p;
3272 int status;
3274 status = decode_op_hdr(xdr, OP_LOCKU);
3275 if (status != -EIO)
3276 nfs_increment_lock_seqid(status, res->seqid);
3277 if (status == 0) {
3278 READ_BUF(NFS4_STATEID_SIZE);
3279 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3281 return status;
3284 static int decode_lookup(struct xdr_stream *xdr)
3286 return decode_op_hdr(xdr, OP_LOOKUP);
3289 /* This is too sick! */
3290 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3292 __be32 *p;
3293 uint32_t limit_type, nblocks, blocksize;
3295 READ_BUF(12);
3296 READ32(limit_type);
3297 switch (limit_type) {
3298 case 1:
3299 READ64(*maxsize);
3300 break;
3301 case 2:
3302 READ32(nblocks);
3303 READ32(blocksize);
3304 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3306 return 0;
3309 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3311 __be32 *p;
3312 uint32_t delegation_type;
3314 READ_BUF(4);
3315 READ32(delegation_type);
3316 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3317 res->delegation_type = 0;
3318 return 0;
3320 READ_BUF(NFS4_STATEID_SIZE+4);
3321 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3322 READ32(res->do_recall);
3324 switch (delegation_type) {
3325 case NFS4_OPEN_DELEGATE_READ:
3326 res->delegation_type = FMODE_READ;
3327 break;
3328 case NFS4_OPEN_DELEGATE_WRITE:
3329 res->delegation_type = FMODE_WRITE|FMODE_READ;
3330 if (decode_space_limit(xdr, &res->maxsize) < 0)
3331 return -EIO;
3333 return decode_ace(xdr, NULL, res->server->nfs_client);
3336 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3338 __be32 *p;
3339 uint32_t savewords, bmlen, i;
3340 int status;
3342 status = decode_op_hdr(xdr, OP_OPEN);
3343 if (status != -EIO)
3344 nfs_increment_open_seqid(status, res->seqid);
3345 if (status)
3346 return status;
3347 READ_BUF(NFS4_STATEID_SIZE);
3348 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3350 decode_change_info(xdr, &res->cinfo);
3352 READ_BUF(8);
3353 READ32(res->rflags);
3354 READ32(bmlen);
3355 if (bmlen > 10)
3356 goto xdr_error;
3358 READ_BUF(bmlen << 2);
3359 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3360 for (i = 0; i < savewords; ++i)
3361 READ32(res->attrset[i]);
3362 for (; i < NFS4_BITMAP_SIZE; i++)
3363 res->attrset[i] = 0;
3365 return decode_delegation(xdr, res);
3366 xdr_error:
3367 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
3368 return -EIO;
3371 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3373 __be32 *p;
3374 int status;
3376 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3377 if (status != -EIO)
3378 nfs_increment_open_seqid(status, res->seqid);
3379 if (status)
3380 return status;
3381 READ_BUF(NFS4_STATEID_SIZE);
3382 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3383 return 0;
3386 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3388 __be32 *p;
3389 int status;
3391 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3392 if (status != -EIO)
3393 nfs_increment_open_seqid(status, res->seqid);
3394 if (status)
3395 return status;
3396 READ_BUF(NFS4_STATEID_SIZE);
3397 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3398 return 0;
3401 static int decode_putfh(struct xdr_stream *xdr)
3403 return decode_op_hdr(xdr, OP_PUTFH);
3406 static int decode_putrootfh(struct xdr_stream *xdr)
3408 return decode_op_hdr(xdr, OP_PUTROOTFH);
3411 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3413 struct kvec *iov = req->rq_rcv_buf.head;
3414 __be32 *p;
3415 uint32_t count, eof, recvd, hdrlen;
3416 int status;
3418 status = decode_op_hdr(xdr, OP_READ);
3419 if (status)
3420 return status;
3421 READ_BUF(8);
3422 READ32(eof);
3423 READ32(count);
3424 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3425 recvd = req->rq_rcv_buf.len - hdrlen;
3426 if (count > recvd) {
3427 dprintk("NFS: server cheating in read reply: "
3428 "count %u > recvd %u\n", count, recvd);
3429 count = recvd;
3430 eof = 0;
3432 xdr_read_pages(xdr, count);
3433 res->eof = eof;
3434 res->count = count;
3435 return 0;
3438 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3440 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3441 struct page *page = *rcvbuf->pages;
3442 struct kvec *iov = rcvbuf->head;
3443 size_t hdrlen;
3444 u32 recvd, pglen = rcvbuf->page_len;
3445 __be32 *end, *entry, *p, *kaddr;
3446 unsigned int nr = 0;
3447 int status;
3449 status = decode_op_hdr(xdr, OP_READDIR);
3450 if (status)
3451 return status;
3452 READ_BUF(8);
3453 COPYMEM(readdir->verifier.data, 8);
3454 dprintk("%s: verifier = %08x:%08x\n",
3455 __func__,
3456 ((u32 *)readdir->verifier.data)[0],
3457 ((u32 *)readdir->verifier.data)[1]);
3460 hdrlen = (char *) p - (char *) iov->iov_base;
3461 recvd = rcvbuf->len - hdrlen;
3462 if (pglen > recvd)
3463 pglen = recvd;
3464 xdr_read_pages(xdr, pglen);
3466 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3467 kaddr = p = kmap_atomic(page, KM_USER0);
3468 end = p + ((pglen + readdir->pgbase) >> 2);
3469 entry = p;
3471 /* Make sure the packet actually has a value_follows and EOF entry */
3472 if ((entry + 1) > end)
3473 goto short_pkt;
3475 for (; *p++; nr++) {
3476 u32 len, attrlen, xlen;
3477 if (end - p < 3)
3478 goto short_pkt;
3479 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3480 p += 2; /* cookie */
3481 len = ntohl(*p++); /* filename length */
3482 if (len > NFS4_MAXNAMLEN) {
3483 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3484 len);
3485 goto err_unmap;
3487 xlen = XDR_QUADLEN(len);
3488 if (end - p < xlen + 1)
3489 goto short_pkt;
3490 dprintk("filename = %*s\n", len, (char *)p);
3491 p += xlen;
3492 len = ntohl(*p++); /* bitmap length */
3493 if (end - p < len + 1)
3494 goto short_pkt;
3495 p += len;
3496 attrlen = XDR_QUADLEN(ntohl(*p++));
3497 if (end - p < attrlen + 2)
3498 goto short_pkt;
3499 p += attrlen; /* attributes */
3500 entry = p;
3503 * Apparently some server sends responses that are a valid size, but
3504 * contain no entries, and have value_follows==0 and EOF==0. For
3505 * those, just set the EOF marker.
3507 if (!nr && entry[1] == 0) {
3508 dprintk("NFS: readdir reply truncated!\n");
3509 entry[1] = 1;
3511 out:
3512 kunmap_atomic(kaddr, KM_USER0);
3513 return 0;
3514 short_pkt:
3516 * When we get a short packet there are 2 possibilities. We can
3517 * return an error, or fix up the response to look like a valid
3518 * response and return what we have so far. If there are no
3519 * entries and the packet was short, then return -EIO. If there
3520 * are valid entries in the response, return them and pretend that
3521 * the call was successful, but incomplete. The caller can retry the
3522 * readdir starting at the last cookie.
3524 dprintk("%s: short packet at entry %d\n", __func__, nr);
3525 entry[0] = entry[1] = 0;
3526 if (nr)
3527 goto out;
3528 err_unmap:
3529 kunmap_atomic(kaddr, KM_USER0);
3530 return -errno_NFSERR_IO;
3533 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3535 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3536 struct kvec *iov = rcvbuf->head;
3537 size_t hdrlen;
3538 u32 len, recvd;
3539 __be32 *p;
3540 char *kaddr;
3541 int status;
3543 status = decode_op_hdr(xdr, OP_READLINK);
3544 if (status)
3545 return status;
3547 /* Convert length of symlink */
3548 READ_BUF(4);
3549 READ32(len);
3550 if (len >= rcvbuf->page_len || len <= 0) {
3551 dprintk("nfs: server returned giant symlink!\n");
3552 return -ENAMETOOLONG;
3554 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3555 recvd = req->rq_rcv_buf.len - hdrlen;
3556 if (recvd < len) {
3557 dprintk("NFS: server cheating in readlink reply: "
3558 "count %u > recvd %u\n", len, recvd);
3559 return -EIO;
3561 xdr_read_pages(xdr, len);
3563 * The XDR encode routine has set things up so that
3564 * the link text will be copied directly into the
3565 * buffer. We just have to do overflow-checking,
3566 * and and null-terminate the text (the VFS expects
3567 * null-termination).
3569 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3570 kaddr[len+rcvbuf->page_base] = '\0';
3571 kunmap_atomic(kaddr, KM_USER0);
3572 return 0;
3575 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3577 int status;
3579 status = decode_op_hdr(xdr, OP_REMOVE);
3580 if (status)
3581 goto out;
3582 status = decode_change_info(xdr, cinfo);
3583 out:
3584 return status;
3587 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3588 struct nfs4_change_info *new_cinfo)
3590 int status;
3592 status = decode_op_hdr(xdr, OP_RENAME);
3593 if (status)
3594 goto out;
3595 if ((status = decode_change_info(xdr, old_cinfo)))
3596 goto out;
3597 status = decode_change_info(xdr, new_cinfo);
3598 out:
3599 return status;
3602 static int decode_renew(struct xdr_stream *xdr)
3604 return decode_op_hdr(xdr, OP_RENEW);
3607 static int
3608 decode_restorefh(struct xdr_stream *xdr)
3610 return decode_op_hdr(xdr, OP_RESTOREFH);
3613 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3614 size_t *acl_len)
3616 __be32 *savep;
3617 uint32_t attrlen,
3618 bitmap[2] = {0};
3619 struct kvec *iov = req->rq_rcv_buf.head;
3620 int status;
3622 *acl_len = 0;
3623 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3624 goto out;
3625 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3626 goto out;
3627 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3628 goto out;
3630 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3631 return -EIO;
3632 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3633 size_t hdrlen;
3634 u32 recvd;
3636 /* We ignore &savep and don't do consistency checks on
3637 * the attr length. Let userspace figure it out.... */
3638 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3639 recvd = req->rq_rcv_buf.len - hdrlen;
3640 if (attrlen > recvd) {
3641 dprintk("NFS: server cheating in getattr"
3642 " acl reply: attrlen %u > recvd %u\n",
3643 attrlen, recvd);
3644 return -EINVAL;
3646 xdr_read_pages(xdr, attrlen);
3647 *acl_len = attrlen;
3648 } else
3649 status = -EOPNOTSUPP;
3651 out:
3652 return status;
3655 static int
3656 decode_savefh(struct xdr_stream *xdr)
3658 return decode_op_hdr(xdr, OP_SAVEFH);
3661 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3663 __be32 *p;
3664 uint32_t bmlen;
3665 int status;
3667 status = decode_op_hdr(xdr, OP_SETATTR);
3668 if (status)
3669 return status;
3670 READ_BUF(4);
3671 READ32(bmlen);
3672 READ_BUF(bmlen << 2);
3673 return 0;
3676 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3678 __be32 *p;
3679 uint32_t opnum;
3680 int32_t nfserr;
3682 READ_BUF(8);
3683 READ32(opnum);
3684 if (opnum != OP_SETCLIENTID) {
3685 dprintk("nfs: decode_setclientid: Server returned operation"
3686 " %d\n", opnum);
3687 return -EIO;
3689 READ32(nfserr);
3690 if (nfserr == NFS_OK) {
3691 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3692 READ64(clp->cl_clientid);
3693 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3694 } else if (nfserr == NFSERR_CLID_INUSE) {
3695 uint32_t len;
3697 /* skip netid string */
3698 READ_BUF(4);
3699 READ32(len);
3700 READ_BUF(len);
3702 /* skip uaddr string */
3703 READ_BUF(4);
3704 READ32(len);
3705 READ_BUF(len);
3706 return -NFSERR_CLID_INUSE;
3707 } else
3708 return nfs4_stat_to_errno(nfserr);
3710 return 0;
3713 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3715 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3718 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3720 __be32 *p;
3721 int status;
3723 status = decode_op_hdr(xdr, OP_WRITE);
3724 if (status)
3725 return status;
3727 READ_BUF(16);
3728 READ32(res->count);
3729 READ32(res->verf->committed);
3730 COPYMEM(res->verf->verifier, 8);
3731 return 0;
3734 static int decode_delegreturn(struct xdr_stream *xdr)
3736 return decode_op_hdr(xdr, OP_DELEGRETURN);
3740 * END OF "GENERIC" DECODE ROUTINES.
3744 * Decode OPEN_DOWNGRADE response
3746 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3748 struct xdr_stream xdr;
3749 struct compound_hdr hdr;
3750 int status;
3752 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3753 status = decode_compound_hdr(&xdr, &hdr);
3754 if (status)
3755 goto out;
3756 status = decode_putfh(&xdr);
3757 if (status)
3758 goto out;
3759 status = decode_open_downgrade(&xdr, res);
3760 if (status != 0)
3761 goto out;
3762 decode_getfattr(&xdr, res->fattr, res->server);
3763 out:
3764 return status;
3768 * Decode ACCESS response
3770 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3772 struct xdr_stream xdr;
3773 struct compound_hdr hdr;
3774 int status;
3776 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3777 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3778 goto out;
3779 status = decode_putfh(&xdr);
3780 if (status != 0)
3781 goto out;
3782 status = decode_access(&xdr, res);
3783 if (status != 0)
3784 goto out;
3785 decode_getfattr(&xdr, res->fattr, res->server);
3786 out:
3787 return status;
3791 * Decode LOOKUP response
3793 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3795 struct xdr_stream xdr;
3796 struct compound_hdr hdr;
3797 int status;
3799 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3800 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3801 goto out;
3802 if ((status = decode_putfh(&xdr)) != 0)
3803 goto out;
3804 if ((status = decode_lookup(&xdr)) != 0)
3805 goto out;
3806 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3807 goto out;
3808 status = decode_getfattr(&xdr, res->fattr, res->server);
3809 out:
3810 return status;
3814 * Decode LOOKUP_ROOT response
3816 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3818 struct xdr_stream xdr;
3819 struct compound_hdr hdr;
3820 int status;
3822 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3823 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3824 goto out;
3825 if ((status = decode_putrootfh(&xdr)) != 0)
3826 goto out;
3827 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3828 status = decode_getfattr(&xdr, res->fattr, res->server);
3829 out:
3830 return status;
3834 * Decode REMOVE response
3836 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
3838 struct xdr_stream xdr;
3839 struct compound_hdr hdr;
3840 int status;
3842 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3843 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3844 goto out;
3845 if ((status = decode_putfh(&xdr)) != 0)
3846 goto out;
3847 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3848 goto out;
3849 decode_getfattr(&xdr, &res->dir_attr, res->server);
3850 out:
3851 return status;
3855 * Decode RENAME response
3857 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3859 struct xdr_stream xdr;
3860 struct compound_hdr hdr;
3861 int status;
3863 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3864 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3865 goto out;
3866 if ((status = decode_putfh(&xdr)) != 0)
3867 goto out;
3868 if ((status = decode_savefh(&xdr)) != 0)
3869 goto out;
3870 if ((status = decode_putfh(&xdr)) != 0)
3871 goto out;
3872 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3873 goto out;
3874 /* Current FH is target directory */
3875 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3876 goto out;
3877 if ((status = decode_restorefh(&xdr)) != 0)
3878 goto out;
3879 decode_getfattr(&xdr, res->old_fattr, res->server);
3880 out:
3881 return status;
3885 * Decode LINK response
3887 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3889 struct xdr_stream xdr;
3890 struct compound_hdr hdr;
3891 int status;
3893 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3894 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3895 goto out;
3896 if ((status = decode_putfh(&xdr)) != 0)
3897 goto out;
3898 if ((status = decode_savefh(&xdr)) != 0)
3899 goto out;
3900 if ((status = decode_putfh(&xdr)) != 0)
3901 goto out;
3902 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3903 goto out;
3905 * Note order: OP_LINK leaves the directory as the current
3906 * filehandle.
3908 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3909 goto out;
3910 if ((status = decode_restorefh(&xdr)) != 0)
3911 goto out;
3912 decode_getfattr(&xdr, res->fattr, res->server);
3913 out:
3914 return status;
3918 * Decode CREATE response
3920 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3922 struct xdr_stream xdr;
3923 struct compound_hdr hdr;
3924 int status;
3926 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3927 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3928 goto out;
3929 if ((status = decode_putfh(&xdr)) != 0)
3930 goto out;
3931 if ((status = decode_savefh(&xdr)) != 0)
3932 goto out;
3933 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3934 goto out;
3935 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3936 goto out;
3937 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3938 goto out;
3939 if ((status = decode_restorefh(&xdr)) != 0)
3940 goto out;
3941 decode_getfattr(&xdr, res->dir_fattr, res->server);
3942 out:
3943 return status;
3947 * Decode SYMLINK response
3949 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3951 return nfs4_xdr_dec_create(rqstp, p, res);
3955 * Decode GETATTR response
3957 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3959 struct xdr_stream xdr;
3960 struct compound_hdr hdr;
3961 int status;
3963 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3964 status = decode_compound_hdr(&xdr, &hdr);
3965 if (status)
3966 goto out;
3967 status = decode_putfh(&xdr);
3968 if (status)
3969 goto out;
3970 status = decode_getfattr(&xdr, res->fattr, res->server);
3971 out:
3972 return status;
3976 * Encode an SETACL request
3978 static int
3979 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3981 struct xdr_stream xdr;
3982 struct compound_hdr hdr = {
3983 .nops = 0,
3985 int status;
3987 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3988 encode_compound_hdr(&xdr, &hdr);
3989 encode_putfh(&xdr, args->fh, &hdr);
3990 status = encode_setacl(&xdr, args, &hdr);
3991 encode_nops(&hdr);
3992 return status;
3996 * Decode SETACL response
3998 static int
3999 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
4001 struct xdr_stream xdr;
4002 struct compound_hdr hdr;
4003 int status;
4005 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4006 status = decode_compound_hdr(&xdr, &hdr);
4007 if (status)
4008 goto out;
4009 status = decode_putfh(&xdr);
4010 if (status)
4011 goto out;
4012 status = decode_setattr(&xdr, res);
4013 out:
4014 return status;
4018 * Decode GETACL response
4020 static int
4021 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
4023 struct xdr_stream xdr;
4024 struct compound_hdr hdr;
4025 int status;
4027 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4028 status = decode_compound_hdr(&xdr, &hdr);
4029 if (status)
4030 goto out;
4031 status = decode_putfh(&xdr);
4032 if (status)
4033 goto out;
4034 status = decode_getacl(&xdr, rqstp, acl_len);
4036 out:
4037 return status;
4041 * Decode CLOSE response
4043 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4045 struct xdr_stream xdr;
4046 struct compound_hdr hdr;
4047 int status;
4049 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4050 status = decode_compound_hdr(&xdr, &hdr);
4051 if (status)
4052 goto out;
4053 status = decode_putfh(&xdr);
4054 if (status)
4055 goto out;
4056 status = decode_close(&xdr, res);
4057 if (status != 0)
4058 goto out;
4060 * Note: Server may do delete on close for this file
4061 * in which case the getattr call will fail with
4062 * an ESTALE error. Shouldn't be a problem,
4063 * though, since fattr->valid will remain unset.
4065 decode_getfattr(&xdr, res->fattr, res->server);
4066 out:
4067 return status;
4071 * Decode OPEN response
4073 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4075 struct xdr_stream xdr;
4076 struct compound_hdr hdr;
4077 int status;
4079 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4080 status = decode_compound_hdr(&xdr, &hdr);
4081 if (status)
4082 goto out;
4083 status = decode_putfh(&xdr);
4084 if (status)
4085 goto out;
4086 status = decode_savefh(&xdr);
4087 if (status)
4088 goto out;
4089 status = decode_open(&xdr, res);
4090 if (status)
4091 goto out;
4092 if (decode_getfh(&xdr, &res->fh) != 0)
4093 goto out;
4094 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4095 goto out;
4096 if (decode_restorefh(&xdr) != 0)
4097 goto out;
4098 decode_getfattr(&xdr, res->dir_attr, res->server);
4099 out:
4100 return status;
4104 * Decode OPEN_CONFIRM response
4106 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4108 struct xdr_stream xdr;
4109 struct compound_hdr hdr;
4110 int status;
4112 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4113 status = decode_compound_hdr(&xdr, &hdr);
4114 if (status)
4115 goto out;
4116 status = decode_putfh(&xdr);
4117 if (status)
4118 goto out;
4119 status = decode_open_confirm(&xdr, res);
4120 out:
4121 return status;
4125 * Decode OPEN response
4127 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4129 struct xdr_stream xdr;
4130 struct compound_hdr hdr;
4131 int status;
4133 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4134 status = decode_compound_hdr(&xdr, &hdr);
4135 if (status)
4136 goto out;
4137 status = decode_putfh(&xdr);
4138 if (status)
4139 goto out;
4140 status = decode_open(&xdr, res);
4141 if (status)
4142 goto out;
4143 decode_getfattr(&xdr, res->f_attr, res->server);
4144 out:
4145 return status;
4149 * Decode SETATTR response
4151 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4153 struct xdr_stream xdr;
4154 struct compound_hdr hdr;
4155 int status;
4157 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4158 status = decode_compound_hdr(&xdr, &hdr);
4159 if (status)
4160 goto out;
4161 status = decode_putfh(&xdr);
4162 if (status)
4163 goto out;
4164 status = decode_setattr(&xdr, res);
4165 if (status)
4166 goto out;
4167 decode_getfattr(&xdr, res->fattr, res->server);
4168 out:
4169 return status;
4173 * Decode LOCK response
4175 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4177 struct xdr_stream xdr;
4178 struct compound_hdr hdr;
4179 int status;
4181 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4182 status = decode_compound_hdr(&xdr, &hdr);
4183 if (status)
4184 goto out;
4185 status = decode_putfh(&xdr);
4186 if (status)
4187 goto out;
4188 status = decode_lock(&xdr, res);
4189 out:
4190 return status;
4194 * Decode LOCKT response
4196 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4198 struct xdr_stream xdr;
4199 struct compound_hdr hdr;
4200 int status;
4202 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4203 status = decode_compound_hdr(&xdr, &hdr);
4204 if (status)
4205 goto out;
4206 status = decode_putfh(&xdr);
4207 if (status)
4208 goto out;
4209 status = decode_lockt(&xdr, res);
4210 out:
4211 return status;
4215 * Decode LOCKU response
4217 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4219 struct xdr_stream xdr;
4220 struct compound_hdr hdr;
4221 int status;
4223 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4224 status = decode_compound_hdr(&xdr, &hdr);
4225 if (status)
4226 goto out;
4227 status = decode_putfh(&xdr);
4228 if (status)
4229 goto out;
4230 status = decode_locku(&xdr, res);
4231 out:
4232 return status;
4236 * Decode READLINK response
4238 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
4240 struct xdr_stream xdr;
4241 struct compound_hdr hdr;
4242 int status;
4244 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4245 status = decode_compound_hdr(&xdr, &hdr);
4246 if (status)
4247 goto out;
4248 status = decode_putfh(&xdr);
4249 if (status)
4250 goto out;
4251 status = decode_readlink(&xdr, rqstp);
4252 out:
4253 return status;
4257 * Decode READDIR response
4259 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4261 struct xdr_stream xdr;
4262 struct compound_hdr hdr;
4263 int status;
4265 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4266 status = decode_compound_hdr(&xdr, &hdr);
4267 if (status)
4268 goto out;
4269 status = decode_putfh(&xdr);
4270 if (status)
4271 goto out;
4272 status = decode_readdir(&xdr, rqstp, res);
4273 out:
4274 return status;
4278 * Decode Read response
4280 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4282 struct xdr_stream xdr;
4283 struct compound_hdr hdr;
4284 int status;
4286 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4287 status = decode_compound_hdr(&xdr, &hdr);
4288 if (status)
4289 goto out;
4290 status = decode_putfh(&xdr);
4291 if (status)
4292 goto out;
4293 status = decode_read(&xdr, rqstp, res);
4294 if (!status)
4295 status = res->count;
4296 out:
4297 return status;
4301 * Decode WRITE response
4303 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4305 struct xdr_stream xdr;
4306 struct compound_hdr hdr;
4307 int status;
4309 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4310 status = decode_compound_hdr(&xdr, &hdr);
4311 if (status)
4312 goto out;
4313 status = decode_putfh(&xdr);
4314 if (status)
4315 goto out;
4316 status = decode_write(&xdr, res);
4317 if (status)
4318 goto out;
4319 decode_getfattr(&xdr, res->fattr, res->server);
4320 if (!status)
4321 status = res->count;
4322 out:
4323 return status;
4327 * Decode COMMIT response
4329 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4331 struct xdr_stream xdr;
4332 struct compound_hdr hdr;
4333 int status;
4335 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4336 status = decode_compound_hdr(&xdr, &hdr);
4337 if (status)
4338 goto out;
4339 status = decode_putfh(&xdr);
4340 if (status)
4341 goto out;
4342 status = decode_commit(&xdr, res);
4343 if (status)
4344 goto out;
4345 decode_getfattr(&xdr, res->fattr, res->server);
4346 out:
4347 return status;
4351 * FSINFO request
4353 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4355 struct xdr_stream xdr;
4356 struct compound_hdr hdr;
4357 int status;
4359 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4360 status = decode_compound_hdr(&xdr, &hdr);
4361 if (!status)
4362 status = decode_putfh(&xdr);
4363 if (!status)
4364 status = decode_fsinfo(&xdr, fsinfo);
4365 return status;
4369 * PATHCONF request
4371 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
4373 struct xdr_stream xdr;
4374 struct compound_hdr hdr;
4375 int status;
4377 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4378 status = decode_compound_hdr(&xdr, &hdr);
4379 if (!status)
4380 status = decode_putfh(&xdr);
4381 if (!status)
4382 status = decode_pathconf(&xdr, pathconf);
4383 return status;
4387 * STATFS request
4389 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
4391 struct xdr_stream xdr;
4392 struct compound_hdr hdr;
4393 int status;
4395 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4396 status = decode_compound_hdr(&xdr, &hdr);
4397 if (!status)
4398 status = decode_putfh(&xdr);
4399 if (!status)
4400 status = decode_statfs(&xdr, fsstat);
4401 return status;
4405 * GETATTR_BITMAP request
4407 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4409 struct xdr_stream xdr;
4410 struct compound_hdr hdr;
4411 int status;
4413 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4414 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4415 goto out;
4416 if ((status = decode_putfh(&xdr)) != 0)
4417 goto out;
4418 status = decode_server_caps(&xdr, res);
4419 out:
4420 return status;
4424 * Decode RENEW response
4426 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4428 struct xdr_stream xdr;
4429 struct compound_hdr hdr;
4430 int status;
4432 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4433 status = decode_compound_hdr(&xdr, &hdr);
4434 if (!status)
4435 status = decode_renew(&xdr);
4436 return status;
4440 * a SETCLIENTID request
4442 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4443 struct nfs_client *clp)
4445 struct xdr_stream xdr;
4446 struct compound_hdr hdr;
4447 int status;
4449 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4450 status = decode_compound_hdr(&xdr, &hdr);
4451 if (!status)
4452 status = decode_setclientid(&xdr, clp);
4453 return status;
4457 * a SETCLIENTID_CONFIRM request
4459 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4461 struct xdr_stream xdr;
4462 struct compound_hdr hdr;
4463 int status;
4465 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4466 status = decode_compound_hdr(&xdr, &hdr);
4467 if (!status)
4468 status = decode_setclientid_confirm(&xdr);
4469 if (!status)
4470 status = decode_putrootfh(&xdr);
4471 if (!status)
4472 status = decode_fsinfo(&xdr, fsinfo);
4473 return status;
4477 * DELEGRETURN request
4479 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4481 struct xdr_stream xdr;
4482 struct compound_hdr hdr;
4483 int status;
4485 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4486 status = decode_compound_hdr(&xdr, &hdr);
4487 if (status != 0)
4488 goto out;
4489 status = decode_putfh(&xdr);
4490 if (status != 0)
4491 goto out;
4492 status = decode_delegreturn(&xdr);
4493 decode_getfattr(&xdr, res->fattr, res->server);
4494 out:
4495 return status;
4499 * FS_LOCATIONS request
4501 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
4503 struct xdr_stream xdr;
4504 struct compound_hdr hdr;
4505 int status;
4507 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4508 status = decode_compound_hdr(&xdr, &hdr);
4509 if (status != 0)
4510 goto out;
4511 if ((status = decode_putfh(&xdr)) != 0)
4512 goto out;
4513 if ((status = decode_lookup(&xdr)) != 0)
4514 goto out;
4515 xdr_enter_page(&xdr, PAGE_SIZE);
4516 status = decode_getfattr(&xdr, &res->fattr, res->server);
4517 out:
4518 return status;
4521 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4523 uint32_t bitmap[2] = {0};
4524 uint32_t len;
4526 if (!*p++) {
4527 if (!*p)
4528 return ERR_PTR(-EAGAIN);
4529 entry->eof = 1;
4530 return ERR_PTR(-EBADCOOKIE);
4533 entry->prev_cookie = entry->cookie;
4534 p = xdr_decode_hyper(p, &entry->cookie);
4535 entry->len = ntohl(*p++);
4536 entry->name = (const char *) p;
4537 p += XDR_QUADLEN(entry->len);
4540 * In case the server doesn't return an inode number,
4541 * we fake one here. (We don't use inode number 0,
4542 * since glibc seems to choke on it...)
4544 entry->ino = 1;
4546 len = ntohl(*p++); /* bitmap length */
4547 if (len-- > 0) {
4548 bitmap[0] = ntohl(*p++);
4549 if (len-- > 0) {
4550 bitmap[1] = ntohl(*p++);
4551 p += len;
4554 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4555 if (len > 0) {
4556 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4557 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4558 /* Ignore the return value of rdattr_error for now */
4559 p++;
4560 len--;
4562 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4563 xdr_decode_hyper(p, &entry->ino);
4564 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4565 xdr_decode_hyper(p, &entry->ino);
4566 p += len;
4569 entry->eof = !p[0] && p[1];
4570 return p;
4574 * We need to translate between nfs status return values and
4575 * the local errno values which may not be the same.
4577 static struct {
4578 int stat;
4579 int errno;
4580 } nfs_errtbl[] = {
4581 { NFS4_OK, 0 },
4582 { NFS4ERR_PERM, -EPERM },
4583 { NFS4ERR_NOENT, -ENOENT },
4584 { NFS4ERR_IO, -errno_NFSERR_IO},
4585 { NFS4ERR_NXIO, -ENXIO },
4586 { NFS4ERR_ACCESS, -EACCES },
4587 { NFS4ERR_EXIST, -EEXIST },
4588 { NFS4ERR_XDEV, -EXDEV },
4589 { NFS4ERR_NOTDIR, -ENOTDIR },
4590 { NFS4ERR_ISDIR, -EISDIR },
4591 { NFS4ERR_INVAL, -EINVAL },
4592 { NFS4ERR_FBIG, -EFBIG },
4593 { NFS4ERR_NOSPC, -ENOSPC },
4594 { NFS4ERR_ROFS, -EROFS },
4595 { NFS4ERR_MLINK, -EMLINK },
4596 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4597 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4598 { NFS4ERR_DQUOT, -EDQUOT },
4599 { NFS4ERR_STALE, -ESTALE },
4600 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4601 { NFS4ERR_BADOWNER, -EINVAL },
4602 { NFS4ERR_BADNAME, -EINVAL },
4603 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4604 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4605 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4606 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4607 { NFS4ERR_BADTYPE, -EBADTYPE },
4608 { NFS4ERR_LOCKED, -EAGAIN },
4609 { NFS4ERR_RESOURCE, -EREMOTEIO },
4610 { NFS4ERR_SYMLINK, -ELOOP },
4611 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4612 { NFS4ERR_DEADLOCK, -EDEADLK },
4613 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
4614 * to be handled by a
4615 * middle-layer.
4617 { -1, -EIO }
4621 * Convert an NFS error code to a local one.
4622 * This one is used jointly by NFSv2 and NFSv3.
4624 static int
4625 nfs4_stat_to_errno(int stat)
4627 int i;
4628 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4629 if (nfs_errtbl[i].stat == stat)
4630 return nfs_errtbl[i].errno;
4632 if (stat <= 10000 || stat > 10100) {
4633 /* The server is looney tunes. */
4634 return -ESERVERFAULT;
4636 /* If we cannot translate the error, the recovery routines should
4637 * handle it.
4638 * Note: remaining NFSv4 error codes have values > 10000, so should
4639 * not conflict with native Linux error codes.
4641 return -stat;
4644 #define PROC(proc, argtype, restype) \
4645 [NFSPROC4_CLNT_##proc] = { \
4646 .p_proc = NFSPROC4_COMPOUND, \
4647 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4648 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4649 .p_arglen = NFS4_##argtype##_sz, \
4650 .p_replen = NFS4_##restype##_sz, \
4651 .p_statidx = NFSPROC4_CLNT_##proc, \
4652 .p_name = #proc, \
4655 struct rpc_procinfo nfs4_procedures[] = {
4656 PROC(READ, enc_read, dec_read),
4657 PROC(WRITE, enc_write, dec_write),
4658 PROC(COMMIT, enc_commit, dec_commit),
4659 PROC(OPEN, enc_open, dec_open),
4660 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4661 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4662 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4663 PROC(CLOSE, enc_close, dec_close),
4664 PROC(SETATTR, enc_setattr, dec_setattr),
4665 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4666 PROC(RENEW, enc_renew, dec_renew),
4667 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4668 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4669 PROC(LOCK, enc_lock, dec_lock),
4670 PROC(LOCKT, enc_lockt, dec_lockt),
4671 PROC(LOCKU, enc_locku, dec_locku),
4672 PROC(ACCESS, enc_access, dec_access),
4673 PROC(GETATTR, enc_getattr, dec_getattr),
4674 PROC(LOOKUP, enc_lookup, dec_lookup),
4675 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4676 PROC(REMOVE, enc_remove, dec_remove),
4677 PROC(RENAME, enc_rename, dec_rename),
4678 PROC(LINK, enc_link, dec_link),
4679 PROC(SYMLINK, enc_symlink, dec_symlink),
4680 PROC(CREATE, enc_create, dec_create),
4681 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4682 PROC(STATFS, enc_statfs, dec_statfs),
4683 PROC(READLINK, enc_readlink, dec_readlink),
4684 PROC(READDIR, enc_readdir, dec_readdir),
4685 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4686 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4687 PROC(GETACL, enc_getacl, dec_getacl),
4688 PROC(SETACL, enc_setacl, dec_setacl),
4689 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4692 struct rpc_version nfs_version4 = {
4693 .number = 4,
4694 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4695 .procs = nfs4_procedures
4699 * Local variables:
4700 * c-basic-offset: 8
4701 * End: