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