initial libnfs checkin
[deb_libnfs.git] / include / libnfs-raw.h
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 /*
18 * This is the lowlevel interface to access NFS resources.
19 * Through this interface you have access to the full gamut of nfs and nfs related
20 * protocol as well as the XDR encoded/decoded structures.
21 */
22 #include <stdint.h>
23
24 struct rpc_data {
25 int size;
26 unsigned char *data;
27 };
28
29 struct rpc_context;
30 struct rpc_context *rpc_init_context(void);
31 void rpc_destroy_context(struct rpc_context *rpc);
32
33 struct AUTH;
34 void rpc_set_auth(struct rpc_context *rpc, struct AUTH *auth);
35
36 int rpc_get_fd(struct rpc_context *rpc);
37 int rpc_which_events(struct rpc_context *rpc);
38 int rpc_service(struct rpc_context *rpc, int revents);
39 char *rpc_get_error(struct rpc_context *rpc);
40
41
42 #define RPC_STATUS_SUCCESS 0
43 #define RPC_STATUS_ERROR 1
44 #define RPC_STATUS_CANCEL 2
45
46 typedef void (*rpc_cb)(struct rpc_context *rpc, int status, void *data, void *private_data);
47
48 /*
49 * Async connection to the tcp port at server:port.
50 * Function returns
51 * 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
52 * <0 : An error occured when trying to set up the connection. The callback will not be invoked.
53 *
54 * When the callback is invoked, status indicates the result:
55 * RPC_STATUS_SUCCESS : The tcp connection was successfully established.
56 * data is NULL.
57 * RPC_STATUS_ERROR : The connection failed to establish.
58 * data is the erro string.
59 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
60 * : data is NULL.
61 */
62 int rpc_connect_async(struct rpc_context *rpc, const char *server, int port, rpc_cb cb, void *private_data);
63 /*
64 * When disconnecting a connection in flight. All commands in flight will be called with the callback
65 * and status RPC_STATUS_ERROR. Data will be the error string for the disconnection.
66 */
67 int rpc_disconnect(struct rpc_context *rpc, char *error);
68
69 void rpc_set_error(struct rpc_context *rpc, char *error_string, ...);
70
71
72 /*
73 * PORTMAP FUNCTIONS
74 */
75
76 /*
77 * Call PORTMAPPER/NULL
78 * Function returns
79 * 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
80 * <0 : An error occured when trying to set up the connection. The callback will not be invoked.
81 *
82 * When the callback is invoked, status indicates the result:
83 * RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
84 * data is NULL.
85 * RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
86 * data is the error string.
87 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
88 * data is NULL.
89 */
90 int rpc_pmap_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
91
92
93 /*
94 * Call PORTMAPPER/GETPORT.
95 * Function returns
96 * 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
97 * <0 : An error occured when trying to set up the connection. The callback will not be invoked.
98 *
99 * When the callback is invoked, status indicates the result:
100 * RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
101 * data is a (uint32_t *), containing the port returned.
102 * RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
103 * data is the error string.
104 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
105 * data is NULL.
106 */
107 int rpc_pmap_getport_async(struct rpc_context *rpc, int program, int version, rpc_cb cb, void *private_data);
108
109
110
111 /*
112 * MOUNT FUNCTIONS
113 */
114 char *mountstat3_to_str(int stat);
115 int mountstat3_to_errno(int error);
116
117 /*
118 * Call MOUNT/NULL
119 * Function returns
120 * 0 : The call was initiated. The callback will be invoked when the call completes.
121 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
122 *
123 * When the callback is invoked, status indicates the result:
124 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
125 * data is NULL.
126 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
127 * data is the error string.
128 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
129 * data is NULL.
130 */
131 int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
132
133 /*
134 * Call MOUNT/MNT
135 * Function returns
136 * 0 : The call was initiated. The callback will be invoked when the call completes.
137 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
138 *
139 * When the callback is invoked, status indicates the result:
140 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
141 * data is union mountres3.
142 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
143 * data is the error string.
144 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
145 * data is NULL.
146 */
147 int rpc_mount_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data);
148
149 /*
150 * Call MOUNT/DUMP
151 * Function returns
152 * 0 : The call was initiated. The callback will be invoked when the call completes.
153 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
154 *
155 * When the callback is invoked, status indicates the result:
156 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
157 * data is a mountlist.
158 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
159 * data is the error string.
160 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
161 * data is NULL.
162 */
163 int rpc_mount_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
164
165 /*
166 * Call MOUNT/UMNT
167 * Function returns
168 * 0 : The call was initiated. The callback will be invoked when the call completes.
169 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
170 *
171 * When the callback is invoked, status indicates the result:
172 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
173 * data NULL.
174 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
175 * data is the error string.
176 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
177 * data is NULL.
178 */
179 int rpc_mount_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data);
180
181 /*
182 * Call MOUNT/UMNTALL
183 * Function returns
184 * 0 : The call was initiated. The callback will be invoked when the call completes.
185 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
186 *
187 * When the callback is invoked, status indicates the result:
188 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
189 * data NULL.
190 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
191 * data is the error string.
192 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
193 * data is NULL.
194 */
195 int rpc_mount_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
196
197 /*
198 * Call MOUNT/EXPORT
199 * Function returns
200 * 0 : The call was initiated. The callback will be invoked when the call completes.
201 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
202 *
203 * When the callback is invoked, status indicates the result:
204 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
205 * data is an exports.
206 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
207 * data is the error string.
208 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
209 * data is NULL.
210 */
211 int rpc_mount_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
212
213
214
215
216 /*
217 * NFS FUNCTIONS
218 */
219 struct nfs_fh3;
220 char *nfsstat3_to_str(int error);
221 int nfsstat3_to_errno(int error);
222
223 /*
224 * Call NFS/NULL
225 * Function returns
226 * 0 : The call was initiated. The callback will be invoked when the call completes.
227 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
228 *
229 * When the callback is invoked, status indicates the result:
230 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
231 * data is NULL.
232 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
233 * data is the error string.
234 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
235 * data is NULL.
236 */
237 int rpc_nfs_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
238
239 /*
240 * Call NFS/GETATTR
241 * Function returns
242 * 0 : The call was initiated. The callback will be invoked when the call completes.
243 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
244 *
245 * When the callback is invoked, status indicates the result:
246 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
247 * data is GETATTR3res
248 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
249 * data is the error string.
250 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
251 * data is NULL.
252 */
253 int rpc_nfs_getattr_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data);
254
255 /*
256 * Call NFS/LOOKUP
257 * Function returns
258 * 0 : The call was initiated. The callback will be invoked when the call completes.
259 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
260 *
261 * When the callback is invoked, status indicates the result:
262 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
263 * data is LOOKUP3res
264 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
265 * data is the error string.
266 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
267 * data is NULL.
268 */
269 int rpc_nfs_lookup_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *name, void *private_data);
270
271 /*
272 * Call NFS/ACCESS
273 * Function returns
274 * 0 : The call was initiated. The callback will be invoked when the call completes.
275 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
276 *
277 * When the callback is invoked, status indicates the result:
278 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
279 * data is ACCESS3res
280 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
281 * data is the error string.
282 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
283 * data is NULL.
284 */
285 int rpc_nfs_access_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, int access, void *private_data);
286
287 /*
288 * Call NFS/READ
289 * Function returns
290 * 0 : The call was initiated. The callback will be invoked when the call completes.
291 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
292 *
293 * When the callback is invoked, status indicates the result:
294 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
295 * data is ACCESS3res
296 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
297 * data is the error string.
298 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
299 * data is NULL.
300 */
301 int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, off_t offset, size_t count, void *private_data);
302
303 /*
304 * Call NFS/WRITE
305 * Function returns
306 * 0 : The call was initiated. The callback will be invoked when the call completes.
307 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
308 *
309 * When the callback is invoked, status indicates the result:
310 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
311 * data is WRITE3res *
312 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
313 * data is the error string.
314 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
315 * data is NULL.
316 */
317 int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, off_t offset, size_t count, int stable_how, void *private_data);
318
319 /*
320 * Call NFS/COMMIT
321 * Function returns
322 * 0 : The call was initiated. The callback will be invoked when the call completes.
323 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
324 *
325 * When the callback is invoked, status indicates the result:
326 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
327 * data is COMMIT3res *
328 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
329 * data is the error string.
330 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
331 * data is NULL.
332 */
333 int rpc_nfs_commit_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data);
334
335
336 /*
337 * Call NFS/SETATTR
338 * Function returns
339 * 0 : The call was initiated. The callback will be invoked when the call completes.
340 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
341 *
342 * When the callback is invoked, status indicates the result:
343 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
344 * data is SETATTR3res *
345 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
346 * data is the error string.
347 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
348 * data is NULL.
349 */
350 struct SETATTR3args;
351 int rpc_nfs_setattr_async(struct rpc_context *rpc, rpc_cb cb, struct SETATTR3args *args, void *private_data);
352
353
354
355 /*
356 * Call NFS/MKDIR
357 * Function returns
358 * 0 : The call was initiated. The callback will be invoked when the call completes.
359 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
360 *
361 * When the callback is invoked, status indicates the result:
362 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
363 * data is MKDIR3res *
364 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
365 * data is the error string.
366 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
367 * data is NULL.
368 */
369 int rpc_nfs_mkdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *dir, void *private_data);
370
371
372
373
374
375 /*
376 * Call NFS/RMDIR
377 * Function returns
378 * 0 : The call was initiated. The callback will be invoked when the call completes.
379 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
380 *
381 * When the callback is invoked, status indicates the result:
382 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
383 * data is RMDIR3res *
384 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
385 * data is the error string.
386 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
387 * data is NULL.
388 */
389 int rpc_nfs_rmdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *dir, void *private_data);
390
391
392
393
394 /*
395 * Call NFS/CREATE
396 * Function returns
397 * 0 : The call was initiated. The callback will be invoked when the call completes.
398 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
399 *
400 * When the callback is invoked, status indicates the result:
401 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
402 * data is CREATE3res *
403 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
404 * data is the error string.
405 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
406 * data is NULL.
407 */
408 int rpc_nfs_create_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *name, int mode, void *private_data);
409
410
411
412
413 /*
414 * Call NFS/REMOVE
415 * Function returns
416 * 0 : The call was initiated. The callback will be invoked when the call completes.
417 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
418 *
419 * When the callback is invoked, status indicates the result:
420 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
421 * data is REMOVE3res *
422 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
423 * data is the error string.
424 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
425 * data is NULL.
426 */
427 int rpc_nfs_remove_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *name, void *private_data);
428
429
430
431 /*
432 * Call NFS/REMOVE
433 * Function returns
434 * 0 : The call was initiated. The callback will be invoked when the call completes.
435 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
436 *
437 * When the callback is invoked, status indicates the result:
438 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
439 * data is READDIR3res *
440 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
441 * data is the error string.
442 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
443 * data is NULL.
444 */
445 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);
446
447 /*
448 * Call NFS/FSSTAT
449 * Function returns
450 * 0 : The call was initiated. The callback will be invoked when the call completes.
451 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
452 *
453 * When the callback is invoked, status indicates the result:
454 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
455 * data is FSSTAT3res
456 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
457 * data is the error string.
458 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
459 * data is NULL.
460 */
461 int rpc_nfs_fsstat_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data);
462
463
464
465
466 /*
467 * Call NFS/READLINK
468 * Function returns
469 * 0 : The call was initiated. The callback will be invoked when the call completes.
470 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
471 *
472 * When the callback is invoked, status indicates the result:
473 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
474 * data is READLINK3res *
475 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
476 * data is the error string.
477 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
478 * data is NULL.
479 */
480 int rpc_nfs_readlink_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data);
481
482
483
484 /*
485 * Call NFS/SYMLINK
486 * Function returns
487 * 0 : The call was initiated. The callback will be invoked when the call completes.
488 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
489 *
490 * When the callback is invoked, status indicates the result:
491 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
492 * data is SYMLINK3res *
493 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
494 * data is the error string.
495 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
496 * data is NULL.
497 */
498 int rpc_nfs_symlink_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *newname, char *oldpath, void *private_data);
499
500
501 /*
502 * Call NFS/RENAME
503 * Function returns
504 * 0 : The call was initiated. The callback will be invoked when the call completes.
505 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
506 *
507 * When the callback is invoked, status indicates the result:
508 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
509 * data is RENAME3res *
510 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
511 * data is the error string.
512 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
513 * data is NULL.
514 */
515 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);
516
517
518
519 /*
520 * Call NFS/LINK
521 * Function returns
522 * 0 : The call was initiated. The callback will be invoked when the call completes.
523 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
524 *
525 * When the callback is invoked, status indicates the result:
526 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
527 * data is LINK3res *
528 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
529 * data is the error string.
530 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
531 * data is NULL.
532 */
533 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);
534
535
536