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