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