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 encode_getattr_maxsz (op_encode_hdr_maxsz + 3)
87 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
88 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
89 #define nfs4_fattr_bitmap_maxsz (36 + 2 * nfs4_name_maxsz)
90 #define decode_getattr_maxsz (op_decode_hdr_maxsz + 3 + \
91 nfs4_fattr_bitmap_maxsz)
92 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
93 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
94 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
95 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
96 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
97 #define decode_renew_maxsz (op_decode_hdr_maxsz)
98 #define encode_setclientid_maxsz \
99 (op_encode_hdr_maxsz + \
100 4 /*server->ip_addr*/ + \
103 6 + (NFS4_VERIFIER_SIZE >> 2))
104 #define decode_setclientid_maxsz \
105 (op_decode_hdr_maxsz + \
107 1024) /* large value for CLID_INUSE */
108 #define encode_setclientid_confirm_maxsz \
109 (op_encode_hdr_maxsz + \
110 3 + (NFS4_VERIFIER_SIZE >> 2))
111 #define decode_setclientid_confirm_maxsz \
112 (op_decode_hdr_maxsz)
113 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
114 1 + ((3 + NFS4_FHSIZE) >> 2))
115 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
117 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
119 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
120 #define encode_link_maxsz (op_encode_hdr_maxsz + \
122 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
123 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
124 1 + nfs4_name_maxsz + \
126 nfs4_fattr_bitmap_maxsz)
127 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
128 #define encode_create_maxsz (op_encode_hdr_maxsz + \
129 2 + nfs4_name_maxsz + \
130 nfs4_fattr_bitmap_maxsz)
131 #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
132 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
133 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
134 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
135 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
136 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
137 encode_putfh_maxsz + \
138 op_encode_hdr_maxsz + 7)
139 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
140 decode_putfh_maxsz + \
141 op_decode_hdr_maxsz + 2)
142 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
143 encode_putfh_maxsz + \
145 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
146 decode_putfh_maxsz + \
148 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
149 encode_putfh_maxsz + \
150 op_encode_hdr_maxsz + 9)
151 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
152 decode_putfh_maxsz + \
153 op_decode_hdr_maxsz + 2)
154 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
155 encode_putfh_maxsz + \
156 op_encode_hdr_maxsz + 8)
157 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
158 decode_putfh_maxsz + \
159 op_decode_hdr_maxsz + 4)
160 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
161 encode_putfh_maxsz + \
162 op_encode_hdr_maxsz + 3)
163 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
164 decode_putfh_maxsz + \
165 op_decode_hdr_maxsz + 2)
166 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
167 encode_putfh_maxsz + \
168 op_encode_hdr_maxsz + \
170 encode_getattr_maxsz + \
172 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
173 decode_putfh_maxsz + \
174 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
175 decode_getattr_maxsz + \
177 #define NFS4_enc_open_confirm_sz \
178 (compound_encode_hdr_maxsz + \
179 encode_putfh_maxsz + \
180 op_encode_hdr_maxsz + 5)
181 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
182 decode_putfh_maxsz + \
183 op_decode_hdr_maxsz + 4)
184 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
185 encode_putfh_maxsz + \
186 op_encode_hdr_maxsz + \
188 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
189 decode_putfh_maxsz + \
190 op_decode_hdr_maxsz + \
192 #define NFS4_enc_open_downgrade_sz \
193 (compound_encode_hdr_maxsz + \
194 encode_putfh_maxsz + \
195 op_encode_hdr_maxsz + 7)
196 #define NFS4_dec_open_downgrade_sz \
197 (compound_decode_hdr_maxsz + \
198 decode_putfh_maxsz + \
199 op_decode_hdr_maxsz + 4)
200 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
201 encode_putfh_maxsz + \
202 op_encode_hdr_maxsz + 5)
203 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
204 decode_putfh_maxsz + \
205 op_decode_hdr_maxsz + 4)
206 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
207 encode_putfh_maxsz + \
208 op_encode_hdr_maxsz + 4 + \
209 nfs4_fattr_bitmap_maxsz + \
210 encode_getattr_maxsz)
211 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
212 decode_putfh_maxsz + \
213 op_decode_hdr_maxsz + 3)
214 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
215 encode_putfh_maxsz + \
217 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
218 decode_putfh_maxsz + \
220 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
222 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
224 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
225 encode_setclientid_maxsz)
226 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
227 decode_setclientid_maxsz)
228 #define NFS4_enc_setclientid_confirm_sz \
229 (compound_encode_hdr_maxsz + \
230 encode_setclientid_confirm_maxsz + \
231 encode_putrootfh_maxsz + \
233 #define NFS4_dec_setclientid_confirm_sz \
234 (compound_decode_hdr_maxsz + \
235 decode_setclientid_confirm_maxsz + \
236 decode_putrootfh_maxsz + \
238 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
239 encode_putfh_maxsz + \
240 encode_getattr_maxsz + \
241 op_encode_hdr_maxsz + \
245 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
246 decode_putfh_maxsz + \
247 decode_getattr_maxsz + \
248 op_decode_hdr_maxsz + \
251 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
252 encode_putfh_maxsz + \
253 encode_getattr_maxsz + \
254 op_encode_hdr_maxsz + \
257 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
258 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
259 encode_putfh_maxsz + \
260 encode_getattr_maxsz + \
261 op_encode_hdr_maxsz + \
263 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
264 decode_putfh_maxsz + \
265 decode_getattr_maxsz + \
266 op_decode_hdr_maxsz + 4)
267 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
268 encode_putfh_maxsz + \
269 op_encode_hdr_maxsz + 1)
270 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
271 decode_putfh_maxsz + \
272 op_decode_hdr_maxsz + 2)
273 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
274 encode_putfh_maxsz + \
275 encode_getattr_maxsz)
276 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
277 decode_putfh_maxsz + \
278 decode_getattr_maxsz)
279 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
280 encode_putfh_maxsz + \
281 encode_lookup_maxsz + \
282 encode_getattr_maxsz + \
284 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
285 decode_putfh_maxsz + \
286 op_decode_hdr_maxsz + \
287 decode_getattr_maxsz + \
289 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
290 encode_putrootfh_maxsz + \
291 encode_getattr_maxsz + \
293 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
294 decode_putrootfh_maxsz + \
295 decode_getattr_maxsz + \
297 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
298 encode_putfh_maxsz + \
300 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
301 decode_putfh_maxsz + \
302 op_decode_hdr_maxsz + 5)
303 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
304 encode_putfh_maxsz + \
305 encode_savefh_maxsz + \
306 encode_putfh_maxsz + \
308 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
309 decode_putfh_maxsz + \
310 decode_savefh_maxsz + \
311 decode_putfh_maxsz + \
313 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
314 encode_putfh_maxsz + \
315 encode_savefh_maxsz + \
316 encode_putfh_maxsz + \
318 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
319 decode_putfh_maxsz + \
320 decode_savefh_maxsz + \
321 decode_putfh_maxsz + \
323 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
324 encode_putfh_maxsz + \
325 encode_symlink_maxsz + \
326 encode_getattr_maxsz + \
328 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
329 decode_putfh_maxsz + \
330 decode_symlink_maxsz + \
331 decode_getattr_maxsz + \
333 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
334 encode_putfh_maxsz + \
335 encode_create_maxsz + \
336 encode_getattr_maxsz + \
338 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
339 decode_putfh_maxsz + \
340 decode_create_maxsz + \
341 decode_getattr_maxsz + \
343 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
344 encode_putfh_maxsz + \
345 encode_getattr_maxsz)
346 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
347 decode_putfh_maxsz + \
348 decode_getattr_maxsz)
349 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
350 encode_putfh_maxsz + \
351 encode_getattr_maxsz)
352 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
353 decode_putfh_maxsz + \
354 op_decode_hdr_maxsz + 12)
355 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
356 encode_getattr_maxsz)
357 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
358 decode_getattr_maxsz)
359 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
360 encode_putfh_maxsz + \
361 encode_delegreturn_maxsz)
362 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
363 decode_delegreturn_maxsz)
367 unsigned int nfs2type;
375 { S_IFSOCK, NFSOCK },
381 struct compound_hdr {
389 * START OF "GENERIC" ENCODE ROUTINES.
390 * These may look a little ugly since they are imported from a "generic"
391 * set of XDR encode/decode routines which are intended to be shared by
392 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
394 * If the pain of reading these is too great, it should be a straightforward
395 * task to translate them into Linux-specific versions which are more
396 * consistent with the style used in NFSv2/v3...
398 #define WRITE32(n) *p++ = htonl(n)
399 #define WRITE64(n) do { \
400 *p++ = htonl((uint32_t)((n) >> 32)); \
401 *p++ = htonl((uint32_t)(n)); \
403 #define WRITEMEM(ptr,nbytes) do { \
404 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
407 #define RESERVE_SPACE(nbytes) do { \
408 p = xdr_reserve_space(xdr, nbytes); \
409 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
413 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
417 p = xdr_reserve_space(xdr, 4 + len);
419 xdr_encode_opaque(p, str, len);
422 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
426 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
427 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
428 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
429 WRITE32(hdr->taglen);
430 WRITEMEM(hdr->tag, hdr->taglen);
431 WRITE32(NFS4_MINOR_VERSION);
436 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
440 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
442 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
445 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
447 char owner_name[IDMAP_NAMESZ];
448 char owner_group[IDMAP_NAMESZ];
449 int owner_namelen = 0;
450 int owner_grouplen = 0;
459 * We reserve enough space to write the entire attribute buffer at once.
460 * In the worst-case, this would be
461 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
462 * = 36 bytes, plus any contribution from variable-length fields
463 * such as owner/group/acl's.
468 if (iap->ia_valid & ATTR_SIZE)
470 if (iap->ia_valid & ATTR_MODE)
472 if (iap->ia_valid & ATTR_UID) {
473 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
474 if (owner_namelen < 0) {
475 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
478 strcpy(owner_name, "nobody");
479 owner_namelen = sizeof("nobody") - 1;
482 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
484 if (iap->ia_valid & ATTR_GID) {
485 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
486 if (owner_grouplen < 0) {
487 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
489 strcpy(owner_group, "nobody");
490 owner_grouplen = sizeof("nobody") - 1;
493 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
495 if (iap->ia_valid & ATTR_ATIME_SET)
497 else if (iap->ia_valid & ATTR_ATIME)
499 if (iap->ia_valid & ATTR_MTIME_SET)
501 else if (iap->ia_valid & ATTR_MTIME)
506 * We write the bitmap length now, but leave the bitmap and the attribute
507 * buffer length to be backfilled at the end of this routine.
513 if (iap->ia_valid & ATTR_SIZE) {
514 bmval0 |= FATTR4_WORD0_SIZE;
515 WRITE64(iap->ia_size);
517 if (iap->ia_valid & ATTR_MODE) {
518 bmval1 |= FATTR4_WORD1_MODE;
519 WRITE32(iap->ia_mode);
521 if (iap->ia_valid & ATTR_UID) {
522 bmval1 |= FATTR4_WORD1_OWNER;
523 WRITE32(owner_namelen);
524 WRITEMEM(owner_name, owner_namelen);
526 if (iap->ia_valid & ATTR_GID) {
527 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
528 WRITE32(owner_grouplen);
529 WRITEMEM(owner_group, owner_grouplen);
531 if (iap->ia_valid & ATTR_ATIME_SET) {
532 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
533 WRITE32(NFS4_SET_TO_CLIENT_TIME);
535 WRITE32(iap->ia_mtime.tv_sec);
536 WRITE32(iap->ia_mtime.tv_nsec);
538 else if (iap->ia_valid & ATTR_ATIME) {
539 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
540 WRITE32(NFS4_SET_TO_SERVER_TIME);
542 if (iap->ia_valid & ATTR_MTIME_SET) {
543 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
544 WRITE32(NFS4_SET_TO_CLIENT_TIME);
546 WRITE32(iap->ia_mtime.tv_sec);
547 WRITE32(iap->ia_mtime.tv_nsec);
549 else if (iap->ia_valid & ATTR_MTIME) {
550 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
551 WRITE32(NFS4_SET_TO_SERVER_TIME);
555 * Now we backfill the bitmap and the attribute buffer length.
557 if (len != ((char *)p - (char *)q) + 4) {
558 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
559 len, ((char *)p - (char *)q) + 4);
562 len = (char *)p - (char *)q - 12;
563 *q++ = htonl(bmval0);
564 *q++ = htonl(bmval1);
572 static int encode_access(struct xdr_stream *xdr, u32 access)
583 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
587 RESERVE_SPACE(8+sizeof(arg->stateid.data));
590 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
595 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
601 WRITE64(args->offset);
602 WRITE32(args->count);
607 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
613 WRITE32(create->ftype);
615 switch (create->ftype) {
617 RESERVE_SPACE(4 + create->u.symlink->len);
618 WRITE32(create->u.symlink->len);
619 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
622 case NF4BLK: case NF4CHR:
624 WRITE32(create->u.device.specdata1);
625 WRITE32(create->u.device.specdata2);
632 RESERVE_SPACE(4 + create->name->len);
633 WRITE32(create->name->len);
634 WRITEMEM(create->name->name, create->name->len);
636 return encode_attrs(xdr, create->attrs, create->server);
639 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
650 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
662 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
664 return encode_getattr_two(xdr,
665 bitmask[0] & nfs4_fattr_bitmap[0],
666 bitmask[1] & nfs4_fattr_bitmap[1]);
669 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
671 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
672 bitmask[1] & nfs4_fsinfo_bitmap[1]);
675 static int encode_getfh(struct xdr_stream *xdr)
685 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
689 RESERVE_SPACE(8 + name->len);
692 WRITEMEM(name->name, name->len);
698 * opcode,type,reclaim,offset,length,new_lock_owner = 32
699 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
701 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
704 struct nfs_lock_opargs *opargs = arg->u.lock;
709 WRITE32(opargs->reclaim);
710 WRITE64(arg->offset);
711 WRITE64(arg->length);
712 WRITE32(opargs->new_lock_owner);
713 if (opargs->new_lock_owner){
714 struct nfs_open_to_lock *ol = opargs->u.open_lock;
717 WRITE32(ol->open_seqid);
718 WRITEMEM(&ol->open_stateid, sizeof(ol->open_stateid));
719 WRITE32(ol->lock_seqid);
720 WRITE64(ol->lock_owner.clientid);
722 WRITE32(ol->lock_owner.id);
725 struct nfs_exist_lock *el = opargs->u.exist_lock;
728 WRITEMEM(&el->stateid, sizeof(el->stateid));
735 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
738 struct nfs_lowner *opargs = arg->u.lockt;
743 WRITE64(arg->offset);
744 WRITE64(arg->length);
745 WRITE64(opargs->clientid);
752 static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
755 struct nfs_locku_opargs *opargs = arg->u.locku;
760 WRITE32(opargs->seqid);
761 WRITEMEM(&opargs->stateid, sizeof(opargs->stateid));
762 WRITE64(arg->offset);
763 WRITE64(arg->length);
768 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
773 RESERVE_SPACE(8 + len);
776 WRITEMEM(name->name, len);
781 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
786 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
788 WRITE32(NFS4_SHARE_ACCESS_READ);
791 WRITE32(NFS4_SHARE_ACCESS_WRITE);
793 case FMODE_READ|FMODE_WRITE:
794 WRITE32(NFS4_SHARE_ACCESS_BOTH);
799 WRITE32(0); /* for linux, share_deny = 0 always */
802 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
806 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
812 encode_share_access(xdr, arg->open_flags);
814 WRITE64(arg->clientid);
819 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
824 switch(arg->open_flags & O_EXCL) {
826 WRITE32(NFS4_CREATE_UNCHECKED);
827 encode_attrs(xdr, arg->u.attrs, arg->server);
830 WRITE32(NFS4_CREATE_EXCLUSIVE);
831 encode_nfs4_verifier(xdr, &arg->u.verifier);
835 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
840 switch (arg->open_flags & O_CREAT) {
842 WRITE32(NFS4_OPEN_NOCREATE);
845 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
846 WRITE32(NFS4_OPEN_CREATE);
847 encode_createmode(xdr, arg);
851 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
856 switch (delegation_type) {
858 WRITE32(NFS4_OPEN_DELEGATE_NONE);
861 WRITE32(NFS4_OPEN_DELEGATE_READ);
863 case FMODE_WRITE|FMODE_READ:
864 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
871 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
876 WRITE32(NFS4_OPEN_CLAIM_NULL);
877 encode_string(xdr, name->len, name->name);
880 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
885 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
886 encode_delegation_type(xdr, type);
889 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
893 RESERVE_SPACE(4+sizeof(stateid->data));
894 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
895 WRITEMEM(stateid->data, sizeof(stateid->data));
896 encode_string(xdr, name->len, name->name);
899 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
901 encode_openhdr(xdr, arg);
902 encode_opentype(xdr, arg);
903 switch (arg->claim) {
904 case NFS4_OPEN_CLAIM_NULL:
905 encode_claim_null(xdr, arg->name);
907 case NFS4_OPEN_CLAIM_PREVIOUS:
908 encode_claim_previous(xdr, arg->u.delegation_type);
910 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
911 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
919 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
923 RESERVE_SPACE(8+sizeof(arg->stateid.data));
924 WRITE32(OP_OPEN_CONFIRM);
925 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
931 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
935 RESERVE_SPACE(8+sizeof(arg->stateid.data));
936 WRITE32(OP_OPEN_DOWNGRADE);
937 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
939 encode_share_access(xdr, arg->open_flags);
944 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
949 RESERVE_SPACE(8 + len);
952 WRITEMEM(fh->data, len);
957 static int encode_putrootfh(struct xdr_stream *xdr)
962 WRITE32(OP_PUTROOTFH);
967 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
969 nfs4_stateid stateid;
973 if (ctx->state != NULL) {
974 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
975 WRITEMEM(stateid.data, sizeof(stateid.data));
977 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
980 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
987 encode_stateid(xdr, args->context);
990 WRITE64(args->offset);
991 WRITE32(args->count);
996 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
998 struct rpc_auth *auth = req->rq_task->tk_auth;
1002 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1003 WRITE32(OP_READDIR);
1004 WRITE64(readdir->cookie);
1005 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1006 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1007 WRITE32(readdir->count);
1009 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) {
1011 WRITE32(FATTR4_WORD1_MOUNTED_ON_FILEID);
1013 WRITE32(FATTR4_WORD0_FILEID);
1017 /* set up reply kvec
1018 * toplevel_status + taglen + rescount + OP_PUTFH + status
1019 * + OP_READDIR + status + verifer(2) = 9
1021 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1022 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1023 readdir->pgbase, readdir->count);
1028 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1030 struct rpc_auth *auth = req->rq_task->tk_auth;
1031 unsigned int replen;
1035 WRITE32(OP_READLINK);
1037 /* set up reply kvec
1038 * toplevel_status + taglen + rescount + OP_PUTFH + status
1039 * + OP_READLINK + status + string length = 8
1041 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1042 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1043 readlink->pgbase, readlink->pglen);
1048 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1052 RESERVE_SPACE(8 + name->len);
1055 WRITEMEM(name->name, name->len);
1060 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1064 RESERVE_SPACE(8 + oldname->len);
1066 WRITE32(oldname->len);
1067 WRITEMEM(oldname->name, oldname->len);
1069 RESERVE_SPACE(4 + newname->len);
1070 WRITE32(newname->len);
1071 WRITEMEM(newname->name, newname->len);
1076 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1082 WRITE64(client_stateid->cl_clientid);
1088 encode_savefh(struct xdr_stream *xdr)
1098 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1103 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1104 WRITE32(OP_SETATTR);
1105 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1107 if ((status = encode_attrs(xdr, arg->iap, server)))
1113 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1117 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1118 WRITE32(OP_SETCLIENTID);
1119 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1121 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1123 WRITE32(setclientid->sc_prog);
1124 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1125 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1127 WRITE32(setclientid->sc_cb_ident);
1132 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1136 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1137 WRITE32(OP_SETCLIENTID_CONFIRM);
1138 WRITE64(client_state->cl_clientid);
1139 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1144 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1151 encode_stateid(xdr, args->context);
1154 WRITE64(args->offset);
1155 WRITE32(args->stable);
1156 WRITE32(args->count);
1158 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1163 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1169 WRITE32(OP_DELEGRETURN);
1170 WRITEMEM(stateid->data, sizeof(stateid->data));
1175 * END OF "GENERIC" ENCODE ROUTINES.
1179 * Encode an ACCESS request
1181 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1183 struct xdr_stream xdr;
1184 struct compound_hdr hdr = {
1189 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1190 encode_compound_hdr(&xdr, &hdr);
1191 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1192 status = encode_access(&xdr, args->access);
1197 * Encode LOOKUP request
1199 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1201 struct xdr_stream xdr;
1202 struct compound_hdr hdr = {
1207 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1208 encode_compound_hdr(&xdr, &hdr);
1209 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1211 if ((status = encode_lookup(&xdr, args->name)) != 0)
1213 if ((status = encode_getfh(&xdr)) != 0)
1215 status = encode_getfattr(&xdr, args->bitmask);
1221 * Encode LOOKUP_ROOT request
1223 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1225 struct xdr_stream xdr;
1226 struct compound_hdr hdr = {
1231 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1232 encode_compound_hdr(&xdr, &hdr);
1233 if ((status = encode_putrootfh(&xdr)) != 0)
1235 if ((status = encode_getfh(&xdr)) == 0)
1236 status = encode_getfattr(&xdr, args->bitmask);
1242 * Encode REMOVE request
1244 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1246 struct xdr_stream xdr;
1247 struct compound_hdr hdr = {
1252 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1253 encode_compound_hdr(&xdr, &hdr);
1254 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1255 status = encode_remove(&xdr, args->name);
1260 * Encode RENAME request
1262 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1264 struct xdr_stream xdr;
1265 struct compound_hdr hdr = {
1270 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1271 encode_compound_hdr(&xdr, &hdr);
1272 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1274 if ((status = encode_savefh(&xdr)) != 0)
1276 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1278 status = encode_rename(&xdr, args->old_name, args->new_name);
1284 * Encode LINK request
1286 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1288 struct xdr_stream xdr;
1289 struct compound_hdr hdr = {
1294 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1295 encode_compound_hdr(&xdr, &hdr);
1296 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1298 if ((status = encode_savefh(&xdr)) != 0)
1300 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1302 status = encode_link(&xdr, args->name);
1308 * Encode CREATE request
1310 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1312 struct xdr_stream xdr;
1313 struct compound_hdr hdr = {
1318 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1319 encode_compound_hdr(&xdr, &hdr);
1320 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1322 if ((status = encode_create(&xdr, args)) != 0)
1324 if ((status = encode_getfh(&xdr)) != 0)
1326 status = encode_getfattr(&xdr, args->bitmask);
1332 * Encode SYMLINK request
1334 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1336 return nfs4_xdr_enc_create(req, p, args);
1340 * Encode GETATTR request
1342 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1344 struct xdr_stream xdr;
1345 struct compound_hdr hdr = {
1350 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1351 encode_compound_hdr(&xdr, &hdr);
1352 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1353 status = encode_getfattr(&xdr, args->bitmask);
1358 * Encode a CLOSE request
1360 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1362 struct xdr_stream xdr;
1363 struct compound_hdr hdr = {
1368 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1369 encode_compound_hdr(&xdr, &hdr);
1370 status = encode_putfh(&xdr, args->fh);
1373 status = encode_close(&xdr, args);
1379 * Encode an OPEN request
1381 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1383 struct xdr_stream xdr;
1384 struct compound_hdr hdr = {
1389 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1390 encode_compound_hdr(&xdr, &hdr);
1391 status = encode_putfh(&xdr, args->fh);
1394 status = encode_open(&xdr, args);
1397 status = encode_getfh(&xdr);
1400 status = encode_getfattr(&xdr, args->bitmask);
1406 * Encode an OPEN_CONFIRM request
1408 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1410 struct xdr_stream xdr;
1411 struct compound_hdr hdr = {
1416 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1417 encode_compound_hdr(&xdr, &hdr);
1418 status = encode_putfh(&xdr, args->fh);
1421 status = encode_open_confirm(&xdr, args);
1427 * Encode an OPEN request with no attributes.
1429 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1431 struct xdr_stream xdr;
1432 struct compound_hdr hdr = {
1437 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1438 encode_compound_hdr(&xdr, &hdr);
1439 status = encode_putfh(&xdr, args->fh);
1442 status = encode_open(&xdr, args);
1448 * Encode an OPEN_DOWNGRADE request
1450 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1452 struct xdr_stream xdr;
1453 struct compound_hdr hdr = {
1458 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1459 encode_compound_hdr(&xdr, &hdr);
1460 status = encode_putfh(&xdr, args->fh);
1463 status = encode_open_downgrade(&xdr, args);
1469 * Encode a LOCK request
1471 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1473 struct xdr_stream xdr;
1474 struct compound_hdr hdr = {
1479 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1480 encode_compound_hdr(&xdr, &hdr);
1481 status = encode_putfh(&xdr, args->fh);
1484 status = encode_lock(&xdr, args);
1490 * Encode a LOCKT request
1492 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1494 struct xdr_stream xdr;
1495 struct compound_hdr hdr = {
1500 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1501 encode_compound_hdr(&xdr, &hdr);
1502 status = encode_putfh(&xdr, args->fh);
1505 status = encode_lockt(&xdr, args);
1511 * Encode a LOCKU request
1513 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1515 struct xdr_stream xdr;
1516 struct compound_hdr hdr = {
1521 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1522 encode_compound_hdr(&xdr, &hdr);
1523 status = encode_putfh(&xdr, args->fh);
1526 status = encode_locku(&xdr, args);
1532 * Encode a READLINK request
1534 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1536 struct xdr_stream xdr;
1537 struct compound_hdr hdr = {
1542 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1543 encode_compound_hdr(&xdr, &hdr);
1544 status = encode_putfh(&xdr, args->fh);
1547 status = encode_readlink(&xdr, args, req);
1553 * Encode a READDIR request
1555 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1557 struct xdr_stream xdr;
1558 struct compound_hdr hdr = {
1563 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1564 encode_compound_hdr(&xdr, &hdr);
1565 status = encode_putfh(&xdr, args->fh);
1568 status = encode_readdir(&xdr, args, req);
1574 * Encode a READ request
1576 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1578 struct rpc_auth *auth = req->rq_task->tk_auth;
1579 struct xdr_stream xdr;
1580 struct compound_hdr hdr = {
1585 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1586 encode_compound_hdr(&xdr, &hdr);
1587 status = encode_putfh(&xdr, args->fh);
1590 status = encode_read(&xdr, args);
1594 /* set up reply kvec
1595 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1596 * + OP_READ + status + eof + datalen = 9
1598 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1599 xdr_inline_pages(&req->rq_rcv_buf, replen,
1600 args->pages, args->pgbase, args->count);
1606 * Encode an SETATTR request
1608 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1611 struct xdr_stream xdr;
1612 struct compound_hdr hdr = {
1617 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1618 encode_compound_hdr(&xdr, &hdr);
1619 status = encode_putfh(&xdr, args->fh);
1622 status = encode_setattr(&xdr, args, args->server);
1625 status = encode_getfattr(&xdr, args->bitmask);
1631 * Encode a WRITE request
1633 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1635 struct xdr_stream xdr;
1636 struct compound_hdr hdr = {
1641 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1642 encode_compound_hdr(&xdr, &hdr);
1643 status = encode_putfh(&xdr, args->fh);
1646 status = encode_write(&xdr, args);
1654 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1656 struct xdr_stream xdr;
1657 struct compound_hdr hdr = {
1662 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1663 encode_compound_hdr(&xdr, &hdr);
1664 status = encode_putfh(&xdr, args->fh);
1667 status = encode_commit(&xdr, args);
1675 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1677 struct xdr_stream xdr;
1678 struct compound_hdr hdr = {
1683 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1684 encode_compound_hdr(&xdr, &hdr);
1685 status = encode_putfh(&xdr, args->fh);
1687 status = encode_fsinfo(&xdr, args->bitmask);
1692 * a PATHCONF request
1694 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1696 struct xdr_stream xdr;
1697 struct compound_hdr hdr = {
1702 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1703 encode_compound_hdr(&xdr, &hdr);
1704 status = encode_putfh(&xdr, args->fh);
1706 status = encode_getattr_one(&xdr,
1707 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1714 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1716 struct xdr_stream xdr;
1717 struct compound_hdr hdr = {
1722 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1723 encode_compound_hdr(&xdr, &hdr);
1724 status = encode_putfh(&xdr, args->fh);
1726 status = encode_getattr_two(&xdr,
1727 args->bitmask[0] & nfs4_statfs_bitmap[0],
1728 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1733 * GETATTR_BITMAP request
1735 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1737 struct xdr_stream xdr;
1738 struct compound_hdr hdr = {
1743 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1744 encode_compound_hdr(&xdr, &hdr);
1745 status = encode_putfh(&xdr, fhandle);
1747 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1748 FATTR4_WORD0_LINK_SUPPORT|
1749 FATTR4_WORD0_SYMLINK_SUPPORT|
1750 FATTR4_WORD0_ACLSUPPORT);
1757 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1759 struct xdr_stream xdr;
1760 struct compound_hdr hdr = {
1764 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1765 encode_compound_hdr(&xdr, &hdr);
1766 return encode_renew(&xdr, clp);
1770 * a SETCLIENTID request
1772 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1774 struct xdr_stream xdr;
1775 struct compound_hdr hdr = {
1779 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1780 encode_compound_hdr(&xdr, &hdr);
1781 return encode_setclientid(&xdr, sc);
1785 * a SETCLIENTID_CONFIRM request
1787 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1789 struct xdr_stream xdr;
1790 struct compound_hdr hdr = {
1793 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1796 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1797 encode_compound_hdr(&xdr, &hdr);
1798 status = encode_setclientid_confirm(&xdr, clp);
1800 status = encode_putrootfh(&xdr);
1802 status = encode_fsinfo(&xdr, lease_bitmap);
1807 * DELEGRETURN request
1809 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1811 struct xdr_stream xdr;
1812 struct compound_hdr hdr = {
1817 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1818 encode_compound_hdr(&xdr, &hdr);
1819 if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
1820 status = encode_delegreturn(&xdr, args->stateid);
1825 * START OF "GENERIC" DECODE ROUTINES.
1826 * These may look a little ugly since they are imported from a "generic"
1827 * set of XDR encode/decode routines which are intended to be shared by
1828 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1830 * If the pain of reading these is too great, it should be a straightforward
1831 * task to translate them into Linux-specific versions which are more
1832 * consistent with the style used in NFSv2/v3...
1834 #define READ32(x) (x) = ntohl(*p++)
1835 #define READ64(x) do { \
1836 (x) = (u64)ntohl(*p++) << 32; \
1837 (x) |= ntohl(*p++); \
1839 #define READTIME(x) do { \
1841 (x.tv_sec) = ntohl(*p++); \
1842 (x.tv_nsec) = ntohl(*p++); \
1844 #define COPYMEM(x,nbytes) do { \
1845 memcpy((x), p, nbytes); \
1846 p += XDR_QUADLEN(nbytes); \
1849 #define READ_BUF(nbytes) do { \
1850 p = xdr_inline_decode(xdr, nbytes); \
1852 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
1853 __FUNCTION__, __LINE__); \
1858 static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
1865 *string = (char *)p;
1869 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
1874 READ32(hdr->status);
1875 READ32(hdr->taglen);
1877 READ_BUF(hdr->taglen + 4);
1878 hdr->tag = (char *)p;
1879 p += XDR_QUADLEN(hdr->taglen);
1884 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
1892 if (opnum != expected) {
1894 "nfs4_decode_op_hdr: Server returned operation"
1895 " %d but we issued a request for %d\n",
1900 if (nfserr != NFS_OK)
1901 return -nfs_stat_to_errno(nfserr);
1906 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
1913 return decode_opaque_inline(xdr, &strlen, &str);
1916 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
1923 bitmap[0] = bitmap[1] = 0;
1924 READ_BUF((bmlen << 2));
1933 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
1943 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
1945 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
1946 decode_attr_bitmap(xdr, bitmask);
1947 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
1949 bitmask[0] = bitmask[1] = 0;
1950 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
1954 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
1959 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
1961 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
1964 if (*type < NF4REG || *type > NF4NAMEDATTR) {
1965 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
1968 bitmap[0] &= ~FATTR4_WORD0_TYPE;
1970 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
1974 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
1979 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
1981 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
1984 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
1986 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
1987 (unsigned long long)*change);
1991 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
1996 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
1998 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2001 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2003 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2007 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2012 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2014 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2017 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2019 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2023 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2028 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2030 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2033 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2035 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2039 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2045 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2047 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2049 READ64(fsid->major);
2050 READ64(fsid->minor);
2051 bitmap[0] &= ~FATTR4_WORD0_FSID;
2053 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2054 (unsigned long long)fsid->major,
2055 (unsigned long long)fsid->minor);
2059 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2064 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2066 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2069 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2071 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2075 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2079 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2080 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2082 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2085 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2087 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2091 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2096 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2098 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2101 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2103 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2107 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2113 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2115 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2118 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2120 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2124 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2130 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2132 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2135 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2137 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2141 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2147 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2149 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2152 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2154 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2158 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2164 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2166 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2169 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2171 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2175 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2181 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2183 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2186 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2188 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2192 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2198 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2200 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2203 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2205 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2209 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2215 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2217 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2221 if (maxread > 0x7FFFFFFF)
2222 maxread = 0x7FFFFFFF;
2223 *res = (uint32_t)maxread;
2224 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2226 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2230 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2236 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2238 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2242 if (maxwrite > 0x7FFFFFFF)
2243 maxwrite = 0x7FFFFFFF;
2244 *res = (uint32_t)maxwrite;
2245 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2247 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2251 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2256 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2258 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2262 bitmap[1] &= ~FATTR4_WORD1_MODE;
2264 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2268 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2273 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2275 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2278 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2280 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2284 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2289 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2291 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2295 if (len < XDR_MAX_NETOBJ) {
2296 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2297 dprintk("%s: nfs_map_name_to_uid failed!\n",
2300 printk(KERN_WARNING "%s: name too long (%u)!\n",
2302 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2304 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2308 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2313 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2315 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2319 if (len < XDR_MAX_NETOBJ) {
2320 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2321 dprintk("%s: nfs_map_group_to_gid failed!\n",
2324 printk(KERN_WARNING "%s: name too long (%u)!\n",
2326 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2328 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2332 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2334 uint32_t major = 0, minor = 0, *p;
2337 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2339 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2345 tmp = MKDEV(major, minor);
2346 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2348 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2350 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2354 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2360 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2362 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2365 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2367 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2371 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2377 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2379 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2382 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2384 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2388 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2394 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2396 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2399 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2401 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2405 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2410 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2412 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2415 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2417 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2418 (unsigned long long)*used);
2422 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2431 time->tv_sec = (time_t)sec;
2432 time->tv_nsec = (long)nsec;
2436 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2442 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2444 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2445 status = decode_attr_time(xdr, time);
2446 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2448 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2452 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2458 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2460 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2461 status = decode_attr_time(xdr, time);
2462 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2464 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2468 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2474 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2476 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2477 status = decode_attr_time(xdr, time);
2478 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2480 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2484 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2486 unsigned int attrwords = XDR_QUADLEN(attrlen);
2487 unsigned int nwords = xdr->p - savep;
2489 if (unlikely(attrwords != nwords)) {
2490 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2493 (attrwords < nwords) ? '<' : '>',
2500 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2505 READ32(cinfo->atomic);
2506 READ64(cinfo->before);
2507 READ64(cinfo->after);
2511 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2517 status = decode_op_hdr(xdr, OP_ACCESS);
2523 access->supported = supp;
2524 access->access = acc;
2528 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2533 status = decode_op_hdr(xdr, OP_CLOSE);
2536 READ_BUF(sizeof(res->stateid.data));
2537 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2541 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2546 status = decode_op_hdr(xdr, OP_COMMIT);
2550 COPYMEM(res->verf->verifier, 8);
2554 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2560 status = decode_op_hdr(xdr, OP_CREATE);
2563 if ((status = decode_change_info(xdr, cinfo)))
2567 READ_BUF(bmlen << 2);
2571 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2578 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2580 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2582 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2584 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2586 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2588 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2590 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2592 status = verify_attr_len(xdr, savep, attrlen);
2595 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2599 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2606 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2608 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2610 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2613 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2615 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2617 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2619 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2621 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2623 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2626 status = verify_attr_len(xdr, savep, attrlen);
2629 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2633 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2640 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2642 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2644 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2647 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2649 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2652 status = verify_attr_len(xdr, savep, attrlen);
2655 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2659 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2665 int status, fmode = 0;
2667 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2669 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2672 fattr->bitmap[0] = bitmap[0];
2673 fattr->bitmap[1] = bitmap[1];
2675 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2679 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2681 fattr->type = nfs_type2fmt[type].nfs2type;
2682 fmode = nfs_type2fmt[type].mode;
2684 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2686 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2688 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2690 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2692 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2694 fattr->mode |= fmode;
2695 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2697 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2699 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2701 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2703 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2705 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2707 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2709 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2711 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) {
2712 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2713 fattr->timestamp = jiffies;
2717 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2722 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2725 uint32_t attrlen, bitmap[2];
2728 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2730 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2732 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2735 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2737 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2739 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2741 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2743 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2744 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2746 fsinfo->wtpref = fsinfo->wtmax;
2748 status = verify_attr_len(xdr, savep, attrlen);
2751 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2755 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2761 status = decode_op_hdr(xdr, OP_GETFH);
2764 /* Zero handle first to allow comparisons */
2765 memset(fh, 0, sizeof(*fh));
2769 if (len > NFS4_FHSIZE)
2773 COPYMEM(fh->data, len);
2777 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2781 status = decode_op_hdr(xdr, OP_LINK);
2784 return decode_change_info(xdr, cinfo);
2788 * We create the owner, so we know a proper owner.id length is 4.
2790 static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2796 READ64(denied->offset);
2797 READ64(denied->length);
2798 READ32(denied->type);
2799 READ64(denied->owner.clientid);
2803 READ32(denied->owner.id);
2804 return -NFS4ERR_DENIED;
2807 static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2812 status = decode_op_hdr(xdr, OP_LOCK);
2814 READ_BUF(sizeof(nfs4_stateid));
2815 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2816 } else if (status == -NFS4ERR_DENIED)
2817 return decode_lock_denied(xdr, &res->u.denied);
2821 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2824 status = decode_op_hdr(xdr, OP_LOCKT);
2825 if (status == -NFS4ERR_DENIED)
2826 return decode_lock_denied(xdr, &res->u.denied);
2830 static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2835 status = decode_op_hdr(xdr, OP_LOCKU);
2837 READ_BUF(sizeof(nfs4_stateid));
2838 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2843 static int decode_lookup(struct xdr_stream *xdr)
2845 return decode_op_hdr(xdr, OP_LOOKUP);
2848 /* This is too sick! */
2849 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
2852 uint32_t limit_type, nblocks, blocksize;
2856 switch (limit_type) {
2863 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
2868 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
2871 uint32_t delegation_type;
2874 READ32(delegation_type);
2875 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
2876 res->delegation_type = 0;
2880 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
2881 READ32(res->do_recall);
2882 switch (delegation_type) {
2883 case NFS4_OPEN_DELEGATE_READ:
2884 res->delegation_type = FMODE_READ;
2886 case NFS4_OPEN_DELEGATE_WRITE:
2887 res->delegation_type = FMODE_WRITE|FMODE_READ;
2888 if (decode_space_limit(xdr, &res->maxsize) < 0)
2891 return decode_ace(xdr, NULL, res->server->nfs4_state);
2894 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
2900 status = decode_op_hdr(xdr, OP_OPEN);
2903 READ_BUF(sizeof(res->stateid.data));
2904 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2906 decode_change_info(xdr, &res->cinfo);
2909 READ32(res->rflags);
2914 READ_BUF(bmlen << 2);
2916 return decode_delegation(xdr, res);
2918 printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
2922 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
2927 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
2930 READ_BUF(sizeof(res->stateid.data));
2931 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2935 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
2940 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
2943 READ_BUF(sizeof(res->stateid.data));
2944 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2948 static int decode_putfh(struct xdr_stream *xdr)
2950 return decode_op_hdr(xdr, OP_PUTFH);
2953 static int decode_putrootfh(struct xdr_stream *xdr)
2955 return decode_op_hdr(xdr, OP_PUTROOTFH);
2958 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
2960 struct kvec *iov = req->rq_rcv_buf.head;
2962 uint32_t count, eof, recvd, hdrlen;
2965 status = decode_op_hdr(xdr, OP_READ);
2971 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
2972 recvd = req->rq_rcv_buf.len - hdrlen;
2973 if (count > recvd) {
2974 printk(KERN_WARNING "NFS: server cheating in read reply: "
2975 "count %u > recvd %u\n", count, recvd);
2979 xdr_read_pages(xdr, count);
2985 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
2987 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
2988 struct page *page = *rcvbuf->pages;
2989 struct kvec *iov = rcvbuf->head;
2990 unsigned int nr, pglen = rcvbuf->page_len;
2991 uint32_t *end, *entry, *p, *kaddr;
2992 uint32_t len, attrlen;
2993 int hdrlen, recvd, status;
2995 status = decode_op_hdr(xdr, OP_READDIR);
2999 COPYMEM(readdir->verifier.data, 8);
3001 hdrlen = (char *) p - (char *) iov->iov_base;
3002 recvd = rcvbuf->len - hdrlen;
3005 xdr_read_pages(xdr, pglen);
3007 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3008 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3009 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3011 for (nr = 0; *p++; nr++) {
3014 p += 2; /* cookie */
3015 len = ntohl(*p++); /* filename length */
3016 if (len > NFS4_MAXNAMLEN) {
3017 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3020 p += XDR_QUADLEN(len);
3023 len = ntohl(*p++); /* bitmap length */
3027 attrlen = XDR_QUADLEN(ntohl(*p++));
3028 p += attrlen; /* attributes */
3033 if (!nr && (entry[0] != 0 || entry[1] == 0))
3036 kunmap_atomic(kaddr, KM_USER0);
3039 entry[0] = entry[1] = 0;
3040 /* truncate listing ? */
3042 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3047 kunmap_atomic(kaddr, KM_USER0);
3048 return -errno_NFSERR_IO;
3051 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3053 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3054 struct kvec *iov = rcvbuf->head;
3055 int hdrlen, len, recvd;
3060 status = decode_op_hdr(xdr, OP_READLINK);
3064 /* Convert length of symlink */
3067 if (len >= rcvbuf->page_len || len <= 0) {
3068 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3069 return -ENAMETOOLONG;
3071 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3072 recvd = req->rq_rcv_buf.len - hdrlen;
3074 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3075 "count %u > recvd %u\n", len, recvd);
3078 xdr_read_pages(xdr, len);
3080 * The XDR encode routine has set things up so that
3081 * the link text will be copied directly into the
3082 * buffer. We just have to do overflow-checking,
3083 * and and null-terminate the text (the VFS expects
3084 * null-termination).
3086 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3087 kaddr[len+rcvbuf->page_base] = '\0';
3088 kunmap_atomic(kaddr, KM_USER0);
3092 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3096 status = decode_op_hdr(xdr, OP_REMOVE);
3099 status = decode_change_info(xdr, cinfo);
3104 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3105 struct nfs4_change_info *new_cinfo)
3109 status = decode_op_hdr(xdr, OP_RENAME);
3112 if ((status = decode_change_info(xdr, old_cinfo)))
3114 status = decode_change_info(xdr, new_cinfo);
3119 static int decode_renew(struct xdr_stream *xdr)
3121 return decode_op_hdr(xdr, OP_RENEW);
3125 decode_savefh(struct xdr_stream *xdr)
3127 return decode_op_hdr(xdr, OP_SAVEFH);
3130 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3137 status = decode_op_hdr(xdr, OP_SETATTR);
3142 READ_BUF(bmlen << 2);
3146 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3154 if (opnum != OP_SETCLIENTID) {
3156 "nfs4_decode_setclientid: Server returned operation"
3161 if (nfserr == NFS_OK) {
3162 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3163 READ64(clp->cl_clientid);
3164 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3165 } else if (nfserr == NFSERR_CLID_INUSE) {
3168 /* skip netid string */
3173 /* skip uaddr string */
3177 return -NFSERR_CLID_INUSE;
3179 return -nfs_stat_to_errno(nfserr);
3184 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3186 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3189 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3194 status = decode_op_hdr(xdr, OP_WRITE);
3200 READ32(res->verf->committed);
3201 COPYMEM(res->verf->verifier, 8);
3205 static int decode_delegreturn(struct xdr_stream *xdr)
3207 return decode_op_hdr(xdr, OP_DELEGRETURN);
3211 * Decode OPEN_DOWNGRADE response
3213 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3215 struct xdr_stream xdr;
3216 struct compound_hdr hdr;
3219 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3220 status = decode_compound_hdr(&xdr, &hdr);
3223 status = decode_putfh(&xdr);
3226 status = decode_open_downgrade(&xdr, res);
3232 * END OF "GENERIC" DECODE ROUTINES.
3236 * Decode ACCESS response
3238 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3240 struct xdr_stream xdr;
3241 struct compound_hdr hdr;
3244 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3245 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3247 if ((status = decode_putfh(&xdr)) == 0)
3248 status = decode_access(&xdr, res);
3254 * Decode LOOKUP response
3256 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3258 struct xdr_stream xdr;
3259 struct compound_hdr hdr;
3262 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3263 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3265 if ((status = decode_putfh(&xdr)) != 0)
3267 if ((status = decode_lookup(&xdr)) != 0)
3269 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3271 status = decode_getfattr(&xdr, res->fattr, res->server);
3277 * Decode LOOKUP_ROOT response
3279 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3281 struct xdr_stream xdr;
3282 struct compound_hdr hdr;
3285 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3286 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3288 if ((status = decode_putrootfh(&xdr)) != 0)
3290 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3291 status = decode_getfattr(&xdr, res->fattr, res->server);
3297 * Decode REMOVE response
3299 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3301 struct xdr_stream xdr;
3302 struct compound_hdr hdr;
3305 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3306 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3308 if ((status = decode_putfh(&xdr)) == 0)
3309 status = decode_remove(&xdr, cinfo);
3315 * Decode RENAME response
3317 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3319 struct xdr_stream xdr;
3320 struct compound_hdr hdr;
3323 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3324 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3326 if ((status = decode_putfh(&xdr)) != 0)
3328 if ((status = decode_savefh(&xdr)) != 0)
3330 if ((status = decode_putfh(&xdr)) != 0)
3332 status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
3338 * Decode LINK response
3340 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3342 struct xdr_stream xdr;
3343 struct compound_hdr hdr;
3346 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3347 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3349 if ((status = decode_putfh(&xdr)) != 0)
3351 if ((status = decode_savefh(&xdr)) != 0)
3353 if ((status = decode_putfh(&xdr)) != 0)
3355 status = decode_link(&xdr, cinfo);
3361 * Decode CREATE response
3363 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3365 struct xdr_stream xdr;
3366 struct compound_hdr hdr;
3369 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3370 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3372 if ((status = decode_putfh(&xdr)) != 0)
3374 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3376 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3378 status = decode_getfattr(&xdr, res->fattr, res->server);
3379 if (status == NFS4ERR_DELAY)
3386 * Decode SYMLINK response
3388 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3390 return nfs4_xdr_dec_create(rqstp, p, res);
3394 * Decode GETATTR response
3396 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3398 struct xdr_stream xdr;
3399 struct compound_hdr hdr;
3402 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3403 status = decode_compound_hdr(&xdr, &hdr);
3406 status = decode_putfh(&xdr);
3409 status = decode_getfattr(&xdr, res->fattr, res->server);
3417 * Decode CLOSE response
3419 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3421 struct xdr_stream xdr;
3422 struct compound_hdr hdr;
3425 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3426 status = decode_compound_hdr(&xdr, &hdr);
3429 status = decode_putfh(&xdr);
3432 status = decode_close(&xdr, res);
3438 * Decode OPEN response
3440 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3442 struct xdr_stream xdr;
3443 struct compound_hdr hdr;
3446 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3447 status = decode_compound_hdr(&xdr, &hdr);
3450 status = decode_putfh(&xdr);
3453 status = decode_open(&xdr, res);
3456 status = decode_getfh(&xdr, &res->fh);
3459 status = decode_getfattr(&xdr, res->f_attr, res->server);
3460 if (status == NFS4ERR_DELAY)
3467 * Decode OPEN_CONFIRM response
3469 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3471 struct xdr_stream xdr;
3472 struct compound_hdr hdr;
3475 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3476 status = decode_compound_hdr(&xdr, &hdr);
3479 status = decode_putfh(&xdr);
3482 status = decode_open_confirm(&xdr, res);
3488 * Decode OPEN response
3490 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3492 struct xdr_stream xdr;
3493 struct compound_hdr hdr;
3496 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3497 status = decode_compound_hdr(&xdr, &hdr);
3500 status = decode_putfh(&xdr);
3503 status = decode_open(&xdr, res);
3509 * Decode SETATTR response
3511 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3513 struct xdr_stream xdr;
3514 struct compound_hdr hdr;
3517 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3518 status = decode_compound_hdr(&xdr, &hdr);
3521 status = decode_putfh(&xdr);
3524 status = decode_setattr(&xdr, res);
3527 status = decode_getfattr(&xdr, res->fattr, res->server);
3528 if (status == NFS4ERR_DELAY)
3535 * Decode LOCK response
3537 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3539 struct xdr_stream xdr;
3540 struct compound_hdr hdr;
3543 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3544 status = decode_compound_hdr(&xdr, &hdr);
3547 status = decode_putfh(&xdr);
3550 status = decode_lock(&xdr, res);
3556 * Decode LOCKT response
3558 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3560 struct xdr_stream xdr;
3561 struct compound_hdr hdr;
3564 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3565 status = decode_compound_hdr(&xdr, &hdr);
3568 status = decode_putfh(&xdr);
3571 status = decode_lockt(&xdr, res);
3577 * Decode LOCKU response
3579 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3581 struct xdr_stream xdr;
3582 struct compound_hdr hdr;
3585 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3586 status = decode_compound_hdr(&xdr, &hdr);
3589 status = decode_putfh(&xdr);
3592 status = decode_locku(&xdr, res);
3598 * Decode READLINK response
3600 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3602 struct xdr_stream xdr;
3603 struct compound_hdr hdr;
3606 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3607 status = decode_compound_hdr(&xdr, &hdr);
3610 status = decode_putfh(&xdr);
3613 status = decode_readlink(&xdr, rqstp);
3619 * Decode READDIR response
3621 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3623 struct xdr_stream xdr;
3624 struct compound_hdr hdr;
3627 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3628 status = decode_compound_hdr(&xdr, &hdr);
3631 status = decode_putfh(&xdr);
3634 status = decode_readdir(&xdr, rqstp, res);
3640 * Decode Read response
3642 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3644 struct xdr_stream xdr;
3645 struct compound_hdr hdr;
3648 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3649 status = decode_compound_hdr(&xdr, &hdr);
3652 status = decode_putfh(&xdr);
3655 status = decode_read(&xdr, rqstp, res);
3657 status = res->count;
3663 * Decode WRITE response
3665 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *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_write(&xdr, res);
3680 status = res->count;
3686 * Decode COMMIT response
3688 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3690 struct xdr_stream xdr;
3691 struct compound_hdr hdr;
3694 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3695 status = decode_compound_hdr(&xdr, &hdr);
3698 status = decode_putfh(&xdr);
3701 status = decode_commit(&xdr, res);
3709 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3711 struct xdr_stream xdr;
3712 struct compound_hdr hdr;
3715 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3716 status = decode_compound_hdr(&xdr, &hdr);
3718 status = decode_putfh(&xdr);
3720 status = decode_fsinfo(&xdr, fsinfo);
3722 status = -nfs_stat_to_errno(hdr.status);
3729 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
3731 struct xdr_stream xdr;
3732 struct compound_hdr hdr;
3735 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3736 status = decode_compound_hdr(&xdr, &hdr);
3738 status = decode_putfh(&xdr);
3740 status = decode_pathconf(&xdr, pathconf);
3747 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
3749 struct xdr_stream xdr;
3750 struct compound_hdr hdr;
3753 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3754 status = decode_compound_hdr(&xdr, &hdr);
3756 status = decode_putfh(&xdr);
3758 status = decode_statfs(&xdr, fsstat);
3763 * GETATTR_BITMAP request
3765 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
3767 struct xdr_stream xdr;
3768 struct compound_hdr hdr;
3771 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3772 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3774 if ((status = decode_putfh(&xdr)) != 0)
3776 status = decode_server_caps(&xdr, res);
3782 * Decode RENEW response
3784 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3786 struct xdr_stream xdr;
3787 struct compound_hdr hdr;
3790 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3791 status = decode_compound_hdr(&xdr, &hdr);
3793 status = decode_renew(&xdr);
3798 * a SETCLIENTID request
3800 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
3801 struct nfs4_client *clp)
3803 struct xdr_stream xdr;
3804 struct compound_hdr hdr;
3807 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3808 status = decode_compound_hdr(&xdr, &hdr);
3810 status = decode_setclientid(&xdr, clp);
3812 status = -nfs_stat_to_errno(hdr.status);
3817 * a SETCLIENTID_CONFIRM request
3819 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3821 struct xdr_stream xdr;
3822 struct compound_hdr hdr;
3825 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3826 status = decode_compound_hdr(&xdr, &hdr);
3828 status = decode_setclientid_confirm(&xdr);
3830 status = decode_putrootfh(&xdr);
3832 status = decode_fsinfo(&xdr, fsinfo);
3834 status = -nfs_stat_to_errno(hdr.status);
3839 * DELEGRETURN request
3841 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3843 struct xdr_stream xdr;
3844 struct compound_hdr hdr;
3847 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3848 status = decode_compound_hdr(&xdr, &hdr);
3850 status = decode_putfh(&xdr);
3852 status = decode_delegreturn(&xdr);
3857 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
3859 uint32_t bitmap[2] = {0};
3864 return ERR_PTR(-EAGAIN);
3866 return ERR_PTR(-EBADCOOKIE);
3869 entry->prev_cookie = entry->cookie;
3870 p = xdr_decode_hyper(p, &entry->cookie);
3871 entry->len = ntohl(*p++);
3872 entry->name = (const char *) p;
3873 p += XDR_QUADLEN(entry->len);
3876 * In case the server doesn't return an inode number,
3877 * we fake one here. (We don't use inode number 0,
3878 * since glibc seems to choke on it...)
3882 len = ntohl(*p++); /* bitmap length */
3884 bitmap[0] = ntohl(*p++);
3886 bitmap[1] = ntohl(*p++);
3890 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
3892 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
3893 xdr_decode_hyper(p, &entry->ino);
3894 else if (bitmap[0] == FATTR4_WORD0_FILEID)
3895 xdr_decode_hyper(p, &entry->ino);
3899 entry->eof = !p[0] && p[1];
3904 * We need to translate between nfs status return values and
3905 * the local errno values which may not be the same.
3912 { NFS4ERR_PERM, EPERM },
3913 { NFS4ERR_NOENT, ENOENT },
3914 { NFS4ERR_IO, errno_NFSERR_IO },
3915 { NFS4ERR_NXIO, ENXIO },
3916 { NFS4ERR_ACCESS, EACCES },
3917 { NFS4ERR_EXIST, EEXIST },
3918 { NFS4ERR_XDEV, EXDEV },
3919 { NFS4ERR_NOTDIR, ENOTDIR },
3920 { NFS4ERR_ISDIR, EISDIR },
3921 { NFS4ERR_INVAL, EINVAL },
3922 { NFS4ERR_FBIG, EFBIG },
3923 { NFS4ERR_NOSPC, ENOSPC },
3924 { NFS4ERR_ROFS, EROFS },
3925 { NFS4ERR_MLINK, EMLINK },
3926 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
3927 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
3928 { NFS4ERR_DQUOT, EDQUOT },
3929 { NFS4ERR_STALE, ESTALE },
3930 { NFS4ERR_BADHANDLE, EBADHANDLE },
3931 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
3932 { NFS4ERR_NOTSUPP, ENOTSUPP },
3933 { NFS4ERR_TOOSMALL, ETOOSMALL },
3934 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
3935 { NFS4ERR_BADTYPE, EBADTYPE },
3936 { NFS4ERR_LOCKED, EAGAIN },
3937 { NFS4ERR_RESOURCE, EREMOTEIO },
3938 { NFS4ERR_SYMLINK, ELOOP },
3939 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
3940 { NFS4ERR_DEADLOCK, EDEADLK },
3941 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
3942 * to be handled by a
3949 * Convert an NFS error code to a local one.
3950 * This one is used jointly by NFSv2 and NFSv3.
3953 nfs_stat_to_errno(int stat)
3956 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
3957 if (nfs_errtbl[i].stat == stat)
3958 return nfs_errtbl[i].errno;
3960 if (stat <= 10000 || stat > 10100) {
3961 /* The server is looney tunes. */
3962 return ESERVERFAULT;
3964 /* If we cannot translate the error, the recovery routines should
3966 * Note: remaining NFSv4 error codes have values > 10000, so should
3967 * not conflict with native Linux error codes.
3973 # define MAX(a, b) (((a) > (b))? (a) : (b))
3976 #define PROC(proc, argtype, restype) \
3977 [NFSPROC4_CLNT_##proc] = { \
3978 .p_proc = NFSPROC4_COMPOUND, \
3979 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
3980 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
3981 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
3984 struct rpc_procinfo nfs4_procedures[] = {
3985 PROC(READ, enc_read, dec_read),
3986 PROC(WRITE, enc_write, dec_write),
3987 PROC(COMMIT, enc_commit, dec_commit),
3988 PROC(OPEN, enc_open, dec_open),
3989 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
3990 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
3991 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
3992 PROC(CLOSE, enc_close, dec_close),
3993 PROC(SETATTR, enc_setattr, dec_setattr),
3994 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
3995 PROC(RENEW, enc_renew, dec_renew),
3996 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
3997 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
3998 PROC(LOCK, enc_lock, dec_lock),
3999 PROC(LOCKT, enc_lockt, dec_lockt),
4000 PROC(LOCKU, enc_locku, dec_locku),
4001 PROC(ACCESS, enc_access, dec_access),
4002 PROC(GETATTR, enc_getattr, dec_getattr),
4003 PROC(LOOKUP, enc_lookup, dec_lookup),
4004 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4005 PROC(REMOVE, enc_remove, dec_remove),
4006 PROC(RENAME, enc_rename, dec_rename),
4007 PROC(LINK, enc_link, dec_link),
4008 PROC(SYMLINK, enc_symlink, dec_symlink),
4009 PROC(CREATE, enc_create, dec_create),
4010 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4011 PROC(STATFS, enc_statfs, dec_statfs),
4012 PROC(READLINK, enc_readlink, dec_readlink),
4013 PROC(READDIR, enc_readdir, dec_readdir),
4014 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4015 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4018 struct rpc_version nfs_version4 = {
4020 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
4021 .procs = nfs4_procedures