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>
55 #define NFSDBG_FACILITY NFSDBG_XDR
57 /* Mapping from NFS error code to "errno" error code. */
58 #define errno_NFSERR_IO EIO
60 static int nfs_stat_to_errno(int);
62 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
64 #define NFS4_MAXTAGLEN 20
66 #define NFS4_MAXTAGLEN 0
69 /* lock,open owner id:
70 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
72 #define owner_id_maxsz (1 + 1)
73 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
74 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
75 #define op_encode_hdr_maxsz (1)
76 #define op_decode_hdr_maxsz (2)
77 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
79 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
80 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
81 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
82 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
83 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
84 ((3+NFS4_FHSIZE) >> 2))
85 #define encode_getattr_maxsz (op_encode_hdr_maxsz + 3)
86 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
87 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
88 #define nfs4_fattr_bitmap_maxsz (36 + 2 * nfs4_name_maxsz)
89 #define decode_getattr_maxsz (op_decode_hdr_maxsz + 3 + \
90 nfs4_fattr_bitmap_maxsz)
91 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
92 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
93 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
94 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
95 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
96 #define decode_renew_maxsz (op_decode_hdr_maxsz)
97 #define encode_setclientid_maxsz \
98 (op_encode_hdr_maxsz + \
99 4 /*server->ip_addr*/ + \
102 6 + (NFS4_VERIFIER_SIZE >> 2))
103 #define decode_setclientid_maxsz \
104 (op_decode_hdr_maxsz + \
106 1024) /* large value for CLID_INUSE */
107 #define encode_setclientid_confirm_maxsz \
108 (op_encode_hdr_maxsz + \
109 3 + (NFS4_VERIFIER_SIZE >> 2))
110 #define decode_setclientid_confirm_maxsz \
111 (op_decode_hdr_maxsz)
112 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
113 1 + ((3 + NFS4_FHSIZE) >> 2))
114 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
116 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
118 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
119 #define encode_link_maxsz (op_encode_hdr_maxsz + \
121 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
122 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
123 1 + nfs4_name_maxsz + \
125 nfs4_fattr_bitmap_maxsz)
126 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
127 #define encode_create_maxsz (op_encode_hdr_maxsz + \
128 2 + nfs4_name_maxsz + \
129 nfs4_fattr_bitmap_maxsz)
130 #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
131 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
132 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
133 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
134 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
135 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
136 encode_putfh_maxsz + \
137 op_encode_hdr_maxsz + 7)
138 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
139 decode_putfh_maxsz + \
140 op_decode_hdr_maxsz + 2)
141 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
142 encode_putfh_maxsz + \
144 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
145 decode_putfh_maxsz + \
147 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
148 encode_putfh_maxsz + \
149 op_encode_hdr_maxsz + 9)
150 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
151 decode_putfh_maxsz + \
152 op_decode_hdr_maxsz + 2)
153 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
154 encode_putfh_maxsz + \
155 op_encode_hdr_maxsz + 8)
156 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
157 decode_putfh_maxsz + \
158 op_decode_hdr_maxsz + 4)
159 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
160 encode_putfh_maxsz + \
161 op_encode_hdr_maxsz + 3)
162 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
163 decode_putfh_maxsz + \
164 op_decode_hdr_maxsz + 2)
165 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
166 encode_putfh_maxsz + \
167 op_encode_hdr_maxsz + \
169 encode_getattr_maxsz + \
171 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
172 decode_putfh_maxsz + \
173 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
174 decode_getattr_maxsz + \
176 #define NFS4_enc_open_confirm_sz \
177 (compound_encode_hdr_maxsz + \
178 encode_putfh_maxsz + \
179 op_encode_hdr_maxsz + 5)
180 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
181 decode_putfh_maxsz + \
182 op_decode_hdr_maxsz + 4)
183 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
184 encode_putfh_maxsz + \
185 op_encode_hdr_maxsz + \
187 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
188 decode_putfh_maxsz + \
189 op_decode_hdr_maxsz + \
191 #define NFS4_enc_open_downgrade_sz \
192 (compound_encode_hdr_maxsz + \
193 encode_putfh_maxsz + \
194 op_encode_hdr_maxsz + 7)
195 #define NFS4_dec_open_downgrade_sz \
196 (compound_decode_hdr_maxsz + \
197 decode_putfh_maxsz + \
198 op_decode_hdr_maxsz + 4)
199 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
200 encode_putfh_maxsz + \
201 op_encode_hdr_maxsz + 5)
202 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
203 decode_putfh_maxsz + \
204 op_decode_hdr_maxsz + 4)
205 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
206 encode_putfh_maxsz + \
207 op_encode_hdr_maxsz + 4 + \
208 nfs4_fattr_bitmap_maxsz + \
209 encode_getattr_maxsz)
210 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
211 decode_putfh_maxsz + \
212 op_decode_hdr_maxsz + 3)
213 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
214 encode_putfh_maxsz + \
216 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
217 decode_putfh_maxsz + \
219 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
221 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
223 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
224 encode_setclientid_maxsz)
225 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
226 decode_setclientid_maxsz)
227 #define NFS4_enc_setclientid_confirm_sz \
228 (compound_encode_hdr_maxsz + \
229 encode_setclientid_confirm_maxsz + \
230 encode_putrootfh_maxsz + \
232 #define NFS4_dec_setclientid_confirm_sz \
233 (compound_decode_hdr_maxsz + \
234 decode_setclientid_confirm_maxsz + \
235 decode_putrootfh_maxsz + \
237 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
238 encode_putfh_maxsz + \
239 encode_getattr_maxsz + \
240 op_encode_hdr_maxsz + \
244 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
245 decode_putfh_maxsz + \
246 decode_getattr_maxsz + \
247 op_decode_hdr_maxsz + \
250 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
251 encode_putfh_maxsz + \
252 encode_getattr_maxsz + \
253 op_encode_hdr_maxsz + \
256 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
257 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
258 encode_putfh_maxsz + \
259 encode_getattr_maxsz + \
260 op_encode_hdr_maxsz + \
262 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
263 decode_putfh_maxsz + \
264 decode_getattr_maxsz + \
265 op_decode_hdr_maxsz + 4)
266 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
267 encode_putfh_maxsz + \
268 op_encode_hdr_maxsz + 1)
269 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
270 decode_putfh_maxsz + \
271 op_decode_hdr_maxsz + 2)
272 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
273 encode_putfh_maxsz + \
274 encode_getattr_maxsz)
275 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
276 decode_putfh_maxsz + \
277 decode_getattr_maxsz)
278 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
279 encode_putfh_maxsz + \
280 encode_lookup_maxsz + \
281 encode_getattr_maxsz + \
283 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
284 decode_putfh_maxsz + \
285 op_decode_hdr_maxsz + \
286 decode_getattr_maxsz + \
288 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
289 encode_putrootfh_maxsz + \
290 encode_getattr_maxsz + \
292 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
293 decode_putrootfh_maxsz + \
294 decode_getattr_maxsz + \
296 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
297 encode_putfh_maxsz + \
299 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
300 decode_putfh_maxsz + \
301 op_decode_hdr_maxsz + 5)
302 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
303 encode_putfh_maxsz + \
304 encode_savefh_maxsz + \
305 encode_putfh_maxsz + \
307 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
308 decode_putfh_maxsz + \
309 decode_savefh_maxsz + \
310 decode_putfh_maxsz + \
312 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
313 encode_putfh_maxsz + \
314 encode_savefh_maxsz + \
315 encode_putfh_maxsz + \
317 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
318 decode_putfh_maxsz + \
319 decode_savefh_maxsz + \
320 decode_putfh_maxsz + \
322 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
323 encode_putfh_maxsz + \
324 encode_symlink_maxsz + \
325 encode_getattr_maxsz + \
327 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
328 decode_putfh_maxsz + \
329 decode_symlink_maxsz + \
330 decode_getattr_maxsz + \
332 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
333 encode_putfh_maxsz + \
334 encode_create_maxsz + \
335 encode_getattr_maxsz + \
337 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
338 decode_putfh_maxsz + \
339 decode_create_maxsz + \
340 decode_getattr_maxsz + \
342 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
343 encode_putfh_maxsz + \
344 encode_getattr_maxsz)
345 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
346 decode_putfh_maxsz + \
347 decode_getattr_maxsz)
348 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
349 encode_putfh_maxsz + \
350 encode_getattr_maxsz)
351 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
352 decode_putfh_maxsz + \
353 op_decode_hdr_maxsz + 12)
354 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
355 encode_getattr_maxsz)
356 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
357 decode_getattr_maxsz)
358 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
359 encode_putfh_maxsz + \
360 encode_delegreturn_maxsz)
361 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
362 decode_delegreturn_maxsz)
366 unsigned int nfs2type;
374 { S_IFSOCK, NFSOCK },
380 struct compound_hdr {
388 * START OF "GENERIC" ENCODE ROUTINES.
389 * These may look a little ugly since they are imported from a "generic"
390 * set of XDR encode/decode routines which are intended to be shared by
391 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
393 * If the pain of reading these is too great, it should be a straightforward
394 * task to translate them into Linux-specific versions which are more
395 * consistent with the style used in NFSv2/v3...
397 #define WRITE32(n) *p++ = htonl(n)
398 #define WRITE64(n) do { \
399 *p++ = htonl((uint32_t)((n) >> 32)); \
400 *p++ = htonl((uint32_t)(n)); \
402 #define WRITEMEM(ptr,nbytes) do { \
403 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
406 #define RESERVE_SPACE(nbytes) do { \
407 p = xdr_reserve_space(xdr, nbytes); \
408 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
412 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
416 p = xdr_reserve_space(xdr, 4 + len);
418 xdr_encode_opaque(p, str, len);
421 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
425 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
426 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
427 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
428 WRITE32(hdr->taglen);
429 WRITEMEM(hdr->tag, hdr->taglen);
430 WRITE32(NFS4_MINOR_VERSION);
435 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
439 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
441 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
444 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
446 char owner_name[IDMAP_NAMESZ];
447 char owner_group[IDMAP_NAMESZ];
448 int owner_namelen = 0;
449 int owner_grouplen = 0;
458 * We reserve enough space to write the entire attribute buffer at once.
459 * In the worst-case, this would be
460 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
461 * = 36 bytes, plus any contribution from variable-length fields
462 * such as owner/group/acl's.
467 if (iap->ia_valid & ATTR_SIZE)
469 if (iap->ia_valid & ATTR_MODE)
471 if (iap->ia_valid & ATTR_UID) {
472 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
473 if (owner_namelen < 0) {
474 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
477 strcpy(owner_name, "nobody");
478 owner_namelen = sizeof("nobody") - 1;
481 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
483 if (iap->ia_valid & ATTR_GID) {
484 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
485 if (owner_grouplen < 0) {
486 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
488 strcpy(owner_group, "nobody");
489 owner_grouplen = sizeof("nobody") - 1;
492 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
494 if (iap->ia_valid & ATTR_ATIME_SET)
496 else if (iap->ia_valid & ATTR_ATIME)
498 if (iap->ia_valid & ATTR_MTIME_SET)
500 else if (iap->ia_valid & ATTR_MTIME)
505 * We write the bitmap length now, but leave the bitmap and the attribute
506 * buffer length to be backfilled at the end of this routine.
512 if (iap->ia_valid & ATTR_SIZE) {
513 bmval0 |= FATTR4_WORD0_SIZE;
514 WRITE64(iap->ia_size);
516 if (iap->ia_valid & ATTR_MODE) {
517 bmval1 |= FATTR4_WORD1_MODE;
518 WRITE32(iap->ia_mode);
520 if (iap->ia_valid & ATTR_UID) {
521 bmval1 |= FATTR4_WORD1_OWNER;
522 WRITE32(owner_namelen);
523 WRITEMEM(owner_name, owner_namelen);
525 if (iap->ia_valid & ATTR_GID) {
526 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
527 WRITE32(owner_grouplen);
528 WRITEMEM(owner_group, owner_grouplen);
530 if (iap->ia_valid & ATTR_ATIME_SET) {
531 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
532 WRITE32(NFS4_SET_TO_CLIENT_TIME);
534 WRITE32(iap->ia_mtime.tv_sec);
535 WRITE32(iap->ia_mtime.tv_nsec);
537 else if (iap->ia_valid & ATTR_ATIME) {
538 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
539 WRITE32(NFS4_SET_TO_SERVER_TIME);
541 if (iap->ia_valid & ATTR_MTIME_SET) {
542 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
543 WRITE32(NFS4_SET_TO_CLIENT_TIME);
545 WRITE32(iap->ia_mtime.tv_sec);
546 WRITE32(iap->ia_mtime.tv_nsec);
548 else if (iap->ia_valid & ATTR_MTIME) {
549 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
550 WRITE32(NFS4_SET_TO_SERVER_TIME);
554 * Now we backfill the bitmap and the attribute buffer length.
556 if (len != ((char *)p - (char *)q) + 4) {
557 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
558 len, ((char *)p - (char *)q) + 4);
561 len = (char *)p - (char *)q - 12;
562 *q++ = htonl(bmval0);
563 *q++ = htonl(bmval1);
571 static int encode_access(struct xdr_stream *xdr, u32 access)
582 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
586 RESERVE_SPACE(8+sizeof(arg->stateid.data));
589 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
594 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
600 WRITE64(args->offset);
601 WRITE32(args->count);
606 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
612 WRITE32(create->ftype);
614 switch (create->ftype) {
616 RESERVE_SPACE(4 + create->u.symlink->len);
617 WRITE32(create->u.symlink->len);
618 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
621 case NF4BLK: case NF4CHR:
623 WRITE32(create->u.device.specdata1);
624 WRITE32(create->u.device.specdata2);
631 RESERVE_SPACE(4 + create->name->len);
632 WRITE32(create->name->len);
633 WRITEMEM(create->name->name, create->name->len);
635 return encode_attrs(xdr, create->attrs, create->server);
638 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
649 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
661 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
663 extern u32 nfs4_fattr_bitmap[];
665 return encode_getattr_two(xdr,
666 bitmask[0] & nfs4_fattr_bitmap[0],
667 bitmask[1] & nfs4_fattr_bitmap[1]);
670 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
672 extern u32 nfs4_fsinfo_bitmap[];
674 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
675 bitmask[1] & nfs4_fsinfo_bitmap[1]);
678 static int encode_getfh(struct xdr_stream *xdr)
688 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
692 RESERVE_SPACE(8 + name->len);
695 WRITEMEM(name->name, name->len);
701 * opcode,type,reclaim,offset,length,new_lock_owner = 32
702 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
704 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
707 struct nfs_lock_opargs *opargs = arg->u.lock;
712 WRITE32(opargs->reclaim);
713 WRITE64(arg->offset);
714 WRITE64(arg->length);
715 WRITE32(opargs->new_lock_owner);
716 if (opargs->new_lock_owner){
717 struct nfs_open_to_lock *ol = opargs->u.open_lock;
720 WRITE32(ol->open_seqid);
721 WRITEMEM(&ol->open_stateid, sizeof(ol->open_stateid));
722 WRITE32(ol->lock_seqid);
723 WRITE64(ol->lock_owner.clientid);
725 WRITE32(ol->lock_owner.id);
728 struct nfs_exist_lock *el = opargs->u.exist_lock;
731 WRITEMEM(&el->stateid, sizeof(el->stateid));
738 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
741 struct nfs_lowner *opargs = arg->u.lockt;
746 WRITE64(arg->offset);
747 WRITE64(arg->length);
748 WRITE64(opargs->clientid);
755 static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
758 struct nfs_locku_opargs *opargs = arg->u.locku;
763 WRITE32(opargs->seqid);
764 WRITEMEM(&opargs->stateid, sizeof(opargs->stateid));
765 WRITE64(arg->offset);
766 WRITE64(arg->length);
771 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
776 RESERVE_SPACE(8 + len);
779 WRITEMEM(name->name, len);
784 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
789 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
791 WRITE32(NFS4_SHARE_ACCESS_READ);
794 WRITE32(NFS4_SHARE_ACCESS_WRITE);
796 case FMODE_READ|FMODE_WRITE:
797 WRITE32(NFS4_SHARE_ACCESS_BOTH);
802 WRITE32(0); /* for linux, share_deny = 0 always */
805 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
809 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
815 encode_share_access(xdr, arg->open_flags);
817 WRITE64(arg->clientid);
822 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
827 switch(arg->open_flags & O_EXCL) {
829 WRITE32(NFS4_CREATE_UNCHECKED);
830 encode_attrs(xdr, arg->u.attrs, arg->server);
833 WRITE32(NFS4_CREATE_EXCLUSIVE);
834 encode_nfs4_verifier(xdr, &arg->u.verifier);
838 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
843 switch (arg->open_flags & O_CREAT) {
845 WRITE32(NFS4_OPEN_NOCREATE);
848 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
849 WRITE32(NFS4_OPEN_CREATE);
850 encode_createmode(xdr, arg);
854 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
859 switch (delegation_type) {
861 WRITE32(NFS4_OPEN_DELEGATE_NONE);
864 WRITE32(NFS4_OPEN_DELEGATE_READ);
866 case FMODE_WRITE|FMODE_READ:
867 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
874 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
879 WRITE32(NFS4_OPEN_CLAIM_NULL);
880 encode_string(xdr, name->len, name->name);
883 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
888 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
889 encode_delegation_type(xdr, type);
892 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
896 RESERVE_SPACE(4+sizeof(stateid->data));
897 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
898 WRITEMEM(stateid->data, sizeof(stateid->data));
899 encode_string(xdr, name->len, name->name);
902 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
904 encode_openhdr(xdr, arg);
905 encode_opentype(xdr, arg);
906 switch (arg->claim) {
907 case NFS4_OPEN_CLAIM_NULL:
908 encode_claim_null(xdr, arg->name);
910 case NFS4_OPEN_CLAIM_PREVIOUS:
911 encode_claim_previous(xdr, arg->u.delegation_type);
913 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
914 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
922 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
926 RESERVE_SPACE(8+sizeof(arg->stateid.data));
927 WRITE32(OP_OPEN_CONFIRM);
928 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
934 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
938 RESERVE_SPACE(8+sizeof(arg->stateid.data));
939 WRITE32(OP_OPEN_DOWNGRADE);
940 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
942 encode_share_access(xdr, arg->open_flags);
947 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
952 RESERVE_SPACE(8 + len);
955 WRITEMEM(fh->data, len);
960 static int encode_putrootfh(struct xdr_stream *xdr)
965 WRITE32(OP_PUTROOTFH);
970 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
972 extern nfs4_stateid zero_stateid;
973 nfs4_stateid stateid;
977 if (ctx->state != NULL) {
978 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
979 WRITEMEM(stateid.data, sizeof(stateid.data));
981 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
984 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
991 encode_stateid(xdr, args->context);
994 WRITE64(args->offset);
995 WRITE32(args->count);
1000 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1002 struct rpc_auth *auth = req->rq_task->tk_auth;
1006 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1007 WRITE32(OP_READDIR);
1008 WRITE64(readdir->cookie);
1009 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1010 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1011 WRITE32(readdir->count);
1013 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) {
1015 WRITE32(FATTR4_WORD1_MOUNTED_ON_FILEID);
1017 WRITE32(FATTR4_WORD0_FILEID);
1021 /* set up reply kvec
1022 * toplevel_status + taglen + rescount + OP_PUTFH + status
1023 * + OP_READDIR + status + verifer(2) = 9
1025 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1026 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1027 readdir->pgbase, readdir->count);
1032 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1034 struct rpc_auth *auth = req->rq_task->tk_auth;
1035 unsigned int replen;
1039 WRITE32(OP_READLINK);
1041 /* set up reply kvec
1042 * toplevel_status + taglen + rescount + OP_PUTFH + status
1043 * + OP_READLINK + status + string length = 8
1045 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1046 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1047 readlink->pgbase, readlink->pglen);
1052 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1056 RESERVE_SPACE(8 + name->len);
1059 WRITEMEM(name->name, name->len);
1064 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1068 RESERVE_SPACE(8 + oldname->len);
1070 WRITE32(oldname->len);
1071 WRITEMEM(oldname->name, oldname->len);
1073 RESERVE_SPACE(4 + newname->len);
1074 WRITE32(newname->len);
1075 WRITEMEM(newname->name, newname->len);
1080 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1086 WRITE64(client_stateid->cl_clientid);
1092 encode_savefh(struct xdr_stream *xdr)
1102 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1107 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1108 WRITE32(OP_SETATTR);
1109 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1111 if ((status = encode_attrs(xdr, arg->iap, server)))
1117 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1121 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1122 WRITE32(OP_SETCLIENTID);
1123 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1125 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1127 WRITE32(setclientid->sc_prog);
1128 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1129 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1131 WRITE32(setclientid->sc_cb_ident);
1136 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1140 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1141 WRITE32(OP_SETCLIENTID_CONFIRM);
1142 WRITE64(client_state->cl_clientid);
1143 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1148 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1155 encode_stateid(xdr, args->context);
1158 WRITE64(args->offset);
1159 WRITE32(args->stable);
1160 WRITE32(args->count);
1162 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1167 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1173 WRITE32(OP_DELEGRETURN);
1174 WRITEMEM(stateid->data, sizeof(stateid->data));
1179 * END OF "GENERIC" ENCODE ROUTINES.
1183 * Encode an ACCESS request
1185 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1187 struct xdr_stream xdr;
1188 struct compound_hdr hdr = {
1193 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1194 encode_compound_hdr(&xdr, &hdr);
1195 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1196 status = encode_access(&xdr, args->access);
1201 * Encode LOOKUP request
1203 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1205 struct xdr_stream xdr;
1206 struct compound_hdr hdr = {
1211 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1212 encode_compound_hdr(&xdr, &hdr);
1213 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1215 if ((status = encode_lookup(&xdr, args->name)) != 0)
1217 if ((status = encode_getfh(&xdr)) != 0)
1219 status = encode_getfattr(&xdr, args->bitmask);
1225 * Encode LOOKUP_ROOT request
1227 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1229 struct xdr_stream xdr;
1230 struct compound_hdr hdr = {
1235 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1236 encode_compound_hdr(&xdr, &hdr);
1237 if ((status = encode_putrootfh(&xdr)) != 0)
1239 if ((status = encode_getfh(&xdr)) == 0)
1240 status = encode_getfattr(&xdr, args->bitmask);
1246 * Encode REMOVE request
1248 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1250 struct xdr_stream xdr;
1251 struct compound_hdr hdr = {
1256 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1257 encode_compound_hdr(&xdr, &hdr);
1258 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1259 status = encode_remove(&xdr, args->name);
1264 * Encode RENAME request
1266 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1268 struct xdr_stream xdr;
1269 struct compound_hdr hdr = {
1274 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1275 encode_compound_hdr(&xdr, &hdr);
1276 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1278 if ((status = encode_savefh(&xdr)) != 0)
1280 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1282 status = encode_rename(&xdr, args->old_name, args->new_name);
1288 * Encode LINK request
1290 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1292 struct xdr_stream xdr;
1293 struct compound_hdr hdr = {
1298 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1299 encode_compound_hdr(&xdr, &hdr);
1300 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1302 if ((status = encode_savefh(&xdr)) != 0)
1304 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1306 status = encode_link(&xdr, args->name);
1312 * Encode CREATE request
1314 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1316 struct xdr_stream xdr;
1317 struct compound_hdr hdr = {
1322 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1323 encode_compound_hdr(&xdr, &hdr);
1324 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1326 if ((status = encode_create(&xdr, args)) != 0)
1328 if ((status = encode_getfh(&xdr)) != 0)
1330 status = encode_getfattr(&xdr, args->bitmask);
1336 * Encode SYMLINK request
1338 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1340 return nfs4_xdr_enc_create(req, p, args);
1344 * Encode GETATTR request
1346 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1348 struct xdr_stream xdr;
1349 struct compound_hdr hdr = {
1354 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1355 encode_compound_hdr(&xdr, &hdr);
1356 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1357 status = encode_getfattr(&xdr, args->bitmask);
1362 * Encode a CLOSE request
1364 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1366 struct xdr_stream xdr;
1367 struct compound_hdr hdr = {
1372 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1373 encode_compound_hdr(&xdr, &hdr);
1374 status = encode_putfh(&xdr, args->fh);
1377 status = encode_close(&xdr, args);
1383 * Encode an OPEN request
1385 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1387 struct xdr_stream xdr;
1388 struct compound_hdr hdr = {
1393 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1394 encode_compound_hdr(&xdr, &hdr);
1395 status = encode_putfh(&xdr, args->fh);
1398 status = encode_open(&xdr, args);
1401 status = encode_getfh(&xdr);
1404 status = encode_getfattr(&xdr, args->bitmask);
1410 * Encode an OPEN_CONFIRM request
1412 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1414 struct xdr_stream xdr;
1415 struct compound_hdr hdr = {
1420 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1421 encode_compound_hdr(&xdr, &hdr);
1422 status = encode_putfh(&xdr, args->fh);
1425 status = encode_open_confirm(&xdr, args);
1431 * Encode an OPEN request with no attributes.
1433 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1435 struct xdr_stream xdr;
1436 struct compound_hdr hdr = {
1441 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1442 encode_compound_hdr(&xdr, &hdr);
1443 status = encode_putfh(&xdr, args->fh);
1446 status = encode_open(&xdr, args);
1452 * Encode an OPEN_DOWNGRADE request
1454 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1456 struct xdr_stream xdr;
1457 struct compound_hdr hdr = {
1462 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1463 encode_compound_hdr(&xdr, &hdr);
1464 status = encode_putfh(&xdr, args->fh);
1467 status = encode_open_downgrade(&xdr, args);
1473 * Encode a LOCK request
1475 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1477 struct xdr_stream xdr;
1478 struct compound_hdr hdr = {
1483 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1484 encode_compound_hdr(&xdr, &hdr);
1485 status = encode_putfh(&xdr, args->fh);
1488 status = encode_lock(&xdr, args);
1494 * Encode a LOCKT request
1496 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1498 struct xdr_stream xdr;
1499 struct compound_hdr hdr = {
1504 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1505 encode_compound_hdr(&xdr, &hdr);
1506 status = encode_putfh(&xdr, args->fh);
1509 status = encode_lockt(&xdr, args);
1515 * Encode a LOCKU request
1517 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1519 struct xdr_stream xdr;
1520 struct compound_hdr hdr = {
1525 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1526 encode_compound_hdr(&xdr, &hdr);
1527 status = encode_putfh(&xdr, args->fh);
1530 status = encode_locku(&xdr, args);
1536 * Encode a READLINK request
1538 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1540 struct xdr_stream xdr;
1541 struct compound_hdr hdr = {
1546 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1547 encode_compound_hdr(&xdr, &hdr);
1548 status = encode_putfh(&xdr, args->fh);
1551 status = encode_readlink(&xdr, args, req);
1557 * Encode a READDIR request
1559 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1561 struct xdr_stream xdr;
1562 struct compound_hdr hdr = {
1567 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1568 encode_compound_hdr(&xdr, &hdr);
1569 status = encode_putfh(&xdr, args->fh);
1572 status = encode_readdir(&xdr, args, req);
1578 * Encode a READ request
1580 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1582 struct rpc_auth *auth = req->rq_task->tk_auth;
1583 struct xdr_stream xdr;
1584 struct compound_hdr hdr = {
1589 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1590 encode_compound_hdr(&xdr, &hdr);
1591 status = encode_putfh(&xdr, args->fh);
1594 status = encode_read(&xdr, args);
1598 /* set up reply kvec
1599 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1600 * + OP_READ + status + eof + datalen = 9
1602 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1603 xdr_inline_pages(&req->rq_rcv_buf, replen,
1604 args->pages, args->pgbase, args->count);
1610 * Encode an SETATTR request
1612 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1615 struct xdr_stream xdr;
1616 struct compound_hdr hdr = {
1621 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1622 encode_compound_hdr(&xdr, &hdr);
1623 status = encode_putfh(&xdr, args->fh);
1626 status = encode_setattr(&xdr, args, args->server);
1629 status = encode_getfattr(&xdr, args->bitmask);
1635 * Encode a WRITE request
1637 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1639 struct xdr_stream xdr;
1640 struct compound_hdr hdr = {
1645 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1646 encode_compound_hdr(&xdr, &hdr);
1647 status = encode_putfh(&xdr, args->fh);
1650 status = encode_write(&xdr, args);
1658 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1660 struct xdr_stream xdr;
1661 struct compound_hdr hdr = {
1666 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1667 encode_compound_hdr(&xdr, &hdr);
1668 status = encode_putfh(&xdr, args->fh);
1671 status = encode_commit(&xdr, args);
1679 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1681 struct xdr_stream xdr;
1682 struct compound_hdr hdr = {
1687 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1688 encode_compound_hdr(&xdr, &hdr);
1689 status = encode_putfh(&xdr, args->fh);
1691 status = encode_fsinfo(&xdr, args->bitmask);
1696 * a PATHCONF request
1698 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1700 extern u32 nfs4_pathconf_bitmap[2];
1701 struct xdr_stream xdr;
1702 struct compound_hdr hdr = {
1707 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1708 encode_compound_hdr(&xdr, &hdr);
1709 status = encode_putfh(&xdr, args->fh);
1711 status = encode_getattr_one(&xdr,
1712 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1719 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1721 extern u32 nfs4_statfs_bitmap[];
1722 struct xdr_stream xdr;
1723 struct compound_hdr hdr = {
1728 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1729 encode_compound_hdr(&xdr, &hdr);
1730 status = encode_putfh(&xdr, args->fh);
1732 status = encode_getattr_two(&xdr,
1733 args->bitmask[0] & nfs4_statfs_bitmap[0],
1734 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1739 * GETATTR_BITMAP request
1741 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1743 struct xdr_stream xdr;
1744 struct compound_hdr hdr = {
1749 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1750 encode_compound_hdr(&xdr, &hdr);
1751 status = encode_putfh(&xdr, fhandle);
1753 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1754 FATTR4_WORD0_LINK_SUPPORT|
1755 FATTR4_WORD0_SYMLINK_SUPPORT|
1756 FATTR4_WORD0_ACLSUPPORT);
1763 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1765 struct xdr_stream xdr;
1766 struct compound_hdr hdr = {
1770 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1771 encode_compound_hdr(&xdr, &hdr);
1772 return encode_renew(&xdr, clp);
1776 * a SETCLIENTID request
1778 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1780 struct xdr_stream xdr;
1781 struct compound_hdr hdr = {
1785 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1786 encode_compound_hdr(&xdr, &hdr);
1787 return encode_setclientid(&xdr, sc);
1791 * a SETCLIENTID_CONFIRM request
1793 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1795 struct xdr_stream xdr;
1796 struct compound_hdr hdr = {
1799 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1802 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1803 encode_compound_hdr(&xdr, &hdr);
1804 status = encode_setclientid_confirm(&xdr, clp);
1806 status = encode_putrootfh(&xdr);
1808 status = encode_fsinfo(&xdr, lease_bitmap);
1813 * DELEGRETURN request
1815 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1817 struct xdr_stream xdr;
1818 struct compound_hdr hdr = {
1823 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1824 encode_compound_hdr(&xdr, &hdr);
1825 if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
1826 status = encode_delegreturn(&xdr, args->stateid);
1831 * START OF "GENERIC" DECODE ROUTINES.
1832 * These may look a little ugly since they are imported from a "generic"
1833 * set of XDR encode/decode routines which are intended to be shared by
1834 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1836 * If the pain of reading these is too great, it should be a straightforward
1837 * task to translate them into Linux-specific versions which are more
1838 * consistent with the style used in NFSv2/v3...
1840 #define READ32(x) (x) = ntohl(*p++)
1841 #define READ64(x) do { \
1842 (x) = (u64)ntohl(*p++) << 32; \
1843 (x) |= ntohl(*p++); \
1845 #define READTIME(x) do { \
1847 (x.tv_sec) = ntohl(*p++); \
1848 (x.tv_nsec) = ntohl(*p++); \
1850 #define COPYMEM(x,nbytes) do { \
1851 memcpy((x), p, nbytes); \
1852 p += XDR_QUADLEN(nbytes); \
1855 #define READ_BUF(nbytes) do { \
1856 p = xdr_inline_decode(xdr, nbytes); \
1858 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
1859 __FUNCTION__, __LINE__); \
1864 static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
1871 *string = (char *)p;
1875 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
1880 READ32(hdr->status);
1881 READ32(hdr->taglen);
1883 READ_BUF(hdr->taglen + 4);
1884 hdr->tag = (char *)p;
1885 p += XDR_QUADLEN(hdr->taglen);
1890 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
1898 if (opnum != expected) {
1900 "nfs4_decode_op_hdr: Server returned operation"
1901 " %d but we issued a request for %d\n",
1906 if (nfserr != NFS_OK)
1907 return -nfs_stat_to_errno(nfserr);
1912 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
1919 return decode_opaque_inline(xdr, &strlen, &str);
1922 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
1929 bitmap[0] = bitmap[1] = 0;
1930 READ_BUF((bmlen << 2));
1939 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
1949 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
1951 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
1952 decode_attr_bitmap(xdr, bitmask);
1953 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
1955 bitmask[0] = bitmask[1] = 0;
1956 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
1960 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
1965 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
1967 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
1970 if (*type < NF4REG || *type > NF4NAMEDATTR) {
1971 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
1974 bitmap[0] &= ~FATTR4_WORD0_TYPE;
1976 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
1980 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
1985 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
1987 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
1990 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
1992 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
1993 (unsigned long long)*change);
1997 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2002 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2004 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2007 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2009 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2013 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2018 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2020 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2023 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2025 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2029 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2034 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2036 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2039 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2041 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2045 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2051 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2053 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2055 READ64(fsid->major);
2056 READ64(fsid->minor);
2057 bitmap[0] &= ~FATTR4_WORD0_FSID;
2059 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2060 (unsigned long long)fsid->major,
2061 (unsigned long long)fsid->minor);
2065 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2070 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2072 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2075 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2077 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2081 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2085 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2086 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2088 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2091 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2093 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2097 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2102 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2104 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2107 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2109 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2113 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2119 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2121 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2124 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2126 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2130 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2136 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2138 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2141 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2143 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2147 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2153 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2155 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2158 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2160 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2164 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2170 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2172 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2175 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2177 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2181 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2187 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2189 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2192 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2194 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2198 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2204 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2206 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2209 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2211 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2215 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2221 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2223 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2227 if (maxread > 0x7FFFFFFF)
2228 maxread = 0x7FFFFFFF;
2229 *res = (uint32_t)maxread;
2230 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2232 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2236 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2242 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2244 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2248 if (maxwrite > 0x7FFFFFFF)
2249 maxwrite = 0x7FFFFFFF;
2250 *res = (uint32_t)maxwrite;
2251 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2253 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2257 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2262 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2264 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2268 bitmap[1] &= ~FATTR4_WORD1_MODE;
2270 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2274 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2279 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2281 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2284 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2286 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2290 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2295 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2297 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2301 if (len < XDR_MAX_NETOBJ) {
2302 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2303 dprintk("%s: nfs_map_name_to_uid failed!\n",
2306 printk(KERN_WARNING "%s: name too long (%u)!\n",
2308 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2310 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2314 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2319 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2321 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2325 if (len < XDR_MAX_NETOBJ) {
2326 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2327 dprintk("%s: nfs_map_group_to_gid failed!\n",
2330 printk(KERN_WARNING "%s: name too long (%u)!\n",
2332 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2334 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2338 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2340 uint32_t major = 0, minor = 0, *p;
2343 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2345 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2351 tmp = MKDEV(major, minor);
2352 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2354 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2356 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2360 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2366 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2368 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2371 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2373 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2377 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2383 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2385 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2388 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2390 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2394 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2400 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2402 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2405 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2407 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2411 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2416 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2418 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2421 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2423 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2424 (unsigned long long)*used);
2428 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2437 time->tv_sec = (time_t)sec;
2438 time->tv_nsec = (long)nsec;
2442 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2448 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2450 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2451 status = decode_attr_time(xdr, time);
2452 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2454 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2458 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2464 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2466 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2467 status = decode_attr_time(xdr, time);
2468 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2470 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2474 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2480 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2482 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2483 status = decode_attr_time(xdr, time);
2484 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2486 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2490 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2492 unsigned int attrwords = XDR_QUADLEN(attrlen);
2493 unsigned int nwords = xdr->p - savep;
2495 if (unlikely(attrwords != nwords)) {
2496 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2499 (attrwords < nwords) ? '<' : '>',
2506 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2511 READ32(cinfo->atomic);
2512 READ64(cinfo->before);
2513 READ64(cinfo->after);
2517 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2523 status = decode_op_hdr(xdr, OP_ACCESS);
2529 access->supported = supp;
2530 access->access = acc;
2534 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2539 status = decode_op_hdr(xdr, OP_CLOSE);
2542 READ_BUF(sizeof(res->stateid.data));
2543 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2547 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2552 status = decode_op_hdr(xdr, OP_COMMIT);
2556 COPYMEM(res->verf->verifier, 8);
2560 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2566 status = decode_op_hdr(xdr, OP_CREATE);
2569 if ((status = decode_change_info(xdr, cinfo)))
2573 READ_BUF(bmlen << 2);
2577 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2584 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2586 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2588 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2590 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2592 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2594 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2596 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2598 status = verify_attr_len(xdr, savep, attrlen);
2601 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2605 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2612 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2614 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2616 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2619 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2621 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2623 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2625 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2627 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2629 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2632 status = verify_attr_len(xdr, savep, attrlen);
2635 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2639 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2646 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2648 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2650 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2653 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2655 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2658 status = verify_attr_len(xdr, savep, attrlen);
2661 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2665 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2671 int status, fmode = 0;
2673 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2675 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2678 fattr->bitmap[0] = bitmap[0];
2679 fattr->bitmap[1] = bitmap[1];
2681 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2685 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2687 fattr->type = nfs_type2fmt[type].nfs2type;
2688 fmode = nfs_type2fmt[type].mode;
2690 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2692 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2694 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2696 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2698 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2700 fattr->mode |= fmode;
2701 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2703 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2705 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2707 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2709 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2711 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2713 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2715 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2717 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) {
2718 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2719 fattr->timestamp = jiffies;
2723 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2728 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2731 uint32_t attrlen, bitmap[2];
2734 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2736 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2738 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2741 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2743 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2745 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2747 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2749 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2750 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2752 fsinfo->wtpref = fsinfo->wtmax;
2754 status = verify_attr_len(xdr, savep, attrlen);
2757 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2761 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2767 status = decode_op_hdr(xdr, OP_GETFH);
2770 /* Zero handle first to allow comparisons */
2771 memset(fh, 0, sizeof(*fh));
2775 if (len > NFS4_FHSIZE)
2779 COPYMEM(fh->data, len);
2783 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2787 status = decode_op_hdr(xdr, OP_LINK);
2790 return decode_change_info(xdr, cinfo);
2794 * We create the owner, so we know a proper owner.id length is 4.
2796 static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2802 READ64(denied->offset);
2803 READ64(denied->length);
2804 READ32(denied->type);
2805 READ64(denied->owner.clientid);
2809 READ32(denied->owner.id);
2810 return -NFS4ERR_DENIED;
2813 static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2818 status = decode_op_hdr(xdr, OP_LOCK);
2820 READ_BUF(sizeof(nfs4_stateid));
2821 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2822 } else if (status == -NFS4ERR_DENIED)
2823 return decode_lock_denied(xdr, &res->u.denied);
2827 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2830 status = decode_op_hdr(xdr, OP_LOCKT);
2831 if (status == -NFS4ERR_DENIED)
2832 return decode_lock_denied(xdr, &res->u.denied);
2836 static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2841 status = decode_op_hdr(xdr, OP_LOCKU);
2843 READ_BUF(sizeof(nfs4_stateid));
2844 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2849 static int decode_lookup(struct xdr_stream *xdr)
2851 return decode_op_hdr(xdr, OP_LOOKUP);
2854 /* This is too sick! */
2855 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
2858 uint32_t limit_type, nblocks, blocksize;
2862 switch (limit_type) {
2869 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
2874 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
2877 uint32_t delegation_type;
2880 READ32(delegation_type);
2881 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
2882 res->delegation_type = 0;
2886 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
2887 READ32(res->do_recall);
2888 switch (delegation_type) {
2889 case NFS4_OPEN_DELEGATE_READ:
2890 res->delegation_type = FMODE_READ;
2892 case NFS4_OPEN_DELEGATE_WRITE:
2893 res->delegation_type = FMODE_WRITE|FMODE_READ;
2894 if (decode_space_limit(xdr, &res->maxsize) < 0)
2897 return decode_ace(xdr, NULL, res->server->nfs4_state);
2900 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
2906 status = decode_op_hdr(xdr, OP_OPEN);
2909 READ_BUF(sizeof(res->stateid.data));
2910 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2912 decode_change_info(xdr, &res->cinfo);
2915 READ32(res->rflags);
2920 READ_BUF(bmlen << 2);
2922 return decode_delegation(xdr, res);
2924 printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
2928 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
2933 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
2936 READ_BUF(sizeof(res->stateid.data));
2937 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2941 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
2946 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
2949 READ_BUF(sizeof(res->stateid.data));
2950 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2954 static int decode_putfh(struct xdr_stream *xdr)
2956 return decode_op_hdr(xdr, OP_PUTFH);
2959 static int decode_putrootfh(struct xdr_stream *xdr)
2961 return decode_op_hdr(xdr, OP_PUTROOTFH);
2964 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
2966 struct kvec *iov = req->rq_rcv_buf.head;
2968 uint32_t count, eof, recvd, hdrlen;
2971 status = decode_op_hdr(xdr, OP_READ);
2977 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
2978 recvd = req->rq_rcv_buf.len - hdrlen;
2979 if (count > recvd) {
2980 printk(KERN_WARNING "NFS: server cheating in read reply: "
2981 "count %u > recvd %u\n", count, recvd);
2985 xdr_read_pages(xdr, count);
2991 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
2993 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
2994 struct page *page = *rcvbuf->pages;
2995 struct kvec *iov = rcvbuf->head;
2996 unsigned int nr, pglen = rcvbuf->page_len;
2997 uint32_t *end, *entry, *p, *kaddr;
2998 uint32_t len, attrlen;
2999 int hdrlen, recvd, status;
3001 status = decode_op_hdr(xdr, OP_READDIR);
3005 COPYMEM(readdir->verifier.data, 8);
3007 hdrlen = (char *) p - (char *) iov->iov_base;
3008 recvd = rcvbuf->len - hdrlen;
3011 xdr_read_pages(xdr, pglen);
3013 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3014 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3015 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3017 for (nr = 0; *p++; nr++) {
3020 p += 2; /* cookie */
3021 len = ntohl(*p++); /* filename length */
3022 if (len > NFS4_MAXNAMLEN) {
3023 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3026 p += XDR_QUADLEN(len);
3029 len = ntohl(*p++); /* bitmap length */
3033 attrlen = XDR_QUADLEN(ntohl(*p++));
3034 p += attrlen; /* attributes */
3039 if (!nr && (entry[0] != 0 || entry[1] == 0))
3042 kunmap_atomic(kaddr, KM_USER0);
3045 entry[0] = entry[1] = 0;
3046 /* truncate listing ? */
3048 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3053 kunmap_atomic(kaddr, KM_USER0);
3054 return -errno_NFSERR_IO;
3057 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3059 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3060 struct kvec *iov = rcvbuf->head;
3061 int hdrlen, len, recvd;
3066 status = decode_op_hdr(xdr, OP_READLINK);
3070 /* Convert length of symlink */
3073 if (len >= rcvbuf->page_len || len <= 0) {
3074 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3075 return -ENAMETOOLONG;
3077 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3078 recvd = req->rq_rcv_buf.len - hdrlen;
3080 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3081 "count %u > recvd %u\n", len, recvd);
3084 xdr_read_pages(xdr, len);
3086 * The XDR encode routine has set things up so that
3087 * the link text will be copied directly into the
3088 * buffer. We just have to do overflow-checking,
3089 * and and null-terminate the text (the VFS expects
3090 * null-termination).
3092 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3093 kaddr[len+rcvbuf->page_base] = '\0';
3094 kunmap_atomic(kaddr, KM_USER0);
3098 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3102 status = decode_op_hdr(xdr, OP_REMOVE);
3105 status = decode_change_info(xdr, cinfo);
3110 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3111 struct nfs4_change_info *new_cinfo)
3115 status = decode_op_hdr(xdr, OP_RENAME);
3118 if ((status = decode_change_info(xdr, old_cinfo)))
3120 status = decode_change_info(xdr, new_cinfo);
3125 static int decode_renew(struct xdr_stream *xdr)
3127 return decode_op_hdr(xdr, OP_RENEW);
3131 decode_savefh(struct xdr_stream *xdr)
3133 return decode_op_hdr(xdr, OP_SAVEFH);
3136 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3143 status = decode_op_hdr(xdr, OP_SETATTR);
3148 READ_BUF(bmlen << 2);
3152 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3160 if (opnum != OP_SETCLIENTID) {
3162 "nfs4_decode_setclientid: Server returned operation"
3167 if (nfserr == NFS_OK) {
3168 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3169 READ64(clp->cl_clientid);
3170 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3171 } else if (nfserr == NFSERR_CLID_INUSE) {
3174 /* skip netid string */
3179 /* skip uaddr string */
3183 return -NFSERR_CLID_INUSE;
3185 return -nfs_stat_to_errno(nfserr);
3190 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3192 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3195 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3200 status = decode_op_hdr(xdr, OP_WRITE);
3206 READ32(res->verf->committed);
3207 COPYMEM(res->verf->verifier, 8);
3211 static int decode_delegreturn(struct xdr_stream *xdr)
3213 return decode_op_hdr(xdr, OP_DELEGRETURN);
3217 * Decode OPEN_DOWNGRADE response
3219 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3221 struct xdr_stream xdr;
3222 struct compound_hdr hdr;
3225 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3226 status = decode_compound_hdr(&xdr, &hdr);
3229 status = decode_putfh(&xdr);
3232 status = decode_open_downgrade(&xdr, res);
3238 * END OF "GENERIC" DECODE ROUTINES.
3242 * Decode ACCESS response
3244 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3246 struct xdr_stream xdr;
3247 struct compound_hdr hdr;
3250 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3251 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3253 if ((status = decode_putfh(&xdr)) == 0)
3254 status = decode_access(&xdr, res);
3260 * Decode LOOKUP response
3262 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3264 struct xdr_stream xdr;
3265 struct compound_hdr hdr;
3268 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3269 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3271 if ((status = decode_putfh(&xdr)) != 0)
3273 if ((status = decode_lookup(&xdr)) != 0)
3275 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3277 status = decode_getfattr(&xdr, res->fattr, res->server);
3283 * Decode LOOKUP_ROOT response
3285 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3287 struct xdr_stream xdr;
3288 struct compound_hdr hdr;
3291 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3292 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3294 if ((status = decode_putrootfh(&xdr)) != 0)
3296 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3297 status = decode_getfattr(&xdr, res->fattr, res->server);
3303 * Decode REMOVE response
3305 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3307 struct xdr_stream xdr;
3308 struct compound_hdr hdr;
3311 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3312 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3314 if ((status = decode_putfh(&xdr)) == 0)
3315 status = decode_remove(&xdr, cinfo);
3321 * Decode RENAME response
3323 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3325 struct xdr_stream xdr;
3326 struct compound_hdr hdr;
3329 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3330 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3332 if ((status = decode_putfh(&xdr)) != 0)
3334 if ((status = decode_savefh(&xdr)) != 0)
3336 if ((status = decode_putfh(&xdr)) != 0)
3338 status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
3344 * Decode LINK response
3346 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3348 struct xdr_stream xdr;
3349 struct compound_hdr hdr;
3352 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3353 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3355 if ((status = decode_putfh(&xdr)) != 0)
3357 if ((status = decode_savefh(&xdr)) != 0)
3359 if ((status = decode_putfh(&xdr)) != 0)
3361 status = decode_link(&xdr, cinfo);
3367 * Decode CREATE response
3369 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3371 struct xdr_stream xdr;
3372 struct compound_hdr hdr;
3375 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3376 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3378 if ((status = decode_putfh(&xdr)) != 0)
3380 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3382 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3384 status = decode_getfattr(&xdr, res->fattr, res->server);
3385 if (status == NFS4ERR_DELAY)
3392 * Decode SYMLINK response
3394 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3396 return nfs4_xdr_dec_create(rqstp, p, res);
3400 * Decode GETATTR response
3402 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3404 struct xdr_stream xdr;
3405 struct compound_hdr hdr;
3408 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3409 status = decode_compound_hdr(&xdr, &hdr);
3412 status = decode_putfh(&xdr);
3415 status = decode_getfattr(&xdr, res->fattr, res->server);
3423 * Decode CLOSE response
3425 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3427 struct xdr_stream xdr;
3428 struct compound_hdr hdr;
3431 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3432 status = decode_compound_hdr(&xdr, &hdr);
3435 status = decode_putfh(&xdr);
3438 status = decode_close(&xdr, res);
3444 * Decode OPEN response
3446 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3448 struct xdr_stream xdr;
3449 struct compound_hdr hdr;
3452 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3453 status = decode_compound_hdr(&xdr, &hdr);
3456 status = decode_putfh(&xdr);
3459 status = decode_open(&xdr, res);
3462 status = decode_getfh(&xdr, &res->fh);
3465 status = decode_getfattr(&xdr, res->f_attr, res->server);
3466 if (status == NFS4ERR_DELAY)
3473 * Decode OPEN_CONFIRM response
3475 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3477 struct xdr_stream xdr;
3478 struct compound_hdr hdr;
3481 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3482 status = decode_compound_hdr(&xdr, &hdr);
3485 status = decode_putfh(&xdr);
3488 status = decode_open_confirm(&xdr, res);
3494 * Decode OPEN response
3496 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3498 struct xdr_stream xdr;
3499 struct compound_hdr hdr;
3502 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3503 status = decode_compound_hdr(&xdr, &hdr);
3506 status = decode_putfh(&xdr);
3509 status = decode_open(&xdr, res);
3515 * Decode SETATTR response
3517 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3519 struct xdr_stream xdr;
3520 struct compound_hdr hdr;
3523 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3524 status = decode_compound_hdr(&xdr, &hdr);
3527 status = decode_putfh(&xdr);
3530 status = decode_setattr(&xdr, res);
3533 status = decode_getfattr(&xdr, res->fattr, res->server);
3534 if (status == NFS4ERR_DELAY)
3541 * Decode LOCK response
3543 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3545 struct xdr_stream xdr;
3546 struct compound_hdr hdr;
3549 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3550 status = decode_compound_hdr(&xdr, &hdr);
3553 status = decode_putfh(&xdr);
3556 status = decode_lock(&xdr, res);
3562 * Decode LOCKT response
3564 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3566 struct xdr_stream xdr;
3567 struct compound_hdr hdr;
3570 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3571 status = decode_compound_hdr(&xdr, &hdr);
3574 status = decode_putfh(&xdr);
3577 status = decode_lockt(&xdr, res);
3583 * Decode LOCKU response
3585 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3587 struct xdr_stream xdr;
3588 struct compound_hdr hdr;
3591 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3592 status = decode_compound_hdr(&xdr, &hdr);
3595 status = decode_putfh(&xdr);
3598 status = decode_locku(&xdr, res);
3604 * Decode READLINK response
3606 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3608 struct xdr_stream xdr;
3609 struct compound_hdr hdr;
3612 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3613 status = decode_compound_hdr(&xdr, &hdr);
3616 status = decode_putfh(&xdr);
3619 status = decode_readlink(&xdr, rqstp);
3625 * Decode READDIR response
3627 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3629 struct xdr_stream xdr;
3630 struct compound_hdr hdr;
3633 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3634 status = decode_compound_hdr(&xdr, &hdr);
3637 status = decode_putfh(&xdr);
3640 status = decode_readdir(&xdr, rqstp, res);
3646 * Decode Read response
3648 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3650 struct xdr_stream xdr;
3651 struct compound_hdr hdr;
3654 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3655 status = decode_compound_hdr(&xdr, &hdr);
3658 status = decode_putfh(&xdr);
3661 status = decode_read(&xdr, rqstp, res);
3663 status = res->count;
3669 * Decode WRITE response
3671 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3673 struct xdr_stream xdr;
3674 struct compound_hdr hdr;
3677 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3678 status = decode_compound_hdr(&xdr, &hdr);
3681 status = decode_putfh(&xdr);
3684 status = decode_write(&xdr, res);
3686 status = res->count;
3692 * Decode COMMIT response
3694 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3696 struct xdr_stream xdr;
3697 struct compound_hdr hdr;
3700 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3701 status = decode_compound_hdr(&xdr, &hdr);
3704 status = decode_putfh(&xdr);
3707 status = decode_commit(&xdr, res);
3715 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3717 struct xdr_stream xdr;
3718 struct compound_hdr hdr;
3721 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3722 status = decode_compound_hdr(&xdr, &hdr);
3724 status = decode_putfh(&xdr);
3726 status = decode_fsinfo(&xdr, fsinfo);
3728 status = -nfs_stat_to_errno(hdr.status);
3735 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
3737 struct xdr_stream xdr;
3738 struct compound_hdr hdr;
3741 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3742 status = decode_compound_hdr(&xdr, &hdr);
3744 status = decode_putfh(&xdr);
3746 status = decode_pathconf(&xdr, pathconf);
3753 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
3755 struct xdr_stream xdr;
3756 struct compound_hdr hdr;
3759 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3760 status = decode_compound_hdr(&xdr, &hdr);
3762 status = decode_putfh(&xdr);
3764 status = decode_statfs(&xdr, fsstat);
3769 * GETATTR_BITMAP request
3771 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
3773 struct xdr_stream xdr;
3774 struct compound_hdr hdr;
3777 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3778 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3780 if ((status = decode_putfh(&xdr)) != 0)
3782 status = decode_server_caps(&xdr, res);
3788 * Decode RENEW response
3790 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3792 struct xdr_stream xdr;
3793 struct compound_hdr hdr;
3796 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3797 status = decode_compound_hdr(&xdr, &hdr);
3799 status = decode_renew(&xdr);
3804 * a SETCLIENTID request
3806 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
3807 struct nfs4_client *clp)
3809 struct xdr_stream xdr;
3810 struct compound_hdr hdr;
3813 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3814 status = decode_compound_hdr(&xdr, &hdr);
3816 status = decode_setclientid(&xdr, clp);
3818 status = -nfs_stat_to_errno(hdr.status);
3823 * a SETCLIENTID_CONFIRM request
3825 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3827 struct xdr_stream xdr;
3828 struct compound_hdr hdr;
3831 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3832 status = decode_compound_hdr(&xdr, &hdr);
3834 status = decode_setclientid_confirm(&xdr);
3836 status = decode_putrootfh(&xdr);
3838 status = decode_fsinfo(&xdr, fsinfo);
3840 status = -nfs_stat_to_errno(hdr.status);
3845 * DELEGRETURN request
3847 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3849 struct xdr_stream xdr;
3850 struct compound_hdr hdr;
3853 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3854 status = decode_compound_hdr(&xdr, &hdr);
3856 status = decode_putfh(&xdr);
3858 status = decode_delegreturn(&xdr);
3863 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
3865 uint32_t bitmap[2] = {0};
3870 return ERR_PTR(-EAGAIN);
3872 return ERR_PTR(-EBADCOOKIE);
3875 entry->prev_cookie = entry->cookie;
3876 p = xdr_decode_hyper(p, &entry->cookie);
3877 entry->len = ntohl(*p++);
3878 entry->name = (const char *) p;
3879 p += XDR_QUADLEN(entry->len);
3882 * In case the server doesn't return an inode number,
3883 * we fake one here. (We don't use inode number 0,
3884 * since glibc seems to choke on it...)
3888 len = ntohl(*p++); /* bitmap length */
3890 bitmap[0] = ntohl(*p++);
3892 bitmap[1] = ntohl(*p++);
3896 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
3898 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
3899 xdr_decode_hyper(p, &entry->ino);
3900 else if (bitmap[0] == FATTR4_WORD0_FILEID)
3901 xdr_decode_hyper(p, &entry->ino);
3905 entry->eof = !p[0] && p[1];
3910 * We need to translate between nfs status return values and
3911 * the local errno values which may not be the same.
3918 { NFS4ERR_PERM, EPERM },
3919 { NFS4ERR_NOENT, ENOENT },
3920 { NFS4ERR_IO, errno_NFSERR_IO },
3921 { NFS4ERR_NXIO, ENXIO },
3922 { NFS4ERR_ACCESS, EACCES },
3923 { NFS4ERR_EXIST, EEXIST },
3924 { NFS4ERR_XDEV, EXDEV },
3925 { NFS4ERR_NOTDIR, ENOTDIR },
3926 { NFS4ERR_ISDIR, EISDIR },
3927 { NFS4ERR_INVAL, EINVAL },
3928 { NFS4ERR_FBIG, EFBIG },
3929 { NFS4ERR_NOSPC, ENOSPC },
3930 { NFS4ERR_ROFS, EROFS },
3931 { NFS4ERR_MLINK, EMLINK },
3932 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
3933 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
3934 { NFS4ERR_DQUOT, EDQUOT },
3935 { NFS4ERR_STALE, ESTALE },
3936 { NFS4ERR_BADHANDLE, EBADHANDLE },
3937 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
3938 { NFS4ERR_NOTSUPP, ENOTSUPP },
3939 { NFS4ERR_TOOSMALL, ETOOSMALL },
3940 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
3941 { NFS4ERR_BADTYPE, EBADTYPE },
3942 { NFS4ERR_LOCKED, EAGAIN },
3943 { NFS4ERR_RESOURCE, EREMOTEIO },
3944 { NFS4ERR_SYMLINK, ELOOP },
3945 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
3946 { NFS4ERR_DEADLOCK, EDEADLK },
3947 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
3948 * to be handled by a
3955 * Convert an NFS error code to a local one.
3956 * This one is used jointly by NFSv2 and NFSv3.
3959 nfs_stat_to_errno(int stat)
3962 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
3963 if (nfs_errtbl[i].stat == stat)
3964 return nfs_errtbl[i].errno;
3966 if (stat <= 10000 || stat > 10100) {
3967 /* The server is looney tunes. */
3968 return ESERVERFAULT;
3970 /* If we cannot translate the error, the recovery routines should
3972 * Note: remaining NFSv4 error codes have values > 10000, so should
3973 * not conflict with native Linux error codes.
3979 # define MAX(a, b) (((a) > (b))? (a) : (b))
3982 #define PROC(proc, argtype, restype) \
3983 [NFSPROC4_CLNT_##proc] = { \
3984 .p_proc = NFSPROC4_COMPOUND, \
3985 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
3986 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
3987 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
3990 struct rpc_procinfo nfs4_procedures[] = {
3991 PROC(READ, enc_read, dec_read),
3992 PROC(WRITE, enc_write, dec_write),
3993 PROC(COMMIT, enc_commit, dec_commit),
3994 PROC(OPEN, enc_open, dec_open),
3995 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
3996 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
3997 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
3998 PROC(CLOSE, enc_close, dec_close),
3999 PROC(SETATTR, enc_setattr, dec_setattr),
4000 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4001 PROC(RENEW, enc_renew, dec_renew),
4002 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4003 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4004 PROC(LOCK, enc_lock, dec_lock),
4005 PROC(LOCKT, enc_lockt, dec_lockt),
4006 PROC(LOCKU, enc_locku, dec_locku),
4007 PROC(ACCESS, enc_access, dec_access),
4008 PROC(GETATTR, enc_getattr, dec_getattr),
4009 PROC(LOOKUP, enc_lookup, dec_lookup),
4010 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4011 PROC(REMOVE, enc_remove, dec_remove),
4012 PROC(RENAME, enc_rename, dec_rename),
4013 PROC(LINK, enc_link, dec_link),
4014 PROC(SYMLINK, enc_symlink, dec_symlink),
4015 PROC(CREATE, enc_create, dec_create),
4016 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4017 PROC(STATFS, enc_statfs, dec_statfs),
4018 PROC(READLINK, enc_readlink, dec_readlink),
4019 PROC(READDIR, enc_readdir, dec_readdir),
4020 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4021 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4024 struct rpc_version nfs_version4 = {
4026 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
4027 .procs = nfs4_procedures