4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define owner_id_maxsz (1 + 1)
74 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
75 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
76 #define op_encode_hdr_maxsz (1)
77 #define op_decode_hdr_maxsz (2)
78 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
80 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
81 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
82 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
83 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
84 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
85 ((3+NFS4_FHSIZE) >> 2))
86 #define nfs4_fattr_bitmap_maxsz 3
87 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
88 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
89 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
90 /* This is based on getfattr, which uses the most attributes: */
91 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
92 3 + 3 + 3 + 2 * nfs4_name_maxsz))
93 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
94 nfs4_fattr_value_maxsz)
95 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
96 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
97 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
98 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
99 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
100 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
101 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
102 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
103 #define decode_renew_maxsz (op_decode_hdr_maxsz)
104 #define encode_setclientid_maxsz \
105 (op_encode_hdr_maxsz + \
106 4 /*server->ip_addr*/ + \
109 6 + (NFS4_VERIFIER_SIZE >> 2))
110 #define decode_setclientid_maxsz \
111 (op_decode_hdr_maxsz + \
113 1024) /* large value for CLID_INUSE */
114 #define encode_setclientid_confirm_maxsz \
115 (op_encode_hdr_maxsz + \
116 3 + (NFS4_VERIFIER_SIZE >> 2))
117 #define decode_setclientid_confirm_maxsz \
118 (op_decode_hdr_maxsz)
119 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
120 1 + ((3 + NFS4_FHSIZE) >> 2))
121 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
123 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
125 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
126 #define encode_link_maxsz (op_encode_hdr_maxsz + \
128 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
129 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
130 1 + nfs4_name_maxsz + \
133 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
134 #define encode_create_maxsz (op_encode_hdr_maxsz + \
135 2 + nfs4_name_maxsz + \
137 #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
138 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
139 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
140 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
141 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
142 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
143 encode_putfh_maxsz + \
144 op_encode_hdr_maxsz + 7)
145 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
146 decode_putfh_maxsz + \
147 op_decode_hdr_maxsz + 2)
148 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
149 encode_putfh_maxsz + \
151 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
152 decode_putfh_maxsz + \
154 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
155 encode_putfh_maxsz + \
156 op_encode_hdr_maxsz + 9)
157 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
158 decode_putfh_maxsz + \
159 op_decode_hdr_maxsz + 2)
160 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
161 encode_putfh_maxsz + \
162 op_encode_hdr_maxsz + 8 + \
163 encode_getattr_maxsz)
164 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
165 decode_putfh_maxsz + \
166 op_decode_hdr_maxsz + 4 + \
167 decode_getattr_maxsz)
168 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
169 encode_putfh_maxsz + \
170 op_encode_hdr_maxsz + 3 + \
171 encode_getattr_maxsz)
172 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
173 decode_putfh_maxsz + \
174 op_decode_hdr_maxsz + 2 + \
175 decode_getattr_maxsz)
176 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
177 encode_putfh_maxsz + \
178 op_encode_hdr_maxsz + \
180 encode_getattr_maxsz + \
182 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
183 decode_putfh_maxsz + \
184 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
185 decode_getattr_maxsz + \
187 #define NFS4_enc_open_confirm_sz \
188 (compound_encode_hdr_maxsz + \
189 encode_putfh_maxsz + \
190 op_encode_hdr_maxsz + 5)
191 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
192 decode_putfh_maxsz + \
193 op_decode_hdr_maxsz + 4)
194 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
195 encode_putfh_maxsz + \
196 op_encode_hdr_maxsz + \
198 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
199 decode_putfh_maxsz + \
200 op_decode_hdr_maxsz + \
202 #define NFS4_enc_open_downgrade_sz \
203 (compound_encode_hdr_maxsz + \
204 encode_putfh_maxsz + \
205 op_encode_hdr_maxsz + 7 + \
206 encode_getattr_maxsz)
207 #define NFS4_dec_open_downgrade_sz \
208 (compound_decode_hdr_maxsz + \
209 decode_putfh_maxsz + \
210 op_decode_hdr_maxsz + 4 + \
211 decode_getattr_maxsz)
212 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
213 encode_putfh_maxsz + \
214 op_encode_hdr_maxsz + 5 + \
215 encode_getattr_maxsz)
216 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
217 decode_putfh_maxsz + \
218 op_decode_hdr_maxsz + 4 + \
219 decode_getattr_maxsz)
220 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
221 encode_putfh_maxsz + \
222 op_encode_hdr_maxsz + 4 + \
224 encode_getattr_maxsz)
225 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
226 decode_putfh_maxsz + \
227 op_decode_hdr_maxsz + 3)
228 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
229 encode_putfh_maxsz + \
231 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
232 decode_putfh_maxsz + \
234 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
236 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
238 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
239 encode_setclientid_maxsz)
240 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
241 decode_setclientid_maxsz)
242 #define NFS4_enc_setclientid_confirm_sz \
243 (compound_encode_hdr_maxsz + \
244 encode_setclientid_confirm_maxsz + \
245 encode_putrootfh_maxsz + \
247 #define NFS4_dec_setclientid_confirm_sz \
248 (compound_decode_hdr_maxsz + \
249 decode_setclientid_confirm_maxsz + \
250 decode_putrootfh_maxsz + \
252 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
253 encode_putfh_maxsz + \
254 encode_getattr_maxsz + \
255 op_encode_hdr_maxsz + \
259 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
260 decode_putfh_maxsz + \
261 decode_getattr_maxsz + \
262 op_decode_hdr_maxsz + \
265 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
266 encode_putfh_maxsz + \
267 encode_getattr_maxsz + \
268 op_encode_hdr_maxsz + \
271 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
272 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
273 encode_putfh_maxsz + \
274 encode_getattr_maxsz + \
275 op_encode_hdr_maxsz + \
277 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
278 decode_putfh_maxsz + \
279 decode_getattr_maxsz + \
280 op_decode_hdr_maxsz + 4)
281 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
282 encode_putfh_maxsz + \
283 op_encode_hdr_maxsz + 1)
284 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
285 decode_putfh_maxsz + \
286 op_decode_hdr_maxsz + 2)
287 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
288 encode_putfh_maxsz + \
289 encode_getattr_maxsz)
290 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
291 decode_putfh_maxsz + \
292 decode_getattr_maxsz)
293 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
294 encode_putfh_maxsz + \
295 encode_lookup_maxsz + \
296 encode_getattr_maxsz + \
298 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
299 decode_putfh_maxsz + \
300 op_decode_hdr_maxsz + \
301 decode_getattr_maxsz + \
303 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
304 encode_putrootfh_maxsz + \
305 encode_getattr_maxsz + \
307 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
308 decode_putrootfh_maxsz + \
309 decode_getattr_maxsz + \
311 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
312 encode_putfh_maxsz + \
313 encode_remove_maxsz + \
314 encode_getattr_maxsz)
315 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
316 decode_putfh_maxsz + \
317 op_decode_hdr_maxsz + 5 + \
318 decode_getattr_maxsz)
319 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
320 encode_putfh_maxsz + \
321 encode_savefh_maxsz + \
322 encode_putfh_maxsz + \
323 encode_rename_maxsz + \
324 encode_getattr_maxsz + \
325 encode_restorefh_maxsz + \
326 encode_getattr_maxsz)
327 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
328 decode_putfh_maxsz + \
329 decode_savefh_maxsz + \
330 decode_putfh_maxsz + \
331 decode_rename_maxsz + \
332 decode_getattr_maxsz + \
333 decode_restorefh_maxsz + \
334 decode_getattr_maxsz)
335 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
336 encode_putfh_maxsz + \
337 encode_savefh_maxsz + \
338 encode_putfh_maxsz + \
339 encode_link_maxsz + \
340 decode_getattr_maxsz + \
341 encode_restorefh_maxsz + \
342 decode_getattr_maxsz)
343 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
344 decode_putfh_maxsz + \
345 decode_savefh_maxsz + \
346 decode_putfh_maxsz + \
347 decode_link_maxsz + \
348 decode_getattr_maxsz + \
349 decode_restorefh_maxsz + \
350 decode_getattr_maxsz)
351 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
352 encode_putfh_maxsz + \
353 encode_symlink_maxsz + \
354 encode_getattr_maxsz + \
356 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
357 decode_putfh_maxsz + \
358 decode_symlink_maxsz + \
359 decode_getattr_maxsz + \
361 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
362 encode_putfh_maxsz + \
363 encode_savefh_maxsz + \
364 encode_create_maxsz + \
365 encode_getfh_maxsz + \
366 encode_getattr_maxsz + \
367 encode_restorefh_maxsz + \
368 encode_getattr_maxsz)
369 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
370 decode_putfh_maxsz + \
371 decode_savefh_maxsz + \
372 decode_create_maxsz + \
373 decode_getfh_maxsz + \
374 decode_getattr_maxsz + \
375 decode_restorefh_maxsz + \
376 decode_getattr_maxsz)
377 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
379 encode_getattr_maxsz)
380 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
381 decode_putfh_maxsz + \
382 decode_getattr_maxsz)
383 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_getattr_maxsz)
386 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
387 decode_putfh_maxsz + \
388 op_decode_hdr_maxsz + 12)
389 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
390 encode_putfh_maxsz + \
391 encode_getattr_maxsz)
392 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
393 decode_putfh_maxsz + \
394 decode_getattr_maxsz)
395 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
396 encode_putfh_maxsz + \
397 encode_delegreturn_maxsz + \
398 encode_getattr_maxsz)
399 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
400 decode_delegreturn_maxsz + \
401 decode_getattr_maxsz)
402 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
403 encode_putfh_maxsz + \
404 encode_getattr_maxsz)
405 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
406 decode_putfh_maxsz + \
407 op_decode_hdr_maxsz + \
408 nfs4_fattr_bitmap_maxsz + 1)
409 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
410 encode_putfh_maxsz + \
411 op_encode_hdr_maxsz + 4 + \
412 nfs4_fattr_bitmap_maxsz + 1)
413 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
414 decode_putfh_maxsz + \
415 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
416 #define NFS4_enc_fs_locations_sz \
417 (compound_encode_hdr_maxsz + \
418 encode_putfh_maxsz + \
419 encode_getattr_maxsz)
420 #define NFS4_dec_fs_locations_sz \
421 (compound_decode_hdr_maxsz + \
422 decode_putfh_maxsz + \
423 op_decode_hdr_maxsz + \
424 nfs4_fattr_bitmap_maxsz)
428 unsigned int nfs2type
;
436 { S_IFSOCK
, NFSOCK
},
442 struct compound_hdr
{
450 * START OF "GENERIC" ENCODE ROUTINES.
451 * These may look a little ugly since they are imported from a "generic"
452 * set of XDR encode/decode routines which are intended to be shared by
453 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
455 * If the pain of reading these is too great, it should be a straightforward
456 * task to translate them into Linux-specific versions which are more
457 * consistent with the style used in NFSv2/v3...
459 #define WRITE32(n) *p++ = htonl(n)
460 #define WRITE64(n) do { \
461 *p++ = htonl((uint32_t)((n) >> 32)); \
462 *p++ = htonl((uint32_t)(n)); \
464 #define WRITEMEM(ptr,nbytes) do { \
465 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
468 #define RESERVE_SPACE(nbytes) do { \
469 p = xdr_reserve_space(xdr, nbytes); \
470 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
474 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
478 p
= xdr_reserve_space(xdr
, 4 + len
);
480 xdr_encode_opaque(p
, str
, len
);
483 static int encode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
487 dprintk("encode_compound: tag=%.*s\n", (int)hdr
->taglen
, hdr
->tag
);
488 BUG_ON(hdr
->taglen
> NFS4_MAXTAGLEN
);
489 RESERVE_SPACE(12+(XDR_QUADLEN(hdr
->taglen
)<<2));
490 WRITE32(hdr
->taglen
);
491 WRITEMEM(hdr
->tag
, hdr
->taglen
);
492 WRITE32(NFS4_MINOR_VERSION
);
497 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
501 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
503 xdr_encode_opaque_fixed(p
, verf
->data
, NFS4_VERIFIER_SIZE
);
506 static int encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
, const struct nfs_server
*server
)
508 char owner_name
[IDMAP_NAMESZ
];
509 char owner_group
[IDMAP_NAMESZ
];
510 int owner_namelen
= 0;
511 int owner_grouplen
= 0;
520 * We reserve enough space to write the entire attribute buffer at once.
521 * In the worst-case, this would be
522 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
523 * = 36 bytes, plus any contribution from variable-length fields
524 * such as owner/group.
529 if (iap
->ia_valid
& ATTR_SIZE
)
531 if (iap
->ia_valid
& ATTR_MODE
)
533 if (iap
->ia_valid
& ATTR_UID
) {
534 owner_namelen
= nfs_map_uid_to_name(server
->nfs_client
, iap
->ia_uid
, owner_name
);
535 if (owner_namelen
< 0) {
536 printk(KERN_WARNING
"nfs: couldn't resolve uid %d to string\n",
539 strcpy(owner_name
, "nobody");
540 owner_namelen
= sizeof("nobody") - 1;
543 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
545 if (iap
->ia_valid
& ATTR_GID
) {
546 owner_grouplen
= nfs_map_gid_to_group(server
->nfs_client
, iap
->ia_gid
, owner_group
);
547 if (owner_grouplen
< 0) {
548 printk(KERN_WARNING
"nfs4: couldn't resolve gid %d to string\n",
550 strcpy(owner_group
, "nobody");
551 owner_grouplen
= sizeof("nobody") - 1;
554 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
556 if (iap
->ia_valid
& ATTR_ATIME_SET
)
558 else if (iap
->ia_valid
& ATTR_ATIME
)
560 if (iap
->ia_valid
& ATTR_MTIME_SET
)
562 else if (iap
->ia_valid
& ATTR_MTIME
)
567 * We write the bitmap length now, but leave the bitmap and the attribute
568 * buffer length to be backfilled at the end of this routine.
574 if (iap
->ia_valid
& ATTR_SIZE
) {
575 bmval0
|= FATTR4_WORD0_SIZE
;
576 WRITE64(iap
->ia_size
);
578 if (iap
->ia_valid
& ATTR_MODE
) {
579 bmval1
|= FATTR4_WORD1_MODE
;
580 WRITE32(iap
->ia_mode
& S_IALLUGO
);
582 if (iap
->ia_valid
& ATTR_UID
) {
583 bmval1
|= FATTR4_WORD1_OWNER
;
584 WRITE32(owner_namelen
);
585 WRITEMEM(owner_name
, owner_namelen
);
587 if (iap
->ia_valid
& ATTR_GID
) {
588 bmval1
|= FATTR4_WORD1_OWNER_GROUP
;
589 WRITE32(owner_grouplen
);
590 WRITEMEM(owner_group
, owner_grouplen
);
592 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
593 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
594 WRITE32(NFS4_SET_TO_CLIENT_TIME
);
596 WRITE32(iap
->ia_mtime
.tv_sec
);
597 WRITE32(iap
->ia_mtime
.tv_nsec
);
599 else if (iap
->ia_valid
& ATTR_ATIME
) {
600 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
601 WRITE32(NFS4_SET_TO_SERVER_TIME
);
603 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
604 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
605 WRITE32(NFS4_SET_TO_CLIENT_TIME
);
607 WRITE32(iap
->ia_mtime
.tv_sec
);
608 WRITE32(iap
->ia_mtime
.tv_nsec
);
610 else if (iap
->ia_valid
& ATTR_MTIME
) {
611 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
612 WRITE32(NFS4_SET_TO_SERVER_TIME
);
616 * Now we backfill the bitmap and the attribute buffer length.
618 if (len
!= ((char *)p
- (char *)q
) + 4) {
619 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
620 len
, ((char *)p
- (char *)q
) + 4);
623 len
= (char *)p
- (char *)q
- 12;
624 *q
++ = htonl(bmval0
);
625 *q
++ = htonl(bmval1
);
633 static int encode_access(struct xdr_stream
*xdr
, u32 access
)
644 static int encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
)
648 RESERVE_SPACE(8+sizeof(arg
->stateid
->data
));
650 WRITE32(arg
->seqid
->sequence
->counter
);
651 WRITEMEM(arg
->stateid
->data
, sizeof(arg
->stateid
->data
));
656 static int encode_commit(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
)
662 WRITE64(args
->offset
);
663 WRITE32(args
->count
);
668 static int encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
)
674 WRITE32(create
->ftype
);
676 switch (create
->ftype
) {
679 WRITE32(create
->u
.symlink
.len
);
680 xdr_write_pages(xdr
, create
->u
.symlink
.pages
, 0, create
->u
.symlink
.len
);
683 case NF4BLK
: case NF4CHR
:
685 WRITE32(create
->u
.device
.specdata1
);
686 WRITE32(create
->u
.device
.specdata2
);
693 RESERVE_SPACE(4 + create
->name
->len
);
694 WRITE32(create
->name
->len
);
695 WRITEMEM(create
->name
->name
, create
->name
->len
);
697 return encode_attrs(xdr
, create
->attrs
, create
->server
);
700 static int encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
)
711 static int encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
)
723 static int encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
)
725 return encode_getattr_two(xdr
,
726 bitmask
[0] & nfs4_fattr_bitmap
[0],
727 bitmask
[1] & nfs4_fattr_bitmap
[1]);
730 static int encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
)
732 return encode_getattr_two(xdr
, bitmask
[0] & nfs4_fsinfo_bitmap
[0],
733 bitmask
[1] & nfs4_fsinfo_bitmap
[1]);
736 static int encode_fs_locations(struct xdr_stream
*xdr
, const u32
* bitmask
)
738 return encode_getattr_two(xdr
,
739 bitmask
[0] & nfs4_fs_locations_bitmap
[0],
740 bitmask
[1] & nfs4_fs_locations_bitmap
[1]);
743 static int encode_getfh(struct xdr_stream
*xdr
)
753 static int encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
)
757 RESERVE_SPACE(8 + name
->len
);
760 WRITEMEM(name
->name
, name
->len
);
765 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
767 if ((fl
->fl_type
& (F_RDLCK
|F_WRLCK
|F_UNLCK
)) == F_RDLCK
)
768 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
769 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
772 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
774 if (fl
->fl_end
== OFFSET_MAX
)
776 return fl
->fl_end
- fl
->fl_start
+ 1;
780 * opcode,type,reclaim,offset,length,new_lock_owner = 32
781 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
783 static int encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
)
789 WRITE32(nfs4_lock_type(args
->fl
, args
->block
));
790 WRITE32(args
->reclaim
);
791 WRITE64(args
->fl
->fl_start
);
792 WRITE64(nfs4_lock_length(args
->fl
));
793 WRITE32(args
->new_lock_owner
);
794 if (args
->new_lock_owner
){
796 WRITE32(args
->open_seqid
->sequence
->counter
);
797 WRITEMEM(args
->open_stateid
->data
, sizeof(args
->open_stateid
->data
));
798 WRITE32(args
->lock_seqid
->sequence
->counter
);
799 WRITE64(args
->lock_owner
.clientid
);
801 WRITE32(args
->lock_owner
.id
);
805 WRITEMEM(args
->lock_stateid
->data
, sizeof(args
->lock_stateid
->data
));
806 WRITE32(args
->lock_seqid
->sequence
->counter
);
812 static int encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
)
818 WRITE32(nfs4_lock_type(args
->fl
, 0));
819 WRITE64(args
->fl
->fl_start
);
820 WRITE64(nfs4_lock_length(args
->fl
));
821 WRITE64(args
->lock_owner
.clientid
);
823 WRITE32(args
->lock_owner
.id
);
828 static int encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
)
834 WRITE32(nfs4_lock_type(args
->fl
, 0));
835 WRITE32(args
->seqid
->sequence
->counter
);
836 WRITEMEM(args
->stateid
->data
, sizeof(args
->stateid
->data
));
837 WRITE64(args
->fl
->fl_start
);
838 WRITE64(nfs4_lock_length(args
->fl
));
843 static int encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
)
848 RESERVE_SPACE(8 + len
);
851 WRITEMEM(name
->name
, len
);
856 static void encode_share_access(struct xdr_stream
*xdr
, int open_flags
)
861 switch (open_flags
& (FMODE_READ
|FMODE_WRITE
)) {
863 WRITE32(NFS4_SHARE_ACCESS_READ
);
866 WRITE32(NFS4_SHARE_ACCESS_WRITE
);
868 case FMODE_READ
|FMODE_WRITE
:
869 WRITE32(NFS4_SHARE_ACCESS_BOTH
);
874 WRITE32(0); /* for linux, share_deny = 0 always */
877 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
881 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
886 WRITE32(arg
->seqid
->sequence
->counter
);
887 encode_share_access(xdr
, arg
->open_flags
);
889 WRITE64(arg
->clientid
);
894 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
899 switch(arg
->open_flags
& O_EXCL
) {
901 WRITE32(NFS4_CREATE_UNCHECKED
);
902 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
905 WRITE32(NFS4_CREATE_EXCLUSIVE
);
906 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
910 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
915 switch (arg
->open_flags
& O_CREAT
) {
917 WRITE32(NFS4_OPEN_NOCREATE
);
920 BUG_ON(arg
->claim
!= NFS4_OPEN_CLAIM_NULL
);
921 WRITE32(NFS4_OPEN_CREATE
);
922 encode_createmode(xdr
, arg
);
926 static inline void encode_delegation_type(struct xdr_stream
*xdr
, int delegation_type
)
931 switch (delegation_type
) {
933 WRITE32(NFS4_OPEN_DELEGATE_NONE
);
936 WRITE32(NFS4_OPEN_DELEGATE_READ
);
938 case FMODE_WRITE
|FMODE_READ
:
939 WRITE32(NFS4_OPEN_DELEGATE_WRITE
);
946 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
951 WRITE32(NFS4_OPEN_CLAIM_NULL
);
952 encode_string(xdr
, name
->len
, name
->name
);
955 static inline void encode_claim_previous(struct xdr_stream
*xdr
, int type
)
960 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS
);
961 encode_delegation_type(xdr
, type
);
964 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
968 RESERVE_SPACE(4+sizeof(stateid
->data
));
969 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
970 WRITEMEM(stateid
->data
, sizeof(stateid
->data
));
971 encode_string(xdr
, name
->len
, name
->name
);
974 static int encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
976 encode_openhdr(xdr
, arg
);
977 encode_opentype(xdr
, arg
);
978 switch (arg
->claim
) {
979 case NFS4_OPEN_CLAIM_NULL
:
980 encode_claim_null(xdr
, arg
->name
);
982 case NFS4_OPEN_CLAIM_PREVIOUS
:
983 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
985 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
986 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
994 static int encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
)
998 RESERVE_SPACE(8+sizeof(arg
->stateid
->data
));
999 WRITE32(OP_OPEN_CONFIRM
);
1000 WRITEMEM(arg
->stateid
->data
, sizeof(arg
->stateid
->data
));
1001 WRITE32(arg
->seqid
->sequence
->counter
);
1006 static int encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
)
1010 RESERVE_SPACE(8+sizeof(arg
->stateid
->data
));
1011 WRITE32(OP_OPEN_DOWNGRADE
);
1012 WRITEMEM(arg
->stateid
->data
, sizeof(arg
->stateid
->data
));
1013 WRITE32(arg
->seqid
->sequence
->counter
);
1014 encode_share_access(xdr
, arg
->open_flags
);
1019 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
)
1024 RESERVE_SPACE(8 + len
);
1027 WRITEMEM(fh
->data
, len
);
1032 static int encode_putrootfh(struct xdr_stream
*xdr
)
1037 WRITE32(OP_PUTROOTFH
);
1042 static void encode_stateid(struct xdr_stream
*xdr
, const struct nfs_open_context
*ctx
)
1044 nfs4_stateid stateid
;
1048 if (ctx
->state
!= NULL
) {
1049 nfs4_copy_stateid(&stateid
, ctx
->state
, ctx
->lockowner
);
1050 WRITEMEM(stateid
.data
, sizeof(stateid
.data
));
1052 WRITEMEM(zero_stateid
.data
, sizeof(zero_stateid
.data
));
1055 static int encode_read(struct xdr_stream
*xdr
, const struct nfs_readargs
*args
)
1062 encode_stateid(xdr
, args
->context
);
1065 WRITE64(args
->offset
);
1066 WRITE32(args
->count
);
1071 static int encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
)
1073 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1074 uint32_t attrs
[2] = {
1075 FATTR4_WORD0_RDATTR_ERROR
|FATTR4_WORD0_FILEID
,
1076 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1081 RESERVE_SPACE(32+sizeof(nfs4_verifier
));
1082 WRITE32(OP_READDIR
);
1083 WRITE64(readdir
->cookie
);
1084 WRITEMEM(readdir
->verifier
.data
, sizeof(readdir
->verifier
.data
));
1085 WRITE32(readdir
->count
>> 1); /* We're not doing readdirplus */
1086 WRITE32(readdir
->count
);
1088 /* Switch to mounted_on_fileid if the server supports it */
1089 if (readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
1090 attrs
[0] &= ~FATTR4_WORD0_FILEID
;
1092 attrs
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
1093 WRITE32(attrs
[0] & readdir
->bitmask
[0]);
1094 WRITE32(attrs
[1] & readdir
->bitmask
[1]);
1095 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1097 (unsigned long long)readdir
->cookie
,
1098 ((u32
*)readdir
->verifier
.data
)[0],
1099 ((u32
*)readdir
->verifier
.data
)[1],
1100 attrs
[0] & readdir
->bitmask
[0],
1101 attrs
[1] & readdir
->bitmask
[1]);
1103 /* set up reply kvec
1104 * toplevel_status + taglen + rescount + OP_PUTFH + status
1105 * + OP_READDIR + status + verifer(2) = 9
1107 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 9) << 2;
1108 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, readdir
->pages
,
1109 readdir
->pgbase
, readdir
->count
);
1110 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1111 __FUNCTION__
, replen
, readdir
->pages
,
1112 readdir
->pgbase
, readdir
->count
);
1117 static int encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
)
1119 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1120 unsigned int replen
;
1124 WRITE32(OP_READLINK
);
1126 /* set up reply kvec
1127 * toplevel_status + taglen + rescount + OP_PUTFH + status
1128 * + OP_READLINK + status + string length = 8
1130 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 8) << 2;
1131 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, readlink
->pages
,
1132 readlink
->pgbase
, readlink
->pglen
);
1137 static int encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
)
1141 RESERVE_SPACE(8 + name
->len
);
1144 WRITEMEM(name
->name
, name
->len
);
1149 static int encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
)
1153 RESERVE_SPACE(8 + oldname
->len
);
1155 WRITE32(oldname
->len
);
1156 WRITEMEM(oldname
->name
, oldname
->len
);
1158 RESERVE_SPACE(4 + newname
->len
);
1159 WRITE32(newname
->len
);
1160 WRITEMEM(newname
->name
, newname
->len
);
1165 static int encode_renew(struct xdr_stream
*xdr
, const struct nfs_client
*client_stateid
)
1171 WRITE64(client_stateid
->cl_clientid
);
1177 encode_restorefh(struct xdr_stream
*xdr
)
1182 WRITE32(OP_RESTOREFH
);
1188 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
)
1192 RESERVE_SPACE(4+sizeof(zero_stateid
.data
));
1193 WRITE32(OP_SETATTR
);
1194 WRITEMEM(zero_stateid
.data
, sizeof(zero_stateid
.data
));
1197 WRITE32(FATTR4_WORD0_ACL
);
1198 if (arg
->acl_len
% 4)
1201 WRITE32(arg
->acl_len
);
1202 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1207 encode_savefh(struct xdr_stream
*xdr
)
1217 static int encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
)
1222 RESERVE_SPACE(4+sizeof(arg
->stateid
.data
));
1223 WRITE32(OP_SETATTR
);
1224 WRITEMEM(arg
->stateid
.data
, sizeof(arg
->stateid
.data
));
1226 if ((status
= encode_attrs(xdr
, arg
->iap
, server
)))
1232 static int encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
)
1236 RESERVE_SPACE(4 + sizeof(setclientid
->sc_verifier
->data
));
1237 WRITE32(OP_SETCLIENTID
);
1238 WRITEMEM(setclientid
->sc_verifier
->data
, sizeof(setclientid
->sc_verifier
->data
));
1240 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1242 WRITE32(setclientid
->sc_prog
);
1243 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1244 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1246 WRITE32(setclientid
->sc_cb_ident
);
1251 static int encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs_client
*client_state
)
1255 RESERVE_SPACE(12 + sizeof(client_state
->cl_confirm
.data
));
1256 WRITE32(OP_SETCLIENTID_CONFIRM
);
1257 WRITE64(client_state
->cl_clientid
);
1258 WRITEMEM(client_state
->cl_confirm
.data
, sizeof(client_state
->cl_confirm
.data
));
1263 static int encode_write(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
)
1270 encode_stateid(xdr
, args
->context
);
1273 WRITE64(args
->offset
);
1274 WRITE32(args
->stable
);
1275 WRITE32(args
->count
);
1277 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1282 static int encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
)
1288 WRITE32(OP_DELEGRETURN
);
1289 WRITEMEM(stateid
->data
, sizeof(stateid
->data
));
1294 * END OF "GENERIC" ENCODE ROUTINES.
1298 * Encode an ACCESS request
1300 static int nfs4_xdr_enc_access(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_accessargs
*args
)
1302 struct xdr_stream xdr
;
1303 struct compound_hdr hdr
= {
1308 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1309 encode_compound_hdr(&xdr
, &hdr
);
1310 if ((status
= encode_putfh(&xdr
, args
->fh
)) == 0)
1311 status
= encode_access(&xdr
, args
->access
);
1316 * Encode LOOKUP request
1318 static int nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_arg
*args
)
1320 struct xdr_stream xdr
;
1321 struct compound_hdr hdr
= {
1326 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1327 encode_compound_hdr(&xdr
, &hdr
);
1328 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1330 if ((status
= encode_lookup(&xdr
, args
->name
)) != 0)
1332 if ((status
= encode_getfh(&xdr
)) != 0)
1334 status
= encode_getfattr(&xdr
, args
->bitmask
);
1340 * Encode LOOKUP_ROOT request
1342 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_root_arg
*args
)
1344 struct xdr_stream xdr
;
1345 struct compound_hdr hdr
= {
1350 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1351 encode_compound_hdr(&xdr
, &hdr
);
1352 if ((status
= encode_putrootfh(&xdr
)) != 0)
1354 if ((status
= encode_getfh(&xdr
)) == 0)
1355 status
= encode_getfattr(&xdr
, args
->bitmask
);
1361 * Encode REMOVE request
1363 static int nfs4_xdr_enc_remove(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_remove_arg
*args
)
1365 struct xdr_stream xdr
;
1366 struct compound_hdr hdr
= {
1371 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1372 encode_compound_hdr(&xdr
, &hdr
);
1373 if ((status
= encode_putfh(&xdr
, args
->fh
)) != 0)
1375 if ((status
= encode_remove(&xdr
, args
->name
)) != 0)
1377 status
= encode_getfattr(&xdr
, args
->bitmask
);
1383 * Encode RENAME request
1385 static int nfs4_xdr_enc_rename(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_rename_arg
*args
)
1387 struct xdr_stream xdr
;
1388 struct compound_hdr hdr
= {
1393 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1394 encode_compound_hdr(&xdr
, &hdr
);
1395 if ((status
= encode_putfh(&xdr
, args
->old_dir
)) != 0)
1397 if ((status
= encode_savefh(&xdr
)) != 0)
1399 if ((status
= encode_putfh(&xdr
, args
->new_dir
)) != 0)
1401 if ((status
= encode_rename(&xdr
, args
->old_name
, args
->new_name
)) != 0)
1403 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1405 if ((status
= encode_restorefh(&xdr
)) != 0)
1407 status
= encode_getfattr(&xdr
, args
->bitmask
);
1413 * Encode LINK request
1415 static int nfs4_xdr_enc_link(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_link_arg
*args
)
1417 struct xdr_stream xdr
;
1418 struct compound_hdr hdr
= {
1423 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1424 encode_compound_hdr(&xdr
, &hdr
);
1425 if ((status
= encode_putfh(&xdr
, args
->fh
)) != 0)
1427 if ((status
= encode_savefh(&xdr
)) != 0)
1429 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1431 if ((status
= encode_link(&xdr
, args
->name
)) != 0)
1433 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1435 if ((status
= encode_restorefh(&xdr
)) != 0)
1437 status
= encode_getfattr(&xdr
, args
->bitmask
);
1443 * Encode CREATE request
1445 static int nfs4_xdr_enc_create(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1447 struct xdr_stream xdr
;
1448 struct compound_hdr hdr
= {
1453 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1454 encode_compound_hdr(&xdr
, &hdr
);
1455 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1457 if ((status
= encode_savefh(&xdr
)) != 0)
1459 if ((status
= encode_create(&xdr
, args
)) != 0)
1461 if ((status
= encode_getfh(&xdr
)) != 0)
1463 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1465 if ((status
= encode_restorefh(&xdr
)) != 0)
1467 status
= encode_getfattr(&xdr
, args
->bitmask
);
1473 * Encode SYMLINK request
1475 static int nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1477 return nfs4_xdr_enc_create(req
, p
, args
);
1481 * Encode GETATTR request
1483 static int nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_getattr_arg
*args
)
1485 struct xdr_stream xdr
;
1486 struct compound_hdr hdr
= {
1491 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1492 encode_compound_hdr(&xdr
, &hdr
);
1493 if ((status
= encode_putfh(&xdr
, args
->fh
)) == 0)
1494 status
= encode_getfattr(&xdr
, args
->bitmask
);
1499 * Encode a CLOSE request
1501 static int nfs4_xdr_enc_close(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1503 struct xdr_stream xdr
;
1504 struct compound_hdr hdr
= {
1509 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1510 encode_compound_hdr(&xdr
, &hdr
);
1511 status
= encode_putfh(&xdr
, args
->fh
);
1514 status
= encode_close(&xdr
, args
);
1517 status
= encode_getfattr(&xdr
, args
->bitmask
);
1523 * Encode an OPEN request
1525 static int nfs4_xdr_enc_open(struct rpc_rqst
*req
, __be32
*p
, struct nfs_openargs
*args
)
1527 struct xdr_stream xdr
;
1528 struct compound_hdr hdr
= {
1533 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1534 encode_compound_hdr(&xdr
, &hdr
);
1535 status
= encode_putfh(&xdr
, args
->fh
);
1538 status
= encode_savefh(&xdr
);
1541 status
= encode_open(&xdr
, args
);
1544 status
= encode_getfh(&xdr
);
1547 status
= encode_getfattr(&xdr
, args
->bitmask
);
1550 status
= encode_restorefh(&xdr
);
1553 status
= encode_getfattr(&xdr
, args
->bitmask
);
1559 * Encode an OPEN_CONFIRM request
1561 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_open_confirmargs
*args
)
1563 struct xdr_stream xdr
;
1564 struct compound_hdr hdr
= {
1569 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1570 encode_compound_hdr(&xdr
, &hdr
);
1571 status
= encode_putfh(&xdr
, args
->fh
);
1574 status
= encode_open_confirm(&xdr
, args
);
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
= {
1590 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1591 encode_compound_hdr(&xdr
, &hdr
);
1592 status
= encode_putfh(&xdr
, args
->fh
);
1595 status
= encode_open(&xdr
, args
);
1598 status
= encode_getfattr(&xdr
, args
->bitmask
);
1604 * Encode an OPEN_DOWNGRADE request
1606 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1608 struct xdr_stream xdr
;
1609 struct compound_hdr hdr
= {
1614 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1615 encode_compound_hdr(&xdr
, &hdr
);
1616 status
= encode_putfh(&xdr
, args
->fh
);
1619 status
= encode_open_downgrade(&xdr
, args
);
1622 status
= encode_getfattr(&xdr
, args
->bitmask
);
1628 * Encode a LOCK request
1630 static int nfs4_xdr_enc_lock(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lock_args
*args
)
1632 struct xdr_stream xdr
;
1633 struct compound_hdr hdr
= {
1638 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1639 encode_compound_hdr(&xdr
, &hdr
);
1640 status
= encode_putfh(&xdr
, args
->fh
);
1643 status
= encode_lock(&xdr
, args
);
1649 * Encode a LOCKT request
1651 static int nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lockt_args
*args
)
1653 struct xdr_stream xdr
;
1654 struct compound_hdr hdr
= {
1659 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1660 encode_compound_hdr(&xdr
, &hdr
);
1661 status
= encode_putfh(&xdr
, args
->fh
);
1664 status
= encode_lockt(&xdr
, args
);
1670 * Encode a LOCKU request
1672 static int nfs4_xdr_enc_locku(struct rpc_rqst
*req
, __be32
*p
, struct nfs_locku_args
*args
)
1674 struct xdr_stream xdr
;
1675 struct compound_hdr hdr
= {
1680 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1681 encode_compound_hdr(&xdr
, &hdr
);
1682 status
= encode_putfh(&xdr
, args
->fh
);
1685 status
= encode_locku(&xdr
, args
);
1691 * Encode a READLINK request
1693 static int nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readlink
*args
)
1695 struct xdr_stream xdr
;
1696 struct compound_hdr hdr
= {
1701 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1702 encode_compound_hdr(&xdr
, &hdr
);
1703 status
= encode_putfh(&xdr
, args
->fh
);
1706 status
= encode_readlink(&xdr
, args
, req
);
1712 * Encode a READDIR request
1714 static int nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readdir_arg
*args
)
1716 struct xdr_stream xdr
;
1717 struct compound_hdr hdr
= {
1722 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1723 encode_compound_hdr(&xdr
, &hdr
);
1724 status
= encode_putfh(&xdr
, args
->fh
);
1727 status
= encode_readdir(&xdr
, args
, req
);
1733 * Encode a READ request
1735 static int nfs4_xdr_enc_read(struct rpc_rqst
*req
, __be32
*p
, struct nfs_readargs
*args
)
1737 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1738 struct xdr_stream xdr
;
1739 struct compound_hdr hdr
= {
1744 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1745 encode_compound_hdr(&xdr
, &hdr
);
1746 status
= encode_putfh(&xdr
, args
->fh
);
1749 status
= encode_read(&xdr
, args
);
1753 /* set up reply kvec
1754 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1755 * + OP_READ + status + eof + datalen = 9
1757 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_read_sz
) << 2;
1758 xdr_inline_pages(&req
->rq_rcv_buf
, replen
,
1759 args
->pages
, args
->pgbase
, args
->count
);
1765 * Encode an SETATTR request
1767 static int nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setattrargs
*args
)
1770 struct xdr_stream xdr
;
1771 struct compound_hdr hdr
= {
1776 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1777 encode_compound_hdr(&xdr
, &hdr
);
1778 status
= encode_putfh(&xdr
, args
->fh
);
1781 status
= encode_setattr(&xdr
, args
, args
->server
);
1784 status
= encode_getfattr(&xdr
, args
->bitmask
);
1790 * Encode a GETACL request
1793 nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, __be32
*p
,
1794 struct nfs_getaclargs
*args
)
1796 struct xdr_stream xdr
;
1797 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1798 struct compound_hdr hdr
= {
1803 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1804 encode_compound_hdr(&xdr
, &hdr
);
1805 status
= encode_putfh(&xdr
, args
->fh
);
1808 status
= encode_getattr_two(&xdr
, FATTR4_WORD0_ACL
, 0);
1809 /* set up reply buffer: */
1810 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_getacl_sz
) << 2;
1811 xdr_inline_pages(&req
->rq_rcv_buf
, replen
,
1812 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
1818 * Encode a WRITE request
1820 static int nfs4_xdr_enc_write(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*args
)
1822 struct xdr_stream xdr
;
1823 struct compound_hdr hdr
= {
1828 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1829 encode_compound_hdr(&xdr
, &hdr
);
1830 status
= encode_putfh(&xdr
, args
->fh
);
1833 status
= encode_write(&xdr
, args
);
1836 status
= encode_getfattr(&xdr
, args
->bitmask
);
1844 static int nfs4_xdr_enc_commit(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*args
)
1846 struct xdr_stream xdr
;
1847 struct compound_hdr hdr
= {
1852 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1853 encode_compound_hdr(&xdr
, &hdr
);
1854 status
= encode_putfh(&xdr
, args
->fh
);
1857 status
= encode_commit(&xdr
, args
);
1860 status
= encode_getfattr(&xdr
, args
->bitmask
);
1868 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fsinfo_arg
*args
)
1870 struct xdr_stream xdr
;
1871 struct compound_hdr hdr
= {
1876 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1877 encode_compound_hdr(&xdr
, &hdr
);
1878 status
= encode_putfh(&xdr
, args
->fh
);
1880 status
= encode_fsinfo(&xdr
, args
->bitmask
);
1885 * a PATHCONF request
1887 static int nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_pathconf_arg
*args
)
1889 struct xdr_stream xdr
;
1890 struct compound_hdr hdr
= {
1895 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1896 encode_compound_hdr(&xdr
, &hdr
);
1897 status
= encode_putfh(&xdr
, args
->fh
);
1899 status
= encode_getattr_one(&xdr
,
1900 args
->bitmask
[0] & nfs4_pathconf_bitmap
[0]);
1907 static int nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_statfs_arg
*args
)
1909 struct xdr_stream xdr
;
1910 struct compound_hdr hdr
= {
1915 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1916 encode_compound_hdr(&xdr
, &hdr
);
1917 status
= encode_putfh(&xdr
, args
->fh
);
1919 status
= encode_getattr_two(&xdr
,
1920 args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
1921 args
->bitmask
[1] & nfs4_statfs_bitmap
[1]);
1926 * GETATTR_BITMAP request
1928 static int nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
, __be32
*p
, const struct nfs_fh
*fhandle
)
1930 struct xdr_stream xdr
;
1931 struct compound_hdr hdr
= {
1936 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1937 encode_compound_hdr(&xdr
, &hdr
);
1938 status
= encode_putfh(&xdr
, fhandle
);
1940 status
= encode_getattr_one(&xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
1941 FATTR4_WORD0_LINK_SUPPORT
|
1942 FATTR4_WORD0_SYMLINK_SUPPORT
|
1943 FATTR4_WORD0_ACLSUPPORT
);
1950 static int nfs4_xdr_enc_renew(struct rpc_rqst
*req
, __be32
*p
, struct nfs_client
*clp
)
1952 struct xdr_stream xdr
;
1953 struct compound_hdr hdr
= {
1957 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1958 encode_compound_hdr(&xdr
, &hdr
);
1959 return encode_renew(&xdr
, clp
);
1963 * a SETCLIENTID request
1965 static int nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_setclientid
*sc
)
1967 struct xdr_stream xdr
;
1968 struct compound_hdr hdr
= {
1972 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1973 encode_compound_hdr(&xdr
, &hdr
);
1974 return encode_setclientid(&xdr
, sc
);
1978 * a SETCLIENTID_CONFIRM request
1980 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_client
*clp
)
1982 struct xdr_stream xdr
;
1983 struct compound_hdr hdr
= {
1986 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
1989 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1990 encode_compound_hdr(&xdr
, &hdr
);
1991 status
= encode_setclientid_confirm(&xdr
, clp
);
1993 status
= encode_putrootfh(&xdr
);
1995 status
= encode_fsinfo(&xdr
, lease_bitmap
);
2000 * DELEGRETURN request
2002 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_delegreturnargs
*args
)
2004 struct xdr_stream xdr
;
2005 struct compound_hdr hdr
= {
2010 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2011 encode_compound_hdr(&xdr
, &hdr
);
2012 status
= encode_putfh(&xdr
, args
->fhandle
);
2015 status
= encode_delegreturn(&xdr
, args
->stateid
);
2018 status
= encode_getfattr(&xdr
, args
->bitmask
);
2024 * Encode FS_LOCATIONS request
2026 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fs_locations_arg
*args
)
2028 struct xdr_stream xdr
;
2029 struct compound_hdr hdr
= {
2032 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
2036 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2037 encode_compound_hdr(&xdr
, &hdr
);
2038 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
2040 if ((status
= encode_lookup(&xdr
, args
->name
)) != 0)
2042 if ((status
= encode_fs_locations(&xdr
, args
->bitmask
)) != 0)
2045 * toplevel_status + OP_PUTFH + status
2046 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2048 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 7) << 2;
2049 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, &args
->page
,
2056 * START OF "GENERIC" DECODE ROUTINES.
2057 * These may look a little ugly since they are imported from a "generic"
2058 * set of XDR encode/decode routines which are intended to be shared by
2059 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2061 * If the pain of reading these is too great, it should be a straightforward
2062 * task to translate them into Linux-specific versions which are more
2063 * consistent with the style used in NFSv2/v3...
2065 #define READ32(x) (x) = ntohl(*p++)
2066 #define READ64(x) do { \
2067 (x) = (u64)ntohl(*p++) << 32; \
2068 (x) |= ntohl(*p++); \
2070 #define READTIME(x) do { \
2072 (x.tv_sec) = ntohl(*p++); \
2073 (x.tv_nsec) = ntohl(*p++); \
2075 #define COPYMEM(x,nbytes) do { \
2076 memcpy((x), p, nbytes); \
2077 p += XDR_QUADLEN(nbytes); \
2080 #define READ_BUF(nbytes) do { \
2081 p = xdr_inline_decode(xdr, nbytes); \
2083 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
2084 __FUNCTION__, __LINE__); \
2089 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
2096 *string
= (char *)p
;
2100 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
2105 READ32(hdr
->status
);
2106 READ32(hdr
->taglen
);
2108 READ_BUF(hdr
->taglen
+ 4);
2109 hdr
->tag
= (char *)p
;
2110 p
+= XDR_QUADLEN(hdr
->taglen
);
2115 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
2123 if (opnum
!= expected
) {
2125 "nfs4_decode_op_hdr: Server returned operation"
2126 " %d but we issued a request for %d\n",
2131 if (nfserr
!= NFS_OK
)
2132 return -nfs4_stat_to_errno(nfserr
);
2137 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs_client
*clp
)
2140 unsigned int strlen
;
2144 return decode_opaque_inline(xdr
, &strlen
, &str
);
2147 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
2155 bitmap
[0] = bitmap
[1] = 0;
2156 READ_BUF((bmlen
<< 2));
2165 static inline int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, __be32
**savep
)
2175 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
2177 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
2178 decode_attr_bitmap(xdr
, bitmask
);
2179 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
2181 bitmask
[0] = bitmask
[1] = 0;
2182 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__
, bitmask
[0], bitmask
[1]);
2186 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
2191 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
2193 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
2196 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
2197 dprintk("%s: bad type %d\n", __FUNCTION__
, *type
);
2200 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
2202 dprintk("%s: type=0%o\n", __FUNCTION__
, nfs_type2fmt
[*type
].nfs2type
);
2206 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
2211 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
2213 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
2216 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
2218 dprintk("%s: change attribute=%Lu\n", __FUNCTION__
,
2219 (unsigned long long)*change
);
2223 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
2228 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
2230 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
2233 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
2235 dprintk("%s: file size=%Lu\n", __FUNCTION__
, (unsigned long long)*size
);
2239 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2244 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
2246 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
2249 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
2251 dprintk("%s: link support=%s\n", __FUNCTION__
, *res
== 0 ? "false" : "true");
2255 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2260 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
2262 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
2265 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
2267 dprintk("%s: symlink support=%s\n", __FUNCTION__
, *res
== 0 ? "false" : "true");
2271 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
2277 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
2279 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
2281 READ64(fsid
->major
);
2282 READ64(fsid
->minor
);
2283 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
2285 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__
,
2286 (unsigned long long)fsid
->major
,
2287 (unsigned long long)fsid
->minor
);
2291 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2296 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
2298 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
2301 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
2303 dprintk("%s: file size=%u\n", __FUNCTION__
, (unsigned int)*res
);
2307 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2311 *res
= ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
;
2312 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
2314 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
2317 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
2319 dprintk("%s: ACLs supported=%u\n", __FUNCTION__
, (unsigned int)*res
);
2323 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2328 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
2330 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
2333 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
2335 dprintk("%s: fileid=%Lu\n", __FUNCTION__
, (unsigned long long)*fileid
);
2339 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2344 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
2346 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
2349 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
2351 dprintk("%s: fileid=%Lu\n", __FUNCTION__
, (unsigned long long)*fileid
);
2355 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2361 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
2363 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
2366 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
2368 dprintk("%s: files avail=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2372 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2378 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
2380 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
2383 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
2385 dprintk("%s: files free=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2389 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2395 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
2397 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
2400 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
2402 dprintk("%s: files total=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2406 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
2419 path
->ncomponents
= 0;
2420 while (path
->ncomponents
< n
) {
2421 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
2422 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
2423 if (unlikely(status
!= 0))
2425 if (path
->ncomponents
!= n
)
2427 dprintk("%s", component
->data
);
2428 if (path
->ncomponents
< NFS4_PATHNAME_MAXCOMPONENTS
)
2429 path
->ncomponents
++;
2431 dprintk("cannot parse %d components in path\n", n
);
2439 /* a root pathname is sent as a zero component4 */
2440 path
->ncomponents
= 1;
2441 path
->components
[0].len
=0;
2442 path
->components
[0].data
=NULL
;
2443 dprintk("path /\n");
2446 dprintk(" status %d", status
);
2451 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
2457 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
2460 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
2462 dprintk("%s: fsroot ", __FUNCTION__
);
2463 status
= decode_pathname(xdr
, &res
->fs_path
);
2464 if (unlikely(status
!= 0))
2470 res
->nlocations
= 0;
2471 while (res
->nlocations
< n
) {
2473 struct nfs4_fs_location
*loc
= &res
->locations
[res
->nlocations
];
2481 dprintk("%s: servers ", __FUNCTION__
);
2482 while (loc
->nservers
< m
) {
2483 struct nfs4_string
*server
= &loc
->servers
[loc
->nservers
];
2484 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
2485 if (unlikely(status
!= 0))
2487 dprintk("%s ", server
->data
);
2488 if (loc
->nservers
< NFS4_FS_LOCATION_MAXSERVERS
)
2492 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__
, NFS4_FS_LOCATION_MAXSERVERS
, m
, res
->nlocations
);
2493 for (i
= loc
->nservers
; i
< m
; i
++) {
2496 status
= decode_opaque_inline(xdr
, &len
, &data
);
2497 if (unlikely(status
!= 0))
2502 status
= decode_pathname(xdr
, &loc
->rootpath
);
2503 if (unlikely(status
!= 0))
2505 if (res
->nlocations
< NFS4_FS_LOCATIONS_MAXENTRIES
)
2509 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__
, status
);
2516 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2522 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
2524 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
2527 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
2529 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2533 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
2539 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
2541 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
2544 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
2546 dprintk("%s: maxlink=%u\n", __FUNCTION__
, *maxlink
);
2550 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
2556 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
2558 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
2561 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
2563 dprintk("%s: maxname=%u\n", __FUNCTION__
, *maxname
);
2567 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2573 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
2575 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
2579 if (maxread
> 0x7FFFFFFF)
2580 maxread
= 0x7FFFFFFF;
2581 *res
= (uint32_t)maxread
;
2582 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
2584 dprintk("%s: maxread=%lu\n", __FUNCTION__
, (unsigned long)*res
);
2588 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2594 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
2596 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
2600 if (maxwrite
> 0x7FFFFFFF)
2601 maxwrite
= 0x7FFFFFFF;
2602 *res
= (uint32_t)maxwrite
;
2603 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
2605 dprintk("%s: maxwrite=%lu\n", __FUNCTION__
, (unsigned long)*res
);
2609 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *mode
)
2614 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
2616 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
2620 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
2622 dprintk("%s: file mode=0%o\n", __FUNCTION__
, (unsigned int)*mode
);
2626 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
2631 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
2633 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
2636 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
2638 dprintk("%s: nlink=%u\n", __FUNCTION__
, (unsigned int)*nlink
);
2642 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_client
*clp
, int32_t *uid
)
2648 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
2650 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
2654 if (len
< XDR_MAX_NETOBJ
) {
2655 if (nfs_map_name_to_uid(clp
, (char *)p
, len
, uid
) != 0)
2656 dprintk("%s: nfs_map_name_to_uid failed!\n",
2659 printk(KERN_WARNING
"%s: name too long (%u)!\n",
2661 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
2663 dprintk("%s: uid=%d\n", __FUNCTION__
, (int)*uid
);
2667 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_client
*clp
, int32_t *gid
)
2673 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
2675 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
2679 if (len
< XDR_MAX_NETOBJ
) {
2680 if (nfs_map_group_to_gid(clp
, (char *)p
, len
, gid
) != 0)
2681 dprintk("%s: nfs_map_group_to_gid failed!\n",
2684 printk(KERN_WARNING
"%s: name too long (%u)!\n",
2686 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
2688 dprintk("%s: gid=%d\n", __FUNCTION__
, (int)*gid
);
2692 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
2694 uint32_t major
= 0, minor
= 0;
2698 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
2700 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
2706 tmp
= MKDEV(major
, minor
);
2707 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
2709 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
2711 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__
, major
, minor
);
2715 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2721 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
2723 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
2726 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
2728 dprintk("%s: space avail=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2732 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2738 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
2740 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
2743 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
2745 dprintk("%s: space free=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2749 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2755 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
2757 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
2760 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
2762 dprintk("%s: space total=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2766 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
2771 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
2773 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
2776 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
2778 dprintk("%s: space used=%Lu\n", __FUNCTION__
,
2779 (unsigned long long)*used
);
2783 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
2792 time
->tv_sec
= (time_t)sec
;
2793 time
->tv_nsec
= (long)nsec
;
2797 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2803 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
2805 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
2806 status
= decode_attr_time(xdr
, time
);
2807 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
2809 dprintk("%s: atime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2813 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2819 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
2821 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
2822 status
= decode_attr_time(xdr
, time
);
2823 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
2825 dprintk("%s: ctime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2829 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2835 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
2837 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
2838 status
= decode_attr_time(xdr
, time
);
2839 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
2841 dprintk("%s: mtime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2845 static int verify_attr_len(struct xdr_stream
*xdr
, __be32
*savep
, uint32_t attrlen
)
2847 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
2848 unsigned int nwords
= xdr
->p
- savep
;
2850 if (unlikely(attrwords
!= nwords
)) {
2851 printk(KERN_WARNING
"%s: server returned incorrect attribute length: %u %c %u\n",
2854 (attrwords
< nwords
) ? '<' : '>',
2861 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
2866 READ32(cinfo
->atomic
);
2867 READ64(cinfo
->before
);
2868 READ64(cinfo
->after
);
2872 static int decode_access(struct xdr_stream
*xdr
, struct nfs4_accessres
*access
)
2878 status
= decode_op_hdr(xdr
, OP_ACCESS
);
2884 access
->supported
= supp
;
2885 access
->access
= acc
;
2889 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
2894 status
= decode_op_hdr(xdr
, OP_CLOSE
);
2897 READ_BUF(sizeof(res
->stateid
.data
));
2898 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
2902 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
2907 status
= decode_op_hdr(xdr
, OP_COMMIT
);
2911 COPYMEM(res
->verf
->verifier
, 8);
2915 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
2921 status
= decode_op_hdr(xdr
, OP_CREATE
);
2924 if ((status
= decode_change_info(xdr
, cinfo
)))
2928 READ_BUF(bmlen
<< 2);
2932 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
2939 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2941 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2943 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2945 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
2947 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
2949 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
2951 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
2953 status
= verify_attr_len(xdr
, savep
, attrlen
);
2955 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
2959 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
2966 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2968 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2970 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2973 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
2975 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
2977 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
2979 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
2981 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
2983 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
2986 status
= verify_attr_len(xdr
, savep
, attrlen
);
2988 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
2992 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
2999 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3001 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3003 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3006 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
3008 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
3011 status
= verify_attr_len(xdr
, savep
, attrlen
);
3013 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
3017 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
, const struct nfs_server
*server
)
3023 int status
, fmode
= 0;
3026 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3028 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3031 fattr
->bitmap
[0] = bitmap
[0];
3032 fattr
->bitmap
[1] = bitmap
[1];
3034 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3038 if ((status
= decode_attr_type(xdr
, bitmap
, &type
)) != 0)
3040 fattr
->type
= nfs_type2fmt
[type
].nfs2type
;
3041 fmode
= nfs_type2fmt
[type
].mode
;
3043 if ((status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
)) != 0)
3045 if ((status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
)) != 0)
3047 if ((status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
)) != 0)
3049 if ((status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
)) != 0)
3051 if ((status
= decode_attr_fs_locations(xdr
, bitmap
, container_of(fattr
,
3052 struct nfs4_fs_locations
,
3055 if ((status
= decode_attr_mode(xdr
, bitmap
, &fattr
->mode
)) != 0)
3057 fattr
->mode
|= fmode
;
3058 if ((status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
)) != 0)
3060 if ((status
= decode_attr_owner(xdr
, bitmap
, server
->nfs_client
, &fattr
->uid
)) != 0)
3062 if ((status
= decode_attr_group(xdr
, bitmap
, server
->nfs_client
, &fattr
->gid
)) != 0)
3064 if ((status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
)) != 0)
3066 if ((status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
)) != 0)
3068 if ((status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
)) != 0)
3070 if ((status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
)) != 0)
3072 if ((status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
)) != 0)
3074 if ((status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fileid
)) != 0)
3076 if (fattr
->fileid
== 0 && fileid
!= 0)
3077 fattr
->fileid
= fileid
;
3078 if ((status
= verify_attr_len(xdr
, savep
, attrlen
)) == 0)
3079 fattr
->valid
= NFS_ATTR_FATTR
| NFS_ATTR_FATTR_V3
| NFS_ATTR_FATTR_V4
;
3081 dprintk("%s: xdr returned %d\n", __FUNCTION__
, -status
);
3086 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
3089 uint32_t attrlen
, bitmap
[2];
3092 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3094 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3096 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3099 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
3101 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
3103 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
3105 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
3107 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
3108 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
3110 fsinfo
->wtpref
= fsinfo
->wtmax
;
3112 status
= verify_attr_len(xdr
, savep
, attrlen
);
3114 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
3118 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
3124 status
= decode_op_hdr(xdr
, OP_GETFH
);
3127 /* Zero handle first to allow comparisons */
3128 memset(fh
, 0, sizeof(*fh
));
3132 if (len
> NFS4_FHSIZE
)
3136 COPYMEM(fh
->data
, len
);
3140 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3144 status
= decode_op_hdr(xdr
, OP_LINK
);
3147 return decode_change_info(xdr
, cinfo
);
3151 * We create the owner, so we know a proper owner.id length is 4.
3153 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
3155 uint64_t offset
, length
, clientid
;
3157 uint32_t namelen
, type
;
3164 fl
->fl_start
= (loff_t
)offset
;
3165 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
3166 if (length
== ~(uint64_t)0)
3167 fl
->fl_end
= OFFSET_MAX
;
3168 fl
->fl_type
= F_WRLCK
;
3170 fl
->fl_type
= F_RDLCK
;
3176 return -NFS4ERR_DENIED
;
3179 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
3184 status
= decode_op_hdr(xdr
, OP_LOCK
);
3186 READ_BUF(sizeof(res
->stateid
.data
));
3187 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3188 } else if (status
== -NFS4ERR_DENIED
)
3189 return decode_lock_denied(xdr
, NULL
);
3193 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
3196 status
= decode_op_hdr(xdr
, OP_LOCKT
);
3197 if (status
== -NFS4ERR_DENIED
)
3198 return decode_lock_denied(xdr
, res
->denied
);
3202 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
3207 status
= decode_op_hdr(xdr
, OP_LOCKU
);
3209 READ_BUF(sizeof(res
->stateid
.data
));
3210 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3215 static int decode_lookup(struct xdr_stream
*xdr
)
3217 return decode_op_hdr(xdr
, OP_LOOKUP
);
3220 /* This is too sick! */
3221 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
3224 uint32_t limit_type
, nblocks
, blocksize
;
3228 switch (limit_type
) {
3235 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
3240 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3243 uint32_t delegation_type
;
3246 READ32(delegation_type
);
3247 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
3248 res
->delegation_type
= 0;
3252 COPYMEM(res
->delegation
.data
, sizeof(res
->delegation
.data
));
3253 READ32(res
->do_recall
);
3254 switch (delegation_type
) {
3255 case NFS4_OPEN_DELEGATE_READ
:
3256 res
->delegation_type
= FMODE_READ
;
3258 case NFS4_OPEN_DELEGATE_WRITE
:
3259 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
3260 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
3263 return decode_ace(xdr
, NULL
, res
->server
->nfs_client
);
3266 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3272 status
= decode_op_hdr(xdr
, OP_OPEN
);
3275 READ_BUF(sizeof(res
->stateid
.data
));
3276 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3278 decode_change_info(xdr
, &res
->cinfo
);
3281 READ32(res
->rflags
);
3286 READ_BUF(bmlen
<< 2);
3288 return decode_delegation(xdr
, res
);
3290 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__
, bmlen
);
3294 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
3299 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
3302 READ_BUF(sizeof(res
->stateid
.data
));
3303 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3307 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
3312 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
3315 READ_BUF(sizeof(res
->stateid
.data
));
3316 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3320 static int decode_putfh(struct xdr_stream
*xdr
)
3322 return decode_op_hdr(xdr
, OP_PUTFH
);
3325 static int decode_putrootfh(struct xdr_stream
*xdr
)
3327 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
3330 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs_readres
*res
)
3332 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
3334 uint32_t count
, eof
, recvd
, hdrlen
;
3337 status
= decode_op_hdr(xdr
, OP_READ
);
3343 hdrlen
= (u8
*) p
- (u8
*) iov
->iov_base
;
3344 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3345 if (count
> recvd
) {
3346 printk(KERN_WARNING
"NFS: server cheating in read reply: "
3347 "count %u > recvd %u\n", count
, recvd
);
3351 xdr_read_pages(xdr
, count
);
3357 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
3359 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
3360 struct page
*page
= *rcvbuf
->pages
;
3361 struct kvec
*iov
= rcvbuf
->head
;
3362 unsigned int nr
, pglen
= rcvbuf
->page_len
;
3363 __be32
*end
, *entry
, *p
, *kaddr
;
3364 uint32_t len
, attrlen
, xlen
;
3365 int hdrlen
, recvd
, status
;
3367 status
= decode_op_hdr(xdr
, OP_READDIR
);
3371 COPYMEM(readdir
->verifier
.data
, 8);
3372 dprintk("%s: verifier = 0x%x%x\n",
3374 ((u32
*)readdir
->verifier
.data
)[0],
3375 ((u32
*)readdir
->verifier
.data
)[1]);
3378 hdrlen
= (char *) p
- (char *) iov
->iov_base
;
3379 recvd
= rcvbuf
->len
- hdrlen
;
3382 xdr_read_pages(xdr
, pglen
);
3384 BUG_ON(pglen
+ readdir
->pgbase
> PAGE_CACHE_SIZE
);
3385 kaddr
= p
= kmap_atomic(page
, KM_USER0
);
3386 end
= p
+ ((pglen
+ readdir
->pgbase
) >> 2);
3388 for (nr
= 0; *p
++; nr
++) {
3391 dprintk("cookie = %Lu, ", *((unsigned long long *)p
));
3392 p
+= 2; /* cookie */
3393 len
= ntohl(*p
++); /* filename length */
3394 if (len
> NFS4_MAXNAMLEN
) {
3395 printk(KERN_WARNING
"NFS: giant filename in readdir (len 0x%x)\n", len
);
3398 xlen
= XDR_QUADLEN(len
);
3399 if (end
- p
< xlen
+ 1)
3401 dprintk("filename = %*s\n", len
, (char *)p
);
3403 len
= ntohl(*p
++); /* bitmap length */
3404 if (end
- p
< len
+ 1)
3407 attrlen
= XDR_QUADLEN(ntohl(*p
++));
3408 if (end
- p
< attrlen
+ 2)
3410 p
+= attrlen
; /* attributes */
3413 if (!nr
&& (entry
[0] != 0 || entry
[1] == 0))
3416 kunmap_atomic(kaddr
, KM_USER0
);
3419 dprintk("%s: short packet at entry %d\n", __FUNCTION__
, nr
);
3420 entry
[0] = entry
[1] = 0;
3421 /* truncate listing ? */
3423 printk(KERN_NOTICE
"NFS: readdir reply truncated!\n");
3428 kunmap_atomic(kaddr
, KM_USER0
);
3429 return -errno_NFSERR_IO
;
3432 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
3434 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
3435 struct kvec
*iov
= rcvbuf
->head
;
3436 int hdrlen
, len
, recvd
;
3441 status
= decode_op_hdr(xdr
, OP_READLINK
);
3445 /* Convert length of symlink */
3448 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
3449 dprintk(KERN_WARNING
"nfs: server returned giant symlink!\n");
3450 return -ENAMETOOLONG
;
3452 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
3453 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3455 printk(KERN_WARNING
"NFS: server cheating in readlink reply: "
3456 "count %u > recvd %u\n", len
, recvd
);
3459 xdr_read_pages(xdr
, len
);
3461 * The XDR encode routine has set things up so that
3462 * the link text will be copied directly into the
3463 * buffer. We just have to do overflow-checking,
3464 * and and null-terminate the text (the VFS expects
3465 * null-termination).
3467 kaddr
= (char *)kmap_atomic(rcvbuf
->pages
[0], KM_USER0
);
3468 kaddr
[len
+rcvbuf
->page_base
] = '\0';
3469 kunmap_atomic(kaddr
, KM_USER0
);
3473 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3477 status
= decode_op_hdr(xdr
, OP_REMOVE
);
3480 status
= decode_change_info(xdr
, cinfo
);
3485 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
3486 struct nfs4_change_info
*new_cinfo
)
3490 status
= decode_op_hdr(xdr
, OP_RENAME
);
3493 if ((status
= decode_change_info(xdr
, old_cinfo
)))
3495 status
= decode_change_info(xdr
, new_cinfo
);
3500 static int decode_renew(struct xdr_stream
*xdr
)
3502 return decode_op_hdr(xdr
, OP_RENEW
);
3506 decode_restorefh(struct xdr_stream
*xdr
)
3508 return decode_op_hdr(xdr
, OP_RESTOREFH
);
3511 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
3517 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
3521 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3523 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3525 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3528 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
3530 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
3533 /* We ignore &savep and don't do consistency checks on
3534 * the attr length. Let userspace figure it out.... */
3535 hdrlen
= (u8
*)xdr
->p
- (u8
*)iov
->iov_base
;
3536 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3537 if (attrlen
> recvd
) {
3538 printk(KERN_WARNING
"NFS: server cheating in getattr"
3539 " acl reply: attrlen %u > recvd %u\n",
3543 xdr_read_pages(xdr
, attrlen
);
3546 status
= -EOPNOTSUPP
;
3553 decode_savefh(struct xdr_stream
*xdr
)
3555 return decode_op_hdr(xdr
, OP_SAVEFH
);
3558 static int decode_setattr(struct xdr_stream
*xdr
, struct nfs_setattrres
*res
)
3565 status
= decode_op_hdr(xdr
, OP_SETATTR
);
3570 READ_BUF(bmlen
<< 2);
3574 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs_client
*clp
)
3582 if (opnum
!= OP_SETCLIENTID
) {
3584 "nfs4_decode_setclientid: Server returned operation"
3589 if (nfserr
== NFS_OK
) {
3590 READ_BUF(8 + sizeof(clp
->cl_confirm
.data
));
3591 READ64(clp
->cl_clientid
);
3592 COPYMEM(clp
->cl_confirm
.data
, sizeof(clp
->cl_confirm
.data
));
3593 } else if (nfserr
== NFSERR_CLID_INUSE
) {
3596 /* skip netid string */
3601 /* skip uaddr string */
3605 return -NFSERR_CLID_INUSE
;
3607 return -nfs4_stat_to_errno(nfserr
);
3612 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
3614 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
3617 static int decode_write(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
3622 status
= decode_op_hdr(xdr
, OP_WRITE
);
3628 READ32(res
->verf
->committed
);
3629 COPYMEM(res
->verf
->verifier
, 8);
3633 static int decode_delegreturn(struct xdr_stream
*xdr
)
3635 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
3639 * Decode OPEN_DOWNGRADE response
3641 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*res
)
3643 struct xdr_stream xdr
;
3644 struct compound_hdr hdr
;
3647 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3648 status
= decode_compound_hdr(&xdr
, &hdr
);
3651 status
= decode_putfh(&xdr
);
3654 status
= decode_open_downgrade(&xdr
, res
);
3657 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3663 * END OF "GENERIC" DECODE ROUTINES.
3667 * Decode ACCESS response
3669 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_accessres
*res
)
3671 struct xdr_stream xdr
;
3672 struct compound_hdr hdr
;
3675 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3676 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3678 if ((status
= decode_putfh(&xdr
)) == 0)
3679 status
= decode_access(&xdr
, res
);
3685 * Decode LOOKUP response
3687 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
3689 struct xdr_stream xdr
;
3690 struct compound_hdr hdr
;
3693 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3694 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3696 if ((status
= decode_putfh(&xdr
)) != 0)
3698 if ((status
= decode_lookup(&xdr
)) != 0)
3700 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
3702 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3708 * Decode LOOKUP_ROOT response
3710 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
3712 struct xdr_stream xdr
;
3713 struct compound_hdr hdr
;
3716 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3717 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3719 if ((status
= decode_putrootfh(&xdr
)) != 0)
3721 if ((status
= decode_getfh(&xdr
, res
->fh
)) == 0)
3722 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3728 * Decode REMOVE response
3730 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_remove_res
*res
)
3732 struct xdr_stream xdr
;
3733 struct compound_hdr hdr
;
3736 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3737 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3739 if ((status
= decode_putfh(&xdr
)) != 0)
3741 if ((status
= decode_remove(&xdr
, &res
->cinfo
)) != 0)
3743 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
);
3749 * Decode RENAME response
3751 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_rename_res
*res
)
3753 struct xdr_stream xdr
;
3754 struct compound_hdr hdr
;
3757 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3758 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3760 if ((status
= decode_putfh(&xdr
)) != 0)
3762 if ((status
= decode_savefh(&xdr
)) != 0)
3764 if ((status
= decode_putfh(&xdr
)) != 0)
3766 if ((status
= decode_rename(&xdr
, &res
->old_cinfo
, &res
->new_cinfo
)) != 0)
3768 /* Current FH is target directory */
3769 if (decode_getfattr(&xdr
, res
->new_fattr
, res
->server
) != 0)
3771 if ((status
= decode_restorefh(&xdr
)) != 0)
3773 decode_getfattr(&xdr
, res
->old_fattr
, res
->server
);
3779 * Decode LINK response
3781 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_link_res
*res
)
3783 struct xdr_stream xdr
;
3784 struct compound_hdr hdr
;
3787 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3788 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3790 if ((status
= decode_putfh(&xdr
)) != 0)
3792 if ((status
= decode_savefh(&xdr
)) != 0)
3794 if ((status
= decode_putfh(&xdr
)) != 0)
3796 if ((status
= decode_link(&xdr
, &res
->cinfo
)) != 0)
3799 * Note order: OP_LINK leaves the directory as the current
3802 if (decode_getfattr(&xdr
, res
->dir_attr
, res
->server
) != 0)
3804 if ((status
= decode_restorefh(&xdr
)) != 0)
3806 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3812 * Decode CREATE response
3814 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
3816 struct xdr_stream xdr
;
3817 struct compound_hdr hdr
;
3820 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3821 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3823 if ((status
= decode_putfh(&xdr
)) != 0)
3825 if ((status
= decode_savefh(&xdr
)) != 0)
3827 if ((status
= decode_create(&xdr
,&res
->dir_cinfo
)) != 0)
3829 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
3831 if (decode_getfattr(&xdr
, res
->fattr
, res
->server
) != 0)
3833 if ((status
= decode_restorefh(&xdr
)) != 0)
3835 decode_getfattr(&xdr
, res
->dir_fattr
, res
->server
);
3841 * Decode SYMLINK response
3843 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
3845 return nfs4_xdr_dec_create(rqstp
, p
, res
);
3849 * Decode GETATTR response
3851 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_getattr_res
*res
)
3853 struct xdr_stream xdr
;
3854 struct compound_hdr hdr
;
3857 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3858 status
= decode_compound_hdr(&xdr
, &hdr
);
3861 status
= decode_putfh(&xdr
);
3864 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3871 * Encode an SETACL request
3874 nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setaclargs
*args
)
3876 struct xdr_stream xdr
;
3877 struct compound_hdr hdr
= {
3882 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
3883 encode_compound_hdr(&xdr
, &hdr
);
3884 status
= encode_putfh(&xdr
, args
->fh
);
3887 status
= encode_setacl(&xdr
, args
);
3892 * Decode SETACL response
3895 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, __be32
*p
, void *res
)
3897 struct xdr_stream xdr
;
3898 struct compound_hdr hdr
;
3901 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3902 status
= decode_compound_hdr(&xdr
, &hdr
);
3905 status
= decode_putfh(&xdr
);
3908 status
= decode_setattr(&xdr
, res
);
3914 * Decode GETACL response
3917 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, __be32
*p
, size_t *acl_len
)
3919 struct xdr_stream xdr
;
3920 struct compound_hdr hdr
;
3923 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3924 status
= decode_compound_hdr(&xdr
, &hdr
);
3927 status
= decode_putfh(&xdr
);
3930 status
= decode_getacl(&xdr
, rqstp
, acl_len
);
3937 * Decode CLOSE response
3939 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*res
)
3941 struct xdr_stream xdr
;
3942 struct compound_hdr hdr
;
3945 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3946 status
= decode_compound_hdr(&xdr
, &hdr
);
3949 status
= decode_putfh(&xdr
);
3952 status
= decode_close(&xdr
, res
);
3956 * Note: Server may do delete on close for this file
3957 * in which case the getattr call will fail with
3958 * an ESTALE error. Shouldn't be a problem,
3959 * though, since fattr->valid will remain unset.
3961 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3967 * Decode OPEN response
3969 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
3971 struct xdr_stream xdr
;
3972 struct compound_hdr hdr
;
3975 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3976 status
= decode_compound_hdr(&xdr
, &hdr
);
3979 status
= decode_putfh(&xdr
);
3982 status
= decode_savefh(&xdr
);
3985 status
= decode_open(&xdr
, res
);
3988 status
= decode_getfh(&xdr
, &res
->fh
);
3991 if (decode_getfattr(&xdr
, res
->f_attr
, res
->server
) != 0)
3993 if ((status
= decode_restorefh(&xdr
)) != 0)
3995 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
);
4001 * Decode OPEN_CONFIRM response
4003 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_open_confirmres
*res
)
4005 struct xdr_stream xdr
;
4006 struct compound_hdr hdr
;
4009 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4010 status
= decode_compound_hdr(&xdr
, &hdr
);
4013 status
= decode_putfh(&xdr
);
4016 status
= decode_open_confirm(&xdr
, res
);
4022 * Decode OPEN response
4024 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
4026 struct xdr_stream xdr
;
4027 struct compound_hdr hdr
;
4030 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4031 status
= decode_compound_hdr(&xdr
, &hdr
);
4034 status
= decode_putfh(&xdr
);
4037 status
= decode_open(&xdr
, res
);
4040 decode_getfattr(&xdr
, res
->f_attr
, res
->server
);
4046 * Decode SETATTR response
4048 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_setattrres
*res
)
4050 struct xdr_stream xdr
;
4051 struct compound_hdr hdr
;
4054 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4055 status
= decode_compound_hdr(&xdr
, &hdr
);
4058 status
= decode_putfh(&xdr
);
4061 status
= decode_setattr(&xdr
, res
);
4064 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4065 if (status
== NFS4ERR_DELAY
)
4072 * Decode LOCK response
4074 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lock_res
*res
)
4076 struct xdr_stream xdr
;
4077 struct compound_hdr hdr
;
4080 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4081 status
= decode_compound_hdr(&xdr
, &hdr
);
4084 status
= decode_putfh(&xdr
);
4087 status
= decode_lock(&xdr
, res
);
4093 * Decode LOCKT response
4095 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lockt_res
*res
)
4097 struct xdr_stream xdr
;
4098 struct compound_hdr hdr
;
4101 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4102 status
= decode_compound_hdr(&xdr
, &hdr
);
4105 status
= decode_putfh(&xdr
);
4108 status
= decode_lockt(&xdr
, res
);
4114 * Decode LOCKU response
4116 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_locku_res
*res
)
4118 struct xdr_stream xdr
;
4119 struct compound_hdr hdr
;
4122 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4123 status
= decode_compound_hdr(&xdr
, &hdr
);
4126 status
= decode_putfh(&xdr
);
4129 status
= decode_locku(&xdr
, res
);
4135 * Decode READLINK response
4137 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
, __be32
*p
, void *res
)
4139 struct xdr_stream xdr
;
4140 struct compound_hdr hdr
;
4143 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4144 status
= decode_compound_hdr(&xdr
, &hdr
);
4147 status
= decode_putfh(&xdr
);
4150 status
= decode_readlink(&xdr
, rqstp
);
4156 * Decode READDIR response
4158 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_readdir_res
*res
)
4160 struct xdr_stream xdr
;
4161 struct compound_hdr hdr
;
4164 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4165 status
= decode_compound_hdr(&xdr
, &hdr
);
4168 status
= decode_putfh(&xdr
);
4171 status
= decode_readdir(&xdr
, rqstp
, res
);
4177 * Decode Read response
4179 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_readres
*res
)
4181 struct xdr_stream xdr
;
4182 struct compound_hdr hdr
;
4185 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4186 status
= decode_compound_hdr(&xdr
, &hdr
);
4189 status
= decode_putfh(&xdr
);
4192 status
= decode_read(&xdr
, rqstp
, res
);
4194 status
= res
->count
;
4200 * Decode WRITE response
4202 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
4204 struct xdr_stream xdr
;
4205 struct compound_hdr hdr
;
4208 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4209 status
= decode_compound_hdr(&xdr
, &hdr
);
4212 status
= decode_putfh(&xdr
);
4215 status
= decode_write(&xdr
, res
);
4218 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4220 status
= res
->count
;
4226 * Decode COMMIT response
4228 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
4230 struct xdr_stream xdr
;
4231 struct compound_hdr hdr
;
4234 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4235 status
= decode_compound_hdr(&xdr
, &hdr
);
4238 status
= decode_putfh(&xdr
);
4241 status
= decode_commit(&xdr
, res
);
4244 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4252 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsinfo
*fsinfo
)
4254 struct xdr_stream xdr
;
4255 struct compound_hdr hdr
;
4258 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4259 status
= decode_compound_hdr(&xdr
, &hdr
);
4261 status
= decode_putfh(&xdr
);
4263 status
= decode_fsinfo(&xdr
, fsinfo
);
4265 status
= -nfs4_stat_to_errno(hdr
.status
);
4272 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, __be32
*p
, struct nfs_pathconf
*pathconf
)
4274 struct xdr_stream xdr
;
4275 struct compound_hdr hdr
;
4278 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4279 status
= decode_compound_hdr(&xdr
, &hdr
);
4281 status
= decode_putfh(&xdr
);
4283 status
= decode_pathconf(&xdr
, pathconf
);
4290 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsstat
*fsstat
)
4292 struct xdr_stream xdr
;
4293 struct compound_hdr hdr
;
4296 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4297 status
= decode_compound_hdr(&xdr
, &hdr
);
4299 status
= decode_putfh(&xdr
);
4301 status
= decode_statfs(&xdr
, fsstat
);
4306 * GETATTR_BITMAP request
4308 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_server_caps_res
*res
)
4310 struct xdr_stream xdr
;
4311 struct compound_hdr hdr
;
4314 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4315 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
4317 if ((status
= decode_putfh(&xdr
)) != 0)
4319 status
= decode_server_caps(&xdr
, res
);
4325 * Decode RENEW response
4327 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, __be32
*p
, void *dummy
)
4329 struct xdr_stream xdr
;
4330 struct compound_hdr hdr
;
4333 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4334 status
= decode_compound_hdr(&xdr
, &hdr
);
4336 status
= decode_renew(&xdr
);
4341 * a SETCLIENTID request
4343 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
, __be32
*p
,
4344 struct nfs_client
*clp
)
4346 struct xdr_stream xdr
;
4347 struct compound_hdr hdr
;
4350 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4351 status
= decode_compound_hdr(&xdr
, &hdr
);
4353 status
= decode_setclientid(&xdr
, clp
);
4355 status
= -nfs4_stat_to_errno(hdr
.status
);
4360 * a SETCLIENTID_CONFIRM request
4362 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsinfo
*fsinfo
)
4364 struct xdr_stream xdr
;
4365 struct compound_hdr hdr
;
4368 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4369 status
= decode_compound_hdr(&xdr
, &hdr
);
4371 status
= decode_setclientid_confirm(&xdr
);
4373 status
= decode_putrootfh(&xdr
);
4375 status
= decode_fsinfo(&xdr
, fsinfo
);
4377 status
= -nfs4_stat_to_errno(hdr
.status
);
4382 * DELEGRETURN request
4384 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_delegreturnres
*res
)
4386 struct xdr_stream xdr
;
4387 struct compound_hdr hdr
;
4390 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4391 status
= decode_compound_hdr(&xdr
, &hdr
);
4394 status
= decode_putfh(&xdr
);
4397 status
= decode_delegreturn(&xdr
);
4398 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4404 * FS_LOCATIONS request
4406 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fs_locations
*res
)
4408 struct xdr_stream xdr
;
4409 struct compound_hdr hdr
;
4412 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4413 status
= decode_compound_hdr(&xdr
, &hdr
);
4416 if ((status
= decode_putfh(&xdr
)) != 0)
4418 if ((status
= decode_lookup(&xdr
)) != 0)
4420 xdr_enter_page(&xdr
, PAGE_SIZE
);
4421 status
= decode_getfattr(&xdr
, &res
->fattr
, res
->server
);
4426 __be32
*nfs4_decode_dirent(__be32
*p
, struct nfs_entry
*entry
, int plus
)
4428 uint32_t bitmap
[2] = {0};
4433 return ERR_PTR(-EAGAIN
);
4435 return ERR_PTR(-EBADCOOKIE
);
4438 entry
->prev_cookie
= entry
->cookie
;
4439 p
= xdr_decode_hyper(p
, &entry
->cookie
);
4440 entry
->len
= ntohl(*p
++);
4441 entry
->name
= (const char *) p
;
4442 p
+= XDR_QUADLEN(entry
->len
);
4445 * In case the server doesn't return an inode number,
4446 * we fake one here. (We don't use inode number 0,
4447 * since glibc seems to choke on it...)
4451 len
= ntohl(*p
++); /* bitmap length */
4453 bitmap
[0] = ntohl(*p
++);
4455 bitmap
[1] = ntohl(*p
++);
4459 len
= XDR_QUADLEN(ntohl(*p
++)); /* attribute buffer length */
4461 if (bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
) {
4462 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
4463 /* Ignore the return value of rdattr_error for now */
4467 if (bitmap
[0] == 0 && bitmap
[1] == FATTR4_WORD1_MOUNTED_ON_FILEID
)
4468 xdr_decode_hyper(p
, &entry
->ino
);
4469 else if (bitmap
[0] == FATTR4_WORD0_FILEID
)
4470 xdr_decode_hyper(p
, &entry
->ino
);
4474 entry
->eof
= !p
[0] && p
[1];
4479 * We need to translate between nfs status return values and
4480 * the local errno values which may not be the same.
4487 { NFS4ERR_PERM
, EPERM
},
4488 { NFS4ERR_NOENT
, ENOENT
},
4489 { NFS4ERR_IO
, errno_NFSERR_IO
},
4490 { NFS4ERR_NXIO
, ENXIO
},
4491 { NFS4ERR_ACCESS
, EACCES
},
4492 { NFS4ERR_EXIST
, EEXIST
},
4493 { NFS4ERR_XDEV
, EXDEV
},
4494 { NFS4ERR_NOTDIR
, ENOTDIR
},
4495 { NFS4ERR_ISDIR
, EISDIR
},
4496 { NFS4ERR_INVAL
, EINVAL
},
4497 { NFS4ERR_FBIG
, EFBIG
},
4498 { NFS4ERR_NOSPC
, ENOSPC
},
4499 { NFS4ERR_ROFS
, EROFS
},
4500 { NFS4ERR_MLINK
, EMLINK
},
4501 { NFS4ERR_NAMETOOLONG
, ENAMETOOLONG
},
4502 { NFS4ERR_NOTEMPTY
, ENOTEMPTY
},
4503 { NFS4ERR_DQUOT
, EDQUOT
},
4504 { NFS4ERR_STALE
, ESTALE
},
4505 { NFS4ERR_BADHANDLE
, EBADHANDLE
},
4506 { NFS4ERR_BADOWNER
, EINVAL
},
4507 { NFS4ERR_BADNAME
, EINVAL
},
4508 { NFS4ERR_BAD_COOKIE
, EBADCOOKIE
},
4509 { NFS4ERR_NOTSUPP
, ENOTSUPP
},
4510 { NFS4ERR_TOOSMALL
, ETOOSMALL
},
4511 { NFS4ERR_SERVERFAULT
, ESERVERFAULT
},
4512 { NFS4ERR_BADTYPE
, EBADTYPE
},
4513 { NFS4ERR_LOCKED
, EAGAIN
},
4514 { NFS4ERR_RESOURCE
, EREMOTEIO
},
4515 { NFS4ERR_SYMLINK
, ELOOP
},
4516 { NFS4ERR_OP_ILLEGAL
, EOPNOTSUPP
},
4517 { NFS4ERR_DEADLOCK
, EDEADLK
},
4518 { NFS4ERR_WRONGSEC
, EPERM
}, /* FIXME: this needs
4519 * to be handled by a
4526 * Convert an NFS error code to a local one.
4527 * This one is used jointly by NFSv2 and NFSv3.
4530 nfs4_stat_to_errno(int stat
)
4533 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
4534 if (nfs_errtbl
[i
].stat
== stat
)
4535 return nfs_errtbl
[i
].errno
;
4537 if (stat
<= 10000 || stat
> 10100) {
4538 /* The server is looney tunes. */
4539 return ESERVERFAULT
;
4541 /* If we cannot translate the error, the recovery routines should
4543 * Note: remaining NFSv4 error codes have values > 10000, so should
4544 * not conflict with native Linux error codes.
4549 #define PROC(proc, argtype, restype) \
4550 [NFSPROC4_CLNT_##proc] = { \
4551 .p_proc = NFSPROC4_COMPOUND, \
4552 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4553 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4554 .p_arglen = NFS4_##argtype##_sz, \
4555 .p_replen = NFS4_##restype##_sz, \
4556 .p_statidx = NFSPROC4_CLNT_##proc, \
4560 struct rpc_procinfo nfs4_procedures
[] = {
4561 PROC(READ
, enc_read
, dec_read
),
4562 PROC(WRITE
, enc_write
, dec_write
),
4563 PROC(COMMIT
, enc_commit
, dec_commit
),
4564 PROC(OPEN
, enc_open
, dec_open
),
4565 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
4566 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
4567 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
4568 PROC(CLOSE
, enc_close
, dec_close
),
4569 PROC(SETATTR
, enc_setattr
, dec_setattr
),
4570 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
4571 PROC(RENEW
, enc_renew
, dec_renew
),
4572 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
4573 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
4574 PROC(LOCK
, enc_lock
, dec_lock
),
4575 PROC(LOCKT
, enc_lockt
, dec_lockt
),
4576 PROC(LOCKU
, enc_locku
, dec_locku
),
4577 PROC(ACCESS
, enc_access
, dec_access
),
4578 PROC(GETATTR
, enc_getattr
, dec_getattr
),
4579 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
4580 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
4581 PROC(REMOVE
, enc_remove
, dec_remove
),
4582 PROC(RENAME
, enc_rename
, dec_rename
),
4583 PROC(LINK
, enc_link
, dec_link
),
4584 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
4585 PROC(CREATE
, enc_create
, dec_create
),
4586 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
4587 PROC(STATFS
, enc_statfs
, dec_statfs
),
4588 PROC(READLINK
, enc_readlink
, dec_readlink
),
4589 PROC(READDIR
, enc_readdir
, dec_readdir
),
4590 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
4591 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
4592 PROC(GETACL
, enc_getacl
, dec_getacl
),
4593 PROC(SETACL
, enc_setacl
, dec_setacl
),
4594 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
4597 struct rpc_version nfs_version4
= {
4599 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
4600 .procs
= nfs4_procedures