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_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
99 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
100 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
101 #define decode_renew_maxsz (op_decode_hdr_maxsz)
102 #define encode_setclientid_maxsz \
103 (op_encode_hdr_maxsz + \
104 4 /*server->ip_addr*/ + \
107 6 + (NFS4_VERIFIER_SIZE >> 2))
108 #define decode_setclientid_maxsz \
109 (op_decode_hdr_maxsz + \
111 1024) /* large value for CLID_INUSE */
112 #define encode_setclientid_confirm_maxsz \
113 (op_encode_hdr_maxsz + \
114 3 + (NFS4_VERIFIER_SIZE >> 2))
115 #define decode_setclientid_confirm_maxsz \
116 (op_decode_hdr_maxsz)
117 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
118 1 + ((3 + NFS4_FHSIZE) >> 2))
119 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
121 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
123 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
124 #define encode_link_maxsz (op_encode_hdr_maxsz + \
126 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
127 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
128 1 + nfs4_name_maxsz + \
131 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
132 #define encode_create_maxsz (op_encode_hdr_maxsz + \
133 2 + nfs4_name_maxsz + \
135 #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
136 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
137 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
138 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
139 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
140 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
141 encode_putfh_maxsz + \
142 op_encode_hdr_maxsz + 7)
143 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
144 decode_putfh_maxsz + \
145 op_decode_hdr_maxsz + 2)
146 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
147 encode_putfh_maxsz + \
149 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
150 decode_putfh_maxsz + \
152 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
153 encode_putfh_maxsz + \
154 op_encode_hdr_maxsz + 9)
155 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
156 decode_putfh_maxsz + \
157 op_decode_hdr_maxsz + 2)
158 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
159 encode_putfh_maxsz + \
160 op_encode_hdr_maxsz + 8)
161 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
162 decode_putfh_maxsz + \
163 op_decode_hdr_maxsz + 4)
164 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
165 encode_putfh_maxsz + \
166 op_encode_hdr_maxsz + 3)
167 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
168 decode_putfh_maxsz + \
169 op_decode_hdr_maxsz + 2)
170 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
171 encode_putfh_maxsz + \
172 op_encode_hdr_maxsz + \
174 encode_getattr_maxsz + \
176 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
177 decode_putfh_maxsz + \
178 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
179 decode_getattr_maxsz + \
181 #define NFS4_enc_open_confirm_sz \
182 (compound_encode_hdr_maxsz + \
183 encode_putfh_maxsz + \
184 op_encode_hdr_maxsz + 5)
185 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
186 decode_putfh_maxsz + \
187 op_decode_hdr_maxsz + 4)
188 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
189 encode_putfh_maxsz + \
190 op_encode_hdr_maxsz + \
192 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
193 decode_putfh_maxsz + \
194 op_decode_hdr_maxsz + \
196 #define NFS4_enc_open_downgrade_sz \
197 (compound_encode_hdr_maxsz + \
198 encode_putfh_maxsz + \
199 op_encode_hdr_maxsz + 7)
200 #define NFS4_dec_open_downgrade_sz \
201 (compound_decode_hdr_maxsz + \
202 decode_putfh_maxsz + \
203 op_decode_hdr_maxsz + 4)
204 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
205 encode_putfh_maxsz + \
206 op_encode_hdr_maxsz + 5)
207 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
208 decode_putfh_maxsz + \
209 op_decode_hdr_maxsz + 4)
210 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
211 encode_putfh_maxsz + \
212 op_encode_hdr_maxsz + 4 + \
214 encode_getattr_maxsz)
215 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
216 decode_putfh_maxsz + \
217 op_decode_hdr_maxsz + 3)
218 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
219 encode_putfh_maxsz + \
221 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
222 decode_putfh_maxsz + \
224 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
226 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
228 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
229 encode_setclientid_maxsz)
230 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
231 decode_setclientid_maxsz)
232 #define NFS4_enc_setclientid_confirm_sz \
233 (compound_encode_hdr_maxsz + \
234 encode_setclientid_confirm_maxsz + \
235 encode_putrootfh_maxsz + \
237 #define NFS4_dec_setclientid_confirm_sz \
238 (compound_decode_hdr_maxsz + \
239 decode_setclientid_confirm_maxsz + \
240 decode_putrootfh_maxsz + \
242 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
243 encode_putfh_maxsz + \
244 encode_getattr_maxsz + \
245 op_encode_hdr_maxsz + \
249 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
250 decode_putfh_maxsz + \
251 decode_getattr_maxsz + \
252 op_decode_hdr_maxsz + \
255 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
256 encode_putfh_maxsz + \
257 encode_getattr_maxsz + \
258 op_encode_hdr_maxsz + \
261 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
262 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
263 encode_putfh_maxsz + \
264 encode_getattr_maxsz + \
265 op_encode_hdr_maxsz + \
267 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
268 decode_putfh_maxsz + \
269 decode_getattr_maxsz + \
270 op_decode_hdr_maxsz + 4)
271 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
272 encode_putfh_maxsz + \
273 op_encode_hdr_maxsz + 1)
274 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
275 decode_putfh_maxsz + \
276 op_decode_hdr_maxsz + 2)
277 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
278 encode_putfh_maxsz + \
279 encode_getattr_maxsz)
280 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
281 decode_putfh_maxsz + \
282 decode_getattr_maxsz)
283 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
284 encode_putfh_maxsz + \
285 encode_lookup_maxsz + \
286 encode_getattr_maxsz + \
288 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
289 decode_putfh_maxsz + \
290 op_decode_hdr_maxsz + \
291 decode_getattr_maxsz + \
293 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
294 encode_putrootfh_maxsz + \
295 encode_getattr_maxsz + \
297 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
298 decode_putrootfh_maxsz + \
299 decode_getattr_maxsz + \
301 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
302 encode_putfh_maxsz + \
304 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
305 decode_putfh_maxsz + \
306 op_decode_hdr_maxsz + 5)
307 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
308 encode_putfh_maxsz + \
309 encode_savefh_maxsz + \
310 encode_putfh_maxsz + \
312 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
313 decode_putfh_maxsz + \
314 decode_savefh_maxsz + \
315 decode_putfh_maxsz + \
317 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
318 encode_putfh_maxsz + \
319 encode_savefh_maxsz + \
320 encode_putfh_maxsz + \
322 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
323 decode_putfh_maxsz + \
324 decode_savefh_maxsz + \
325 decode_putfh_maxsz + \
327 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
328 encode_putfh_maxsz + \
329 encode_symlink_maxsz + \
330 encode_getattr_maxsz + \
332 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
333 decode_putfh_maxsz + \
334 decode_symlink_maxsz + \
335 decode_getattr_maxsz + \
337 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
338 encode_putfh_maxsz + \
339 encode_create_maxsz + \
340 encode_getattr_maxsz + \
342 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
343 decode_putfh_maxsz + \
344 decode_create_maxsz + \
345 decode_getattr_maxsz + \
347 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
348 encode_putfh_maxsz + \
349 encode_getattr_maxsz)
350 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
351 decode_putfh_maxsz + \
352 decode_getattr_maxsz)
353 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
354 encode_putfh_maxsz + \
355 encode_getattr_maxsz)
356 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
357 decode_putfh_maxsz + \
358 op_decode_hdr_maxsz + 12)
359 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
360 encode_getattr_maxsz)
361 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
362 decode_getattr_maxsz)
363 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
364 encode_putfh_maxsz + \
365 encode_delegreturn_maxsz)
366 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
367 decode_delegreturn_maxsz)
368 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
369 encode_putfh_maxsz + \
370 encode_getattr_maxsz)
371 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
372 decode_putfh_maxsz + \
373 op_decode_hdr_maxsz + \
374 nfs4_fattr_bitmap_maxsz + 1)
375 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
376 encode_putfh_maxsz + \
377 op_encode_hdr_maxsz + 4 + \
378 nfs4_fattr_bitmap_maxsz + 1)
379 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
380 decode_putfh_maxsz + \
381 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
385 unsigned int nfs2type;
393 { S_IFSOCK, NFSOCK },
399 struct compound_hdr {
407 * START OF "GENERIC" ENCODE ROUTINES.
408 * These may look a little ugly since they are imported from a "generic"
409 * set of XDR encode/decode routines which are intended to be shared by
410 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
412 * If the pain of reading these is too great, it should be a straightforward
413 * task to translate them into Linux-specific versions which are more
414 * consistent with the style used in NFSv2/v3...
416 #define WRITE32(n) *p++ = htonl(n)
417 #define WRITE64(n) do { \
418 *p++ = htonl((uint32_t)((n) >> 32)); \
419 *p++ = htonl((uint32_t)(n)); \
421 #define WRITEMEM(ptr,nbytes) do { \
422 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
425 #define RESERVE_SPACE(nbytes) do { \
426 p = xdr_reserve_space(xdr, nbytes); \
427 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
431 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
435 p = xdr_reserve_space(xdr, 4 + len);
437 xdr_encode_opaque(p, str, len);
440 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
444 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
445 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
446 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
447 WRITE32(hdr->taglen);
448 WRITEMEM(hdr->tag, hdr->taglen);
449 WRITE32(NFS4_MINOR_VERSION);
454 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
458 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
460 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
463 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
465 char owner_name[IDMAP_NAMESZ];
466 char owner_group[IDMAP_NAMESZ];
467 int owner_namelen = 0;
468 int owner_grouplen = 0;
477 * We reserve enough space to write the entire attribute buffer at once.
478 * In the worst-case, this would be
479 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
480 * = 36 bytes, plus any contribution from variable-length fields
481 * such as owner/group.
486 if (iap->ia_valid & ATTR_SIZE)
488 if (iap->ia_valid & ATTR_MODE)
490 if (iap->ia_valid & ATTR_UID) {
491 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
492 if (owner_namelen < 0) {
493 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
496 strcpy(owner_name, "nobody");
497 owner_namelen = sizeof("nobody") - 1;
500 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
502 if (iap->ia_valid & ATTR_GID) {
503 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
504 if (owner_grouplen < 0) {
505 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
507 strcpy(owner_group, "nobody");
508 owner_grouplen = sizeof("nobody") - 1;
511 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
513 if (iap->ia_valid & ATTR_ATIME_SET)
515 else if (iap->ia_valid & ATTR_ATIME)
517 if (iap->ia_valid & ATTR_MTIME_SET)
519 else if (iap->ia_valid & ATTR_MTIME)
524 * We write the bitmap length now, but leave the bitmap and the attribute
525 * buffer length to be backfilled at the end of this routine.
531 if (iap->ia_valid & ATTR_SIZE) {
532 bmval0 |= FATTR4_WORD0_SIZE;
533 WRITE64(iap->ia_size);
535 if (iap->ia_valid & ATTR_MODE) {
536 bmval1 |= FATTR4_WORD1_MODE;
537 WRITE32(iap->ia_mode);
539 if (iap->ia_valid & ATTR_UID) {
540 bmval1 |= FATTR4_WORD1_OWNER;
541 WRITE32(owner_namelen);
542 WRITEMEM(owner_name, owner_namelen);
544 if (iap->ia_valid & ATTR_GID) {
545 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
546 WRITE32(owner_grouplen);
547 WRITEMEM(owner_group, owner_grouplen);
549 if (iap->ia_valid & ATTR_ATIME_SET) {
550 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
551 WRITE32(NFS4_SET_TO_CLIENT_TIME);
553 WRITE32(iap->ia_mtime.tv_sec);
554 WRITE32(iap->ia_mtime.tv_nsec);
556 else if (iap->ia_valid & ATTR_ATIME) {
557 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
558 WRITE32(NFS4_SET_TO_SERVER_TIME);
560 if (iap->ia_valid & ATTR_MTIME_SET) {
561 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
562 WRITE32(NFS4_SET_TO_CLIENT_TIME);
564 WRITE32(iap->ia_mtime.tv_sec);
565 WRITE32(iap->ia_mtime.tv_nsec);
567 else if (iap->ia_valid & ATTR_MTIME) {
568 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
569 WRITE32(NFS4_SET_TO_SERVER_TIME);
573 * Now we backfill the bitmap and the attribute buffer length.
575 if (len != ((char *)p - (char *)q) + 4) {
576 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
577 len, ((char *)p - (char *)q) + 4);
580 len = (char *)p - (char *)q - 12;
581 *q++ = htonl(bmval0);
582 *q++ = htonl(bmval1);
590 static int encode_access(struct xdr_stream *xdr, u32 access)
601 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
605 RESERVE_SPACE(8+sizeof(arg->stateid.data));
608 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
613 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
619 WRITE64(args->offset);
620 WRITE32(args->count);
625 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
631 WRITE32(create->ftype);
633 switch (create->ftype) {
635 RESERVE_SPACE(4 + create->u.symlink->len);
636 WRITE32(create->u.symlink->len);
637 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
640 case NF4BLK: case NF4CHR:
642 WRITE32(create->u.device.specdata1);
643 WRITE32(create->u.device.specdata2);
650 RESERVE_SPACE(4 + create->name->len);
651 WRITE32(create->name->len);
652 WRITEMEM(create->name->name, create->name->len);
654 return encode_attrs(xdr, create->attrs, create->server);
657 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
668 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
680 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
682 return encode_getattr_two(xdr,
683 bitmask[0] & nfs4_fattr_bitmap[0],
684 bitmask[1] & nfs4_fattr_bitmap[1]);
687 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
689 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
690 bitmask[1] & nfs4_fsinfo_bitmap[1]);
693 static int encode_getfh(struct xdr_stream *xdr)
703 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
707 RESERVE_SPACE(8 + name->len);
710 WRITEMEM(name->name, name->len);
716 * opcode,type,reclaim,offset,length,new_lock_owner = 32
717 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
719 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
722 struct nfs_lock_opargs *opargs = arg->u.lock;
727 WRITE32(opargs->reclaim);
728 WRITE64(arg->offset);
729 WRITE64(arg->length);
730 WRITE32(opargs->new_lock_owner);
731 if (opargs->new_lock_owner){
732 struct nfs_open_to_lock *ol = opargs->u.open_lock;
735 WRITE32(ol->open_seqid);
736 WRITEMEM(&ol->open_stateid, sizeof(ol->open_stateid));
737 WRITE32(ol->lock_seqid);
738 WRITE64(ol->lock_owner.clientid);
740 WRITE32(ol->lock_owner.id);
743 struct nfs_exist_lock *el = opargs->u.exist_lock;
746 WRITEMEM(&el->stateid, sizeof(el->stateid));
753 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
756 struct nfs_lowner *opargs = arg->u.lockt;
761 WRITE64(arg->offset);
762 WRITE64(arg->length);
763 WRITE64(opargs->clientid);
770 static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
773 struct nfs_locku_opargs *opargs = arg->u.locku;
778 WRITE32(opargs->seqid);
779 WRITEMEM(&opargs->stateid, sizeof(opargs->stateid));
780 WRITE64(arg->offset);
781 WRITE64(arg->length);
786 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
791 RESERVE_SPACE(8 + len);
794 WRITEMEM(name->name, len);
799 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
804 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
806 WRITE32(NFS4_SHARE_ACCESS_READ);
809 WRITE32(NFS4_SHARE_ACCESS_WRITE);
811 case FMODE_READ|FMODE_WRITE:
812 WRITE32(NFS4_SHARE_ACCESS_BOTH);
817 WRITE32(0); /* for linux, share_deny = 0 always */
820 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
824 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
830 encode_share_access(xdr, arg->open_flags);
832 WRITE64(arg->clientid);
837 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
842 switch(arg->open_flags & O_EXCL) {
844 WRITE32(NFS4_CREATE_UNCHECKED);
845 encode_attrs(xdr, arg->u.attrs, arg->server);
848 WRITE32(NFS4_CREATE_EXCLUSIVE);
849 encode_nfs4_verifier(xdr, &arg->u.verifier);
853 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
858 switch (arg->open_flags & O_CREAT) {
860 WRITE32(NFS4_OPEN_NOCREATE);
863 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
864 WRITE32(NFS4_OPEN_CREATE);
865 encode_createmode(xdr, arg);
869 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
874 switch (delegation_type) {
876 WRITE32(NFS4_OPEN_DELEGATE_NONE);
879 WRITE32(NFS4_OPEN_DELEGATE_READ);
881 case FMODE_WRITE|FMODE_READ:
882 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
889 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
894 WRITE32(NFS4_OPEN_CLAIM_NULL);
895 encode_string(xdr, name->len, name->name);
898 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
903 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
904 encode_delegation_type(xdr, type);
907 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
911 RESERVE_SPACE(4+sizeof(stateid->data));
912 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
913 WRITEMEM(stateid->data, sizeof(stateid->data));
914 encode_string(xdr, name->len, name->name);
917 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
919 encode_openhdr(xdr, arg);
920 encode_opentype(xdr, arg);
921 switch (arg->claim) {
922 case NFS4_OPEN_CLAIM_NULL:
923 encode_claim_null(xdr, arg->name);
925 case NFS4_OPEN_CLAIM_PREVIOUS:
926 encode_claim_previous(xdr, arg->u.delegation_type);
928 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
929 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
937 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
941 RESERVE_SPACE(8+sizeof(arg->stateid.data));
942 WRITE32(OP_OPEN_CONFIRM);
943 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
949 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
953 RESERVE_SPACE(8+sizeof(arg->stateid.data));
954 WRITE32(OP_OPEN_DOWNGRADE);
955 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
957 encode_share_access(xdr, arg->open_flags);
962 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
967 RESERVE_SPACE(8 + len);
970 WRITEMEM(fh->data, len);
975 static int encode_putrootfh(struct xdr_stream *xdr)
980 WRITE32(OP_PUTROOTFH);
985 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
987 nfs4_stateid stateid;
991 if (ctx->state != NULL) {
992 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
993 WRITEMEM(stateid.data, sizeof(stateid.data));
995 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
998 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1005 encode_stateid(xdr, args->context);
1008 WRITE64(args->offset);
1009 WRITE32(args->count);
1014 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1016 struct rpc_auth *auth = req->rq_task->tk_auth;
1017 uint32_t attrs[2] = {
1018 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1019 FATTR4_WORD1_MOUNTED_ON_FILEID,
1024 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1025 WRITE32(OP_READDIR);
1026 WRITE64(readdir->cookie);
1027 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1028 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1029 WRITE32(readdir->count);
1031 /* Switch to mounted_on_fileid if the server supports it */
1032 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1033 attrs[0] &= ~FATTR4_WORD0_FILEID;
1035 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1036 WRITE32(attrs[0] & readdir->bitmask[0]);
1037 WRITE32(attrs[1] & readdir->bitmask[1]);
1039 /* set up reply kvec
1040 * toplevel_status + taglen + rescount + OP_PUTFH + status
1041 * + OP_READDIR + status + verifer(2) = 9
1043 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1044 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1045 readdir->pgbase, readdir->count);
1050 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1052 struct rpc_auth *auth = req->rq_task->tk_auth;
1053 unsigned int replen;
1057 WRITE32(OP_READLINK);
1059 /* set up reply kvec
1060 * toplevel_status + taglen + rescount + OP_PUTFH + status
1061 * + OP_READLINK + status + string length = 8
1063 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1064 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1065 readlink->pgbase, readlink->pglen);
1070 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1074 RESERVE_SPACE(8 + name->len);
1077 WRITEMEM(name->name, name->len);
1082 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1086 RESERVE_SPACE(8 + oldname->len);
1088 WRITE32(oldname->len);
1089 WRITEMEM(oldname->name, oldname->len);
1091 RESERVE_SPACE(4 + newname->len);
1092 WRITE32(newname->len);
1093 WRITEMEM(newname->name, newname->len);
1098 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1104 WRITE64(client_stateid->cl_clientid);
1110 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1114 RESERVE_SPACE(4+sizeof(zero_stateid.data));
1115 WRITE32(OP_SETATTR);
1116 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1119 WRITE32(FATTR4_WORD0_ACL);
1120 if (arg->acl_len % 4)
1123 WRITE32(arg->acl_len);
1124 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1129 encode_savefh(struct xdr_stream *xdr)
1139 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1144 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1145 WRITE32(OP_SETATTR);
1146 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1148 if ((status = encode_attrs(xdr, arg->iap, server)))
1154 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1158 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1159 WRITE32(OP_SETCLIENTID);
1160 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1162 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1164 WRITE32(setclientid->sc_prog);
1165 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1166 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1168 WRITE32(setclientid->sc_cb_ident);
1173 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1177 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1178 WRITE32(OP_SETCLIENTID_CONFIRM);
1179 WRITE64(client_state->cl_clientid);
1180 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1185 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1192 encode_stateid(xdr, args->context);
1195 WRITE64(args->offset);
1196 WRITE32(args->stable);
1197 WRITE32(args->count);
1199 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1204 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1210 WRITE32(OP_DELEGRETURN);
1211 WRITEMEM(stateid->data, sizeof(stateid->data));
1216 * END OF "GENERIC" ENCODE ROUTINES.
1220 * Encode an ACCESS request
1222 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1224 struct xdr_stream xdr;
1225 struct compound_hdr hdr = {
1230 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1231 encode_compound_hdr(&xdr, &hdr);
1232 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1233 status = encode_access(&xdr, args->access);
1238 * Encode LOOKUP request
1240 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1242 struct xdr_stream xdr;
1243 struct compound_hdr hdr = {
1248 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1249 encode_compound_hdr(&xdr, &hdr);
1250 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1252 if ((status = encode_lookup(&xdr, args->name)) != 0)
1254 if ((status = encode_getfh(&xdr)) != 0)
1256 status = encode_getfattr(&xdr, args->bitmask);
1262 * Encode LOOKUP_ROOT request
1264 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1266 struct xdr_stream xdr;
1267 struct compound_hdr hdr = {
1272 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1273 encode_compound_hdr(&xdr, &hdr);
1274 if ((status = encode_putrootfh(&xdr)) != 0)
1276 if ((status = encode_getfh(&xdr)) == 0)
1277 status = encode_getfattr(&xdr, args->bitmask);
1283 * Encode REMOVE request
1285 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1287 struct xdr_stream xdr;
1288 struct compound_hdr hdr = {
1293 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1294 encode_compound_hdr(&xdr, &hdr);
1295 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1296 status = encode_remove(&xdr, args->name);
1301 * Encode RENAME request
1303 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1305 struct xdr_stream xdr;
1306 struct compound_hdr hdr = {
1311 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1312 encode_compound_hdr(&xdr, &hdr);
1313 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1315 if ((status = encode_savefh(&xdr)) != 0)
1317 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1319 status = encode_rename(&xdr, args->old_name, args->new_name);
1325 * Encode LINK request
1327 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1329 struct xdr_stream xdr;
1330 struct compound_hdr hdr = {
1335 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1336 encode_compound_hdr(&xdr, &hdr);
1337 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1339 if ((status = encode_savefh(&xdr)) != 0)
1341 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1343 status = encode_link(&xdr, args->name);
1349 * Encode CREATE request
1351 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1353 struct xdr_stream xdr;
1354 struct compound_hdr hdr = {
1359 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1360 encode_compound_hdr(&xdr, &hdr);
1361 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1363 if ((status = encode_create(&xdr, args)) != 0)
1365 if ((status = encode_getfh(&xdr)) != 0)
1367 status = encode_getfattr(&xdr, args->bitmask);
1373 * Encode SYMLINK request
1375 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1377 return nfs4_xdr_enc_create(req, p, args);
1381 * Encode GETATTR request
1383 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1385 struct xdr_stream xdr;
1386 struct compound_hdr hdr = {
1391 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1392 encode_compound_hdr(&xdr, &hdr);
1393 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1394 status = encode_getfattr(&xdr, args->bitmask);
1399 * Encode a CLOSE request
1401 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1403 struct xdr_stream xdr;
1404 struct compound_hdr hdr = {
1409 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1410 encode_compound_hdr(&xdr, &hdr);
1411 status = encode_putfh(&xdr, args->fh);
1414 status = encode_close(&xdr, args);
1420 * Encode an OPEN request
1422 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1424 struct xdr_stream xdr;
1425 struct compound_hdr hdr = {
1430 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1431 encode_compound_hdr(&xdr, &hdr);
1432 status = encode_putfh(&xdr, args->fh);
1435 status = encode_open(&xdr, args);
1438 status = encode_getfh(&xdr);
1441 status = encode_getfattr(&xdr, args->bitmask);
1447 * Encode an OPEN_CONFIRM request
1449 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1451 struct xdr_stream xdr;
1452 struct compound_hdr hdr = {
1457 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1458 encode_compound_hdr(&xdr, &hdr);
1459 status = encode_putfh(&xdr, args->fh);
1462 status = encode_open_confirm(&xdr, args);
1468 * Encode an OPEN request with no attributes.
1470 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *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_open(&xdr, args);
1489 * Encode an OPEN_DOWNGRADE request
1491 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1493 struct xdr_stream xdr;
1494 struct compound_hdr hdr = {
1499 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1500 encode_compound_hdr(&xdr, &hdr);
1501 status = encode_putfh(&xdr, args->fh);
1504 status = encode_open_downgrade(&xdr, args);
1510 * Encode a LOCK request
1512 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1514 struct xdr_stream xdr;
1515 struct compound_hdr hdr = {
1520 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1521 encode_compound_hdr(&xdr, &hdr);
1522 status = encode_putfh(&xdr, args->fh);
1525 status = encode_lock(&xdr, args);
1531 * Encode a LOCKT request
1533 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1535 struct xdr_stream xdr;
1536 struct compound_hdr hdr = {
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_lockt(&xdr, args);
1552 * Encode a LOCKU request
1554 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1556 struct xdr_stream xdr;
1557 struct compound_hdr hdr = {
1562 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1563 encode_compound_hdr(&xdr, &hdr);
1564 status = encode_putfh(&xdr, args->fh);
1567 status = encode_locku(&xdr, args);
1573 * Encode a READLINK request
1575 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1577 struct xdr_stream xdr;
1578 struct compound_hdr hdr = {
1583 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1584 encode_compound_hdr(&xdr, &hdr);
1585 status = encode_putfh(&xdr, args->fh);
1588 status = encode_readlink(&xdr, args, req);
1594 * Encode a READDIR request
1596 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1598 struct xdr_stream xdr;
1599 struct compound_hdr hdr = {
1604 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1605 encode_compound_hdr(&xdr, &hdr);
1606 status = encode_putfh(&xdr, args->fh);
1609 status = encode_readdir(&xdr, args, req);
1615 * Encode a READ request
1617 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1619 struct rpc_auth *auth = req->rq_task->tk_auth;
1620 struct xdr_stream xdr;
1621 struct compound_hdr hdr = {
1626 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1627 encode_compound_hdr(&xdr, &hdr);
1628 status = encode_putfh(&xdr, args->fh);
1631 status = encode_read(&xdr, args);
1635 /* set up reply kvec
1636 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1637 * + OP_READ + status + eof + datalen = 9
1639 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1640 xdr_inline_pages(&req->rq_rcv_buf, replen,
1641 args->pages, args->pgbase, args->count);
1647 * Encode an SETATTR request
1649 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1652 struct xdr_stream xdr;
1653 struct compound_hdr hdr = {
1658 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1659 encode_compound_hdr(&xdr, &hdr);
1660 status = encode_putfh(&xdr, args->fh);
1663 status = encode_setattr(&xdr, args, args->server);
1666 status = encode_getfattr(&xdr, args->bitmask);
1672 * Encode a GETACL request
1675 nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p,
1676 struct nfs_getaclargs *args)
1678 struct xdr_stream xdr;
1679 struct rpc_auth *auth = req->rq_task->tk_auth;
1680 struct compound_hdr hdr = {
1685 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1686 encode_compound_hdr(&xdr, &hdr);
1687 status = encode_putfh(&xdr, args->fh);
1690 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1691 /* set up reply buffer: */
1692 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1693 xdr_inline_pages(&req->rq_rcv_buf, replen,
1694 args->acl_pages, args->acl_pgbase, args->acl_len);
1700 * Encode a WRITE request
1702 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1704 struct xdr_stream xdr;
1705 struct compound_hdr hdr = {
1710 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1711 encode_compound_hdr(&xdr, &hdr);
1712 status = encode_putfh(&xdr, args->fh);
1715 status = encode_write(&xdr, args);
1723 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1725 struct xdr_stream xdr;
1726 struct compound_hdr hdr = {
1731 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1732 encode_compound_hdr(&xdr, &hdr);
1733 status = encode_putfh(&xdr, args->fh);
1736 status = encode_commit(&xdr, args);
1744 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1746 struct xdr_stream xdr;
1747 struct compound_hdr hdr = {
1752 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1753 encode_compound_hdr(&xdr, &hdr);
1754 status = encode_putfh(&xdr, args->fh);
1756 status = encode_fsinfo(&xdr, args->bitmask);
1761 * a PATHCONF request
1763 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1765 struct xdr_stream xdr;
1766 struct compound_hdr hdr = {
1771 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1772 encode_compound_hdr(&xdr, &hdr);
1773 status = encode_putfh(&xdr, args->fh);
1775 status = encode_getattr_one(&xdr,
1776 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1783 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1785 struct xdr_stream xdr;
1786 struct compound_hdr hdr = {
1791 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1792 encode_compound_hdr(&xdr, &hdr);
1793 status = encode_putfh(&xdr, args->fh);
1795 status = encode_getattr_two(&xdr,
1796 args->bitmask[0] & nfs4_statfs_bitmap[0],
1797 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1802 * GETATTR_BITMAP request
1804 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1806 struct xdr_stream xdr;
1807 struct compound_hdr hdr = {
1812 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1813 encode_compound_hdr(&xdr, &hdr);
1814 status = encode_putfh(&xdr, fhandle);
1816 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1817 FATTR4_WORD0_LINK_SUPPORT|
1818 FATTR4_WORD0_SYMLINK_SUPPORT|
1819 FATTR4_WORD0_ACLSUPPORT);
1826 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1828 struct xdr_stream xdr;
1829 struct compound_hdr hdr = {
1833 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1834 encode_compound_hdr(&xdr, &hdr);
1835 return encode_renew(&xdr, clp);
1839 * a SETCLIENTID request
1841 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1843 struct xdr_stream xdr;
1844 struct compound_hdr hdr = {
1848 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1849 encode_compound_hdr(&xdr, &hdr);
1850 return encode_setclientid(&xdr, sc);
1854 * a SETCLIENTID_CONFIRM request
1856 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1858 struct xdr_stream xdr;
1859 struct compound_hdr hdr = {
1862 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1865 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1866 encode_compound_hdr(&xdr, &hdr);
1867 status = encode_setclientid_confirm(&xdr, clp);
1869 status = encode_putrootfh(&xdr);
1871 status = encode_fsinfo(&xdr, lease_bitmap);
1876 * DELEGRETURN request
1878 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1880 struct xdr_stream xdr;
1881 struct compound_hdr hdr = {
1886 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1887 encode_compound_hdr(&xdr, &hdr);
1888 if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
1889 status = encode_delegreturn(&xdr, args->stateid);
1894 * START OF "GENERIC" DECODE ROUTINES.
1895 * These may look a little ugly since they are imported from a "generic"
1896 * set of XDR encode/decode routines which are intended to be shared by
1897 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1899 * If the pain of reading these is too great, it should be a straightforward
1900 * task to translate them into Linux-specific versions which are more
1901 * consistent with the style used in NFSv2/v3...
1903 #define READ32(x) (x) = ntohl(*p++)
1904 #define READ64(x) do { \
1905 (x) = (u64)ntohl(*p++) << 32; \
1906 (x) |= ntohl(*p++); \
1908 #define READTIME(x) do { \
1910 (x.tv_sec) = ntohl(*p++); \
1911 (x.tv_nsec) = ntohl(*p++); \
1913 #define COPYMEM(x,nbytes) do { \
1914 memcpy((x), p, nbytes); \
1915 p += XDR_QUADLEN(nbytes); \
1918 #define READ_BUF(nbytes) do { \
1919 p = xdr_inline_decode(xdr, nbytes); \
1921 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
1922 __FUNCTION__, __LINE__); \
1927 static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
1934 *string = (char *)p;
1938 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
1943 READ32(hdr->status);
1944 READ32(hdr->taglen);
1946 READ_BUF(hdr->taglen + 4);
1947 hdr->tag = (char *)p;
1948 p += XDR_QUADLEN(hdr->taglen);
1953 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
1961 if (opnum != expected) {
1963 "nfs4_decode_op_hdr: Server returned operation"
1964 " %d but we issued a request for %d\n",
1969 if (nfserr != NFS_OK)
1970 return -nfs_stat_to_errno(nfserr);
1975 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
1982 return decode_opaque_inline(xdr, &strlen, &str);
1985 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
1992 bitmap[0] = bitmap[1] = 0;
1993 READ_BUF((bmlen << 2));
2002 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
2012 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2014 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2015 decode_attr_bitmap(xdr, bitmask);
2016 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2018 bitmask[0] = bitmask[1] = 0;
2019 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2023 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2028 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2030 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2033 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2034 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2037 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2039 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2043 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2048 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2050 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2053 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2055 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2056 (unsigned long long)*change);
2060 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2065 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2067 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2070 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2072 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2076 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2081 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2083 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2086 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2088 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2092 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2097 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2099 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2102 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2104 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2108 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2114 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2116 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2118 READ64(fsid->major);
2119 READ64(fsid->minor);
2120 bitmap[0] &= ~FATTR4_WORD0_FSID;
2122 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2123 (unsigned long long)fsid->major,
2124 (unsigned long long)fsid->minor);
2128 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2133 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2135 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2138 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2140 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2144 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2148 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2149 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2151 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2154 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2156 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2160 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2165 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2167 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2170 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2172 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2176 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2182 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2184 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2187 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2189 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2193 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2199 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2201 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2204 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2206 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2210 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2216 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2218 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2221 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2223 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2227 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2233 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2235 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2238 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2240 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2244 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2250 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2252 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2255 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2257 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2261 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2267 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2269 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2272 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2274 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2278 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2284 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2286 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2290 if (maxread > 0x7FFFFFFF)
2291 maxread = 0x7FFFFFFF;
2292 *res = (uint32_t)maxread;
2293 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2295 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2299 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2305 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2307 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2311 if (maxwrite > 0x7FFFFFFF)
2312 maxwrite = 0x7FFFFFFF;
2313 *res = (uint32_t)maxwrite;
2314 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2316 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2320 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2325 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2327 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2331 bitmap[1] &= ~FATTR4_WORD1_MODE;
2333 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2337 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2342 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2344 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2347 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2349 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2353 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2358 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2360 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2364 if (len < XDR_MAX_NETOBJ) {
2365 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2366 dprintk("%s: nfs_map_name_to_uid failed!\n",
2369 printk(KERN_WARNING "%s: name too long (%u)!\n",
2371 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2373 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2377 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2382 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2384 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2388 if (len < XDR_MAX_NETOBJ) {
2389 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2390 dprintk("%s: nfs_map_group_to_gid failed!\n",
2393 printk(KERN_WARNING "%s: name too long (%u)!\n",
2395 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2397 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2401 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2403 uint32_t major = 0, minor = 0, *p;
2406 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2408 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2414 tmp = MKDEV(major, minor);
2415 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2417 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2419 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2423 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2429 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2431 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2434 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2436 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2440 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2446 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2448 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2451 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2453 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2457 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2463 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2465 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2468 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2470 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2474 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2479 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2481 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2484 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2486 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2487 (unsigned long long)*used);
2491 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2500 time->tv_sec = (time_t)sec;
2501 time->tv_nsec = (long)nsec;
2505 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2511 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2513 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2514 status = decode_attr_time(xdr, time);
2515 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2517 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2521 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2527 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2529 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2530 status = decode_attr_time(xdr, time);
2531 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2533 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2537 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2543 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2545 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2546 status = decode_attr_time(xdr, time);
2547 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2549 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2553 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2555 unsigned int attrwords = XDR_QUADLEN(attrlen);
2556 unsigned int nwords = xdr->p - savep;
2558 if (unlikely(attrwords != nwords)) {
2559 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2562 (attrwords < nwords) ? '<' : '>',
2569 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2574 READ32(cinfo->atomic);
2575 READ64(cinfo->before);
2576 READ64(cinfo->after);
2580 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2586 status = decode_op_hdr(xdr, OP_ACCESS);
2592 access->supported = supp;
2593 access->access = acc;
2597 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2602 status = decode_op_hdr(xdr, OP_CLOSE);
2605 READ_BUF(sizeof(res->stateid.data));
2606 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2610 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2615 status = decode_op_hdr(xdr, OP_COMMIT);
2619 COPYMEM(res->verf->verifier, 8);
2623 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2629 status = decode_op_hdr(xdr, OP_CREATE);
2632 if ((status = decode_change_info(xdr, cinfo)))
2636 READ_BUF(bmlen << 2);
2640 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2647 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2649 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2651 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2653 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2655 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2657 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2659 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2661 status = verify_attr_len(xdr, savep, attrlen);
2664 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2668 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2675 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2677 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2679 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2682 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2684 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2686 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2688 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2690 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2692 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2695 status = verify_attr_len(xdr, savep, attrlen);
2698 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2702 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2709 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2711 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2713 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2716 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2718 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2721 status = verify_attr_len(xdr, savep, attrlen);
2724 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2728 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2734 int status, fmode = 0;
2736 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2738 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2741 fattr->bitmap[0] = bitmap[0];
2742 fattr->bitmap[1] = bitmap[1];
2744 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2748 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2750 fattr->type = nfs_type2fmt[type].nfs2type;
2751 fmode = nfs_type2fmt[type].mode;
2753 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2755 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2757 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2759 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2761 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2763 fattr->mode |= fmode;
2764 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2766 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2768 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2770 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2772 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2774 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2776 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2778 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2780 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) {
2781 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2782 fattr->timestamp = jiffies;
2786 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2791 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2794 uint32_t attrlen, bitmap[2];
2797 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2799 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2801 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2804 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2806 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2808 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2810 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2812 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2813 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2815 fsinfo->wtpref = fsinfo->wtmax;
2817 status = verify_attr_len(xdr, savep, attrlen);
2820 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2824 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2830 status = decode_op_hdr(xdr, OP_GETFH);
2833 /* Zero handle first to allow comparisons */
2834 memset(fh, 0, sizeof(*fh));
2838 if (len > NFS4_FHSIZE)
2842 COPYMEM(fh->data, len);
2846 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2850 status = decode_op_hdr(xdr, OP_LINK);
2853 return decode_change_info(xdr, cinfo);
2857 * We create the owner, so we know a proper owner.id length is 4.
2859 static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2865 READ64(denied->offset);
2866 READ64(denied->length);
2867 READ32(denied->type);
2868 READ64(denied->owner.clientid);
2872 READ32(denied->owner.id);
2873 return -NFS4ERR_DENIED;
2876 static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2881 status = decode_op_hdr(xdr, OP_LOCK);
2883 READ_BUF(sizeof(nfs4_stateid));
2884 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2885 } else if (status == -NFS4ERR_DENIED)
2886 return decode_lock_denied(xdr, &res->u.denied);
2890 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2893 status = decode_op_hdr(xdr, OP_LOCKT);
2894 if (status == -NFS4ERR_DENIED)
2895 return decode_lock_denied(xdr, &res->u.denied);
2899 static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2904 status = decode_op_hdr(xdr, OP_LOCKU);
2906 READ_BUF(sizeof(nfs4_stateid));
2907 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2912 static int decode_lookup(struct xdr_stream *xdr)
2914 return decode_op_hdr(xdr, OP_LOOKUP);
2917 /* This is too sick! */
2918 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
2921 uint32_t limit_type, nblocks, blocksize;
2925 switch (limit_type) {
2932 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
2937 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
2940 uint32_t delegation_type;
2943 READ32(delegation_type);
2944 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
2945 res->delegation_type = 0;
2949 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
2950 READ32(res->do_recall);
2951 switch (delegation_type) {
2952 case NFS4_OPEN_DELEGATE_READ:
2953 res->delegation_type = FMODE_READ;
2955 case NFS4_OPEN_DELEGATE_WRITE:
2956 res->delegation_type = FMODE_WRITE|FMODE_READ;
2957 if (decode_space_limit(xdr, &res->maxsize) < 0)
2960 return decode_ace(xdr, NULL, res->server->nfs4_state);
2963 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
2969 status = decode_op_hdr(xdr, OP_OPEN);
2972 READ_BUF(sizeof(res->stateid.data));
2973 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2975 decode_change_info(xdr, &res->cinfo);
2978 READ32(res->rflags);
2983 READ_BUF(bmlen << 2);
2985 return decode_delegation(xdr, res);
2987 printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
2991 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
2996 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
2999 READ_BUF(sizeof(res->stateid.data));
3000 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3004 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3009 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3012 READ_BUF(sizeof(res->stateid.data));
3013 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3017 static int decode_putfh(struct xdr_stream *xdr)
3019 return decode_op_hdr(xdr, OP_PUTFH);
3022 static int decode_putrootfh(struct xdr_stream *xdr)
3024 return decode_op_hdr(xdr, OP_PUTROOTFH);
3027 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3029 struct kvec *iov = req->rq_rcv_buf.head;
3031 uint32_t count, eof, recvd, hdrlen;
3034 status = decode_op_hdr(xdr, OP_READ);
3040 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3041 recvd = req->rq_rcv_buf.len - hdrlen;
3042 if (count > recvd) {
3043 printk(KERN_WARNING "NFS: server cheating in read reply: "
3044 "count %u > recvd %u\n", count, recvd);
3048 xdr_read_pages(xdr, count);
3054 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3056 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3057 struct page *page = *rcvbuf->pages;
3058 struct kvec *iov = rcvbuf->head;
3059 unsigned int nr, pglen = rcvbuf->page_len;
3060 uint32_t *end, *entry, *p, *kaddr;
3061 uint32_t len, attrlen;
3062 int hdrlen, recvd, status;
3064 status = decode_op_hdr(xdr, OP_READDIR);
3068 COPYMEM(readdir->verifier.data, 8);
3070 hdrlen = (char *) p - (char *) iov->iov_base;
3071 recvd = rcvbuf->len - hdrlen;
3074 xdr_read_pages(xdr, pglen);
3076 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3077 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3078 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3080 for (nr = 0; *p++; nr++) {
3083 p += 2; /* cookie */
3084 len = ntohl(*p++); /* filename length */
3085 if (len > NFS4_MAXNAMLEN) {
3086 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3089 p += XDR_QUADLEN(len);
3092 len = ntohl(*p++); /* bitmap length */
3096 attrlen = XDR_QUADLEN(ntohl(*p++));
3097 p += attrlen; /* attributes */
3102 if (!nr && (entry[0] != 0 || entry[1] == 0))
3105 kunmap_atomic(kaddr, KM_USER0);
3108 entry[0] = entry[1] = 0;
3109 /* truncate listing ? */
3111 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3116 kunmap_atomic(kaddr, KM_USER0);
3117 return -errno_NFSERR_IO;
3120 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3122 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3123 struct kvec *iov = rcvbuf->head;
3124 int hdrlen, len, recvd;
3129 status = decode_op_hdr(xdr, OP_READLINK);
3133 /* Convert length of symlink */
3136 if (len >= rcvbuf->page_len || len <= 0) {
3137 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3138 return -ENAMETOOLONG;
3140 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3141 recvd = req->rq_rcv_buf.len - hdrlen;
3143 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3144 "count %u > recvd %u\n", len, recvd);
3147 xdr_read_pages(xdr, len);
3149 * The XDR encode routine has set things up so that
3150 * the link text will be copied directly into the
3151 * buffer. We just have to do overflow-checking,
3152 * and and null-terminate the text (the VFS expects
3153 * null-termination).
3155 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3156 kaddr[len+rcvbuf->page_base] = '\0';
3157 kunmap_atomic(kaddr, KM_USER0);
3161 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3165 status = decode_op_hdr(xdr, OP_REMOVE);
3168 status = decode_change_info(xdr, cinfo);
3173 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3174 struct nfs4_change_info *new_cinfo)
3178 status = decode_op_hdr(xdr, OP_RENAME);
3181 if ((status = decode_change_info(xdr, old_cinfo)))
3183 status = decode_change_info(xdr, new_cinfo);
3188 static int decode_renew(struct xdr_stream *xdr)
3190 return decode_op_hdr(xdr, OP_RENEW);
3193 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3199 struct kvec *iov = req->rq_rcv_buf.head;
3203 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3205 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3207 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3210 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3212 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3215 /* We ignore &savep and don't do consistency checks on
3216 * the attr length. Let userspace figure it out.... */
3217 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3218 recvd = req->rq_rcv_buf.len - hdrlen;
3219 if (attrlen > recvd) {
3220 printk(KERN_WARNING "NFS: server cheating in getattr"
3221 " acl reply: attrlen %u > recvd %u\n",
3225 if (attrlen <= *acl_len)
3226 xdr_read_pages(xdr, attrlen);
3235 decode_savefh(struct xdr_stream *xdr)
3237 return decode_op_hdr(xdr, OP_SAVEFH);
3240 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3247 status = decode_op_hdr(xdr, OP_SETATTR);
3252 READ_BUF(bmlen << 2);
3256 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3264 if (opnum != OP_SETCLIENTID) {
3266 "nfs4_decode_setclientid: Server returned operation"
3271 if (nfserr == NFS_OK) {
3272 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3273 READ64(clp->cl_clientid);
3274 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3275 } else if (nfserr == NFSERR_CLID_INUSE) {
3278 /* skip netid string */
3283 /* skip uaddr string */
3287 return -NFSERR_CLID_INUSE;
3289 return -nfs_stat_to_errno(nfserr);
3294 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3296 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3299 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3304 status = decode_op_hdr(xdr, OP_WRITE);
3310 READ32(res->verf->committed);
3311 COPYMEM(res->verf->verifier, 8);
3315 static int decode_delegreturn(struct xdr_stream *xdr)
3317 return decode_op_hdr(xdr, OP_DELEGRETURN);
3321 * Decode OPEN_DOWNGRADE response
3323 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3325 struct xdr_stream xdr;
3326 struct compound_hdr hdr;
3329 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3330 status = decode_compound_hdr(&xdr, &hdr);
3333 status = decode_putfh(&xdr);
3336 status = decode_open_downgrade(&xdr, res);
3342 * END OF "GENERIC" DECODE ROUTINES.
3346 * Decode ACCESS response
3348 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3350 struct xdr_stream xdr;
3351 struct compound_hdr hdr;
3354 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3355 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3357 if ((status = decode_putfh(&xdr)) == 0)
3358 status = decode_access(&xdr, res);
3364 * Decode LOOKUP response
3366 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3368 struct xdr_stream xdr;
3369 struct compound_hdr hdr;
3372 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3373 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3375 if ((status = decode_putfh(&xdr)) != 0)
3377 if ((status = decode_lookup(&xdr)) != 0)
3379 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3381 status = decode_getfattr(&xdr, res->fattr, res->server);
3387 * Decode LOOKUP_ROOT response
3389 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3391 struct xdr_stream xdr;
3392 struct compound_hdr hdr;
3395 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3396 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3398 if ((status = decode_putrootfh(&xdr)) != 0)
3400 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3401 status = decode_getfattr(&xdr, res->fattr, res->server);
3407 * Decode REMOVE response
3409 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3411 struct xdr_stream xdr;
3412 struct compound_hdr hdr;
3415 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3416 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3418 if ((status = decode_putfh(&xdr)) == 0)
3419 status = decode_remove(&xdr, cinfo);
3425 * Decode RENAME response
3427 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3429 struct xdr_stream xdr;
3430 struct compound_hdr hdr;
3433 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3434 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3436 if ((status = decode_putfh(&xdr)) != 0)
3438 if ((status = decode_savefh(&xdr)) != 0)
3440 if ((status = decode_putfh(&xdr)) != 0)
3442 status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
3448 * Decode LINK response
3450 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3452 struct xdr_stream xdr;
3453 struct compound_hdr hdr;
3456 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3457 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3459 if ((status = decode_putfh(&xdr)) != 0)
3461 if ((status = decode_savefh(&xdr)) != 0)
3463 if ((status = decode_putfh(&xdr)) != 0)
3465 status = decode_link(&xdr, cinfo);
3471 * Decode CREATE response
3473 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3475 struct xdr_stream xdr;
3476 struct compound_hdr hdr;
3479 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3480 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3482 if ((status = decode_putfh(&xdr)) != 0)
3484 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3486 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3488 status = decode_getfattr(&xdr, res->fattr, res->server);
3489 if (status == NFS4ERR_DELAY)
3496 * Decode SYMLINK response
3498 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3500 return nfs4_xdr_dec_create(rqstp, p, res);
3504 * Decode GETATTR response
3506 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3508 struct xdr_stream xdr;
3509 struct compound_hdr hdr;
3512 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3513 status = decode_compound_hdr(&xdr, &hdr);
3516 status = decode_putfh(&xdr);
3519 status = decode_getfattr(&xdr, res->fattr, res->server);
3526 * Encode an SETACL request
3529 nfs4_xdr_enc_setacl(struct rpc_rqst *req, uint32_t *p, struct nfs_setaclargs *args)
3531 struct xdr_stream xdr;
3532 struct compound_hdr hdr = {
3537 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3538 encode_compound_hdr(&xdr, &hdr);
3539 status = encode_putfh(&xdr, args->fh);
3542 status = encode_setacl(&xdr, args);
3547 * Decode SETACL response
3550 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3552 struct xdr_stream xdr;
3553 struct compound_hdr hdr;
3556 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3557 status = decode_compound_hdr(&xdr, &hdr);
3560 status = decode_putfh(&xdr);
3563 status = decode_setattr(&xdr, res);
3569 * Decode GETACL response
3572 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len)
3574 struct xdr_stream xdr;
3575 struct compound_hdr hdr;
3578 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3579 status = decode_compound_hdr(&xdr, &hdr);
3582 status = decode_putfh(&xdr);
3585 status = decode_getacl(&xdr, rqstp, acl_len);
3592 * Decode CLOSE response
3594 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3596 struct xdr_stream xdr;
3597 struct compound_hdr hdr;
3600 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3601 status = decode_compound_hdr(&xdr, &hdr);
3604 status = decode_putfh(&xdr);
3607 status = decode_close(&xdr, res);
3613 * Decode OPEN response
3615 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3617 struct xdr_stream xdr;
3618 struct compound_hdr hdr;
3621 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3622 status = decode_compound_hdr(&xdr, &hdr);
3625 status = decode_putfh(&xdr);
3628 status = decode_open(&xdr, res);
3631 status = decode_getfh(&xdr, &res->fh);
3634 status = decode_getfattr(&xdr, res->f_attr, res->server);
3635 if (status == NFS4ERR_DELAY)
3642 * Decode OPEN_CONFIRM response
3644 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *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_open_confirm(&xdr, res);
3663 * Decode OPEN response
3665 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3667 struct xdr_stream xdr;
3668 struct compound_hdr hdr;
3671 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3672 status = decode_compound_hdr(&xdr, &hdr);
3675 status = decode_putfh(&xdr);
3678 status = decode_open(&xdr, res);
3684 * Decode SETATTR response
3686 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3688 struct xdr_stream xdr;
3689 struct compound_hdr hdr;
3692 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3693 status = decode_compound_hdr(&xdr, &hdr);
3696 status = decode_putfh(&xdr);
3699 status = decode_setattr(&xdr, res);
3702 status = decode_getfattr(&xdr, res->fattr, res->server);
3703 if (status == NFS4ERR_DELAY)
3710 * Decode LOCK response
3712 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3714 struct xdr_stream xdr;
3715 struct compound_hdr hdr;
3718 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3719 status = decode_compound_hdr(&xdr, &hdr);
3722 status = decode_putfh(&xdr);
3725 status = decode_lock(&xdr, res);
3731 * Decode LOCKT response
3733 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3735 struct xdr_stream xdr;
3736 struct compound_hdr hdr;
3739 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3740 status = decode_compound_hdr(&xdr, &hdr);
3743 status = decode_putfh(&xdr);
3746 status = decode_lockt(&xdr, res);
3752 * Decode LOCKU response
3754 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3756 struct xdr_stream xdr;
3757 struct compound_hdr hdr;
3760 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3761 status = decode_compound_hdr(&xdr, &hdr);
3764 status = decode_putfh(&xdr);
3767 status = decode_locku(&xdr, res);
3773 * Decode READLINK response
3775 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3777 struct xdr_stream xdr;
3778 struct compound_hdr hdr;
3781 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3782 status = decode_compound_hdr(&xdr, &hdr);
3785 status = decode_putfh(&xdr);
3788 status = decode_readlink(&xdr, rqstp);
3794 * Decode READDIR response
3796 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *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_readdir(&xdr, rqstp, res);
3815 * Decode Read response
3817 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *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_read(&xdr, rqstp, res);
3832 status = res->count;
3838 * Decode WRITE response
3840 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3842 struct xdr_stream xdr;
3843 struct compound_hdr hdr;
3846 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3847 status = decode_compound_hdr(&xdr, &hdr);
3850 status = decode_putfh(&xdr);
3853 status = decode_write(&xdr, res);
3855 status = res->count;
3861 * Decode COMMIT response
3863 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3865 struct xdr_stream xdr;
3866 struct compound_hdr hdr;
3869 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3870 status = decode_compound_hdr(&xdr, &hdr);
3873 status = decode_putfh(&xdr);
3876 status = decode_commit(&xdr, res);
3884 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3886 struct xdr_stream xdr;
3887 struct compound_hdr hdr;
3890 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3891 status = decode_compound_hdr(&xdr, &hdr);
3893 status = decode_putfh(&xdr);
3895 status = decode_fsinfo(&xdr, fsinfo);
3897 status = -nfs_stat_to_errno(hdr.status);
3904 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
3906 struct xdr_stream xdr;
3907 struct compound_hdr hdr;
3910 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3911 status = decode_compound_hdr(&xdr, &hdr);
3913 status = decode_putfh(&xdr);
3915 status = decode_pathconf(&xdr, pathconf);
3922 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
3924 struct xdr_stream xdr;
3925 struct compound_hdr hdr;
3928 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3929 status = decode_compound_hdr(&xdr, &hdr);
3931 status = decode_putfh(&xdr);
3933 status = decode_statfs(&xdr, fsstat);
3938 * GETATTR_BITMAP request
3940 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
3942 struct xdr_stream xdr;
3943 struct compound_hdr hdr;
3946 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3947 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3949 if ((status = decode_putfh(&xdr)) != 0)
3951 status = decode_server_caps(&xdr, res);
3957 * Decode RENEW response
3959 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3961 struct xdr_stream xdr;
3962 struct compound_hdr hdr;
3965 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3966 status = decode_compound_hdr(&xdr, &hdr);
3968 status = decode_renew(&xdr);
3973 * a SETCLIENTID request
3975 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
3976 struct nfs4_client *clp)
3978 struct xdr_stream xdr;
3979 struct compound_hdr hdr;
3982 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3983 status = decode_compound_hdr(&xdr, &hdr);
3985 status = decode_setclientid(&xdr, clp);
3987 status = -nfs_stat_to_errno(hdr.status);
3992 * a SETCLIENTID_CONFIRM request
3994 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3996 struct xdr_stream xdr;
3997 struct compound_hdr hdr;
4000 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4001 status = decode_compound_hdr(&xdr, &hdr);
4003 status = decode_setclientid_confirm(&xdr);
4005 status = decode_putrootfh(&xdr);
4007 status = decode_fsinfo(&xdr, fsinfo);
4009 status = -nfs_stat_to_errno(hdr.status);
4014 * DELEGRETURN request
4016 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
4018 struct xdr_stream xdr;
4019 struct compound_hdr hdr;
4022 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4023 status = decode_compound_hdr(&xdr, &hdr);
4025 status = decode_putfh(&xdr);
4027 status = decode_delegreturn(&xdr);
4032 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
4034 uint32_t bitmap[2] = {0};
4039 return ERR_PTR(-EAGAIN);
4041 return ERR_PTR(-EBADCOOKIE);
4044 entry->prev_cookie = entry->cookie;
4045 p = xdr_decode_hyper(p, &entry->cookie);
4046 entry->len = ntohl(*p++);
4047 entry->name = (const char *) p;
4048 p += XDR_QUADLEN(entry->len);
4051 * In case the server doesn't return an inode number,
4052 * we fake one here. (We don't use inode number 0,
4053 * since glibc seems to choke on it...)
4057 len = ntohl(*p++); /* bitmap length */
4059 bitmap[0] = ntohl(*p++);
4061 bitmap[1] = ntohl(*p++);
4065 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4067 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4068 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4069 /* Ignore the return value of rdattr_error for now */
4073 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4074 xdr_decode_hyper(p, &entry->ino);
4075 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4076 xdr_decode_hyper(p, &entry->ino);
4080 entry->eof = !p[0] && p[1];
4085 * We need to translate between nfs status return values and
4086 * the local errno values which may not be the same.
4093 { NFS4ERR_PERM, EPERM },
4094 { NFS4ERR_NOENT, ENOENT },
4095 { NFS4ERR_IO, errno_NFSERR_IO },
4096 { NFS4ERR_NXIO, ENXIO },
4097 { NFS4ERR_ACCESS, EACCES },
4098 { NFS4ERR_EXIST, EEXIST },
4099 { NFS4ERR_XDEV, EXDEV },
4100 { NFS4ERR_NOTDIR, ENOTDIR },
4101 { NFS4ERR_ISDIR, EISDIR },
4102 { NFS4ERR_INVAL, EINVAL },
4103 { NFS4ERR_FBIG, EFBIG },
4104 { NFS4ERR_NOSPC, ENOSPC },
4105 { NFS4ERR_ROFS, EROFS },
4106 { NFS4ERR_MLINK, EMLINK },
4107 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4108 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4109 { NFS4ERR_DQUOT, EDQUOT },
4110 { NFS4ERR_STALE, ESTALE },
4111 { NFS4ERR_BADHANDLE, EBADHANDLE },
4112 { NFS4ERR_BADOWNER, EINVAL },
4113 { NFS4ERR_BADNAME, EINVAL },
4114 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4115 { NFS4ERR_NOTSUPP, ENOTSUPP },
4116 { NFS4ERR_TOOSMALL, ETOOSMALL },
4117 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4118 { NFS4ERR_BADTYPE, EBADTYPE },
4119 { NFS4ERR_LOCKED, EAGAIN },
4120 { NFS4ERR_RESOURCE, EREMOTEIO },
4121 { NFS4ERR_SYMLINK, ELOOP },
4122 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4123 { NFS4ERR_DEADLOCK, EDEADLK },
4124 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4125 * to be handled by a
4132 * Convert an NFS error code to a local one.
4133 * This one is used jointly by NFSv2 and NFSv3.
4136 nfs_stat_to_errno(int stat)
4139 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4140 if (nfs_errtbl[i].stat == stat)
4141 return nfs_errtbl[i].errno;
4143 if (stat <= 10000 || stat > 10100) {
4144 /* The server is looney tunes. */
4145 return ESERVERFAULT;
4147 /* If we cannot translate the error, the recovery routines should
4149 * Note: remaining NFSv4 error codes have values > 10000, so should
4150 * not conflict with native Linux error codes.
4156 # define MAX(a, b) (((a) > (b))? (a) : (b))
4159 #define PROC(proc, argtype, restype) \
4160 [NFSPROC4_CLNT_##proc] = { \
4161 .p_proc = NFSPROC4_COMPOUND, \
4162 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4163 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4164 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
4167 struct rpc_procinfo nfs4_procedures[] = {
4168 PROC(READ, enc_read, dec_read),
4169 PROC(WRITE, enc_write, dec_write),
4170 PROC(COMMIT, enc_commit, dec_commit),
4171 PROC(OPEN, enc_open, dec_open),
4172 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4173 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4174 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4175 PROC(CLOSE, enc_close, dec_close),
4176 PROC(SETATTR, enc_setattr, dec_setattr),
4177 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4178 PROC(RENEW, enc_renew, dec_renew),
4179 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4180 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4181 PROC(LOCK, enc_lock, dec_lock),
4182 PROC(LOCKT, enc_lockt, dec_lockt),
4183 PROC(LOCKU, enc_locku, dec_locku),
4184 PROC(ACCESS, enc_access, dec_access),
4185 PROC(GETATTR, enc_getattr, dec_getattr),
4186 PROC(LOOKUP, enc_lookup, dec_lookup),
4187 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4188 PROC(REMOVE, enc_remove, dec_remove),
4189 PROC(RENAME, enc_rename, dec_rename),
4190 PROC(LINK, enc_link, dec_link),
4191 PROC(SYMLINK, enc_symlink, dec_symlink),
4192 PROC(CREATE, enc_create, dec_create),
4193 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4194 PROC(STATFS, enc_statfs, dec_statfs),
4195 PROC(READLINK, enc_readlink, dec_readlink),
4196 PROC(READDIR, enc_readdir, dec_readdir),
4197 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4198 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4199 PROC(GETACL, enc_getacl, dec_getacl),
4200 PROC(SETACL, enc_setacl, dec_setacl),
4203 struct rpc_version nfs_version4 = {
4205 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
4206 .procs = nfs4_procedures