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 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
164 decode_putfh_maxsz + \
165 op_decode_hdr_maxsz + 4)
166 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
167 encode_putfh_maxsz + \
168 op_encode_hdr_maxsz + 3)
169 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
170 decode_putfh_maxsz + \
171 op_decode_hdr_maxsz + 2)
172 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
173 encode_putfh_maxsz + \
174 op_encode_hdr_maxsz + \
176 encode_getattr_maxsz + \
178 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
179 decode_putfh_maxsz + \
180 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
181 decode_getattr_maxsz + \
183 #define NFS4_enc_open_confirm_sz \
184 (compound_encode_hdr_maxsz + \
185 encode_putfh_maxsz + \
186 op_encode_hdr_maxsz + 5)
187 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
188 decode_putfh_maxsz + \
189 op_decode_hdr_maxsz + 4)
190 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
191 encode_putfh_maxsz + \
192 op_encode_hdr_maxsz + \
194 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
195 decode_putfh_maxsz + \
196 op_decode_hdr_maxsz + \
198 #define NFS4_enc_open_downgrade_sz \
199 (compound_encode_hdr_maxsz + \
200 encode_putfh_maxsz + \
201 op_encode_hdr_maxsz + 7 + \
202 encode_getattr_maxsz)
203 #define NFS4_dec_open_downgrade_sz \
204 (compound_decode_hdr_maxsz + \
205 decode_putfh_maxsz + \
206 op_decode_hdr_maxsz + 4 + \
207 decode_getattr_maxsz)
208 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
209 encode_putfh_maxsz + \
210 op_encode_hdr_maxsz + 5 + \
211 encode_getattr_maxsz)
212 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
213 decode_putfh_maxsz + \
214 op_decode_hdr_maxsz + 4 + \
215 decode_getattr_maxsz)
216 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
217 encode_putfh_maxsz + \
218 op_encode_hdr_maxsz + 4 + \
220 encode_getattr_maxsz)
221 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
222 decode_putfh_maxsz + \
223 op_decode_hdr_maxsz + 3)
224 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
225 encode_putfh_maxsz + \
227 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
228 decode_putfh_maxsz + \
230 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
232 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
234 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
235 encode_setclientid_maxsz)
236 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
237 decode_setclientid_maxsz)
238 #define NFS4_enc_setclientid_confirm_sz \
239 (compound_encode_hdr_maxsz + \
240 encode_setclientid_confirm_maxsz + \
241 encode_putrootfh_maxsz + \
243 #define NFS4_dec_setclientid_confirm_sz \
244 (compound_decode_hdr_maxsz + \
245 decode_setclientid_confirm_maxsz + \
246 decode_putrootfh_maxsz + \
248 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
249 encode_putfh_maxsz + \
250 encode_getattr_maxsz + \
251 op_encode_hdr_maxsz + \
255 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
256 decode_putfh_maxsz + \
257 decode_getattr_maxsz + \
258 op_decode_hdr_maxsz + \
261 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
262 encode_putfh_maxsz + \
263 encode_getattr_maxsz + \
264 op_encode_hdr_maxsz + \
267 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
268 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
269 encode_putfh_maxsz + \
270 encode_getattr_maxsz + \
271 op_encode_hdr_maxsz + \
273 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
274 decode_putfh_maxsz + \
275 decode_getattr_maxsz + \
276 op_decode_hdr_maxsz + 4)
277 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
278 encode_putfh_maxsz + \
279 op_encode_hdr_maxsz + 1)
280 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
281 decode_putfh_maxsz + \
282 op_decode_hdr_maxsz + 2)
283 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
284 encode_putfh_maxsz + \
285 encode_getattr_maxsz)
286 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
287 decode_putfh_maxsz + \
288 decode_getattr_maxsz)
289 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
290 encode_putfh_maxsz + \
291 encode_lookup_maxsz + \
292 encode_getattr_maxsz + \
294 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
295 decode_putfh_maxsz + \
296 op_decode_hdr_maxsz + \
297 decode_getattr_maxsz + \
299 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
300 encode_putrootfh_maxsz + \
301 encode_getattr_maxsz + \
303 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
304 decode_putrootfh_maxsz + \
305 decode_getattr_maxsz + \
307 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
308 encode_putfh_maxsz + \
310 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
311 decode_putfh_maxsz + \
312 op_decode_hdr_maxsz + 5)
313 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
314 encode_putfh_maxsz + \
315 encode_savefh_maxsz + \
316 encode_putfh_maxsz + \
318 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
319 decode_putfh_maxsz + \
320 decode_savefh_maxsz + \
321 decode_putfh_maxsz + \
323 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
324 encode_putfh_maxsz + \
325 encode_savefh_maxsz + \
326 encode_putfh_maxsz + \
328 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
329 decode_putfh_maxsz + \
330 decode_savefh_maxsz + \
331 decode_putfh_maxsz + \
333 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
334 encode_putfh_maxsz + \
335 encode_symlink_maxsz + \
336 encode_getattr_maxsz + \
338 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
339 decode_putfh_maxsz + \
340 decode_symlink_maxsz + \
341 decode_getattr_maxsz + \
343 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
344 encode_putfh_maxsz + \
345 encode_savefh_maxsz + \
346 encode_create_maxsz + \
347 encode_getfh_maxsz + \
348 encode_getattr_maxsz + \
349 encode_restorefh_maxsz + \
350 encode_getattr_maxsz)
351 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
352 decode_putfh_maxsz + \
353 decode_savefh_maxsz + \
354 decode_create_maxsz + \
355 decode_getfh_maxsz + \
356 decode_getattr_maxsz + \
357 decode_restorefh_maxsz + \
358 decode_getattr_maxsz)
359 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
360 encode_putfh_maxsz + \
361 encode_getattr_maxsz)
362 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
363 decode_putfh_maxsz + \
364 decode_getattr_maxsz)
365 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
366 encode_putfh_maxsz + \
367 encode_getattr_maxsz)
368 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
369 decode_putfh_maxsz + \
370 op_decode_hdr_maxsz + 12)
371 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
372 encode_getattr_maxsz)
373 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
374 decode_getattr_maxsz)
375 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
376 encode_putfh_maxsz + \
377 encode_delegreturn_maxsz)
378 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
379 decode_delegreturn_maxsz)
380 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
381 encode_putfh_maxsz + \
382 encode_getattr_maxsz)
383 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
384 decode_putfh_maxsz + \
385 op_decode_hdr_maxsz + \
386 nfs4_fattr_bitmap_maxsz + 1)
387 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
388 encode_putfh_maxsz + \
389 op_encode_hdr_maxsz + 4 + \
390 nfs4_fattr_bitmap_maxsz + 1)
391 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
392 decode_putfh_maxsz + \
393 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
397 unsigned int nfs2type;
405 { S_IFSOCK, NFSOCK },
411 struct compound_hdr {
419 * START OF "GENERIC" ENCODE ROUTINES.
420 * These may look a little ugly since they are imported from a "generic"
421 * set of XDR encode/decode routines which are intended to be shared by
422 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
424 * If the pain of reading these is too great, it should be a straightforward
425 * task to translate them into Linux-specific versions which are more
426 * consistent with the style used in NFSv2/v3...
428 #define WRITE32(n) *p++ = htonl(n)
429 #define WRITE64(n) do { \
430 *p++ = htonl((uint32_t)((n) >> 32)); \
431 *p++ = htonl((uint32_t)(n)); \
433 #define WRITEMEM(ptr,nbytes) do { \
434 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
437 #define RESERVE_SPACE(nbytes) do { \
438 p = xdr_reserve_space(xdr, nbytes); \
439 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
443 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
447 p = xdr_reserve_space(xdr, 4 + len);
449 xdr_encode_opaque(p, str, len);
452 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
456 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
457 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
458 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
459 WRITE32(hdr->taglen);
460 WRITEMEM(hdr->tag, hdr->taglen);
461 WRITE32(NFS4_MINOR_VERSION);
466 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
470 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
472 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
475 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
477 char owner_name[IDMAP_NAMESZ];
478 char owner_group[IDMAP_NAMESZ];
479 int owner_namelen = 0;
480 int owner_grouplen = 0;
489 * We reserve enough space to write the entire attribute buffer at once.
490 * In the worst-case, this would be
491 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
492 * = 36 bytes, plus any contribution from variable-length fields
493 * such as owner/group.
498 if (iap->ia_valid & ATTR_SIZE)
500 if (iap->ia_valid & ATTR_MODE)
502 if (iap->ia_valid & ATTR_UID) {
503 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
504 if (owner_namelen < 0) {
505 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
508 strcpy(owner_name, "nobody");
509 owner_namelen = sizeof("nobody") - 1;
512 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
514 if (iap->ia_valid & ATTR_GID) {
515 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
516 if (owner_grouplen < 0) {
517 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
519 strcpy(owner_group, "nobody");
520 owner_grouplen = sizeof("nobody") - 1;
523 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
525 if (iap->ia_valid & ATTR_ATIME_SET)
527 else if (iap->ia_valid & ATTR_ATIME)
529 if (iap->ia_valid & ATTR_MTIME_SET)
531 else if (iap->ia_valid & ATTR_MTIME)
536 * We write the bitmap length now, but leave the bitmap and the attribute
537 * buffer length to be backfilled at the end of this routine.
543 if (iap->ia_valid & ATTR_SIZE) {
544 bmval0 |= FATTR4_WORD0_SIZE;
545 WRITE64(iap->ia_size);
547 if (iap->ia_valid & ATTR_MODE) {
548 bmval1 |= FATTR4_WORD1_MODE;
549 WRITE32(iap->ia_mode);
551 if (iap->ia_valid & ATTR_UID) {
552 bmval1 |= FATTR4_WORD1_OWNER;
553 WRITE32(owner_namelen);
554 WRITEMEM(owner_name, owner_namelen);
556 if (iap->ia_valid & ATTR_GID) {
557 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
558 WRITE32(owner_grouplen);
559 WRITEMEM(owner_group, owner_grouplen);
561 if (iap->ia_valid & ATTR_ATIME_SET) {
562 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
563 WRITE32(NFS4_SET_TO_CLIENT_TIME);
565 WRITE32(iap->ia_mtime.tv_sec);
566 WRITE32(iap->ia_mtime.tv_nsec);
568 else if (iap->ia_valid & ATTR_ATIME) {
569 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
570 WRITE32(NFS4_SET_TO_SERVER_TIME);
572 if (iap->ia_valid & ATTR_MTIME_SET) {
573 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
574 WRITE32(NFS4_SET_TO_CLIENT_TIME);
576 WRITE32(iap->ia_mtime.tv_sec);
577 WRITE32(iap->ia_mtime.tv_nsec);
579 else if (iap->ia_valid & ATTR_MTIME) {
580 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
581 WRITE32(NFS4_SET_TO_SERVER_TIME);
585 * Now we backfill the bitmap and the attribute buffer length.
587 if (len != ((char *)p - (char *)q) + 4) {
588 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
589 len, ((char *)p - (char *)q) + 4);
592 len = (char *)p - (char *)q - 12;
593 *q++ = htonl(bmval0);
594 *q++ = htonl(bmval1);
602 static int encode_access(struct xdr_stream *xdr, u32 access)
613 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
617 RESERVE_SPACE(8+sizeof(arg->stateid->data));
619 WRITE32(arg->seqid->sequence->counter);
620 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
625 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
631 WRITE64(args->offset);
632 WRITE32(args->count);
637 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
643 WRITE32(create->ftype);
645 switch (create->ftype) {
647 RESERVE_SPACE(4 + create->u.symlink->len);
648 WRITE32(create->u.symlink->len);
649 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
652 case NF4BLK: case NF4CHR:
654 WRITE32(create->u.device.specdata1);
655 WRITE32(create->u.device.specdata2);
662 RESERVE_SPACE(4 + create->name->len);
663 WRITE32(create->name->len);
664 WRITEMEM(create->name->name, create->name->len);
666 return encode_attrs(xdr, create->attrs, create->server);
669 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
680 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
692 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
694 return encode_getattr_two(xdr,
695 bitmask[0] & nfs4_fattr_bitmap[0],
696 bitmask[1] & nfs4_fattr_bitmap[1]);
699 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
701 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
702 bitmask[1] & nfs4_fsinfo_bitmap[1]);
705 static int encode_getfh(struct xdr_stream *xdr)
715 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
719 RESERVE_SPACE(8 + name->len);
722 WRITEMEM(name->name, name->len);
728 * opcode,type,reclaim,offset,length,new_lock_owner = 32
729 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
731 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
734 struct nfs_lock_opargs *opargs = arg->u.lock;
739 WRITE32(opargs->reclaim);
740 WRITE64(arg->offset);
741 WRITE64(arg->length);
742 WRITE32(opargs->new_lock_owner);
743 if (opargs->new_lock_owner){
745 WRITE32(opargs->open_seqid->sequence->counter);
746 WRITEMEM(opargs->open_stateid->data, sizeof(opargs->open_stateid->data));
747 WRITE32(opargs->lock_seqid->sequence->counter);
748 WRITE64(opargs->lock_owner.clientid);
750 WRITE32(opargs->lock_owner.id);
754 WRITEMEM(opargs->lock_stateid->data, sizeof(opargs->lock_stateid->data));
755 WRITE32(opargs->lock_seqid->sequence->counter);
761 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
764 struct nfs_lowner *opargs = arg->u.lockt;
769 WRITE64(arg->offset);
770 WRITE64(arg->length);
771 WRITE64(opargs->clientid);
778 static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
781 struct nfs_locku_opargs *opargs = arg->u.locku;
786 WRITE32(opargs->seqid->sequence->counter);
787 WRITEMEM(opargs->stateid->data, sizeof(opargs->stateid->data));
788 WRITE64(arg->offset);
789 WRITE64(arg->length);
794 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
799 RESERVE_SPACE(8 + len);
802 WRITEMEM(name->name, len);
807 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
812 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
814 WRITE32(NFS4_SHARE_ACCESS_READ);
817 WRITE32(NFS4_SHARE_ACCESS_WRITE);
819 case FMODE_READ|FMODE_WRITE:
820 WRITE32(NFS4_SHARE_ACCESS_BOTH);
825 WRITE32(0); /* for linux, share_deny = 0 always */
828 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
832 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
837 WRITE32(arg->seqid->sequence->counter);
838 encode_share_access(xdr, arg->open_flags);
840 WRITE64(arg->clientid);
845 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
850 switch(arg->open_flags & O_EXCL) {
852 WRITE32(NFS4_CREATE_UNCHECKED);
853 encode_attrs(xdr, arg->u.attrs, arg->server);
856 WRITE32(NFS4_CREATE_EXCLUSIVE);
857 encode_nfs4_verifier(xdr, &arg->u.verifier);
861 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
866 switch (arg->open_flags & O_CREAT) {
868 WRITE32(NFS4_OPEN_NOCREATE);
871 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
872 WRITE32(NFS4_OPEN_CREATE);
873 encode_createmode(xdr, arg);
877 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
882 switch (delegation_type) {
884 WRITE32(NFS4_OPEN_DELEGATE_NONE);
887 WRITE32(NFS4_OPEN_DELEGATE_READ);
889 case FMODE_WRITE|FMODE_READ:
890 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
897 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
902 WRITE32(NFS4_OPEN_CLAIM_NULL);
903 encode_string(xdr, name->len, name->name);
906 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
911 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
912 encode_delegation_type(xdr, type);
915 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
919 RESERVE_SPACE(4+sizeof(stateid->data));
920 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
921 WRITEMEM(stateid->data, sizeof(stateid->data));
922 encode_string(xdr, name->len, name->name);
925 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
927 encode_openhdr(xdr, arg);
928 encode_opentype(xdr, arg);
929 switch (arg->claim) {
930 case NFS4_OPEN_CLAIM_NULL:
931 encode_claim_null(xdr, arg->name);
933 case NFS4_OPEN_CLAIM_PREVIOUS:
934 encode_claim_previous(xdr, arg->u.delegation_type);
936 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
937 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
945 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
949 RESERVE_SPACE(8+sizeof(arg->stateid.data));
950 WRITE32(OP_OPEN_CONFIRM);
951 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
952 WRITE32(arg->seqid->sequence->counter);
957 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
961 RESERVE_SPACE(8+sizeof(arg->stateid->data));
962 WRITE32(OP_OPEN_DOWNGRADE);
963 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
964 WRITE32(arg->seqid->sequence->counter);
965 encode_share_access(xdr, arg->open_flags);
970 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
975 RESERVE_SPACE(8 + len);
978 WRITEMEM(fh->data, len);
983 static int encode_putrootfh(struct xdr_stream *xdr)
988 WRITE32(OP_PUTROOTFH);
993 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
995 nfs4_stateid stateid;
999 if (ctx->state != NULL) {
1000 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1001 WRITEMEM(stateid.data, sizeof(stateid.data));
1003 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1006 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1013 encode_stateid(xdr, args->context);
1016 WRITE64(args->offset);
1017 WRITE32(args->count);
1022 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1024 struct rpc_auth *auth = req->rq_task->tk_auth;
1025 uint32_t attrs[2] = {
1026 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1027 FATTR4_WORD1_MOUNTED_ON_FILEID,
1032 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1033 WRITE32(OP_READDIR);
1034 WRITE64(readdir->cookie);
1035 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1036 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1037 WRITE32(readdir->count);
1039 /* Switch to mounted_on_fileid if the server supports it */
1040 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1041 attrs[0] &= ~FATTR4_WORD0_FILEID;
1043 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1044 WRITE32(attrs[0] & readdir->bitmask[0]);
1045 WRITE32(attrs[1] & readdir->bitmask[1]);
1046 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1048 (unsigned long long)readdir->cookie,
1049 ((u32 *)readdir->verifier.data)[0],
1050 ((u32 *)readdir->verifier.data)[1],
1051 attrs[0] & readdir->bitmask[0],
1052 attrs[1] & readdir->bitmask[1]);
1054 /* set up reply kvec
1055 * toplevel_status + taglen + rescount + OP_PUTFH + status
1056 * + OP_READDIR + status + verifer(2) = 9
1058 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1059 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1060 readdir->pgbase, readdir->count);
1061 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1062 __FUNCTION__, replen, readdir->pages,
1063 readdir->pgbase, readdir->count);
1068 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1070 struct rpc_auth *auth = req->rq_task->tk_auth;
1071 unsigned int replen;
1075 WRITE32(OP_READLINK);
1077 /* set up reply kvec
1078 * toplevel_status + taglen + rescount + OP_PUTFH + status
1079 * + OP_READLINK + status + string length = 8
1081 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1082 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1083 readlink->pgbase, readlink->pglen);
1088 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1092 RESERVE_SPACE(8 + name->len);
1095 WRITEMEM(name->name, name->len);
1100 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1104 RESERVE_SPACE(8 + oldname->len);
1106 WRITE32(oldname->len);
1107 WRITEMEM(oldname->name, oldname->len);
1109 RESERVE_SPACE(4 + newname->len);
1110 WRITE32(newname->len);
1111 WRITEMEM(newname->name, newname->len);
1116 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1122 WRITE64(client_stateid->cl_clientid);
1128 encode_restorefh(struct xdr_stream *xdr)
1133 WRITE32(OP_RESTOREFH);
1139 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1143 RESERVE_SPACE(4+sizeof(zero_stateid.data));
1144 WRITE32(OP_SETATTR);
1145 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1148 WRITE32(FATTR4_WORD0_ACL);
1149 if (arg->acl_len % 4)
1152 WRITE32(arg->acl_len);
1153 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1158 encode_savefh(struct xdr_stream *xdr)
1168 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1173 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1174 WRITE32(OP_SETATTR);
1175 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1177 if ((status = encode_attrs(xdr, arg->iap, server)))
1183 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1187 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1188 WRITE32(OP_SETCLIENTID);
1189 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1191 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1193 WRITE32(setclientid->sc_prog);
1194 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1195 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1197 WRITE32(setclientid->sc_cb_ident);
1202 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1206 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1207 WRITE32(OP_SETCLIENTID_CONFIRM);
1208 WRITE64(client_state->cl_clientid);
1209 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1214 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1221 encode_stateid(xdr, args->context);
1224 WRITE64(args->offset);
1225 WRITE32(args->stable);
1226 WRITE32(args->count);
1228 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1233 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1239 WRITE32(OP_DELEGRETURN);
1240 WRITEMEM(stateid->data, sizeof(stateid->data));
1245 * END OF "GENERIC" ENCODE ROUTINES.
1249 * Encode an ACCESS request
1251 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1253 struct xdr_stream xdr;
1254 struct compound_hdr hdr = {
1259 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1260 encode_compound_hdr(&xdr, &hdr);
1261 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1262 status = encode_access(&xdr, args->access);
1267 * Encode LOOKUP request
1269 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1271 struct xdr_stream xdr;
1272 struct compound_hdr hdr = {
1277 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1278 encode_compound_hdr(&xdr, &hdr);
1279 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1281 if ((status = encode_lookup(&xdr, args->name)) != 0)
1283 if ((status = encode_getfh(&xdr)) != 0)
1285 status = encode_getfattr(&xdr, args->bitmask);
1291 * Encode LOOKUP_ROOT request
1293 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1295 struct xdr_stream xdr;
1296 struct compound_hdr hdr = {
1301 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1302 encode_compound_hdr(&xdr, &hdr);
1303 if ((status = encode_putrootfh(&xdr)) != 0)
1305 if ((status = encode_getfh(&xdr)) == 0)
1306 status = encode_getfattr(&xdr, args->bitmask);
1312 * Encode REMOVE request
1314 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1316 struct xdr_stream xdr;
1317 struct compound_hdr hdr = {
1322 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1323 encode_compound_hdr(&xdr, &hdr);
1324 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1325 status = encode_remove(&xdr, args->name);
1330 * Encode RENAME request
1332 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1334 struct xdr_stream xdr;
1335 struct compound_hdr hdr = {
1340 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1341 encode_compound_hdr(&xdr, &hdr);
1342 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1344 if ((status = encode_savefh(&xdr)) != 0)
1346 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1348 status = encode_rename(&xdr, args->old_name, args->new_name);
1354 * Encode LINK request
1356 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1358 struct xdr_stream xdr;
1359 struct compound_hdr hdr = {
1364 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1365 encode_compound_hdr(&xdr, &hdr);
1366 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1368 if ((status = encode_savefh(&xdr)) != 0)
1370 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1372 status = encode_link(&xdr, args->name);
1378 * Encode CREATE request
1380 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1382 struct xdr_stream xdr;
1383 struct compound_hdr hdr = {
1388 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1389 encode_compound_hdr(&xdr, &hdr);
1390 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1392 if ((status = encode_savefh(&xdr)) != 0)
1394 if ((status = encode_create(&xdr, args)) != 0)
1396 if ((status = encode_getfh(&xdr)) != 0)
1398 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1400 if ((status = encode_restorefh(&xdr)) != 0)
1402 status = encode_getfattr(&xdr, args->bitmask);
1408 * Encode SYMLINK request
1410 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1412 return nfs4_xdr_enc_create(req, p, args);
1416 * Encode GETATTR request
1418 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1420 struct xdr_stream xdr;
1421 struct compound_hdr hdr = {
1426 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1427 encode_compound_hdr(&xdr, &hdr);
1428 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1429 status = encode_getfattr(&xdr, args->bitmask);
1434 * Encode a CLOSE request
1436 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1438 struct xdr_stream xdr;
1439 struct compound_hdr hdr = {
1444 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1445 encode_compound_hdr(&xdr, &hdr);
1446 status = encode_putfh(&xdr, args->fh);
1449 status = encode_close(&xdr, args);
1452 status = encode_getfattr(&xdr, args->bitmask);
1458 * Encode an OPEN request
1460 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1462 struct xdr_stream xdr;
1463 struct compound_hdr hdr = {
1468 status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1471 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1472 encode_compound_hdr(&xdr, &hdr);
1473 status = encode_putfh(&xdr, args->fh);
1476 status = encode_savefh(&xdr);
1479 status = encode_open(&xdr, args);
1482 status = encode_getfh(&xdr);
1485 status = encode_getfattr(&xdr, args->bitmask);
1488 status = encode_restorefh(&xdr);
1491 status = encode_getfattr(&xdr, args->bitmask);
1497 * Encode an OPEN_CONFIRM request
1499 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1501 struct xdr_stream xdr;
1502 struct compound_hdr hdr = {
1507 status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1510 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1511 encode_compound_hdr(&xdr, &hdr);
1512 status = encode_putfh(&xdr, args->fh);
1515 status = encode_open_confirm(&xdr, args);
1521 * Encode an OPEN request with no attributes.
1523 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1525 struct xdr_stream xdr;
1526 struct compound_hdr hdr = {
1531 status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1534 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1535 encode_compound_hdr(&xdr, &hdr);
1536 status = encode_putfh(&xdr, args->fh);
1539 status = encode_open(&xdr, args);
1545 * Encode an OPEN_DOWNGRADE request
1547 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1549 struct xdr_stream xdr;
1550 struct compound_hdr hdr = {
1555 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1556 encode_compound_hdr(&xdr, &hdr);
1557 status = encode_putfh(&xdr, args->fh);
1560 status = encode_open_downgrade(&xdr, args);
1563 status = encode_getfattr(&xdr, args->bitmask);
1569 * Encode a LOCK request
1571 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1573 struct xdr_stream xdr;
1574 struct compound_hdr hdr = {
1577 struct nfs_lock_opargs *opargs = args->u.lock;
1580 status = nfs_wait_on_sequence(opargs->lock_seqid, req->rq_task);
1583 /* Do we need to do an open_to_lock_owner? */
1584 if (opargs->lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)
1585 opargs->new_lock_owner = 0;
1586 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1587 encode_compound_hdr(&xdr, &hdr);
1588 status = encode_putfh(&xdr, args->fh);
1591 status = encode_lock(&xdr, args);
1597 * Encode a LOCKT request
1599 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1601 struct xdr_stream xdr;
1602 struct compound_hdr hdr = {
1607 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1608 encode_compound_hdr(&xdr, &hdr);
1609 status = encode_putfh(&xdr, args->fh);
1612 status = encode_lockt(&xdr, args);
1618 * Encode a LOCKU request
1620 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1622 struct xdr_stream xdr;
1623 struct compound_hdr hdr = {
1628 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1629 encode_compound_hdr(&xdr, &hdr);
1630 status = encode_putfh(&xdr, args->fh);
1633 status = encode_locku(&xdr, args);
1639 * Encode a READLINK request
1641 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1643 struct xdr_stream xdr;
1644 struct compound_hdr hdr = {
1649 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1650 encode_compound_hdr(&xdr, &hdr);
1651 status = encode_putfh(&xdr, args->fh);
1654 status = encode_readlink(&xdr, args, req);
1660 * Encode a READDIR request
1662 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1664 struct xdr_stream xdr;
1665 struct compound_hdr hdr = {
1670 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1671 encode_compound_hdr(&xdr, &hdr);
1672 status = encode_putfh(&xdr, args->fh);
1675 status = encode_readdir(&xdr, args, req);
1681 * Encode a READ request
1683 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1685 struct rpc_auth *auth = req->rq_task->tk_auth;
1686 struct xdr_stream xdr;
1687 struct compound_hdr hdr = {
1692 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1693 encode_compound_hdr(&xdr, &hdr);
1694 status = encode_putfh(&xdr, args->fh);
1697 status = encode_read(&xdr, args);
1701 /* set up reply kvec
1702 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1703 * + OP_READ + status + eof + datalen = 9
1705 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1706 xdr_inline_pages(&req->rq_rcv_buf, replen,
1707 args->pages, args->pgbase, args->count);
1713 * Encode an SETATTR request
1715 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1718 struct xdr_stream xdr;
1719 struct compound_hdr hdr = {
1724 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1725 encode_compound_hdr(&xdr, &hdr);
1726 status = encode_putfh(&xdr, args->fh);
1729 status = encode_setattr(&xdr, args, args->server);
1732 status = encode_getfattr(&xdr, args->bitmask);
1738 * Encode a GETACL request
1741 nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p,
1742 struct nfs_getaclargs *args)
1744 struct xdr_stream xdr;
1745 struct rpc_auth *auth = req->rq_task->tk_auth;
1746 struct compound_hdr hdr = {
1751 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1752 encode_compound_hdr(&xdr, &hdr);
1753 status = encode_putfh(&xdr, args->fh);
1756 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1757 /* set up reply buffer: */
1758 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1759 xdr_inline_pages(&req->rq_rcv_buf, replen,
1760 args->acl_pages, args->acl_pgbase, args->acl_len);
1766 * Encode a WRITE request
1768 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1770 struct xdr_stream xdr;
1771 struct compound_hdr hdr = {
1776 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1777 encode_compound_hdr(&xdr, &hdr);
1778 status = encode_putfh(&xdr, args->fh);
1781 status = encode_write(&xdr, args);
1789 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1791 struct xdr_stream xdr;
1792 struct compound_hdr hdr = {
1797 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1798 encode_compound_hdr(&xdr, &hdr);
1799 status = encode_putfh(&xdr, args->fh);
1802 status = encode_commit(&xdr, args);
1810 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1812 struct xdr_stream xdr;
1813 struct compound_hdr hdr = {
1818 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1819 encode_compound_hdr(&xdr, &hdr);
1820 status = encode_putfh(&xdr, args->fh);
1822 status = encode_fsinfo(&xdr, args->bitmask);
1827 * a PATHCONF request
1829 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1831 struct xdr_stream xdr;
1832 struct compound_hdr hdr = {
1837 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1838 encode_compound_hdr(&xdr, &hdr);
1839 status = encode_putfh(&xdr, args->fh);
1841 status = encode_getattr_one(&xdr,
1842 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1849 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1851 struct xdr_stream xdr;
1852 struct compound_hdr hdr = {
1857 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1858 encode_compound_hdr(&xdr, &hdr);
1859 status = encode_putfh(&xdr, args->fh);
1861 status = encode_getattr_two(&xdr,
1862 args->bitmask[0] & nfs4_statfs_bitmap[0],
1863 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1868 * GETATTR_BITMAP request
1870 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1872 struct xdr_stream xdr;
1873 struct compound_hdr hdr = {
1878 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1879 encode_compound_hdr(&xdr, &hdr);
1880 status = encode_putfh(&xdr, fhandle);
1882 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1883 FATTR4_WORD0_LINK_SUPPORT|
1884 FATTR4_WORD0_SYMLINK_SUPPORT|
1885 FATTR4_WORD0_ACLSUPPORT);
1892 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1894 struct xdr_stream xdr;
1895 struct compound_hdr hdr = {
1899 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1900 encode_compound_hdr(&xdr, &hdr);
1901 return encode_renew(&xdr, clp);
1905 * a SETCLIENTID request
1907 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1909 struct xdr_stream xdr;
1910 struct compound_hdr hdr = {
1914 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1915 encode_compound_hdr(&xdr, &hdr);
1916 return encode_setclientid(&xdr, sc);
1920 * a SETCLIENTID_CONFIRM request
1922 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1924 struct xdr_stream xdr;
1925 struct compound_hdr hdr = {
1928 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1931 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1932 encode_compound_hdr(&xdr, &hdr);
1933 status = encode_setclientid_confirm(&xdr, clp);
1935 status = encode_putrootfh(&xdr);
1937 status = encode_fsinfo(&xdr, lease_bitmap);
1942 * DELEGRETURN request
1944 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1946 struct xdr_stream xdr;
1947 struct compound_hdr hdr = {
1952 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1953 encode_compound_hdr(&xdr, &hdr);
1954 if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
1955 status = encode_delegreturn(&xdr, args->stateid);
1960 * START OF "GENERIC" DECODE ROUTINES.
1961 * These may look a little ugly since they are imported from a "generic"
1962 * set of XDR encode/decode routines which are intended to be shared by
1963 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1965 * If the pain of reading these is too great, it should be a straightforward
1966 * task to translate them into Linux-specific versions which are more
1967 * consistent with the style used in NFSv2/v3...
1969 #define READ32(x) (x) = ntohl(*p++)
1970 #define READ64(x) do { \
1971 (x) = (u64)ntohl(*p++) << 32; \
1972 (x) |= ntohl(*p++); \
1974 #define READTIME(x) do { \
1976 (x.tv_sec) = ntohl(*p++); \
1977 (x.tv_nsec) = ntohl(*p++); \
1979 #define COPYMEM(x,nbytes) do { \
1980 memcpy((x), p, nbytes); \
1981 p += XDR_QUADLEN(nbytes); \
1984 #define READ_BUF(nbytes) do { \
1985 p = xdr_inline_decode(xdr, nbytes); \
1987 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
1988 __FUNCTION__, __LINE__); \
1993 static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
2000 *string = (char *)p;
2004 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2009 READ32(hdr->status);
2010 READ32(hdr->taglen);
2012 READ_BUF(hdr->taglen + 4);
2013 hdr->tag = (char *)p;
2014 p += XDR_QUADLEN(hdr->taglen);
2019 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2027 if (opnum != expected) {
2029 "nfs4_decode_op_hdr: Server returned operation"
2030 " %d but we issued a request for %d\n",
2035 if (nfserr != NFS_OK)
2036 return -nfs_stat_to_errno(nfserr);
2041 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
2048 return decode_opaque_inline(xdr, &strlen, &str);
2051 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2058 bitmap[0] = bitmap[1] = 0;
2059 READ_BUF((bmlen << 2));
2068 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
2078 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2080 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2081 decode_attr_bitmap(xdr, bitmask);
2082 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2084 bitmask[0] = bitmask[1] = 0;
2085 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2089 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2094 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2096 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2099 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2100 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2103 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2105 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2109 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2114 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2116 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2119 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2121 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2122 (unsigned long long)*change);
2126 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2131 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2133 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2136 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2138 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2142 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2147 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2149 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2152 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2154 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2158 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2163 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2165 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2168 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2170 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2174 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2180 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2182 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2184 READ64(fsid->major);
2185 READ64(fsid->minor);
2186 bitmap[0] &= ~FATTR4_WORD0_FSID;
2188 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2189 (unsigned long long)fsid->major,
2190 (unsigned long long)fsid->minor);
2194 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2199 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2201 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2204 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2206 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2210 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2214 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2215 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2217 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2220 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2222 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2226 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2231 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2233 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2236 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2238 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2242 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2248 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2250 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2253 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2255 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2259 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2265 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2267 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2270 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2272 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2276 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2282 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2284 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2287 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2289 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2293 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2299 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2301 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2304 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2306 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2310 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2316 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2318 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2321 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2323 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2327 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2333 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2335 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2338 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2340 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2344 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2350 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2352 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2356 if (maxread > 0x7FFFFFFF)
2357 maxread = 0x7FFFFFFF;
2358 *res = (uint32_t)maxread;
2359 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2361 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2365 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2371 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2373 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2377 if (maxwrite > 0x7FFFFFFF)
2378 maxwrite = 0x7FFFFFFF;
2379 *res = (uint32_t)maxwrite;
2380 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2382 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2386 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2391 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2393 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2397 bitmap[1] &= ~FATTR4_WORD1_MODE;
2399 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2403 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2408 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2410 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2413 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2415 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2419 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2424 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2426 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2430 if (len < XDR_MAX_NETOBJ) {
2431 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2432 dprintk("%s: nfs_map_name_to_uid failed!\n",
2435 printk(KERN_WARNING "%s: name too long (%u)!\n",
2437 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2439 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2443 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2448 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2450 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2454 if (len < XDR_MAX_NETOBJ) {
2455 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2456 dprintk("%s: nfs_map_group_to_gid failed!\n",
2459 printk(KERN_WARNING "%s: name too long (%u)!\n",
2461 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2463 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2467 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2469 uint32_t major = 0, minor = 0, *p;
2472 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2474 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2480 tmp = MKDEV(major, minor);
2481 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2483 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2485 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2489 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2495 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2497 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2500 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2502 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2506 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2512 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2514 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2517 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2519 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2523 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2529 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2531 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2534 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2536 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2540 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2545 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2547 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2550 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2552 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2553 (unsigned long long)*used);
2557 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2566 time->tv_sec = (time_t)sec;
2567 time->tv_nsec = (long)nsec;
2571 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2577 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2579 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2580 status = decode_attr_time(xdr, time);
2581 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2583 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2587 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2593 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2595 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2596 status = decode_attr_time(xdr, time);
2597 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2599 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2603 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2609 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2611 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2612 status = decode_attr_time(xdr, time);
2613 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2615 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2619 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2621 unsigned int attrwords = XDR_QUADLEN(attrlen);
2622 unsigned int nwords = xdr->p - savep;
2624 if (unlikely(attrwords != nwords)) {
2625 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2628 (attrwords < nwords) ? '<' : '>',
2635 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2640 READ32(cinfo->atomic);
2641 READ64(cinfo->before);
2642 READ64(cinfo->after);
2646 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2652 status = decode_op_hdr(xdr, OP_ACCESS);
2658 access->supported = supp;
2659 access->access = acc;
2663 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2668 status = decode_op_hdr(xdr, OP_CLOSE);
2671 READ_BUF(sizeof(res->stateid.data));
2672 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2676 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2681 status = decode_op_hdr(xdr, OP_COMMIT);
2685 COPYMEM(res->verf->verifier, 8);
2689 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2695 status = decode_op_hdr(xdr, OP_CREATE);
2698 if ((status = decode_change_info(xdr, cinfo)))
2702 READ_BUF(bmlen << 2);
2706 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2713 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2715 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2717 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2719 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2721 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2723 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2725 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2727 status = verify_attr_len(xdr, savep, attrlen);
2730 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2734 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2741 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2743 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2745 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2748 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2750 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2752 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2754 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2756 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2758 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2761 status = verify_attr_len(xdr, savep, attrlen);
2764 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2768 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2775 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2777 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2779 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2782 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2784 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2787 status = verify_attr_len(xdr, savep, attrlen);
2790 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2794 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2800 int status, fmode = 0;
2802 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2804 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2807 fattr->bitmap[0] = bitmap[0];
2808 fattr->bitmap[1] = bitmap[1];
2810 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2814 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2816 fattr->type = nfs_type2fmt[type].nfs2type;
2817 fmode = nfs_type2fmt[type].mode;
2819 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2821 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2823 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2825 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2827 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2829 fattr->mode |= fmode;
2830 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2832 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2834 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2836 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2838 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2840 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2842 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2844 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2846 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
2847 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2850 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2855 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2858 uint32_t attrlen, bitmap[2];
2861 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2863 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2865 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2868 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2870 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2872 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2874 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2876 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2877 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2879 fsinfo->wtpref = fsinfo->wtmax;
2881 status = verify_attr_len(xdr, savep, attrlen);
2884 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2888 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2894 status = decode_op_hdr(xdr, OP_GETFH);
2897 /* Zero handle first to allow comparisons */
2898 memset(fh, 0, sizeof(*fh));
2902 if (len > NFS4_FHSIZE)
2906 COPYMEM(fh->data, len);
2910 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2914 status = decode_op_hdr(xdr, OP_LINK);
2917 return decode_change_info(xdr, cinfo);
2921 * We create the owner, so we know a proper owner.id length is 4.
2923 static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2929 READ64(denied->offset);
2930 READ64(denied->length);
2931 READ32(denied->type);
2932 READ64(denied->owner.clientid);
2936 READ32(denied->owner.id);
2937 return -NFS4ERR_DENIED;
2940 static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2945 status = decode_op_hdr(xdr, OP_LOCK);
2947 READ_BUF(sizeof(res->u.stateid.data));
2948 COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data));
2949 } else if (status == -NFS4ERR_DENIED)
2950 return decode_lock_denied(xdr, &res->u.denied);
2954 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2957 status = decode_op_hdr(xdr, OP_LOCKT);
2958 if (status == -NFS4ERR_DENIED)
2959 return decode_lock_denied(xdr, &res->u.denied);
2963 static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2968 status = decode_op_hdr(xdr, OP_LOCKU);
2970 READ_BUF(sizeof(res->u.stateid.data));
2971 COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data));
2976 static int decode_lookup(struct xdr_stream *xdr)
2978 return decode_op_hdr(xdr, OP_LOOKUP);
2981 /* This is too sick! */
2982 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
2985 uint32_t limit_type, nblocks, blocksize;
2989 switch (limit_type) {
2996 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3001 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3004 uint32_t delegation_type;
3007 READ32(delegation_type);
3008 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3009 res->delegation_type = 0;
3013 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
3014 READ32(res->do_recall);
3015 switch (delegation_type) {
3016 case NFS4_OPEN_DELEGATE_READ:
3017 res->delegation_type = FMODE_READ;
3019 case NFS4_OPEN_DELEGATE_WRITE:
3020 res->delegation_type = FMODE_WRITE|FMODE_READ;
3021 if (decode_space_limit(xdr, &res->maxsize) < 0)
3024 return decode_ace(xdr, NULL, res->server->nfs4_state);
3027 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3033 status = decode_op_hdr(xdr, OP_OPEN);
3036 READ_BUF(sizeof(res->stateid.data));
3037 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3039 decode_change_info(xdr, &res->cinfo);
3042 READ32(res->rflags);
3047 READ_BUF(bmlen << 2);
3049 return decode_delegation(xdr, res);
3051 printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
3055 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3060 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3063 READ_BUF(sizeof(res->stateid.data));
3064 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3068 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3073 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3076 READ_BUF(sizeof(res->stateid.data));
3077 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3081 static int decode_putfh(struct xdr_stream *xdr)
3083 return decode_op_hdr(xdr, OP_PUTFH);
3086 static int decode_putrootfh(struct xdr_stream *xdr)
3088 return decode_op_hdr(xdr, OP_PUTROOTFH);
3091 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3093 struct kvec *iov = req->rq_rcv_buf.head;
3095 uint32_t count, eof, recvd, hdrlen;
3098 status = decode_op_hdr(xdr, OP_READ);
3104 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3105 recvd = req->rq_rcv_buf.len - hdrlen;
3106 if (count > recvd) {
3107 printk(KERN_WARNING "NFS: server cheating in read reply: "
3108 "count %u > recvd %u\n", count, recvd);
3112 xdr_read_pages(xdr, count);
3118 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3120 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3121 struct page *page = *rcvbuf->pages;
3122 struct kvec *iov = rcvbuf->head;
3123 unsigned int nr, pglen = rcvbuf->page_len;
3124 uint32_t *end, *entry, *p, *kaddr;
3125 uint32_t len, attrlen;
3126 int hdrlen, recvd, status;
3128 status = decode_op_hdr(xdr, OP_READDIR);
3132 COPYMEM(readdir->verifier.data, 8);
3133 dprintk("%s: verifier = 0x%x%x\n",
3135 ((u32 *)readdir->verifier.data)[0],
3136 ((u32 *)readdir->verifier.data)[1]);
3139 hdrlen = (char *) p - (char *) iov->iov_base;
3140 recvd = rcvbuf->len - hdrlen;
3143 xdr_read_pages(xdr, pglen);
3145 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3146 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3147 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3149 for (nr = 0; *p++; nr++) {
3152 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3153 p += 2; /* cookie */
3154 len = ntohl(*p++); /* filename length */
3155 if (len > NFS4_MAXNAMLEN) {
3156 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3159 dprintk("filename = %*s\n", len, (char *)p);
3160 p += XDR_QUADLEN(len);
3163 len = ntohl(*p++); /* bitmap length */
3167 attrlen = XDR_QUADLEN(ntohl(*p++));
3168 p += attrlen; /* attributes */
3173 if (!nr && (entry[0] != 0 || entry[1] == 0))
3176 kunmap_atomic(kaddr, KM_USER0);
3179 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3180 entry[0] = entry[1] = 0;
3181 /* truncate listing ? */
3183 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3188 kunmap_atomic(kaddr, KM_USER0);
3189 return -errno_NFSERR_IO;
3192 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3194 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3195 struct kvec *iov = rcvbuf->head;
3196 int hdrlen, len, recvd;
3201 status = decode_op_hdr(xdr, OP_READLINK);
3205 /* Convert length of symlink */
3208 if (len >= rcvbuf->page_len || len <= 0) {
3209 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3210 return -ENAMETOOLONG;
3212 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3213 recvd = req->rq_rcv_buf.len - hdrlen;
3215 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3216 "count %u > recvd %u\n", len, recvd);
3219 xdr_read_pages(xdr, len);
3221 * The XDR encode routine has set things up so that
3222 * the link text will be copied directly into the
3223 * buffer. We just have to do overflow-checking,
3224 * and and null-terminate the text (the VFS expects
3225 * null-termination).
3227 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3228 kaddr[len+rcvbuf->page_base] = '\0';
3229 kunmap_atomic(kaddr, KM_USER0);
3233 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3237 status = decode_op_hdr(xdr, OP_REMOVE);
3240 status = decode_change_info(xdr, cinfo);
3245 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3246 struct nfs4_change_info *new_cinfo)
3250 status = decode_op_hdr(xdr, OP_RENAME);
3253 if ((status = decode_change_info(xdr, old_cinfo)))
3255 status = decode_change_info(xdr, new_cinfo);
3260 static int decode_renew(struct xdr_stream *xdr)
3262 return decode_op_hdr(xdr, OP_RENEW);
3266 decode_restorefh(struct xdr_stream *xdr)
3268 return decode_op_hdr(xdr, OP_RESTOREFH);
3271 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3277 struct kvec *iov = req->rq_rcv_buf.head;
3281 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3283 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3285 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3288 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3290 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3293 /* We ignore &savep and don't do consistency checks on
3294 * the attr length. Let userspace figure it out.... */
3295 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3296 recvd = req->rq_rcv_buf.len - hdrlen;
3297 if (attrlen > recvd) {
3298 printk(KERN_WARNING "NFS: server cheating in getattr"
3299 " acl reply: attrlen %u > recvd %u\n",
3303 if (attrlen <= *acl_len)
3304 xdr_read_pages(xdr, attrlen);
3307 status = -EOPNOTSUPP;
3314 decode_savefh(struct xdr_stream *xdr)
3316 return decode_op_hdr(xdr, OP_SAVEFH);
3319 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3326 status = decode_op_hdr(xdr, OP_SETATTR);
3331 READ_BUF(bmlen << 2);
3335 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3343 if (opnum != OP_SETCLIENTID) {
3345 "nfs4_decode_setclientid: Server returned operation"
3350 if (nfserr == NFS_OK) {
3351 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3352 READ64(clp->cl_clientid);
3353 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3354 } else if (nfserr == NFSERR_CLID_INUSE) {
3357 /* skip netid string */
3362 /* skip uaddr string */
3366 return -NFSERR_CLID_INUSE;
3368 return -nfs_stat_to_errno(nfserr);
3373 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3375 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3378 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3383 status = decode_op_hdr(xdr, OP_WRITE);
3389 READ32(res->verf->committed);
3390 COPYMEM(res->verf->verifier, 8);
3394 static int decode_delegreturn(struct xdr_stream *xdr)
3396 return decode_op_hdr(xdr, OP_DELEGRETURN);
3400 * Decode OPEN_DOWNGRADE response
3402 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3404 struct xdr_stream xdr;
3405 struct compound_hdr hdr;
3408 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3409 status = decode_compound_hdr(&xdr, &hdr);
3412 status = decode_putfh(&xdr);
3415 status = decode_open_downgrade(&xdr, res);
3418 decode_getfattr(&xdr, res->fattr, res->server);
3424 * END OF "GENERIC" DECODE ROUTINES.
3428 * Decode ACCESS response
3430 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3432 struct xdr_stream xdr;
3433 struct compound_hdr hdr;
3436 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3437 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3439 if ((status = decode_putfh(&xdr)) == 0)
3440 status = decode_access(&xdr, res);
3446 * Decode LOOKUP response
3448 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3450 struct xdr_stream xdr;
3451 struct compound_hdr hdr;
3454 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3455 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3457 if ((status = decode_putfh(&xdr)) != 0)
3459 if ((status = decode_lookup(&xdr)) != 0)
3461 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3463 status = decode_getfattr(&xdr, res->fattr, res->server);
3469 * Decode LOOKUP_ROOT response
3471 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3473 struct xdr_stream xdr;
3474 struct compound_hdr hdr;
3477 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3478 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3480 if ((status = decode_putrootfh(&xdr)) != 0)
3482 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3483 status = decode_getfattr(&xdr, res->fattr, res->server);
3489 * Decode REMOVE response
3491 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3493 struct xdr_stream xdr;
3494 struct compound_hdr hdr;
3497 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3498 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3500 if ((status = decode_putfh(&xdr)) == 0)
3501 status = decode_remove(&xdr, cinfo);
3507 * Decode RENAME response
3509 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3511 struct xdr_stream xdr;
3512 struct compound_hdr hdr;
3515 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3516 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3518 if ((status = decode_putfh(&xdr)) != 0)
3520 if ((status = decode_savefh(&xdr)) != 0)
3522 if ((status = decode_putfh(&xdr)) != 0)
3524 status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
3530 * Decode LINK response
3532 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3534 struct xdr_stream xdr;
3535 struct compound_hdr hdr;
3538 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3539 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3541 if ((status = decode_putfh(&xdr)) != 0)
3543 if ((status = decode_savefh(&xdr)) != 0)
3545 if ((status = decode_putfh(&xdr)) != 0)
3547 status = decode_link(&xdr, cinfo);
3553 * Decode CREATE response
3555 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3557 struct xdr_stream xdr;
3558 struct compound_hdr hdr;
3561 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3562 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3564 if ((status = decode_putfh(&xdr)) != 0)
3566 if ((status = decode_savefh(&xdr)) != 0)
3568 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3570 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3572 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3574 if ((status = decode_restorefh(&xdr)) != 0)
3576 decode_getfattr(&xdr, res->dir_fattr, res->server);
3582 * Decode SYMLINK response
3584 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3586 return nfs4_xdr_dec_create(rqstp, p, res);
3590 * Decode GETATTR response
3592 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3594 struct xdr_stream xdr;
3595 struct compound_hdr hdr;
3598 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3599 status = decode_compound_hdr(&xdr, &hdr);
3602 status = decode_putfh(&xdr);
3605 status = decode_getfattr(&xdr, res->fattr, res->server);
3612 * Encode an SETACL request
3615 nfs4_xdr_enc_setacl(struct rpc_rqst *req, uint32_t *p, struct nfs_setaclargs *args)
3617 struct xdr_stream xdr;
3618 struct compound_hdr hdr = {
3623 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3624 encode_compound_hdr(&xdr, &hdr);
3625 status = encode_putfh(&xdr, args->fh);
3628 status = encode_setacl(&xdr, args);
3633 * Decode SETACL response
3636 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3638 struct xdr_stream xdr;
3639 struct compound_hdr hdr;
3642 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3643 status = decode_compound_hdr(&xdr, &hdr);
3646 status = decode_putfh(&xdr);
3649 status = decode_setattr(&xdr, res);
3655 * Decode GETACL response
3658 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len)
3660 struct xdr_stream xdr;
3661 struct compound_hdr hdr;
3664 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3665 status = decode_compound_hdr(&xdr, &hdr);
3668 status = decode_putfh(&xdr);
3671 status = decode_getacl(&xdr, rqstp, acl_len);
3678 * Decode CLOSE response
3680 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3682 struct xdr_stream xdr;
3683 struct compound_hdr hdr;
3686 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3687 status = decode_compound_hdr(&xdr, &hdr);
3690 status = decode_putfh(&xdr);
3693 status = decode_close(&xdr, res);
3697 * Note: Server may do delete on close for this file
3698 * in which case the getattr call will fail with
3699 * an ESTALE error. Shouldn't be a problem,
3700 * though, since fattr->valid will remain unset.
3702 decode_getfattr(&xdr, res->fattr, res->server);
3708 * Decode OPEN response
3710 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3712 struct xdr_stream xdr;
3713 struct compound_hdr hdr;
3716 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3717 status = decode_compound_hdr(&xdr, &hdr);
3720 status = decode_putfh(&xdr);
3723 status = decode_savefh(&xdr);
3726 status = decode_open(&xdr, res);
3729 status = decode_getfh(&xdr, &res->fh);
3732 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
3734 if ((status = decode_restorefh(&xdr)) != 0)
3736 decode_getfattr(&xdr, res->dir_attr, res->server);
3742 * Decode OPEN_CONFIRM response
3744 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3746 struct xdr_stream xdr;
3747 struct compound_hdr hdr;
3750 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3751 status = decode_compound_hdr(&xdr, &hdr);
3754 status = decode_putfh(&xdr);
3757 status = decode_open_confirm(&xdr, res);
3763 * Decode OPEN response
3765 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3767 struct xdr_stream xdr;
3768 struct compound_hdr hdr;
3771 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3772 status = decode_compound_hdr(&xdr, &hdr);
3775 status = decode_putfh(&xdr);
3778 status = decode_open(&xdr, res);
3784 * Decode SETATTR response
3786 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3788 struct xdr_stream xdr;
3789 struct compound_hdr hdr;
3792 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3793 status = decode_compound_hdr(&xdr, &hdr);
3796 status = decode_putfh(&xdr);
3799 status = decode_setattr(&xdr, res);
3802 status = decode_getfattr(&xdr, res->fattr, res->server);
3803 if (status == NFS4ERR_DELAY)
3810 * Decode LOCK response
3812 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3814 struct xdr_stream xdr;
3815 struct compound_hdr hdr;
3818 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3819 status = decode_compound_hdr(&xdr, &hdr);
3822 status = decode_putfh(&xdr);
3825 status = decode_lock(&xdr, res);
3831 * Decode LOCKT response
3833 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3835 struct xdr_stream xdr;
3836 struct compound_hdr hdr;
3839 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3840 status = decode_compound_hdr(&xdr, &hdr);
3843 status = decode_putfh(&xdr);
3846 status = decode_lockt(&xdr, res);
3852 * Decode LOCKU response
3854 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3856 struct xdr_stream xdr;
3857 struct compound_hdr hdr;
3860 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3861 status = decode_compound_hdr(&xdr, &hdr);
3864 status = decode_putfh(&xdr);
3867 status = decode_locku(&xdr, res);
3873 * Decode READLINK response
3875 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3877 struct xdr_stream xdr;
3878 struct compound_hdr hdr;
3881 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3882 status = decode_compound_hdr(&xdr, &hdr);
3885 status = decode_putfh(&xdr);
3888 status = decode_readlink(&xdr, rqstp);
3894 * Decode READDIR response
3896 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3898 struct xdr_stream xdr;
3899 struct compound_hdr hdr;
3902 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3903 status = decode_compound_hdr(&xdr, &hdr);
3906 status = decode_putfh(&xdr);
3909 status = decode_readdir(&xdr, rqstp, res);
3915 * Decode Read response
3917 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3919 struct xdr_stream xdr;
3920 struct compound_hdr hdr;
3923 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3924 status = decode_compound_hdr(&xdr, &hdr);
3927 status = decode_putfh(&xdr);
3930 status = decode_read(&xdr, rqstp, res);
3932 status = res->count;
3938 * Decode WRITE response
3940 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3942 struct xdr_stream xdr;
3943 struct compound_hdr hdr;
3946 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3947 status = decode_compound_hdr(&xdr, &hdr);
3950 status = decode_putfh(&xdr);
3953 status = decode_write(&xdr, res);
3955 status = res->count;
3961 * Decode COMMIT response
3963 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3965 struct xdr_stream xdr;
3966 struct compound_hdr hdr;
3969 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3970 status = decode_compound_hdr(&xdr, &hdr);
3973 status = decode_putfh(&xdr);
3976 status = decode_commit(&xdr, res);
3984 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3986 struct xdr_stream xdr;
3987 struct compound_hdr hdr;
3990 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3991 status = decode_compound_hdr(&xdr, &hdr);
3993 status = decode_putfh(&xdr);
3995 status = decode_fsinfo(&xdr, fsinfo);
3997 status = -nfs_stat_to_errno(hdr.status);
4004 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
4006 struct xdr_stream xdr;
4007 struct compound_hdr hdr;
4010 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4011 status = decode_compound_hdr(&xdr, &hdr);
4013 status = decode_putfh(&xdr);
4015 status = decode_pathconf(&xdr, pathconf);
4022 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
4024 struct xdr_stream xdr;
4025 struct compound_hdr hdr;
4028 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4029 status = decode_compound_hdr(&xdr, &hdr);
4031 status = decode_putfh(&xdr);
4033 status = decode_statfs(&xdr, fsstat);
4038 * GETATTR_BITMAP request
4040 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
4042 struct xdr_stream xdr;
4043 struct compound_hdr hdr;
4046 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4047 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4049 if ((status = decode_putfh(&xdr)) != 0)
4051 status = decode_server_caps(&xdr, res);
4057 * Decode RENEW response
4059 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
4061 struct xdr_stream xdr;
4062 struct compound_hdr hdr;
4065 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4066 status = decode_compound_hdr(&xdr, &hdr);
4068 status = decode_renew(&xdr);
4073 * a SETCLIENTID request
4075 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
4076 struct nfs4_client *clp)
4078 struct xdr_stream xdr;
4079 struct compound_hdr hdr;
4082 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4083 status = decode_compound_hdr(&xdr, &hdr);
4085 status = decode_setclientid(&xdr, clp);
4087 status = -nfs_stat_to_errno(hdr.status);
4092 * a SETCLIENTID_CONFIRM request
4094 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
4096 struct xdr_stream xdr;
4097 struct compound_hdr hdr;
4100 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4101 status = decode_compound_hdr(&xdr, &hdr);
4103 status = decode_setclientid_confirm(&xdr);
4105 status = decode_putrootfh(&xdr);
4107 status = decode_fsinfo(&xdr, fsinfo);
4109 status = -nfs_stat_to_errno(hdr.status);
4114 * DELEGRETURN request
4116 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
4118 struct xdr_stream xdr;
4119 struct compound_hdr hdr;
4122 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4123 status = decode_compound_hdr(&xdr, &hdr);
4125 status = decode_putfh(&xdr);
4127 status = decode_delegreturn(&xdr);
4132 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
4134 uint32_t bitmap[2] = {0};
4139 return ERR_PTR(-EAGAIN);
4141 return ERR_PTR(-EBADCOOKIE);
4144 entry->prev_cookie = entry->cookie;
4145 p = xdr_decode_hyper(p, &entry->cookie);
4146 entry->len = ntohl(*p++);
4147 entry->name = (const char *) p;
4148 p += XDR_QUADLEN(entry->len);
4151 * In case the server doesn't return an inode number,
4152 * we fake one here. (We don't use inode number 0,
4153 * since glibc seems to choke on it...)
4157 len = ntohl(*p++); /* bitmap length */
4159 bitmap[0] = ntohl(*p++);
4161 bitmap[1] = ntohl(*p++);
4165 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4167 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4168 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4169 /* Ignore the return value of rdattr_error for now */
4173 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4174 xdr_decode_hyper(p, &entry->ino);
4175 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4176 xdr_decode_hyper(p, &entry->ino);
4180 entry->eof = !p[0] && p[1];
4185 * We need to translate between nfs status return values and
4186 * the local errno values which may not be the same.
4193 { NFS4ERR_PERM, EPERM },
4194 { NFS4ERR_NOENT, ENOENT },
4195 { NFS4ERR_IO, errno_NFSERR_IO },
4196 { NFS4ERR_NXIO, ENXIO },
4197 { NFS4ERR_ACCESS, EACCES },
4198 { NFS4ERR_EXIST, EEXIST },
4199 { NFS4ERR_XDEV, EXDEV },
4200 { NFS4ERR_NOTDIR, ENOTDIR },
4201 { NFS4ERR_ISDIR, EISDIR },
4202 { NFS4ERR_INVAL, EINVAL },
4203 { NFS4ERR_FBIG, EFBIG },
4204 { NFS4ERR_NOSPC, ENOSPC },
4205 { NFS4ERR_ROFS, EROFS },
4206 { NFS4ERR_MLINK, EMLINK },
4207 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4208 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4209 { NFS4ERR_DQUOT, EDQUOT },
4210 { NFS4ERR_STALE, ESTALE },
4211 { NFS4ERR_BADHANDLE, EBADHANDLE },
4212 { NFS4ERR_BADOWNER, EINVAL },
4213 { NFS4ERR_BADNAME, EINVAL },
4214 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4215 { NFS4ERR_NOTSUPP, ENOTSUPP },
4216 { NFS4ERR_TOOSMALL, ETOOSMALL },
4217 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4218 { NFS4ERR_BADTYPE, EBADTYPE },
4219 { NFS4ERR_LOCKED, EAGAIN },
4220 { NFS4ERR_RESOURCE, EREMOTEIO },
4221 { NFS4ERR_SYMLINK, ELOOP },
4222 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4223 { NFS4ERR_DEADLOCK, EDEADLK },
4224 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4225 * to be handled by a
4232 * Convert an NFS error code to a local one.
4233 * This one is used jointly by NFSv2 and NFSv3.
4236 nfs_stat_to_errno(int stat)
4239 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4240 if (nfs_errtbl[i].stat == stat)
4241 return nfs_errtbl[i].errno;
4243 if (stat <= 10000 || stat > 10100) {
4244 /* The server is looney tunes. */
4245 return ESERVERFAULT;
4247 /* If we cannot translate the error, the recovery routines should
4249 * Note: remaining NFSv4 error codes have values > 10000, so should
4250 * not conflict with native Linux error codes.
4256 # define MAX(a, b) (((a) > (b))? (a) : (b))
4259 #define PROC(proc, argtype, restype) \
4260 [NFSPROC4_CLNT_##proc] = { \
4261 .p_proc = NFSPROC4_COMPOUND, \
4262 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4263 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4264 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
4267 struct rpc_procinfo nfs4_procedures[] = {
4268 PROC(READ, enc_read, dec_read),
4269 PROC(WRITE, enc_write, dec_write),
4270 PROC(COMMIT, enc_commit, dec_commit),
4271 PROC(OPEN, enc_open, dec_open),
4272 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4273 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4274 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4275 PROC(CLOSE, enc_close, dec_close),
4276 PROC(SETATTR, enc_setattr, dec_setattr),
4277 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4278 PROC(RENEW, enc_renew, dec_renew),
4279 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4280 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4281 PROC(LOCK, enc_lock, dec_lock),
4282 PROC(LOCKT, enc_lockt, dec_lockt),
4283 PROC(LOCKU, enc_locku, dec_locku),
4284 PROC(ACCESS, enc_access, dec_access),
4285 PROC(GETATTR, enc_getattr, dec_getattr),
4286 PROC(LOOKUP, enc_lookup, dec_lookup),
4287 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4288 PROC(REMOVE, enc_remove, dec_remove),
4289 PROC(RENAME, enc_rename, dec_rename),
4290 PROC(LINK, enc_link, dec_link),
4291 PROC(SYMLINK, enc_symlink, dec_symlink),
4292 PROC(CREATE, enc_create, dec_create),
4293 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4294 PROC(STATFS, enc_statfs, dec_statfs),
4295 PROC(READLINK, enc_readlink, dec_readlink),
4296 PROC(READDIR, enc_readdir, dec_readdir),
4297 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4298 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4299 PROC(GETACL, enc_getacl, dec_getacl),
4300 PROC(SETACL, enc_setacl, dec_setacl),
4303 struct rpc_version nfs_version4 = {
4305 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
4306 .procs = nfs4_procedures