[NETPOLL]: remove unused variable
[linux-2.6/zen-sources.git] / fs / nfs / nfs4xdr.c
blob6c564ef9489ef833fb293eb776aee4ec75db1290
1 /*
2 * fs/nfs/nfs4xdr.c
4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
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
14 * are met:
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>
40 #include <linux/mm.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
45 #include <linux/in.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>
54 #include "nfs4_fs.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 */
64 #ifdef DEBUG
65 #define NFS4_MAXTAGLEN 20
66 #else
67 #define NFS4_MAXTAGLEN 0
68 #endif
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 + \
79 (NFS4_FHSIZE >> 2))
80 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
81 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
82 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
83 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
84 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
85 ((3+NFS4_FHSIZE) >> 2))
86 #define nfs4_fattr_bitmap_maxsz 3
87 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
88 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
89 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
90 /* This is based on getfattr, which uses the most attributes: */
91 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
92 3 + 3 + 3 + 2 * nfs4_name_maxsz))
93 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
94 nfs4_fattr_value_maxsz)
95 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
96 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
97 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
98 #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
99 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
100 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
101 #define decode_renew_maxsz (op_decode_hdr_maxsz)
102 #define encode_setclientid_maxsz \
103 (op_encode_hdr_maxsz + \
104 4 /*server->ip_addr*/ + \
105 1 /*Netid*/ + \
106 6 /*uaddr*/ + \
107 6 + (NFS4_VERIFIER_SIZE >> 2))
108 #define decode_setclientid_maxsz \
109 (op_decode_hdr_maxsz + \
110 2 + \
111 1024) /* large value for CLID_INUSE */
112 #define encode_setclientid_confirm_maxsz \
113 (op_encode_hdr_maxsz + \
114 3 + (NFS4_VERIFIER_SIZE >> 2))
115 #define decode_setclientid_confirm_maxsz \
116 (op_decode_hdr_maxsz)
117 #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
118 1 + ((3 + NFS4_FHSIZE) >> 2))
119 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
120 nfs4_name_maxsz)
121 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
122 2 * nfs4_name_maxsz)
123 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
124 #define encode_link_maxsz (op_encode_hdr_maxsz + \
125 nfs4_name_maxsz)
126 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
127 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
128 1 + nfs4_name_maxsz + \
129 nfs4_path_maxsz + \
130 nfs4_fattr_maxsz)
131 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
132 #define encode_create_maxsz (op_encode_hdr_maxsz + \
133 2 + nfs4_name_maxsz + \
134 nfs4_fattr_maxsz)
135 #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
136 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
137 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
138 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
139 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
140 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
141 encode_putfh_maxsz + \
142 op_encode_hdr_maxsz + 7)
143 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
144 decode_putfh_maxsz + \
145 op_decode_hdr_maxsz + 2)
146 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
147 encode_putfh_maxsz + \
148 op_encode_hdr_maxsz)
149 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
150 decode_putfh_maxsz + \
151 op_decode_hdr_maxsz)
152 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
153 encode_putfh_maxsz + \
154 op_encode_hdr_maxsz + 9)
155 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
156 decode_putfh_maxsz + \
157 op_decode_hdr_maxsz + 2)
158 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
159 encode_putfh_maxsz + \
160 op_encode_hdr_maxsz + 8)
161 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
162 decode_putfh_maxsz + \
163 op_decode_hdr_maxsz + 4)
164 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
165 encode_putfh_maxsz + \
166 op_encode_hdr_maxsz + 3)
167 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
168 decode_putfh_maxsz + \
169 op_decode_hdr_maxsz + 2)
170 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
171 encode_putfh_maxsz + \
172 op_encode_hdr_maxsz + \
173 13 + 3 + 2 + 64 + \
174 encode_getattr_maxsz + \
175 encode_getfh_maxsz)
176 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
177 decode_putfh_maxsz + \
178 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
179 decode_getattr_maxsz + \
180 decode_getfh_maxsz)
181 #define NFS4_enc_open_confirm_sz \
182 (compound_encode_hdr_maxsz + \
183 encode_putfh_maxsz + \
184 op_encode_hdr_maxsz + 5)
185 #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
186 decode_putfh_maxsz + \
187 op_decode_hdr_maxsz + 4)
188 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
189 encode_putfh_maxsz + \
190 op_encode_hdr_maxsz + \
192 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
193 decode_putfh_maxsz + \
194 op_decode_hdr_maxsz + \
195 4 + 5 + 2 + 3)
196 #define NFS4_enc_open_downgrade_sz \
197 (compound_encode_hdr_maxsz + \
198 encode_putfh_maxsz + \
199 op_encode_hdr_maxsz + 7)
200 #define NFS4_dec_open_downgrade_sz \
201 (compound_decode_hdr_maxsz + \
202 decode_putfh_maxsz + \
203 op_decode_hdr_maxsz + 4)
204 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
205 encode_putfh_maxsz + \
206 op_encode_hdr_maxsz + 5)
207 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
208 decode_putfh_maxsz + \
209 op_decode_hdr_maxsz + 4)
210 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
211 encode_putfh_maxsz + \
212 op_encode_hdr_maxsz + 4 + \
213 nfs4_fattr_maxsz + \
214 encode_getattr_maxsz)
215 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
216 decode_putfh_maxsz + \
217 op_decode_hdr_maxsz + 3)
218 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
219 encode_putfh_maxsz + \
220 encode_fsinfo_maxsz)
221 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
222 decode_putfh_maxsz + \
223 decode_fsinfo_maxsz)
224 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
225 encode_renew_maxsz)
226 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
227 decode_renew_maxsz)
228 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
229 encode_setclientid_maxsz)
230 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
231 decode_setclientid_maxsz)
232 #define NFS4_enc_setclientid_confirm_sz \
233 (compound_encode_hdr_maxsz + \
234 encode_setclientid_confirm_maxsz + \
235 encode_putrootfh_maxsz + \
236 encode_fsinfo_maxsz)
237 #define NFS4_dec_setclientid_confirm_sz \
238 (compound_decode_hdr_maxsz + \
239 decode_setclientid_confirm_maxsz + \
240 decode_putrootfh_maxsz + \
241 decode_fsinfo_maxsz)
242 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
243 encode_putfh_maxsz + \
244 encode_getattr_maxsz + \
245 op_encode_hdr_maxsz + \
246 1 + 1 + 2 + 2 + \
247 1 + 4 + 1 + 2 + \
248 owner_id_maxsz)
249 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
250 decode_putfh_maxsz + \
251 decode_getattr_maxsz + \
252 op_decode_hdr_maxsz + \
253 2 + 2 + 1 + 2 + \
254 owner_id_maxsz)
255 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
256 encode_putfh_maxsz + \
257 encode_getattr_maxsz + \
258 op_encode_hdr_maxsz + \
259 1 + 2 + 2 + 2 + \
260 owner_id_maxsz)
261 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
262 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
263 encode_putfh_maxsz + \
264 encode_getattr_maxsz + \
265 op_encode_hdr_maxsz + \
266 1 + 1 + 4 + 2 + 2)
267 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
268 decode_putfh_maxsz + \
269 decode_getattr_maxsz + \
270 op_decode_hdr_maxsz + 4)
271 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
272 encode_putfh_maxsz + \
273 op_encode_hdr_maxsz + 1)
274 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
275 decode_putfh_maxsz + \
276 op_decode_hdr_maxsz + 2)
277 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
278 encode_putfh_maxsz + \
279 encode_getattr_maxsz)
280 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
281 decode_putfh_maxsz + \
282 decode_getattr_maxsz)
283 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
284 encode_putfh_maxsz + \
285 encode_lookup_maxsz + \
286 encode_getattr_maxsz + \
287 encode_getfh_maxsz)
288 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
289 decode_putfh_maxsz + \
290 op_decode_hdr_maxsz + \
291 decode_getattr_maxsz + \
292 decode_getfh_maxsz)
293 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
294 encode_putrootfh_maxsz + \
295 encode_getattr_maxsz + \
296 encode_getfh_maxsz)
297 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
298 decode_putrootfh_maxsz + \
299 decode_getattr_maxsz + \
300 decode_getfh_maxsz)
301 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
302 encode_putfh_maxsz + \
303 encode_remove_maxsz)
304 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
305 decode_putfh_maxsz + \
306 op_decode_hdr_maxsz + 5)
307 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
308 encode_putfh_maxsz + \
309 encode_savefh_maxsz + \
310 encode_putfh_maxsz + \
311 encode_rename_maxsz)
312 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
313 decode_putfh_maxsz + \
314 decode_savefh_maxsz + \
315 decode_putfh_maxsz + \
316 decode_rename_maxsz)
317 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
318 encode_putfh_maxsz + \
319 encode_savefh_maxsz + \
320 encode_putfh_maxsz + \
321 encode_link_maxsz)
322 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
323 decode_putfh_maxsz + \
324 decode_savefh_maxsz + \
325 decode_putfh_maxsz + \
326 decode_link_maxsz)
327 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
328 encode_putfh_maxsz + \
329 encode_symlink_maxsz + \
330 encode_getattr_maxsz + \
331 encode_getfh_maxsz)
332 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
333 decode_putfh_maxsz + \
334 decode_symlink_maxsz + \
335 decode_getattr_maxsz + \
336 decode_getfh_maxsz)
337 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
338 encode_putfh_maxsz + \
339 encode_create_maxsz + \
340 encode_getattr_maxsz + \
341 encode_getfh_maxsz)
342 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
343 decode_putfh_maxsz + \
344 decode_create_maxsz + \
345 decode_getattr_maxsz + \
346 decode_getfh_maxsz)
347 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
348 encode_putfh_maxsz + \
349 encode_getattr_maxsz)
350 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
351 decode_putfh_maxsz + \
352 decode_getattr_maxsz)
353 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
354 encode_putfh_maxsz + \
355 encode_getattr_maxsz)
356 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
357 decode_putfh_maxsz + \
358 op_decode_hdr_maxsz + 12)
359 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
360 encode_getattr_maxsz)
361 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
362 decode_getattr_maxsz)
363 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
364 encode_putfh_maxsz + \
365 encode_delegreturn_maxsz)
366 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
367 decode_delegreturn_maxsz)
368 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
369 encode_putfh_maxsz + \
370 encode_getattr_maxsz)
371 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
372 decode_putfh_maxsz + \
373 op_decode_hdr_maxsz + \
374 nfs4_fattr_bitmap_maxsz + 1)
375 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
376 encode_putfh_maxsz + \
377 op_encode_hdr_maxsz + 4 + \
378 nfs4_fattr_bitmap_maxsz + 1)
379 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
380 decode_putfh_maxsz + \
381 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
383 static struct {
384 unsigned int mode;
385 unsigned int nfs2type;
386 } nfs_type2fmt[] = {
387 { 0, NFNON },
388 { S_IFREG, NFREG },
389 { S_IFDIR, NFDIR },
390 { S_IFBLK, NFBLK },
391 { S_IFCHR, NFCHR },
392 { S_IFLNK, NFLNK },
393 { S_IFSOCK, NFSOCK },
394 { S_IFIFO, NFFIFO },
395 { 0, NFNON },
396 { 0, NFNON },
399 struct compound_hdr {
400 int32_t status;
401 uint32_t nops;
402 uint32_t taglen;
403 char * tag;
407 * START OF "GENERIC" ENCODE ROUTINES.
408 * These may look a little ugly since they are imported from a "generic"
409 * set of XDR encode/decode routines which are intended to be shared by
410 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
412 * If the pain of reading these is too great, it should be a straightforward
413 * task to translate them into Linux-specific versions which are more
414 * consistent with the style used in NFSv2/v3...
416 #define WRITE32(n) *p++ = htonl(n)
417 #define WRITE64(n) do { \
418 *p++ = htonl((uint32_t)((n) >> 32)); \
419 *p++ = htonl((uint32_t)(n)); \
420 } while (0)
421 #define WRITEMEM(ptr,nbytes) do { \
422 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
423 } while (0)
425 #define RESERVE_SPACE(nbytes) do { \
426 p = xdr_reserve_space(xdr, nbytes); \
427 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
428 BUG_ON(!p); \
429 } while (0)
431 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
433 uint32_t *p;
435 p = xdr_reserve_space(xdr, 4 + len);
436 BUG_ON(p == NULL);
437 xdr_encode_opaque(p, str, len);
440 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
442 uint32_t *p;
444 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
445 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
446 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
447 WRITE32(hdr->taglen);
448 WRITEMEM(hdr->tag, hdr->taglen);
449 WRITE32(NFS4_MINOR_VERSION);
450 WRITE32(hdr->nops);
451 return 0;
454 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
456 uint32_t *p;
458 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
459 BUG_ON(p == NULL);
460 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
463 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
465 char owner_name[IDMAP_NAMESZ];
466 char owner_group[IDMAP_NAMESZ];
467 int owner_namelen = 0;
468 int owner_grouplen = 0;
469 uint32_t *p;
470 uint32_t *q;
471 int len;
472 uint32_t bmval0 = 0;
473 uint32_t bmval1 = 0;
474 int status;
477 * We reserve enough space to write the entire attribute buffer at once.
478 * In the worst-case, this would be
479 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
480 * = 36 bytes, plus any contribution from variable-length fields
481 * such as owner/group.
483 len = 16;
485 /* Sigh */
486 if (iap->ia_valid & ATTR_SIZE)
487 len += 8;
488 if (iap->ia_valid & ATTR_MODE)
489 len += 4;
490 if (iap->ia_valid & ATTR_UID) {
491 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
492 if (owner_namelen < 0) {
493 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
494 iap->ia_uid);
495 /* XXX */
496 strcpy(owner_name, "nobody");
497 owner_namelen = sizeof("nobody") - 1;
498 /* goto out; */
500 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
502 if (iap->ia_valid & ATTR_GID) {
503 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
504 if (owner_grouplen < 0) {
505 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
506 iap->ia_gid);
507 strcpy(owner_group, "nobody");
508 owner_grouplen = sizeof("nobody") - 1;
509 /* goto out; */
511 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
513 if (iap->ia_valid & ATTR_ATIME_SET)
514 len += 16;
515 else if (iap->ia_valid & ATTR_ATIME)
516 len += 4;
517 if (iap->ia_valid & ATTR_MTIME_SET)
518 len += 16;
519 else if (iap->ia_valid & ATTR_MTIME)
520 len += 4;
521 RESERVE_SPACE(len);
524 * We write the bitmap length now, but leave the bitmap and the attribute
525 * buffer length to be backfilled at the end of this routine.
527 WRITE32(2);
528 q = p;
529 p += 3;
531 if (iap->ia_valid & ATTR_SIZE) {
532 bmval0 |= FATTR4_WORD0_SIZE;
533 WRITE64(iap->ia_size);
535 if (iap->ia_valid & ATTR_MODE) {
536 bmval1 |= FATTR4_WORD1_MODE;
537 WRITE32(iap->ia_mode);
539 if (iap->ia_valid & ATTR_UID) {
540 bmval1 |= FATTR4_WORD1_OWNER;
541 WRITE32(owner_namelen);
542 WRITEMEM(owner_name, owner_namelen);
544 if (iap->ia_valid & ATTR_GID) {
545 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
546 WRITE32(owner_grouplen);
547 WRITEMEM(owner_group, owner_grouplen);
549 if (iap->ia_valid & ATTR_ATIME_SET) {
550 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
551 WRITE32(NFS4_SET_TO_CLIENT_TIME);
552 WRITE32(0);
553 WRITE32(iap->ia_mtime.tv_sec);
554 WRITE32(iap->ia_mtime.tv_nsec);
556 else if (iap->ia_valid & ATTR_ATIME) {
557 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
558 WRITE32(NFS4_SET_TO_SERVER_TIME);
560 if (iap->ia_valid & ATTR_MTIME_SET) {
561 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
562 WRITE32(NFS4_SET_TO_CLIENT_TIME);
563 WRITE32(0);
564 WRITE32(iap->ia_mtime.tv_sec);
565 WRITE32(iap->ia_mtime.tv_nsec);
567 else if (iap->ia_valid & ATTR_MTIME) {
568 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
569 WRITE32(NFS4_SET_TO_SERVER_TIME);
573 * Now we backfill the bitmap and the attribute buffer length.
575 if (len != ((char *)p - (char *)q) + 4) {
576 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
577 len, ((char *)p - (char *)q) + 4);
578 BUG();
580 len = (char *)p - (char *)q - 12;
581 *q++ = htonl(bmval0);
582 *q++ = htonl(bmval1);
583 *q++ = htonl(len);
585 status = 0;
586 /* out: */
587 return status;
590 static int encode_access(struct xdr_stream *xdr, u32 access)
592 uint32_t *p;
594 RESERVE_SPACE(8);
595 WRITE32(OP_ACCESS);
596 WRITE32(access);
598 return 0;
601 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
603 uint32_t *p;
605 RESERVE_SPACE(8+sizeof(arg->stateid.data));
606 WRITE32(OP_CLOSE);
607 WRITE32(arg->seqid);
608 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
610 return 0;
613 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
615 uint32_t *p;
617 RESERVE_SPACE(16);
618 WRITE32(OP_COMMIT);
619 WRITE64(args->offset);
620 WRITE32(args->count);
622 return 0;
625 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
627 uint32_t *p;
629 RESERVE_SPACE(8);
630 WRITE32(OP_CREATE);
631 WRITE32(create->ftype);
633 switch (create->ftype) {
634 case NF4LNK:
635 RESERVE_SPACE(4 + create->u.symlink->len);
636 WRITE32(create->u.symlink->len);
637 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
638 break;
640 case NF4BLK: case NF4CHR:
641 RESERVE_SPACE(8);
642 WRITE32(create->u.device.specdata1);
643 WRITE32(create->u.device.specdata2);
644 break;
646 default:
647 break;
650 RESERVE_SPACE(4 + create->name->len);
651 WRITE32(create->name->len);
652 WRITEMEM(create->name->name, create->name->len);
654 return encode_attrs(xdr, create->attrs, create->server);
657 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
659 uint32_t *p;
661 RESERVE_SPACE(12);
662 WRITE32(OP_GETATTR);
663 WRITE32(1);
664 WRITE32(bitmap);
665 return 0;
668 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
670 uint32_t *p;
672 RESERVE_SPACE(16);
673 WRITE32(OP_GETATTR);
674 WRITE32(2);
675 WRITE32(bm0);
676 WRITE32(bm1);
677 return 0;
680 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
682 return encode_getattr_two(xdr,
683 bitmask[0] & nfs4_fattr_bitmap[0],
684 bitmask[1] & nfs4_fattr_bitmap[1]);
687 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
689 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
690 bitmask[1] & nfs4_fsinfo_bitmap[1]);
693 static int encode_getfh(struct xdr_stream *xdr)
695 uint32_t *p;
697 RESERVE_SPACE(4);
698 WRITE32(OP_GETFH);
700 return 0;
703 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
705 uint32_t *p;
707 RESERVE_SPACE(8 + name->len);
708 WRITE32(OP_LINK);
709 WRITE32(name->len);
710 WRITEMEM(name->name, name->len);
712 return 0;
716 * opcode,type,reclaim,offset,length,new_lock_owner = 32
717 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
719 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
721 uint32_t *p;
722 struct nfs_lock_opargs *opargs = arg->u.lock;
724 RESERVE_SPACE(32);
725 WRITE32(OP_LOCK);
726 WRITE32(arg->type);
727 WRITE32(opargs->reclaim);
728 WRITE64(arg->offset);
729 WRITE64(arg->length);
730 WRITE32(opargs->new_lock_owner);
731 if (opargs->new_lock_owner){
732 struct nfs_open_to_lock *ol = opargs->u.open_lock;
734 RESERVE_SPACE(40);
735 WRITE32(ol->open_seqid);
736 WRITEMEM(&ol->open_stateid, sizeof(ol->open_stateid));
737 WRITE32(ol->lock_seqid);
738 WRITE64(ol->lock_owner.clientid);
739 WRITE32(4);
740 WRITE32(ol->lock_owner.id);
742 else {
743 struct nfs_exist_lock *el = opargs->u.exist_lock;
745 RESERVE_SPACE(20);
746 WRITEMEM(&el->stateid, sizeof(el->stateid));
747 WRITE32(el->seqid);
750 return 0;
753 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
755 uint32_t *p;
756 struct nfs_lowner *opargs = arg->u.lockt;
758 RESERVE_SPACE(40);
759 WRITE32(OP_LOCKT);
760 WRITE32(arg->type);
761 WRITE64(arg->offset);
762 WRITE64(arg->length);
763 WRITE64(opargs->clientid);
764 WRITE32(4);
765 WRITE32(opargs->id);
767 return 0;
770 static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
772 uint32_t *p;
773 struct nfs_locku_opargs *opargs = arg->u.locku;
775 RESERVE_SPACE(44);
776 WRITE32(OP_LOCKU);
777 WRITE32(arg->type);
778 WRITE32(opargs->seqid);
779 WRITEMEM(&opargs->stateid, sizeof(opargs->stateid));
780 WRITE64(arg->offset);
781 WRITE64(arg->length);
783 return 0;
786 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
788 int len = name->len;
789 uint32_t *p;
791 RESERVE_SPACE(8 + len);
792 WRITE32(OP_LOOKUP);
793 WRITE32(len);
794 WRITEMEM(name->name, len);
796 return 0;
799 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
801 uint32_t *p;
803 RESERVE_SPACE(8);
804 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
805 case FMODE_READ:
806 WRITE32(NFS4_SHARE_ACCESS_READ);
807 break;
808 case FMODE_WRITE:
809 WRITE32(NFS4_SHARE_ACCESS_WRITE);
810 break;
811 case FMODE_READ|FMODE_WRITE:
812 WRITE32(NFS4_SHARE_ACCESS_BOTH);
813 break;
814 default:
815 BUG();
817 WRITE32(0); /* for linux, share_deny = 0 always */
820 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
822 uint32_t *p;
824 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
825 * owner 4 = 32
827 RESERVE_SPACE(8);
828 WRITE32(OP_OPEN);
829 WRITE32(arg->seqid);
830 encode_share_access(xdr, arg->open_flags);
831 RESERVE_SPACE(16);
832 WRITE64(arg->clientid);
833 WRITE32(4);
834 WRITE32(arg->id);
837 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
839 uint32_t *p;
841 RESERVE_SPACE(4);
842 switch(arg->open_flags & O_EXCL) {
843 case 0:
844 WRITE32(NFS4_CREATE_UNCHECKED);
845 encode_attrs(xdr, arg->u.attrs, arg->server);
846 break;
847 default:
848 WRITE32(NFS4_CREATE_EXCLUSIVE);
849 encode_nfs4_verifier(xdr, &arg->u.verifier);
853 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
855 uint32_t *p;
857 RESERVE_SPACE(4);
858 switch (arg->open_flags & O_CREAT) {
859 case 0:
860 WRITE32(NFS4_OPEN_NOCREATE);
861 break;
862 default:
863 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
864 WRITE32(NFS4_OPEN_CREATE);
865 encode_createmode(xdr, arg);
869 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
871 uint32_t *p;
873 RESERVE_SPACE(4);
874 switch (delegation_type) {
875 case 0:
876 WRITE32(NFS4_OPEN_DELEGATE_NONE);
877 break;
878 case FMODE_READ:
879 WRITE32(NFS4_OPEN_DELEGATE_READ);
880 break;
881 case FMODE_WRITE|FMODE_READ:
882 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
883 break;
884 default:
885 BUG();
889 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
891 uint32_t *p;
893 RESERVE_SPACE(4);
894 WRITE32(NFS4_OPEN_CLAIM_NULL);
895 encode_string(xdr, name->len, name->name);
898 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
900 uint32_t *p;
902 RESERVE_SPACE(4);
903 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
904 encode_delegation_type(xdr, type);
907 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
909 uint32_t *p;
911 RESERVE_SPACE(4+sizeof(stateid->data));
912 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
913 WRITEMEM(stateid->data, sizeof(stateid->data));
914 encode_string(xdr, name->len, name->name);
917 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
919 encode_openhdr(xdr, arg);
920 encode_opentype(xdr, arg);
921 switch (arg->claim) {
922 case NFS4_OPEN_CLAIM_NULL:
923 encode_claim_null(xdr, arg->name);
924 break;
925 case NFS4_OPEN_CLAIM_PREVIOUS:
926 encode_claim_previous(xdr, arg->u.delegation_type);
927 break;
928 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
929 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
930 break;
931 default:
932 BUG();
934 return 0;
937 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
939 uint32_t *p;
941 RESERVE_SPACE(8+sizeof(arg->stateid.data));
942 WRITE32(OP_OPEN_CONFIRM);
943 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
944 WRITE32(arg->seqid);
946 return 0;
949 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
951 uint32_t *p;
953 RESERVE_SPACE(8+sizeof(arg->stateid.data));
954 WRITE32(OP_OPEN_DOWNGRADE);
955 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
956 WRITE32(arg->seqid);
957 encode_share_access(xdr, arg->open_flags);
958 return 0;
961 static int
962 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
964 int len = fh->size;
965 uint32_t *p;
967 RESERVE_SPACE(8 + len);
968 WRITE32(OP_PUTFH);
969 WRITE32(len);
970 WRITEMEM(fh->data, len);
972 return 0;
975 static int encode_putrootfh(struct xdr_stream *xdr)
977 uint32_t *p;
979 RESERVE_SPACE(4);
980 WRITE32(OP_PUTROOTFH);
982 return 0;
985 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
987 nfs4_stateid stateid;
988 uint32_t *p;
990 RESERVE_SPACE(16);
991 if (ctx->state != NULL) {
992 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
993 WRITEMEM(stateid.data, sizeof(stateid.data));
994 } else
995 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
998 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1000 uint32_t *p;
1002 RESERVE_SPACE(4);
1003 WRITE32(OP_READ);
1005 encode_stateid(xdr, args->context);
1007 RESERVE_SPACE(12);
1008 WRITE64(args->offset);
1009 WRITE32(args->count);
1011 return 0;
1014 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1016 struct rpc_auth *auth = req->rq_task->tk_auth;
1017 uint32_t attrs[2] = {
1018 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1019 FATTR4_WORD1_MOUNTED_ON_FILEID,
1021 int replen;
1022 uint32_t *p;
1024 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1025 WRITE32(OP_READDIR);
1026 WRITE64(readdir->cookie);
1027 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1028 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1029 WRITE32(readdir->count);
1030 WRITE32(2);
1031 /* Switch to mounted_on_fileid if the server supports it */
1032 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1033 attrs[0] &= ~FATTR4_WORD0_FILEID;
1034 else
1035 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1036 WRITE32(attrs[0] & readdir->bitmask[0]);
1037 WRITE32(attrs[1] & readdir->bitmask[1]);
1038 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1039 __FUNCTION__,
1040 (unsigned long long)readdir->cookie,
1041 ((u32 *)readdir->verifier.data)[0],
1042 ((u32 *)readdir->verifier.data)[1],
1043 attrs[0] & readdir->bitmask[0],
1044 attrs[1] & readdir->bitmask[1]);
1046 /* set up reply kvec
1047 * toplevel_status + taglen + rescount + OP_PUTFH + status
1048 * + OP_READDIR + status + verifer(2) = 9
1050 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1051 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1052 readdir->pgbase, readdir->count);
1053 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1054 __FUNCTION__, replen, readdir->pages,
1055 readdir->pgbase, readdir->count);
1057 return 0;
1060 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1062 struct rpc_auth *auth = req->rq_task->tk_auth;
1063 unsigned int replen;
1064 uint32_t *p;
1066 RESERVE_SPACE(4);
1067 WRITE32(OP_READLINK);
1069 /* set up reply kvec
1070 * toplevel_status + taglen + rescount + OP_PUTFH + status
1071 * + OP_READLINK + status + string length = 8
1073 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1074 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1075 readlink->pgbase, readlink->pglen);
1077 return 0;
1080 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1082 uint32_t *p;
1084 RESERVE_SPACE(8 + name->len);
1085 WRITE32(OP_REMOVE);
1086 WRITE32(name->len);
1087 WRITEMEM(name->name, name->len);
1089 return 0;
1092 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1094 uint32_t *p;
1096 RESERVE_SPACE(8 + oldname->len);
1097 WRITE32(OP_RENAME);
1098 WRITE32(oldname->len);
1099 WRITEMEM(oldname->name, oldname->len);
1101 RESERVE_SPACE(4 + newname->len);
1102 WRITE32(newname->len);
1103 WRITEMEM(newname->name, newname->len);
1105 return 0;
1108 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1110 uint32_t *p;
1112 RESERVE_SPACE(12);
1113 WRITE32(OP_RENEW);
1114 WRITE64(client_stateid->cl_clientid);
1116 return 0;
1119 static int
1120 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1122 uint32_t *p;
1124 RESERVE_SPACE(4+sizeof(zero_stateid.data));
1125 WRITE32(OP_SETATTR);
1126 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1127 RESERVE_SPACE(2*4);
1128 WRITE32(1);
1129 WRITE32(FATTR4_WORD0_ACL);
1130 if (arg->acl_len % 4)
1131 return -EINVAL;
1132 RESERVE_SPACE(4);
1133 WRITE32(arg->acl_len);
1134 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1135 return 0;
1138 static int
1139 encode_savefh(struct xdr_stream *xdr)
1141 uint32_t *p;
1143 RESERVE_SPACE(4);
1144 WRITE32(OP_SAVEFH);
1146 return 0;
1149 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1151 int status;
1152 uint32_t *p;
1154 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1155 WRITE32(OP_SETATTR);
1156 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1158 if ((status = encode_attrs(xdr, arg->iap, server)))
1159 return status;
1161 return 0;
1164 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1166 uint32_t *p;
1168 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1169 WRITE32(OP_SETCLIENTID);
1170 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1172 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1173 RESERVE_SPACE(4);
1174 WRITE32(setclientid->sc_prog);
1175 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1176 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1177 RESERVE_SPACE(4);
1178 WRITE32(setclientid->sc_cb_ident);
1180 return 0;
1183 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1185 uint32_t *p;
1187 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1188 WRITE32(OP_SETCLIENTID_CONFIRM);
1189 WRITE64(client_state->cl_clientid);
1190 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1192 return 0;
1195 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1197 uint32_t *p;
1199 RESERVE_SPACE(4);
1200 WRITE32(OP_WRITE);
1202 encode_stateid(xdr, args->context);
1204 RESERVE_SPACE(16);
1205 WRITE64(args->offset);
1206 WRITE32(args->stable);
1207 WRITE32(args->count);
1209 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1211 return 0;
1214 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1216 uint32_t *p;
1218 RESERVE_SPACE(20);
1220 WRITE32(OP_DELEGRETURN);
1221 WRITEMEM(stateid->data, sizeof(stateid->data));
1222 return 0;
1226 * END OF "GENERIC" ENCODE ROUTINES.
1230 * Encode an ACCESS request
1232 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1234 struct xdr_stream xdr;
1235 struct compound_hdr hdr = {
1236 .nops = 2,
1238 int status;
1240 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1241 encode_compound_hdr(&xdr, &hdr);
1242 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1243 status = encode_access(&xdr, args->access);
1244 return status;
1248 * Encode LOOKUP request
1250 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1252 struct xdr_stream xdr;
1253 struct compound_hdr hdr = {
1254 .nops = 4,
1256 int status;
1258 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1259 encode_compound_hdr(&xdr, &hdr);
1260 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1261 goto out;
1262 if ((status = encode_lookup(&xdr, args->name)) != 0)
1263 goto out;
1264 if ((status = encode_getfh(&xdr)) != 0)
1265 goto out;
1266 status = encode_getfattr(&xdr, args->bitmask);
1267 out:
1268 return status;
1272 * Encode LOOKUP_ROOT request
1274 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1276 struct xdr_stream xdr;
1277 struct compound_hdr hdr = {
1278 .nops = 3,
1280 int status;
1282 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1283 encode_compound_hdr(&xdr, &hdr);
1284 if ((status = encode_putrootfh(&xdr)) != 0)
1285 goto out;
1286 if ((status = encode_getfh(&xdr)) == 0)
1287 status = encode_getfattr(&xdr, args->bitmask);
1288 out:
1289 return status;
1293 * Encode REMOVE request
1295 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1297 struct xdr_stream xdr;
1298 struct compound_hdr hdr = {
1299 .nops = 2,
1301 int status;
1303 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1304 encode_compound_hdr(&xdr, &hdr);
1305 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1306 status = encode_remove(&xdr, args->name);
1307 return status;
1311 * Encode RENAME request
1313 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1315 struct xdr_stream xdr;
1316 struct compound_hdr hdr = {
1317 .nops = 4,
1319 int status;
1321 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1322 encode_compound_hdr(&xdr, &hdr);
1323 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1324 goto out;
1325 if ((status = encode_savefh(&xdr)) != 0)
1326 goto out;
1327 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1328 goto out;
1329 status = encode_rename(&xdr, args->old_name, args->new_name);
1330 out:
1331 return status;
1335 * Encode LINK request
1337 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1339 struct xdr_stream xdr;
1340 struct compound_hdr hdr = {
1341 .nops = 4,
1343 int status;
1345 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1346 encode_compound_hdr(&xdr, &hdr);
1347 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1348 goto out;
1349 if ((status = encode_savefh(&xdr)) != 0)
1350 goto out;
1351 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1352 goto out;
1353 status = encode_link(&xdr, args->name);
1354 out:
1355 return status;
1359 * Encode CREATE request
1361 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1363 struct xdr_stream xdr;
1364 struct compound_hdr hdr = {
1365 .nops = 4,
1367 int status;
1369 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1370 encode_compound_hdr(&xdr, &hdr);
1371 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1372 goto out;
1373 if ((status = encode_create(&xdr, args)) != 0)
1374 goto out;
1375 if ((status = encode_getfh(&xdr)) != 0)
1376 goto out;
1377 status = encode_getfattr(&xdr, args->bitmask);
1378 out:
1379 return status;
1383 * Encode SYMLINK request
1385 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1387 return nfs4_xdr_enc_create(req, p, args);
1391 * Encode GETATTR request
1393 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1395 struct xdr_stream xdr;
1396 struct compound_hdr hdr = {
1397 .nops = 2,
1399 int status;
1401 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1402 encode_compound_hdr(&xdr, &hdr);
1403 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1404 status = encode_getfattr(&xdr, args->bitmask);
1405 return status;
1409 * Encode a CLOSE request
1411 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1413 struct xdr_stream xdr;
1414 struct compound_hdr hdr = {
1415 .nops = 2,
1417 int status;
1419 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1420 encode_compound_hdr(&xdr, &hdr);
1421 status = encode_putfh(&xdr, args->fh);
1422 if(status)
1423 goto out;
1424 status = encode_close(&xdr, args);
1425 out:
1426 return status;
1430 * Encode an OPEN request
1432 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1434 struct xdr_stream xdr;
1435 struct compound_hdr hdr = {
1436 .nops = 4,
1438 int status;
1440 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1441 encode_compound_hdr(&xdr, &hdr);
1442 status = encode_putfh(&xdr, args->fh);
1443 if (status)
1444 goto out;
1445 status = encode_open(&xdr, args);
1446 if (status)
1447 goto out;
1448 status = encode_getfh(&xdr);
1449 if (status)
1450 goto out;
1451 status = encode_getfattr(&xdr, args->bitmask);
1452 out:
1453 return status;
1457 * Encode an OPEN_CONFIRM request
1459 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1461 struct xdr_stream xdr;
1462 struct compound_hdr hdr = {
1463 .nops = 2,
1465 int status;
1467 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1468 encode_compound_hdr(&xdr, &hdr);
1469 status = encode_putfh(&xdr, args->fh);
1470 if(status)
1471 goto out;
1472 status = encode_open_confirm(&xdr, args);
1473 out:
1474 return status;
1478 * Encode an OPEN request with no attributes.
1480 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1482 struct xdr_stream xdr;
1483 struct compound_hdr hdr = {
1484 .nops = 2,
1486 int status;
1488 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1489 encode_compound_hdr(&xdr, &hdr);
1490 status = encode_putfh(&xdr, args->fh);
1491 if (status)
1492 goto out;
1493 status = encode_open(&xdr, args);
1494 out:
1495 return status;
1499 * Encode an OPEN_DOWNGRADE request
1501 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1503 struct xdr_stream xdr;
1504 struct compound_hdr hdr = {
1505 .nops = 2,
1507 int status;
1509 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1510 encode_compound_hdr(&xdr, &hdr);
1511 status = encode_putfh(&xdr, args->fh);
1512 if (status)
1513 goto out;
1514 status = encode_open_downgrade(&xdr, args);
1515 out:
1516 return status;
1520 * Encode a LOCK request
1522 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1524 struct xdr_stream xdr;
1525 struct compound_hdr hdr = {
1526 .nops = 2,
1528 int status;
1530 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1531 encode_compound_hdr(&xdr, &hdr);
1532 status = encode_putfh(&xdr, args->fh);
1533 if(status)
1534 goto out;
1535 status = encode_lock(&xdr, args);
1536 out:
1537 return status;
1541 * Encode a LOCKT request
1543 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1545 struct xdr_stream xdr;
1546 struct compound_hdr hdr = {
1547 .nops = 2,
1549 int status;
1551 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1552 encode_compound_hdr(&xdr, &hdr);
1553 status = encode_putfh(&xdr, args->fh);
1554 if(status)
1555 goto out;
1556 status = encode_lockt(&xdr, args);
1557 out:
1558 return status;
1562 * Encode a LOCKU request
1564 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1566 struct xdr_stream xdr;
1567 struct compound_hdr hdr = {
1568 .nops = 2,
1570 int status;
1572 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1573 encode_compound_hdr(&xdr, &hdr);
1574 status = encode_putfh(&xdr, args->fh);
1575 if(status)
1576 goto out;
1577 status = encode_locku(&xdr, args);
1578 out:
1579 return status;
1583 * Encode a READLINK request
1585 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1587 struct xdr_stream xdr;
1588 struct compound_hdr hdr = {
1589 .nops = 2,
1591 int status;
1593 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1594 encode_compound_hdr(&xdr, &hdr);
1595 status = encode_putfh(&xdr, args->fh);
1596 if(status)
1597 goto out;
1598 status = encode_readlink(&xdr, args, req);
1599 out:
1600 return status;
1604 * Encode a READDIR request
1606 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1608 struct xdr_stream xdr;
1609 struct compound_hdr hdr = {
1610 .nops = 2,
1612 int status;
1614 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1615 encode_compound_hdr(&xdr, &hdr);
1616 status = encode_putfh(&xdr, args->fh);
1617 if(status)
1618 goto out;
1619 status = encode_readdir(&xdr, args, req);
1620 out:
1621 return status;
1625 * Encode a READ request
1627 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1629 struct rpc_auth *auth = req->rq_task->tk_auth;
1630 struct xdr_stream xdr;
1631 struct compound_hdr hdr = {
1632 .nops = 2,
1634 int replen, status;
1636 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1637 encode_compound_hdr(&xdr, &hdr);
1638 status = encode_putfh(&xdr, args->fh);
1639 if (status)
1640 goto out;
1641 status = encode_read(&xdr, args);
1642 if (status)
1643 goto out;
1645 /* set up reply kvec
1646 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1647 * + OP_READ + status + eof + datalen = 9
1649 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1650 xdr_inline_pages(&req->rq_rcv_buf, replen,
1651 args->pages, args->pgbase, args->count);
1652 out:
1653 return status;
1657 * Encode an SETATTR request
1659 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1662 struct xdr_stream xdr;
1663 struct compound_hdr hdr = {
1664 .nops = 3,
1666 int status;
1668 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1669 encode_compound_hdr(&xdr, &hdr);
1670 status = encode_putfh(&xdr, args->fh);
1671 if(status)
1672 goto out;
1673 status = encode_setattr(&xdr, args, args->server);
1674 if(status)
1675 goto out;
1676 status = encode_getfattr(&xdr, args->bitmask);
1677 out:
1678 return status;
1682 * Encode a GETACL request
1684 static int
1685 nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p,
1686 struct nfs_getaclargs *args)
1688 struct xdr_stream xdr;
1689 struct rpc_auth *auth = req->rq_task->tk_auth;
1690 struct compound_hdr hdr = {
1691 .nops = 2,
1693 int replen, status;
1695 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1696 encode_compound_hdr(&xdr, &hdr);
1697 status = encode_putfh(&xdr, args->fh);
1698 if (status)
1699 goto out;
1700 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1701 /* set up reply buffer: */
1702 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1703 xdr_inline_pages(&req->rq_rcv_buf, replen,
1704 args->acl_pages, args->acl_pgbase, args->acl_len);
1705 out:
1706 return status;
1710 * Encode a WRITE request
1712 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1714 struct xdr_stream xdr;
1715 struct compound_hdr hdr = {
1716 .nops = 2,
1718 int status;
1720 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1721 encode_compound_hdr(&xdr, &hdr);
1722 status = encode_putfh(&xdr, args->fh);
1723 if (status)
1724 goto out;
1725 status = encode_write(&xdr, args);
1726 out:
1727 return status;
1731 * a COMMIT request
1733 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1735 struct xdr_stream xdr;
1736 struct compound_hdr hdr = {
1737 .nops = 2,
1739 int status;
1741 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1742 encode_compound_hdr(&xdr, &hdr);
1743 status = encode_putfh(&xdr, args->fh);
1744 if (status)
1745 goto out;
1746 status = encode_commit(&xdr, args);
1747 out:
1748 return status;
1752 * FSINFO request
1754 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1756 struct xdr_stream xdr;
1757 struct compound_hdr hdr = {
1758 .nops = 2,
1760 int status;
1762 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1763 encode_compound_hdr(&xdr, &hdr);
1764 status = encode_putfh(&xdr, args->fh);
1765 if (!status)
1766 status = encode_fsinfo(&xdr, args->bitmask);
1767 return status;
1771 * a PATHCONF request
1773 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1775 struct xdr_stream xdr;
1776 struct compound_hdr hdr = {
1777 .nops = 2,
1779 int status;
1781 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1782 encode_compound_hdr(&xdr, &hdr);
1783 status = encode_putfh(&xdr, args->fh);
1784 if (!status)
1785 status = encode_getattr_one(&xdr,
1786 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1787 return status;
1791 * a STATFS request
1793 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1795 struct xdr_stream xdr;
1796 struct compound_hdr hdr = {
1797 .nops = 2,
1799 int status;
1801 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1802 encode_compound_hdr(&xdr, &hdr);
1803 status = encode_putfh(&xdr, args->fh);
1804 if (status == 0)
1805 status = encode_getattr_two(&xdr,
1806 args->bitmask[0] & nfs4_statfs_bitmap[0],
1807 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1808 return status;
1812 * GETATTR_BITMAP request
1814 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1816 struct xdr_stream xdr;
1817 struct compound_hdr hdr = {
1818 .nops = 2,
1820 int status;
1822 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1823 encode_compound_hdr(&xdr, &hdr);
1824 status = encode_putfh(&xdr, fhandle);
1825 if (status == 0)
1826 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1827 FATTR4_WORD0_LINK_SUPPORT|
1828 FATTR4_WORD0_SYMLINK_SUPPORT|
1829 FATTR4_WORD0_ACLSUPPORT);
1830 return status;
1834 * a RENEW request
1836 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1838 struct xdr_stream xdr;
1839 struct compound_hdr hdr = {
1840 .nops = 1,
1843 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1844 encode_compound_hdr(&xdr, &hdr);
1845 return encode_renew(&xdr, clp);
1849 * a SETCLIENTID request
1851 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1853 struct xdr_stream xdr;
1854 struct compound_hdr hdr = {
1855 .nops = 1,
1858 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1859 encode_compound_hdr(&xdr, &hdr);
1860 return encode_setclientid(&xdr, sc);
1864 * a SETCLIENTID_CONFIRM request
1866 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1868 struct xdr_stream xdr;
1869 struct compound_hdr hdr = {
1870 .nops = 3,
1872 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1873 int status;
1875 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1876 encode_compound_hdr(&xdr, &hdr);
1877 status = encode_setclientid_confirm(&xdr, clp);
1878 if (!status)
1879 status = encode_putrootfh(&xdr);
1880 if (!status)
1881 status = encode_fsinfo(&xdr, lease_bitmap);
1882 return status;
1886 * DELEGRETURN request
1888 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1890 struct xdr_stream xdr;
1891 struct compound_hdr hdr = {
1892 .nops = 2,
1894 int status;
1896 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1897 encode_compound_hdr(&xdr, &hdr);
1898 if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
1899 status = encode_delegreturn(&xdr, args->stateid);
1900 return status;
1904 * START OF "GENERIC" DECODE ROUTINES.
1905 * These may look a little ugly since they are imported from a "generic"
1906 * set of XDR encode/decode routines which are intended to be shared by
1907 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1909 * If the pain of reading these is too great, it should be a straightforward
1910 * task to translate them into Linux-specific versions which are more
1911 * consistent with the style used in NFSv2/v3...
1913 #define READ32(x) (x) = ntohl(*p++)
1914 #define READ64(x) do { \
1915 (x) = (u64)ntohl(*p++) << 32; \
1916 (x) |= ntohl(*p++); \
1917 } while (0)
1918 #define READTIME(x) do { \
1919 p++; \
1920 (x.tv_sec) = ntohl(*p++); \
1921 (x.tv_nsec) = ntohl(*p++); \
1922 } while (0)
1923 #define COPYMEM(x,nbytes) do { \
1924 memcpy((x), p, nbytes); \
1925 p += XDR_QUADLEN(nbytes); \
1926 } while (0)
1928 #define READ_BUF(nbytes) do { \
1929 p = xdr_inline_decode(xdr, nbytes); \
1930 if (!p) { \
1931 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
1932 __FUNCTION__, __LINE__); \
1933 return -EIO; \
1935 } while (0)
1937 static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
1939 uint32_t *p;
1941 READ_BUF(4);
1942 READ32(*len);
1943 READ_BUF(*len);
1944 *string = (char *)p;
1945 return 0;
1948 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
1950 uint32_t *p;
1952 READ_BUF(8);
1953 READ32(hdr->status);
1954 READ32(hdr->taglen);
1956 READ_BUF(hdr->taglen + 4);
1957 hdr->tag = (char *)p;
1958 p += XDR_QUADLEN(hdr->taglen);
1959 READ32(hdr->nops);
1960 return 0;
1963 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
1965 uint32_t *p;
1966 uint32_t opnum;
1967 int32_t nfserr;
1969 READ_BUF(8);
1970 READ32(opnum);
1971 if (opnum != expected) {
1972 printk(KERN_NOTICE
1973 "nfs4_decode_op_hdr: Server returned operation"
1974 " %d but we issued a request for %d\n",
1975 opnum, expected);
1976 return -EIO;
1978 READ32(nfserr);
1979 if (nfserr != NFS_OK)
1980 return -nfs_stat_to_errno(nfserr);
1981 return 0;
1984 /* Dummy routine */
1985 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
1987 uint32_t *p;
1988 uint32_t strlen;
1989 char *str;
1991 READ_BUF(12);
1992 return decode_opaque_inline(xdr, &strlen, &str);
1995 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
1997 uint32_t bmlen, *p;
1999 READ_BUF(4);
2000 READ32(bmlen);
2002 bitmap[0] = bitmap[1] = 0;
2003 READ_BUF((bmlen << 2));
2004 if (bmlen > 0) {
2005 READ32(bitmap[0]);
2006 if (bmlen > 1)
2007 READ32(bitmap[1]);
2009 return 0;
2012 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
2014 uint32_t *p;
2016 READ_BUF(4);
2017 READ32(*attrlen);
2018 *savep = xdr->p;
2019 return 0;
2022 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2024 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2025 decode_attr_bitmap(xdr, bitmask);
2026 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2027 } else
2028 bitmask[0] = bitmask[1] = 0;
2029 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2030 return 0;
2033 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2035 uint32_t *p;
2037 *type = 0;
2038 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2039 return -EIO;
2040 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2041 READ_BUF(4);
2042 READ32(*type);
2043 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2044 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2045 return -EIO;
2047 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2049 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2050 return 0;
2053 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2055 uint32_t *p;
2057 *change = 0;
2058 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2059 return -EIO;
2060 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2061 READ_BUF(8);
2062 READ64(*change);
2063 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2065 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2066 (unsigned long long)*change);
2067 return 0;
2070 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2072 uint32_t *p;
2074 *size = 0;
2075 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2076 return -EIO;
2077 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2078 READ_BUF(8);
2079 READ64(*size);
2080 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2082 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2083 return 0;
2086 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2088 uint32_t *p;
2090 *res = 0;
2091 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2092 return -EIO;
2093 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2094 READ_BUF(4);
2095 READ32(*res);
2096 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2098 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2099 return 0;
2102 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2104 uint32_t *p;
2106 *res = 0;
2107 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2108 return -EIO;
2109 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2110 READ_BUF(4);
2111 READ32(*res);
2112 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2114 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2115 return 0;
2118 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2120 uint32_t *p;
2122 fsid->major = 0;
2123 fsid->minor = 0;
2124 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2125 return -EIO;
2126 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2127 READ_BUF(16);
2128 READ64(fsid->major);
2129 READ64(fsid->minor);
2130 bitmap[0] &= ~FATTR4_WORD0_FSID;
2132 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2133 (unsigned long long)fsid->major,
2134 (unsigned long long)fsid->minor);
2135 return 0;
2138 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2140 uint32_t *p;
2142 *res = 60;
2143 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2144 return -EIO;
2145 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2146 READ_BUF(4);
2147 READ32(*res);
2148 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2150 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2151 return 0;
2154 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2156 uint32_t *p;
2158 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2159 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2160 return -EIO;
2161 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2162 READ_BUF(4);
2163 READ32(*res);
2164 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2166 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2167 return 0;
2170 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2172 uint32_t *p;
2174 *fileid = 0;
2175 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2176 return -EIO;
2177 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2178 READ_BUF(8);
2179 READ64(*fileid);
2180 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2182 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2183 return 0;
2186 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2188 uint32_t *p;
2189 int status = 0;
2191 *res = 0;
2192 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2193 return -EIO;
2194 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2195 READ_BUF(8);
2196 READ64(*res);
2197 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2199 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2200 return status;
2203 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2205 uint32_t *p;
2206 int status = 0;
2208 *res = 0;
2209 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2210 return -EIO;
2211 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2212 READ_BUF(8);
2213 READ64(*res);
2214 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2216 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2217 return status;
2220 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2222 uint32_t *p;
2223 int status = 0;
2225 *res = 0;
2226 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2227 return -EIO;
2228 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2229 READ_BUF(8);
2230 READ64(*res);
2231 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2233 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2234 return status;
2237 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2239 uint32_t *p;
2240 int status = 0;
2242 *res = 0;
2243 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2244 return -EIO;
2245 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2246 READ_BUF(8);
2247 READ64(*res);
2248 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2250 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2251 return status;
2254 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2256 uint32_t *p;
2257 int status = 0;
2259 *maxlink = 1;
2260 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2261 return -EIO;
2262 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2263 READ_BUF(4);
2264 READ32(*maxlink);
2265 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2267 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2268 return status;
2271 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2273 uint32_t *p;
2274 int status = 0;
2276 *maxname = 1024;
2277 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2278 return -EIO;
2279 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2280 READ_BUF(4);
2281 READ32(*maxname);
2282 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2284 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2285 return status;
2288 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2290 uint32_t *p;
2291 int status = 0;
2293 *res = 1024;
2294 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2295 return -EIO;
2296 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2297 uint64_t maxread;
2298 READ_BUF(8);
2299 READ64(maxread);
2300 if (maxread > 0x7FFFFFFF)
2301 maxread = 0x7FFFFFFF;
2302 *res = (uint32_t)maxread;
2303 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2305 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2306 return status;
2309 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2311 uint32_t *p;
2312 int status = 0;
2314 *res = 1024;
2315 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2316 return -EIO;
2317 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2318 uint64_t maxwrite;
2319 READ_BUF(8);
2320 READ64(maxwrite);
2321 if (maxwrite > 0x7FFFFFFF)
2322 maxwrite = 0x7FFFFFFF;
2323 *res = (uint32_t)maxwrite;
2324 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2326 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2327 return status;
2330 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2332 uint32_t *p;
2334 *mode = 0;
2335 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2336 return -EIO;
2337 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2338 READ_BUF(4);
2339 READ32(*mode);
2340 *mode &= ~S_IFMT;
2341 bitmap[1] &= ~FATTR4_WORD1_MODE;
2343 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2344 return 0;
2347 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2349 uint32_t *p;
2351 *nlink = 1;
2352 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2353 return -EIO;
2354 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2355 READ_BUF(4);
2356 READ32(*nlink);
2357 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2359 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2360 return 0;
2363 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2365 uint32_t len, *p;
2367 *uid = -2;
2368 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2369 return -EIO;
2370 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2371 READ_BUF(4);
2372 READ32(len);
2373 READ_BUF(len);
2374 if (len < XDR_MAX_NETOBJ) {
2375 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2376 dprintk("%s: nfs_map_name_to_uid failed!\n",
2377 __FUNCTION__);
2378 } else
2379 printk(KERN_WARNING "%s: name too long (%u)!\n",
2380 __FUNCTION__, len);
2381 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2383 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2384 return 0;
2387 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2389 uint32_t len, *p;
2391 *gid = -2;
2392 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2393 return -EIO;
2394 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2395 READ_BUF(4);
2396 READ32(len);
2397 READ_BUF(len);
2398 if (len < XDR_MAX_NETOBJ) {
2399 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2400 dprintk("%s: nfs_map_group_to_gid failed!\n",
2401 __FUNCTION__);
2402 } else
2403 printk(KERN_WARNING "%s: name too long (%u)!\n",
2404 __FUNCTION__, len);
2405 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2407 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2408 return 0;
2411 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2413 uint32_t major = 0, minor = 0, *p;
2415 *rdev = MKDEV(0,0);
2416 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2417 return -EIO;
2418 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2419 dev_t tmp;
2421 READ_BUF(8);
2422 READ32(major);
2423 READ32(minor);
2424 tmp = MKDEV(major, minor);
2425 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2426 *rdev = tmp;
2427 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2429 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2430 return 0;
2433 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2435 uint32_t *p;
2436 int status = 0;
2438 *res = 0;
2439 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2440 return -EIO;
2441 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2442 READ_BUF(8);
2443 READ64(*res);
2444 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2446 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2447 return status;
2450 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2452 uint32_t *p;
2453 int status = 0;
2455 *res = 0;
2456 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2457 return -EIO;
2458 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2459 READ_BUF(8);
2460 READ64(*res);
2461 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2463 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2464 return status;
2467 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2469 uint32_t *p;
2470 int status = 0;
2472 *res = 0;
2473 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2474 return -EIO;
2475 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2476 READ_BUF(8);
2477 READ64(*res);
2478 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2480 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2481 return status;
2484 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2486 uint32_t *p;
2488 *used = 0;
2489 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2490 return -EIO;
2491 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2492 READ_BUF(8);
2493 READ64(*used);
2494 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2496 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2497 (unsigned long long)*used);
2498 return 0;
2501 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2503 uint32_t *p;
2504 uint64_t sec;
2505 uint32_t nsec;
2507 READ_BUF(12);
2508 READ64(sec);
2509 READ32(nsec);
2510 time->tv_sec = (time_t)sec;
2511 time->tv_nsec = (long)nsec;
2512 return 0;
2515 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2517 int status = 0;
2519 time->tv_sec = 0;
2520 time->tv_nsec = 0;
2521 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2522 return -EIO;
2523 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2524 status = decode_attr_time(xdr, time);
2525 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2527 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2528 return status;
2531 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2533 int status = 0;
2535 time->tv_sec = 0;
2536 time->tv_nsec = 0;
2537 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2538 return -EIO;
2539 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2540 status = decode_attr_time(xdr, time);
2541 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2543 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2544 return status;
2547 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2549 int status = 0;
2551 time->tv_sec = 0;
2552 time->tv_nsec = 0;
2553 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2554 return -EIO;
2555 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2556 status = decode_attr_time(xdr, time);
2557 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2559 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2560 return status;
2563 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2565 unsigned int attrwords = XDR_QUADLEN(attrlen);
2566 unsigned int nwords = xdr->p - savep;
2568 if (unlikely(attrwords != nwords)) {
2569 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2570 __FUNCTION__,
2571 attrwords << 2,
2572 (attrwords < nwords) ? '<' : '>',
2573 nwords << 2);
2574 return -EIO;
2576 return 0;
2579 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2581 uint32_t *p;
2583 READ_BUF(20);
2584 READ32(cinfo->atomic);
2585 READ64(cinfo->before);
2586 READ64(cinfo->after);
2587 return 0;
2590 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2592 uint32_t *p;
2593 uint32_t supp, acc;
2594 int status;
2596 status = decode_op_hdr(xdr, OP_ACCESS);
2597 if (status)
2598 return status;
2599 READ_BUF(8);
2600 READ32(supp);
2601 READ32(acc);
2602 access->supported = supp;
2603 access->access = acc;
2604 return 0;
2607 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2609 uint32_t *p;
2610 int status;
2612 status = decode_op_hdr(xdr, OP_CLOSE);
2613 if (status)
2614 return status;
2615 READ_BUF(sizeof(res->stateid.data));
2616 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2617 return 0;
2620 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2622 uint32_t *p;
2623 int status;
2625 status = decode_op_hdr(xdr, OP_COMMIT);
2626 if (status)
2627 return status;
2628 READ_BUF(8);
2629 COPYMEM(res->verf->verifier, 8);
2630 return 0;
2633 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2635 uint32_t *p;
2636 uint32_t bmlen;
2637 int status;
2639 status = decode_op_hdr(xdr, OP_CREATE);
2640 if (status)
2641 return status;
2642 if ((status = decode_change_info(xdr, cinfo)))
2643 return status;
2644 READ_BUF(4);
2645 READ32(bmlen);
2646 READ_BUF(bmlen << 2);
2647 return 0;
2650 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2652 uint32_t *savep;
2653 uint32_t attrlen,
2654 bitmap[2] = {0};
2655 int status;
2657 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2658 goto xdr_error;
2659 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2660 goto xdr_error;
2661 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2662 goto xdr_error;
2663 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2664 goto xdr_error;
2665 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2666 goto xdr_error;
2667 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2668 goto xdr_error;
2669 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2670 goto xdr_error;
2671 status = verify_attr_len(xdr, savep, attrlen);
2672 xdr_error:
2673 if (status != 0)
2674 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2675 return status;
2678 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2680 uint32_t *savep;
2681 uint32_t attrlen,
2682 bitmap[2] = {0};
2683 int status;
2685 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2686 goto xdr_error;
2687 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2688 goto xdr_error;
2689 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2690 goto xdr_error;
2692 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2693 goto xdr_error;
2694 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2695 goto xdr_error;
2696 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2697 goto xdr_error;
2698 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2699 goto xdr_error;
2700 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2701 goto xdr_error;
2702 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2703 goto xdr_error;
2705 status = verify_attr_len(xdr, savep, attrlen);
2706 xdr_error:
2707 if (status != 0)
2708 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2709 return status;
2712 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2714 uint32_t *savep;
2715 uint32_t attrlen,
2716 bitmap[2] = {0};
2717 int status;
2719 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2720 goto xdr_error;
2721 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2722 goto xdr_error;
2723 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2724 goto xdr_error;
2726 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2727 goto xdr_error;
2728 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2729 goto xdr_error;
2731 status = verify_attr_len(xdr, savep, attrlen);
2732 xdr_error:
2733 if (status != 0)
2734 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2735 return status;
2738 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2740 uint32_t *savep;
2741 uint32_t attrlen,
2742 bitmap[2] = {0},
2743 type;
2744 int status, fmode = 0;
2746 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2747 goto xdr_error;
2748 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2749 goto xdr_error;
2751 fattr->bitmap[0] = bitmap[0];
2752 fattr->bitmap[1] = bitmap[1];
2754 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2755 goto xdr_error;
2758 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2759 goto xdr_error;
2760 fattr->type = nfs_type2fmt[type].nfs2type;
2761 fmode = nfs_type2fmt[type].mode;
2763 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2764 goto xdr_error;
2765 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2766 goto xdr_error;
2767 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2768 goto xdr_error;
2769 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2770 goto xdr_error;
2771 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2772 goto xdr_error;
2773 fattr->mode |= fmode;
2774 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2775 goto xdr_error;
2776 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2777 goto xdr_error;
2778 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2779 goto xdr_error;
2780 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2781 goto xdr_error;
2782 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2783 goto xdr_error;
2784 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2785 goto xdr_error;
2786 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2787 goto xdr_error;
2788 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2789 goto xdr_error;
2790 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) {
2791 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2792 fattr->timestamp = jiffies;
2794 xdr_error:
2795 if (status != 0)
2796 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2797 return status;
2801 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2803 uint32_t *savep;
2804 uint32_t attrlen, bitmap[2];
2805 int status;
2807 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2808 goto xdr_error;
2809 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2810 goto xdr_error;
2811 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2812 goto xdr_error;
2814 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2816 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2817 goto xdr_error;
2818 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2819 goto xdr_error;
2820 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2821 goto xdr_error;
2822 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2823 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2824 goto xdr_error;
2825 fsinfo->wtpref = fsinfo->wtmax;
2827 status = verify_attr_len(xdr, savep, attrlen);
2828 xdr_error:
2829 if (status != 0)
2830 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2831 return status;
2834 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2836 uint32_t *p;
2837 uint32_t len;
2838 int status;
2840 status = decode_op_hdr(xdr, OP_GETFH);
2841 if (status)
2842 return status;
2843 /* Zero handle first to allow comparisons */
2844 memset(fh, 0, sizeof(*fh));
2846 READ_BUF(4);
2847 READ32(len);
2848 if (len > NFS4_FHSIZE)
2849 return -EIO;
2850 fh->size = len;
2851 READ_BUF(len);
2852 COPYMEM(fh->data, len);
2853 return 0;
2856 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2858 int status;
2860 status = decode_op_hdr(xdr, OP_LINK);
2861 if (status)
2862 return status;
2863 return decode_change_info(xdr, cinfo);
2867 * We create the owner, so we know a proper owner.id length is 4.
2869 static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2871 uint32_t *p;
2872 uint32_t namelen;
2874 READ_BUF(32);
2875 READ64(denied->offset);
2876 READ64(denied->length);
2877 READ32(denied->type);
2878 READ64(denied->owner.clientid);
2879 READ32(namelen);
2880 READ_BUF(namelen);
2881 if (namelen == 4)
2882 READ32(denied->owner.id);
2883 return -NFS4ERR_DENIED;
2886 static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2888 uint32_t *p;
2889 int status;
2891 status = decode_op_hdr(xdr, OP_LOCK);
2892 if (status == 0) {
2893 READ_BUF(sizeof(nfs4_stateid));
2894 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2895 } else if (status == -NFS4ERR_DENIED)
2896 return decode_lock_denied(xdr, &res->u.denied);
2897 return status;
2900 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2902 int status;
2903 status = decode_op_hdr(xdr, OP_LOCKT);
2904 if (status == -NFS4ERR_DENIED)
2905 return decode_lock_denied(xdr, &res->u.denied);
2906 return status;
2909 static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2911 uint32_t *p;
2912 int status;
2914 status = decode_op_hdr(xdr, OP_LOCKU);
2915 if (status == 0) {
2916 READ_BUF(sizeof(nfs4_stateid));
2917 COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
2919 return status;
2922 static int decode_lookup(struct xdr_stream *xdr)
2924 return decode_op_hdr(xdr, OP_LOOKUP);
2927 /* This is too sick! */
2928 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
2930 uint32_t *p;
2931 uint32_t limit_type, nblocks, blocksize;
2933 READ_BUF(12);
2934 READ32(limit_type);
2935 switch (limit_type) {
2936 case 1:
2937 READ64(*maxsize);
2938 break;
2939 case 2:
2940 READ32(nblocks);
2941 READ32(blocksize);
2942 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
2944 return 0;
2947 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
2949 uint32_t *p;
2950 uint32_t delegation_type;
2952 READ_BUF(4);
2953 READ32(delegation_type);
2954 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
2955 res->delegation_type = 0;
2956 return 0;
2958 READ_BUF(20);
2959 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
2960 READ32(res->do_recall);
2961 switch (delegation_type) {
2962 case NFS4_OPEN_DELEGATE_READ:
2963 res->delegation_type = FMODE_READ;
2964 break;
2965 case NFS4_OPEN_DELEGATE_WRITE:
2966 res->delegation_type = FMODE_WRITE|FMODE_READ;
2967 if (decode_space_limit(xdr, &res->maxsize) < 0)
2968 return -EIO;
2970 return decode_ace(xdr, NULL, res->server->nfs4_state);
2973 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
2975 uint32_t *p;
2976 uint32_t bmlen;
2977 int status;
2979 status = decode_op_hdr(xdr, OP_OPEN);
2980 if (status)
2981 return status;
2982 READ_BUF(sizeof(res->stateid.data));
2983 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2985 decode_change_info(xdr, &res->cinfo);
2987 READ_BUF(8);
2988 READ32(res->rflags);
2989 READ32(bmlen);
2990 if (bmlen > 10)
2991 goto xdr_error;
2993 READ_BUF(bmlen << 2);
2994 p += bmlen;
2995 return decode_delegation(xdr, res);
2996 xdr_error:
2997 printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
2998 return -EIO;
3001 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3003 uint32_t *p;
3004 int status;
3006 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3007 if (status)
3008 return status;
3009 READ_BUF(sizeof(res->stateid.data));
3010 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3011 return 0;
3014 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3016 uint32_t *p;
3017 int status;
3019 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3020 if (status)
3021 return status;
3022 READ_BUF(sizeof(res->stateid.data));
3023 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3024 return 0;
3027 static int decode_putfh(struct xdr_stream *xdr)
3029 return decode_op_hdr(xdr, OP_PUTFH);
3032 static int decode_putrootfh(struct xdr_stream *xdr)
3034 return decode_op_hdr(xdr, OP_PUTROOTFH);
3037 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3039 struct kvec *iov = req->rq_rcv_buf.head;
3040 uint32_t *p;
3041 uint32_t count, eof, recvd, hdrlen;
3042 int status;
3044 status = decode_op_hdr(xdr, OP_READ);
3045 if (status)
3046 return status;
3047 READ_BUF(8);
3048 READ32(eof);
3049 READ32(count);
3050 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3051 recvd = req->rq_rcv_buf.len - hdrlen;
3052 if (count > recvd) {
3053 printk(KERN_WARNING "NFS: server cheating in read reply: "
3054 "count %u > recvd %u\n", count, recvd);
3055 count = recvd;
3056 eof = 0;
3058 xdr_read_pages(xdr, count);
3059 res->eof = eof;
3060 res->count = count;
3061 return 0;
3064 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3066 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3067 struct page *page = *rcvbuf->pages;
3068 struct kvec *iov = rcvbuf->head;
3069 unsigned int nr, pglen = rcvbuf->page_len;
3070 uint32_t *end, *entry, *p, *kaddr;
3071 uint32_t len, attrlen;
3072 int hdrlen, recvd, status;
3074 status = decode_op_hdr(xdr, OP_READDIR);
3075 if (status)
3076 return status;
3077 READ_BUF(8);
3078 COPYMEM(readdir->verifier.data, 8);
3079 dprintk("%s: verifier = 0x%x%x\n",
3080 __FUNCTION__,
3081 ((u32 *)readdir->verifier.data)[0],
3082 ((u32 *)readdir->verifier.data)[1]);
3085 hdrlen = (char *) p - (char *) iov->iov_base;
3086 recvd = rcvbuf->len - hdrlen;
3087 if (pglen > recvd)
3088 pglen = recvd;
3089 xdr_read_pages(xdr, pglen);
3091 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3092 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3093 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3094 entry = p;
3095 for (nr = 0; *p++; nr++) {
3096 if (p + 3 > end)
3097 goto short_pkt;
3098 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3099 p += 2; /* cookie */
3100 len = ntohl(*p++); /* filename length */
3101 if (len > NFS4_MAXNAMLEN) {
3102 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3103 goto err_unmap;
3105 dprintk("filename = %*s\n", len, (char *)p);
3106 p += XDR_QUADLEN(len);
3107 if (p + 1 > end)
3108 goto short_pkt;
3109 len = ntohl(*p++); /* bitmap length */
3110 p += len;
3111 if (p + 1 > end)
3112 goto short_pkt;
3113 attrlen = XDR_QUADLEN(ntohl(*p++));
3114 p += attrlen; /* attributes */
3115 if (p + 2 > end)
3116 goto short_pkt;
3117 entry = p;
3119 if (!nr && (entry[0] != 0 || entry[1] == 0))
3120 goto short_pkt;
3121 out:
3122 kunmap_atomic(kaddr, KM_USER0);
3123 return 0;
3124 short_pkt:
3125 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3126 entry[0] = entry[1] = 0;
3127 /* truncate listing ? */
3128 if (!nr) {
3129 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3130 entry[1] = 1;
3132 goto out;
3133 err_unmap:
3134 kunmap_atomic(kaddr, KM_USER0);
3135 return -errno_NFSERR_IO;
3138 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3140 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3141 struct kvec *iov = rcvbuf->head;
3142 int hdrlen, len, recvd;
3143 uint32_t *p;
3144 char *kaddr;
3145 int status;
3147 status = decode_op_hdr(xdr, OP_READLINK);
3148 if (status)
3149 return status;
3151 /* Convert length of symlink */
3152 READ_BUF(4);
3153 READ32(len);
3154 if (len >= rcvbuf->page_len || len <= 0) {
3155 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3156 return -ENAMETOOLONG;
3158 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3159 recvd = req->rq_rcv_buf.len - hdrlen;
3160 if (recvd < len) {
3161 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3162 "count %u > recvd %u\n", len, recvd);
3163 return -EIO;
3165 xdr_read_pages(xdr, len);
3167 * The XDR encode routine has set things up so that
3168 * the link text will be copied directly into the
3169 * buffer. We just have to do overflow-checking,
3170 * and and null-terminate the text (the VFS expects
3171 * null-termination).
3173 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3174 kaddr[len+rcvbuf->page_base] = '\0';
3175 kunmap_atomic(kaddr, KM_USER0);
3176 return 0;
3179 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3181 int status;
3183 status = decode_op_hdr(xdr, OP_REMOVE);
3184 if (status)
3185 goto out;
3186 status = decode_change_info(xdr, cinfo);
3187 out:
3188 return status;
3191 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3192 struct nfs4_change_info *new_cinfo)
3194 int status;
3196 status = decode_op_hdr(xdr, OP_RENAME);
3197 if (status)
3198 goto out;
3199 if ((status = decode_change_info(xdr, old_cinfo)))
3200 goto out;
3201 status = decode_change_info(xdr, new_cinfo);
3202 out:
3203 return status;
3206 static int decode_renew(struct xdr_stream *xdr)
3208 return decode_op_hdr(xdr, OP_RENEW);
3211 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3212 size_t *acl_len)
3214 uint32_t *savep;
3215 uint32_t attrlen,
3216 bitmap[2] = {0};
3217 struct kvec *iov = req->rq_rcv_buf.head;
3218 int status;
3220 *acl_len = 0;
3221 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3222 goto out;
3223 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3224 goto out;
3225 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3226 goto out;
3228 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3229 return -EIO;
3230 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3231 int hdrlen, recvd;
3233 /* We ignore &savep and don't do consistency checks on
3234 * the attr length. Let userspace figure it out.... */
3235 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3236 recvd = req->rq_rcv_buf.len - hdrlen;
3237 if (attrlen > recvd) {
3238 printk(KERN_WARNING "NFS: server cheating in getattr"
3239 " acl reply: attrlen %u > recvd %u\n",
3240 attrlen, recvd);
3241 return -EINVAL;
3243 if (attrlen <= *acl_len)
3244 xdr_read_pages(xdr, attrlen);
3245 *acl_len = attrlen;
3248 out:
3249 return status;
3252 static int
3253 decode_savefh(struct xdr_stream *xdr)
3255 return decode_op_hdr(xdr, OP_SAVEFH);
3258 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3260 uint32_t *p;
3261 uint32_t bmlen;
3262 int status;
3265 status = decode_op_hdr(xdr, OP_SETATTR);
3266 if (status)
3267 return status;
3268 READ_BUF(4);
3269 READ32(bmlen);
3270 READ_BUF(bmlen << 2);
3271 return 0;
3274 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3276 uint32_t *p;
3277 uint32_t opnum;
3278 int32_t nfserr;
3280 READ_BUF(8);
3281 READ32(opnum);
3282 if (opnum != OP_SETCLIENTID) {
3283 printk(KERN_NOTICE
3284 "nfs4_decode_setclientid: Server returned operation"
3285 " %d\n", opnum);
3286 return -EIO;
3288 READ32(nfserr);
3289 if (nfserr == NFS_OK) {
3290 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3291 READ64(clp->cl_clientid);
3292 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3293 } else if (nfserr == NFSERR_CLID_INUSE) {
3294 uint32_t len;
3296 /* skip netid string */
3297 READ_BUF(4);
3298 READ32(len);
3299 READ_BUF(len);
3301 /* skip uaddr string */
3302 READ_BUF(4);
3303 READ32(len);
3304 READ_BUF(len);
3305 return -NFSERR_CLID_INUSE;
3306 } else
3307 return -nfs_stat_to_errno(nfserr);
3309 return 0;
3312 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3314 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3317 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3319 uint32_t *p;
3320 int status;
3322 status = decode_op_hdr(xdr, OP_WRITE);
3323 if (status)
3324 return status;
3326 READ_BUF(16);
3327 READ32(res->count);
3328 READ32(res->verf->committed);
3329 COPYMEM(res->verf->verifier, 8);
3330 return 0;
3333 static int decode_delegreturn(struct xdr_stream *xdr)
3335 return decode_op_hdr(xdr, OP_DELEGRETURN);
3339 * Decode OPEN_DOWNGRADE response
3341 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3343 struct xdr_stream xdr;
3344 struct compound_hdr hdr;
3345 int status;
3347 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3348 status = decode_compound_hdr(&xdr, &hdr);
3349 if (status)
3350 goto out;
3351 status = decode_putfh(&xdr);
3352 if (status)
3353 goto out;
3354 status = decode_open_downgrade(&xdr, res);
3355 out:
3356 return status;
3360 * END OF "GENERIC" DECODE ROUTINES.
3364 * Decode ACCESS response
3366 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3368 struct xdr_stream xdr;
3369 struct compound_hdr hdr;
3370 int status;
3372 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3373 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3374 goto out;
3375 if ((status = decode_putfh(&xdr)) == 0)
3376 status = decode_access(&xdr, res);
3377 out:
3378 return status;
3382 * Decode LOOKUP response
3384 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3386 struct xdr_stream xdr;
3387 struct compound_hdr hdr;
3388 int status;
3390 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3391 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3392 goto out;
3393 if ((status = decode_putfh(&xdr)) != 0)
3394 goto out;
3395 if ((status = decode_lookup(&xdr)) != 0)
3396 goto out;
3397 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3398 goto out;
3399 status = decode_getfattr(&xdr, res->fattr, res->server);
3400 out:
3401 return status;
3405 * Decode LOOKUP_ROOT response
3407 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3409 struct xdr_stream xdr;
3410 struct compound_hdr hdr;
3411 int status;
3413 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3414 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3415 goto out;
3416 if ((status = decode_putrootfh(&xdr)) != 0)
3417 goto out;
3418 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3419 status = decode_getfattr(&xdr, res->fattr, res->server);
3420 out:
3421 return status;
3425 * Decode REMOVE response
3427 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3429 struct xdr_stream xdr;
3430 struct compound_hdr hdr;
3431 int status;
3433 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3434 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3435 goto out;
3436 if ((status = decode_putfh(&xdr)) == 0)
3437 status = decode_remove(&xdr, cinfo);
3438 out:
3439 return status;
3443 * Decode RENAME response
3445 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3447 struct xdr_stream xdr;
3448 struct compound_hdr hdr;
3449 int status;
3451 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3452 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3453 goto out;
3454 if ((status = decode_putfh(&xdr)) != 0)
3455 goto out;
3456 if ((status = decode_savefh(&xdr)) != 0)
3457 goto out;
3458 if ((status = decode_putfh(&xdr)) != 0)
3459 goto out;
3460 status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
3461 out:
3462 return status;
3466 * Decode LINK response
3468 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3470 struct xdr_stream xdr;
3471 struct compound_hdr hdr;
3472 int status;
3474 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3475 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3476 goto out;
3477 if ((status = decode_putfh(&xdr)) != 0)
3478 goto out;
3479 if ((status = decode_savefh(&xdr)) != 0)
3480 goto out;
3481 if ((status = decode_putfh(&xdr)) != 0)
3482 goto out;
3483 status = decode_link(&xdr, cinfo);
3484 out:
3485 return status;
3489 * Decode CREATE response
3491 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3493 struct xdr_stream xdr;
3494 struct compound_hdr hdr;
3495 int status;
3497 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3498 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3499 goto out;
3500 if ((status = decode_putfh(&xdr)) != 0)
3501 goto out;
3502 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3503 goto out;
3504 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3505 goto out;
3506 status = decode_getfattr(&xdr, res->fattr, res->server);
3507 if (status == NFS4ERR_DELAY)
3508 status = 0;
3509 out:
3510 return status;
3514 * Decode SYMLINK response
3516 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3518 return nfs4_xdr_dec_create(rqstp, p, res);
3522 * Decode GETATTR response
3524 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3526 struct xdr_stream xdr;
3527 struct compound_hdr hdr;
3528 int status;
3530 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3531 status = decode_compound_hdr(&xdr, &hdr);
3532 if (status)
3533 goto out;
3534 status = decode_putfh(&xdr);
3535 if (status)
3536 goto out;
3537 status = decode_getfattr(&xdr, res->fattr, res->server);
3538 out:
3539 return status;
3544 * Encode an SETACL request
3546 static int
3547 nfs4_xdr_enc_setacl(struct rpc_rqst *req, uint32_t *p, struct nfs_setaclargs *args)
3549 struct xdr_stream xdr;
3550 struct compound_hdr hdr = {
3551 .nops = 2,
3553 int status;
3555 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3556 encode_compound_hdr(&xdr, &hdr);
3557 status = encode_putfh(&xdr, args->fh);
3558 if (status)
3559 goto out;
3560 status = encode_setacl(&xdr, args);
3561 out:
3562 return status;
3565 * Decode SETACL response
3567 static int
3568 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3570 struct xdr_stream xdr;
3571 struct compound_hdr hdr;
3572 int status;
3574 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3575 status = decode_compound_hdr(&xdr, &hdr);
3576 if (status)
3577 goto out;
3578 status = decode_putfh(&xdr);
3579 if (status)
3580 goto out;
3581 status = decode_setattr(&xdr, res);
3582 out:
3583 return status;
3587 * Decode GETACL response
3589 static int
3590 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len)
3592 struct xdr_stream xdr;
3593 struct compound_hdr hdr;
3594 int status;
3596 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3597 status = decode_compound_hdr(&xdr, &hdr);
3598 if (status)
3599 goto out;
3600 status = decode_putfh(&xdr);
3601 if (status)
3602 goto out;
3603 status = decode_getacl(&xdr, rqstp, acl_len);
3605 out:
3606 return status;
3610 * Decode CLOSE response
3612 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3614 struct xdr_stream xdr;
3615 struct compound_hdr hdr;
3616 int status;
3618 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3619 status = decode_compound_hdr(&xdr, &hdr);
3620 if (status)
3621 goto out;
3622 status = decode_putfh(&xdr);
3623 if (status)
3624 goto out;
3625 status = decode_close(&xdr, res);
3626 out:
3627 return status;
3631 * Decode OPEN response
3633 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3635 struct xdr_stream xdr;
3636 struct compound_hdr hdr;
3637 int status;
3639 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3640 status = decode_compound_hdr(&xdr, &hdr);
3641 if (status)
3642 goto out;
3643 status = decode_putfh(&xdr);
3644 if (status)
3645 goto out;
3646 status = decode_open(&xdr, res);
3647 if (status)
3648 goto out;
3649 status = decode_getfh(&xdr, &res->fh);
3650 if (status)
3651 goto out;
3652 status = decode_getfattr(&xdr, res->f_attr, res->server);
3653 if (status == NFS4ERR_DELAY)
3654 status = 0;
3655 out:
3656 return status;
3660 * Decode OPEN_CONFIRM response
3662 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3664 struct xdr_stream xdr;
3665 struct compound_hdr hdr;
3666 int status;
3668 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3669 status = decode_compound_hdr(&xdr, &hdr);
3670 if (status)
3671 goto out;
3672 status = decode_putfh(&xdr);
3673 if (status)
3674 goto out;
3675 status = decode_open_confirm(&xdr, res);
3676 out:
3677 return status;
3681 * Decode OPEN response
3683 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3685 struct xdr_stream xdr;
3686 struct compound_hdr hdr;
3687 int status;
3689 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3690 status = decode_compound_hdr(&xdr, &hdr);
3691 if (status)
3692 goto out;
3693 status = decode_putfh(&xdr);
3694 if (status)
3695 goto out;
3696 status = decode_open(&xdr, res);
3697 out:
3698 return status;
3702 * Decode SETATTR response
3704 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3706 struct xdr_stream xdr;
3707 struct compound_hdr hdr;
3708 int status;
3710 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3711 status = decode_compound_hdr(&xdr, &hdr);
3712 if (status)
3713 goto out;
3714 status = decode_putfh(&xdr);
3715 if (status)
3716 goto out;
3717 status = decode_setattr(&xdr, res);
3718 if (status)
3719 goto out;
3720 status = decode_getfattr(&xdr, res->fattr, res->server);
3721 if (status == NFS4ERR_DELAY)
3722 status = 0;
3723 out:
3724 return status;
3728 * Decode LOCK response
3730 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3732 struct xdr_stream xdr;
3733 struct compound_hdr hdr;
3734 int status;
3736 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3737 status = decode_compound_hdr(&xdr, &hdr);
3738 if (status)
3739 goto out;
3740 status = decode_putfh(&xdr);
3741 if (status)
3742 goto out;
3743 status = decode_lock(&xdr, res);
3744 out:
3745 return status;
3749 * Decode LOCKT response
3751 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3753 struct xdr_stream xdr;
3754 struct compound_hdr hdr;
3755 int status;
3757 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3758 status = decode_compound_hdr(&xdr, &hdr);
3759 if (status)
3760 goto out;
3761 status = decode_putfh(&xdr);
3762 if (status)
3763 goto out;
3764 status = decode_lockt(&xdr, res);
3765 out:
3766 return status;
3770 * Decode LOCKU response
3772 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3774 struct xdr_stream xdr;
3775 struct compound_hdr hdr;
3776 int status;
3778 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3779 status = decode_compound_hdr(&xdr, &hdr);
3780 if (status)
3781 goto out;
3782 status = decode_putfh(&xdr);
3783 if (status)
3784 goto out;
3785 status = decode_locku(&xdr, res);
3786 out:
3787 return status;
3791 * Decode READLINK response
3793 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3795 struct xdr_stream xdr;
3796 struct compound_hdr hdr;
3797 int status;
3799 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3800 status = decode_compound_hdr(&xdr, &hdr);
3801 if (status)
3802 goto out;
3803 status = decode_putfh(&xdr);
3804 if (status)
3805 goto out;
3806 status = decode_readlink(&xdr, rqstp);
3807 out:
3808 return status;
3812 * Decode READDIR response
3814 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3816 struct xdr_stream xdr;
3817 struct compound_hdr hdr;
3818 int status;
3820 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3821 status = decode_compound_hdr(&xdr, &hdr);
3822 if (status)
3823 goto out;
3824 status = decode_putfh(&xdr);
3825 if (status)
3826 goto out;
3827 status = decode_readdir(&xdr, rqstp, res);
3828 out:
3829 return status;
3833 * Decode Read response
3835 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3837 struct xdr_stream xdr;
3838 struct compound_hdr hdr;
3839 int status;
3841 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3842 status = decode_compound_hdr(&xdr, &hdr);
3843 if (status)
3844 goto out;
3845 status = decode_putfh(&xdr);
3846 if (status)
3847 goto out;
3848 status = decode_read(&xdr, rqstp, res);
3849 if (!status)
3850 status = res->count;
3851 out:
3852 return status;
3856 * Decode WRITE response
3858 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3860 struct xdr_stream xdr;
3861 struct compound_hdr hdr;
3862 int status;
3864 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3865 status = decode_compound_hdr(&xdr, &hdr);
3866 if (status)
3867 goto out;
3868 status = decode_putfh(&xdr);
3869 if (status)
3870 goto out;
3871 status = decode_write(&xdr, res);
3872 if (!status)
3873 status = res->count;
3874 out:
3875 return status;
3879 * Decode COMMIT response
3881 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3883 struct xdr_stream xdr;
3884 struct compound_hdr hdr;
3885 int status;
3887 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3888 status = decode_compound_hdr(&xdr, &hdr);
3889 if (status)
3890 goto out;
3891 status = decode_putfh(&xdr);
3892 if (status)
3893 goto out;
3894 status = decode_commit(&xdr, res);
3895 out:
3896 return status;
3900 * FSINFO request
3902 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
3904 struct xdr_stream xdr;
3905 struct compound_hdr hdr;
3906 int status;
3908 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3909 status = decode_compound_hdr(&xdr, &hdr);
3910 if (!status)
3911 status = decode_putfh(&xdr);
3912 if (!status)
3913 status = decode_fsinfo(&xdr, fsinfo);
3914 if (!status)
3915 status = -nfs_stat_to_errno(hdr.status);
3916 return status;
3920 * PATHCONF request
3922 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
3924 struct xdr_stream xdr;
3925 struct compound_hdr hdr;
3926 int status;
3928 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3929 status = decode_compound_hdr(&xdr, &hdr);
3930 if (!status)
3931 status = decode_putfh(&xdr);
3932 if (!status)
3933 status = decode_pathconf(&xdr, pathconf);
3934 return status;
3938 * STATFS request
3940 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
3942 struct xdr_stream xdr;
3943 struct compound_hdr hdr;
3944 int status;
3946 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3947 status = decode_compound_hdr(&xdr, &hdr);
3948 if (!status)
3949 status = decode_putfh(&xdr);
3950 if (!status)
3951 status = decode_statfs(&xdr, fsstat);
3952 return status;
3956 * GETATTR_BITMAP request
3958 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
3960 struct xdr_stream xdr;
3961 struct compound_hdr hdr;
3962 int status;
3964 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
3965 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3966 goto out;
3967 if ((status = decode_putfh(&xdr)) != 0)
3968 goto out;
3969 status = decode_server_caps(&xdr, res);
3970 out:
3971 return status;
3975 * Decode RENEW response
3977 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
3979 struct xdr_stream xdr;
3980 struct compound_hdr hdr;
3981 int status;
3983 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3984 status = decode_compound_hdr(&xdr, &hdr);
3985 if (!status)
3986 status = decode_renew(&xdr);
3987 return status;
3991 * a SETCLIENTID request
3993 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
3994 struct nfs4_client *clp)
3996 struct xdr_stream xdr;
3997 struct compound_hdr hdr;
3998 int status;
4000 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4001 status = decode_compound_hdr(&xdr, &hdr);
4002 if (!status)
4003 status = decode_setclientid(&xdr, clp);
4004 if (!status)
4005 status = -nfs_stat_to_errno(hdr.status);
4006 return status;
4010 * a SETCLIENTID_CONFIRM request
4012 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
4014 struct xdr_stream xdr;
4015 struct compound_hdr hdr;
4016 int status;
4018 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4019 status = decode_compound_hdr(&xdr, &hdr);
4020 if (!status)
4021 status = decode_setclientid_confirm(&xdr);
4022 if (!status)
4023 status = decode_putrootfh(&xdr);
4024 if (!status)
4025 status = decode_fsinfo(&xdr, fsinfo);
4026 if (!status)
4027 status = -nfs_stat_to_errno(hdr.status);
4028 return status;
4032 * DELEGRETURN request
4034 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
4036 struct xdr_stream xdr;
4037 struct compound_hdr hdr;
4038 int status;
4040 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4041 status = decode_compound_hdr(&xdr, &hdr);
4042 if (status == 0) {
4043 status = decode_putfh(&xdr);
4044 if (status == 0)
4045 status = decode_delegreturn(&xdr);
4047 return status;
4050 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
4052 uint32_t bitmap[2] = {0};
4053 uint32_t len;
4055 if (!*p++) {
4056 if (!*p)
4057 return ERR_PTR(-EAGAIN);
4058 entry->eof = 1;
4059 return ERR_PTR(-EBADCOOKIE);
4062 entry->prev_cookie = entry->cookie;
4063 p = xdr_decode_hyper(p, &entry->cookie);
4064 entry->len = ntohl(*p++);
4065 entry->name = (const char *) p;
4066 p += XDR_QUADLEN(entry->len);
4069 * In case the server doesn't return an inode number,
4070 * we fake one here. (We don't use inode number 0,
4071 * since glibc seems to choke on it...)
4073 entry->ino = 1;
4075 len = ntohl(*p++); /* bitmap length */
4076 if (len-- > 0) {
4077 bitmap[0] = ntohl(*p++);
4078 if (len-- > 0) {
4079 bitmap[1] = ntohl(*p++);
4080 p += len;
4083 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4084 if (len > 0) {
4085 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4086 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4087 /* Ignore the return value of rdattr_error for now */
4088 p++;
4089 len--;
4091 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4092 xdr_decode_hyper(p, &entry->ino);
4093 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4094 xdr_decode_hyper(p, &entry->ino);
4095 p += len;
4098 entry->eof = !p[0] && p[1];
4099 return p;
4103 * We need to translate between nfs status return values and
4104 * the local errno values which may not be the same.
4106 static struct {
4107 int stat;
4108 int errno;
4109 } nfs_errtbl[] = {
4110 { NFS4_OK, 0 },
4111 { NFS4ERR_PERM, EPERM },
4112 { NFS4ERR_NOENT, ENOENT },
4113 { NFS4ERR_IO, errno_NFSERR_IO },
4114 { NFS4ERR_NXIO, ENXIO },
4115 { NFS4ERR_ACCESS, EACCES },
4116 { NFS4ERR_EXIST, EEXIST },
4117 { NFS4ERR_XDEV, EXDEV },
4118 { NFS4ERR_NOTDIR, ENOTDIR },
4119 { NFS4ERR_ISDIR, EISDIR },
4120 { NFS4ERR_INVAL, EINVAL },
4121 { NFS4ERR_FBIG, EFBIG },
4122 { NFS4ERR_NOSPC, ENOSPC },
4123 { NFS4ERR_ROFS, EROFS },
4124 { NFS4ERR_MLINK, EMLINK },
4125 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4126 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4127 { NFS4ERR_DQUOT, EDQUOT },
4128 { NFS4ERR_STALE, ESTALE },
4129 { NFS4ERR_BADHANDLE, EBADHANDLE },
4130 { NFS4ERR_BADOWNER, EINVAL },
4131 { NFS4ERR_BADNAME, EINVAL },
4132 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4133 { NFS4ERR_NOTSUPP, ENOTSUPP },
4134 { NFS4ERR_TOOSMALL, ETOOSMALL },
4135 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4136 { NFS4ERR_BADTYPE, EBADTYPE },
4137 { NFS4ERR_LOCKED, EAGAIN },
4138 { NFS4ERR_RESOURCE, EREMOTEIO },
4139 { NFS4ERR_SYMLINK, ELOOP },
4140 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4141 { NFS4ERR_DEADLOCK, EDEADLK },
4142 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4143 * to be handled by a
4144 * middle-layer.
4146 { -1, EIO }
4150 * Convert an NFS error code to a local one.
4151 * This one is used jointly by NFSv2 and NFSv3.
4153 static int
4154 nfs_stat_to_errno(int stat)
4156 int i;
4157 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4158 if (nfs_errtbl[i].stat == stat)
4159 return nfs_errtbl[i].errno;
4161 if (stat <= 10000 || stat > 10100) {
4162 /* The server is looney tunes. */
4163 return ESERVERFAULT;
4165 /* If we cannot translate the error, the recovery routines should
4166 * handle it.
4167 * Note: remaining NFSv4 error codes have values > 10000, so should
4168 * not conflict with native Linux error codes.
4170 return stat;
4173 #ifndef MAX
4174 # define MAX(a, b) (((a) > (b))? (a) : (b))
4175 #endif
4177 #define PROC(proc, argtype, restype) \
4178 [NFSPROC4_CLNT_##proc] = { \
4179 .p_proc = NFSPROC4_COMPOUND, \
4180 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4181 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4182 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
4185 struct rpc_procinfo nfs4_procedures[] = {
4186 PROC(READ, enc_read, dec_read),
4187 PROC(WRITE, enc_write, dec_write),
4188 PROC(COMMIT, enc_commit, dec_commit),
4189 PROC(OPEN, enc_open, dec_open),
4190 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4191 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4192 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4193 PROC(CLOSE, enc_close, dec_close),
4194 PROC(SETATTR, enc_setattr, dec_setattr),
4195 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4196 PROC(RENEW, enc_renew, dec_renew),
4197 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4198 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4199 PROC(LOCK, enc_lock, dec_lock),
4200 PROC(LOCKT, enc_lockt, dec_lockt),
4201 PROC(LOCKU, enc_locku, dec_locku),
4202 PROC(ACCESS, enc_access, dec_access),
4203 PROC(GETATTR, enc_getattr, dec_getattr),
4204 PROC(LOOKUP, enc_lookup, dec_lookup),
4205 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4206 PROC(REMOVE, enc_remove, dec_remove),
4207 PROC(RENAME, enc_rename, dec_rename),
4208 PROC(LINK, enc_link, dec_link),
4209 PROC(SYMLINK, enc_symlink, dec_symlink),
4210 PROC(CREATE, enc_create, dec_create),
4211 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4212 PROC(STATFS, enc_statfs, dec_statfs),
4213 PROC(READLINK, enc_readlink, dec_readlink),
4214 PROC(READDIR, enc_readdir, dec_readdir),
4215 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4216 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4217 PROC(GETACL, enc_getacl, dec_getacl),
4218 PROC(SETACL, enc_setacl, dec_setacl),
4221 struct rpc_version nfs_version4 = {
4222 .number = 4,
4223 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
4224 .procs = nfs4_procedures
4228 * Local variables:
4229 * c-basic-offset: 8
4230 * End: