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