4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define owner_id_maxsz (1 + 1)
74 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
75 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
76 #define op_encode_hdr_maxsz (1)
77 #define op_decode_hdr_maxsz (2)
78 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
80 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
81 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
82 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
83 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
84 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
85 ((3+NFS4_FHSIZE) >> 2))
86 #define nfs4_fattr_bitmap_maxsz 3
87 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
88 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
89 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
90 /* This is based on getfattr, which uses the most attributes: */
91 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
92 3 + 3 + 3 + 2 * nfs4_name_maxsz))
93 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
94 nfs4_fattr_value_maxsz)
95 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
96 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
97 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
98 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
99 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
100 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
101 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
102 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
103 #define decode_renew_maxsz (op_decode_hdr_maxsz)
104 #define encode_setclientid_maxsz \
105 (op_encode_hdr_maxsz + \
106 4 /*server->ip_addr*/ + \
109 6 + (NFS4_VERIFIER_SIZE >> 2))
110 #define decode_setclientid_maxsz \
111 (op_decode_hdr_maxsz + \
113 1024) /* large value for CLID_INUSE */
114 #define encode_setclientid_confirm_maxsz \
115 (op_encode_hdr_maxsz + \
116 3 + (NFS4_VERIFIER_SIZE >> 2))
117 #define decode_setclientid_confirm_maxsz \
118 (op_decode_hdr_maxsz)
119 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
120 1 + ((3 + NFS4_FHSIZE) >> 2))
121 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
123 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
125 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
126 #define encode_link_maxsz (op_encode_hdr_maxsz + \
128 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
129 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
130 1 + nfs4_name_maxsz + \
133 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
134 #define encode_create_maxsz (op_encode_hdr_maxsz + \
135 2 + nfs4_name_maxsz + \
137 #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
138 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
139 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
140 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
141 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
142 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
143 encode_putfh_maxsz + \
144 op_encode_hdr_maxsz + 7)
145 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
146 decode_putfh_maxsz + \
147 op_decode_hdr_maxsz + 2)
148 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
149 encode_putfh_maxsz + \
151 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
152 decode_putfh_maxsz + \
154 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
155 encode_putfh_maxsz + \
156 op_encode_hdr_maxsz + 9)
157 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
158 decode_putfh_maxsz + \
159 op_decode_hdr_maxsz + 2)
160 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
161 encode_putfh_maxsz + \
162 op_encode_hdr_maxsz + 8 + \
163 encode_getattr_maxsz)
164 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
165 decode_putfh_maxsz + \
166 op_decode_hdr_maxsz + 4 + \
167 decode_getattr_maxsz)
168 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
169 encode_putfh_maxsz + \
170 op_encode_hdr_maxsz + 3 + \
171 encode_getattr_maxsz)
172 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
173 decode_putfh_maxsz + \
174 op_decode_hdr_maxsz + 2 + \
175 decode_getattr_maxsz)
176 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
177 encode_putfh_maxsz + \
178 op_encode_hdr_maxsz + \
180 encode_getattr_maxsz + \
182 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
183 decode_putfh_maxsz + \
184 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
185 decode_getattr_maxsz + \
187 #define NFS4_enc_open_confirm_sz \
188 (compound_encode_hdr_maxsz + \
189 encode_putfh_maxsz + \
190 op_encode_hdr_maxsz + 5)
191 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
192 decode_putfh_maxsz + \
193 op_decode_hdr_maxsz + 4)
194 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
195 encode_putfh_maxsz + \
196 op_encode_hdr_maxsz + \
198 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
199 decode_putfh_maxsz + \
200 op_decode_hdr_maxsz + \
202 #define NFS4_enc_open_downgrade_sz \
203 (compound_encode_hdr_maxsz + \
204 encode_putfh_maxsz + \
205 op_encode_hdr_maxsz + 7 + \
206 encode_getattr_maxsz)
207 #define NFS4_dec_open_downgrade_sz \
208 (compound_decode_hdr_maxsz + \
209 decode_putfh_maxsz + \
210 op_decode_hdr_maxsz + 4 + \
211 decode_getattr_maxsz)
212 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
213 encode_putfh_maxsz + \
214 op_encode_hdr_maxsz + 5 + \
215 encode_getattr_maxsz)
216 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
217 decode_putfh_maxsz + \
218 op_decode_hdr_maxsz + 4 + \
219 decode_getattr_maxsz)
220 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
221 encode_putfh_maxsz + \
222 op_encode_hdr_maxsz + 4 + \
224 encode_getattr_maxsz)
225 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
226 decode_putfh_maxsz + \
227 op_decode_hdr_maxsz + 3)
228 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
229 encode_putfh_maxsz + \
231 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
232 decode_putfh_maxsz + \
234 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
236 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
238 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
239 encode_setclientid_maxsz)
240 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
241 decode_setclientid_maxsz)
242 #define NFS4_enc_setclientid_confirm_sz \
243 (compound_encode_hdr_maxsz + \
244 encode_setclientid_confirm_maxsz + \
245 encode_putrootfh_maxsz + \
247 #define NFS4_dec_setclientid_confirm_sz \
248 (compound_decode_hdr_maxsz + \
249 decode_setclientid_confirm_maxsz + \
250 decode_putrootfh_maxsz + \
252 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
253 encode_putfh_maxsz + \
254 encode_getattr_maxsz + \
255 op_encode_hdr_maxsz + \
259 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
260 decode_putfh_maxsz + \
261 decode_getattr_maxsz + \
262 op_decode_hdr_maxsz + \
265 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
266 encode_putfh_maxsz + \
267 encode_getattr_maxsz + \
268 op_encode_hdr_maxsz + \
271 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
272 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
273 encode_putfh_maxsz + \
274 encode_getattr_maxsz + \
275 op_encode_hdr_maxsz + \
277 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
278 decode_putfh_maxsz + \
279 decode_getattr_maxsz + \
280 op_decode_hdr_maxsz + 4)
281 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
282 encode_putfh_maxsz + \
283 op_encode_hdr_maxsz + 1)
284 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
285 decode_putfh_maxsz + \
286 op_decode_hdr_maxsz + 2)
287 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
288 encode_putfh_maxsz + \
289 encode_getattr_maxsz)
290 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
291 decode_putfh_maxsz + \
292 decode_getattr_maxsz)
293 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
294 encode_putfh_maxsz + \
295 encode_lookup_maxsz + \
296 encode_getattr_maxsz + \
298 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
299 decode_putfh_maxsz + \
300 op_decode_hdr_maxsz + \
301 decode_getattr_maxsz + \
303 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
304 encode_putrootfh_maxsz + \
305 encode_getattr_maxsz + \
307 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
308 decode_putrootfh_maxsz + \
309 decode_getattr_maxsz + \
311 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
312 encode_putfh_maxsz + \
313 encode_remove_maxsz + \
314 encode_getattr_maxsz)
315 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
316 decode_putfh_maxsz + \
317 op_decode_hdr_maxsz + 5 + \
318 decode_getattr_maxsz)
319 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
320 encode_putfh_maxsz + \
321 encode_savefh_maxsz + \
322 encode_putfh_maxsz + \
323 encode_rename_maxsz + \
324 encode_getattr_maxsz + \
325 encode_restorefh_maxsz + \
326 encode_getattr_maxsz)
327 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
328 decode_putfh_maxsz + \
329 decode_savefh_maxsz + \
330 decode_putfh_maxsz + \
331 decode_rename_maxsz + \
332 decode_getattr_maxsz + \
333 decode_restorefh_maxsz + \
334 decode_getattr_maxsz)
335 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
336 encode_putfh_maxsz + \
337 encode_savefh_maxsz + \
338 encode_putfh_maxsz + \
339 encode_link_maxsz + \
340 decode_getattr_maxsz + \
341 encode_restorefh_maxsz + \
342 decode_getattr_maxsz)
343 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
344 decode_putfh_maxsz + \
345 decode_savefh_maxsz + \
346 decode_putfh_maxsz + \
347 decode_link_maxsz + \
348 decode_getattr_maxsz + \
349 decode_restorefh_maxsz + \
350 decode_getattr_maxsz)
351 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
352 encode_putfh_maxsz + \
353 encode_symlink_maxsz + \
354 encode_getattr_maxsz + \
356 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
357 decode_putfh_maxsz + \
358 decode_symlink_maxsz + \
359 decode_getattr_maxsz + \
361 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
362 encode_putfh_maxsz + \
363 encode_savefh_maxsz + \
364 encode_create_maxsz + \
365 encode_getfh_maxsz + \
366 encode_getattr_maxsz + \
367 encode_restorefh_maxsz + \
368 encode_getattr_maxsz)
369 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
370 decode_putfh_maxsz + \
371 decode_savefh_maxsz + \
372 decode_create_maxsz + \
373 decode_getfh_maxsz + \
374 decode_getattr_maxsz + \
375 decode_restorefh_maxsz + \
376 decode_getattr_maxsz)
377 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
379 encode_getattr_maxsz)
380 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
381 decode_putfh_maxsz + \
382 decode_getattr_maxsz)
383 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_getattr_maxsz)
386 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
387 decode_putfh_maxsz + \
388 op_decode_hdr_maxsz + 12)
389 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
390 encode_getattr_maxsz)
391 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
392 decode_getattr_maxsz)
393 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
394 encode_putfh_maxsz + \
395 encode_delegreturn_maxsz + \
396 encode_getattr_maxsz)
397 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
398 decode_delegreturn_maxsz + \
399 decode_getattr_maxsz)
400 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
401 encode_putfh_maxsz + \
402 encode_getattr_maxsz)
403 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
404 decode_putfh_maxsz + \
405 op_decode_hdr_maxsz + \
406 nfs4_fattr_bitmap_maxsz + 1)
407 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
408 encode_putfh_maxsz + \
409 op_encode_hdr_maxsz + 4 + \
410 nfs4_fattr_bitmap_maxsz + 1)
411 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
412 decode_putfh_maxsz + \
413 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
417 unsigned int nfs2type;
425 { S_IFSOCK, NFSOCK },
431 struct compound_hdr {
439 * START OF "GENERIC" ENCODE ROUTINES.
440 * These may look a little ugly since they are imported from a "generic"
441 * set of XDR encode/decode routines which are intended to be shared by
442 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
444 * If the pain of reading these is too great, it should be a straightforward
445 * task to translate them into Linux-specific versions which are more
446 * consistent with the style used in NFSv2/v3...
448 #define WRITE32(n) *p++ = htonl(n)
449 #define WRITE64(n) do { \
450 *p++ = htonl((uint32_t)((n) >> 32)); \
451 *p++ = htonl((uint32_t)(n)); \
453 #define WRITEMEM(ptr,nbytes) do { \
454 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
457 #define RESERVE_SPACE(nbytes) do { \
458 p = xdr_reserve_space(xdr, nbytes); \
459 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
463 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
467 p = xdr_reserve_space(xdr, 4 + len);
469 xdr_encode_opaque(p, str, len);
472 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
476 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
477 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
478 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
479 WRITE32(hdr->taglen);
480 WRITEMEM(hdr->tag, hdr->taglen);
481 WRITE32(NFS4_MINOR_VERSION);
486 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
490 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
492 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
495 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
497 char owner_name[IDMAP_NAMESZ];
498 char owner_group[IDMAP_NAMESZ];
499 int owner_namelen = 0;
500 int owner_grouplen = 0;
509 * We reserve enough space to write the entire attribute buffer at once.
510 * In the worst-case, this would be
511 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
512 * = 36 bytes, plus any contribution from variable-length fields
513 * such as owner/group.
518 if (iap->ia_valid & ATTR_SIZE)
520 if (iap->ia_valid & ATTR_MODE)
522 if (iap->ia_valid & ATTR_UID) {
523 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
524 if (owner_namelen < 0) {
525 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
528 strcpy(owner_name, "nobody");
529 owner_namelen = sizeof("nobody") - 1;
532 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
534 if (iap->ia_valid & ATTR_GID) {
535 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
536 if (owner_grouplen < 0) {
537 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
539 strcpy(owner_group, "nobody");
540 owner_grouplen = sizeof("nobody") - 1;
543 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
545 if (iap->ia_valid & ATTR_ATIME_SET)
547 else if (iap->ia_valid & ATTR_ATIME)
549 if (iap->ia_valid & ATTR_MTIME_SET)
551 else if (iap->ia_valid & ATTR_MTIME)
556 * We write the bitmap length now, but leave the bitmap and the attribute
557 * buffer length to be backfilled at the end of this routine.
563 if (iap->ia_valid & ATTR_SIZE) {
564 bmval0 |= FATTR4_WORD0_SIZE;
565 WRITE64(iap->ia_size);
567 if (iap->ia_valid & ATTR_MODE) {
568 bmval1 |= FATTR4_WORD1_MODE;
569 WRITE32(iap->ia_mode & S_IALLUGO);
571 if (iap->ia_valid & ATTR_UID) {
572 bmval1 |= FATTR4_WORD1_OWNER;
573 WRITE32(owner_namelen);
574 WRITEMEM(owner_name, owner_namelen);
576 if (iap->ia_valid & ATTR_GID) {
577 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
578 WRITE32(owner_grouplen);
579 WRITEMEM(owner_group, owner_grouplen);
581 if (iap->ia_valid & ATTR_ATIME_SET) {
582 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
583 WRITE32(NFS4_SET_TO_CLIENT_TIME);
585 WRITE32(iap->ia_mtime.tv_sec);
586 WRITE32(iap->ia_mtime.tv_nsec);
588 else if (iap->ia_valid & ATTR_ATIME) {
589 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
590 WRITE32(NFS4_SET_TO_SERVER_TIME);
592 if (iap->ia_valid & ATTR_MTIME_SET) {
593 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
594 WRITE32(NFS4_SET_TO_CLIENT_TIME);
596 WRITE32(iap->ia_mtime.tv_sec);
597 WRITE32(iap->ia_mtime.tv_nsec);
599 else if (iap->ia_valid & ATTR_MTIME) {
600 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
601 WRITE32(NFS4_SET_TO_SERVER_TIME);
605 * Now we backfill the bitmap and the attribute buffer length.
607 if (len != ((char *)p - (char *)q) + 4) {
608 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
609 len, ((char *)p - (char *)q) + 4);
612 len = (char *)p - (char *)q - 12;
613 *q++ = htonl(bmval0);
614 *q++ = htonl(bmval1);
622 static int encode_access(struct xdr_stream *xdr, u32 access)
633 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
637 RESERVE_SPACE(8+sizeof(arg->stateid->data));
639 WRITE32(arg->seqid->sequence->counter);
640 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
645 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
651 WRITE64(args->offset);
652 WRITE32(args->count);
657 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
663 WRITE32(create->ftype);
665 switch (create->ftype) {
667 RESERVE_SPACE(4 + create->u.symlink->len);
668 WRITE32(create->u.symlink->len);
669 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
672 case NF4BLK: case NF4CHR:
674 WRITE32(create->u.device.specdata1);
675 WRITE32(create->u.device.specdata2);
682 RESERVE_SPACE(4 + create->name->len);
683 WRITE32(create->name->len);
684 WRITEMEM(create->name->name, create->name->len);
686 return encode_attrs(xdr, create->attrs, create->server);
689 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
700 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
712 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
714 return encode_getattr_two(xdr,
715 bitmask[0] & nfs4_fattr_bitmap[0],
716 bitmask[1] & nfs4_fattr_bitmap[1]);
719 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
721 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
722 bitmask[1] & nfs4_fsinfo_bitmap[1]);
725 static int encode_getfh(struct xdr_stream *xdr)
735 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
739 RESERVE_SPACE(8 + name->len);
742 WRITEMEM(name->name, name->len);
747 static inline int nfs4_lock_type(struct file_lock *fl, int block)
749 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
750 return block ? NFS4_READW_LT : NFS4_READ_LT;
751 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
754 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
756 if (fl->fl_end == OFFSET_MAX)
758 return fl->fl_end - fl->fl_start + 1;
762 * opcode,type,reclaim,offset,length,new_lock_owner = 32
763 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
765 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
771 WRITE32(nfs4_lock_type(args->fl, args->block));
772 WRITE32(args->reclaim);
773 WRITE64(args->fl->fl_start);
774 WRITE64(nfs4_lock_length(args->fl));
775 WRITE32(args->new_lock_owner);
776 if (args->new_lock_owner){
778 WRITE32(args->open_seqid->sequence->counter);
779 WRITEMEM(args->open_stateid->data, sizeof(args->open_stateid->data));
780 WRITE32(args->lock_seqid->sequence->counter);
781 WRITE64(args->lock_owner.clientid);
783 WRITE32(args->lock_owner.id);
787 WRITEMEM(args->lock_stateid->data, sizeof(args->lock_stateid->data));
788 WRITE32(args->lock_seqid->sequence->counter);
794 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
800 WRITE32(nfs4_lock_type(args->fl, 0));
801 WRITE64(args->fl->fl_start);
802 WRITE64(nfs4_lock_length(args->fl));
803 WRITE64(args->lock_owner.clientid);
805 WRITE32(args->lock_owner.id);
810 static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
816 WRITE32(nfs4_lock_type(args->fl, 0));
817 WRITE32(args->seqid->sequence->counter);
818 WRITEMEM(args->stateid->data, sizeof(args->stateid->data));
819 WRITE64(args->fl->fl_start);
820 WRITE64(nfs4_lock_length(args->fl));
825 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
830 RESERVE_SPACE(8 + len);
833 WRITEMEM(name->name, len);
838 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
843 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
845 WRITE32(NFS4_SHARE_ACCESS_READ);
848 WRITE32(NFS4_SHARE_ACCESS_WRITE);
850 case FMODE_READ|FMODE_WRITE:
851 WRITE32(NFS4_SHARE_ACCESS_BOTH);
856 WRITE32(0); /* for linux, share_deny = 0 always */
859 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
863 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
868 WRITE32(arg->seqid->sequence->counter);
869 encode_share_access(xdr, arg->open_flags);
871 WRITE64(arg->clientid);
876 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
881 switch(arg->open_flags & O_EXCL) {
883 WRITE32(NFS4_CREATE_UNCHECKED);
884 encode_attrs(xdr, arg->u.attrs, arg->server);
887 WRITE32(NFS4_CREATE_EXCLUSIVE);
888 encode_nfs4_verifier(xdr, &arg->u.verifier);
892 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
897 switch (arg->open_flags & O_CREAT) {
899 WRITE32(NFS4_OPEN_NOCREATE);
902 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
903 WRITE32(NFS4_OPEN_CREATE);
904 encode_createmode(xdr, arg);
908 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
913 switch (delegation_type) {
915 WRITE32(NFS4_OPEN_DELEGATE_NONE);
918 WRITE32(NFS4_OPEN_DELEGATE_READ);
920 case FMODE_WRITE|FMODE_READ:
921 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
928 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
933 WRITE32(NFS4_OPEN_CLAIM_NULL);
934 encode_string(xdr, name->len, name->name);
937 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
942 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
943 encode_delegation_type(xdr, type);
946 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
950 RESERVE_SPACE(4+sizeof(stateid->data));
951 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
952 WRITEMEM(stateid->data, sizeof(stateid->data));
953 encode_string(xdr, name->len, name->name);
956 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
958 encode_openhdr(xdr, arg);
959 encode_opentype(xdr, arg);
960 switch (arg->claim) {
961 case NFS4_OPEN_CLAIM_NULL:
962 encode_claim_null(xdr, arg->name);
964 case NFS4_OPEN_CLAIM_PREVIOUS:
965 encode_claim_previous(xdr, arg->u.delegation_type);
967 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
968 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
976 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
980 RESERVE_SPACE(8+sizeof(arg->stateid->data));
981 WRITE32(OP_OPEN_CONFIRM);
982 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
983 WRITE32(arg->seqid->sequence->counter);
988 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
992 RESERVE_SPACE(8+sizeof(arg->stateid->data));
993 WRITE32(OP_OPEN_DOWNGRADE);
994 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
995 WRITE32(arg->seqid->sequence->counter);
996 encode_share_access(xdr, arg->open_flags);
1001 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1006 RESERVE_SPACE(8 + len);
1009 WRITEMEM(fh->data, len);
1014 static int encode_putrootfh(struct xdr_stream *xdr)
1019 WRITE32(OP_PUTROOTFH);
1024 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1026 nfs4_stateid stateid;
1030 if (ctx->state != NULL) {
1031 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1032 WRITEMEM(stateid.data, sizeof(stateid.data));
1034 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1037 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1044 encode_stateid(xdr, args->context);
1047 WRITE64(args->offset);
1048 WRITE32(args->count);
1053 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1055 struct rpc_auth *auth = req->rq_task->tk_auth;
1056 uint32_t attrs[2] = {
1057 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1058 FATTR4_WORD1_MOUNTED_ON_FILEID,
1063 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1064 WRITE32(OP_READDIR);
1065 WRITE64(readdir->cookie);
1066 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1067 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1068 WRITE32(readdir->count);
1070 /* Switch to mounted_on_fileid if the server supports it */
1071 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1072 attrs[0] &= ~FATTR4_WORD0_FILEID;
1074 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1075 WRITE32(attrs[0] & readdir->bitmask[0]);
1076 WRITE32(attrs[1] & readdir->bitmask[1]);
1077 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1079 (unsigned long long)readdir->cookie,
1080 ((u32 *)readdir->verifier.data)[0],
1081 ((u32 *)readdir->verifier.data)[1],
1082 attrs[0] & readdir->bitmask[0],
1083 attrs[1] & readdir->bitmask[1]);
1085 /* set up reply kvec
1086 * toplevel_status + taglen + rescount + OP_PUTFH + status
1087 * + OP_READDIR + status + verifer(2) = 9
1089 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1090 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1091 readdir->pgbase, readdir->count);
1092 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1093 __FUNCTION__, replen, readdir->pages,
1094 readdir->pgbase, readdir->count);
1099 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1101 struct rpc_auth *auth = req->rq_task->tk_auth;
1102 unsigned int replen;
1106 WRITE32(OP_READLINK);
1108 /* set up reply kvec
1109 * toplevel_status + taglen + rescount + OP_PUTFH + status
1110 * + OP_READLINK + status + string length = 8
1112 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1113 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1114 readlink->pgbase, readlink->pglen);
1119 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1123 RESERVE_SPACE(8 + name->len);
1126 WRITEMEM(name->name, name->len);
1131 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1135 RESERVE_SPACE(8 + oldname->len);
1137 WRITE32(oldname->len);
1138 WRITEMEM(oldname->name, oldname->len);
1140 RESERVE_SPACE(4 + newname->len);
1141 WRITE32(newname->len);
1142 WRITEMEM(newname->name, newname->len);
1147 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1153 WRITE64(client_stateid->cl_clientid);
1159 encode_restorefh(struct xdr_stream *xdr)
1164 WRITE32(OP_RESTOREFH);
1170 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1174 RESERVE_SPACE(4+sizeof(zero_stateid.data));
1175 WRITE32(OP_SETATTR);
1176 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1179 WRITE32(FATTR4_WORD0_ACL);
1180 if (arg->acl_len % 4)
1183 WRITE32(arg->acl_len);
1184 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1189 encode_savefh(struct xdr_stream *xdr)
1199 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1204 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1205 WRITE32(OP_SETATTR);
1206 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1208 if ((status = encode_attrs(xdr, arg->iap, server)))
1214 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1218 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1219 WRITE32(OP_SETCLIENTID);
1220 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1222 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1224 WRITE32(setclientid->sc_prog);
1225 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1226 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1228 WRITE32(setclientid->sc_cb_ident);
1233 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1237 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1238 WRITE32(OP_SETCLIENTID_CONFIRM);
1239 WRITE64(client_state->cl_clientid);
1240 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1245 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1252 encode_stateid(xdr, args->context);
1255 WRITE64(args->offset);
1256 WRITE32(args->stable);
1257 WRITE32(args->count);
1259 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1264 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1270 WRITE32(OP_DELEGRETURN);
1271 WRITEMEM(stateid->data, sizeof(stateid->data));
1276 * END OF "GENERIC" ENCODE ROUTINES.
1280 * Encode an ACCESS request
1282 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1284 struct xdr_stream xdr;
1285 struct compound_hdr hdr = {
1290 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1291 encode_compound_hdr(&xdr, &hdr);
1292 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1293 status = encode_access(&xdr, args->access);
1298 * Encode LOOKUP request
1300 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1302 struct xdr_stream xdr;
1303 struct compound_hdr hdr = {
1308 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1309 encode_compound_hdr(&xdr, &hdr);
1310 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1312 if ((status = encode_lookup(&xdr, args->name)) != 0)
1314 if ((status = encode_getfh(&xdr)) != 0)
1316 status = encode_getfattr(&xdr, args->bitmask);
1322 * Encode LOOKUP_ROOT request
1324 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1326 struct xdr_stream xdr;
1327 struct compound_hdr hdr = {
1332 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1333 encode_compound_hdr(&xdr, &hdr);
1334 if ((status = encode_putrootfh(&xdr)) != 0)
1336 if ((status = encode_getfh(&xdr)) == 0)
1337 status = encode_getfattr(&xdr, args->bitmask);
1343 * Encode REMOVE request
1345 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1347 struct xdr_stream xdr;
1348 struct compound_hdr hdr = {
1353 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1354 encode_compound_hdr(&xdr, &hdr);
1355 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1357 if ((status = encode_remove(&xdr, args->name)) != 0)
1359 status = encode_getfattr(&xdr, args->bitmask);
1365 * Encode RENAME request
1367 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1369 struct xdr_stream xdr;
1370 struct compound_hdr hdr = {
1375 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1376 encode_compound_hdr(&xdr, &hdr);
1377 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1379 if ((status = encode_savefh(&xdr)) != 0)
1381 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1383 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1385 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1387 if ((status = encode_restorefh(&xdr)) != 0)
1389 status = encode_getfattr(&xdr, args->bitmask);
1395 * Encode LINK request
1397 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1399 struct xdr_stream xdr;
1400 struct compound_hdr hdr = {
1405 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1406 encode_compound_hdr(&xdr, &hdr);
1407 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1409 if ((status = encode_savefh(&xdr)) != 0)
1411 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1413 if ((status = encode_link(&xdr, args->name)) != 0)
1415 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1417 if ((status = encode_restorefh(&xdr)) != 0)
1419 status = encode_getfattr(&xdr, args->bitmask);
1425 * Encode CREATE request
1427 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1429 struct xdr_stream xdr;
1430 struct compound_hdr hdr = {
1435 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1436 encode_compound_hdr(&xdr, &hdr);
1437 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1439 if ((status = encode_savefh(&xdr)) != 0)
1441 if ((status = encode_create(&xdr, args)) != 0)
1443 if ((status = encode_getfh(&xdr)) != 0)
1445 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1447 if ((status = encode_restorefh(&xdr)) != 0)
1449 status = encode_getfattr(&xdr, args->bitmask);
1455 * Encode SYMLINK request
1457 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1459 return nfs4_xdr_enc_create(req, p, args);
1463 * Encode GETATTR request
1465 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1467 struct xdr_stream xdr;
1468 struct compound_hdr hdr = {
1473 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1474 encode_compound_hdr(&xdr, &hdr);
1475 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1476 status = encode_getfattr(&xdr, args->bitmask);
1481 * Encode a CLOSE request
1483 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1485 struct xdr_stream xdr;
1486 struct compound_hdr hdr = {
1491 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1492 encode_compound_hdr(&xdr, &hdr);
1493 status = encode_putfh(&xdr, args->fh);
1496 status = encode_close(&xdr, args);
1499 status = encode_getfattr(&xdr, args->bitmask);
1505 * Encode an OPEN request
1507 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1509 struct xdr_stream xdr;
1510 struct compound_hdr hdr = {
1515 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1516 encode_compound_hdr(&xdr, &hdr);
1517 status = encode_putfh(&xdr, args->fh);
1520 status = encode_savefh(&xdr);
1523 status = encode_open(&xdr, args);
1526 status = encode_getfh(&xdr);
1529 status = encode_getfattr(&xdr, args->bitmask);
1532 status = encode_restorefh(&xdr);
1535 status = encode_getfattr(&xdr, args->bitmask);
1541 * Encode an OPEN_CONFIRM request
1543 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1545 struct xdr_stream xdr;
1546 struct compound_hdr hdr = {
1551 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1552 encode_compound_hdr(&xdr, &hdr);
1553 status = encode_putfh(&xdr, args->fh);
1556 status = encode_open_confirm(&xdr, args);
1562 * Encode an OPEN request with no attributes.
1564 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1566 struct xdr_stream xdr;
1567 struct compound_hdr hdr = {
1572 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1573 encode_compound_hdr(&xdr, &hdr);
1574 status = encode_putfh(&xdr, args->fh);
1577 status = encode_open(&xdr, args);
1580 status = encode_getfattr(&xdr, args->bitmask);
1586 * Encode an OPEN_DOWNGRADE request
1588 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1590 struct xdr_stream xdr;
1591 struct compound_hdr hdr = {
1596 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1597 encode_compound_hdr(&xdr, &hdr);
1598 status = encode_putfh(&xdr, args->fh);
1601 status = encode_open_downgrade(&xdr, args);
1604 status = encode_getfattr(&xdr, args->bitmask);
1610 * Encode a LOCK request
1612 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lock_args *args)
1614 struct xdr_stream xdr;
1615 struct compound_hdr hdr = {
1620 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1621 encode_compound_hdr(&xdr, &hdr);
1622 status = encode_putfh(&xdr, args->fh);
1625 status = encode_lock(&xdr, args);
1631 * Encode a LOCKT request
1633 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockt_args *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_lockt(&xdr, args);
1652 * Encode a LOCKU request
1654 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_locku_args *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_locku(&xdr, args);
1673 * Encode a READLINK request
1675 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *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);
1688 status = encode_readlink(&xdr, args, req);
1694 * Encode a READDIR request
1696 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1698 struct xdr_stream xdr;
1699 struct compound_hdr hdr = {
1704 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1705 encode_compound_hdr(&xdr, &hdr);
1706 status = encode_putfh(&xdr, args->fh);
1709 status = encode_readdir(&xdr, args, req);
1715 * Encode a READ request
1717 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1719 struct rpc_auth *auth = req->rq_task->tk_auth;
1720 struct xdr_stream xdr;
1721 struct compound_hdr hdr = {
1726 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1727 encode_compound_hdr(&xdr, &hdr);
1728 status = encode_putfh(&xdr, args->fh);
1731 status = encode_read(&xdr, args);
1735 /* set up reply kvec
1736 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1737 * + OP_READ + status + eof + datalen = 9
1739 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1740 xdr_inline_pages(&req->rq_rcv_buf, replen,
1741 args->pages, args->pgbase, args->count);
1747 * Encode an SETATTR request
1749 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1752 struct xdr_stream xdr;
1753 struct compound_hdr hdr = {
1758 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1759 encode_compound_hdr(&xdr, &hdr);
1760 status = encode_putfh(&xdr, args->fh);
1763 status = encode_setattr(&xdr, args, args->server);
1766 status = encode_getfattr(&xdr, args->bitmask);
1772 * Encode a GETACL request
1775 nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p,
1776 struct nfs_getaclargs *args)
1778 struct xdr_stream xdr;
1779 struct rpc_auth *auth = req->rq_task->tk_auth;
1780 struct compound_hdr hdr = {
1785 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1786 encode_compound_hdr(&xdr, &hdr);
1787 status = encode_putfh(&xdr, args->fh);
1790 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1791 /* set up reply buffer: */
1792 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1793 xdr_inline_pages(&req->rq_rcv_buf, replen,
1794 args->acl_pages, args->acl_pgbase, args->acl_len);
1800 * Encode a WRITE request
1802 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1804 struct xdr_stream xdr;
1805 struct compound_hdr hdr = {
1810 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1811 encode_compound_hdr(&xdr, &hdr);
1812 status = encode_putfh(&xdr, args->fh);
1815 status = encode_write(&xdr, args);
1818 status = encode_getfattr(&xdr, args->bitmask);
1826 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1828 struct xdr_stream xdr;
1829 struct compound_hdr hdr = {
1834 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1835 encode_compound_hdr(&xdr, &hdr);
1836 status = encode_putfh(&xdr, args->fh);
1839 status = encode_commit(&xdr, args);
1842 status = encode_getfattr(&xdr, args->bitmask);
1850 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1852 struct xdr_stream xdr;
1853 struct compound_hdr hdr = {
1858 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1859 encode_compound_hdr(&xdr, &hdr);
1860 status = encode_putfh(&xdr, args->fh);
1862 status = encode_fsinfo(&xdr, args->bitmask);
1867 * a PATHCONF request
1869 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1871 struct xdr_stream xdr;
1872 struct compound_hdr hdr = {
1877 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1878 encode_compound_hdr(&xdr, &hdr);
1879 status = encode_putfh(&xdr, args->fh);
1881 status = encode_getattr_one(&xdr,
1882 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1889 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1891 struct xdr_stream xdr;
1892 struct compound_hdr hdr = {
1897 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1898 encode_compound_hdr(&xdr, &hdr);
1899 status = encode_putfh(&xdr, args->fh);
1901 status = encode_getattr_two(&xdr,
1902 args->bitmask[0] & nfs4_statfs_bitmap[0],
1903 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1908 * GETATTR_BITMAP request
1910 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1912 struct xdr_stream xdr;
1913 struct compound_hdr hdr = {
1918 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1919 encode_compound_hdr(&xdr, &hdr);
1920 status = encode_putfh(&xdr, fhandle);
1922 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1923 FATTR4_WORD0_LINK_SUPPORT|
1924 FATTR4_WORD0_SYMLINK_SUPPORT|
1925 FATTR4_WORD0_ACLSUPPORT);
1932 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1934 struct xdr_stream xdr;
1935 struct compound_hdr hdr = {
1939 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1940 encode_compound_hdr(&xdr, &hdr);
1941 return encode_renew(&xdr, clp);
1945 * a SETCLIENTID request
1947 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1949 struct xdr_stream xdr;
1950 struct compound_hdr hdr = {
1954 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1955 encode_compound_hdr(&xdr, &hdr);
1956 return encode_setclientid(&xdr, sc);
1960 * a SETCLIENTID_CONFIRM request
1962 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1964 struct xdr_stream xdr;
1965 struct compound_hdr hdr = {
1968 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1971 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1972 encode_compound_hdr(&xdr, &hdr);
1973 status = encode_setclientid_confirm(&xdr, clp);
1975 status = encode_putrootfh(&xdr);
1977 status = encode_fsinfo(&xdr, lease_bitmap);
1982 * DELEGRETURN request
1984 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1986 struct xdr_stream xdr;
1987 struct compound_hdr hdr = {
1992 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1993 encode_compound_hdr(&xdr, &hdr);
1994 status = encode_putfh(&xdr, args->fhandle);
1997 status = encode_delegreturn(&xdr, args->stateid);
2000 status = encode_getfattr(&xdr, args->bitmask);
2006 * START OF "GENERIC" DECODE ROUTINES.
2007 * These may look a little ugly since they are imported from a "generic"
2008 * set of XDR encode/decode routines which are intended to be shared by
2009 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2011 * If the pain of reading these is too great, it should be a straightforward
2012 * task to translate them into Linux-specific versions which are more
2013 * consistent with the style used in NFSv2/v3...
2015 #define READ32(x) (x) = ntohl(*p++)
2016 #define READ64(x) do { \
2017 (x) = (u64)ntohl(*p++) << 32; \
2018 (x) |= ntohl(*p++); \
2020 #define READTIME(x) do { \
2022 (x.tv_sec) = ntohl(*p++); \
2023 (x.tv_nsec) = ntohl(*p++); \
2025 #define COPYMEM(x,nbytes) do { \
2026 memcpy((x), p, nbytes); \
2027 p += XDR_QUADLEN(nbytes); \
2030 #define READ_BUF(nbytes) do { \
2031 p = xdr_inline_decode(xdr, nbytes); \
2033 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
2034 __FUNCTION__, __LINE__); \
2039 static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
2046 *string = (char *)p;
2050 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2055 READ32(hdr->status);
2056 READ32(hdr->taglen);
2058 READ_BUF(hdr->taglen + 4);
2059 hdr->tag = (char *)p;
2060 p += XDR_QUADLEN(hdr->taglen);
2065 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2073 if (opnum != expected) {
2075 "nfs4_decode_op_hdr: Server returned operation"
2076 " %d but we issued a request for %d\n",
2081 if (nfserr != NFS_OK)
2082 return -nfs_stat_to_errno(nfserr);
2087 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
2094 return decode_opaque_inline(xdr, &strlen, &str);
2097 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2104 bitmap[0] = bitmap[1] = 0;
2105 READ_BUF((bmlen << 2));
2114 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
2124 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2126 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2127 decode_attr_bitmap(xdr, bitmask);
2128 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2130 bitmask[0] = bitmask[1] = 0;
2131 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2135 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2140 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2142 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2145 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2146 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2149 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2151 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2155 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2160 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2162 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2165 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2167 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2168 (unsigned long long)*change);
2172 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2177 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2179 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2182 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2184 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2188 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2193 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2195 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2198 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2200 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2204 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2209 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2211 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2214 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2216 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2220 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2226 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2228 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2230 READ64(fsid->major);
2231 READ64(fsid->minor);
2232 bitmap[0] &= ~FATTR4_WORD0_FSID;
2234 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2235 (unsigned long long)fsid->major,
2236 (unsigned long long)fsid->minor);
2240 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2245 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2247 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2250 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2252 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2256 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2260 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2261 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2263 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2266 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2268 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2272 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2277 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2279 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2282 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2284 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2288 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2294 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2296 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2299 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2301 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2305 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2311 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2313 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2316 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2318 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2322 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2328 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2330 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2333 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2335 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2339 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2345 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2347 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2350 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2352 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2356 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2362 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2364 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2367 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2369 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2373 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2379 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2381 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2384 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2386 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2390 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2396 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2398 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2402 if (maxread > 0x7FFFFFFF)
2403 maxread = 0x7FFFFFFF;
2404 *res = (uint32_t)maxread;
2405 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2407 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2411 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2417 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2419 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2423 if (maxwrite > 0x7FFFFFFF)
2424 maxwrite = 0x7FFFFFFF;
2425 *res = (uint32_t)maxwrite;
2426 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2428 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2432 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2437 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2439 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2443 bitmap[1] &= ~FATTR4_WORD1_MODE;
2445 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2449 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2454 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2456 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2459 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2461 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2465 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2470 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2472 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2476 if (len < XDR_MAX_NETOBJ) {
2477 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2478 dprintk("%s: nfs_map_name_to_uid failed!\n",
2481 printk(KERN_WARNING "%s: name too long (%u)!\n",
2483 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2485 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2489 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2494 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2496 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2500 if (len < XDR_MAX_NETOBJ) {
2501 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2502 dprintk("%s: nfs_map_group_to_gid failed!\n",
2505 printk(KERN_WARNING "%s: name too long (%u)!\n",
2507 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2509 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2513 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2515 uint32_t major = 0, minor = 0, *p;
2518 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2520 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2526 tmp = MKDEV(major, minor);
2527 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2529 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2531 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2535 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2541 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2543 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2546 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2548 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2552 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2558 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2560 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2563 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2565 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2569 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2575 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2577 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2580 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2582 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2586 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2591 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2593 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2596 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2598 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2599 (unsigned long long)*used);
2603 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2612 time->tv_sec = (time_t)sec;
2613 time->tv_nsec = (long)nsec;
2617 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2623 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2625 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2626 status = decode_attr_time(xdr, time);
2627 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2629 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2633 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2639 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2641 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2642 status = decode_attr_time(xdr, time);
2643 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2645 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2649 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2655 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2657 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2658 status = decode_attr_time(xdr, time);
2659 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2661 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2665 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2667 unsigned int attrwords = XDR_QUADLEN(attrlen);
2668 unsigned int nwords = xdr->p - savep;
2670 if (unlikely(attrwords != nwords)) {
2671 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2674 (attrwords < nwords) ? '<' : '>',
2681 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2686 READ32(cinfo->atomic);
2687 READ64(cinfo->before);
2688 READ64(cinfo->after);
2692 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2698 status = decode_op_hdr(xdr, OP_ACCESS);
2704 access->supported = supp;
2705 access->access = acc;
2709 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2714 status = decode_op_hdr(xdr, OP_CLOSE);
2717 READ_BUF(sizeof(res->stateid.data));
2718 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2722 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2727 status = decode_op_hdr(xdr, OP_COMMIT);
2731 COPYMEM(res->verf->verifier, 8);
2735 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2741 status = decode_op_hdr(xdr, OP_CREATE);
2744 if ((status = decode_change_info(xdr, cinfo)))
2748 READ_BUF(bmlen << 2);
2752 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2759 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2761 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2763 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2765 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2767 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2769 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2771 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2773 status = verify_attr_len(xdr, savep, attrlen);
2775 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2779 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2786 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2788 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2790 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2793 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2795 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2797 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2799 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2801 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2803 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2806 status = verify_attr_len(xdr, savep, attrlen);
2808 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2812 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2819 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2821 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2823 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2826 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2828 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2831 status = verify_attr_len(xdr, savep, attrlen);
2833 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2837 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2843 int status, fmode = 0;
2845 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2847 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2850 fattr->bitmap[0] = bitmap[0];
2851 fattr->bitmap[1] = bitmap[1];
2853 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2857 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2859 fattr->type = nfs_type2fmt[type].nfs2type;
2860 fmode = nfs_type2fmt[type].mode;
2862 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2864 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2866 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2868 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2870 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2872 fattr->mode |= fmode;
2873 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2875 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2877 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2879 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2881 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2883 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2885 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2887 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2889 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
2890 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2892 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
2897 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2900 uint32_t attrlen, bitmap[2];
2903 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2905 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2907 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2910 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2912 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2914 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2916 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2918 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2919 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2921 fsinfo->wtpref = fsinfo->wtmax;
2923 status = verify_attr_len(xdr, savep, attrlen);
2925 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
2929 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2935 status = decode_op_hdr(xdr, OP_GETFH);
2938 /* Zero handle first to allow comparisons */
2939 memset(fh, 0, sizeof(*fh));
2943 if (len > NFS4_FHSIZE)
2947 COPYMEM(fh->data, len);
2951 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2955 status = decode_op_hdr(xdr, OP_LINK);
2958 return decode_change_info(xdr, cinfo);
2962 * We create the owner, so we know a proper owner.id length is 4.
2964 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
2966 uint64_t offset, length, clientid;
2968 uint32_t namelen, type;
2975 fl->fl_start = (loff_t)offset;
2976 fl->fl_end = fl->fl_start + (loff_t)length - 1;
2977 if (length == ~(uint64_t)0)
2978 fl->fl_end = OFFSET_MAX;
2979 fl->fl_type = F_WRLCK;
2981 fl->fl_type = F_RDLCK;
2987 return -NFS4ERR_DENIED;
2990 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
2995 status = decode_op_hdr(xdr, OP_LOCK);
2997 READ_BUF(sizeof(res->stateid.data));
2998 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2999 } else if (status == -NFS4ERR_DENIED)
3000 return decode_lock_denied(xdr, NULL);
3004 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3007 status = decode_op_hdr(xdr, OP_LOCKT);
3008 if (status == -NFS4ERR_DENIED)
3009 return decode_lock_denied(xdr, res->denied);
3013 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3018 status = decode_op_hdr(xdr, OP_LOCKU);
3020 READ_BUF(sizeof(res->stateid.data));
3021 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3026 static int decode_lookup(struct xdr_stream *xdr)
3028 return decode_op_hdr(xdr, OP_LOOKUP);
3031 /* This is too sick! */
3032 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3035 uint32_t limit_type, nblocks, blocksize;
3039 switch (limit_type) {
3046 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3051 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3054 uint32_t delegation_type;
3057 READ32(delegation_type);
3058 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3059 res->delegation_type = 0;
3063 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
3064 READ32(res->do_recall);
3065 switch (delegation_type) {
3066 case NFS4_OPEN_DELEGATE_READ:
3067 res->delegation_type = FMODE_READ;
3069 case NFS4_OPEN_DELEGATE_WRITE:
3070 res->delegation_type = FMODE_WRITE|FMODE_READ;
3071 if (decode_space_limit(xdr, &res->maxsize) < 0)
3074 return decode_ace(xdr, NULL, res->server->nfs4_state);
3077 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3083 status = decode_op_hdr(xdr, OP_OPEN);
3086 READ_BUF(sizeof(res->stateid.data));
3087 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3089 decode_change_info(xdr, &res->cinfo);
3092 READ32(res->rflags);
3097 READ_BUF(bmlen << 2);
3099 return decode_delegation(xdr, res);
3101 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
3105 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3110 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3113 READ_BUF(sizeof(res->stateid.data));
3114 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3118 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3123 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3126 READ_BUF(sizeof(res->stateid.data));
3127 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3131 static int decode_putfh(struct xdr_stream *xdr)
3133 return decode_op_hdr(xdr, OP_PUTFH);
3136 static int decode_putrootfh(struct xdr_stream *xdr)
3138 return decode_op_hdr(xdr, OP_PUTROOTFH);
3141 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3143 struct kvec *iov = req->rq_rcv_buf.head;
3145 uint32_t count, eof, recvd, hdrlen;
3148 status = decode_op_hdr(xdr, OP_READ);
3154 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3155 recvd = req->rq_rcv_buf.len - hdrlen;
3156 if (count > recvd) {
3157 printk(KERN_WARNING "NFS: server cheating in read reply: "
3158 "count %u > recvd %u\n", count, recvd);
3162 xdr_read_pages(xdr, count);
3168 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3170 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3171 struct page *page = *rcvbuf->pages;
3172 struct kvec *iov = rcvbuf->head;
3173 unsigned int nr, pglen = rcvbuf->page_len;
3174 uint32_t *end, *entry, *p, *kaddr;
3175 uint32_t len, attrlen;
3176 int hdrlen, recvd, status;
3178 status = decode_op_hdr(xdr, OP_READDIR);
3182 COPYMEM(readdir->verifier.data, 8);
3183 dprintk("%s: verifier = 0x%x%x\n",
3185 ((u32 *)readdir->verifier.data)[0],
3186 ((u32 *)readdir->verifier.data)[1]);
3189 hdrlen = (char *) p - (char *) iov->iov_base;
3190 recvd = rcvbuf->len - hdrlen;
3193 xdr_read_pages(xdr, pglen);
3195 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3196 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3197 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3199 for (nr = 0; *p++; nr++) {
3202 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3203 p += 2; /* cookie */
3204 len = ntohl(*p++); /* filename length */
3205 if (len > NFS4_MAXNAMLEN) {
3206 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3209 dprintk("filename = %*s\n", len, (char *)p);
3210 p += XDR_QUADLEN(len);
3213 len = ntohl(*p++); /* bitmap length */
3217 attrlen = XDR_QUADLEN(ntohl(*p++));
3218 p += attrlen; /* attributes */
3223 if (!nr && (entry[0] != 0 || entry[1] == 0))
3226 kunmap_atomic(kaddr, KM_USER0);
3229 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3230 entry[0] = entry[1] = 0;
3231 /* truncate listing ? */
3233 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3238 kunmap_atomic(kaddr, KM_USER0);
3239 return -errno_NFSERR_IO;
3242 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3244 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3245 struct kvec *iov = rcvbuf->head;
3246 int hdrlen, len, recvd;
3251 status = decode_op_hdr(xdr, OP_READLINK);
3255 /* Convert length of symlink */
3258 if (len >= rcvbuf->page_len || len <= 0) {
3259 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3260 return -ENAMETOOLONG;
3262 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3263 recvd = req->rq_rcv_buf.len - hdrlen;
3265 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3266 "count %u > recvd %u\n", len, recvd);
3269 xdr_read_pages(xdr, len);
3271 * The XDR encode routine has set things up so that
3272 * the link text will be copied directly into the
3273 * buffer. We just have to do overflow-checking,
3274 * and and null-terminate the text (the VFS expects
3275 * null-termination).
3277 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3278 kaddr[len+rcvbuf->page_base] = '\0';
3279 kunmap_atomic(kaddr, KM_USER0);
3283 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3287 status = decode_op_hdr(xdr, OP_REMOVE);
3290 status = decode_change_info(xdr, cinfo);
3295 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3296 struct nfs4_change_info *new_cinfo)
3300 status = decode_op_hdr(xdr, OP_RENAME);
3303 if ((status = decode_change_info(xdr, old_cinfo)))
3305 status = decode_change_info(xdr, new_cinfo);
3310 static int decode_renew(struct xdr_stream *xdr)
3312 return decode_op_hdr(xdr, OP_RENEW);
3316 decode_restorefh(struct xdr_stream *xdr)
3318 return decode_op_hdr(xdr, OP_RESTOREFH);
3321 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3327 struct kvec *iov = req->rq_rcv_buf.head;
3331 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3333 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3335 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3338 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3340 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3343 /* We ignore &savep and don't do consistency checks on
3344 * the attr length. Let userspace figure it out.... */
3345 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3346 recvd = req->rq_rcv_buf.len - hdrlen;
3347 if (attrlen > recvd) {
3348 printk(KERN_WARNING "NFS: server cheating in getattr"
3349 " acl reply: attrlen %u > recvd %u\n",
3353 if (attrlen <= *acl_len)
3354 xdr_read_pages(xdr, attrlen);
3357 status = -EOPNOTSUPP;
3364 decode_savefh(struct xdr_stream *xdr)
3366 return decode_op_hdr(xdr, OP_SAVEFH);
3369 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3376 status = decode_op_hdr(xdr, OP_SETATTR);
3381 READ_BUF(bmlen << 2);
3385 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3393 if (opnum != OP_SETCLIENTID) {
3395 "nfs4_decode_setclientid: Server returned operation"
3400 if (nfserr == NFS_OK) {
3401 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3402 READ64(clp->cl_clientid);
3403 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3404 } else if (nfserr == NFSERR_CLID_INUSE) {
3407 /* skip netid string */
3412 /* skip uaddr string */
3416 return -NFSERR_CLID_INUSE;
3418 return -nfs_stat_to_errno(nfserr);
3423 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3425 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3428 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3433 status = decode_op_hdr(xdr, OP_WRITE);
3439 READ32(res->verf->committed);
3440 COPYMEM(res->verf->verifier, 8);
3444 static int decode_delegreturn(struct xdr_stream *xdr)
3446 return decode_op_hdr(xdr, OP_DELEGRETURN);
3450 * Decode OPEN_DOWNGRADE response
3452 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3454 struct xdr_stream xdr;
3455 struct compound_hdr hdr;
3458 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3459 status = decode_compound_hdr(&xdr, &hdr);
3462 status = decode_putfh(&xdr);
3465 status = decode_open_downgrade(&xdr, res);
3468 decode_getfattr(&xdr, res->fattr, res->server);
3474 * END OF "GENERIC" DECODE ROUTINES.
3478 * Decode ACCESS response
3480 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3482 struct xdr_stream xdr;
3483 struct compound_hdr hdr;
3486 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3487 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3489 if ((status = decode_putfh(&xdr)) == 0)
3490 status = decode_access(&xdr, res);
3496 * Decode LOOKUP response
3498 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3500 struct xdr_stream xdr;
3501 struct compound_hdr hdr;
3504 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3505 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3507 if ((status = decode_putfh(&xdr)) != 0)
3509 if ((status = decode_lookup(&xdr)) != 0)
3511 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3513 status = decode_getfattr(&xdr, res->fattr, res->server);
3519 * Decode LOOKUP_ROOT response
3521 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3523 struct xdr_stream xdr;
3524 struct compound_hdr hdr;
3527 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3528 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3530 if ((status = decode_putrootfh(&xdr)) != 0)
3532 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3533 status = decode_getfattr(&xdr, res->fattr, res->server);
3539 * Decode REMOVE response
3541 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_remove_res *res)
3543 struct xdr_stream xdr;
3544 struct compound_hdr hdr;
3547 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3548 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3550 if ((status = decode_putfh(&xdr)) != 0)
3552 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3554 decode_getfattr(&xdr, res->dir_attr, res->server);
3560 * Decode RENAME response
3562 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3564 struct xdr_stream xdr;
3565 struct compound_hdr hdr;
3568 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3569 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3571 if ((status = decode_putfh(&xdr)) != 0)
3573 if ((status = decode_savefh(&xdr)) != 0)
3575 if ((status = decode_putfh(&xdr)) != 0)
3577 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3579 /* Current FH is target directory */
3580 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3582 if ((status = decode_restorefh(&xdr)) != 0)
3584 decode_getfattr(&xdr, res->old_fattr, res->server);
3590 * Decode LINK response
3592 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_link_res *res)
3594 struct xdr_stream xdr;
3595 struct compound_hdr hdr;
3598 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3599 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3601 if ((status = decode_putfh(&xdr)) != 0)
3603 if ((status = decode_savefh(&xdr)) != 0)
3605 if ((status = decode_putfh(&xdr)) != 0)
3607 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3610 * Note order: OP_LINK leaves the directory as the current
3613 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3615 if ((status = decode_restorefh(&xdr)) != 0)
3617 decode_getfattr(&xdr, res->fattr, res->server);
3623 * Decode CREATE response
3625 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3627 struct xdr_stream xdr;
3628 struct compound_hdr hdr;
3631 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3632 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3634 if ((status = decode_putfh(&xdr)) != 0)
3636 if ((status = decode_savefh(&xdr)) != 0)
3638 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3640 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3642 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3644 if ((status = decode_restorefh(&xdr)) != 0)
3646 decode_getfattr(&xdr, res->dir_fattr, res->server);
3652 * Decode SYMLINK response
3654 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3656 return nfs4_xdr_dec_create(rqstp, p, res);
3660 * Decode GETATTR response
3662 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3664 struct xdr_stream xdr;
3665 struct compound_hdr hdr;
3668 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3669 status = decode_compound_hdr(&xdr, &hdr);
3672 status = decode_putfh(&xdr);
3675 status = decode_getfattr(&xdr, res->fattr, res->server);
3682 * Encode an SETACL request
3685 nfs4_xdr_enc_setacl(struct rpc_rqst *req, uint32_t *p, struct nfs_setaclargs *args)
3687 struct xdr_stream xdr;
3688 struct compound_hdr hdr = {
3693 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3694 encode_compound_hdr(&xdr, &hdr);
3695 status = encode_putfh(&xdr, args->fh);
3698 status = encode_setacl(&xdr, args);
3703 * Decode SETACL response
3706 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3708 struct xdr_stream xdr;
3709 struct compound_hdr hdr;
3712 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3713 status = decode_compound_hdr(&xdr, &hdr);
3716 status = decode_putfh(&xdr);
3719 status = decode_setattr(&xdr, res);
3725 * Decode GETACL response
3728 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len)
3730 struct xdr_stream xdr;
3731 struct compound_hdr hdr;
3734 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3735 status = decode_compound_hdr(&xdr, &hdr);
3738 status = decode_putfh(&xdr);
3741 status = decode_getacl(&xdr, rqstp, acl_len);
3748 * Decode CLOSE response
3750 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3752 struct xdr_stream xdr;
3753 struct compound_hdr hdr;
3756 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3757 status = decode_compound_hdr(&xdr, &hdr);
3760 status = decode_putfh(&xdr);
3763 status = decode_close(&xdr, res);
3767 * Note: Server may do delete on close for this file
3768 * in which case the getattr call will fail with
3769 * an ESTALE error. Shouldn't be a problem,
3770 * though, since fattr->valid will remain unset.
3772 decode_getfattr(&xdr, res->fattr, res->server);
3778 * Decode OPEN response
3780 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3782 struct xdr_stream xdr;
3783 struct compound_hdr hdr;
3786 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3787 status = decode_compound_hdr(&xdr, &hdr);
3790 status = decode_putfh(&xdr);
3793 status = decode_savefh(&xdr);
3796 status = decode_open(&xdr, res);
3799 status = decode_getfh(&xdr, &res->fh);
3802 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
3804 if ((status = decode_restorefh(&xdr)) != 0)
3806 decode_getfattr(&xdr, res->dir_attr, res->server);
3812 * Decode OPEN_CONFIRM response
3814 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3816 struct xdr_stream xdr;
3817 struct compound_hdr hdr;
3820 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3821 status = decode_compound_hdr(&xdr, &hdr);
3824 status = decode_putfh(&xdr);
3827 status = decode_open_confirm(&xdr, res);
3833 * Decode OPEN response
3835 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3837 struct xdr_stream xdr;
3838 struct compound_hdr hdr;
3841 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3842 status = decode_compound_hdr(&xdr, &hdr);
3845 status = decode_putfh(&xdr);
3848 status = decode_open(&xdr, res);
3851 decode_getfattr(&xdr, res->f_attr, res->server);
3857 * Decode SETATTR response
3859 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3861 struct xdr_stream xdr;
3862 struct compound_hdr hdr;
3865 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3866 status = decode_compound_hdr(&xdr, &hdr);
3869 status = decode_putfh(&xdr);
3872 status = decode_setattr(&xdr, res);
3875 status = decode_getfattr(&xdr, res->fattr, res->server);
3876 if (status == NFS4ERR_DELAY)
3883 * Decode LOCK response
3885 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lock_res *res)
3887 struct xdr_stream xdr;
3888 struct compound_hdr hdr;
3891 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3892 status = decode_compound_hdr(&xdr, &hdr);
3895 status = decode_putfh(&xdr);
3898 status = decode_lock(&xdr, res);
3904 * Decode LOCKT response
3906 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockt_res *res)
3908 struct xdr_stream xdr;
3909 struct compound_hdr hdr;
3912 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3913 status = decode_compound_hdr(&xdr, &hdr);
3916 status = decode_putfh(&xdr);
3919 status = decode_lockt(&xdr, res);
3925 * Decode LOCKU response
3927 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_locku_res *res)
3929 struct xdr_stream xdr;
3930 struct compound_hdr hdr;
3933 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3934 status = decode_compound_hdr(&xdr, &hdr);
3937 status = decode_putfh(&xdr);
3940 status = decode_locku(&xdr, res);
3946 * Decode READLINK response
3948 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3950 struct xdr_stream xdr;
3951 struct compound_hdr hdr;
3954 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3955 status = decode_compound_hdr(&xdr, &hdr);
3958 status = decode_putfh(&xdr);
3961 status = decode_readlink(&xdr, rqstp);
3967 * Decode READDIR response
3969 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3971 struct xdr_stream xdr;
3972 struct compound_hdr hdr;
3975 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3976 status = decode_compound_hdr(&xdr, &hdr);
3979 status = decode_putfh(&xdr);
3982 status = decode_readdir(&xdr, rqstp, res);
3988 * Decode Read response
3990 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3992 struct xdr_stream xdr;
3993 struct compound_hdr hdr;
3996 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3997 status = decode_compound_hdr(&xdr, &hdr);
4000 status = decode_putfh(&xdr);
4003 status = decode_read(&xdr, rqstp, res);
4005 status = res->count;
4011 * Decode WRITE response
4013 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
4015 struct xdr_stream xdr;
4016 struct compound_hdr hdr;
4019 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4020 status = decode_compound_hdr(&xdr, &hdr);
4023 status = decode_putfh(&xdr);
4026 status = decode_write(&xdr, res);
4029 decode_getfattr(&xdr, res->fattr, res->server);
4031 status = res->count;
4037 * Decode COMMIT response
4039 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
4041 struct xdr_stream xdr;
4042 struct compound_hdr hdr;
4045 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4046 status = decode_compound_hdr(&xdr, &hdr);
4049 status = decode_putfh(&xdr);
4052 status = decode_commit(&xdr, res);
4055 decode_getfattr(&xdr, res->fattr, res->server);
4063 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
4065 struct xdr_stream xdr;
4066 struct compound_hdr hdr;
4069 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4070 status = decode_compound_hdr(&xdr, &hdr);
4072 status = decode_putfh(&xdr);
4074 status = decode_fsinfo(&xdr, fsinfo);
4076 status = -nfs_stat_to_errno(hdr.status);
4083 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
4085 struct xdr_stream xdr;
4086 struct compound_hdr hdr;
4089 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4090 status = decode_compound_hdr(&xdr, &hdr);
4092 status = decode_putfh(&xdr);
4094 status = decode_pathconf(&xdr, pathconf);
4101 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
4103 struct xdr_stream xdr;
4104 struct compound_hdr hdr;
4107 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4108 status = decode_compound_hdr(&xdr, &hdr);
4110 status = decode_putfh(&xdr);
4112 status = decode_statfs(&xdr, fsstat);
4117 * GETATTR_BITMAP request
4119 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
4121 struct xdr_stream xdr;
4122 struct compound_hdr hdr;
4125 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4126 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4128 if ((status = decode_putfh(&xdr)) != 0)
4130 status = decode_server_caps(&xdr, res);
4136 * Decode RENEW response
4138 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
4140 struct xdr_stream xdr;
4141 struct compound_hdr hdr;
4144 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4145 status = decode_compound_hdr(&xdr, &hdr);
4147 status = decode_renew(&xdr);
4152 * a SETCLIENTID request
4154 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
4155 struct nfs4_client *clp)
4157 struct xdr_stream xdr;
4158 struct compound_hdr hdr;
4161 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4162 status = decode_compound_hdr(&xdr, &hdr);
4164 status = decode_setclientid(&xdr, clp);
4166 status = -nfs_stat_to_errno(hdr.status);
4171 * a SETCLIENTID_CONFIRM request
4173 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
4175 struct xdr_stream xdr;
4176 struct compound_hdr hdr;
4179 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4180 status = decode_compound_hdr(&xdr, &hdr);
4182 status = decode_setclientid_confirm(&xdr);
4184 status = decode_putrootfh(&xdr);
4186 status = decode_fsinfo(&xdr, fsinfo);
4188 status = -nfs_stat_to_errno(hdr.status);
4193 * DELEGRETURN request
4195 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_delegreturnres *res)
4197 struct xdr_stream xdr;
4198 struct compound_hdr hdr;
4201 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4202 status = decode_compound_hdr(&xdr, &hdr);
4205 status = decode_putfh(&xdr);
4208 status = decode_delegreturn(&xdr);
4209 decode_getfattr(&xdr, res->fattr, res->server);
4214 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
4216 uint32_t bitmap[2] = {0};
4221 return ERR_PTR(-EAGAIN);
4223 return ERR_PTR(-EBADCOOKIE);
4226 entry->prev_cookie = entry->cookie;
4227 p = xdr_decode_hyper(p, &entry->cookie);
4228 entry->len = ntohl(*p++);
4229 entry->name = (const char *) p;
4230 p += XDR_QUADLEN(entry->len);
4233 * In case the server doesn't return an inode number,
4234 * we fake one here. (We don't use inode number 0,
4235 * since glibc seems to choke on it...)
4239 len = ntohl(*p++); /* bitmap length */
4241 bitmap[0] = ntohl(*p++);
4243 bitmap[1] = ntohl(*p++);
4247 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4249 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4250 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4251 /* Ignore the return value of rdattr_error for now */
4255 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4256 xdr_decode_hyper(p, &entry->ino);
4257 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4258 xdr_decode_hyper(p, &entry->ino);
4262 entry->eof = !p[0] && p[1];
4267 * We need to translate between nfs status return values and
4268 * the local errno values which may not be the same.
4275 { NFS4ERR_PERM, EPERM },
4276 { NFS4ERR_NOENT, ENOENT },
4277 { NFS4ERR_IO, errno_NFSERR_IO },
4278 { NFS4ERR_NXIO, ENXIO },
4279 { NFS4ERR_ACCESS, EACCES },
4280 { NFS4ERR_EXIST, EEXIST },
4281 { NFS4ERR_XDEV, EXDEV },
4282 { NFS4ERR_NOTDIR, ENOTDIR },
4283 { NFS4ERR_ISDIR, EISDIR },
4284 { NFS4ERR_INVAL, EINVAL },
4285 { NFS4ERR_FBIG, EFBIG },
4286 { NFS4ERR_NOSPC, ENOSPC },
4287 { NFS4ERR_ROFS, EROFS },
4288 { NFS4ERR_MLINK, EMLINK },
4289 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4290 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4291 { NFS4ERR_DQUOT, EDQUOT },
4292 { NFS4ERR_STALE, ESTALE },
4293 { NFS4ERR_BADHANDLE, EBADHANDLE },
4294 { NFS4ERR_BADOWNER, EINVAL },
4295 { NFS4ERR_BADNAME, EINVAL },
4296 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4297 { NFS4ERR_NOTSUPP, ENOTSUPP },
4298 { NFS4ERR_TOOSMALL, ETOOSMALL },
4299 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4300 { NFS4ERR_BADTYPE, EBADTYPE },
4301 { NFS4ERR_LOCKED, EAGAIN },
4302 { NFS4ERR_RESOURCE, EREMOTEIO },
4303 { NFS4ERR_SYMLINK, ELOOP },
4304 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4305 { NFS4ERR_DEADLOCK, EDEADLK },
4306 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4307 * to be handled by a
4314 * Convert an NFS error code to a local one.
4315 * This one is used jointly by NFSv2 and NFSv3.
4318 nfs_stat_to_errno(int stat)
4321 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4322 if (nfs_errtbl[i].stat == stat)
4323 return nfs_errtbl[i].errno;
4325 if (stat <= 10000 || stat > 10100) {
4326 /* The server is looney tunes. */
4327 return ESERVERFAULT;
4329 /* If we cannot translate the error, the recovery routines should
4331 * Note: remaining NFSv4 error codes have values > 10000, so should
4332 * not conflict with native Linux error codes.
4338 # define MAX(a, b) (((a) > (b))? (a) : (b))
4341 #define PROC(proc, argtype, restype) \
4342 [NFSPROC4_CLNT_##proc] = { \
4343 .p_proc = NFSPROC4_COMPOUND, \
4344 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4345 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4346 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
4349 struct rpc_procinfo nfs4_procedures[] = {
4350 PROC(READ, enc_read, dec_read),
4351 PROC(WRITE, enc_write, dec_write),
4352 PROC(COMMIT, enc_commit, dec_commit),
4353 PROC(OPEN, enc_open, dec_open),
4354 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4355 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4356 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4357 PROC(CLOSE, enc_close, dec_close),
4358 PROC(SETATTR, enc_setattr, dec_setattr),
4359 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4360 PROC(RENEW, enc_renew, dec_renew),
4361 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4362 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4363 PROC(LOCK, enc_lock, dec_lock),
4364 PROC(LOCKT, enc_lockt, dec_lockt),
4365 PROC(LOCKU, enc_locku, dec_locku),
4366 PROC(ACCESS, enc_access, dec_access),
4367 PROC(GETATTR, enc_getattr, dec_getattr),
4368 PROC(LOOKUP, enc_lookup, dec_lookup),
4369 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4370 PROC(REMOVE, enc_remove, dec_remove),
4371 PROC(RENAME, enc_rename, dec_rename),
4372 PROC(LINK, enc_link, dec_link),
4373 PROC(SYMLINK, enc_symlink, dec_symlink),
4374 PROC(CREATE, enc_create, dec_create),
4375 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4376 PROC(STATFS, enc_statfs, dec_statfs),
4377 PROC(READLINK, enc_readlink, dec_readlink),
4378 PROC(READDIR, enc_readdir, dec_readdir),
4379 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4380 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4381 PROC(GETACL, enc_getacl, dec_getacl),
4382 PROC(SETACL, enc_setacl, dec_setacl),
4385 struct rpc_version nfs_version4 = {
4387 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
4388 .procs = nfs4_procedures