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