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 nfs_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_getattr_maxsz)
391 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
392 decode_getattr_maxsz)
393 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
394 encode_putfh_maxsz + \
395 encode_delegreturn_maxsz)
396 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
397 decode_delegreturn_maxsz)
398 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
399 encode_putfh_maxsz + \
400 encode_getattr_maxsz)
401 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
402 decode_putfh_maxsz + \
403 op_decode_hdr_maxsz + \
404 nfs4_fattr_bitmap_maxsz + 1)
405 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
406 encode_putfh_maxsz + \
407 op_encode_hdr_maxsz + 4 + \
408 nfs4_fattr_bitmap_maxsz + 1)
409 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
410 decode_putfh_maxsz + \
411 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
415 unsigned int nfs2type
;
423 { S_IFSOCK
, NFSOCK
},
429 struct compound_hdr
{
437 * START OF "GENERIC" ENCODE ROUTINES.
438 * These may look a little ugly since they are imported from a "generic"
439 * set of XDR encode/decode routines which are intended to be shared by
440 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
442 * If the pain of reading these is too great, it should be a straightforward
443 * task to translate them into Linux-specific versions which are more
444 * consistent with the style used in NFSv2/v3...
446 #define WRITE32(n) *p++ = htonl(n)
447 #define WRITE64(n) do { \
448 *p++ = htonl((uint32_t)((n) >> 32)); \
449 *p++ = htonl((uint32_t)(n)); \
451 #define WRITEMEM(ptr,nbytes) do { \
452 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
455 #define RESERVE_SPACE(nbytes) do { \
456 p = xdr_reserve_space(xdr, nbytes); \
457 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
461 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
465 p
= xdr_reserve_space(xdr
, 4 + len
);
467 xdr_encode_opaque(p
, str
, len
);
470 static int encode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
474 dprintk("encode_compound: tag=%.*s\n", (int)hdr
->taglen
, hdr
->tag
);
475 BUG_ON(hdr
->taglen
> NFS4_MAXTAGLEN
);
476 RESERVE_SPACE(12+(XDR_QUADLEN(hdr
->taglen
)<<2));
477 WRITE32(hdr
->taglen
);
478 WRITEMEM(hdr
->tag
, hdr
->taglen
);
479 WRITE32(NFS4_MINOR_VERSION
);
484 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
488 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
490 xdr_encode_opaque_fixed(p
, verf
->data
, NFS4_VERIFIER_SIZE
);
493 static int encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
, const struct nfs_server
*server
)
495 char owner_name
[IDMAP_NAMESZ
];
496 char owner_group
[IDMAP_NAMESZ
];
497 int owner_namelen
= 0;
498 int owner_grouplen
= 0;
507 * We reserve enough space to write the entire attribute buffer at once.
508 * In the worst-case, this would be
509 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
510 * = 36 bytes, plus any contribution from variable-length fields
511 * such as owner/group.
516 if (iap
->ia_valid
& ATTR_SIZE
)
518 if (iap
->ia_valid
& ATTR_MODE
)
520 if (iap
->ia_valid
& ATTR_UID
) {
521 owner_namelen
= nfs_map_uid_to_name(server
->nfs4_state
, iap
->ia_uid
, owner_name
);
522 if (owner_namelen
< 0) {
523 printk(KERN_WARNING
"nfs: couldn't resolve uid %d to string\n",
526 strcpy(owner_name
, "nobody");
527 owner_namelen
= sizeof("nobody") - 1;
530 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
532 if (iap
->ia_valid
& ATTR_GID
) {
533 owner_grouplen
= nfs_map_gid_to_group(server
->nfs4_state
, iap
->ia_gid
, owner_group
);
534 if (owner_grouplen
< 0) {
535 printk(KERN_WARNING
"nfs4: couldn't resolve gid %d to string\n",
537 strcpy(owner_group
, "nobody");
538 owner_grouplen
= sizeof("nobody") - 1;
541 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
543 if (iap
->ia_valid
& ATTR_ATIME_SET
)
545 else if (iap
->ia_valid
& ATTR_ATIME
)
547 if (iap
->ia_valid
& ATTR_MTIME_SET
)
549 else if (iap
->ia_valid
& ATTR_MTIME
)
554 * We write the bitmap length now, but leave the bitmap and the attribute
555 * buffer length to be backfilled at the end of this routine.
561 if (iap
->ia_valid
& ATTR_SIZE
) {
562 bmval0
|= FATTR4_WORD0_SIZE
;
563 WRITE64(iap
->ia_size
);
565 if (iap
->ia_valid
& ATTR_MODE
) {
566 bmval1
|= FATTR4_WORD1_MODE
;
567 WRITE32(iap
->ia_mode
);
569 if (iap
->ia_valid
& ATTR_UID
) {
570 bmval1
|= FATTR4_WORD1_OWNER
;
571 WRITE32(owner_namelen
);
572 WRITEMEM(owner_name
, owner_namelen
);
574 if (iap
->ia_valid
& ATTR_GID
) {
575 bmval1
|= FATTR4_WORD1_OWNER_GROUP
;
576 WRITE32(owner_grouplen
);
577 WRITEMEM(owner_group
, owner_grouplen
);
579 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
580 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
581 WRITE32(NFS4_SET_TO_CLIENT_TIME
);
583 WRITE32(iap
->ia_mtime
.tv_sec
);
584 WRITE32(iap
->ia_mtime
.tv_nsec
);
586 else if (iap
->ia_valid
& ATTR_ATIME
) {
587 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
588 WRITE32(NFS4_SET_TO_SERVER_TIME
);
590 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
591 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
592 WRITE32(NFS4_SET_TO_CLIENT_TIME
);
594 WRITE32(iap
->ia_mtime
.tv_sec
);
595 WRITE32(iap
->ia_mtime
.tv_nsec
);
597 else if (iap
->ia_valid
& ATTR_MTIME
) {
598 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
599 WRITE32(NFS4_SET_TO_SERVER_TIME
);
603 * Now we backfill the bitmap and the attribute buffer length.
605 if (len
!= ((char *)p
- (char *)q
) + 4) {
606 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
607 len
, ((char *)p
- (char *)q
) + 4);
610 len
= (char *)p
- (char *)q
- 12;
611 *q
++ = htonl(bmval0
);
612 *q
++ = htonl(bmval1
);
620 static int encode_access(struct xdr_stream
*xdr
, u32 access
)
631 static int encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
)
635 RESERVE_SPACE(8+sizeof(arg
->stateid
->data
));
637 WRITE32(arg
->seqid
->sequence
->counter
);
638 WRITEMEM(arg
->stateid
->data
, sizeof(arg
->stateid
->data
));
643 static int encode_commit(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
)
649 WRITE64(args
->offset
);
650 WRITE32(args
->count
);
655 static int encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
)
661 WRITE32(create
->ftype
);
663 switch (create
->ftype
) {
665 RESERVE_SPACE(4 + create
->u
.symlink
->len
);
666 WRITE32(create
->u
.symlink
->len
);
667 WRITEMEM(create
->u
.symlink
->name
, create
->u
.symlink
->len
);
670 case NF4BLK
: case NF4CHR
:
672 WRITE32(create
->u
.device
.specdata1
);
673 WRITE32(create
->u
.device
.specdata2
);
680 RESERVE_SPACE(4 + create
->name
->len
);
681 WRITE32(create
->name
->len
);
682 WRITEMEM(create
->name
->name
, create
->name
->len
);
684 return encode_attrs(xdr
, create
->attrs
, create
->server
);
687 static int encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
)
698 static int encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
)
710 static int encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
)
712 return encode_getattr_two(xdr
,
713 bitmask
[0] & nfs4_fattr_bitmap
[0],
714 bitmask
[1] & nfs4_fattr_bitmap
[1]);
717 static int encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
)
719 return encode_getattr_two(xdr
, bitmask
[0] & nfs4_fsinfo_bitmap
[0],
720 bitmask
[1] & nfs4_fsinfo_bitmap
[1]);
723 static int encode_getfh(struct xdr_stream
*xdr
)
733 static int encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
)
737 RESERVE_SPACE(8 + name
->len
);
740 WRITEMEM(name
->name
, name
->len
);
746 * opcode,type,reclaim,offset,length,new_lock_owner = 32
747 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
749 static int encode_lock(struct xdr_stream
*xdr
, const struct nfs_lockargs
*arg
)
752 struct nfs_lock_opargs
*opargs
= arg
->u
.lock
;
757 WRITE32(opargs
->reclaim
);
758 WRITE64(arg
->offset
);
759 WRITE64(arg
->length
);
760 WRITE32(opargs
->new_lock_owner
);
761 if (opargs
->new_lock_owner
){
763 WRITE32(opargs
->open_seqid
->sequence
->counter
);
764 WRITEMEM(opargs
->open_stateid
->data
, sizeof(opargs
->open_stateid
->data
));
765 WRITE32(opargs
->lock_seqid
->sequence
->counter
);
766 WRITE64(opargs
->lock_owner
.clientid
);
768 WRITE32(opargs
->lock_owner
.id
);
772 WRITEMEM(opargs
->lock_stateid
->data
, sizeof(opargs
->lock_stateid
->data
));
773 WRITE32(opargs
->lock_seqid
->sequence
->counter
);
779 static int encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockargs
*arg
)
782 struct nfs_lowner
*opargs
= arg
->u
.lockt
;
787 WRITE64(arg
->offset
);
788 WRITE64(arg
->length
);
789 WRITE64(opargs
->clientid
);
796 static int encode_locku(struct xdr_stream
*xdr
, const struct nfs_lockargs
*arg
)
799 struct nfs_locku_opargs
*opargs
= arg
->u
.locku
;
804 WRITE32(opargs
->seqid
->sequence
->counter
);
805 WRITEMEM(opargs
->stateid
->data
, sizeof(opargs
->stateid
->data
));
806 WRITE64(arg
->offset
);
807 WRITE64(arg
->length
);
812 static int encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
)
817 RESERVE_SPACE(8 + len
);
820 WRITEMEM(name
->name
, len
);
825 static void encode_share_access(struct xdr_stream
*xdr
, int open_flags
)
830 switch (open_flags
& (FMODE_READ
|FMODE_WRITE
)) {
832 WRITE32(NFS4_SHARE_ACCESS_READ
);
835 WRITE32(NFS4_SHARE_ACCESS_WRITE
);
837 case FMODE_READ
|FMODE_WRITE
:
838 WRITE32(NFS4_SHARE_ACCESS_BOTH
);
843 WRITE32(0); /* for linux, share_deny = 0 always */
846 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
850 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
855 WRITE32(arg
->seqid
->sequence
->counter
);
856 encode_share_access(xdr
, arg
->open_flags
);
858 WRITE64(arg
->clientid
);
863 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
868 switch(arg
->open_flags
& O_EXCL
) {
870 WRITE32(NFS4_CREATE_UNCHECKED
);
871 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
874 WRITE32(NFS4_CREATE_EXCLUSIVE
);
875 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
879 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
884 switch (arg
->open_flags
& O_CREAT
) {
886 WRITE32(NFS4_OPEN_NOCREATE
);
889 BUG_ON(arg
->claim
!= NFS4_OPEN_CLAIM_NULL
);
890 WRITE32(NFS4_OPEN_CREATE
);
891 encode_createmode(xdr
, arg
);
895 static inline void encode_delegation_type(struct xdr_stream
*xdr
, int delegation_type
)
900 switch (delegation_type
) {
902 WRITE32(NFS4_OPEN_DELEGATE_NONE
);
905 WRITE32(NFS4_OPEN_DELEGATE_READ
);
907 case FMODE_WRITE
|FMODE_READ
:
908 WRITE32(NFS4_OPEN_DELEGATE_WRITE
);
915 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
920 WRITE32(NFS4_OPEN_CLAIM_NULL
);
921 encode_string(xdr
, name
->len
, name
->name
);
924 static inline void encode_claim_previous(struct xdr_stream
*xdr
, int type
)
929 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS
);
930 encode_delegation_type(xdr
, type
);
933 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
937 RESERVE_SPACE(4+sizeof(stateid
->data
));
938 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
939 WRITEMEM(stateid
->data
, sizeof(stateid
->data
));
940 encode_string(xdr
, name
->len
, name
->name
);
943 static int encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
945 encode_openhdr(xdr
, arg
);
946 encode_opentype(xdr
, arg
);
947 switch (arg
->claim
) {
948 case NFS4_OPEN_CLAIM_NULL
:
949 encode_claim_null(xdr
, arg
->name
);
951 case NFS4_OPEN_CLAIM_PREVIOUS
:
952 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
954 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
955 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
963 static int encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
)
967 RESERVE_SPACE(8+sizeof(arg
->stateid
.data
));
968 WRITE32(OP_OPEN_CONFIRM
);
969 WRITEMEM(arg
->stateid
.data
, sizeof(arg
->stateid
.data
));
970 WRITE32(arg
->seqid
->sequence
->counter
);
975 static int encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
)
979 RESERVE_SPACE(8+sizeof(arg
->stateid
->data
));
980 WRITE32(OP_OPEN_DOWNGRADE
);
981 WRITEMEM(arg
->stateid
->data
, sizeof(arg
->stateid
->data
));
982 WRITE32(arg
->seqid
->sequence
->counter
);
983 encode_share_access(xdr
, arg
->open_flags
);
988 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
)
993 RESERVE_SPACE(8 + len
);
996 WRITEMEM(fh
->data
, len
);
1001 static int encode_putrootfh(struct xdr_stream
*xdr
)
1006 WRITE32(OP_PUTROOTFH
);
1011 static void encode_stateid(struct xdr_stream
*xdr
, const struct nfs_open_context
*ctx
)
1013 nfs4_stateid stateid
;
1017 if (ctx
->state
!= NULL
) {
1018 nfs4_copy_stateid(&stateid
, ctx
->state
, ctx
->lockowner
);
1019 WRITEMEM(stateid
.data
, sizeof(stateid
.data
));
1021 WRITEMEM(zero_stateid
.data
, sizeof(zero_stateid
.data
));
1024 static int encode_read(struct xdr_stream
*xdr
, const struct nfs_readargs
*args
)
1031 encode_stateid(xdr
, args
->context
);
1034 WRITE64(args
->offset
);
1035 WRITE32(args
->count
);
1040 static int encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
)
1042 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1043 uint32_t attrs
[2] = {
1044 FATTR4_WORD0_RDATTR_ERROR
|FATTR4_WORD0_FILEID
,
1045 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1050 RESERVE_SPACE(32+sizeof(nfs4_verifier
));
1051 WRITE32(OP_READDIR
);
1052 WRITE64(readdir
->cookie
);
1053 WRITEMEM(readdir
->verifier
.data
, sizeof(readdir
->verifier
.data
));
1054 WRITE32(readdir
->count
>> 1); /* We're not doing readdirplus */
1055 WRITE32(readdir
->count
);
1057 /* Switch to mounted_on_fileid if the server supports it */
1058 if (readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
1059 attrs
[0] &= ~FATTR4_WORD0_FILEID
;
1061 attrs
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
1062 WRITE32(attrs
[0] & readdir
->bitmask
[0]);
1063 WRITE32(attrs
[1] & readdir
->bitmask
[1]);
1064 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1066 (unsigned long long)readdir
->cookie
,
1067 ((u32
*)readdir
->verifier
.data
)[0],
1068 ((u32
*)readdir
->verifier
.data
)[1],
1069 attrs
[0] & readdir
->bitmask
[0],
1070 attrs
[1] & readdir
->bitmask
[1]);
1072 /* set up reply kvec
1073 * toplevel_status + taglen + rescount + OP_PUTFH + status
1074 * + OP_READDIR + status + verifer(2) = 9
1076 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 9) << 2;
1077 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, readdir
->pages
,
1078 readdir
->pgbase
, readdir
->count
);
1079 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1080 __FUNCTION__
, replen
, readdir
->pages
,
1081 readdir
->pgbase
, readdir
->count
);
1086 static int encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
)
1088 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1089 unsigned int replen
;
1093 WRITE32(OP_READLINK
);
1095 /* set up reply kvec
1096 * toplevel_status + taglen + rescount + OP_PUTFH + status
1097 * + OP_READLINK + status + string length = 8
1099 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 8) << 2;
1100 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, readlink
->pages
,
1101 readlink
->pgbase
, readlink
->pglen
);
1106 static int encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
)
1110 RESERVE_SPACE(8 + name
->len
);
1113 WRITEMEM(name
->name
, name
->len
);
1118 static int encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
)
1122 RESERVE_SPACE(8 + oldname
->len
);
1124 WRITE32(oldname
->len
);
1125 WRITEMEM(oldname
->name
, oldname
->len
);
1127 RESERVE_SPACE(4 + newname
->len
);
1128 WRITE32(newname
->len
);
1129 WRITEMEM(newname
->name
, newname
->len
);
1134 static int encode_renew(struct xdr_stream
*xdr
, const struct nfs4_client
*client_stateid
)
1140 WRITE64(client_stateid
->cl_clientid
);
1146 encode_restorefh(struct xdr_stream
*xdr
)
1151 WRITE32(OP_RESTOREFH
);
1157 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
)
1161 RESERVE_SPACE(4+sizeof(zero_stateid
.data
));
1162 WRITE32(OP_SETATTR
);
1163 WRITEMEM(zero_stateid
.data
, sizeof(zero_stateid
.data
));
1166 WRITE32(FATTR4_WORD0_ACL
);
1167 if (arg
->acl_len
% 4)
1170 WRITE32(arg
->acl_len
);
1171 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1176 encode_savefh(struct xdr_stream
*xdr
)
1186 static int encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
)
1191 RESERVE_SPACE(4+sizeof(arg
->stateid
.data
));
1192 WRITE32(OP_SETATTR
);
1193 WRITEMEM(arg
->stateid
.data
, sizeof(arg
->stateid
.data
));
1195 if ((status
= encode_attrs(xdr
, arg
->iap
, server
)))
1201 static int encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
)
1205 RESERVE_SPACE(4 + sizeof(setclientid
->sc_verifier
->data
));
1206 WRITE32(OP_SETCLIENTID
);
1207 WRITEMEM(setclientid
->sc_verifier
->data
, sizeof(setclientid
->sc_verifier
->data
));
1209 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1211 WRITE32(setclientid
->sc_prog
);
1212 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1213 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1215 WRITE32(setclientid
->sc_cb_ident
);
1220 static int encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs4_client
*client_state
)
1224 RESERVE_SPACE(12 + sizeof(client_state
->cl_confirm
.data
));
1225 WRITE32(OP_SETCLIENTID_CONFIRM
);
1226 WRITE64(client_state
->cl_clientid
);
1227 WRITEMEM(client_state
->cl_confirm
.data
, sizeof(client_state
->cl_confirm
.data
));
1232 static int encode_write(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
)
1239 encode_stateid(xdr
, args
->context
);
1242 WRITE64(args
->offset
);
1243 WRITE32(args
->stable
);
1244 WRITE32(args
->count
);
1246 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1251 static int encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
)
1257 WRITE32(OP_DELEGRETURN
);
1258 WRITEMEM(stateid
->data
, sizeof(stateid
->data
));
1263 * END OF "GENERIC" ENCODE ROUTINES.
1267 * Encode an ACCESS request
1269 static int nfs4_xdr_enc_access(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_accessargs
*args
)
1271 struct xdr_stream xdr
;
1272 struct compound_hdr hdr
= {
1277 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1278 encode_compound_hdr(&xdr
, &hdr
);
1279 if ((status
= encode_putfh(&xdr
, args
->fh
)) == 0)
1280 status
= encode_access(&xdr
, args
->access
);
1285 * Encode LOOKUP request
1287 static int nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_lookup_arg
*args
)
1289 struct xdr_stream xdr
;
1290 struct compound_hdr hdr
= {
1295 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1296 encode_compound_hdr(&xdr
, &hdr
);
1297 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1299 if ((status
= encode_lookup(&xdr
, args
->name
)) != 0)
1301 if ((status
= encode_getfh(&xdr
)) != 0)
1303 status
= encode_getfattr(&xdr
, args
->bitmask
);
1309 * Encode LOOKUP_ROOT request
1311 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_lookup_root_arg
*args
)
1313 struct xdr_stream xdr
;
1314 struct compound_hdr hdr
= {
1319 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1320 encode_compound_hdr(&xdr
, &hdr
);
1321 if ((status
= encode_putrootfh(&xdr
)) != 0)
1323 if ((status
= encode_getfh(&xdr
)) == 0)
1324 status
= encode_getfattr(&xdr
, args
->bitmask
);
1330 * Encode REMOVE request
1332 static int nfs4_xdr_enc_remove(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_remove_arg
*args
)
1334 struct xdr_stream xdr
;
1335 struct compound_hdr hdr
= {
1340 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1341 encode_compound_hdr(&xdr
, &hdr
);
1342 if ((status
= encode_putfh(&xdr
, args
->fh
)) != 0)
1344 if ((status
= encode_remove(&xdr
, args
->name
)) != 0)
1346 status
= encode_getfattr(&xdr
, args
->bitmask
);
1352 * Encode RENAME request
1354 static int nfs4_xdr_enc_rename(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_rename_arg
*args
)
1356 struct xdr_stream xdr
;
1357 struct compound_hdr hdr
= {
1362 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1363 encode_compound_hdr(&xdr
, &hdr
);
1364 if ((status
= encode_putfh(&xdr
, args
->old_dir
)) != 0)
1366 if ((status
= encode_savefh(&xdr
)) != 0)
1368 if ((status
= encode_putfh(&xdr
, args
->new_dir
)) != 0)
1370 if ((status
= encode_rename(&xdr
, args
->old_name
, args
->new_name
)) != 0)
1372 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1374 if ((status
= encode_restorefh(&xdr
)) != 0)
1376 status
= encode_getfattr(&xdr
, args
->bitmask
);
1382 * Encode LINK request
1384 static int nfs4_xdr_enc_link(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_link_arg
*args
)
1386 struct xdr_stream xdr
;
1387 struct compound_hdr hdr
= {
1392 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1393 encode_compound_hdr(&xdr
, &hdr
);
1394 if ((status
= encode_putfh(&xdr
, args
->fh
)) != 0)
1396 if ((status
= encode_savefh(&xdr
)) != 0)
1398 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1400 if ((status
= encode_link(&xdr
, args
->name
)) != 0)
1402 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1404 if ((status
= encode_restorefh(&xdr
)) != 0)
1406 status
= encode_getfattr(&xdr
, args
->bitmask
);
1412 * Encode CREATE request
1414 static int nfs4_xdr_enc_create(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_create_arg
*args
)
1416 struct xdr_stream xdr
;
1417 struct compound_hdr hdr
= {
1422 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1423 encode_compound_hdr(&xdr
, &hdr
);
1424 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1426 if ((status
= encode_savefh(&xdr
)) != 0)
1428 if ((status
= encode_create(&xdr
, args
)) != 0)
1430 if ((status
= encode_getfh(&xdr
)) != 0)
1432 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1434 if ((status
= encode_restorefh(&xdr
)) != 0)
1436 status
= encode_getfattr(&xdr
, args
->bitmask
);
1442 * Encode SYMLINK request
1444 static int nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_create_arg
*args
)
1446 return nfs4_xdr_enc_create(req
, p
, args
);
1450 * Encode GETATTR request
1452 static int nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_getattr_arg
*args
)
1454 struct xdr_stream xdr
;
1455 struct compound_hdr hdr
= {
1460 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1461 encode_compound_hdr(&xdr
, &hdr
);
1462 if ((status
= encode_putfh(&xdr
, args
->fh
)) == 0)
1463 status
= encode_getfattr(&xdr
, args
->bitmask
);
1468 * Encode a CLOSE request
1470 static int nfs4_xdr_enc_close(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_closeargs
*args
)
1472 struct xdr_stream xdr
;
1473 struct compound_hdr hdr
= {
1478 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1479 encode_compound_hdr(&xdr
, &hdr
);
1480 status
= encode_putfh(&xdr
, args
->fh
);
1483 status
= encode_close(&xdr
, args
);
1486 status
= encode_getfattr(&xdr
, args
->bitmask
);
1492 * Encode an OPEN request
1494 static int nfs4_xdr_enc_open(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_openargs
*args
)
1496 struct xdr_stream xdr
;
1497 struct compound_hdr hdr
= {
1502 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1503 encode_compound_hdr(&xdr
, &hdr
);
1504 status
= encode_putfh(&xdr
, args
->fh
);
1507 status
= encode_savefh(&xdr
);
1510 status
= encode_open(&xdr
, args
);
1513 status
= encode_getfh(&xdr
);
1516 status
= encode_getfattr(&xdr
, args
->bitmask
);
1519 status
= encode_restorefh(&xdr
);
1522 status
= encode_getfattr(&xdr
, args
->bitmask
);
1528 * Encode an OPEN_CONFIRM request
1530 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_open_confirmargs
*args
)
1532 struct xdr_stream xdr
;
1533 struct compound_hdr hdr
= {
1538 status
= nfs_wait_on_sequence(args
->seqid
, req
->rq_task
);
1541 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1542 encode_compound_hdr(&xdr
, &hdr
);
1543 status
= encode_putfh(&xdr
, args
->fh
);
1546 status
= encode_open_confirm(&xdr
, args
);
1552 * Encode an OPEN request with no attributes.
1554 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_openargs
*args
)
1556 struct xdr_stream xdr
;
1557 struct compound_hdr hdr
= {
1562 status
= nfs_wait_on_sequence(args
->seqid
, req
->rq_task
);
1565 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1566 encode_compound_hdr(&xdr
, &hdr
);
1567 status
= encode_putfh(&xdr
, args
->fh
);
1570 status
= encode_open(&xdr
, args
);
1576 * Encode an OPEN_DOWNGRADE request
1578 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_closeargs
*args
)
1580 struct xdr_stream xdr
;
1581 struct compound_hdr hdr
= {
1586 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1587 encode_compound_hdr(&xdr
, &hdr
);
1588 status
= encode_putfh(&xdr
, args
->fh
);
1591 status
= encode_open_downgrade(&xdr
, args
);
1594 status
= encode_getfattr(&xdr
, args
->bitmask
);
1600 * Encode a LOCK request
1602 static int nfs4_xdr_enc_lock(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_lockargs
*args
)
1604 struct xdr_stream xdr
;
1605 struct compound_hdr hdr
= {
1608 struct nfs_lock_opargs
*opargs
= args
->u
.lock
;
1611 status
= nfs_wait_on_sequence(opargs
->lock_seqid
, req
->rq_task
);
1614 /* Do we need to do an open_to_lock_owner? */
1615 if (opargs
->lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)
1616 opargs
->new_lock_owner
= 0;
1617 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1618 encode_compound_hdr(&xdr
, &hdr
);
1619 status
= encode_putfh(&xdr
, args
->fh
);
1622 status
= encode_lock(&xdr
, args
);
1628 * Encode a LOCKT request
1630 static int nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_lockargs
*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_lockt(&xdr
, args
);
1649 * Encode a LOCKU request
1651 static int nfs4_xdr_enc_locku(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_lockargs
*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_locku(&xdr
, args
);
1670 * Encode a READLINK request
1672 static int nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_readlink
*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_readlink(&xdr
, args
, req
);
1691 * Encode a READDIR request
1693 static int nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_readdir_arg
*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_readdir(&xdr
, args
, req
);
1712 * Encode a READ request
1714 static int nfs4_xdr_enc_read(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_readargs
*args
)
1716 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1717 struct xdr_stream xdr
;
1718 struct compound_hdr hdr
= {
1723 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1724 encode_compound_hdr(&xdr
, &hdr
);
1725 status
= encode_putfh(&xdr
, args
->fh
);
1728 status
= encode_read(&xdr
, args
);
1732 /* set up reply kvec
1733 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1734 * + OP_READ + status + eof + datalen = 9
1736 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_read_sz
) << 2;
1737 xdr_inline_pages(&req
->rq_rcv_buf
, replen
,
1738 args
->pages
, args
->pgbase
, args
->count
);
1744 * Encode an SETATTR request
1746 static int nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_setattrargs
*args
)
1749 struct xdr_stream xdr
;
1750 struct compound_hdr hdr
= {
1755 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1756 encode_compound_hdr(&xdr
, &hdr
);
1757 status
= encode_putfh(&xdr
, args
->fh
);
1760 status
= encode_setattr(&xdr
, args
, args
->server
);
1763 status
= encode_getfattr(&xdr
, args
->bitmask
);
1769 * Encode a GETACL request
1772 nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, uint32_t *p
,
1773 struct nfs_getaclargs
*args
)
1775 struct xdr_stream xdr
;
1776 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1777 struct compound_hdr hdr
= {
1782 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1783 encode_compound_hdr(&xdr
, &hdr
);
1784 status
= encode_putfh(&xdr
, args
->fh
);
1787 status
= encode_getattr_two(&xdr
, FATTR4_WORD0_ACL
, 0);
1788 /* set up reply buffer: */
1789 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_getacl_sz
) << 2;
1790 xdr_inline_pages(&req
->rq_rcv_buf
, replen
,
1791 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
1797 * Encode a WRITE request
1799 static int nfs4_xdr_enc_write(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_writeargs
*args
)
1801 struct xdr_stream xdr
;
1802 struct compound_hdr hdr
= {
1807 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1808 encode_compound_hdr(&xdr
, &hdr
);
1809 status
= encode_putfh(&xdr
, args
->fh
);
1812 status
= encode_write(&xdr
, args
);
1815 status
= encode_getfattr(&xdr
, args
->bitmask
);
1823 static int nfs4_xdr_enc_commit(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_writeargs
*args
)
1825 struct xdr_stream xdr
;
1826 struct compound_hdr hdr
= {
1831 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1832 encode_compound_hdr(&xdr
, &hdr
);
1833 status
= encode_putfh(&xdr
, args
->fh
);
1836 status
= encode_commit(&xdr
, args
);
1839 status
= encode_getfattr(&xdr
, args
->bitmask
);
1847 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_fsinfo_arg
*args
)
1849 struct xdr_stream xdr
;
1850 struct compound_hdr hdr
= {
1855 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1856 encode_compound_hdr(&xdr
, &hdr
);
1857 status
= encode_putfh(&xdr
, args
->fh
);
1859 status
= encode_fsinfo(&xdr
, args
->bitmask
);
1864 * a PATHCONF request
1866 static int nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_pathconf_arg
*args
)
1868 struct xdr_stream xdr
;
1869 struct compound_hdr hdr
= {
1874 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1875 encode_compound_hdr(&xdr
, &hdr
);
1876 status
= encode_putfh(&xdr
, args
->fh
);
1878 status
= encode_getattr_one(&xdr
,
1879 args
->bitmask
[0] & nfs4_pathconf_bitmap
[0]);
1886 static int nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_statfs_arg
*args
)
1888 struct xdr_stream xdr
;
1889 struct compound_hdr hdr
= {
1894 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1895 encode_compound_hdr(&xdr
, &hdr
);
1896 status
= encode_putfh(&xdr
, args
->fh
);
1898 status
= encode_getattr_two(&xdr
,
1899 args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
1900 args
->bitmask
[1] & nfs4_statfs_bitmap
[1]);
1905 * GETATTR_BITMAP request
1907 static int nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs_fh
*fhandle
)
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
, fhandle
);
1919 status
= encode_getattr_one(&xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
1920 FATTR4_WORD0_LINK_SUPPORT
|
1921 FATTR4_WORD0_SYMLINK_SUPPORT
|
1922 FATTR4_WORD0_ACLSUPPORT
);
1929 static int nfs4_xdr_enc_renew(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_client
*clp
)
1931 struct xdr_stream xdr
;
1932 struct compound_hdr hdr
= {
1936 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1937 encode_compound_hdr(&xdr
, &hdr
);
1938 return encode_renew(&xdr
, clp
);
1942 * a SETCLIENTID request
1944 static int nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_setclientid
*sc
)
1946 struct xdr_stream xdr
;
1947 struct compound_hdr hdr
= {
1951 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1952 encode_compound_hdr(&xdr
, &hdr
);
1953 return encode_setclientid(&xdr
, sc
);
1957 * a SETCLIENTID_CONFIRM request
1959 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_client
*clp
)
1961 struct xdr_stream xdr
;
1962 struct compound_hdr hdr
= {
1965 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
1968 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1969 encode_compound_hdr(&xdr
, &hdr
);
1970 status
= encode_setclientid_confirm(&xdr
, clp
);
1972 status
= encode_putrootfh(&xdr
);
1974 status
= encode_fsinfo(&xdr
, lease_bitmap
);
1979 * DELEGRETURN request
1981 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_delegreturnargs
*args
)
1983 struct xdr_stream xdr
;
1984 struct compound_hdr hdr
= {
1989 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1990 encode_compound_hdr(&xdr
, &hdr
);
1991 if ((status
= encode_putfh(&xdr
, args
->fhandle
)) == 0)
1992 status
= encode_delegreturn(&xdr
, args
->stateid
);
1997 * START OF "GENERIC" DECODE ROUTINES.
1998 * These may look a little ugly since they are imported from a "generic"
1999 * set of XDR encode/decode routines which are intended to be shared by
2000 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2002 * If the pain of reading these is too great, it should be a straightforward
2003 * task to translate them into Linux-specific versions which are more
2004 * consistent with the style used in NFSv2/v3...
2006 #define READ32(x) (x) = ntohl(*p++)
2007 #define READ64(x) do { \
2008 (x) = (u64)ntohl(*p++) << 32; \
2009 (x) |= ntohl(*p++); \
2011 #define READTIME(x) do { \
2013 (x.tv_sec) = ntohl(*p++); \
2014 (x.tv_nsec) = ntohl(*p++); \
2016 #define COPYMEM(x,nbytes) do { \
2017 memcpy((x), p, nbytes); \
2018 p += XDR_QUADLEN(nbytes); \
2021 #define READ_BUF(nbytes) do { \
2022 p = xdr_inline_decode(xdr, nbytes); \
2024 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
2025 __FUNCTION__, __LINE__); \
2030 static int decode_opaque_inline(struct xdr_stream
*xdr
, uint32_t *len
, char **string
)
2037 *string
= (char *)p
;
2041 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
2046 READ32(hdr
->status
);
2047 READ32(hdr
->taglen
);
2049 READ_BUF(hdr
->taglen
+ 4);
2050 hdr
->tag
= (char *)p
;
2051 p
+= XDR_QUADLEN(hdr
->taglen
);
2056 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
2064 if (opnum
!= expected
) {
2066 "nfs4_decode_op_hdr: Server returned operation"
2067 " %d but we issued a request for %d\n",
2072 if (nfserr
!= NFS_OK
)
2073 return -nfs_stat_to_errno(nfserr
);
2078 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs4_client
*clp
)
2085 return decode_opaque_inline(xdr
, &strlen
, &str
);
2088 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
2095 bitmap
[0] = bitmap
[1] = 0;
2096 READ_BUF((bmlen
<< 2));
2105 static inline int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, uint32_t **savep
)
2115 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
2117 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
2118 decode_attr_bitmap(xdr
, bitmask
);
2119 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
2121 bitmask
[0] = bitmask
[1] = 0;
2122 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__
, bitmask
[0], bitmask
[1]);
2126 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
2131 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
2133 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
2136 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
2137 dprintk("%s: bad type %d\n", __FUNCTION__
, *type
);
2140 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
2142 dprintk("%s: type=0%o\n", __FUNCTION__
, nfs_type2fmt
[*type
].nfs2type
);
2146 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
2151 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
2153 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
2156 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
2158 dprintk("%s: change attribute=%Lu\n", __FUNCTION__
,
2159 (unsigned long long)*change
);
2163 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
2168 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
2170 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
2173 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
2175 dprintk("%s: file size=%Lu\n", __FUNCTION__
, (unsigned long long)*size
);
2179 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2184 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
2186 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
2189 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
2191 dprintk("%s: link support=%s\n", __FUNCTION__
, *res
== 0 ? "false" : "true");
2195 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2200 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
2202 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
2205 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
2207 dprintk("%s: symlink support=%s\n", __FUNCTION__
, *res
== 0 ? "false" : "true");
2211 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fsid
*fsid
)
2217 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
2219 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
2221 READ64(fsid
->major
);
2222 READ64(fsid
->minor
);
2223 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
2225 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__
,
2226 (unsigned long long)fsid
->major
,
2227 (unsigned long long)fsid
->minor
);
2231 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2236 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
2238 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
2241 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
2243 dprintk("%s: file size=%u\n", __FUNCTION__
, (unsigned int)*res
);
2247 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2251 *res
= ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
;
2252 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
2254 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
2257 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
2259 dprintk("%s: ACLs supported=%u\n", __FUNCTION__
, (unsigned int)*res
);
2263 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2268 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
2270 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
2273 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
2275 dprintk("%s: fileid=%Lu\n", __FUNCTION__
, (unsigned long long)*fileid
);
2279 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2285 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
2287 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
2290 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
2292 dprintk("%s: files avail=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2296 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2302 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
2304 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
2307 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
2309 dprintk("%s: files free=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2313 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2319 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
2321 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
2324 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
2326 dprintk("%s: files total=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2330 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2336 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
2338 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
2341 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
2343 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2347 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
2353 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
2355 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
2358 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
2360 dprintk("%s: maxlink=%u\n", __FUNCTION__
, *maxlink
);
2364 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
2370 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
2372 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
2375 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
2377 dprintk("%s: maxname=%u\n", __FUNCTION__
, *maxname
);
2381 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2387 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
2389 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
2393 if (maxread
> 0x7FFFFFFF)
2394 maxread
= 0x7FFFFFFF;
2395 *res
= (uint32_t)maxread
;
2396 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
2398 dprintk("%s: maxread=%lu\n", __FUNCTION__
, (unsigned long)*res
);
2402 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2408 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
2410 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
2414 if (maxwrite
> 0x7FFFFFFF)
2415 maxwrite
= 0x7FFFFFFF;
2416 *res
= (uint32_t)maxwrite
;
2417 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
2419 dprintk("%s: maxwrite=%lu\n", __FUNCTION__
, (unsigned long)*res
);
2423 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *mode
)
2428 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
2430 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
2434 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
2436 dprintk("%s: file mode=0%o\n", __FUNCTION__
, (unsigned int)*mode
);
2440 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
2445 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
2447 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
2450 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
2452 dprintk("%s: nlink=%u\n", __FUNCTION__
, (unsigned int)*nlink
);
2456 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_client
*clp
, int32_t *uid
)
2461 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
2463 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
2467 if (len
< XDR_MAX_NETOBJ
) {
2468 if (nfs_map_name_to_uid(clp
, (char *)p
, len
, uid
) != 0)
2469 dprintk("%s: nfs_map_name_to_uid failed!\n",
2472 printk(KERN_WARNING
"%s: name too long (%u)!\n",
2474 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
2476 dprintk("%s: uid=%d\n", __FUNCTION__
, (int)*uid
);
2480 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_client
*clp
, int32_t *gid
)
2485 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
2487 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
2491 if (len
< XDR_MAX_NETOBJ
) {
2492 if (nfs_map_group_to_gid(clp
, (char *)p
, len
, gid
) != 0)
2493 dprintk("%s: nfs_map_group_to_gid failed!\n",
2496 printk(KERN_WARNING
"%s: name too long (%u)!\n",
2498 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
2500 dprintk("%s: gid=%d\n", __FUNCTION__
, (int)*gid
);
2504 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
2506 uint32_t major
= 0, minor
= 0, *p
;
2509 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
2511 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
2517 tmp
= MKDEV(major
, minor
);
2518 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
2520 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
2522 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__
, major
, minor
);
2526 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2532 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
2534 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
2537 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
2539 dprintk("%s: space avail=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2543 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2549 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
2551 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
2554 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
2556 dprintk("%s: space free=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2560 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2566 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
2568 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
2571 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
2573 dprintk("%s: space total=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2577 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
2582 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
2584 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
2587 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
2589 dprintk("%s: space used=%Lu\n", __FUNCTION__
,
2590 (unsigned long long)*used
);
2594 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
2603 time
->tv_sec
= (time_t)sec
;
2604 time
->tv_nsec
= (long)nsec
;
2608 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2614 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
2616 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
2617 status
= decode_attr_time(xdr
, time
);
2618 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
2620 dprintk("%s: atime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2624 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2630 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
2632 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
2633 status
= decode_attr_time(xdr
, time
);
2634 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
2636 dprintk("%s: ctime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2640 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2646 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
2648 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
2649 status
= decode_attr_time(xdr
, time
);
2650 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
2652 dprintk("%s: mtime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2656 static int verify_attr_len(struct xdr_stream
*xdr
, uint32_t *savep
, uint32_t attrlen
)
2658 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
2659 unsigned int nwords
= xdr
->p
- savep
;
2661 if (unlikely(attrwords
!= nwords
)) {
2662 printk(KERN_WARNING
"%s: server returned incorrect attribute length: %u %c %u\n",
2665 (attrwords
< nwords
) ? '<' : '>',
2672 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
2677 READ32(cinfo
->atomic
);
2678 READ64(cinfo
->before
);
2679 READ64(cinfo
->after
);
2683 static int decode_access(struct xdr_stream
*xdr
, struct nfs4_accessres
*access
)
2689 status
= decode_op_hdr(xdr
, OP_ACCESS
);
2695 access
->supported
= supp
;
2696 access
->access
= acc
;
2700 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
2705 status
= decode_op_hdr(xdr
, OP_CLOSE
);
2708 READ_BUF(sizeof(res
->stateid
.data
));
2709 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
2713 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
2718 status
= decode_op_hdr(xdr
, OP_COMMIT
);
2722 COPYMEM(res
->verf
->verifier
, 8);
2726 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
2732 status
= decode_op_hdr(xdr
, OP_CREATE
);
2735 if ((status
= decode_change_info(xdr
, cinfo
)))
2739 READ_BUF(bmlen
<< 2);
2743 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
2750 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2752 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2754 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2756 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
2758 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
2760 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
2762 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
2764 status
= verify_attr_len(xdr
, savep
, attrlen
);
2766 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
2770 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
2777 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2779 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2781 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2784 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
2786 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
2788 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
2790 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
2792 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
2794 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
2797 status
= verify_attr_len(xdr
, savep
, attrlen
);
2799 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
2803 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
2810 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2812 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2814 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2817 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
2819 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
2822 status
= verify_attr_len(xdr
, savep
, attrlen
);
2824 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
2828 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
, const struct nfs_server
*server
)
2834 int status
, fmode
= 0;
2836 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2838 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2841 fattr
->bitmap
[0] = bitmap
[0];
2842 fattr
->bitmap
[1] = bitmap
[1];
2844 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2848 if ((status
= decode_attr_type(xdr
, bitmap
, &type
)) != 0)
2850 fattr
->type
= nfs_type2fmt
[type
].nfs2type
;
2851 fmode
= nfs_type2fmt
[type
].mode
;
2853 if ((status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
)) != 0)
2855 if ((status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
)) != 0)
2857 if ((status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid_u
.nfs4
)) != 0)
2859 if ((status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
)) != 0)
2861 if ((status
= decode_attr_mode(xdr
, bitmap
, &fattr
->mode
)) != 0)
2863 fattr
->mode
|= fmode
;
2864 if ((status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
)) != 0)
2866 if ((status
= decode_attr_owner(xdr
, bitmap
, server
->nfs4_state
, &fattr
->uid
)) != 0)
2868 if ((status
= decode_attr_group(xdr
, bitmap
, server
->nfs4_state
, &fattr
->gid
)) != 0)
2870 if ((status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
)) != 0)
2872 if ((status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
)) != 0)
2874 if ((status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
)) != 0)
2876 if ((status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
)) != 0)
2878 if ((status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
)) != 0)
2880 if ((status
= verify_attr_len(xdr
, savep
, attrlen
)) == 0)
2881 fattr
->valid
= NFS_ATTR_FATTR
| NFS_ATTR_FATTR_V3
| NFS_ATTR_FATTR_V4
;
2883 dprintk("%s: xdr returned %d\n", __FUNCTION__
, -status
);
2888 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
2891 uint32_t attrlen
, bitmap
[2];
2894 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2896 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2898 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2901 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
2903 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
2905 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
2907 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
2909 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
2910 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
2912 fsinfo
->wtpref
= fsinfo
->wtmax
;
2914 status
= verify_attr_len(xdr
, savep
, attrlen
);
2916 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
2920 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
2926 status
= decode_op_hdr(xdr
, OP_GETFH
);
2929 /* Zero handle first to allow comparisons */
2930 memset(fh
, 0, sizeof(*fh
));
2934 if (len
> NFS4_FHSIZE
)
2938 COPYMEM(fh
->data
, len
);
2942 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
2946 status
= decode_op_hdr(xdr
, OP_LINK
);
2949 return decode_change_info(xdr
, cinfo
);
2953 * We create the owner, so we know a proper owner.id length is 4.
2955 static int decode_lock_denied (struct xdr_stream
*xdr
, struct nfs_lock_denied
*denied
)
2961 READ64(denied
->offset
);
2962 READ64(denied
->length
);
2963 READ32(denied
->type
);
2964 READ64(denied
->owner
.clientid
);
2968 READ32(denied
->owner
.id
);
2969 return -NFS4ERR_DENIED
;
2972 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lockres
*res
)
2977 status
= decode_op_hdr(xdr
, OP_LOCK
);
2979 READ_BUF(sizeof(res
->u
.stateid
.data
));
2980 COPYMEM(res
->u
.stateid
.data
, sizeof(res
->u
.stateid
.data
));
2981 } else if (status
== -NFS4ERR_DENIED
)
2982 return decode_lock_denied(xdr
, &res
->u
.denied
);
2986 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockres
*res
)
2989 status
= decode_op_hdr(xdr
, OP_LOCKT
);
2990 if (status
== -NFS4ERR_DENIED
)
2991 return decode_lock_denied(xdr
, &res
->u
.denied
);
2995 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_lockres
*res
)
3000 status
= decode_op_hdr(xdr
, OP_LOCKU
);
3002 READ_BUF(sizeof(res
->u
.stateid
.data
));
3003 COPYMEM(res
->u
.stateid
.data
, sizeof(res
->u
.stateid
.data
));
3008 static int decode_lookup(struct xdr_stream
*xdr
)
3010 return decode_op_hdr(xdr
, OP_LOOKUP
);
3013 /* This is too sick! */
3014 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
3017 uint32_t limit_type
, nblocks
, blocksize
;
3021 switch (limit_type
) {
3028 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
3033 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3036 uint32_t delegation_type
;
3039 READ32(delegation_type
);
3040 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
3041 res
->delegation_type
= 0;
3045 COPYMEM(res
->delegation
.data
, sizeof(res
->delegation
.data
));
3046 READ32(res
->do_recall
);
3047 switch (delegation_type
) {
3048 case NFS4_OPEN_DELEGATE_READ
:
3049 res
->delegation_type
= FMODE_READ
;
3051 case NFS4_OPEN_DELEGATE_WRITE
:
3052 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
3053 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
3056 return decode_ace(xdr
, NULL
, res
->server
->nfs4_state
);
3059 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3065 status
= decode_op_hdr(xdr
, OP_OPEN
);
3068 READ_BUF(sizeof(res
->stateid
.data
));
3069 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3071 decode_change_info(xdr
, &res
->cinfo
);
3074 READ32(res
->rflags
);
3079 READ_BUF(bmlen
<< 2);
3081 return decode_delegation(xdr
, res
);
3083 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__
, bmlen
);
3087 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
3092 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
3095 READ_BUF(sizeof(res
->stateid
.data
));
3096 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3100 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
3105 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
3108 READ_BUF(sizeof(res
->stateid
.data
));
3109 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3113 static int decode_putfh(struct xdr_stream
*xdr
)
3115 return decode_op_hdr(xdr
, OP_PUTFH
);
3118 static int decode_putrootfh(struct xdr_stream
*xdr
)
3120 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
3123 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs_readres
*res
)
3125 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
3127 uint32_t count
, eof
, recvd
, hdrlen
;
3130 status
= decode_op_hdr(xdr
, OP_READ
);
3136 hdrlen
= (u8
*) p
- (u8
*) iov
->iov_base
;
3137 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3138 if (count
> recvd
) {
3139 printk(KERN_WARNING
"NFS: server cheating in read reply: "
3140 "count %u > recvd %u\n", count
, recvd
);
3144 xdr_read_pages(xdr
, count
);
3150 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
3152 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
3153 struct page
*page
= *rcvbuf
->pages
;
3154 struct kvec
*iov
= rcvbuf
->head
;
3155 unsigned int nr
, pglen
= rcvbuf
->page_len
;
3156 uint32_t *end
, *entry
, *p
, *kaddr
;
3157 uint32_t len
, attrlen
;
3158 int hdrlen
, recvd
, status
;
3160 status
= decode_op_hdr(xdr
, OP_READDIR
);
3164 COPYMEM(readdir
->verifier
.data
, 8);
3165 dprintk("%s: verifier = 0x%x%x\n",
3167 ((u32
*)readdir
->verifier
.data
)[0],
3168 ((u32
*)readdir
->verifier
.data
)[1]);
3171 hdrlen
= (char *) p
- (char *) iov
->iov_base
;
3172 recvd
= rcvbuf
->len
- hdrlen
;
3175 xdr_read_pages(xdr
, pglen
);
3177 BUG_ON(pglen
+ readdir
->pgbase
> PAGE_CACHE_SIZE
);
3178 kaddr
= p
= (uint32_t *) kmap_atomic(page
, KM_USER0
);
3179 end
= (uint32_t *) ((char *)p
+ pglen
+ readdir
->pgbase
);
3181 for (nr
= 0; *p
++; nr
++) {
3184 dprintk("cookie = %Lu, ", *((unsigned long long *)p
));
3185 p
+= 2; /* cookie */
3186 len
= ntohl(*p
++); /* filename length */
3187 if (len
> NFS4_MAXNAMLEN
) {
3188 printk(KERN_WARNING
"NFS: giant filename in readdir (len 0x%x)\n", len
);
3191 dprintk("filename = %*s\n", len
, (char *)p
);
3192 p
+= XDR_QUADLEN(len
);
3195 len
= ntohl(*p
++); /* bitmap length */
3199 attrlen
= XDR_QUADLEN(ntohl(*p
++));
3200 p
+= attrlen
; /* attributes */
3205 if (!nr
&& (entry
[0] != 0 || entry
[1] == 0))
3208 kunmap_atomic(kaddr
, KM_USER0
);
3211 dprintk("%s: short packet at entry %d\n", __FUNCTION__
, nr
);
3212 entry
[0] = entry
[1] = 0;
3213 /* truncate listing ? */
3215 printk(KERN_NOTICE
"NFS: readdir reply truncated!\n");
3220 kunmap_atomic(kaddr
, KM_USER0
);
3221 return -errno_NFSERR_IO
;
3224 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
3226 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
3227 struct kvec
*iov
= rcvbuf
->head
;
3228 int hdrlen
, len
, recvd
;
3233 status
= decode_op_hdr(xdr
, OP_READLINK
);
3237 /* Convert length of symlink */
3240 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
3241 dprintk(KERN_WARNING
"nfs: server returned giant symlink!\n");
3242 return -ENAMETOOLONG
;
3244 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
3245 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3247 printk(KERN_WARNING
"NFS: server cheating in readlink reply: "
3248 "count %u > recvd %u\n", len
, recvd
);
3251 xdr_read_pages(xdr
, len
);
3253 * The XDR encode routine has set things up so that
3254 * the link text will be copied directly into the
3255 * buffer. We just have to do overflow-checking,
3256 * and and null-terminate the text (the VFS expects
3257 * null-termination).
3259 kaddr
= (char *)kmap_atomic(rcvbuf
->pages
[0], KM_USER0
);
3260 kaddr
[len
+rcvbuf
->page_base
] = '\0';
3261 kunmap_atomic(kaddr
, KM_USER0
);
3265 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3269 status
= decode_op_hdr(xdr
, OP_REMOVE
);
3272 status
= decode_change_info(xdr
, cinfo
);
3277 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
3278 struct nfs4_change_info
*new_cinfo
)
3282 status
= decode_op_hdr(xdr
, OP_RENAME
);
3285 if ((status
= decode_change_info(xdr
, old_cinfo
)))
3287 status
= decode_change_info(xdr
, new_cinfo
);
3292 static int decode_renew(struct xdr_stream
*xdr
)
3294 return decode_op_hdr(xdr
, OP_RENEW
);
3298 decode_restorefh(struct xdr_stream
*xdr
)
3300 return decode_op_hdr(xdr
, OP_RESTOREFH
);
3303 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
3309 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
3313 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3315 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3317 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3320 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
3322 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
3325 /* We ignore &savep and don't do consistency checks on
3326 * the attr length. Let userspace figure it out.... */
3327 hdrlen
= (u8
*)xdr
->p
- (u8
*)iov
->iov_base
;
3328 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3329 if (attrlen
> recvd
) {
3330 printk(KERN_WARNING
"NFS: server cheating in getattr"
3331 " acl reply: attrlen %u > recvd %u\n",
3335 if (attrlen
<= *acl_len
)
3336 xdr_read_pages(xdr
, attrlen
);
3339 status
= -EOPNOTSUPP
;
3346 decode_savefh(struct xdr_stream
*xdr
)
3348 return decode_op_hdr(xdr
, OP_SAVEFH
);
3351 static int decode_setattr(struct xdr_stream
*xdr
, struct nfs_setattrres
*res
)
3358 status
= decode_op_hdr(xdr
, OP_SETATTR
);
3363 READ_BUF(bmlen
<< 2);
3367 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs4_client
*clp
)
3375 if (opnum
!= OP_SETCLIENTID
) {
3377 "nfs4_decode_setclientid: Server returned operation"
3382 if (nfserr
== NFS_OK
) {
3383 READ_BUF(8 + sizeof(clp
->cl_confirm
.data
));
3384 READ64(clp
->cl_clientid
);
3385 COPYMEM(clp
->cl_confirm
.data
, sizeof(clp
->cl_confirm
.data
));
3386 } else if (nfserr
== NFSERR_CLID_INUSE
) {
3389 /* skip netid string */
3394 /* skip uaddr string */
3398 return -NFSERR_CLID_INUSE
;
3400 return -nfs_stat_to_errno(nfserr
);
3405 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
3407 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
3410 static int decode_write(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
3415 status
= decode_op_hdr(xdr
, OP_WRITE
);
3421 READ32(res
->verf
->committed
);
3422 COPYMEM(res
->verf
->verifier
, 8);
3426 static int decode_delegreturn(struct xdr_stream
*xdr
)
3428 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
3432 * Decode OPEN_DOWNGRADE response
3434 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_closeres
*res
)
3436 struct xdr_stream xdr
;
3437 struct compound_hdr hdr
;
3440 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3441 status
= decode_compound_hdr(&xdr
, &hdr
);
3444 status
= decode_putfh(&xdr
);
3447 status
= decode_open_downgrade(&xdr
, res
);
3450 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3456 * END OF "GENERIC" DECODE ROUTINES.
3460 * Decode ACCESS response
3462 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_accessres
*res
)
3464 struct xdr_stream xdr
;
3465 struct compound_hdr hdr
;
3468 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3469 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3471 if ((status
= decode_putfh(&xdr
)) == 0)
3472 status
= decode_access(&xdr
, res
);
3478 * Decode LOOKUP response
3480 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_lookup_res
*res
)
3482 struct xdr_stream xdr
;
3483 struct compound_hdr hdr
;
3486 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3487 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3489 if ((status
= decode_putfh(&xdr
)) != 0)
3491 if ((status
= decode_lookup(&xdr
)) != 0)
3493 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
3495 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3501 * Decode LOOKUP_ROOT response
3503 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_lookup_res
*res
)
3505 struct xdr_stream xdr
;
3506 struct compound_hdr hdr
;
3509 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3510 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3512 if ((status
= decode_putrootfh(&xdr
)) != 0)
3514 if ((status
= decode_getfh(&xdr
, res
->fh
)) == 0)
3515 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3521 * Decode REMOVE response
3523 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_remove_res
*res
)
3525 struct xdr_stream xdr
;
3526 struct compound_hdr hdr
;
3529 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3530 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3532 if ((status
= decode_putfh(&xdr
)) != 0)
3534 if ((status
= decode_remove(&xdr
, &res
->cinfo
)) != 0)
3536 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
);
3542 * Decode RENAME response
3544 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_rename_res
*res
)
3546 struct xdr_stream xdr
;
3547 struct compound_hdr hdr
;
3550 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3551 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3553 if ((status
= decode_putfh(&xdr
)) != 0)
3555 if ((status
= decode_savefh(&xdr
)) != 0)
3557 if ((status
= decode_putfh(&xdr
)) != 0)
3559 if ((status
= decode_rename(&xdr
, &res
->old_cinfo
, &res
->new_cinfo
)) != 0)
3561 /* Current FH is target directory */
3562 if (decode_getfattr(&xdr
, res
->new_fattr
, res
->server
) != 0)
3564 if ((status
= decode_restorefh(&xdr
)) != 0)
3566 decode_getfattr(&xdr
, res
->old_fattr
, res
->server
);
3572 * Decode LINK response
3574 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_link_res
*res
)
3576 struct xdr_stream xdr
;
3577 struct compound_hdr hdr
;
3580 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3581 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3583 if ((status
= decode_putfh(&xdr
)) != 0)
3585 if ((status
= decode_savefh(&xdr
)) != 0)
3587 if ((status
= decode_putfh(&xdr
)) != 0)
3589 if ((status
= decode_link(&xdr
, &res
->cinfo
)) != 0)
3592 * Note order: OP_LINK leaves the directory as the current
3595 if (decode_getfattr(&xdr
, res
->dir_attr
, res
->server
) != 0)
3597 if ((status
= decode_restorefh(&xdr
)) != 0)
3599 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3605 * Decode CREATE response
3607 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_create_res
*res
)
3609 struct xdr_stream xdr
;
3610 struct compound_hdr hdr
;
3613 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3614 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3616 if ((status
= decode_putfh(&xdr
)) != 0)
3618 if ((status
= decode_savefh(&xdr
)) != 0)
3620 if ((status
= decode_create(&xdr
,&res
->dir_cinfo
)) != 0)
3622 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
3624 if (decode_getfattr(&xdr
, res
->fattr
, res
->server
) != 0)
3626 if ((status
= decode_restorefh(&xdr
)) != 0)
3628 decode_getfattr(&xdr
, res
->dir_fattr
, res
->server
);
3634 * Decode SYMLINK response
3636 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_create_res
*res
)
3638 return nfs4_xdr_dec_create(rqstp
, p
, res
);
3642 * Decode GETATTR response
3644 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_getattr_res
*res
)
3646 struct xdr_stream xdr
;
3647 struct compound_hdr hdr
;
3650 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3651 status
= decode_compound_hdr(&xdr
, &hdr
);
3654 status
= decode_putfh(&xdr
);
3657 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3664 * Encode an SETACL request
3667 nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_setaclargs
*args
)
3669 struct xdr_stream xdr
;
3670 struct compound_hdr hdr
= {
3675 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
3676 encode_compound_hdr(&xdr
, &hdr
);
3677 status
= encode_putfh(&xdr
, args
->fh
);
3680 status
= encode_setacl(&xdr
, args
);
3685 * Decode SETACL response
3688 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, uint32_t *p
, void *res
)
3690 struct xdr_stream xdr
;
3691 struct compound_hdr hdr
;
3694 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3695 status
= decode_compound_hdr(&xdr
, &hdr
);
3698 status
= decode_putfh(&xdr
);
3701 status
= decode_setattr(&xdr
, res
);
3707 * Decode GETACL response
3710 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, uint32_t *p
, size_t *acl_len
)
3712 struct xdr_stream xdr
;
3713 struct compound_hdr hdr
;
3716 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3717 status
= decode_compound_hdr(&xdr
, &hdr
);
3720 status
= decode_putfh(&xdr
);
3723 status
= decode_getacl(&xdr
, rqstp
, acl_len
);
3730 * Decode CLOSE response
3732 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_closeres
*res
)
3734 struct xdr_stream xdr
;
3735 struct compound_hdr hdr
;
3738 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3739 status
= decode_compound_hdr(&xdr
, &hdr
);
3742 status
= decode_putfh(&xdr
);
3745 status
= decode_close(&xdr
, res
);
3749 * Note: Server may do delete on close for this file
3750 * in which case the getattr call will fail with
3751 * an ESTALE error. Shouldn't be a problem,
3752 * though, since fattr->valid will remain unset.
3754 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3760 * Decode OPEN response
3762 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_openres
*res
)
3764 struct xdr_stream xdr
;
3765 struct compound_hdr hdr
;
3768 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3769 status
= decode_compound_hdr(&xdr
, &hdr
);
3772 status
= decode_putfh(&xdr
);
3775 status
= decode_savefh(&xdr
);
3778 status
= decode_open(&xdr
, res
);
3781 status
= decode_getfh(&xdr
, &res
->fh
);
3784 if (decode_getfattr(&xdr
, res
->f_attr
, res
->server
) != 0)
3786 if ((status
= decode_restorefh(&xdr
)) != 0)
3788 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
);
3794 * Decode OPEN_CONFIRM response
3796 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_open_confirmres
*res
)
3798 struct xdr_stream xdr
;
3799 struct compound_hdr hdr
;
3802 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3803 status
= decode_compound_hdr(&xdr
, &hdr
);
3806 status
= decode_putfh(&xdr
);
3809 status
= decode_open_confirm(&xdr
, res
);
3815 * Decode OPEN response
3817 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_openres
*res
)
3819 struct xdr_stream xdr
;
3820 struct compound_hdr hdr
;
3823 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3824 status
= decode_compound_hdr(&xdr
, &hdr
);
3827 status
= decode_putfh(&xdr
);
3830 status
= decode_open(&xdr
, res
);
3836 * Decode SETATTR response
3838 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_setattrres
*res
)
3840 struct xdr_stream xdr
;
3841 struct compound_hdr hdr
;
3844 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3845 status
= decode_compound_hdr(&xdr
, &hdr
);
3848 status
= decode_putfh(&xdr
);
3851 status
= decode_setattr(&xdr
, res
);
3854 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3855 if (status
== NFS4ERR_DELAY
)
3862 * Decode LOCK response
3864 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_lockres
*res
)
3866 struct xdr_stream xdr
;
3867 struct compound_hdr hdr
;
3870 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3871 status
= decode_compound_hdr(&xdr
, &hdr
);
3874 status
= decode_putfh(&xdr
);
3877 status
= decode_lock(&xdr
, res
);
3883 * Decode LOCKT response
3885 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_lockres
*res
)
3887 struct xdr_stream xdr
;
3888 struct compound_hdr hdr
;
3891 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3892 status
= decode_compound_hdr(&xdr
, &hdr
);
3895 status
= decode_putfh(&xdr
);
3898 status
= decode_lockt(&xdr
, res
);
3904 * Decode LOCKU response
3906 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_lockres
*res
)
3908 struct xdr_stream xdr
;
3909 struct compound_hdr hdr
;
3912 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3913 status
= decode_compound_hdr(&xdr
, &hdr
);
3916 status
= decode_putfh(&xdr
);
3919 status
= decode_locku(&xdr
, res
);
3925 * Decode READLINK response
3927 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
, uint32_t *p
, void *res
)
3929 struct xdr_stream xdr
;
3930 struct compound_hdr hdr
;
3933 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3934 status
= decode_compound_hdr(&xdr
, &hdr
);
3937 status
= decode_putfh(&xdr
);
3940 status
= decode_readlink(&xdr
, rqstp
);
3946 * Decode READDIR response
3948 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_readdir_res
*res
)
3950 struct xdr_stream xdr
;
3951 struct compound_hdr hdr
;
3954 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3955 status
= decode_compound_hdr(&xdr
, &hdr
);
3958 status
= decode_putfh(&xdr
);
3961 status
= decode_readdir(&xdr
, rqstp
, res
);
3967 * Decode Read response
3969 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_readres
*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_read(&xdr
, rqstp
, res
);
3984 status
= res
->count
;
3990 * Decode WRITE response
3992 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_writeres
*res
)
3994 struct xdr_stream xdr
;
3995 struct compound_hdr hdr
;
3998 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3999 status
= decode_compound_hdr(&xdr
, &hdr
);
4002 status
= decode_putfh(&xdr
);
4005 status
= decode_write(&xdr
, res
);
4008 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4010 status
= res
->count
;
4016 * Decode COMMIT response
4018 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_writeres
*res
)
4020 struct xdr_stream xdr
;
4021 struct compound_hdr hdr
;
4024 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4025 status
= decode_compound_hdr(&xdr
, &hdr
);
4028 status
= decode_putfh(&xdr
);
4031 status
= decode_commit(&xdr
, res
);
4034 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4042 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_fsinfo
*fsinfo
)
4044 struct xdr_stream xdr
;
4045 struct compound_hdr hdr
;
4048 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4049 status
= decode_compound_hdr(&xdr
, &hdr
);
4051 status
= decode_putfh(&xdr
);
4053 status
= decode_fsinfo(&xdr
, fsinfo
);
4055 status
= -nfs_stat_to_errno(hdr
.status
);
4062 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_pathconf
*pathconf
)
4064 struct xdr_stream xdr
;
4065 struct compound_hdr hdr
;
4068 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4069 status
= decode_compound_hdr(&xdr
, &hdr
);
4071 status
= decode_putfh(&xdr
);
4073 status
= decode_pathconf(&xdr
, pathconf
);
4080 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_fsstat
*fsstat
)
4082 struct xdr_stream xdr
;
4083 struct compound_hdr hdr
;
4086 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4087 status
= decode_compound_hdr(&xdr
, &hdr
);
4089 status
= decode_putfh(&xdr
);
4091 status
= decode_statfs(&xdr
, fsstat
);
4096 * GETATTR_BITMAP request
4098 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_server_caps_res
*res
)
4100 struct xdr_stream xdr
;
4101 struct compound_hdr hdr
;
4104 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4105 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
4107 if ((status
= decode_putfh(&xdr
)) != 0)
4109 status
= decode_server_caps(&xdr
, res
);
4115 * Decode RENEW response
4117 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, uint32_t *p
, void *dummy
)
4119 struct xdr_stream xdr
;
4120 struct compound_hdr hdr
;
4123 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4124 status
= decode_compound_hdr(&xdr
, &hdr
);
4126 status
= decode_renew(&xdr
);
4131 * a SETCLIENTID request
4133 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
, uint32_t *p
,
4134 struct nfs4_client
*clp
)
4136 struct xdr_stream xdr
;
4137 struct compound_hdr hdr
;
4140 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4141 status
= decode_compound_hdr(&xdr
, &hdr
);
4143 status
= decode_setclientid(&xdr
, clp
);
4145 status
= -nfs_stat_to_errno(hdr
.status
);
4150 * a SETCLIENTID_CONFIRM request
4152 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_fsinfo
*fsinfo
)
4154 struct xdr_stream xdr
;
4155 struct compound_hdr hdr
;
4158 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4159 status
= decode_compound_hdr(&xdr
, &hdr
);
4161 status
= decode_setclientid_confirm(&xdr
);
4163 status
= decode_putrootfh(&xdr
);
4165 status
= decode_fsinfo(&xdr
, fsinfo
);
4167 status
= -nfs_stat_to_errno(hdr
.status
);
4172 * DELEGRETURN request
4174 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
, uint32_t *p
, void *dummy
)
4176 struct xdr_stream xdr
;
4177 struct compound_hdr hdr
;
4180 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4181 status
= decode_compound_hdr(&xdr
, &hdr
);
4183 status
= decode_putfh(&xdr
);
4185 status
= decode_delegreturn(&xdr
);
4190 uint32_t *nfs4_decode_dirent(uint32_t *p
, struct nfs_entry
*entry
, int plus
)
4192 uint32_t bitmap
[2] = {0};
4197 return ERR_PTR(-EAGAIN
);
4199 return ERR_PTR(-EBADCOOKIE
);
4202 entry
->prev_cookie
= entry
->cookie
;
4203 p
= xdr_decode_hyper(p
, &entry
->cookie
);
4204 entry
->len
= ntohl(*p
++);
4205 entry
->name
= (const char *) p
;
4206 p
+= XDR_QUADLEN(entry
->len
);
4209 * In case the server doesn't return an inode number,
4210 * we fake one here. (We don't use inode number 0,
4211 * since glibc seems to choke on it...)
4215 len
= ntohl(*p
++); /* bitmap length */
4217 bitmap
[0] = ntohl(*p
++);
4219 bitmap
[1] = ntohl(*p
++);
4223 len
= XDR_QUADLEN(ntohl(*p
++)); /* attribute buffer length */
4225 if (bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
) {
4226 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
4227 /* Ignore the return value of rdattr_error for now */
4231 if (bitmap
[0] == 0 && bitmap
[1] == FATTR4_WORD1_MOUNTED_ON_FILEID
)
4232 xdr_decode_hyper(p
, &entry
->ino
);
4233 else if (bitmap
[0] == FATTR4_WORD0_FILEID
)
4234 xdr_decode_hyper(p
, &entry
->ino
);
4238 entry
->eof
= !p
[0] && p
[1];
4243 * We need to translate between nfs status return values and
4244 * the local errno values which may not be the same.
4251 { NFS4ERR_PERM
, EPERM
},
4252 { NFS4ERR_NOENT
, ENOENT
},
4253 { NFS4ERR_IO
, errno_NFSERR_IO
},
4254 { NFS4ERR_NXIO
, ENXIO
},
4255 { NFS4ERR_ACCESS
, EACCES
},
4256 { NFS4ERR_EXIST
, EEXIST
},
4257 { NFS4ERR_XDEV
, EXDEV
},
4258 { NFS4ERR_NOTDIR
, ENOTDIR
},
4259 { NFS4ERR_ISDIR
, EISDIR
},
4260 { NFS4ERR_INVAL
, EINVAL
},
4261 { NFS4ERR_FBIG
, EFBIG
},
4262 { NFS4ERR_NOSPC
, ENOSPC
},
4263 { NFS4ERR_ROFS
, EROFS
},
4264 { NFS4ERR_MLINK
, EMLINK
},
4265 { NFS4ERR_NAMETOOLONG
, ENAMETOOLONG
},
4266 { NFS4ERR_NOTEMPTY
, ENOTEMPTY
},
4267 { NFS4ERR_DQUOT
, EDQUOT
},
4268 { NFS4ERR_STALE
, ESTALE
},
4269 { NFS4ERR_BADHANDLE
, EBADHANDLE
},
4270 { NFS4ERR_BADOWNER
, EINVAL
},
4271 { NFS4ERR_BADNAME
, EINVAL
},
4272 { NFS4ERR_BAD_COOKIE
, EBADCOOKIE
},
4273 { NFS4ERR_NOTSUPP
, ENOTSUPP
},
4274 { NFS4ERR_TOOSMALL
, ETOOSMALL
},
4275 { NFS4ERR_SERVERFAULT
, ESERVERFAULT
},
4276 { NFS4ERR_BADTYPE
, EBADTYPE
},
4277 { NFS4ERR_LOCKED
, EAGAIN
},
4278 { NFS4ERR_RESOURCE
, EREMOTEIO
},
4279 { NFS4ERR_SYMLINK
, ELOOP
},
4280 { NFS4ERR_OP_ILLEGAL
, EOPNOTSUPP
},
4281 { NFS4ERR_DEADLOCK
, EDEADLK
},
4282 { NFS4ERR_WRONGSEC
, EPERM
}, /* FIXME: this needs
4283 * to be handled by a
4290 * Convert an NFS error code to a local one.
4291 * This one is used jointly by NFSv2 and NFSv3.
4294 nfs_stat_to_errno(int stat
)
4297 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
4298 if (nfs_errtbl
[i
].stat
== stat
)
4299 return nfs_errtbl
[i
].errno
;
4301 if (stat
<= 10000 || stat
> 10100) {
4302 /* The server is looney tunes. */
4303 return ESERVERFAULT
;
4305 /* If we cannot translate the error, the recovery routines should
4307 * Note: remaining NFSv4 error codes have values > 10000, so should
4308 * not conflict with native Linux error codes.
4314 # define MAX(a, b) (((a) > (b))? (a) : (b))
4317 #define PROC(proc, argtype, restype) \
4318 [NFSPROC4_CLNT_##proc] = { \
4319 .p_proc = NFSPROC4_COMPOUND, \
4320 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4321 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4322 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
4325 struct rpc_procinfo nfs4_procedures
[] = {
4326 PROC(READ
, enc_read
, dec_read
),
4327 PROC(WRITE
, enc_write
, dec_write
),
4328 PROC(COMMIT
, enc_commit
, dec_commit
),
4329 PROC(OPEN
, enc_open
, dec_open
),
4330 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
4331 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
4332 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
4333 PROC(CLOSE
, enc_close
, dec_close
),
4334 PROC(SETATTR
, enc_setattr
, dec_setattr
),
4335 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
4336 PROC(RENEW
, enc_renew
, dec_renew
),
4337 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
4338 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
4339 PROC(LOCK
, enc_lock
, dec_lock
),
4340 PROC(LOCKT
, enc_lockt
, dec_lockt
),
4341 PROC(LOCKU
, enc_locku
, dec_locku
),
4342 PROC(ACCESS
, enc_access
, dec_access
),
4343 PROC(GETATTR
, enc_getattr
, dec_getattr
),
4344 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
4345 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
4346 PROC(REMOVE
, enc_remove
, dec_remove
),
4347 PROC(RENAME
, enc_rename
, dec_rename
),
4348 PROC(LINK
, enc_link
, dec_link
),
4349 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
4350 PROC(CREATE
, enc_create
, dec_create
),
4351 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
4352 PROC(STATFS
, enc_statfs
, dec_statfs
),
4353 PROC(READLINK
, enc_readlink
, dec_readlink
),
4354 PROC(READDIR
, enc_readdir
, dec_readdir
),
4355 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
4356 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
4357 PROC(GETACL
, enc_getacl
, dec_getacl
),
4358 PROC(SETACL
, enc_setacl
, dec_setacl
),
4361 struct rpc_version nfs_version4
= {
4363 .nrprocs
= sizeof(nfs4_procedures
)/sizeof(nfs4_procedures
[0]),
4364 .procs
= nfs4_procedures