NFSv4: Add post-op attributes to nfs4_proc_link()
[pandora-kernel.git] / fs / nfs / nfs4xdr.c
1 /*
2  *  fs/nfs/nfs4xdr.c
3  *
4  *  Client-side XDR for NFSv4.
5  *
6  *  Copyright (c) 2002 The Regents of the University of Michigan.
7  *  All rights reserved.
8  *
9  *  Kendrick Smith <kmsmith@umich.edu>
10  *  Andy Adamson   <andros@umich.edu>
11  * 
12  *  Redistribution and use in source and binary forms, with or without
13  *  modification, are permitted provided that the following conditions
14  *  are met:
15  *
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.
24  *
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.
36  */
37
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"
55
56 #define NFSDBG_FACILITY         NFSDBG_XDR
57
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO         EIO
60
61 static int nfs_stat_to_errno(int);
62
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
69
70 /* lock,open owner id: 
71  * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT  >> 2)
72  */
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_restorefh_maxsz  (op_encode_hdr_maxsz)
99 #define decode_restorefh_maxsz  (op_decode_hdr_maxsz)
100 #define encode_fsinfo_maxsz     (op_encode_hdr_maxsz + 2)
101 #define decode_fsinfo_maxsz     (op_decode_hdr_maxsz + 11)
102 #define encode_renew_maxsz      (op_encode_hdr_maxsz + 3)
103 #define decode_renew_maxsz      (op_decode_hdr_maxsz)
104 #define encode_setclientid_maxsz \
105                                 (op_encode_hdr_maxsz + \
106                                 4 /*server->ip_addr*/ + \
107                                 1 /*Netid*/ + \
108                                 6 /*uaddr*/ + \
109                                 6 + (NFS4_VERIFIER_SIZE >> 2))
110 #define decode_setclientid_maxsz \
111                                 (op_decode_hdr_maxsz + \
112                                 2 + \
113                                 1024) /* large value for CLID_INUSE */
114 #define encode_setclientid_confirm_maxsz \
115                                 (op_encode_hdr_maxsz + \
116                                 3 + (NFS4_VERIFIER_SIZE >> 2))
117 #define decode_setclientid_confirm_maxsz \
118                                 (op_decode_hdr_maxsz)
119 #define encode_lookup_maxsz     (op_encode_hdr_maxsz + \
120                                 1 + ((3 + NFS4_FHSIZE) >> 2))
121 #define encode_remove_maxsz     (op_encode_hdr_maxsz + \
122                                 nfs4_name_maxsz)
123 #define encode_rename_maxsz     (op_encode_hdr_maxsz + \
124                                 2 * nfs4_name_maxsz)
125 #define decode_rename_maxsz     (op_decode_hdr_maxsz + 5 + 5)
126 #define encode_link_maxsz       (op_encode_hdr_maxsz + \
127                                 nfs4_name_maxsz)
128 #define decode_link_maxsz       (op_decode_hdr_maxsz + 5)
129 #define encode_symlink_maxsz    (op_encode_hdr_maxsz + \
130                                 1 + nfs4_name_maxsz + \
131                                 nfs4_path_maxsz + \
132                                 nfs4_fattr_maxsz)
133 #define decode_symlink_maxsz    (op_decode_hdr_maxsz + 8)
134 #define encode_create_maxsz     (op_encode_hdr_maxsz + \
135                                 2 + nfs4_name_maxsz + \
136                                 nfs4_fattr_maxsz)
137 #define decode_create_maxsz     (op_decode_hdr_maxsz + 8)
138 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
139 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
140 #define NFS4_enc_compound_sz    (1024)  /* XXX: large enough? */
141 #define NFS4_dec_compound_sz    (1024)  /* XXX: large enough? */
142 #define NFS4_enc_read_sz        (compound_encode_hdr_maxsz + \
143                                 encode_putfh_maxsz + \
144                                 op_encode_hdr_maxsz + 7)
145 #define NFS4_dec_read_sz        (compound_decode_hdr_maxsz + \
146                                 decode_putfh_maxsz + \
147                                 op_decode_hdr_maxsz + 2)
148 #define NFS4_enc_readlink_sz    (compound_encode_hdr_maxsz + \
149                                 encode_putfh_maxsz + \
150                                 op_encode_hdr_maxsz)
151 #define NFS4_dec_readlink_sz    (compound_decode_hdr_maxsz + \
152                                 decode_putfh_maxsz + \
153                                 op_decode_hdr_maxsz)
154 #define NFS4_enc_readdir_sz     (compound_encode_hdr_maxsz + \
155                                 encode_putfh_maxsz + \
156                                 op_encode_hdr_maxsz + 9)
157 #define NFS4_dec_readdir_sz     (compound_decode_hdr_maxsz + \
158                                 decode_putfh_maxsz + \
159                                 op_decode_hdr_maxsz + 2)
160 #define NFS4_enc_write_sz       (compound_encode_hdr_maxsz + \
161                                 encode_putfh_maxsz + \
162                                 op_encode_hdr_maxsz + 8)
163 #define NFS4_dec_write_sz       (compound_decode_hdr_maxsz + \
164                                 decode_putfh_maxsz + \
165                                 op_decode_hdr_maxsz + 4)
166 #define NFS4_enc_commit_sz      (compound_encode_hdr_maxsz + \
167                                 encode_putfh_maxsz + \
168                                 op_encode_hdr_maxsz + 3)
169 #define NFS4_dec_commit_sz      (compound_decode_hdr_maxsz + \
170                                 decode_putfh_maxsz + \
171                                 op_decode_hdr_maxsz + 2)
172 #define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
173                                 encode_putfh_maxsz + \
174                                 op_encode_hdr_maxsz + \
175                                 13 + 3 + 2 + 64 + \
176                                 encode_getattr_maxsz + \
177                                 encode_getfh_maxsz)
178 #define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
179                                 decode_putfh_maxsz + \
180                                 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
181                                 decode_getattr_maxsz + \
182                                 decode_getfh_maxsz)
183 #define NFS4_enc_open_confirm_sz      \
184                                 (compound_encode_hdr_maxsz + \
185                                 encode_putfh_maxsz + \
186                                 op_encode_hdr_maxsz + 5)
187 #define NFS4_dec_open_confirm_sz        (compound_decode_hdr_maxsz + \
188                                         decode_putfh_maxsz + \
189                                         op_decode_hdr_maxsz + 4)
190 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
191                                         encode_putfh_maxsz + \
192                                         op_encode_hdr_maxsz + \
193                                         11)
194 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
195                                         decode_putfh_maxsz + \
196                                         op_decode_hdr_maxsz + \
197                                         4 + 5 + 2 + 3)
198 #define NFS4_enc_open_downgrade_sz \
199                                 (compound_encode_hdr_maxsz + \
200                                 encode_putfh_maxsz + \
201                                 op_encode_hdr_maxsz + 7 + \
202                                 encode_getattr_maxsz)
203 #define NFS4_dec_open_downgrade_sz \
204                                 (compound_decode_hdr_maxsz + \
205                                 decode_putfh_maxsz + \
206                                 op_decode_hdr_maxsz + 4 + \
207                                 decode_getattr_maxsz)
208 #define NFS4_enc_close_sz       (compound_encode_hdr_maxsz + \
209                                 encode_putfh_maxsz + \
210                                 op_encode_hdr_maxsz + 5 + \
211                                 encode_getattr_maxsz)
212 #define NFS4_dec_close_sz       (compound_decode_hdr_maxsz + \
213                                 decode_putfh_maxsz + \
214                                 op_decode_hdr_maxsz + 4 + \
215                                 decode_getattr_maxsz)
216 #define NFS4_enc_setattr_sz     (compound_encode_hdr_maxsz + \
217                                 encode_putfh_maxsz + \
218                                 op_encode_hdr_maxsz + 4 + \
219                                 nfs4_fattr_maxsz + \
220                                 encode_getattr_maxsz)
221 #define NFS4_dec_setattr_sz     (compound_decode_hdr_maxsz + \
222                                 decode_putfh_maxsz + \
223                                 op_decode_hdr_maxsz + 3)
224 #define NFS4_enc_fsinfo_sz      (compound_encode_hdr_maxsz + \
225                                 encode_putfh_maxsz + \
226                                 encode_fsinfo_maxsz)
227 #define NFS4_dec_fsinfo_sz      (compound_decode_hdr_maxsz + \
228                                 decode_putfh_maxsz + \
229                                 decode_fsinfo_maxsz)
230 #define NFS4_enc_renew_sz       (compound_encode_hdr_maxsz + \
231                                 encode_renew_maxsz)
232 #define NFS4_dec_renew_sz       (compound_decode_hdr_maxsz + \
233                                 decode_renew_maxsz)
234 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
235                                 encode_setclientid_maxsz)
236 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
237                                 decode_setclientid_maxsz)
238 #define NFS4_enc_setclientid_confirm_sz \
239                                 (compound_encode_hdr_maxsz + \
240                                 encode_setclientid_confirm_maxsz + \
241                                 encode_putrootfh_maxsz + \
242                                 encode_fsinfo_maxsz)
243 #define NFS4_dec_setclientid_confirm_sz \
244                                 (compound_decode_hdr_maxsz + \
245                                 decode_setclientid_confirm_maxsz + \
246                                 decode_putrootfh_maxsz + \
247                                 decode_fsinfo_maxsz)
248 #define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
249                                 encode_putfh_maxsz + \
250                                 encode_getattr_maxsz + \
251                                 op_encode_hdr_maxsz + \
252                                 1 + 1 + 2 + 2 + \
253                                 1 + 4 + 1 + 2 + \
254                                 owner_id_maxsz)
255 #define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
256                                 decode_putfh_maxsz + \
257                                 decode_getattr_maxsz + \
258                                 op_decode_hdr_maxsz + \
259                                 2 + 2 + 1 + 2 + \
260                                 owner_id_maxsz)
261 #define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
262                                 encode_putfh_maxsz + \
263                                 encode_getattr_maxsz + \
264                                 op_encode_hdr_maxsz + \
265                                 1 + 2 + 2 + 2 + \
266                                 owner_id_maxsz)
267 #define NFS4_dec_lockt_sz       (NFS4_dec_lock_sz)
268 #define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
269                                 encode_putfh_maxsz + \
270                                 encode_getattr_maxsz + \
271                                 op_encode_hdr_maxsz + \
272                                 1 + 1 + 4 + 2 + 2)
273 #define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
274                                 decode_putfh_maxsz + \
275                                 decode_getattr_maxsz + \
276                                 op_decode_hdr_maxsz + 4)
277 #define NFS4_enc_access_sz      (compound_encode_hdr_maxsz + \
278                                 encode_putfh_maxsz + \
279                                 op_encode_hdr_maxsz + 1)
280 #define NFS4_dec_access_sz      (compound_decode_hdr_maxsz + \
281                                 decode_putfh_maxsz + \
282                                 op_decode_hdr_maxsz + 2)
283 #define NFS4_enc_getattr_sz     (compound_encode_hdr_maxsz + \
284                                 encode_putfh_maxsz + \
285                                 encode_getattr_maxsz)
286 #define NFS4_dec_getattr_sz     (compound_decode_hdr_maxsz + \
287                                 decode_putfh_maxsz + \
288                                 decode_getattr_maxsz)
289 #define NFS4_enc_lookup_sz      (compound_encode_hdr_maxsz + \
290                                 encode_putfh_maxsz + \
291                                 encode_lookup_maxsz + \
292                                 encode_getattr_maxsz + \
293                                 encode_getfh_maxsz)
294 #define NFS4_dec_lookup_sz      (compound_decode_hdr_maxsz + \
295                                 decode_putfh_maxsz + \
296                                 op_decode_hdr_maxsz + \
297                                 decode_getattr_maxsz + \
298                                 decode_getfh_maxsz)
299 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
300                                 encode_putrootfh_maxsz + \
301                                 encode_getattr_maxsz + \
302                                 encode_getfh_maxsz)
303 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
304                                 decode_putrootfh_maxsz + \
305                                 decode_getattr_maxsz + \
306                                 decode_getfh_maxsz)
307 #define NFS4_enc_remove_sz      (compound_encode_hdr_maxsz + \
308                                 encode_putfh_maxsz + \
309                                 encode_remove_maxsz)
310 #define NFS4_dec_remove_sz      (compound_decode_hdr_maxsz + \
311                                 decode_putfh_maxsz + \
312                                 op_decode_hdr_maxsz + 5)
313 #define NFS4_enc_rename_sz      (compound_encode_hdr_maxsz + \
314                                 encode_putfh_maxsz + \
315                                 encode_savefh_maxsz + \
316                                 encode_putfh_maxsz + \
317                                 encode_rename_maxsz)
318 #define NFS4_dec_rename_sz      (compound_decode_hdr_maxsz + \
319                                 decode_putfh_maxsz + \
320                                 decode_savefh_maxsz + \
321                                 decode_putfh_maxsz + \
322                                 decode_rename_maxsz)
323 #define NFS4_enc_link_sz        (compound_encode_hdr_maxsz + \
324                                 encode_putfh_maxsz + \
325                                 encode_savefh_maxsz + \
326                                 encode_putfh_maxsz + \
327                                 encode_link_maxsz + \
328                                 decode_getattr_maxsz + \
329                                 encode_restorefh_maxsz + \
330                                 decode_getattr_maxsz)
331 #define NFS4_dec_link_sz        (compound_decode_hdr_maxsz + \
332                                 decode_putfh_maxsz + \
333                                 decode_savefh_maxsz + \
334                                 decode_putfh_maxsz + \
335                                 decode_link_maxsz + \
336                                 decode_getattr_maxsz + \
337                                 decode_restorefh_maxsz + \
338                                 decode_getattr_maxsz)
339 #define NFS4_enc_symlink_sz     (compound_encode_hdr_maxsz + \
340                                 encode_putfh_maxsz + \
341                                 encode_symlink_maxsz + \
342                                 encode_getattr_maxsz + \
343                                 encode_getfh_maxsz)
344 #define NFS4_dec_symlink_sz     (compound_decode_hdr_maxsz + \
345                                 decode_putfh_maxsz + \
346                                 decode_symlink_maxsz + \
347                                 decode_getattr_maxsz + \
348                                 decode_getfh_maxsz)
349 #define NFS4_enc_create_sz      (compound_encode_hdr_maxsz + \
350                                 encode_putfh_maxsz + \
351                                 encode_savefh_maxsz + \
352                                 encode_create_maxsz + \
353                                 encode_getfh_maxsz + \
354                                 encode_getattr_maxsz + \
355                                 encode_restorefh_maxsz + \
356                                 encode_getattr_maxsz)
357 #define NFS4_dec_create_sz      (compound_decode_hdr_maxsz + \
358                                 decode_putfh_maxsz + \
359                                 decode_savefh_maxsz + \
360                                 decode_create_maxsz + \
361                                 decode_getfh_maxsz + \
362                                 decode_getattr_maxsz + \
363                                 decode_restorefh_maxsz + \
364                                 decode_getattr_maxsz)
365 #define NFS4_enc_pathconf_sz    (compound_encode_hdr_maxsz + \
366                                 encode_putfh_maxsz + \
367                                 encode_getattr_maxsz)
368 #define NFS4_dec_pathconf_sz    (compound_decode_hdr_maxsz + \
369                                 decode_putfh_maxsz + \
370                                 decode_getattr_maxsz)
371 #define NFS4_enc_statfs_sz      (compound_encode_hdr_maxsz + \
372                                 encode_putfh_maxsz + \
373                                 encode_getattr_maxsz)
374 #define NFS4_dec_statfs_sz      (compound_decode_hdr_maxsz + \
375                                 decode_putfh_maxsz + \
376                                 op_decode_hdr_maxsz + 12)
377 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
378                                 encode_getattr_maxsz)
379 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
380                                 decode_getattr_maxsz)
381 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
382                                 encode_putfh_maxsz + \
383                                 encode_delegreturn_maxsz)
384 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
385                                 decode_delegreturn_maxsz)
386 #define NFS4_enc_getacl_sz      (compound_encode_hdr_maxsz + \
387                                 encode_putfh_maxsz + \
388                                 encode_getattr_maxsz)
389 #define NFS4_dec_getacl_sz      (compound_decode_hdr_maxsz + \
390                                 decode_putfh_maxsz + \
391                                 op_decode_hdr_maxsz + \
392                                 nfs4_fattr_bitmap_maxsz + 1)
393 #define NFS4_enc_setacl_sz      (compound_encode_hdr_maxsz + \
394                                 encode_putfh_maxsz + \
395                                 op_encode_hdr_maxsz + 4 + \
396                                 nfs4_fattr_bitmap_maxsz + 1)
397 #define NFS4_dec_setacl_sz      (compound_decode_hdr_maxsz + \
398                                 decode_putfh_maxsz + \
399                                 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
400
401 static struct {
402         unsigned int    mode;
403         unsigned int    nfs2type;
404 } nfs_type2fmt[] = {
405         { 0,            NFNON        },
406         { S_IFREG,      NFREG        },
407         { S_IFDIR,      NFDIR        },
408         { S_IFBLK,      NFBLK        },
409         { S_IFCHR,      NFCHR        },
410         { S_IFLNK,      NFLNK        },
411         { S_IFSOCK,     NFSOCK       },
412         { S_IFIFO,      NFFIFO       },
413         { 0,            NFNON        },
414         { 0,            NFNON        },
415 };
416
417 struct compound_hdr {
418         int32_t         status;
419         uint32_t        nops;
420         uint32_t        taglen;
421         char *          tag;
422 };
423
424 /*
425  * START OF "GENERIC" ENCODE ROUTINES.
426  *   These may look a little ugly since they are imported from a "generic"
427  * set of XDR encode/decode routines which are intended to be shared by
428  * all of our NFSv4 implementations (OpenBSD, MacOS X...).
429  *
430  * If the pain of reading these is too great, it should be a straightforward
431  * task to translate them into Linux-specific versions which are more
432  * consistent with the style used in NFSv2/v3...
433  */
434 #define WRITE32(n)               *p++ = htonl(n)
435 #define WRITE64(n)               do {                           \
436         *p++ = htonl((uint32_t)((n) >> 32));                            \
437         *p++ = htonl((uint32_t)(n));                                    \
438 } while (0)
439 #define WRITEMEM(ptr,nbytes)     do {                           \
440         p = xdr_encode_opaque_fixed(p, ptr, nbytes);            \
441 } while (0)
442
443 #define RESERVE_SPACE(nbytes)   do {                            \
444         p = xdr_reserve_space(xdr, nbytes);                     \
445         if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
446         BUG_ON(!p);                                             \
447 } while (0)
448
449 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
450 {
451         uint32_t *p;
452
453         p = xdr_reserve_space(xdr, 4 + len);
454         BUG_ON(p == NULL);
455         xdr_encode_opaque(p, str, len);
456 }
457
458 static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
459 {
460         uint32_t *p;
461
462         dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
463         BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
464         RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
465         WRITE32(hdr->taglen);
466         WRITEMEM(hdr->tag, hdr->taglen);
467         WRITE32(NFS4_MINOR_VERSION);
468         WRITE32(hdr->nops);
469         return 0;
470 }
471
472 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
473 {
474         uint32_t *p;
475
476         p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
477         BUG_ON(p == NULL);
478         xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
479 }
480
481 static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
482 {
483         char owner_name[IDMAP_NAMESZ];
484         char owner_group[IDMAP_NAMESZ];
485         int owner_namelen = 0;
486         int owner_grouplen = 0;
487         uint32_t *p;
488         uint32_t *q;
489         int len;
490         uint32_t bmval0 = 0;
491         uint32_t bmval1 = 0;
492         int status;
493
494         /*
495          * We reserve enough space to write the entire attribute buffer at once.
496          * In the worst-case, this would be
497          *   12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
498          *          = 36 bytes, plus any contribution from variable-length fields
499          *            such as owner/group.
500          */
501         len = 16;
502
503         /* Sigh */
504         if (iap->ia_valid & ATTR_SIZE)
505                 len += 8;
506         if (iap->ia_valid & ATTR_MODE)
507                 len += 4;
508         if (iap->ia_valid & ATTR_UID) {
509                 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
510                 if (owner_namelen < 0) {
511                         printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
512                                iap->ia_uid);
513                         /* XXX */
514                         strcpy(owner_name, "nobody");
515                         owner_namelen = sizeof("nobody") - 1;
516                         /* goto out; */
517                 }
518                 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
519         }
520         if (iap->ia_valid & ATTR_GID) {
521                 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
522                 if (owner_grouplen < 0) {
523                         printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
524                                iap->ia_gid);
525                         strcpy(owner_group, "nobody");
526                         owner_grouplen = sizeof("nobody") - 1;
527                         /* goto out; */
528                 }
529                 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
530         }
531         if (iap->ia_valid & ATTR_ATIME_SET)
532                 len += 16;
533         else if (iap->ia_valid & ATTR_ATIME)
534                 len += 4;
535         if (iap->ia_valid & ATTR_MTIME_SET)
536                 len += 16;
537         else if (iap->ia_valid & ATTR_MTIME)
538                 len += 4;
539         RESERVE_SPACE(len);
540
541         /*
542          * We write the bitmap length now, but leave the bitmap and the attribute
543          * buffer length to be backfilled at the end of this routine.
544          */
545         WRITE32(2);
546         q = p;
547         p += 3;
548
549         if (iap->ia_valid & ATTR_SIZE) {
550                 bmval0 |= FATTR4_WORD0_SIZE;
551                 WRITE64(iap->ia_size);
552         }
553         if (iap->ia_valid & ATTR_MODE) {
554                 bmval1 |= FATTR4_WORD1_MODE;
555                 WRITE32(iap->ia_mode);
556         }
557         if (iap->ia_valid & ATTR_UID) {
558                 bmval1 |= FATTR4_WORD1_OWNER;
559                 WRITE32(owner_namelen);
560                 WRITEMEM(owner_name, owner_namelen);
561         }
562         if (iap->ia_valid & ATTR_GID) {
563                 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
564                 WRITE32(owner_grouplen);
565                 WRITEMEM(owner_group, owner_grouplen);
566         }
567         if (iap->ia_valid & ATTR_ATIME_SET) {
568                 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
569                 WRITE32(NFS4_SET_TO_CLIENT_TIME);
570                 WRITE32(0);
571                 WRITE32(iap->ia_mtime.tv_sec);
572                 WRITE32(iap->ia_mtime.tv_nsec);
573         }
574         else if (iap->ia_valid & ATTR_ATIME) {
575                 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
576                 WRITE32(NFS4_SET_TO_SERVER_TIME);
577         }
578         if (iap->ia_valid & ATTR_MTIME_SET) {
579                 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
580                 WRITE32(NFS4_SET_TO_CLIENT_TIME);
581                 WRITE32(0);
582                 WRITE32(iap->ia_mtime.tv_sec);
583                 WRITE32(iap->ia_mtime.tv_nsec);
584         }
585         else if (iap->ia_valid & ATTR_MTIME) {
586                 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
587                 WRITE32(NFS4_SET_TO_SERVER_TIME);
588         }
589         
590         /*
591          * Now we backfill the bitmap and the attribute buffer length.
592          */
593         if (len != ((char *)p - (char *)q) + 4) {
594                 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
595                                 len, ((char *)p - (char *)q) + 4);
596                 BUG();
597         }
598         len = (char *)p - (char *)q - 12;
599         *q++ = htonl(bmval0);
600         *q++ = htonl(bmval1);
601         *q++ = htonl(len);
602
603         status = 0;
604 /* out: */
605         return status;
606 }
607
608 static int encode_access(struct xdr_stream *xdr, u32 access)
609 {
610         uint32_t *p;
611
612         RESERVE_SPACE(8);
613         WRITE32(OP_ACCESS);
614         WRITE32(access);
615         
616         return 0;
617 }
618
619 static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
620 {
621         uint32_t *p;
622
623         RESERVE_SPACE(8+sizeof(arg->stateid->data));
624         WRITE32(OP_CLOSE);
625         WRITE32(arg->seqid->sequence->counter);
626         WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
627         
628         return 0;
629 }
630
631 static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
632 {
633         uint32_t *p;
634         
635         RESERVE_SPACE(16);
636         WRITE32(OP_COMMIT);
637         WRITE64(args->offset);
638         WRITE32(args->count);
639
640         return 0;
641 }
642
643 static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
644 {
645         uint32_t *p;
646         
647         RESERVE_SPACE(8);
648         WRITE32(OP_CREATE);
649         WRITE32(create->ftype);
650
651         switch (create->ftype) {
652         case NF4LNK:
653                 RESERVE_SPACE(4 + create->u.symlink->len);
654                 WRITE32(create->u.symlink->len);
655                 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
656                 break;
657
658         case NF4BLK: case NF4CHR:
659                 RESERVE_SPACE(8);
660                 WRITE32(create->u.device.specdata1);
661                 WRITE32(create->u.device.specdata2);
662                 break;
663
664         default:
665                 break;
666         }
667
668         RESERVE_SPACE(4 + create->name->len);
669         WRITE32(create->name->len);
670         WRITEMEM(create->name->name, create->name->len);
671
672         return encode_attrs(xdr, create->attrs, create->server);
673 }
674
675 static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
676 {
677         uint32_t *p;
678
679         RESERVE_SPACE(12);
680         WRITE32(OP_GETATTR);
681         WRITE32(1);
682         WRITE32(bitmap);
683         return 0;
684 }
685
686 static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
687 {
688         uint32_t *p;
689
690         RESERVE_SPACE(16);
691         WRITE32(OP_GETATTR);
692         WRITE32(2);
693         WRITE32(bm0);
694         WRITE32(bm1);
695         return 0;
696 }
697
698 static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
699 {
700         return encode_getattr_two(xdr,
701                         bitmask[0] & nfs4_fattr_bitmap[0],
702                         bitmask[1] & nfs4_fattr_bitmap[1]);
703 }
704
705 static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
706 {
707         return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
708                         bitmask[1] & nfs4_fsinfo_bitmap[1]);
709 }
710
711 static int encode_getfh(struct xdr_stream *xdr)
712 {
713         uint32_t *p;
714
715         RESERVE_SPACE(4);
716         WRITE32(OP_GETFH);
717
718         return 0;
719 }
720
721 static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
722 {
723         uint32_t *p;
724
725         RESERVE_SPACE(8 + name->len);
726         WRITE32(OP_LINK);
727         WRITE32(name->len);
728         WRITEMEM(name->name, name->len);
729         
730         return 0;
731 }
732
733 /*
734  * opcode,type,reclaim,offset,length,new_lock_owner = 32
735  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
736  */
737 static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
738 {
739         uint32_t *p;
740         struct nfs_lock_opargs *opargs = arg->u.lock;
741
742         RESERVE_SPACE(32);
743         WRITE32(OP_LOCK);
744         WRITE32(arg->type); 
745         WRITE32(opargs->reclaim);
746         WRITE64(arg->offset);
747         WRITE64(arg->length);
748         WRITE32(opargs->new_lock_owner);
749         if (opargs->new_lock_owner){
750                 RESERVE_SPACE(40);
751                 WRITE32(opargs->open_seqid->sequence->counter);
752                 WRITEMEM(opargs->open_stateid->data, sizeof(opargs->open_stateid->data));
753                 WRITE32(opargs->lock_seqid->sequence->counter);
754                 WRITE64(opargs->lock_owner.clientid);
755                 WRITE32(4);
756                 WRITE32(opargs->lock_owner.id);
757         }
758         else {
759                 RESERVE_SPACE(20);
760                 WRITEMEM(opargs->lock_stateid->data, sizeof(opargs->lock_stateid->data));
761                 WRITE32(opargs->lock_seqid->sequence->counter);
762         }
763
764         return 0;
765 }
766
767 static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
768 {
769         uint32_t *p;
770         struct nfs_lowner *opargs = arg->u.lockt;
771
772         RESERVE_SPACE(40);
773         WRITE32(OP_LOCKT);
774         WRITE32(arg->type);
775         WRITE64(arg->offset);
776         WRITE64(arg->length);
777         WRITE64(opargs->clientid);
778         WRITE32(4);
779         WRITE32(opargs->id);
780
781         return 0;
782 }
783
784 static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
785 {
786         uint32_t *p;
787         struct nfs_locku_opargs *opargs = arg->u.locku;
788
789         RESERVE_SPACE(44);
790         WRITE32(OP_LOCKU);
791         WRITE32(arg->type);
792         WRITE32(opargs->seqid->sequence->counter);
793         WRITEMEM(opargs->stateid->data, sizeof(opargs->stateid->data));
794         WRITE64(arg->offset);
795         WRITE64(arg->length);
796
797         return 0;
798 }
799
800 static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
801 {
802         int len = name->len;
803         uint32_t *p;
804
805         RESERVE_SPACE(8 + len);
806         WRITE32(OP_LOOKUP);
807         WRITE32(len);
808         WRITEMEM(name->name, len);
809
810         return 0;
811 }
812
813 static void encode_share_access(struct xdr_stream *xdr, int open_flags)
814 {
815         uint32_t *p;
816
817         RESERVE_SPACE(8);
818         switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
819                 case FMODE_READ:
820                         WRITE32(NFS4_SHARE_ACCESS_READ);
821                         break;
822                 case FMODE_WRITE:
823                         WRITE32(NFS4_SHARE_ACCESS_WRITE);
824                         break;
825                 case FMODE_READ|FMODE_WRITE:
826                         WRITE32(NFS4_SHARE_ACCESS_BOTH);
827                         break;
828                 default:
829                         BUG();
830         }
831         WRITE32(0);             /* for linux, share_deny = 0 always */
832 }
833
834 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
835 {
836         uint32_t *p;
837  /*
838  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
839  * owner 4 = 32
840  */
841         RESERVE_SPACE(8);
842         WRITE32(OP_OPEN);
843         WRITE32(arg->seqid->sequence->counter);
844         encode_share_access(xdr, arg->open_flags);
845         RESERVE_SPACE(16);
846         WRITE64(arg->clientid);
847         WRITE32(4);
848         WRITE32(arg->id);
849 }
850
851 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
852 {
853         uint32_t *p;
854
855         RESERVE_SPACE(4);
856         switch(arg->open_flags & O_EXCL) {
857                 case 0:
858                         WRITE32(NFS4_CREATE_UNCHECKED);
859                         encode_attrs(xdr, arg->u.attrs, arg->server);
860                         break;
861                 default:
862                         WRITE32(NFS4_CREATE_EXCLUSIVE);
863                         encode_nfs4_verifier(xdr, &arg->u.verifier);
864         }
865 }
866
867 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
868 {
869         uint32_t *p;
870
871         RESERVE_SPACE(4);
872         switch (arg->open_flags & O_CREAT) {
873                 case 0:
874                         WRITE32(NFS4_OPEN_NOCREATE);
875                         break;
876                 default:
877                         BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
878                         WRITE32(NFS4_OPEN_CREATE);
879                         encode_createmode(xdr, arg);
880         }
881 }
882
883 static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
884 {
885         uint32_t *p;
886
887         RESERVE_SPACE(4);
888         switch (delegation_type) {
889                 case 0:
890                         WRITE32(NFS4_OPEN_DELEGATE_NONE);
891                         break;
892                 case FMODE_READ:
893                         WRITE32(NFS4_OPEN_DELEGATE_READ);
894                         break;
895                 case FMODE_WRITE|FMODE_READ:
896                         WRITE32(NFS4_OPEN_DELEGATE_WRITE);
897                         break;
898                 default:
899                         BUG();
900         }
901 }
902
903 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
904 {
905         uint32_t *p;
906
907         RESERVE_SPACE(4);
908         WRITE32(NFS4_OPEN_CLAIM_NULL);
909         encode_string(xdr, name->len, name->name);
910 }
911
912 static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
913 {
914         uint32_t *p;
915
916         RESERVE_SPACE(4);
917         WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
918         encode_delegation_type(xdr, type);
919 }
920
921 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
922 {
923         uint32_t *p;
924
925         RESERVE_SPACE(4+sizeof(stateid->data));
926         WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
927         WRITEMEM(stateid->data, sizeof(stateid->data));
928         encode_string(xdr, name->len, name->name);
929 }
930
931 static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
932 {
933         encode_openhdr(xdr, arg);
934         encode_opentype(xdr, arg);
935         switch (arg->claim) {
936                 case NFS4_OPEN_CLAIM_NULL:
937                         encode_claim_null(xdr, arg->name);
938                         break;
939                 case NFS4_OPEN_CLAIM_PREVIOUS:
940                         encode_claim_previous(xdr, arg->u.delegation_type);
941                         break;
942                 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
943                         encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
944                         break;
945                 default:
946                         BUG();
947         }
948         return 0;
949 }
950
951 static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
952 {
953         uint32_t *p;
954
955         RESERVE_SPACE(8+sizeof(arg->stateid.data));
956         WRITE32(OP_OPEN_CONFIRM);
957         WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
958         WRITE32(arg->seqid->sequence->counter);
959
960         return 0;
961 }
962
963 static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
964 {
965         uint32_t *p;
966
967         RESERVE_SPACE(8+sizeof(arg->stateid->data));
968         WRITE32(OP_OPEN_DOWNGRADE);
969         WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
970         WRITE32(arg->seqid->sequence->counter);
971         encode_share_access(xdr, arg->open_flags);
972         return 0;
973 }
974
975 static int
976 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
977 {
978         int len = fh->size;
979         uint32_t *p;
980
981         RESERVE_SPACE(8 + len);
982         WRITE32(OP_PUTFH);
983         WRITE32(len);
984         WRITEMEM(fh->data, len);
985
986         return 0;
987 }
988
989 static int encode_putrootfh(struct xdr_stream *xdr)
990 {
991         uint32_t *p;
992         
993         RESERVE_SPACE(4);
994         WRITE32(OP_PUTROOTFH);
995
996         return 0;
997 }
998
999 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1000 {
1001         nfs4_stateid stateid;
1002         uint32_t *p;
1003
1004         RESERVE_SPACE(16);
1005         if (ctx->state != NULL) {
1006                 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1007                 WRITEMEM(stateid.data, sizeof(stateid.data));
1008         } else
1009                 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1010 }
1011
1012 static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1013 {
1014         uint32_t *p;
1015
1016         RESERVE_SPACE(4);
1017         WRITE32(OP_READ);
1018
1019         encode_stateid(xdr, args->context);
1020
1021         RESERVE_SPACE(12);
1022         WRITE64(args->offset);
1023         WRITE32(args->count);
1024
1025         return 0;
1026 }
1027
1028 static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1029 {
1030         struct rpc_auth *auth = req->rq_task->tk_auth;
1031         uint32_t attrs[2] = {
1032                 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1033                 FATTR4_WORD1_MOUNTED_ON_FILEID,
1034         };
1035         int replen;
1036         uint32_t *p;
1037
1038         RESERVE_SPACE(32+sizeof(nfs4_verifier));
1039         WRITE32(OP_READDIR);
1040         WRITE64(readdir->cookie);
1041         WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1042         WRITE32(readdir->count >> 1);  /* We're not doing readdirplus */
1043         WRITE32(readdir->count);
1044         WRITE32(2);
1045         /* Switch to mounted_on_fileid if the server supports it */
1046         if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1047                 attrs[0] &= ~FATTR4_WORD0_FILEID;
1048         else
1049                 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1050         WRITE32(attrs[0] & readdir->bitmask[0]);
1051         WRITE32(attrs[1] & readdir->bitmask[1]);
1052         dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1053                         __FUNCTION__,
1054                         (unsigned long long)readdir->cookie,
1055                         ((u32 *)readdir->verifier.data)[0],
1056                         ((u32 *)readdir->verifier.data)[1],
1057                         attrs[0] & readdir->bitmask[0],
1058                         attrs[1] & readdir->bitmask[1]);
1059
1060         /* set up reply kvec
1061          *    toplevel_status + taglen + rescount + OP_PUTFH + status
1062          *      + OP_READDIR + status + verifer(2)  = 9
1063          */
1064         replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1065         xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1066                          readdir->pgbase, readdir->count);
1067         dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1068                         __FUNCTION__, replen, readdir->pages,
1069                         readdir->pgbase, readdir->count);
1070
1071         return 0;
1072 }
1073
1074 static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1075 {
1076         struct rpc_auth *auth = req->rq_task->tk_auth;
1077         unsigned int replen;
1078         uint32_t *p;
1079
1080         RESERVE_SPACE(4);
1081         WRITE32(OP_READLINK);
1082
1083         /* set up reply kvec
1084          *    toplevel_status + taglen + rescount + OP_PUTFH + status
1085          *      + OP_READLINK + status + string length = 8
1086          */
1087         replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1088         xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1089                         readlink->pgbase, readlink->pglen);
1090         
1091         return 0;
1092 }
1093
1094 static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1095 {
1096         uint32_t *p;
1097
1098         RESERVE_SPACE(8 + name->len);
1099         WRITE32(OP_REMOVE);
1100         WRITE32(name->len);
1101         WRITEMEM(name->name, name->len);
1102
1103         return 0;
1104 }
1105
1106 static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1107 {
1108         uint32_t *p;
1109
1110         RESERVE_SPACE(8 + oldname->len);
1111         WRITE32(OP_RENAME);
1112         WRITE32(oldname->len);
1113         WRITEMEM(oldname->name, oldname->len);
1114         
1115         RESERVE_SPACE(4 + newname->len);
1116         WRITE32(newname->len);
1117         WRITEMEM(newname->name, newname->len);
1118
1119         return 0;
1120 }
1121
1122 static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1123 {
1124         uint32_t *p;
1125
1126         RESERVE_SPACE(12);
1127         WRITE32(OP_RENEW);
1128         WRITE64(client_stateid->cl_clientid);
1129
1130         return 0;
1131 }
1132
1133 static int
1134 encode_restorefh(struct xdr_stream *xdr)
1135 {
1136         uint32_t *p;
1137
1138         RESERVE_SPACE(4);
1139         WRITE32(OP_RESTOREFH);
1140
1141         return 0;
1142 }
1143
1144 static int
1145 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1146 {
1147         uint32_t *p;
1148
1149         RESERVE_SPACE(4+sizeof(zero_stateid.data));
1150         WRITE32(OP_SETATTR);
1151         WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1152         RESERVE_SPACE(2*4);
1153         WRITE32(1);
1154         WRITE32(FATTR4_WORD0_ACL);
1155         if (arg->acl_len % 4)
1156                 return -EINVAL;
1157         RESERVE_SPACE(4);
1158         WRITE32(arg->acl_len);
1159         xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1160         return 0;
1161 }
1162
1163 static int
1164 encode_savefh(struct xdr_stream *xdr)
1165 {
1166         uint32_t *p;
1167
1168         RESERVE_SPACE(4);
1169         WRITE32(OP_SAVEFH);
1170
1171         return 0;
1172 }
1173
1174 static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1175 {
1176         int status;
1177         uint32_t *p;
1178         
1179         RESERVE_SPACE(4+sizeof(arg->stateid.data));
1180         WRITE32(OP_SETATTR);
1181         WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1182
1183         if ((status = encode_attrs(xdr, arg->iap, server)))
1184                 return status;
1185
1186         return 0;
1187 }
1188
1189 static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1190 {
1191         uint32_t *p;
1192
1193         RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1194         WRITE32(OP_SETCLIENTID);
1195         WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1196
1197         encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1198         RESERVE_SPACE(4);
1199         WRITE32(setclientid->sc_prog);
1200         encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1201         encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1202         RESERVE_SPACE(4);
1203         WRITE32(setclientid->sc_cb_ident);
1204
1205         return 0;
1206 }
1207
1208 static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1209 {
1210         uint32_t *p;
1211
1212         RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1213         WRITE32(OP_SETCLIENTID_CONFIRM);
1214         WRITE64(client_state->cl_clientid);
1215         WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1216
1217         return 0;
1218 }
1219
1220 static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1221 {
1222         uint32_t *p;
1223
1224         RESERVE_SPACE(4);
1225         WRITE32(OP_WRITE);
1226
1227         encode_stateid(xdr, args->context);
1228
1229         RESERVE_SPACE(16);
1230         WRITE64(args->offset);
1231         WRITE32(args->stable);
1232         WRITE32(args->count);
1233
1234         xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1235
1236         return 0;
1237 }
1238
1239 static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1240 {
1241         uint32_t *p;
1242
1243         RESERVE_SPACE(20);
1244
1245         WRITE32(OP_DELEGRETURN);
1246         WRITEMEM(stateid->data, sizeof(stateid->data));
1247         return 0;
1248
1249 }
1250 /*
1251  * END OF "GENERIC" ENCODE ROUTINES.
1252  */
1253
1254 /*
1255  * Encode an ACCESS request
1256  */
1257 static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1258 {
1259         struct xdr_stream xdr;
1260         struct compound_hdr hdr = {
1261                 .nops = 2,
1262         };
1263         int status;
1264
1265         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1266         encode_compound_hdr(&xdr, &hdr);
1267         if ((status = encode_putfh(&xdr, args->fh)) == 0)
1268                 status = encode_access(&xdr, args->access);
1269         return status;
1270 }
1271
1272 /*
1273  * Encode LOOKUP request
1274  */
1275 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1276 {
1277         struct xdr_stream xdr;
1278         struct compound_hdr hdr = {
1279                 .nops = 4,
1280         };
1281         int status;
1282
1283         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1284         encode_compound_hdr(&xdr, &hdr);
1285         if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1286                 goto out;
1287         if ((status = encode_lookup(&xdr, args->name)) != 0)
1288                 goto out;
1289         if ((status = encode_getfh(&xdr)) != 0)
1290                 goto out;
1291         status = encode_getfattr(&xdr, args->bitmask);
1292 out:
1293         return status;
1294 }
1295
1296 /*
1297  * Encode LOOKUP_ROOT request
1298  */
1299 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1300 {
1301         struct xdr_stream xdr;
1302         struct compound_hdr hdr = {
1303                 .nops = 3,
1304         };
1305         int status;
1306
1307         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1308         encode_compound_hdr(&xdr, &hdr);
1309         if ((status = encode_putrootfh(&xdr)) != 0)
1310                 goto out;
1311         if ((status = encode_getfh(&xdr)) == 0)
1312                 status = encode_getfattr(&xdr, args->bitmask);
1313 out:
1314         return status;
1315 }
1316
1317 /*
1318  * Encode REMOVE request
1319  */
1320 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1321 {
1322         struct xdr_stream xdr;
1323         struct compound_hdr hdr = {
1324                 .nops = 2,
1325         };
1326         int status;
1327
1328         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1329         encode_compound_hdr(&xdr, &hdr);
1330         if ((status = encode_putfh(&xdr, args->fh)) == 0)
1331                 status = encode_remove(&xdr, args->name);
1332         return status;
1333 }
1334
1335 /*
1336  * Encode RENAME request
1337  */
1338 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1339 {
1340         struct xdr_stream xdr;
1341         struct compound_hdr hdr = {
1342                 .nops = 4,
1343         };
1344         int status;
1345
1346         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1347         encode_compound_hdr(&xdr, &hdr);
1348         if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1349                 goto out;
1350         if ((status = encode_savefh(&xdr)) != 0)
1351                 goto out;
1352         if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1353                 goto out;
1354         status = encode_rename(&xdr, args->old_name, args->new_name);
1355 out:
1356         return status;
1357 }
1358
1359 /*
1360  * Encode LINK request
1361  */
1362 static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1363 {
1364         struct xdr_stream xdr;
1365         struct compound_hdr hdr = {
1366                 .nops = 7,
1367         };
1368         int status;
1369
1370         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1371         encode_compound_hdr(&xdr, &hdr);
1372         if ((status = encode_putfh(&xdr, args->fh)) != 0)
1373                 goto out;
1374         if ((status = encode_savefh(&xdr)) != 0)
1375                 goto out;
1376         if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1377                 goto out;
1378         if ((status = encode_link(&xdr, args->name)) != 0)
1379                 goto out;
1380         if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1381                 goto out;
1382         if ((status = encode_restorefh(&xdr)) != 0)
1383                 goto out;
1384         status = encode_getfattr(&xdr, args->bitmask);
1385 out:
1386         return status;
1387 }
1388
1389 /*
1390  * Encode CREATE request
1391  */
1392 static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1393 {
1394         struct xdr_stream xdr;
1395         struct compound_hdr hdr = {
1396                 .nops = 7,
1397         };
1398         int status;
1399
1400         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1401         encode_compound_hdr(&xdr, &hdr);
1402         if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1403                 goto out;
1404         if ((status = encode_savefh(&xdr)) != 0)
1405                 goto out;
1406         if ((status = encode_create(&xdr, args)) != 0)
1407                 goto out;
1408         if ((status = encode_getfh(&xdr)) != 0)
1409                 goto out;
1410         if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1411                 goto out;
1412         if ((status = encode_restorefh(&xdr)) != 0)
1413                 goto out;
1414         status = encode_getfattr(&xdr, args->bitmask);
1415 out:
1416         return status;
1417 }
1418
1419 /*
1420  * Encode SYMLINK request
1421  */
1422 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1423 {
1424         return nfs4_xdr_enc_create(req, p, args);
1425 }
1426
1427 /*
1428  * Encode GETATTR request
1429  */
1430 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1431 {
1432         struct xdr_stream xdr;
1433         struct compound_hdr hdr = {
1434                 .nops = 2,
1435         };
1436         int status;
1437
1438         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1439         encode_compound_hdr(&xdr, &hdr);
1440         if ((status = encode_putfh(&xdr, args->fh)) == 0)
1441                 status = encode_getfattr(&xdr, args->bitmask);
1442         return status;
1443 }
1444
1445 /*
1446  * Encode a CLOSE request
1447  */
1448 static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1449 {
1450         struct xdr_stream xdr;
1451         struct compound_hdr hdr = {
1452                 .nops   = 3,
1453         };
1454         int status;
1455
1456         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1457         encode_compound_hdr(&xdr, &hdr);
1458         status = encode_putfh(&xdr, args->fh);
1459         if(status)
1460                 goto out;
1461         status = encode_close(&xdr, args);
1462         if (status != 0)
1463                 goto out;
1464         status = encode_getfattr(&xdr, args->bitmask);
1465 out:
1466         return status;
1467 }
1468
1469 /*
1470  * Encode an OPEN request
1471  */
1472 static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1473 {
1474         struct xdr_stream xdr;
1475         struct compound_hdr hdr = {
1476                 .nops = 7,
1477         };
1478         int status;
1479
1480         status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1481         if (status != 0)
1482                 goto out;
1483         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1484         encode_compound_hdr(&xdr, &hdr);
1485         status = encode_putfh(&xdr, args->fh);
1486         if (status)
1487                 goto out;
1488         status = encode_savefh(&xdr);
1489         if (status)
1490                 goto out;
1491         status = encode_open(&xdr, args);
1492         if (status)
1493                 goto out;
1494         status = encode_getfh(&xdr);
1495         if (status)
1496                 goto out;
1497         status = encode_getfattr(&xdr, args->bitmask);
1498         if (status)
1499                 goto out;
1500         status = encode_restorefh(&xdr);
1501         if (status)
1502                 goto out;
1503         status = encode_getfattr(&xdr, args->bitmask);
1504 out:
1505         return status;
1506 }
1507
1508 /*
1509  * Encode an OPEN_CONFIRM request
1510  */
1511 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1512 {
1513         struct xdr_stream xdr;
1514         struct compound_hdr hdr = {
1515                 .nops   = 2,
1516         };
1517         int status;
1518
1519         status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1520         if (status != 0)
1521                 goto out;
1522         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1523         encode_compound_hdr(&xdr, &hdr);
1524         status = encode_putfh(&xdr, args->fh);
1525         if(status)
1526                 goto out;
1527         status = encode_open_confirm(&xdr, args);
1528 out:
1529         return status;
1530 }
1531
1532 /*
1533  * Encode an OPEN request with no attributes.
1534  */
1535 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1536 {
1537         struct xdr_stream xdr;
1538         struct compound_hdr hdr = {
1539                 .nops   = 2,
1540         };
1541         int status;
1542
1543         status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1544         if (status != 0)
1545                 goto out;
1546         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1547         encode_compound_hdr(&xdr, &hdr);
1548         status = encode_putfh(&xdr, args->fh);
1549         if (status)
1550                 goto out;
1551         status = encode_open(&xdr, args);
1552 out:
1553         return status;
1554 }
1555
1556 /*
1557  * Encode an OPEN_DOWNGRADE request
1558  */
1559 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1560 {
1561         struct xdr_stream xdr;
1562         struct compound_hdr hdr = {
1563                 .nops   = 3,
1564         };
1565         int status;
1566
1567         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1568         encode_compound_hdr(&xdr, &hdr);
1569         status = encode_putfh(&xdr, args->fh);
1570         if (status)
1571                 goto out;
1572         status = encode_open_downgrade(&xdr, args);
1573         if (status != 0)
1574                 goto out;
1575         status = encode_getfattr(&xdr, args->bitmask);
1576 out:
1577         return status;
1578 }
1579
1580 /*
1581  * Encode a LOCK request
1582  */
1583 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1584 {
1585         struct xdr_stream xdr;
1586         struct compound_hdr hdr = {
1587                 .nops   = 2,
1588         };
1589         struct nfs_lock_opargs *opargs = args->u.lock;
1590         int status;
1591
1592         status = nfs_wait_on_sequence(opargs->lock_seqid, req->rq_task);
1593         if (status != 0)
1594                 goto out;
1595         /* Do we need to do an open_to_lock_owner? */
1596         if (opargs->lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)
1597                 opargs->new_lock_owner = 0;
1598         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1599         encode_compound_hdr(&xdr, &hdr);
1600         status = encode_putfh(&xdr, args->fh);
1601         if(status)
1602                 goto out;
1603         status = encode_lock(&xdr, args);
1604 out:
1605         return status;
1606 }
1607
1608 /*
1609  * Encode a LOCKT request
1610  */
1611 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1612 {
1613         struct xdr_stream xdr;
1614         struct compound_hdr hdr = {
1615                 .nops   = 2,
1616         };
1617         int status;
1618
1619         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1620         encode_compound_hdr(&xdr, &hdr);
1621         status = encode_putfh(&xdr, args->fh);
1622         if(status)
1623                 goto out;
1624         status = encode_lockt(&xdr, args);
1625 out:
1626         return status;
1627 }
1628
1629 /*
1630  * Encode a LOCKU request
1631  */
1632 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1633 {
1634         struct xdr_stream xdr;
1635         struct compound_hdr hdr = {
1636                 .nops   = 2,
1637         };
1638         int status;
1639
1640         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1641         encode_compound_hdr(&xdr, &hdr);
1642         status = encode_putfh(&xdr, args->fh);
1643         if(status)
1644                 goto out;
1645         status = encode_locku(&xdr, args);
1646 out:
1647         return status;
1648 }
1649
1650 /*
1651  * Encode a READLINK request
1652  */
1653 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1654 {
1655         struct xdr_stream xdr;
1656         struct compound_hdr hdr = {
1657                 .nops = 2,
1658         };
1659         int status;
1660
1661         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1662         encode_compound_hdr(&xdr, &hdr);
1663         status = encode_putfh(&xdr, args->fh);
1664         if(status)
1665                 goto out;
1666         status = encode_readlink(&xdr, args, req);
1667 out:
1668         return status;
1669 }
1670
1671 /*
1672  * Encode a READDIR request
1673  */
1674 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1675 {
1676         struct xdr_stream xdr;
1677         struct compound_hdr hdr = {
1678                 .nops = 2,
1679         };
1680         int status;
1681
1682         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1683         encode_compound_hdr(&xdr, &hdr);
1684         status = encode_putfh(&xdr, args->fh);
1685         if(status)
1686                 goto out;
1687         status = encode_readdir(&xdr, args, req);
1688 out:
1689         return status;
1690 }
1691
1692 /*
1693  * Encode a READ request
1694  */
1695 static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1696 {
1697         struct rpc_auth *auth = req->rq_task->tk_auth;
1698         struct xdr_stream xdr;
1699         struct compound_hdr hdr = {
1700                 .nops = 2,
1701         };
1702         int replen, status;
1703
1704         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1705         encode_compound_hdr(&xdr, &hdr);
1706         status = encode_putfh(&xdr, args->fh);
1707         if (status)
1708                 goto out;
1709         status = encode_read(&xdr, args);
1710         if (status)
1711                 goto out;
1712
1713         /* set up reply kvec
1714          *    toplevel status + taglen=0 + rescount + OP_PUTFH + status
1715          *       + OP_READ + status + eof + datalen = 9
1716          */
1717         replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1718         xdr_inline_pages(&req->rq_rcv_buf, replen,
1719                          args->pages, args->pgbase, args->count);
1720 out:
1721         return status;
1722 }
1723
1724 /*
1725  * Encode an SETATTR request
1726  */
1727 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1728
1729 {
1730         struct xdr_stream xdr;
1731         struct compound_hdr hdr = {
1732                 .nops   = 3,
1733         };
1734         int status;
1735
1736         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1737         encode_compound_hdr(&xdr, &hdr);
1738         status = encode_putfh(&xdr, args->fh);
1739         if(status)
1740                 goto out;
1741         status = encode_setattr(&xdr, args, args->server);
1742         if(status)
1743                 goto out;
1744         status = encode_getfattr(&xdr, args->bitmask);
1745 out:
1746         return status;
1747 }
1748
1749 /*
1750  * Encode a GETACL request
1751  */
1752 static int
1753 nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p,
1754                 struct nfs_getaclargs *args)
1755 {
1756         struct xdr_stream xdr;
1757         struct rpc_auth *auth = req->rq_task->tk_auth;
1758         struct compound_hdr hdr = {
1759                 .nops   = 2,
1760         };
1761         int replen, status;
1762
1763         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1764         encode_compound_hdr(&xdr, &hdr);
1765         status = encode_putfh(&xdr, args->fh);
1766         if (status)
1767                 goto out;
1768         status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1769         /* set up reply buffer: */
1770         replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1771         xdr_inline_pages(&req->rq_rcv_buf, replen,
1772                 args->acl_pages, args->acl_pgbase, args->acl_len);
1773 out:
1774         return status;
1775 }
1776
1777 /*
1778  * Encode a WRITE request
1779  */
1780 static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1781 {
1782         struct xdr_stream xdr;
1783         struct compound_hdr hdr = {
1784                 .nops = 2,
1785         };
1786         int status;
1787
1788         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1789         encode_compound_hdr(&xdr, &hdr);
1790         status = encode_putfh(&xdr, args->fh);
1791         if (status)
1792                 goto out;
1793         status = encode_write(&xdr, args);
1794 out:
1795         return status;
1796 }
1797
1798 /*
1799  *  a COMMIT request
1800  */
1801 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1802 {
1803         struct xdr_stream xdr;
1804         struct compound_hdr hdr = {
1805                 .nops = 2,
1806         };
1807         int status;
1808
1809         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1810         encode_compound_hdr(&xdr, &hdr);
1811         status = encode_putfh(&xdr, args->fh);
1812         if (status)
1813                 goto out;
1814         status = encode_commit(&xdr, args);
1815 out:
1816         return status;
1817 }
1818
1819 /*
1820  * FSINFO request
1821  */
1822 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1823 {
1824         struct xdr_stream xdr;
1825         struct compound_hdr hdr = {
1826                 .nops   = 2,
1827         };
1828         int status;
1829
1830         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1831         encode_compound_hdr(&xdr, &hdr);
1832         status = encode_putfh(&xdr, args->fh);
1833         if (!status)
1834                 status = encode_fsinfo(&xdr, args->bitmask);
1835         return status;
1836 }
1837
1838 /*
1839  * a PATHCONF request
1840  */
1841 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1842 {
1843         struct xdr_stream xdr;
1844         struct compound_hdr hdr = {
1845                 .nops = 2,
1846         };
1847         int status;
1848
1849         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1850         encode_compound_hdr(&xdr, &hdr);
1851         status = encode_putfh(&xdr, args->fh);
1852         if (!status)
1853                 status = encode_getattr_one(&xdr,
1854                                 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1855         return status;
1856 }
1857
1858 /*
1859  * a STATFS request
1860  */
1861 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1862 {
1863         struct xdr_stream xdr;
1864         struct compound_hdr hdr = {
1865                 .nops = 2,
1866         };
1867         int status;
1868
1869         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1870         encode_compound_hdr(&xdr, &hdr);
1871         status = encode_putfh(&xdr, args->fh);
1872         if (status == 0)
1873                 status = encode_getattr_two(&xdr,
1874                                 args->bitmask[0] & nfs4_statfs_bitmap[0],
1875                                 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1876         return status;
1877 }
1878
1879 /*
1880  * GETATTR_BITMAP request
1881  */
1882 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1883 {
1884         struct xdr_stream xdr;
1885         struct compound_hdr hdr = {
1886                 .nops = 2,
1887         };
1888         int status;
1889
1890         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1891         encode_compound_hdr(&xdr, &hdr);
1892         status = encode_putfh(&xdr, fhandle);
1893         if (status == 0)
1894                 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1895                                 FATTR4_WORD0_LINK_SUPPORT|
1896                                 FATTR4_WORD0_SYMLINK_SUPPORT|
1897                                 FATTR4_WORD0_ACLSUPPORT);
1898         return status;
1899 }
1900
1901 /*
1902  * a RENEW request
1903  */
1904 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1905 {
1906         struct xdr_stream xdr;
1907         struct compound_hdr hdr = {
1908                 .nops   = 1,
1909         };
1910
1911         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1912         encode_compound_hdr(&xdr, &hdr);
1913         return encode_renew(&xdr, clp);
1914 }
1915
1916 /*
1917  * a SETCLIENTID request
1918  */
1919 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1920 {
1921         struct xdr_stream xdr;
1922         struct compound_hdr hdr = {
1923                 .nops   = 1,
1924         };
1925
1926         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1927         encode_compound_hdr(&xdr, &hdr);
1928         return encode_setclientid(&xdr, sc);
1929 }
1930
1931 /*
1932  * a SETCLIENTID_CONFIRM request
1933  */
1934 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1935 {
1936         struct xdr_stream xdr;
1937         struct compound_hdr hdr = {
1938                 .nops   = 3,
1939         };
1940         const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1941         int status;
1942
1943         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1944         encode_compound_hdr(&xdr, &hdr);
1945         status = encode_setclientid_confirm(&xdr, clp);
1946         if (!status)
1947                 status = encode_putrootfh(&xdr);
1948         if (!status)
1949                 status = encode_fsinfo(&xdr, lease_bitmap);
1950         return status;
1951 }
1952
1953 /*
1954  * DELEGRETURN request
1955  */
1956 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1957 {
1958         struct xdr_stream xdr;
1959         struct compound_hdr hdr = {
1960                 .nops = 2,
1961         };
1962         int status;
1963
1964         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1965         encode_compound_hdr(&xdr, &hdr);
1966         if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
1967                 status = encode_delegreturn(&xdr, args->stateid);
1968         return status;
1969 }
1970
1971 /*
1972  * START OF "GENERIC" DECODE ROUTINES.
1973  *   These may look a little ugly since they are imported from a "generic"
1974  * set of XDR encode/decode routines which are intended to be shared by
1975  * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1976  *
1977  * If the pain of reading these is too great, it should be a straightforward
1978  * task to translate them into Linux-specific versions which are more
1979  * consistent with the style used in NFSv2/v3...
1980  */
1981 #define READ32(x)         (x) = ntohl(*p++)
1982 #define READ64(x)         do {                  \
1983         (x) = (u64)ntohl(*p++) << 32;           \
1984         (x) |= ntohl(*p++);                     \
1985 } while (0)
1986 #define READTIME(x)       do {                  \
1987         p++;                                    \
1988         (x.tv_sec) = ntohl(*p++);               \
1989         (x.tv_nsec) = ntohl(*p++);              \
1990 } while (0)
1991 #define COPYMEM(x,nbytes) do {                  \
1992         memcpy((x), p, nbytes);                 \
1993         p += XDR_QUADLEN(nbytes);               \
1994 } while (0)
1995
1996 #define READ_BUF(nbytes)  do { \
1997         p = xdr_inline_decode(xdr, nbytes); \
1998         if (!p) { \
1999                 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
2000                                 __FUNCTION__, __LINE__); \
2001                 return -EIO; \
2002         } \
2003 } while (0)
2004
2005 static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
2006 {
2007         uint32_t *p;
2008
2009         READ_BUF(4);
2010         READ32(*len);
2011         READ_BUF(*len);
2012         *string = (char *)p;
2013         return 0;
2014 }
2015
2016 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2017 {
2018         uint32_t *p;
2019
2020         READ_BUF(8);
2021         READ32(hdr->status);
2022         READ32(hdr->taglen);
2023         
2024         READ_BUF(hdr->taglen + 4);
2025         hdr->tag = (char *)p;
2026         p += XDR_QUADLEN(hdr->taglen);
2027         READ32(hdr->nops);
2028         return 0;
2029 }
2030
2031 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2032 {
2033         uint32_t *p;
2034         uint32_t opnum;
2035         int32_t nfserr;
2036
2037         READ_BUF(8);
2038         READ32(opnum);
2039         if (opnum != expected) {
2040                 printk(KERN_NOTICE
2041                                 "nfs4_decode_op_hdr: Server returned operation"
2042                                 " %d but we issued a request for %d\n",
2043                                 opnum, expected);
2044                 return -EIO;
2045         }
2046         READ32(nfserr);
2047         if (nfserr != NFS_OK)
2048                 return -nfs_stat_to_errno(nfserr);
2049         return 0;
2050 }
2051
2052 /* Dummy routine */
2053 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
2054 {
2055         uint32_t *p;
2056         uint32_t strlen;
2057         char *str;
2058
2059         READ_BUF(12);
2060         return decode_opaque_inline(xdr, &strlen, &str);
2061 }
2062
2063 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2064 {
2065         uint32_t bmlen, *p;
2066
2067         READ_BUF(4);
2068         READ32(bmlen);
2069
2070         bitmap[0] = bitmap[1] = 0;
2071         READ_BUF((bmlen << 2));
2072         if (bmlen > 0) {
2073                 READ32(bitmap[0]);
2074                 if (bmlen > 1)
2075                         READ32(bitmap[1]);
2076         }
2077         return 0;
2078 }
2079
2080 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
2081 {
2082         uint32_t *p;
2083
2084         READ_BUF(4);
2085         READ32(*attrlen);
2086         *savep = xdr->p;
2087         return 0;
2088 }
2089
2090 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2091 {
2092         if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2093                 decode_attr_bitmap(xdr, bitmask);
2094                 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2095         } else
2096                 bitmask[0] = bitmask[1] = 0;
2097         dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2098         return 0;
2099 }
2100
2101 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2102 {
2103         uint32_t *p;
2104
2105         *type = 0;
2106         if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2107                 return -EIO;
2108         if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2109                 READ_BUF(4);
2110                 READ32(*type);
2111                 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2112                         dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2113                         return -EIO;
2114                 }
2115                 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2116         }
2117         dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2118         return 0;
2119 }
2120
2121 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2122 {
2123         uint32_t *p;
2124
2125         *change = 0;
2126         if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2127                 return -EIO;
2128         if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2129                 READ_BUF(8);
2130                 READ64(*change);
2131                 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2132         }
2133         dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2134                         (unsigned long long)*change);
2135         return 0;
2136 }
2137
2138 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2139 {
2140         uint32_t *p;
2141
2142         *size = 0;
2143         if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2144                 return -EIO;
2145         if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2146                 READ_BUF(8);
2147                 READ64(*size);
2148                 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2149         }
2150         dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2151         return 0;
2152 }
2153
2154 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2155 {
2156         uint32_t *p;
2157
2158         *res = 0;
2159         if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2160                 return -EIO;
2161         if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2162                 READ_BUF(4);
2163                 READ32(*res);
2164                 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2165         }
2166         dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2167         return 0;
2168 }
2169
2170 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2171 {
2172         uint32_t *p;
2173
2174         *res = 0;
2175         if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2176                 return -EIO;
2177         if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2178                 READ_BUF(4);
2179                 READ32(*res);
2180                 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2181         }
2182         dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2183         return 0;
2184 }
2185
2186 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2187 {
2188         uint32_t *p;
2189
2190         fsid->major = 0;
2191         fsid->minor = 0;
2192         if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2193                 return -EIO;
2194         if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2195                 READ_BUF(16);
2196                 READ64(fsid->major);
2197                 READ64(fsid->minor);
2198                 bitmap[0] &= ~FATTR4_WORD0_FSID;
2199         }
2200         dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2201                         (unsigned long long)fsid->major,
2202                         (unsigned long long)fsid->minor);
2203         return 0;
2204 }
2205
2206 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2207 {
2208         uint32_t *p;
2209
2210         *res = 60;
2211         if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2212                 return -EIO;
2213         if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2214                 READ_BUF(4);
2215                 READ32(*res);
2216                 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2217         }
2218         dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2219         return 0;
2220 }
2221
2222 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2223 {
2224         uint32_t *p;
2225
2226         *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2227         if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2228                 return -EIO;
2229         if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2230                 READ_BUF(4);
2231                 READ32(*res);
2232                 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2233         }
2234         dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2235         return 0;
2236 }
2237
2238 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2239 {
2240         uint32_t *p;
2241
2242         *fileid = 0;
2243         if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2244                 return -EIO;
2245         if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2246                 READ_BUF(8);
2247                 READ64(*fileid);
2248                 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2249         }
2250         dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2251         return 0;
2252 }
2253
2254 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2255 {
2256         uint32_t *p;
2257         int status = 0;
2258
2259         *res = 0;
2260         if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2261                 return -EIO;
2262         if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2263                 READ_BUF(8);
2264                 READ64(*res);
2265                 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2266         }
2267         dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2268         return status;
2269 }
2270
2271 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2272 {
2273         uint32_t *p;
2274         int status = 0;
2275
2276         *res = 0;
2277         if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2278                 return -EIO;
2279         if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2280                 READ_BUF(8);
2281                 READ64(*res);
2282                 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2283         }
2284         dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2285         return status;
2286 }
2287
2288 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2289 {
2290         uint32_t *p;
2291         int status = 0;
2292
2293         *res = 0;
2294         if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2295                 return -EIO;
2296         if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2297                 READ_BUF(8);
2298                 READ64(*res);
2299                 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2300         }
2301         dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2302         return status;
2303 }
2304
2305 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2306 {
2307         uint32_t *p;
2308         int status = 0;
2309
2310         *res = 0;
2311         if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2312                 return -EIO;
2313         if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2314                 READ_BUF(8);
2315                 READ64(*res);
2316                 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2317         }
2318         dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2319         return status;
2320 }
2321
2322 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2323 {
2324         uint32_t *p;
2325         int status = 0;
2326
2327         *maxlink = 1;
2328         if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2329                 return -EIO;
2330         if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2331                 READ_BUF(4);
2332                 READ32(*maxlink);
2333                 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2334         }
2335         dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2336         return status;
2337 }
2338
2339 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2340 {
2341         uint32_t *p;
2342         int status = 0;
2343
2344         *maxname = 1024;
2345         if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2346                 return -EIO;
2347         if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2348                 READ_BUF(4);
2349                 READ32(*maxname);
2350                 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2351         }
2352         dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2353         return status;
2354 }
2355
2356 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2357 {
2358         uint32_t *p;
2359         int status = 0;
2360
2361         *res = 1024;
2362         if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2363                 return -EIO;
2364         if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2365                 uint64_t maxread;
2366                 READ_BUF(8);
2367                 READ64(maxread);
2368                 if (maxread > 0x7FFFFFFF)
2369                         maxread = 0x7FFFFFFF;
2370                 *res = (uint32_t)maxread;
2371                 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2372         }
2373         dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2374         return status;
2375 }
2376
2377 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2378 {
2379         uint32_t *p;
2380         int status = 0;
2381
2382         *res = 1024;
2383         if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2384                 return -EIO;
2385         if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2386                 uint64_t maxwrite;
2387                 READ_BUF(8);
2388                 READ64(maxwrite);
2389                 if (maxwrite > 0x7FFFFFFF)
2390                         maxwrite = 0x7FFFFFFF;
2391                 *res = (uint32_t)maxwrite;
2392                 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2393         }
2394         dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2395         return status;
2396 }
2397
2398 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2399 {
2400         uint32_t *p;
2401
2402         *mode = 0;
2403         if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2404                 return -EIO;
2405         if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2406                 READ_BUF(4);
2407                 READ32(*mode);
2408                 *mode &= ~S_IFMT;
2409                 bitmap[1] &= ~FATTR4_WORD1_MODE;
2410         }
2411         dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2412         return 0;
2413 }
2414
2415 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2416 {
2417         uint32_t *p;
2418
2419         *nlink = 1;
2420         if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2421                 return -EIO;
2422         if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2423                 READ_BUF(4);
2424                 READ32(*nlink);
2425                 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2426         }
2427         dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2428         return 0;
2429 }
2430
2431 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2432 {
2433         uint32_t len, *p;
2434
2435         *uid = -2;
2436         if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2437                 return -EIO;
2438         if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2439                 READ_BUF(4);
2440                 READ32(len);
2441                 READ_BUF(len);
2442                 if (len < XDR_MAX_NETOBJ) {
2443                         if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2444                                 dprintk("%s: nfs_map_name_to_uid failed!\n",
2445                                                 __FUNCTION__);
2446                 } else
2447                         printk(KERN_WARNING "%s: name too long (%u)!\n",
2448                                         __FUNCTION__, len);
2449                 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2450         }
2451         dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2452         return 0;
2453 }
2454
2455 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2456 {
2457         uint32_t len, *p;
2458
2459         *gid = -2;
2460         if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2461                 return -EIO;
2462         if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2463                 READ_BUF(4);
2464                 READ32(len);
2465                 READ_BUF(len);
2466                 if (len < XDR_MAX_NETOBJ) {
2467                         if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2468                                 dprintk("%s: nfs_map_group_to_gid failed!\n",
2469                                                 __FUNCTION__);
2470                 } else
2471                         printk(KERN_WARNING "%s: name too long (%u)!\n",
2472                                         __FUNCTION__, len);
2473                 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2474         }
2475         dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2476         return 0;
2477 }
2478
2479 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2480 {
2481         uint32_t major = 0, minor = 0, *p;
2482
2483         *rdev = MKDEV(0,0);
2484         if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2485                 return -EIO;
2486         if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2487                 dev_t tmp;
2488
2489                 READ_BUF(8);
2490                 READ32(major);
2491                 READ32(minor);
2492                 tmp = MKDEV(major, minor);
2493                 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2494                         *rdev = tmp;
2495                 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2496         }
2497         dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2498         return 0;
2499 }
2500
2501 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2502 {
2503         uint32_t *p;
2504         int status = 0;
2505
2506         *res = 0;
2507         if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2508                 return -EIO;
2509         if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2510                 READ_BUF(8);
2511                 READ64(*res);
2512                 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2513         }
2514         dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2515         return status;
2516 }
2517
2518 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2519 {
2520         uint32_t *p;
2521         int status = 0;
2522
2523         *res = 0;
2524         if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2525                 return -EIO;
2526         if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2527                 READ_BUF(8);
2528                 READ64(*res);
2529                 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2530         }
2531         dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2532         return status;
2533 }
2534
2535 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2536 {
2537         uint32_t *p;
2538         int status = 0;
2539
2540         *res = 0;
2541         if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2542                 return -EIO;
2543         if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2544                 READ_BUF(8);
2545                 READ64(*res);
2546                 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2547         }
2548         dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2549         return status;
2550 }
2551
2552 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2553 {
2554         uint32_t *p;
2555
2556         *used = 0;
2557         if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2558                 return -EIO;
2559         if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2560                 READ_BUF(8);
2561                 READ64(*used);
2562                 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2563         }
2564         dprintk("%s: space used=%Lu\n", __FUNCTION__,
2565                         (unsigned long long)*used);
2566         return 0;
2567 }
2568
2569 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2570 {
2571         uint32_t *p;
2572         uint64_t sec;
2573         uint32_t nsec;
2574
2575         READ_BUF(12);
2576         READ64(sec);
2577         READ32(nsec);
2578         time->tv_sec = (time_t)sec;
2579         time->tv_nsec = (long)nsec;
2580         return 0;
2581 }
2582
2583 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2584 {
2585         int status = 0;
2586
2587         time->tv_sec = 0;
2588         time->tv_nsec = 0;
2589         if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2590                 return -EIO;
2591         if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2592                 status = decode_attr_time(xdr, time);
2593                 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2594         }
2595         dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2596         return status;
2597 }
2598
2599 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2600 {
2601         int status = 0;
2602
2603         time->tv_sec = 0;
2604         time->tv_nsec = 0;
2605         if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2606                 return -EIO;
2607         if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2608                 status = decode_attr_time(xdr, time);
2609                 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2610         }
2611         dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2612         return status;
2613 }
2614
2615 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2616 {
2617         int status = 0;
2618
2619         time->tv_sec = 0;
2620         time->tv_nsec = 0;
2621         if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2622                 return -EIO;
2623         if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2624                 status = decode_attr_time(xdr, time);
2625                 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2626         }
2627         dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2628         return status;
2629 }
2630
2631 static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2632 {
2633         unsigned int attrwords = XDR_QUADLEN(attrlen);
2634         unsigned int nwords = xdr->p - savep;
2635
2636         if (unlikely(attrwords != nwords)) {
2637                 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2638                                 __FUNCTION__,
2639                                 attrwords << 2,
2640                                 (attrwords < nwords) ? '<' : '>',
2641                                 nwords << 2);
2642                 return -EIO;
2643         }
2644         return 0;
2645 }
2646
2647 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2648 {
2649         uint32_t *p;
2650
2651         READ_BUF(20);
2652         READ32(cinfo->atomic);
2653         READ64(cinfo->before);
2654         READ64(cinfo->after);
2655         return 0;
2656 }
2657
2658 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2659 {
2660         uint32_t *p;
2661         uint32_t supp, acc;
2662         int status;
2663
2664         status = decode_op_hdr(xdr, OP_ACCESS);
2665         if (status)
2666                 return status;
2667         READ_BUF(8);
2668         READ32(supp);
2669         READ32(acc);
2670         access->supported = supp;
2671         access->access = acc;
2672         return 0;
2673 }
2674
2675 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2676 {
2677         uint32_t *p;
2678         int status;
2679
2680         status = decode_op_hdr(xdr, OP_CLOSE);
2681         if (status)
2682                 return status;
2683         READ_BUF(sizeof(res->stateid.data));
2684         COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2685         return 0;
2686 }
2687
2688 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2689 {
2690         uint32_t *p;
2691         int status;
2692
2693         status = decode_op_hdr(xdr, OP_COMMIT);
2694         if (status)
2695                 return status;
2696         READ_BUF(8);
2697         COPYMEM(res->verf->verifier, 8);
2698         return 0;
2699 }
2700
2701 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2702 {
2703         uint32_t *p;
2704         uint32_t bmlen;
2705         int status;
2706
2707         status = decode_op_hdr(xdr, OP_CREATE);
2708         if (status)
2709                 return status;
2710         if ((status = decode_change_info(xdr, cinfo)))
2711                 return status;
2712         READ_BUF(4);
2713         READ32(bmlen);
2714         READ_BUF(bmlen << 2);
2715         return 0;
2716 }
2717
2718 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2719 {
2720         uint32_t *savep;
2721         uint32_t attrlen, 
2722                  bitmap[2] = {0};
2723         int status;
2724
2725         if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2726                 goto xdr_error;
2727         if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2728                 goto xdr_error;
2729         if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2730                 goto xdr_error;
2731         if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2732                 goto xdr_error;
2733         if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2734                 goto xdr_error;
2735         if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2736                 goto xdr_error;
2737         if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2738                 goto xdr_error;
2739         status = verify_attr_len(xdr, savep, attrlen);
2740 xdr_error:
2741         if (status != 0)
2742                 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2743         return status;
2744 }
2745         
2746 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2747 {
2748         uint32_t *savep;
2749         uint32_t attrlen, 
2750                  bitmap[2] = {0};
2751         int status;
2752         
2753         if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2754                 goto xdr_error;
2755         if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2756                 goto xdr_error;
2757         if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2758                 goto xdr_error;
2759
2760         if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2761                 goto xdr_error;
2762         if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2763                 goto xdr_error;
2764         if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2765                 goto xdr_error;
2766         if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2767                 goto xdr_error;
2768         if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2769                 goto xdr_error;
2770         if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2771                 goto xdr_error;
2772
2773         status = verify_attr_len(xdr, savep, attrlen);
2774 xdr_error:
2775         if (status != 0)
2776                 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2777         return status;
2778 }
2779
2780 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2781 {
2782         uint32_t *savep;
2783         uint32_t attrlen, 
2784                  bitmap[2] = {0};
2785         int status;
2786         
2787         if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2788                 goto xdr_error;
2789         if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2790                 goto xdr_error;
2791         if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2792                 goto xdr_error;
2793
2794         if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2795                 goto xdr_error;
2796         if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2797                 goto xdr_error;
2798
2799         status = verify_attr_len(xdr, savep, attrlen);
2800 xdr_error:
2801         if (status != 0)
2802                 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2803         return status;
2804 }
2805
2806 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2807 {
2808         uint32_t *savep;
2809         uint32_t attrlen,
2810                  bitmap[2] = {0},
2811                  type;
2812         int status, fmode = 0;
2813
2814         if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2815                 goto xdr_error;
2816         if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2817                 goto xdr_error;
2818
2819         fattr->bitmap[0] = bitmap[0];
2820         fattr->bitmap[1] = bitmap[1];
2821
2822         if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2823                 goto xdr_error;
2824
2825
2826         if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2827                 goto xdr_error;
2828         fattr->type = nfs_type2fmt[type].nfs2type;
2829         fmode = nfs_type2fmt[type].mode;
2830
2831         if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2832                 goto xdr_error;
2833         if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2834                 goto xdr_error;
2835         if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2836                 goto xdr_error;
2837         if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2838                 goto xdr_error;
2839         if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2840                 goto xdr_error;
2841         fattr->mode |= fmode;
2842         if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2843                 goto xdr_error;
2844         if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2845                 goto xdr_error;
2846         if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2847                 goto xdr_error;
2848         if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2849                 goto xdr_error;
2850         if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2851                 goto xdr_error;
2852         if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2853                 goto xdr_error;
2854         if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2855                 goto xdr_error;
2856         if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2857                 goto xdr_error;
2858         if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
2859                 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
2860 xdr_error:
2861         if (status != 0)
2862                 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2863         return status;
2864 }
2865
2866
2867 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2868 {
2869         uint32_t *savep;
2870         uint32_t attrlen, bitmap[2];
2871         int status;
2872
2873         if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2874                 goto xdr_error;
2875         if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2876                 goto xdr_error;
2877         if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2878                 goto xdr_error;
2879
2880         fsinfo->rtmult = fsinfo->wtmult = 512;  /* ??? */
2881
2882         if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2883                 goto xdr_error;
2884         if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2885                 goto xdr_error;
2886         if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2887                 goto xdr_error;
2888         fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2889         if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2890                 goto xdr_error;
2891         fsinfo->wtpref = fsinfo->wtmax;
2892
2893         status = verify_attr_len(xdr, savep, attrlen);
2894 xdr_error:
2895         if (status != 0)
2896                 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2897         return status;
2898 }
2899
2900 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2901 {
2902         uint32_t *p;
2903         uint32_t len;
2904         int status;
2905
2906         status = decode_op_hdr(xdr, OP_GETFH);
2907         if (status)
2908                 return status;
2909         /* Zero handle first to allow comparisons */
2910         memset(fh, 0, sizeof(*fh));
2911
2912         READ_BUF(4);
2913         READ32(len);
2914         if (len > NFS4_FHSIZE)
2915                 return -EIO;
2916         fh->size = len;
2917         READ_BUF(len);
2918         COPYMEM(fh->data, len);
2919         return 0;
2920 }
2921
2922 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2923 {
2924         int status;
2925         
2926         status = decode_op_hdr(xdr, OP_LINK);
2927         if (status)
2928                 return status;
2929         return decode_change_info(xdr, cinfo);
2930 }
2931
2932 /*
2933  * We create the owner, so we know a proper owner.id length is 4.
2934  */
2935 static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2936 {
2937         uint32_t *p;
2938         uint32_t namelen;
2939
2940         READ_BUF(32);
2941         READ64(denied->offset);
2942         READ64(denied->length);
2943         READ32(denied->type);
2944         READ64(denied->owner.clientid);
2945         READ32(namelen);
2946         READ_BUF(namelen);
2947         if (namelen == 4)
2948                 READ32(denied->owner.id);
2949         return -NFS4ERR_DENIED;
2950 }
2951
2952 static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2953 {
2954         uint32_t *p;
2955         int status;
2956
2957         status = decode_op_hdr(xdr, OP_LOCK);
2958         if (status == 0) {
2959                 READ_BUF(sizeof(res->u.stateid.data));
2960                 COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data));
2961         } else if (status == -NFS4ERR_DENIED)
2962                 return decode_lock_denied(xdr, &res->u.denied);
2963         return status;
2964 }
2965
2966 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2967 {
2968         int status;
2969         status = decode_op_hdr(xdr, OP_LOCKT);
2970         if (status == -NFS4ERR_DENIED)
2971                 return decode_lock_denied(xdr, &res->u.denied);
2972         return status;
2973 }
2974
2975 static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2976 {
2977         uint32_t *p;
2978         int status;
2979
2980         status = decode_op_hdr(xdr, OP_LOCKU);
2981         if (status == 0) {
2982                 READ_BUF(sizeof(res->u.stateid.data));
2983                 COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data));
2984         }
2985         return status;
2986 }
2987
2988 static int decode_lookup(struct xdr_stream *xdr)
2989 {
2990         return decode_op_hdr(xdr, OP_LOOKUP);
2991 }
2992
2993 /* This is too sick! */
2994 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
2995 {
2996         uint32_t *p;
2997         uint32_t limit_type, nblocks, blocksize;
2998
2999         READ_BUF(12);
3000         READ32(limit_type);
3001         switch (limit_type) {
3002                 case 1:
3003                         READ64(*maxsize);
3004                         break;
3005                 case 2:
3006                         READ32(nblocks);
3007                         READ32(blocksize);
3008                         *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3009         }
3010         return 0;
3011 }
3012
3013 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3014 {
3015         uint32_t *p;
3016         uint32_t delegation_type;
3017
3018         READ_BUF(4);
3019         READ32(delegation_type);
3020         if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3021                 res->delegation_type = 0;
3022                 return 0;
3023         }
3024         READ_BUF(20);
3025         COPYMEM(res->delegation.data, sizeof(res->delegation.data));
3026         READ32(res->do_recall);
3027         switch (delegation_type) {
3028                 case NFS4_OPEN_DELEGATE_READ:
3029                         res->delegation_type = FMODE_READ;
3030                         break;
3031                 case NFS4_OPEN_DELEGATE_WRITE:
3032                         res->delegation_type = FMODE_WRITE|FMODE_READ;
3033                         if (decode_space_limit(xdr, &res->maxsize) < 0)
3034                                 return -EIO;
3035         }
3036         return decode_ace(xdr, NULL, res->server->nfs4_state);
3037 }
3038
3039 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3040 {
3041         uint32_t *p;
3042         uint32_t bmlen;
3043         int status;
3044
3045         status = decode_op_hdr(xdr, OP_OPEN);
3046         if (status)
3047                 return status;
3048         READ_BUF(sizeof(res->stateid.data));
3049         COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3050
3051         decode_change_info(xdr, &res->cinfo);
3052
3053         READ_BUF(8);
3054         READ32(res->rflags);
3055         READ32(bmlen);
3056         if (bmlen > 10)
3057                 goto xdr_error;
3058
3059         READ_BUF(bmlen << 2);
3060         p += bmlen;
3061         return decode_delegation(xdr, res);
3062 xdr_error:
3063         printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
3064         return -EIO;
3065 }
3066
3067 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3068 {
3069         uint32_t *p;
3070         int status;
3071
3072         status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3073         if (status)
3074                 return status;
3075         READ_BUF(sizeof(res->stateid.data));
3076         COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3077         return 0;
3078 }
3079
3080 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3081 {
3082         uint32_t *p;
3083         int status;
3084
3085         status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3086         if (status)
3087                 return status;
3088         READ_BUF(sizeof(res->stateid.data));
3089         COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3090         return 0;
3091 }
3092
3093 static int decode_putfh(struct xdr_stream *xdr)
3094 {
3095         return decode_op_hdr(xdr, OP_PUTFH);
3096 }
3097
3098 static int decode_putrootfh(struct xdr_stream *xdr)
3099 {
3100         return decode_op_hdr(xdr, OP_PUTROOTFH);
3101 }
3102
3103 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3104 {
3105         struct kvec *iov = req->rq_rcv_buf.head;
3106         uint32_t *p;
3107         uint32_t count, eof, recvd, hdrlen;
3108         int status;
3109
3110         status = decode_op_hdr(xdr, OP_READ);
3111         if (status)
3112                 return status;
3113         READ_BUF(8);
3114         READ32(eof);
3115         READ32(count);
3116         hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3117         recvd = req->rq_rcv_buf.len - hdrlen;
3118         if (count > recvd) {
3119                 printk(KERN_WARNING "NFS: server cheating in read reply: "
3120                                 "count %u > recvd %u\n", count, recvd);
3121                 count = recvd;
3122                 eof = 0;
3123         }
3124         xdr_read_pages(xdr, count);
3125         res->eof = eof;
3126         res->count = count;
3127         return 0;
3128 }
3129
3130 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3131 {
3132         struct xdr_buf  *rcvbuf = &req->rq_rcv_buf;
3133         struct page     *page = *rcvbuf->pages;
3134         struct kvec     *iov = rcvbuf->head;
3135         unsigned int    nr, pglen = rcvbuf->page_len;
3136         uint32_t        *end, *entry, *p, *kaddr;
3137         uint32_t        len, attrlen;
3138         int             hdrlen, recvd, status;
3139
3140         status = decode_op_hdr(xdr, OP_READDIR);
3141         if (status)
3142                 return status;
3143         READ_BUF(8);
3144         COPYMEM(readdir->verifier.data, 8);
3145         dprintk("%s: verifier = 0x%x%x\n",
3146                         __FUNCTION__,
3147                         ((u32 *)readdir->verifier.data)[0],
3148                         ((u32 *)readdir->verifier.data)[1]);
3149
3150
3151         hdrlen = (char *) p - (char *) iov->iov_base;
3152         recvd = rcvbuf->len - hdrlen;
3153         if (pglen > recvd)
3154                 pglen = recvd;
3155         xdr_read_pages(xdr, pglen);
3156
3157         BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3158         kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3159         end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3160         entry = p;
3161         for (nr = 0; *p++; nr++) {
3162                 if (p + 3 > end)
3163                         goto short_pkt;
3164                 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3165                 p += 2;                 /* cookie */
3166                 len = ntohl(*p++);      /* filename length */
3167                 if (len > NFS4_MAXNAMLEN) {
3168                         printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3169                         goto err_unmap;
3170                 }
3171                 dprintk("filename = %*s\n", len, (char *)p);
3172                 p += XDR_QUADLEN(len);
3173                 if (p + 1 > end)
3174                         goto short_pkt;
3175                 len = ntohl(*p++);      /* bitmap length */
3176                 p += len;
3177                 if (p + 1 > end)
3178                         goto short_pkt;
3179                 attrlen = XDR_QUADLEN(ntohl(*p++));
3180                 p += attrlen;           /* attributes */
3181                 if (p + 2 > end)
3182                         goto short_pkt;
3183                 entry = p;
3184         }
3185         if (!nr && (entry[0] != 0 || entry[1] == 0))
3186                 goto short_pkt;
3187 out:    
3188         kunmap_atomic(kaddr, KM_USER0);
3189         return 0;
3190 short_pkt:
3191         dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3192         entry[0] = entry[1] = 0;
3193         /* truncate listing ? */
3194         if (!nr) {
3195                 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3196                 entry[1] = 1;
3197         }
3198         goto out;
3199 err_unmap:
3200         kunmap_atomic(kaddr, KM_USER0);
3201         return -errno_NFSERR_IO;
3202 }
3203
3204 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3205 {
3206         struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3207         struct kvec *iov = rcvbuf->head;
3208         int hdrlen, len, recvd;
3209         uint32_t *p;
3210         char *kaddr;
3211         int status;
3212
3213         status = decode_op_hdr(xdr, OP_READLINK);
3214         if (status)
3215                 return status;
3216
3217         /* Convert length of symlink */
3218         READ_BUF(4);
3219         READ32(len);
3220         if (len >= rcvbuf->page_len || len <= 0) {
3221                 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3222                 return -ENAMETOOLONG;
3223         }
3224         hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3225         recvd = req->rq_rcv_buf.len - hdrlen;
3226         if (recvd < len) {
3227                 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3228                                 "count %u > recvd %u\n", len, recvd);
3229                 return -EIO;
3230         }
3231         xdr_read_pages(xdr, len);
3232         /*
3233          * The XDR encode routine has set things up so that
3234          * the link text will be copied directly into the
3235          * buffer.  We just have to do overflow-checking,
3236          * and and null-terminate the text (the VFS expects
3237          * null-termination).
3238          */
3239         kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3240         kaddr[len+rcvbuf->page_base] = '\0';
3241         kunmap_atomic(kaddr, KM_USER0);
3242         return 0;
3243 }
3244
3245 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3246 {
3247         int status;
3248
3249         status = decode_op_hdr(xdr, OP_REMOVE);
3250         if (status)
3251                 goto out;
3252         status = decode_change_info(xdr, cinfo);
3253 out:
3254         return status;
3255 }
3256
3257 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3258               struct nfs4_change_info *new_cinfo)
3259 {
3260         int status;
3261
3262         status = decode_op_hdr(xdr, OP_RENAME);
3263         if (status)
3264                 goto out;
3265         if ((status = decode_change_info(xdr, old_cinfo)))
3266                 goto out;
3267         status = decode_change_info(xdr, new_cinfo);
3268 out:
3269         return status;
3270 }
3271
3272 static int decode_renew(struct xdr_stream *xdr)
3273 {
3274         return decode_op_hdr(xdr, OP_RENEW);
3275 }
3276
3277 static int
3278 decode_restorefh(struct xdr_stream *xdr)
3279 {
3280         return decode_op_hdr(xdr, OP_RESTOREFH);
3281 }
3282
3283 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3284                 size_t *acl_len)
3285 {
3286         uint32_t *savep;
3287         uint32_t attrlen,
3288                  bitmap[2] = {0};
3289         struct kvec *iov = req->rq_rcv_buf.head;
3290         int status;
3291
3292         *acl_len = 0;
3293         if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3294                 goto out;
3295         if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3296                 goto out;
3297         if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3298                 goto out;
3299
3300         if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3301                 return -EIO;
3302         if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3303                 int hdrlen, recvd;
3304
3305                 /* We ignore &savep and don't do consistency checks on
3306                  * the attr length.  Let userspace figure it out.... */
3307                 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3308                 recvd = req->rq_rcv_buf.len - hdrlen;
3309                 if (attrlen > recvd) {
3310                         printk(KERN_WARNING "NFS: server cheating in getattr"
3311                                         " acl reply: attrlen %u > recvd %u\n",
3312                                         attrlen, recvd);
3313                         return -EINVAL;
3314                 }
3315                 if (attrlen <= *acl_len)
3316                         xdr_read_pages(xdr, attrlen);
3317                 *acl_len = attrlen;
3318         } else
3319                 status = -EOPNOTSUPP;
3320
3321 out:
3322         return status;
3323 }
3324
3325 static int
3326 decode_savefh(struct xdr_stream *xdr)
3327 {
3328         return decode_op_hdr(xdr, OP_SAVEFH);
3329 }
3330
3331 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3332 {
3333         uint32_t *p;
3334         uint32_t bmlen;
3335         int status;
3336
3337         
3338         status = decode_op_hdr(xdr, OP_SETATTR);
3339         if (status)
3340                 return status;
3341         READ_BUF(4);
3342         READ32(bmlen);
3343         READ_BUF(bmlen << 2);
3344         return 0;
3345 }
3346
3347 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3348 {
3349         uint32_t *p;
3350         uint32_t opnum;
3351         int32_t nfserr;
3352
3353         READ_BUF(8);
3354         READ32(opnum);
3355         if (opnum != OP_SETCLIENTID) {
3356                 printk(KERN_NOTICE
3357                                 "nfs4_decode_setclientid: Server returned operation"
3358                                 " %d\n", opnum);
3359                 return -EIO;
3360         }
3361         READ32(nfserr);
3362         if (nfserr == NFS_OK) {
3363                 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3364                 READ64(clp->cl_clientid);
3365                 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3366         } else if (nfserr == NFSERR_CLID_INUSE) {
3367                 uint32_t len;
3368
3369                 /* skip netid string */
3370                 READ_BUF(4);
3371                 READ32(len);
3372                 READ_BUF(len);
3373
3374                 /* skip uaddr string */
3375                 READ_BUF(4);
3376                 READ32(len);
3377                 READ_BUF(len);
3378                 return -NFSERR_CLID_INUSE;
3379         } else
3380                 return -nfs_stat_to_errno(nfserr);
3381
3382         return 0;
3383 }
3384
3385 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3386 {
3387         return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3388 }
3389
3390 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3391 {
3392         uint32_t *p;
3393         int status;
3394
3395         status = decode_op_hdr(xdr, OP_WRITE);
3396         if (status)
3397                 return status;
3398
3399         READ_BUF(16);
3400         READ32(res->count);
3401         READ32(res->verf->committed);
3402         COPYMEM(res->verf->verifier, 8);
3403         return 0;
3404 }
3405
3406 static int decode_delegreturn(struct xdr_stream *xdr)
3407 {
3408         return decode_op_hdr(xdr, OP_DELEGRETURN);
3409 }
3410
3411 /*
3412  * Decode OPEN_DOWNGRADE response
3413  */
3414 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3415 {
3416         struct xdr_stream xdr;
3417         struct compound_hdr hdr;
3418         int status;
3419
3420         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3421         status = decode_compound_hdr(&xdr, &hdr);
3422         if (status)
3423                 goto out;
3424         status = decode_putfh(&xdr);
3425         if (status)
3426                 goto out;
3427         status = decode_open_downgrade(&xdr, res);
3428         if (status != 0)
3429                 goto out;
3430         decode_getfattr(&xdr, res->fattr, res->server);
3431 out:
3432         return status;
3433 }
3434
3435 /*
3436  * END OF "GENERIC" DECODE ROUTINES.
3437  */
3438
3439 /*
3440  * Decode ACCESS response
3441  */
3442 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3443 {
3444         struct xdr_stream xdr;
3445         struct compound_hdr hdr;
3446         int status;
3447         
3448         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3449         if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3450                 goto out;
3451         if ((status = decode_putfh(&xdr)) == 0)
3452                 status = decode_access(&xdr, res);
3453 out:
3454         return status;
3455 }
3456
3457 /*
3458  * Decode LOOKUP response
3459  */
3460 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3461 {
3462         struct xdr_stream xdr;
3463         struct compound_hdr hdr;
3464         int status;
3465         
3466         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3467         if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3468                 goto out;
3469         if ((status = decode_putfh(&xdr)) != 0)
3470                 goto out;
3471         if ((status = decode_lookup(&xdr)) != 0)
3472                 goto out;
3473         if ((status = decode_getfh(&xdr, res->fh)) != 0)
3474                 goto out;
3475         status = decode_getfattr(&xdr, res->fattr, res->server);
3476 out:
3477         return status;
3478 }
3479
3480 /*
3481  * Decode LOOKUP_ROOT response
3482  */
3483 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3484 {
3485         struct xdr_stream xdr;
3486         struct compound_hdr hdr;
3487         int status;
3488         
3489         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3490         if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3491                 goto out;
3492         if ((status = decode_putrootfh(&xdr)) != 0)
3493                 goto out;
3494         if ((status = decode_getfh(&xdr, res->fh)) == 0)
3495                 status = decode_getfattr(&xdr, res->fattr, res->server);
3496 out:
3497         return status;
3498 }
3499
3500 /*
3501  * Decode REMOVE response
3502  */
3503 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
3504 {
3505         struct xdr_stream xdr;
3506         struct compound_hdr hdr;
3507         int status;
3508         
3509         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3510         if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3511                 goto out;
3512         if ((status = decode_putfh(&xdr)) == 0)
3513                 status = decode_remove(&xdr, cinfo);
3514 out:
3515         return status;
3516 }
3517
3518 /*
3519  * Decode RENAME response
3520  */
3521 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3522 {
3523         struct xdr_stream xdr;
3524         struct compound_hdr hdr;
3525         int status;
3526         
3527         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3528         if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3529                 goto out;
3530         if ((status = decode_putfh(&xdr)) != 0)
3531                 goto out;
3532         if ((status = decode_savefh(&xdr)) != 0)
3533                 goto out;
3534         if ((status = decode_putfh(&xdr)) != 0)
3535                 goto out;
3536         status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
3537 out:
3538         return status;
3539 }
3540
3541 /*
3542  * Decode LINK response
3543  */
3544 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_link_res *res)
3545 {
3546         struct xdr_stream xdr;
3547         struct compound_hdr hdr;
3548         int status;
3549         
3550         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3551         if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3552                 goto out;
3553         if ((status = decode_putfh(&xdr)) != 0)
3554                 goto out;
3555         if ((status = decode_savefh(&xdr)) != 0)
3556                 goto out;
3557         if ((status = decode_putfh(&xdr)) != 0)
3558                 goto out;
3559         if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3560                 goto out;
3561         /*
3562          * Note order: OP_LINK leaves the directory as the current
3563          *             filehandle.
3564          */
3565         if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3566                 goto out;
3567         if ((status = decode_restorefh(&xdr)) != 0)
3568                 goto out;
3569         decode_getfattr(&xdr, res->fattr, res->server);
3570 out:
3571         return status;
3572 }
3573
3574 /*
3575  * Decode CREATE response
3576  */
3577 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3578 {
3579         struct xdr_stream xdr;
3580         struct compound_hdr hdr;
3581         int status;
3582         
3583         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3584         if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3585                 goto out;
3586         if ((status = decode_putfh(&xdr)) != 0)
3587                 goto out;
3588         if ((status = decode_savefh(&xdr)) != 0)
3589                 goto out;
3590         if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3591                 goto out;
3592         if ((status = decode_getfh(&xdr, res->fh)) != 0)
3593                 goto out;
3594         if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3595                 goto out;
3596         if ((status = decode_restorefh(&xdr)) != 0)
3597                 goto out;
3598         decode_getfattr(&xdr, res->dir_fattr, res->server);
3599 out:
3600         return status;
3601 }
3602
3603 /*
3604  * Decode SYMLINK response
3605  */
3606 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3607 {
3608         return nfs4_xdr_dec_create(rqstp, p, res);
3609 }
3610
3611 /*
3612  * Decode GETATTR response
3613  */
3614 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3615 {
3616         struct xdr_stream xdr;
3617         struct compound_hdr hdr;
3618         int status;
3619         
3620         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3621         status = decode_compound_hdr(&xdr, &hdr);
3622         if (status)
3623                 goto out;
3624         status = decode_putfh(&xdr);
3625         if (status)
3626                 goto out;
3627         status = decode_getfattr(&xdr, res->fattr, res->server);
3628 out:
3629         return status;
3630
3631 }
3632
3633 /*
3634  * Encode an SETACL request
3635  */
3636 static int
3637 nfs4_xdr_enc_setacl(struct rpc_rqst *req, uint32_t *p, struct nfs_setaclargs *args)
3638 {
3639         struct xdr_stream xdr;
3640         struct compound_hdr hdr = {
3641                 .nops   = 2,
3642         };
3643         int status;
3644
3645         xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3646         encode_compound_hdr(&xdr, &hdr);
3647         status = encode_putfh(&xdr, args->fh);
3648         if (status)
3649                 goto out;
3650         status = encode_setacl(&xdr, args);
3651 out:
3652         return status;
3653 }
3654 /*
3655  * Decode SETACL response
3656  */
3657 static int
3658 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3659 {
3660         struct xdr_stream xdr;
3661         struct compound_hdr hdr;
3662         int status;
3663
3664         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3665         status = decode_compound_hdr(&xdr, &hdr);
3666         if (status)
3667                 goto out;
3668         status = decode_putfh(&xdr);
3669         if (status)
3670                 goto out;
3671         status = decode_setattr(&xdr, res);
3672 out:
3673         return status;
3674 }
3675
3676 /*
3677  * Decode GETACL response
3678  */
3679 static int
3680 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len)
3681 {
3682         struct xdr_stream xdr;
3683         struct compound_hdr hdr;
3684         int status;
3685
3686         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3687         status = decode_compound_hdr(&xdr, &hdr);
3688         if (status)
3689                 goto out;
3690         status = decode_putfh(&xdr);
3691         if (status)
3692                 goto out;
3693         status = decode_getacl(&xdr, rqstp, acl_len);
3694
3695 out:
3696         return status;
3697 }
3698
3699 /*
3700  * Decode CLOSE response
3701  */
3702 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3703 {
3704         struct xdr_stream xdr;
3705         struct compound_hdr hdr;
3706         int status;
3707
3708         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3709         status = decode_compound_hdr(&xdr, &hdr);
3710         if (status)
3711                 goto out;
3712         status = decode_putfh(&xdr);
3713         if (status)
3714                 goto out;
3715         status = decode_close(&xdr, res);
3716         if (status != 0)
3717                 goto out;
3718         /*
3719          * Note: Server may do delete on close for this file
3720          *      in which case the getattr call will fail with
3721          *      an ESTALE error. Shouldn't be a problem,
3722          *      though, since fattr->valid will remain unset.
3723          */
3724         decode_getfattr(&xdr, res->fattr, res->server);
3725 out:
3726         return status;
3727 }
3728
3729 /*
3730  * Decode OPEN response
3731  */
3732 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3733 {
3734         struct xdr_stream xdr;
3735         struct compound_hdr hdr;
3736         int status;
3737
3738         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3739         status = decode_compound_hdr(&xdr, &hdr);
3740         if (status)
3741                 goto out;
3742         status = decode_putfh(&xdr);
3743         if (status)
3744                 goto out;
3745         status = decode_savefh(&xdr);
3746         if (status)
3747                 goto out;
3748         status = decode_open(&xdr, res);
3749         if (status)
3750                 goto out;
3751         status = decode_getfh(&xdr, &res->fh);
3752         if (status)
3753                 goto out;
3754         if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
3755                 goto out;
3756         if ((status = decode_restorefh(&xdr)) != 0)
3757                 goto out;
3758         decode_getfattr(&xdr, res->dir_attr, res->server);
3759 out:
3760         return status;
3761 }
3762
3763 /*
3764  * Decode OPEN_CONFIRM response
3765  */
3766 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3767 {
3768         struct xdr_stream xdr;
3769         struct compound_hdr hdr;
3770         int status;
3771
3772         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3773         status = decode_compound_hdr(&xdr, &hdr);
3774         if (status)
3775                 goto out;
3776         status = decode_putfh(&xdr);
3777         if (status)
3778                 goto out;
3779         status = decode_open_confirm(&xdr, res);
3780 out:
3781         return status;
3782 }
3783
3784 /*
3785  * Decode OPEN response
3786  */
3787 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3788 {
3789         struct xdr_stream xdr;
3790         struct compound_hdr hdr;
3791         int status;
3792
3793         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3794         status = decode_compound_hdr(&xdr, &hdr);
3795         if (status)
3796                 goto out;
3797         status = decode_putfh(&xdr);
3798         if (status)
3799                 goto out;
3800         status = decode_open(&xdr, res);
3801 out:
3802         return status;
3803 }
3804
3805 /*
3806  * Decode SETATTR response
3807  */
3808 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3809 {
3810         struct xdr_stream xdr;
3811         struct compound_hdr hdr;
3812         int status;
3813
3814         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3815         status = decode_compound_hdr(&xdr, &hdr);
3816         if (status)
3817                 goto out;
3818         status = decode_putfh(&xdr);
3819         if (status)
3820                 goto out;
3821         status = decode_setattr(&xdr, res);
3822         if (status)
3823                 goto out;
3824         status = decode_getfattr(&xdr, res->fattr, res->server);
3825         if (status == NFS4ERR_DELAY)
3826                 status = 0;
3827 out:
3828         return status;
3829 }
3830
3831 /*
3832  * Decode LOCK response
3833  */
3834 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3835 {
3836         struct xdr_stream xdr;
3837         struct compound_hdr hdr;
3838         int status;
3839
3840         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3841         status = decode_compound_hdr(&xdr, &hdr);
3842         if (status)
3843                 goto out;
3844         status = decode_putfh(&xdr);
3845         if (status)
3846                 goto out;
3847         status = decode_lock(&xdr, res);
3848 out:
3849         return status;
3850 }
3851
3852 /*
3853  * Decode LOCKT response
3854  */
3855 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3856 {
3857         struct xdr_stream xdr;
3858         struct compound_hdr hdr;
3859         int status;
3860
3861         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3862         status = decode_compound_hdr(&xdr, &hdr);
3863         if (status)
3864                 goto out;
3865         status = decode_putfh(&xdr);
3866         if (status)
3867                 goto out;
3868         status = decode_lockt(&xdr, res);
3869 out:
3870         return status;
3871 }
3872
3873 /*
3874  * Decode LOCKU response
3875  */
3876 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3877 {
3878         struct xdr_stream xdr;
3879         struct compound_hdr hdr;
3880         int status;
3881
3882         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3883         status = decode_compound_hdr(&xdr, &hdr);
3884         if (status)
3885                 goto out;
3886         status = decode_putfh(&xdr);
3887         if (status)
3888                 goto out;
3889         status = decode_locku(&xdr, res);
3890 out:
3891         return status;
3892 }
3893
3894 /*
3895  * Decode READLINK response
3896  */
3897 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3898 {
3899         struct xdr_stream xdr;
3900         struct compound_hdr hdr;
3901         int status;
3902
3903         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3904         status = decode_compound_hdr(&xdr, &hdr);
3905         if (status)
3906                 goto out;
3907         status = decode_putfh(&xdr);
3908         if (status)
3909                 goto out;
3910         status = decode_readlink(&xdr, rqstp);
3911 out:
3912         return status;
3913 }
3914
3915 /*
3916  * Decode READDIR response
3917  */
3918 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3919 {
3920         struct xdr_stream xdr;
3921         struct compound_hdr hdr;
3922         int status;
3923
3924         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3925         status = decode_compound_hdr(&xdr, &hdr);
3926         if (status)
3927                 goto out;
3928         status = decode_putfh(&xdr);
3929         if (status)
3930                 goto out;
3931         status = decode_readdir(&xdr, rqstp, res);
3932 out:
3933         return status;
3934 }
3935
3936 /*
3937  * Decode Read response
3938  */
3939 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3940 {
3941         struct xdr_stream xdr;
3942         struct compound_hdr hdr;
3943         int status;
3944
3945         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3946         status = decode_compound_hdr(&xdr, &hdr);
3947         if (status)
3948                 goto out;
3949         status = decode_putfh(&xdr);
3950         if (status)
3951                 goto out;
3952         status = decode_read(&xdr, rqstp, res);
3953         if (!status)
3954                 status = res->count;
3955 out:
3956         return status;
3957 }
3958
3959 /*
3960  * Decode WRITE response
3961  */
3962 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3963 {
3964         struct xdr_stream xdr;
3965         struct compound_hdr hdr;
3966         int status;
3967
3968         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3969         status = decode_compound_hdr(&xdr, &hdr);
3970         if (status)
3971                 goto out;
3972         status = decode_putfh(&xdr);
3973         if (status)
3974                 goto out;
3975         status = decode_write(&xdr, res);
3976         if (!status)
3977                 status = res->count;
3978 out:
3979         return status;
3980 }
3981
3982 /*
3983  * Decode COMMIT response
3984  */
3985 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
3986 {
3987         struct xdr_stream xdr;
3988         struct compound_hdr hdr;
3989         int status;
3990
3991         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3992         status = decode_compound_hdr(&xdr, &hdr);
3993         if (status)
3994                 goto out;
3995         status = decode_putfh(&xdr);
3996         if (status)
3997                 goto out;
3998         status = decode_commit(&xdr, res);
3999 out:
4000         return status;
4001 }
4002
4003 /*
4004  * FSINFO request
4005  */
4006 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
4007 {
4008         struct xdr_stream xdr;
4009         struct compound_hdr hdr;
4010         int status;
4011
4012         xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4013         status = decode_compound_hdr(&xdr, &hdr);
4014         if (!status)
4015                 status = decode_putfh(&xdr);
4016         if (!status)
4017                 status = decode_fsinfo(&xdr, fsinfo);
4018         if (!status)
4019                 status = -nfs_stat_to_errno(hdr.status);
4020         return status;
4021 }
4022
4023 /*
4024  * PATHCONF request
4025  */
4026 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
4027 {
4028         struct xdr_stream xdr;
4029         struct compound_hdr hdr;
4030         int status;
4031
4032         xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4033         status = decode_compound_hdr(&xdr, &hdr);
4034         if (!status)
4035                 status = decode_putfh(&xdr);
4036         if (!status)
4037                 status = decode_pathconf(&xdr, pathconf);
4038         return status;
4039 }
4040
4041 /*
4042  * STATFS request
4043  */
4044 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
4045 {
4046         struct xdr_stream xdr;
4047         struct compound_hdr hdr;
4048         int status;
4049
4050         xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4051         status = decode_compound_hdr(&xdr, &hdr);
4052         if (!status)
4053                 status = decode_putfh(&xdr);
4054         if (!status)
4055                 status = decode_statfs(&xdr, fsstat);
4056         return status;
4057 }
4058
4059 /*
4060  * GETATTR_BITMAP request
4061  */
4062 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
4063 {
4064         struct xdr_stream xdr;
4065         struct compound_hdr hdr;
4066         int status;
4067
4068         xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4069         if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4070                 goto out;
4071         if ((status = decode_putfh(&xdr)) != 0)
4072                 goto out;
4073         status = decode_server_caps(&xdr, res);
4074 out:
4075         return status;
4076 }
4077
4078 /*
4079  * Decode RENEW response
4080  */
4081 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
4082 {
4083         struct xdr_stream xdr;
4084         struct compound_hdr hdr;
4085         int status;
4086
4087         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4088         status = decode_compound_hdr(&xdr, &hdr);
4089         if (!status)
4090                 status = decode_renew(&xdr);
4091         return status;
4092 }
4093
4094 /*
4095  * a SETCLIENTID request
4096  */
4097 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
4098                 struct nfs4_client *clp)
4099 {
4100         struct xdr_stream xdr;
4101         struct compound_hdr hdr;
4102         int status;
4103
4104         xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4105         status = decode_compound_hdr(&xdr, &hdr);
4106         if (!status)
4107                 status = decode_setclientid(&xdr, clp);
4108         if (!status)
4109                 status = -nfs_stat_to_errno(hdr.status);
4110         return status;
4111 }
4112
4113 /*
4114  * a SETCLIENTID_CONFIRM request
4115  */
4116 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
4117 {
4118         struct xdr_stream xdr;
4119         struct compound_hdr hdr;
4120         int status;
4121
4122         xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4123         status = decode_compound_hdr(&xdr, &hdr);
4124         if (!status)
4125                 status = decode_setclientid_confirm(&xdr);
4126         if (!status)
4127                 status = decode_putrootfh(&xdr);
4128         if (!status)
4129                 status = decode_fsinfo(&xdr, fsinfo);
4130         if (!status)
4131                 status = -nfs_stat_to_errno(hdr.status);
4132         return status;
4133 }
4134
4135 /*
4136  * DELEGRETURN request
4137  */
4138 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
4139 {
4140         struct xdr_stream xdr;
4141         struct compound_hdr hdr;
4142         int status;
4143
4144         xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4145         status = decode_compound_hdr(&xdr, &hdr);
4146         if (status == 0) {
4147                 status = decode_putfh(&xdr);
4148                 if (status == 0)
4149                         status = decode_delegreturn(&xdr);
4150         }
4151         return status;
4152 }
4153
4154 uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
4155 {
4156         uint32_t bitmap[2] = {0};
4157         uint32_t len;
4158
4159         if (!*p++) {
4160                 if (!*p)
4161                         return ERR_PTR(-EAGAIN);
4162                 entry->eof = 1;
4163                 return ERR_PTR(-EBADCOOKIE);
4164         }
4165
4166         entry->prev_cookie = entry->cookie;
4167         p = xdr_decode_hyper(p, &entry->cookie);
4168         entry->len = ntohl(*p++);
4169         entry->name = (const char *) p;
4170         p += XDR_QUADLEN(entry->len);
4171
4172         /*
4173          * In case the server doesn't return an inode number,
4174          * we fake one here.  (We don't use inode number 0,
4175          * since glibc seems to choke on it...)
4176          */
4177         entry->ino = 1;
4178
4179         len = ntohl(*p++);              /* bitmap length */
4180         if (len-- > 0) {
4181                 bitmap[0] = ntohl(*p++);
4182                 if (len-- > 0) {
4183                         bitmap[1] = ntohl(*p++);
4184                         p += len;
4185                 }
4186         }
4187         len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4188         if (len > 0) {
4189                 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4190                         bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4191                         /* Ignore the return value of rdattr_error for now */
4192                         p++;
4193                         len--;
4194                 }
4195                 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4196                         xdr_decode_hyper(p, &entry->ino);
4197                 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4198                         xdr_decode_hyper(p, &entry->ino);
4199                 p += len;
4200         }
4201
4202         entry->eof = !p[0] && p[1];
4203         return p;
4204 }
4205
4206 /*
4207  * We need to translate between nfs status return values and
4208  * the local errno values which may not be the same.
4209  */
4210 static struct {
4211         int stat;
4212         int errno;
4213 } nfs_errtbl[] = {
4214         { NFS4_OK,              0               },
4215         { NFS4ERR_PERM,         EPERM           },
4216         { NFS4ERR_NOENT,        ENOENT          },
4217         { NFS4ERR_IO,           errno_NFSERR_IO },
4218         { NFS4ERR_NXIO,         ENXIO           },
4219         { NFS4ERR_ACCESS,       EACCES          },
4220         { NFS4ERR_EXIST,        EEXIST          },
4221         { NFS4ERR_XDEV,         EXDEV           },
4222         { NFS4ERR_NOTDIR,       ENOTDIR         },
4223         { NFS4ERR_ISDIR,        EISDIR          },
4224         { NFS4ERR_INVAL,        EINVAL          },
4225         { NFS4ERR_FBIG,         EFBIG           },
4226         { NFS4ERR_NOSPC,        ENOSPC          },
4227         { NFS4ERR_ROFS,         EROFS           },
4228         { NFS4ERR_MLINK,        EMLINK          },
4229         { NFS4ERR_NAMETOOLONG,  ENAMETOOLONG    },
4230         { NFS4ERR_NOTEMPTY,     ENOTEMPTY       },
4231         { NFS4ERR_DQUOT,        EDQUOT          },
4232         { NFS4ERR_STALE,        ESTALE          },
4233         { NFS4ERR_BADHANDLE,    EBADHANDLE      },
4234         { NFS4ERR_BADOWNER,     EINVAL          },
4235         { NFS4ERR_BADNAME,      EINVAL          },
4236         { NFS4ERR_BAD_COOKIE,   EBADCOOKIE      },
4237         { NFS4ERR_NOTSUPP,      ENOTSUPP        },
4238         { NFS4ERR_TOOSMALL,     ETOOSMALL       },
4239         { NFS4ERR_SERVERFAULT,  ESERVERFAULT    },
4240         { NFS4ERR_BADTYPE,      EBADTYPE        },
4241         { NFS4ERR_LOCKED,       EAGAIN          },
4242         { NFS4ERR_RESOURCE,     EREMOTEIO       },
4243         { NFS4ERR_SYMLINK,      ELOOP           },
4244         { NFS4ERR_OP_ILLEGAL,   EOPNOTSUPP      },
4245         { NFS4ERR_DEADLOCK,     EDEADLK         },
4246         { NFS4ERR_WRONGSEC,     EPERM           }, /* FIXME: this needs
4247                                                     * to be handled by a
4248                                                     * middle-layer.
4249                                                     */
4250         { -1,                   EIO             }
4251 };
4252
4253 /*
4254  * Convert an NFS error code to a local one.
4255  * This one is used jointly by NFSv2 and NFSv3.
4256  */
4257 static int
4258 nfs_stat_to_errno(int stat)
4259 {
4260         int i;
4261         for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4262                 if (nfs_errtbl[i].stat == stat)
4263                         return nfs_errtbl[i].errno;
4264         }
4265         if (stat <= 10000 || stat > 10100) {
4266                 /* The server is looney tunes. */
4267                 return ESERVERFAULT;
4268         }
4269         /* If we cannot translate the error, the recovery routines should
4270          * handle it.
4271          * Note: remaining NFSv4 error codes have values > 10000, so should
4272          * not conflict with native Linux error codes.
4273          */
4274         return stat;
4275 }
4276
4277 #ifndef MAX
4278 # define MAX(a, b)      (((a) > (b))? (a) : (b))
4279 #endif
4280
4281 #define PROC(proc, argtype, restype)                            \
4282 [NFSPROC4_CLNT_##proc] = {                                      \
4283         .p_proc   = NFSPROC4_COMPOUND,                          \
4284         .p_encode = (kxdrproc_t) nfs4_xdr_##argtype,            \
4285         .p_decode = (kxdrproc_t) nfs4_xdr_##restype,            \
4286         .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2,  \
4287     }
4288
4289 struct rpc_procinfo     nfs4_procedures[] = {
4290   PROC(READ,            enc_read,       dec_read),
4291   PROC(WRITE,           enc_write,      dec_write),
4292   PROC(COMMIT,          enc_commit,     dec_commit),
4293   PROC(OPEN,            enc_open,       dec_open),
4294   PROC(OPEN_CONFIRM,    enc_open_confirm,       dec_open_confirm),
4295   PROC(OPEN_NOATTR,     enc_open_noattr,        dec_open_noattr),
4296   PROC(OPEN_DOWNGRADE,  enc_open_downgrade,     dec_open_downgrade),
4297   PROC(CLOSE,           enc_close,      dec_close),
4298   PROC(SETATTR,         enc_setattr,    dec_setattr),
4299   PROC(FSINFO,          enc_fsinfo,     dec_fsinfo),
4300   PROC(RENEW,           enc_renew,      dec_renew),
4301   PROC(SETCLIENTID,     enc_setclientid,        dec_setclientid),
4302   PROC(SETCLIENTID_CONFIRM,     enc_setclientid_confirm,        dec_setclientid_confirm),
4303   PROC(LOCK,            enc_lock,       dec_lock),
4304   PROC(LOCKT,           enc_lockt,      dec_lockt),
4305   PROC(LOCKU,           enc_locku,      dec_locku),
4306   PROC(ACCESS,          enc_access,     dec_access),
4307   PROC(GETATTR,         enc_getattr,    dec_getattr),
4308   PROC(LOOKUP,          enc_lookup,     dec_lookup),
4309   PROC(LOOKUP_ROOT,     enc_lookup_root,        dec_lookup_root),
4310   PROC(REMOVE,          enc_remove,     dec_remove),
4311   PROC(RENAME,          enc_rename,     dec_rename),
4312   PROC(LINK,            enc_link,       dec_link),
4313   PROC(SYMLINK,         enc_symlink,    dec_symlink),
4314   PROC(CREATE,          enc_create,     dec_create),
4315   PROC(PATHCONF,        enc_pathconf,   dec_pathconf),
4316   PROC(STATFS,          enc_statfs,     dec_statfs),
4317   PROC(READLINK,        enc_readlink,   dec_readlink),
4318   PROC(READDIR,         enc_readdir,    dec_readdir),
4319   PROC(SERVER_CAPS,     enc_server_caps, dec_server_caps),
4320   PROC(DELEGRETURN,     enc_delegreturn, dec_delegreturn),
4321   PROC(GETACL,          enc_getacl,     dec_getacl),
4322   PROC(SETACL,          enc_setacl,     dec_setacl),
4323 };
4324
4325 struct rpc_version              nfs_version4 = {
4326         .number                 = 4,
4327         .nrprocs                = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
4328         .procs                  = nfs4_procedures
4329 };
4330
4331 /*
4332  * Local variables:
4333  *  c-basic-offset: 8
4334  * End:
4335  */