Commit | Line | Data |
---|---|---|
84004dbf RS |
1 | /* |
2 | Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com> | |
3 | ||
4 | This program is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU Lesser General Public License as published by | |
6 | the Free Software Foundation; either version 2.1 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public License | |
15 | along with this program; if not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | ||
a8a1b858 M |
18 | #ifdef WIN32 |
19 | #include "win32_compat.h" | |
20 | #else | |
21 | #include <sys/stat.h> | |
22 | #endif/*WIN32*/ | |
eecdc4f3 | 23 | |
84004dbf RS |
24 | #include <stdio.h> |
25 | #include <errno.h> | |
98f5fee8 | 26 | #include <string.h> |
763cd6e3 | 27 | #include "libnfs-zdr.h" |
84004dbf RS |
28 | #include "libnfs.h" |
29 | #include "libnfs-raw.h" | |
30 | #include "libnfs-private.h" | |
31 | #include "libnfs-raw-nfs.h" | |
32 | ||
84004dbf RS |
33 | char *nfsstat3_to_str(int error) |
34 | { | |
35 | switch (error) { | |
36 | case NFS3_OK: return "NFS3_OK"; break; | |
37 | case NFS3ERR_PERM: return "NFS3ERR_PERM"; break; | |
38 | case NFS3ERR_NOENT: return "NFS3ERR_NOENT"; break; | |
39 | case NFS3ERR_IO: return "NFS3ERR_IO"; break; | |
40 | case NFS3ERR_NXIO: return "NFS3ERR_NXIO"; break; | |
41 | case NFS3ERR_ACCES: return "NFS3ERR_ACCES"; break; | |
42 | case NFS3ERR_EXIST: return "NFS3ERR_EXIST"; break; | |
43 | case NFS3ERR_XDEV: return "NFS3ERR_XDEV"; break; | |
44 | case NFS3ERR_NODEV: return "NFS3ERR_NODEV"; break; | |
45 | case NFS3ERR_NOTDIR: return "NFS3ERR_NOTDIR"; break; | |
46 | case NFS3ERR_ISDIR: return "NFS3ERR_ISDIR"; break; | |
47 | case NFS3ERR_INVAL: return "NFS3ERR_INVAL"; break; | |
48 | case NFS3ERR_FBIG: return "NFS3ERR_FBIG"; break; | |
49 | case NFS3ERR_NOSPC: return "NFS3ERR_NOSPC"; break; | |
50 | case NFS3ERR_ROFS: return "NFS3ERR_ROFS"; break; | |
51 | case NFS3ERR_MLINK: return "NFS3ERR_MLINK"; break; | |
52 | case NFS3ERR_NAMETOOLONG: return "NFS3ERR_NAMETOOLONG"; break; | |
53 | case NFS3ERR_NOTEMPTY: return "NFS3ERR_NOTEMPTY"; break; | |
54 | case NFS3ERR_DQUOT: return "NFS3ERR_DQUOT"; break; | |
55 | case NFS3ERR_STALE: return "NFS3ERR_STALE"; break; | |
56 | case NFS3ERR_REMOTE: return "NFS3ERR_REMOTE"; break; | |
57 | case NFS3ERR_BADHANDLE: return "NFS3ERR_BADHANDLE"; break; | |
58 | case NFS3ERR_NOT_SYNC: return "NFS3ERR_NOT_SYNC"; break; | |
59 | case NFS3ERR_BAD_COOKIE: return "NFS3ERR_BAD_COOKIE"; break; | |
60 | case NFS3ERR_NOTSUPP: return "NFS3ERR_NOTSUPP"; break; | |
61 | case NFS3ERR_TOOSMALL: return "NFS3ERR_TOOSMALL"; break; | |
62 | case NFS3ERR_SERVERFAULT: return "NFS3ERR_SERVERFAULT"; break; | |
63 | case NFS3ERR_BADTYPE: return "NFS3ERR_BADTYPE"; break; | |
64 | case NFS3ERR_JUKEBOX: return "NFS3ERR_JUKEBOX"; break; | |
65 | }; | |
66 | return "unknown nfs error"; | |
67 | } | |
68 | ||
69 | int nfsstat3_to_errno(int error) | |
70 | { | |
71 | switch (error) { | |
72 | case NFS3_OK: return 0; break; | |
73 | case NFS3ERR_PERM: return -EPERM; break; | |
74 | case NFS3ERR_NOENT: return -ENOENT; break; | |
75 | case NFS3ERR_IO: return -EIO; break; | |
76 | case NFS3ERR_NXIO: return -ENXIO; break; | |
77 | case NFS3ERR_ACCES: return -EACCES; break; | |
78 | case NFS3ERR_EXIST: return -EEXIST; break; | |
79 | case NFS3ERR_XDEV: return -EXDEV; break; | |
80 | case NFS3ERR_NODEV: return -ENODEV; break; | |
81 | case NFS3ERR_NOTDIR: return -ENOTDIR; break; | |
82 | case NFS3ERR_ISDIR: return -EISDIR; break; | |
83 | case NFS3ERR_INVAL: return -EINVAL; break; | |
84 | case NFS3ERR_FBIG: return -EFBIG; break; | |
85 | case NFS3ERR_NOSPC: return -ENOSPC; break; | |
86 | case NFS3ERR_ROFS: return -EROFS; break; | |
87 | case NFS3ERR_MLINK: return -EMLINK; break; | |
88 | case NFS3ERR_NAMETOOLONG: return -ENAMETOOLONG; break; | |
89 | case NFS3ERR_NOTEMPTY: return -EEXIST; break; | |
90 | case NFS3ERR_DQUOT: return -ERANGE; break; | |
91 | case NFS3ERR_STALE: return -EIO; break; | |
92 | case NFS3ERR_REMOTE: return -EIO; break; | |
93 | case NFS3ERR_BADHANDLE: return -EIO; break; | |
94 | case NFS3ERR_NOT_SYNC: return -EIO; break; | |
95 | case NFS3ERR_BAD_COOKIE: return -EIO; break; | |
96 | case NFS3ERR_NOTSUPP: return -EINVAL; break; | |
97 | case NFS3ERR_TOOSMALL: return -EIO; break; | |
98 | case NFS3ERR_SERVERFAULT: return -EIO; break; | |
99 | case NFS3ERR_BADTYPE: return -EINVAL; break; | |
100 | case NFS3ERR_JUKEBOX: return -EAGAIN; break; | |
101 | }; | |
102 | return -ERANGE; | |
103 | } | |
104 | ||
105 | ||
106 | int rpc_nfs_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
107 | { | |
108 | struct rpc_pdu *pdu; | |
109 | ||
763cd6e3 | 110 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_NULL, cb, private_data, (zdrproc_t)zdr_void, 0); |
84004dbf RS |
111 | if (pdu == NULL) { |
112 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/null call"); | |
113 | return -1; | |
114 | } | |
115 | ||
116 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
117 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/null call"); | |
118 | rpc_free_pdu(rpc, pdu); | |
119 | return -2; | |
120 | } | |
121 | ||
122 | return 0; | |
123 | } | |
124 | ||
125 | int rpc_nfs_getattr_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data) | |
126 | { | |
127 | struct rpc_pdu *pdu; | |
128 | GETATTR3args args; | |
129 | ||
763cd6e3 | 130 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_GETATTR, cb, private_data, (zdrproc_t)zdr_GETATTR3res, sizeof(GETATTR3res)); |
84004dbf RS |
131 | if (pdu == NULL) { |
132 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/null call"); | |
133 | return -1; | |
134 | } | |
135 | ||
136 | args.object.data.data_len = fh->data.data_len; | |
137 | args.object.data.data_val = fh->data.data_val; | |
138 | ||
763cd6e3 RS |
139 | if (zdr_GETATTR3args(&pdu->zdr, &args) == 0) { |
140 | rpc_set_error(rpc, "ZDR error: Failed to encode GETATTR3args"); | |
84004dbf RS |
141 | rpc_free_pdu(rpc, pdu); |
142 | return -2; | |
143 | } | |
144 | ||
145 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
146 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/null call"); | |
147 | rpc_free_pdu(rpc, pdu); | |
148 | return -3; | |
149 | } | |
150 | ||
151 | return 0; | |
152 | } | |
153 | ||
154 | int rpc_nfs_lookup_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *name, void *private_data) | |
155 | { | |
156 | struct rpc_pdu *pdu; | |
157 | LOOKUP3args args; | |
158 | ||
763cd6e3 | 159 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_LOOKUP, cb, private_data, (zdrproc_t)zdr_LOOKUP3res, sizeof(LOOKUP3res)); |
84004dbf RS |
160 | if (pdu == NULL) { |
161 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/lookup call"); | |
162 | return -1; | |
163 | } | |
164 | ||
165 | args.what.dir.data.data_len = fh->data.data_len; | |
166 | args.what.dir.data.data_val = fh->data.data_val; | |
167 | args.what.name = name; | |
168 | ||
763cd6e3 RS |
169 | if (zdr_LOOKUP3args(&pdu->zdr, &args) == 0) { |
170 | rpc_set_error(rpc, "ZDR error: Failed to encode LOOKUP3args"); | |
84004dbf RS |
171 | rpc_free_pdu(rpc, pdu); |
172 | return -2; | |
173 | } | |
174 | ||
175 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
176 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/lookup call"); | |
177 | rpc_free_pdu(rpc, pdu); | |
178 | return -3; | |
179 | } | |
180 | ||
181 | return 0; | |
182 | } | |
183 | ||
184 | ||
185 | int rpc_nfs_access_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, int access, void *private_data) | |
186 | { | |
187 | struct rpc_pdu *pdu; | |
188 | ACCESS3args args; | |
189 | ||
763cd6e3 | 190 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_ACCESS, cb, private_data, (zdrproc_t)zdr_ACCESS3res, sizeof(ACCESS3res)); |
84004dbf RS |
191 | if (pdu == NULL) { |
192 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/access call"); | |
193 | return -1; | |
194 | } | |
195 | ||
196 | args.object.data.data_len = fh->data.data_len; | |
197 | args.object.data.data_val = fh->data.data_val; | |
198 | args.access = access; | |
199 | ||
763cd6e3 RS |
200 | if (zdr_ACCESS3args(&pdu->zdr, &args) == 0) { |
201 | rpc_set_error(rpc, "ZDR error: Failed to encode ACCESS3args"); | |
84004dbf RS |
202 | rpc_free_pdu(rpc, pdu); |
203 | return -2; | |
204 | } | |
205 | ||
206 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
207 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/access call"); | |
208 | rpc_free_pdu(rpc, pdu); | |
209 | return -3; | |
210 | } | |
211 | ||
212 | return 0; | |
213 | } | |
214 | ||
215 | ||
216 | ||
183451cf | 217 | int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t offset, uint64_t count, void *private_data) |
84004dbf RS |
218 | { |
219 | struct rpc_pdu *pdu; | |
220 | READ3args args; | |
221 | ||
763cd6e3 | 222 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READ, cb, private_data, (zdrproc_t)zdr_READ3res, sizeof(READ3res)); |
84004dbf RS |
223 | if (pdu == NULL) { |
224 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/read call"); | |
225 | return -1; | |
226 | } | |
227 | ||
228 | args.file.data.data_len = fh->data.data_len; | |
229 | args.file.data.data_val = fh->data.data_val; | |
230 | args.offset = offset; | |
231 | args.count = count; | |
232 | ||
763cd6e3 RS |
233 | if (zdr_READ3args(&pdu->zdr, &args) == 0) { |
234 | rpc_set_error(rpc, "ZDR error: Failed to encode READ3args"); | |
84004dbf RS |
235 | rpc_free_pdu(rpc, pdu); |
236 | return -2; | |
237 | } | |
238 | ||
239 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
240 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/read call"); | |
241 | rpc_free_pdu(rpc, pdu); | |
242 | return -3; | |
243 | } | |
244 | ||
245 | return 0; | |
246 | } | |
247 | ||
248 | ||
183451cf | 249 | int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, uint64_t offset, uint64_t count, int stable_how, void *private_data) |
84004dbf RS |
250 | { |
251 | struct rpc_pdu *pdu; | |
252 | WRITE3args args; | |
253 | ||
763cd6e3 | 254 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_WRITE, cb, private_data, (zdrproc_t)zdr_WRITE3res, sizeof(WRITE3res)); |
84004dbf RS |
255 | if (pdu == NULL) { |
256 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/write call"); | |
257 | return -1; | |
258 | } | |
259 | ||
260 | args.file.data.data_len = fh->data.data_len; | |
261 | args.file.data.data_val = fh->data.data_val; | |
262 | args.offset = offset; | |
263 | args.count = count; | |
264 | args.stable = stable_how;; | |
265 | args.data.data_len = count; | |
266 | args.data.data_val = buf; | |
267 | ||
763cd6e3 RS |
268 | if (zdr_WRITE3args(&pdu->zdr, &args) == 0) { |
269 | rpc_set_error(rpc, "ZDR error: Failed to encode WRITE3args"); | |
84004dbf RS |
270 | rpc_free_pdu(rpc, pdu); |
271 | return -2; | |
272 | } | |
273 | ||
274 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
275 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/write call"); | |
276 | rpc_free_pdu(rpc, pdu); | |
277 | return -3; | |
278 | } | |
279 | ||
280 | return 0; | |
281 | } | |
282 | ||
283 | ||
284 | ||
285 | int rpc_nfs_commit_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data) | |
286 | { | |
287 | struct rpc_pdu *pdu; | |
288 | COMMIT3args args; | |
289 | ||
763cd6e3 | 290 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_COMMIT, cb, private_data, (zdrproc_t)zdr_COMMIT3res, sizeof(COMMIT3res)); |
84004dbf RS |
291 | if (pdu == NULL) { |
292 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/commit call"); | |
293 | return -1; | |
294 | } | |
295 | ||
296 | args.file.data.data_len = fh->data.data_len; | |
297 | args.file.data.data_val = fh->data.data_val; | |
298 | args.offset = 0; | |
299 | args.count = 0; | |
300 | ||
763cd6e3 RS |
301 | if (zdr_COMMIT3args(&pdu->zdr, &args) == 0) { |
302 | rpc_set_error(rpc, "ZDR error: Failed to encode WRITE3args"); | |
84004dbf RS |
303 | rpc_free_pdu(rpc, pdu); |
304 | return -2; | |
305 | } | |
306 | ||
307 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
308 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/commit call"); | |
309 | rpc_free_pdu(rpc, pdu); | |
310 | return -3; | |
311 | } | |
312 | ||
313 | return 0; | |
314 | } | |
315 | ||
316 | ||
317 | int rpc_nfs_setattr_async(struct rpc_context *rpc, rpc_cb cb, SETATTR3args *args, void *private_data) | |
318 | { | |
319 | struct rpc_pdu *pdu; | |
320 | ||
763cd6e3 | 321 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_SETATTR, cb, private_data, (zdrproc_t)zdr_SETATTR3res, sizeof(SETATTR3res)); |
84004dbf RS |
322 | if (pdu == NULL) { |
323 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/setattr call"); | |
324 | return -1; | |
325 | } | |
326 | ||
763cd6e3 RS |
327 | if (zdr_SETATTR3args(&pdu->zdr, args) == 0) { |
328 | rpc_set_error(rpc, "ZDR error: Failed to encode SETATTR3args"); | |
84004dbf RS |
329 | rpc_free_pdu(rpc, pdu); |
330 | return -2; | |
331 | } | |
332 | ||
333 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
334 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/setattr call"); | |
335 | rpc_free_pdu(rpc, pdu); | |
336 | return -3; | |
337 | } | |
338 | ||
339 | return 0; | |
340 | } | |
341 | ||
342 | ||
343 | ||
7edc9026 | 344 | int rpc_nfs_mkdir_async(struct rpc_context *rpc, rpc_cb cb, MKDIR3args *args, void *private_data) |
84004dbf RS |
345 | { |
346 | struct rpc_pdu *pdu; | |
84004dbf | 347 | |
763cd6e3 | 348 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_MKDIR, cb, private_data, (zdrproc_t)zdr_MKDIR3res, sizeof(MKDIR3res)); |
84004dbf RS |
349 | if (pdu == NULL) { |
350 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/setattr call"); | |
351 | return -1; | |
352 | } | |
353 | ||
763cd6e3 RS |
354 | if (zdr_MKDIR3args(&pdu->zdr, args) == 0) { |
355 | rpc_set_error(rpc, "ZDR error: Failed to encode MKDIR3args"); | |
84004dbf RS |
356 | rpc_free_pdu(rpc, pdu); |
357 | return -2; | |
358 | } | |
359 | ||
360 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
361 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/mkdir call"); | |
362 | rpc_free_pdu(rpc, pdu); | |
363 | return -3; | |
364 | } | |
365 | ||
366 | return 0; | |
367 | } | |
368 | ||
369 | ||
370 | ||
371 | ||
372 | int rpc_nfs_rmdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *dir, void *private_data) | |
373 | { | |
374 | struct rpc_pdu *pdu; | |
375 | RMDIR3args args; | |
376 | ||
763cd6e3 | 377 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_RMDIR, cb, private_data, (zdrproc_t)zdr_RMDIR3res, sizeof(RMDIR3res)); |
84004dbf RS |
378 | if (pdu == NULL) { |
379 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/rmdir call"); | |
380 | return -1; | |
381 | } | |
382 | ||
ea98629a | 383 | memset(&args, 0, sizeof(RMDIR3args)); |
84004dbf RS |
384 | args.object.dir.data.data_len = fh->data.data_len; |
385 | args.object.dir.data.data_val = fh->data.data_val; | |
386 | args.object.name = dir; | |
387 | ||
763cd6e3 RS |
388 | if (zdr_RMDIR3args(&pdu->zdr, &args) == 0) { |
389 | rpc_set_error(rpc, "ZDR error: Failed to encode RMDIR3args"); | |
84004dbf RS |
390 | rpc_free_pdu(rpc, pdu); |
391 | return -2; | |
392 | } | |
393 | ||
394 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
395 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/rmdir call"); | |
396 | rpc_free_pdu(rpc, pdu); | |
397 | return -3; | |
398 | } | |
399 | ||
400 | return 0; | |
401 | } | |
402 | ||
403 | ||
404 | ||
c985c015 | 405 | int rpc_nfs_create_async(struct rpc_context *rpc, rpc_cb cb, CREATE3args *args, void *private_data) |
84004dbf RS |
406 | { |
407 | struct rpc_pdu *pdu; | |
84004dbf | 408 | |
763cd6e3 | 409 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_CREATE, cb, private_data, (zdrproc_t)zdr_CREATE3res, sizeof(CREATE3res)); |
84004dbf RS |
410 | if (pdu == NULL) { |
411 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/create call"); | |
412 | return -1; | |
413 | } | |
414 | ||
763cd6e3 RS |
415 | if (zdr_CREATE3args(&pdu->zdr, args) == 0) { |
416 | rpc_set_error(rpc, "ZDR error: Failed to encode CREATE3args"); | |
84004dbf RS |
417 | rpc_free_pdu(rpc, pdu); |
418 | return -2; | |
419 | } | |
420 | ||
421 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
422 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/create call"); | |
423 | rpc_free_pdu(rpc, pdu); | |
424 | return -3; | |
425 | } | |
426 | ||
427 | return 0; | |
428 | } | |
429 | ||
430 | ||
431 | ||
1ec6b50a RS |
432 | int rpc_nfs_mknod_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *file, int mode, int major, int minor, void *private_data) |
433 | { | |
434 | struct rpc_pdu *pdu; | |
435 | MKNOD3args args; | |
436 | ||
763cd6e3 | 437 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_MKNOD, cb, private_data, (zdrproc_t)zdr_MKNOD3res, sizeof(MKNOD3res)); |
1ec6b50a RS |
438 | if (pdu == NULL) { |
439 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/mknod call"); | |
440 | return -1; | |
441 | } | |
442 | ||
443 | memset(&args, 0, sizeof(MKNOD3args)); | |
444 | args.where.dir.data.data_len = fh->data.data_len; | |
445 | args.where.dir.data.data_val = fh->data.data_val; | |
446 | args.where.name = file; | |
447 | switch (mode & S_IFMT) { | |
448 | case S_IFCHR: | |
449 | args.what.type = NF3CHR; | |
450 | args.what.mknoddata3_u.chr_device.dev_attributes.mode.set_it = 1; | |
451 | args.what.mknoddata3_u.chr_device.dev_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); | |
452 | args.what.mknoddata3_u.chr_device.spec.specdata1 = major; | |
453 | args.what.mknoddata3_u.chr_device.spec.specdata2 = minor; | |
454 | break; | |
455 | case S_IFBLK: | |
456 | args.what.type = NF3BLK; | |
457 | args.what.mknoddata3_u.blk_device.dev_attributes.mode.set_it = 1; | |
458 | args.what.mknoddata3_u.blk_device.dev_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); | |
459 | args.what.mknoddata3_u.blk_device.spec.specdata1 = major; | |
460 | args.what.mknoddata3_u.blk_device.spec.specdata2 = minor; | |
461 | case S_IFSOCK: | |
462 | args.what.type = NF3SOCK; | |
463 | args.what.mknoddata3_u.sock_attributes.mode.set_it = 1; | |
464 | args.what.mknoddata3_u.sock_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); | |
465 | break; | |
466 | case S_IFIFO: | |
467 | args.what.type = NF3FIFO; | |
468 | args.what.mknoddata3_u.pipe_attributes.mode.set_it = 1; | |
469 | args.what.mknoddata3_u.pipe_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); | |
470 | break; | |
471 | default: | |
472 | rpc_set_error(rpc, "Invalid file type for nfs/mknod call"); | |
473 | rpc_free_pdu(rpc, pdu); | |
474 | return -1; | |
475 | } | |
476 | ||
763cd6e3 RS |
477 | if (zdr_MKNOD3args(&pdu->zdr, &args) == 0) { |
478 | rpc_set_error(rpc, "ZDR error: Failed to encode MKNOD3args"); | |
1ec6b50a RS |
479 | rpc_free_pdu(rpc, pdu); |
480 | return -2; | |
481 | } | |
482 | ||
483 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
484 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/mknod call"); | |
485 | rpc_free_pdu(rpc, pdu); | |
486 | return -3; | |
487 | } | |
488 | ||
489 | return 0; | |
490 | } | |
491 | ||
84004dbf RS |
492 | |
493 | int rpc_nfs_remove_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *file, void *private_data) | |
494 | { | |
495 | struct rpc_pdu *pdu; | |
496 | REMOVE3args args; | |
497 | ||
763cd6e3 | 498 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_REMOVE, cb, private_data, (zdrproc_t)zdr_REMOVE3res, sizeof(REMOVE3res)); |
84004dbf RS |
499 | if (pdu == NULL) { |
500 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/remove call"); | |
501 | return -1; | |
502 | } | |
503 | ||
ea98629a | 504 | memset(&args, 0, sizeof(REMOVE3args)); |
84004dbf RS |
505 | args.object.dir.data.data_len = fh->data.data_len; |
506 | args.object.dir.data.data_val = fh->data.data_val; | |
507 | args.object.name = file; | |
508 | ||
763cd6e3 RS |
509 | if (zdr_REMOVE3args(&pdu->zdr, &args) == 0) { |
510 | rpc_set_error(rpc, "ZDR error: Failed to encode REMOVE3args"); | |
84004dbf RS |
511 | rpc_free_pdu(rpc, pdu); |
512 | return -2; | |
513 | } | |
514 | ||
515 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
516 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/remove call"); | |
517 | rpc_free_pdu(rpc, pdu); | |
518 | return -3; | |
519 | } | |
520 | ||
521 | return 0; | |
522 | } | |
523 | ||
84004dbf RS |
524 | int rpc_nfs_readdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data) |
525 | { | |
526 | struct rpc_pdu *pdu; | |
527 | READDIR3args args; | |
528 | ||
763cd6e3 | 529 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READDIR, cb, private_data, (zdrproc_t)zdr_READDIR3res, sizeof(READDIR3res)); |
84004dbf RS |
530 | if (pdu == NULL) { |
531 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/readdir call"); | |
532 | return -1; | |
533 | } | |
534 | ||
ea98629a | 535 | memset(&args, 0, sizeof(READDIR3args)); |
84004dbf RS |
536 | args.dir.data.data_len = fh->data.data_len; |
537 | args.dir.data.data_val = fh->data.data_val; | |
538 | args.cookie = cookie; | |
539 | memcpy(&args.cookieverf, cookieverf, sizeof(cookieverf3)); | |
540 | args.count = count; | |
541 | ||
763cd6e3 RS |
542 | if (zdr_READDIR3args(&pdu->zdr, &args) == 0) { |
543 | rpc_set_error(rpc, "ZDR error: Failed to encode READDIR3args"); | |
84004dbf RS |
544 | rpc_free_pdu(rpc, pdu); |
545 | return -2; | |
546 | } | |
547 | ||
548 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
549 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/readdir call"); | |
550 | rpc_free_pdu(rpc, pdu); | |
551 | return -3; | |
552 | } | |
553 | ||
554 | return 0; | |
555 | } | |
556 | ||
f390f181 RS |
557 | int rpc_nfs_readdirplus_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data) |
558 | { | |
559 | struct rpc_pdu *pdu; | |
560 | READDIRPLUS3args args; | |
561 | ||
763cd6e3 | 562 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READDIRPLUS, cb, private_data, (zdrproc_t)zdr_READDIRPLUS3res, sizeof(READDIRPLUS3res)); |
f390f181 RS |
563 | if (pdu == NULL) { |
564 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/readdirplus call"); | |
565 | return -1; | |
566 | } | |
567 | ||
ea98629a | 568 | memset(&args, 0, sizeof(READDIRPLUS3args)); |
f390f181 RS |
569 | args.dir.data.data_len = fh->data.data_len; |
570 | args.dir.data.data_val = fh->data.data_val; | |
571 | args.cookie = cookie; | |
572 | memcpy(&args.cookieverf, cookieverf, sizeof(cookieverf3)); | |
573 | args.dircount = count; | |
574 | args.maxcount = count; | |
575 | ||
763cd6e3 RS |
576 | if (zdr_READDIRPLUS3args(&pdu->zdr, &args) == 0) { |
577 | rpc_set_error(rpc, "ZDR error: Failed to encode READDIRPLUS3args"); | |
f390f181 RS |
578 | rpc_free_pdu(rpc, pdu); |
579 | return -2; | |
580 | } | |
581 | ||
582 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
583 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/readdirplus call"); | |
584 | rpc_free_pdu(rpc, pdu); | |
585 | return -3; | |
586 | } | |
587 | ||
588 | return 0; | |
589 | } | |
590 | ||
84004dbf RS |
591 | int rpc_nfs_fsstat_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data) |
592 | { | |
593 | struct rpc_pdu *pdu; | |
594 | FSSTAT3args args; | |
595 | ||
763cd6e3 | 596 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_FSSTAT, cb, private_data, (zdrproc_t)zdr_FSSTAT3res, sizeof(FSSTAT3res)); |
84004dbf RS |
597 | if (pdu == NULL) { |
598 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/fsstat call"); | |
599 | return -1; | |
600 | } | |
601 | ||
602 | args.fsroot.data.data_len = fh->data.data_len; | |
603 | args.fsroot.data.data_val = fh->data.data_val; | |
604 | ||
763cd6e3 RS |
605 | if (zdr_FSSTAT3args(&pdu->zdr, &args) == 0) { |
606 | rpc_set_error(rpc, "ZDR error: Failed to encode FSSTAT3args"); | |
84004dbf RS |
607 | rpc_free_pdu(rpc, pdu); |
608 | return -2; | |
609 | } | |
610 | ||
611 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
612 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/fsstat call"); | |
613 | rpc_free_pdu(rpc, pdu); | |
614 | return -3; | |
615 | } | |
616 | ||
617 | return 0; | |
618 | } | |
619 | ||
1058201e RS |
620 | int rpc_nfs_fsinfo_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data) |
621 | { | |
622 | struct rpc_pdu *pdu; | |
623 | FSINFO3args args; | |
624 | ||
763cd6e3 | 625 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_FSINFO, cb, private_data, (zdrproc_t)zdr_FSINFO3res, sizeof(FSINFO3res)); |
1058201e RS |
626 | if (pdu == NULL) { |
627 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/fsinfo call"); | |
628 | return -1; | |
629 | } | |
630 | ||
631 | args.fsroot.data.data_len = fh->data.data_len; | |
632 | args.fsroot.data.data_val = fh->data.data_val; | |
633 | ||
763cd6e3 RS |
634 | if (zdr_FSINFO3args(&pdu->zdr, &args) == 0) { |
635 | rpc_set_error(rpc, "ZDR error: Failed to encode FSINFO3args"); | |
1058201e RS |
636 | rpc_free_pdu(rpc, pdu); |
637 | return -2; | |
638 | } | |
639 | ||
640 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
641 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/fsinfo call"); | |
642 | rpc_free_pdu(rpc, pdu); | |
643 | return -3; | |
644 | } | |
645 | ||
646 | return 0; | |
647 | } | |
84004dbf | 648 | |
16104b27 | 649 | int rpc_nfs_readlink_async(struct rpc_context *rpc, rpc_cb cb, READLINK3args *args, void *private_data) |
84004dbf RS |
650 | { |
651 | struct rpc_pdu *pdu; | |
84004dbf | 652 | |
763cd6e3 | 653 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READLINK, cb, private_data, (zdrproc_t)zdr_READLINK3res, sizeof(READLINK3res)); |
84004dbf RS |
654 | if (pdu == NULL) { |
655 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/readlink call"); | |
656 | return -1; | |
657 | } | |
658 | ||
763cd6e3 RS |
659 | if (zdr_READLINK3args(&pdu->zdr, args) == 0) { |
660 | rpc_set_error(rpc, "ZDR error: Failed to encode READLINK3args"); | |
84004dbf RS |
661 | rpc_free_pdu(rpc, pdu); |
662 | return -2; | |
663 | } | |
664 | ||
665 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
666 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/readlink call"); | |
667 | rpc_free_pdu(rpc, pdu); | |
668 | return -3; | |
669 | } | |
670 | ||
671 | return 0; | |
672 | } | |
673 | ||
674 | ||
8e255816 | 675 | int rpc_nfs_symlink_async(struct rpc_context *rpc, rpc_cb cb, SYMLINK3args *args, void *private_data) |
84004dbf RS |
676 | { |
677 | struct rpc_pdu *pdu; | |
84004dbf | 678 | |
763cd6e3 | 679 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_SYMLINK, cb, private_data, (zdrproc_t)zdr_SYMLINK3res, sizeof(SYMLINK3res)); |
84004dbf RS |
680 | if (pdu == NULL) { |
681 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/symlink call"); | |
682 | return -1; | |
683 | } | |
684 | ||
763cd6e3 RS |
685 | if (zdr_SYMLINK3args(&pdu->zdr, args) == 0) { |
686 | rpc_set_error(rpc, "ZDR error: Failed to encode SYMLINK3args"); | |
84004dbf RS |
687 | rpc_free_pdu(rpc, pdu); |
688 | return -2; | |
689 | } | |
690 | ||
691 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
692 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/symlink call"); | |
693 | rpc_free_pdu(rpc, pdu); | |
694 | return -3; | |
695 | } | |
696 | ||
697 | return 0; | |
698 | } | |
699 | ||
700 | ||
701 | ||
702 | ||
703 | int rpc_nfs_rename_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *olddir, char *oldname, struct nfs_fh3 *newdir, char *newname, void *private_data) | |
704 | { | |
705 | struct rpc_pdu *pdu; | |
706 | RENAME3args args; | |
707 | ||
763cd6e3 | 708 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_RENAME, cb, private_data, (zdrproc_t)zdr_RENAME3res, sizeof(RENAME3res)); |
84004dbf RS |
709 | if (pdu == NULL) { |
710 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/rename call"); | |
711 | return -1; | |
712 | } | |
713 | ||
ea98629a | 714 | memset(&args, 0, sizeof(RENAME3args)); |
84004dbf RS |
715 | args.from.dir.data.data_len = olddir->data.data_len; |
716 | args.from.dir.data.data_val = olddir->data.data_val; | |
717 | args.from.name = oldname; | |
718 | args.to.dir.data.data_len = newdir->data.data_len; | |
719 | args.to.dir.data.data_val = newdir->data.data_val; | |
720 | args.to.name = newname; | |
721 | ||
763cd6e3 RS |
722 | if (zdr_RENAME3args(&pdu->zdr, &args) == 0) { |
723 | rpc_set_error(rpc, "ZDR error: Failed to encode RENAME3args"); | |
84004dbf RS |
724 | rpc_free_pdu(rpc, pdu); |
725 | return -2; | |
726 | } | |
727 | ||
728 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
729 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/rename call"); | |
730 | rpc_free_pdu(rpc, pdu); | |
731 | return -3; | |
732 | } | |
733 | ||
734 | return 0; | |
735 | } | |
736 | ||
737 | ||
738 | ||
739 | ||
740 | int rpc_nfs_link_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *file, struct nfs_fh3 *newdir, char *newname, void *private_data) | |
741 | { | |
742 | struct rpc_pdu *pdu; | |
743 | LINK3args args; | |
744 | ||
763cd6e3 | 745 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_LINK, cb, private_data, (zdrproc_t)zdr_LINK3res, sizeof(LINK3res)); |
84004dbf RS |
746 | if (pdu == NULL) { |
747 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/link call"); | |
748 | return -1; | |
749 | } | |
750 | ||
ea98629a | 751 | memset(&args, 0, sizeof(LINK3args)); |
84004dbf RS |
752 | args.file.data.data_len = file->data.data_len; |
753 | args.file.data.data_val = file->data.data_val; | |
754 | args.link.dir.data.data_len = newdir->data.data_len; | |
755 | args.link.dir.data.data_val = newdir->data.data_val; | |
756 | args.link.name = newname; | |
757 | ||
763cd6e3 RS |
758 | if (zdr_LINK3args(&pdu->zdr, &args) == 0) { |
759 | rpc_set_error(rpc, "ZDR error: Failed to encode LINK3args"); | |
84004dbf RS |
760 | rpc_free_pdu(rpc, pdu); |
761 | return -2; | |
762 | } | |
763 | ||
764 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
765 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/link call"); | |
766 | rpc_free_pdu(rpc, pdu); | |
767 | return -3; | |
768 | } | |
769 | ||
770 | return 0; | |
771 | } | |
772 | ||
773 | ||
774 | ||
775 |