2 * linux/fs/nfs/nfs3xdr.c
4 * XDR functions to encode/decode NFSv3 RPC arguments and results.
6 * Copyright (C) 1996, 1997 Olaf Kirch
9 #include <linux/param.h>
10 #include <linux/time.h>
12 #include <linux/errno.h>
13 #include <linux/string.h>
15 #include <linux/pagemap.h>
16 #include <linux/proc_fs.h>
17 #include <linux/kdev_t.h>
18 #include <linux/sunrpc/clnt.h>
19 #include <linux/nfs.h>
20 #include <linux/nfs3.h>
21 #include <linux/nfs_fs.h>
22 #include <linux/nfsacl.h>
25 #define NFSDBG_FACILITY NFSDBG_XDR
27 /* Mapping from NFS error code to "errno" error code. */
28 #define errno_NFSERR_IO EIO
31 * Declare the space requirements for NFS arguments and replies as
32 * number of 32bit-words
34 #define NFS3_fhandle_sz (1+16)
35 #define NFS3_fh_sz (NFS3_fhandle_sz) /* shorthand */
36 #define NFS3_sattr_sz (15)
37 #define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2))
38 #define NFS3_path_sz (1+(NFS3_MAXPATHLEN>>2))
39 #define NFS3_fattr_sz (21)
40 #define NFS3_wcc_attr_sz (6)
41 #define NFS3_pre_op_attr_sz (1+NFS3_wcc_attr_sz)
42 #define NFS3_post_op_attr_sz (1+NFS3_fattr_sz)
43 #define NFS3_wcc_data_sz (NFS3_pre_op_attr_sz+NFS3_post_op_attr_sz)
44 #define NFS3_fsstat_sz
45 #define NFS3_fsinfo_sz
46 #define NFS3_pathconf_sz
47 #define NFS3_entry_sz (NFS3_filename_sz+3)
49 #define NFS3_sattrargs_sz (NFS3_fh_sz+NFS3_sattr_sz+3)
50 #define NFS3_diropargs_sz (NFS3_fh_sz+NFS3_filename_sz)
51 #define NFS3_removeargs_sz (NFS3_fh_sz+NFS3_filename_sz)
52 #define NFS3_accessargs_sz (NFS3_fh_sz+1)
53 #define NFS3_readlinkargs_sz (NFS3_fh_sz)
54 #define NFS3_readargs_sz (NFS3_fh_sz+3)
55 #define NFS3_writeargs_sz (NFS3_fh_sz+5)
56 #define NFS3_createargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
57 #define NFS3_mkdirargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
58 #define NFS3_symlinkargs_sz (NFS3_diropargs_sz+1+NFS3_sattr_sz)
59 #define NFS3_mknodargs_sz (NFS3_diropargs_sz+2+NFS3_sattr_sz)
60 #define NFS3_renameargs_sz (NFS3_diropargs_sz+NFS3_diropargs_sz)
61 #define NFS3_linkargs_sz (NFS3_fh_sz+NFS3_diropargs_sz)
62 #define NFS3_readdirargs_sz (NFS3_fh_sz+2)
63 #define NFS3_commitargs_sz (NFS3_fh_sz+3)
65 #define NFS3_attrstat_sz (1+NFS3_fattr_sz)
66 #define NFS3_wccstat_sz (1+NFS3_wcc_data_sz)
67 #define NFS3_removeres_sz (NFS3_wccstat_sz)
68 #define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
69 #define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1)
70 #define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1)
71 #define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3)
72 #define NFS3_writeres_sz (1+NFS3_wcc_data_sz+4)
73 #define NFS3_createres_sz (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
74 #define NFS3_renameres_sz (1+(2 * NFS3_wcc_data_sz))
75 #define NFS3_linkres_sz (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
76 #define NFS3_readdirres_sz (1+NFS3_post_op_attr_sz+2)
77 #define NFS3_fsstatres_sz (1+NFS3_post_op_attr_sz+13)
78 #define NFS3_fsinfores_sz (1+NFS3_post_op_attr_sz+12)
79 #define NFS3_pathconfres_sz (1+NFS3_post_op_attr_sz+6)
80 #define NFS3_commitres_sz (1+NFS3_wcc_data_sz+2)
82 #define ACL3_getaclargs_sz (NFS3_fh_sz+1)
83 #define ACL3_setaclargs_sz (NFS3_fh_sz+1+ \
84 XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
85 #define ACL3_getaclres_sz (1+NFS3_post_op_attr_sz+1+ \
86 XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
87 #define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz)
90 * Map file type to S_IFMT bits
92 static const umode_t nfs_type2fmt
[] = {
103 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
105 dprintk("nfs: %s: prematurely hit end of receive buffer. "
106 "Remaining buffer length is %tu words.\n",
107 func
, xdr
->end
- xdr
->p
);
111 * Common NFS XDR functions as inlines
113 static inline __be32
*
114 xdr_encode_fhandle(__be32
*p
, const struct nfs_fh
*fh
)
116 return xdr_encode_array(p
, fh
->data
, fh
->size
);
119 static inline __be32
*
120 xdr_decode_fhandle(__be32
*p
, struct nfs_fh
*fh
)
122 if ((fh
->size
= ntohl(*p
++)) <= NFS3_FHSIZE
) {
123 memcpy(fh
->data
, p
, fh
->size
);
124 return p
+ XDR_QUADLEN(fh
->size
);
129 static inline __be32
*
130 xdr_decode_fhandle_stream(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
133 p
= xdr_inline_decode(xdr
, 4);
136 fh
->size
= ntohl(*p
++);
138 if (fh
->size
<= NFS3_FHSIZE
) {
139 p
= xdr_inline_decode(xdr
, fh
->size
);
142 memcpy(fh
->data
, p
, fh
->size
);
143 return p
+ XDR_QUADLEN(fh
->size
);
148 print_overflow_msg(__func__
, xdr
);
149 return ERR_PTR(-EIO
);
153 * Encode/decode time.
155 static inline __be32
*
156 xdr_encode_time3(__be32
*p
, struct timespec
*timep
)
158 *p
++ = htonl(timep
->tv_sec
);
159 *p
++ = htonl(timep
->tv_nsec
);
163 static inline __be32
*
164 xdr_decode_time3(__be32
*p
, struct timespec
*timep
)
166 timep
->tv_sec
= ntohl(*p
++);
167 timep
->tv_nsec
= ntohl(*p
++);
172 xdr_decode_fattr(__be32
*p
, struct nfs_fattr
*fattr
)
174 unsigned int type
, major
, minor
;
180 fmode
= nfs_type2fmt
[type
];
181 fattr
->mode
= (ntohl(*p
++) & ~S_IFMT
) | fmode
;
182 fattr
->nlink
= ntohl(*p
++);
183 fattr
->uid
= ntohl(*p
++);
184 fattr
->gid
= ntohl(*p
++);
185 p
= xdr_decode_hyper(p
, &fattr
->size
);
186 p
= xdr_decode_hyper(p
, &fattr
->du
.nfs3
.used
);
188 /* Turn remote device info into Linux-specific dev_t */
191 fattr
->rdev
= MKDEV(major
, minor
);
192 if (MAJOR(fattr
->rdev
) != major
|| MINOR(fattr
->rdev
) != minor
)
195 p
= xdr_decode_hyper(p
, &fattr
->fsid
.major
);
196 fattr
->fsid
.minor
= 0;
197 p
= xdr_decode_hyper(p
, &fattr
->fileid
);
198 p
= xdr_decode_time3(p
, &fattr
->atime
);
199 p
= xdr_decode_time3(p
, &fattr
->mtime
);
200 p
= xdr_decode_time3(p
, &fattr
->ctime
);
202 /* Update the mode bits */
203 fattr
->valid
|= NFS_ATTR_FATTR_V3
;
207 static inline __be32
*
208 xdr_encode_sattr(__be32
*p
, struct iattr
*attr
)
210 if (attr
->ia_valid
& ATTR_MODE
) {
212 *p
++ = htonl(attr
->ia_mode
& S_IALLUGO
);
216 if (attr
->ia_valid
& ATTR_UID
) {
218 *p
++ = htonl(attr
->ia_uid
);
222 if (attr
->ia_valid
& ATTR_GID
) {
224 *p
++ = htonl(attr
->ia_gid
);
228 if (attr
->ia_valid
& ATTR_SIZE
) {
230 p
= xdr_encode_hyper(p
, (__u64
) attr
->ia_size
);
234 if (attr
->ia_valid
& ATTR_ATIME_SET
) {
236 p
= xdr_encode_time3(p
, &attr
->ia_atime
);
237 } else if (attr
->ia_valid
& ATTR_ATIME
) {
242 if (attr
->ia_valid
& ATTR_MTIME_SET
) {
244 p
= xdr_encode_time3(p
, &attr
->ia_mtime
);
245 } else if (attr
->ia_valid
& ATTR_MTIME
) {
253 static inline __be32
*
254 xdr_decode_wcc_attr(__be32
*p
, struct nfs_fattr
*fattr
)
256 p
= xdr_decode_hyper(p
, &fattr
->pre_size
);
257 p
= xdr_decode_time3(p
, &fattr
->pre_mtime
);
258 p
= xdr_decode_time3(p
, &fattr
->pre_ctime
);
259 fattr
->valid
|= NFS_ATTR_FATTR_PRESIZE
260 | NFS_ATTR_FATTR_PREMTIME
261 | NFS_ATTR_FATTR_PRECTIME
;
265 static inline __be32
*
266 xdr_decode_post_op_attr(__be32
*p
, struct nfs_fattr
*fattr
)
269 p
= xdr_decode_fattr(p
, fattr
);
273 static inline __be32
*
274 xdr_decode_post_op_attr_stream(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
)
278 p
= xdr_inline_decode(xdr
, 4);
282 p
= xdr_inline_decode(xdr
, 84);
285 p
= xdr_decode_fattr(p
, fattr
);
289 print_overflow_msg(__func__
, xdr
);
290 return ERR_PTR(-EIO
);
293 static inline __be32
*
294 xdr_decode_pre_op_attr(__be32
*p
, struct nfs_fattr
*fattr
)
297 return xdr_decode_wcc_attr(p
, fattr
);
302 static inline __be32
*
303 xdr_decode_wcc_data(__be32
*p
, struct nfs_fattr
*fattr
)
305 p
= xdr_decode_pre_op_attr(p
, fattr
);
306 return xdr_decode_post_op_attr(p
, fattr
);
310 * NFS encode functions
314 * Encode file handle argument
317 nfs3_xdr_fhandle(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fh
*fh
)
319 p
= xdr_encode_fhandle(p
, fh
);
320 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
325 * Encode SETATTR arguments
328 nfs3_xdr_sattrargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_sattrargs
*args
)
330 p
= xdr_encode_fhandle(p
, args
->fh
);
331 p
= xdr_encode_sattr(p
, args
->sattr
);
332 *p
++ = htonl(args
->guard
);
334 p
= xdr_encode_time3(p
, &args
->guardtime
);
335 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
340 * Encode directory ops argument
343 nfs3_xdr_diropargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_diropargs
*args
)
345 p
= xdr_encode_fhandle(p
, args
->fh
);
346 p
= xdr_encode_array(p
, args
->name
, args
->len
);
347 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
352 * Encode REMOVE argument
355 nfs3_xdr_removeargs(struct rpc_rqst
*req
, __be32
*p
, const struct nfs_removeargs
*args
)
357 p
= xdr_encode_fhandle(p
, args
->fh
);
358 p
= xdr_encode_array(p
, args
->name
.name
, args
->name
.len
);
359 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
364 * Encode access() argument
367 nfs3_xdr_accessargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_accessargs
*args
)
369 p
= xdr_encode_fhandle(p
, args
->fh
);
370 *p
++ = htonl(args
->access
);
371 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
376 * Arguments to a READ call. Since we read data directly into the page
377 * cache, we also set up the reply iovec here so that iov[1] points
378 * exactly to the page we want to fetch.
381 nfs3_xdr_readargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs_readargs
*args
)
383 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
385 u32 count
= args
->count
;
387 p
= xdr_encode_fhandle(p
, args
->fh
);
388 p
= xdr_encode_hyper(p
, args
->offset
);
390 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
392 /* Inline the page array */
393 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS3_readres_sz
) << 2;
394 xdr_inline_pages(&req
->rq_rcv_buf
, replen
,
395 args
->pages
, args
->pgbase
, count
);
396 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
401 * Write arguments. Splice the buffer to be written into the iovec.
404 nfs3_xdr_writeargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*args
)
406 struct xdr_buf
*sndbuf
= &req
->rq_snd_buf
;
407 u32 count
= args
->count
;
409 p
= xdr_encode_fhandle(p
, args
->fh
);
410 p
= xdr_encode_hyper(p
, args
->offset
);
412 *p
++ = htonl(args
->stable
);
414 sndbuf
->len
= xdr_adjust_iovec(sndbuf
->head
, p
);
416 /* Copy the page array */
417 xdr_encode_pages(sndbuf
, args
->pages
, args
->pgbase
, count
);
418 sndbuf
->flags
|= XDRBUF_WRITE
;
423 * Encode CREATE arguments
426 nfs3_xdr_createargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_createargs
*args
)
428 p
= xdr_encode_fhandle(p
, args
->fh
);
429 p
= xdr_encode_array(p
, args
->name
, args
->len
);
431 *p
++ = htonl(args
->createmode
);
432 if (args
->createmode
== NFS3_CREATE_EXCLUSIVE
) {
433 *p
++ = args
->verifier
[0];
434 *p
++ = args
->verifier
[1];
436 p
= xdr_encode_sattr(p
, args
->sattr
);
438 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
443 * Encode MKDIR arguments
446 nfs3_xdr_mkdirargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_mkdirargs
*args
)
448 p
= xdr_encode_fhandle(p
, args
->fh
);
449 p
= xdr_encode_array(p
, args
->name
, args
->len
);
450 p
= xdr_encode_sattr(p
, args
->sattr
);
451 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
456 * Encode SYMLINK arguments
459 nfs3_xdr_symlinkargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_symlinkargs
*args
)
461 p
= xdr_encode_fhandle(p
, args
->fromfh
);
462 p
= xdr_encode_array(p
, args
->fromname
, args
->fromlen
);
463 p
= xdr_encode_sattr(p
, args
->sattr
);
464 *p
++ = htonl(args
->pathlen
);
465 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
468 xdr_encode_pages(&req
->rq_snd_buf
, args
->pages
, 0, args
->pathlen
);
473 * Encode MKNOD arguments
476 nfs3_xdr_mknodargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_mknodargs
*args
)
478 p
= xdr_encode_fhandle(p
, args
->fh
);
479 p
= xdr_encode_array(p
, args
->name
, args
->len
);
480 *p
++ = htonl(args
->type
);
481 p
= xdr_encode_sattr(p
, args
->sattr
);
482 if (args
->type
== NF3CHR
|| args
->type
== NF3BLK
) {
483 *p
++ = htonl(MAJOR(args
->rdev
));
484 *p
++ = htonl(MINOR(args
->rdev
));
487 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
492 * Encode RENAME arguments
495 nfs3_xdr_renameargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs_renameargs
*args
)
497 p
= xdr_encode_fhandle(p
, args
->old_dir
);
498 p
= xdr_encode_array(p
, args
->old_name
->name
, args
->old_name
->len
);
499 p
= xdr_encode_fhandle(p
, args
->new_dir
);
500 p
= xdr_encode_array(p
, args
->new_name
->name
, args
->new_name
->len
);
501 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
506 * Encode LINK arguments
509 nfs3_xdr_linkargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_linkargs
*args
)
511 p
= xdr_encode_fhandle(p
, args
->fromfh
);
512 p
= xdr_encode_fhandle(p
, args
->tofh
);
513 p
= xdr_encode_array(p
, args
->toname
, args
->tolen
);
514 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
519 * Encode arguments to readdir call
522 nfs3_xdr_readdirargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_readdirargs
*args
)
524 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
526 u32 count
= args
->count
;
528 p
= xdr_encode_fhandle(p
, args
->fh
);
529 p
= xdr_encode_hyper(p
, args
->cookie
);
530 *p
++ = args
->verf
[0];
531 *p
++ = args
->verf
[1];
533 /* readdirplus: need dircount + buffer size.
534 * We just make sure we make dircount big enough */
535 *p
++ = htonl(count
>> 3);
538 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
540 /* Inline the page array */
541 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS3_readdirres_sz
) << 2;
542 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, args
->pages
, 0, count
);
547 * Decode the result of a readdir call.
548 * We just check for syntactical correctness.
551 nfs3_xdr_readdirres(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_readdirres
*res
)
553 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
554 struct kvec
*iov
= rcvbuf
->head
;
560 status
= ntohl(*p
++);
561 /* Decode post_op_attrs */
562 p
= xdr_decode_post_op_attr(p
, res
->dir_attr
);
564 return nfs_stat_to_errno(status
);
565 /* Decode verifier cookie */
573 hdrlen
= (u8
*) p
- (u8
*) iov
->iov_base
;
574 if (iov
->iov_len
< hdrlen
) {
575 dprintk("NFS: READDIR reply header overflowed:"
576 "length %Zu > %Zu\n", hdrlen
, iov
->iov_len
);
577 return -errno_NFSERR_IO
;
578 } else if (iov
->iov_len
!= hdrlen
) {
579 dprintk("NFS: READDIR header is short. iovec will be shifted.\n");
580 xdr_shift_buf(rcvbuf
, iov
->iov_len
- hdrlen
);
583 pglen
= rcvbuf
->page_len
;
584 recvd
= rcvbuf
->len
- hdrlen
;
587 page
= rcvbuf
->pages
;
593 nfs3_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
, struct nfs_server
*server
, int plus
)
596 struct nfs_entry old
= *entry
;
598 p
= xdr_inline_decode(xdr
, 4);
602 p
= xdr_inline_decode(xdr
, 4);
606 return ERR_PTR(-EAGAIN
);
608 return ERR_PTR(-EBADCOOKIE
);
611 p
= xdr_inline_decode(xdr
, 12);
614 p
= xdr_decode_hyper(p
, &entry
->ino
);
615 entry
->len
= ntohl(*p
++);
617 p
= xdr_inline_decode(xdr
, entry
->len
+ 8);
620 entry
->name
= (const char *) p
;
621 p
+= XDR_QUADLEN(entry
->len
);
622 entry
->prev_cookie
= entry
->cookie
;
623 p
= xdr_decode_hyper(p
, &entry
->cookie
);
626 entry
->fattr
->valid
= 0;
627 p
= xdr_decode_post_op_attr_stream(xdr
, entry
->fattr
);
629 goto out_overflow_exit
;
630 /* In fact, a post_op_fh3: */
631 p
= xdr_inline_decode(xdr
, 4);
635 p
= xdr_decode_fhandle_stream(xdr
, entry
->fh
);
637 goto out_overflow_exit
;
638 /* Ugh -- server reply was truncated */
640 dprintk("NFS: FH truncated\n");
642 return ERR_PTR(-EAGAIN
);
645 memset((u8
*)(entry
->fh
), 0, sizeof(*entry
->fh
));
648 p
= xdr_inline_peek(xdr
, 8);
650 entry
->eof
= !p
[0] && p
[1];
657 print_overflow_msg(__func__
, xdr
);
659 return ERR_PTR(-EIO
);
663 * Encode COMMIT arguments
666 nfs3_xdr_commitargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*args
)
668 p
= xdr_encode_fhandle(p
, args
->fh
);
669 p
= xdr_encode_hyper(p
, args
->offset
);
670 *p
++ = htonl(args
->count
);
671 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
675 #ifdef CONFIG_NFS_V3_ACL
677 * Encode GETACL arguments
680 nfs3_xdr_getaclargs(struct rpc_rqst
*req
, __be32
*p
,
681 struct nfs3_getaclargs
*args
)
683 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
686 p
= xdr_encode_fhandle(p
, args
->fh
);
687 *p
++ = htonl(args
->mask
);
688 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
690 if (args
->mask
& (NFS_ACL
| NFS_DFACL
)) {
691 /* Inline the page array */
692 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+
693 ACL3_getaclres_sz
) << 2;
694 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, args
->pages
, 0,
695 NFSACL_MAXPAGES
<< PAGE_SHIFT
);
701 * Encode SETACL arguments
704 nfs3_xdr_setaclargs(struct rpc_rqst
*req
, __be32
*p
,
705 struct nfs3_setaclargs
*args
)
707 struct xdr_buf
*buf
= &req
->rq_snd_buf
;
711 p
= xdr_encode_fhandle(p
, NFS_FH(args
->inode
));
712 *p
++ = htonl(args
->mask
);
713 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
716 if (args
->npages
!= 0)
717 xdr_encode_pages(buf
, args
->pages
, 0, args
->len
);
719 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
,
720 p
+ XDR_QUADLEN(args
->len
));
722 err
= nfsacl_encode(buf
, base
, args
->inode
,
723 (args
->mask
& NFS_ACL
) ?
724 args
->acl_access
: NULL
, 1, 0);
726 err
= nfsacl_encode(buf
, base
+ err
, args
->inode
,
727 (args
->mask
& NFS_DFACL
) ?
728 args
->acl_default
: NULL
, 1,
730 return (err
> 0) ? 0 : err
;
732 #endif /* CONFIG_NFS_V3_ACL */
735 * NFS XDR decode functions
739 * Decode attrstat reply.
742 nfs3_xdr_attrstat(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fattr
*fattr
)
746 if ((status
= ntohl(*p
++)))
747 return nfs_stat_to_errno(status
);
748 xdr_decode_fattr(p
, fattr
);
753 * Decode status+wcc_data reply
754 * SATTR, REMOVE, RMDIR
757 nfs3_xdr_wccstat(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fattr
*fattr
)
761 if ((status
= ntohl(*p
++)))
762 status
= nfs_stat_to_errno(status
);
763 xdr_decode_wcc_data(p
, fattr
);
768 nfs3_xdr_removeres(struct rpc_rqst
*req
, __be32
*p
, struct nfs_removeres
*res
)
770 return nfs3_xdr_wccstat(req
, p
, res
->dir_attr
);
774 * Decode LOOKUP reply
777 nfs3_xdr_lookupres(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_diropres
*res
)
781 if ((status
= ntohl(*p
++))) {
782 status
= nfs_stat_to_errno(status
);
784 if (!(p
= xdr_decode_fhandle(p
, res
->fh
)))
785 return -errno_NFSERR_IO
;
786 p
= xdr_decode_post_op_attr(p
, res
->fattr
);
788 xdr_decode_post_op_attr(p
, res
->dir_attr
);
793 * Decode ACCESS reply
796 nfs3_xdr_accessres(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_accessres
*res
)
798 int status
= ntohl(*p
++);
800 p
= xdr_decode_post_op_attr(p
, res
->fattr
);
802 return nfs_stat_to_errno(status
);
803 res
->access
= ntohl(*p
++);
808 nfs3_xdr_readlinkargs(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_readlinkargs
*args
)
810 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
813 p
= xdr_encode_fhandle(p
, args
->fh
);
814 req
->rq_slen
= xdr_adjust_iovec(req
->rq_svec
, p
);
816 /* Inline the page array */
817 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS3_readlinkres_sz
) << 2;
818 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, args
->pages
, args
->pgbase
, args
->pglen
);
823 * Decode READLINK reply
826 nfs3_xdr_readlinkres(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fattr
*fattr
)
828 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
829 struct kvec
*iov
= rcvbuf
->head
;
834 status
= ntohl(*p
++);
835 p
= xdr_decode_post_op_attr(p
, fattr
);
838 return nfs_stat_to_errno(status
);
840 /* Convert length of symlink */
842 if (len
>= rcvbuf
->page_len
) {
843 dprintk("nfs: server returned giant symlink!\n");
844 return -ENAMETOOLONG
;
847 hdrlen
= (u8
*) p
- (u8
*) iov
->iov_base
;
848 if (iov
->iov_len
< hdrlen
) {
849 dprintk("NFS: READLINK reply header overflowed:"
850 "length %Zu > %Zu\n", hdrlen
, iov
->iov_len
);
851 return -errno_NFSERR_IO
;
852 } else if (iov
->iov_len
!= hdrlen
) {
853 dprintk("NFS: READLINK header is short. "
854 "iovec will be shifted.\n");
855 xdr_shift_buf(rcvbuf
, iov
->iov_len
- hdrlen
);
857 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
859 dprintk("NFS: server cheating in readlink reply: "
860 "count %u > recvd %u\n", len
, recvd
);
864 xdr_terminate_string(rcvbuf
, len
);
872 nfs3_xdr_readres(struct rpc_rqst
*req
, __be32
*p
, struct nfs_readres
*res
)
874 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
876 u32 count
, ocount
, recvd
;
879 status
= ntohl(*p
++);
880 p
= xdr_decode_post_op_attr(p
, res
->fattr
);
883 return nfs_stat_to_errno(status
);
885 /* Decode reply count and EOF flag. NFSv3 is somewhat redundant
886 * in that it puts the count both in the res struct and in the
887 * opaque data count. */
889 res
->eof
= ntohl(*p
++);
890 ocount
= ntohl(*p
++);
892 if (ocount
!= count
) {
893 dprintk("NFS: READ count doesn't match RPC opaque count.\n");
894 return -errno_NFSERR_IO
;
897 hdrlen
= (u8
*) p
- (u8
*) iov
->iov_base
;
898 if (iov
->iov_len
< hdrlen
) {
899 dprintk("NFS: READ reply header overflowed:"
900 "length %Zu > %Zu\n", hdrlen
, iov
->iov_len
);
901 return -errno_NFSERR_IO
;
902 } else if (iov
->iov_len
!= hdrlen
) {
903 dprintk("NFS: READ header is short. iovec will be shifted.\n");
904 xdr_shift_buf(&req
->rq_rcv_buf
, iov
->iov_len
- hdrlen
);
907 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
909 dprintk("NFS: server cheating in read reply: "
910 "count %u > recvd %u\n", count
, recvd
);
915 if (count
< res
->count
)
922 * Decode WRITE response
925 nfs3_xdr_writeres(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeres
*res
)
929 status
= ntohl(*p
++);
930 p
= xdr_decode_wcc_data(p
, res
->fattr
);
933 return nfs_stat_to_errno(status
);
935 res
->count
= ntohl(*p
++);
936 res
->verf
->committed
= (enum nfs3_stable_how
)ntohl(*p
++);
937 res
->verf
->verifier
[0] = *p
++;
938 res
->verf
->verifier
[1] = *p
++;
944 * Decode a CREATE response
947 nfs3_xdr_createres(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_diropres
*res
)
951 status
= ntohl(*p
++);
954 if (!(p
= xdr_decode_fhandle(p
, res
->fh
)))
955 return -errno_NFSERR_IO
;
956 p
= xdr_decode_post_op_attr(p
, res
->fattr
);
958 memset(res
->fh
, 0, sizeof(*res
->fh
));
959 /* Do decode post_op_attr but set it to NULL */
960 p
= xdr_decode_post_op_attr(p
, res
->fattr
);
961 res
->fattr
->valid
= 0;
964 status
= nfs_stat_to_errno(status
);
966 p
= xdr_decode_wcc_data(p
, res
->dir_attr
);
971 * Decode RENAME reply
974 nfs3_xdr_renameres(struct rpc_rqst
*req
, __be32
*p
, struct nfs_renameres
*res
)
978 if ((status
= ntohl(*p
++)) != 0)
979 status
= nfs_stat_to_errno(status
);
980 p
= xdr_decode_wcc_data(p
, res
->old_fattr
);
981 p
= xdr_decode_wcc_data(p
, res
->new_fattr
);
989 nfs3_xdr_linkres(struct rpc_rqst
*req
, __be32
*p
, struct nfs3_linkres
*res
)
993 if ((status
= ntohl(*p
++)) != 0)
994 status
= nfs_stat_to_errno(status
);
995 p
= xdr_decode_post_op_attr(p
, res
->fattr
);
996 p
= xdr_decode_wcc_data(p
, res
->dir_attr
);
1001 * Decode FSSTAT reply
1004 nfs3_xdr_fsstatres(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsstat
*res
)
1008 status
= ntohl(*p
++);
1010 p
= xdr_decode_post_op_attr(p
, res
->fattr
);
1012 return nfs_stat_to_errno(status
);
1014 p
= xdr_decode_hyper(p
, &res
->tbytes
);
1015 p
= xdr_decode_hyper(p
, &res
->fbytes
);
1016 p
= xdr_decode_hyper(p
, &res
->abytes
);
1017 p
= xdr_decode_hyper(p
, &res
->tfiles
);
1018 p
= xdr_decode_hyper(p
, &res
->ffiles
);
1019 p
= xdr_decode_hyper(p
, &res
->afiles
);
1021 /* ignore invarsec */
1026 * Decode FSINFO reply
1029 nfs3_xdr_fsinfores(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsinfo
*res
)
1033 status
= ntohl(*p
++);
1035 p
= xdr_decode_post_op_attr(p
, res
->fattr
);
1037 return nfs_stat_to_errno(status
);
1039 res
->rtmax
= ntohl(*p
++);
1040 res
->rtpref
= ntohl(*p
++);
1041 res
->rtmult
= ntohl(*p
++);
1042 res
->wtmax
= ntohl(*p
++);
1043 res
->wtpref
= ntohl(*p
++);
1044 res
->wtmult
= ntohl(*p
++);
1045 res
->dtpref
= ntohl(*p
++);
1046 p
= xdr_decode_hyper(p
, &res
->maxfilesize
);
1047 p
= xdr_decode_time3(p
, &res
->time_delta
);
1049 /* ignore properties */
1050 res
->lease_time
= 0;
1055 * Decode PATHCONF reply
1058 nfs3_xdr_pathconfres(struct rpc_rqst
*req
, __be32
*p
, struct nfs_pathconf
*res
)
1062 status
= ntohl(*p
++);
1064 p
= xdr_decode_post_op_attr(p
, res
->fattr
);
1066 return nfs_stat_to_errno(status
);
1067 res
->max_link
= ntohl(*p
++);
1068 res
->max_namelen
= ntohl(*p
++);
1070 /* ignore remaining fields */
1075 * Decode COMMIT reply
1078 nfs3_xdr_commitres(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeres
*res
)
1082 status
= ntohl(*p
++);
1083 p
= xdr_decode_wcc_data(p
, res
->fattr
);
1085 return nfs_stat_to_errno(status
);
1087 res
->verf
->verifier
[0] = *p
++;
1088 res
->verf
->verifier
[1] = *p
++;
1092 #ifdef CONFIG_NFS_V3_ACL
1094 * Decode GETACL reply
1097 nfs3_xdr_getaclres(struct rpc_rqst
*req
, __be32
*p
,
1098 struct nfs3_getaclres
*res
)
1100 struct xdr_buf
*buf
= &req
->rq_rcv_buf
;
1101 int status
= ntohl(*p
++);
1102 struct posix_acl
**acl
;
1103 unsigned int *aclcnt
;
1107 return nfs_stat_to_errno(status
);
1108 p
= xdr_decode_post_op_attr(p
, res
->fattr
);
1109 res
->mask
= ntohl(*p
++);
1110 if (res
->mask
& ~(NFS_ACL
|NFS_ACLCNT
|NFS_DFACL
|NFS_DFACLCNT
))
1112 base
= (char *)p
- (char *)req
->rq_rcv_buf
.head
->iov_base
;
1114 acl
= (res
->mask
& NFS_ACL
) ? &res
->acl_access
: NULL
;
1115 aclcnt
= (res
->mask
& NFS_ACLCNT
) ? &res
->acl_access_count
: NULL
;
1116 err
= nfsacl_decode(buf
, base
, aclcnt
, acl
);
1118 acl
= (res
->mask
& NFS_DFACL
) ? &res
->acl_default
: NULL
;
1119 aclcnt
= (res
->mask
& NFS_DFACLCNT
) ? &res
->acl_default_count
: NULL
;
1121 err
= nfsacl_decode(buf
, base
+ err
, aclcnt
, acl
);
1122 return (err
> 0) ? 0 : err
;
1126 * Decode setacl reply.
1129 nfs3_xdr_setaclres(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fattr
*fattr
)
1131 int status
= ntohl(*p
++);
1134 return nfs_stat_to_errno(status
);
1135 xdr_decode_post_op_attr(p
, fattr
);
1138 #endif /* CONFIG_NFS_V3_ACL */
1140 #define PROC(proc, argtype, restype, timer) \
1141 [NFS3PROC_##proc] = { \
1142 .p_proc = NFS3PROC_##proc, \
1143 .p_encode = (kxdrproc_t) nfs3_xdr_##argtype, \
1144 .p_decode = (kxdrproc_t) nfs3_xdr_##restype, \
1145 .p_arglen = NFS3_##argtype##_sz, \
1146 .p_replen = NFS3_##restype##_sz, \
1148 .p_statidx = NFS3PROC_##proc, \
1152 struct rpc_procinfo nfs3_procedures
[] = {
1153 PROC(GETATTR
, fhandle
, attrstat
, 1),
1154 PROC(SETATTR
, sattrargs
, wccstat
, 0),
1155 PROC(LOOKUP
, diropargs
, lookupres
, 2),
1156 PROC(ACCESS
, accessargs
, accessres
, 1),
1157 PROC(READLINK
, readlinkargs
, readlinkres
, 3),
1158 PROC(READ
, readargs
, readres
, 3),
1159 PROC(WRITE
, writeargs
, writeres
, 4),
1160 PROC(CREATE
, createargs
, createres
, 0),
1161 PROC(MKDIR
, mkdirargs
, createres
, 0),
1162 PROC(SYMLINK
, symlinkargs
, createres
, 0),
1163 PROC(MKNOD
, mknodargs
, createres
, 0),
1164 PROC(REMOVE
, removeargs
, removeres
, 0),
1165 PROC(RMDIR
, diropargs
, wccstat
, 0),
1166 PROC(RENAME
, renameargs
, renameres
, 0),
1167 PROC(LINK
, linkargs
, linkres
, 0),
1168 PROC(READDIR
, readdirargs
, readdirres
, 3),
1169 PROC(READDIRPLUS
, readdirargs
, readdirres
, 3),
1170 PROC(FSSTAT
, fhandle
, fsstatres
, 0),
1171 PROC(FSINFO
, fhandle
, fsinfores
, 0),
1172 PROC(PATHCONF
, fhandle
, pathconfres
, 0),
1173 PROC(COMMIT
, commitargs
, commitres
, 5),
1176 struct rpc_version nfs_version3
= {
1178 .nrprocs
= ARRAY_SIZE(nfs3_procedures
),
1179 .procs
= nfs3_procedures
1182 #ifdef CONFIG_NFS_V3_ACL
1183 static struct rpc_procinfo nfs3_acl_procedures
[] = {
1184 [ACLPROC3_GETACL
] = {
1185 .p_proc
= ACLPROC3_GETACL
,
1186 .p_encode
= (kxdrproc_t
) nfs3_xdr_getaclargs
,
1187 .p_decode
= (kxdrproc_t
) nfs3_xdr_getaclres
,
1188 .p_arglen
= ACL3_getaclargs_sz
,
1189 .p_replen
= ACL3_getaclres_sz
,
1193 [ACLPROC3_SETACL
] = {
1194 .p_proc
= ACLPROC3_SETACL
,
1195 .p_encode
= (kxdrproc_t
) nfs3_xdr_setaclargs
,
1196 .p_decode
= (kxdrproc_t
) nfs3_xdr_setaclres
,
1197 .p_arglen
= ACL3_setaclargs_sz
,
1198 .p_replen
= ACL3_setaclres_sz
,
1204 struct rpc_version nfsacl_version3
= {
1206 .nrprocs
= sizeof(nfs3_acl_procedures
)/
1207 sizeof(nfs3_acl_procedures
[0]),
1208 .procs
= nfs3_acl_procedures
,
1210 #endif /* CONFIG_NFS_V3_ACL */