Simplify the upgrade path handling from PPA.
[deb_libnfs.git] / nfsc / libnfs.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 highlevel interface to access NFS resources using a posix-like interface
19 */
20
21 #ifndef _LIBNFS_H_
22 #define _LIBNFS_H_
23
24 #include <stdint.h>
25 #if defined(ANDROID)
26 #include <sys/time.h>
27 #endif
28 #if defined(AROS)
29 #include <sys/time.h>
30 #endif
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 struct nfs_context;
37 struct rpc_context;
38
39 struct nfs_url {
40 char *server;
41 char *path;
42 char *file;
43 };
44
45 #if defined(WIN32)
46 #define EXTERN __declspec( dllexport )
47 #else
48 #define EXTERN
49 #endif
50
51 #if defined(WIN32)
52 struct statvfs {
53 uint32_t f_bsize;
54 uint32_t f_frsize;
55 uint64_t f_blocks;
56 uint64_t f_bfree;
57 uint64_t f_bavail;
58 uint32_t f_files;
59 uint32_t f_ffree;
60 uint32_t f_favail;
61 uint32_t f_fsid;
62 uint32_t f_flag;
63 uint32_t f_namemax;
64 };
65 struct utimbuf {
66 time_t actime;
67 time_t modtime;
68 };
69 #define R_OK 4
70 #define W_OK 2
71 #define X_OK 1
72 #endif
73
74 /*
75 * Used for interfacing the async version of the api into an external eventsystem
76 */
77 EXTERN int nfs_get_fd(struct nfs_context *nfs);
78 EXTERN int nfs_which_events(struct nfs_context *nfs);
79 EXTERN int nfs_service(struct nfs_context *nfs, int revents);
80 EXTERN int nfs_queue_length(struct nfs_context *nfs);
81
82 /*
83 * Used if you need different credentials than the default for the current user.
84 */
85 struct AUTH;
86 EXTERN void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth);
87
88 /*
89 * When an operation failed, this function can extract a detailed error string.
90 */
91 EXTERN char *nfs_get_error(struct nfs_context *nfs);
92
93
94 /*
95 * Callback for all ASYNC nfs functions
96 */
97 typedef void (*nfs_cb)(int err, struct nfs_context *nfs, void *data, void *private_data);
98
99 /*
100 * Callback for all ASYNC rpc functions
101 */
102 typedef void (*rpc_cb)(struct rpc_context *rpc, int status, void *data, void *private_data);
103
104
105
106 /*
107 * NFS CONTEXT.
108 */
109 /*
110 * Create an NFS c, the context.
111 * Function returns
112 * NULL : Failed to create a context.
113 * *nfs : A pointer to an nfs context.
114 */
115 EXTERN struct nfs_context *nfs_init_context(void);
116 /*
117 * Destroy an nfs context.
118 */
119 EXTERN void nfs_destroy_context(struct nfs_context *nfs);
120
121
122 /*
123 * URL parsing functions.
124 * These functions all parse a URL of the form
125 * nfs://server/path/file?argv=val[&arg=val]*
126 * and returns a nfs_url.
127 *
128 * Apart from parsing the URL the functions will also update
129 * the nfs context to reflect settings controlled via url arguments.
130 *
131 * Current URL arguments are :
132 * tcp-syncnt=<int> : Number of SYNs to send during the seccion establish
133 * before failing settin up the tcp connection to the
134 * server.
135 * uid=<int> : UID value to use when talking to the server.
136 * default it 65534 on Windows and getuid() on unixen.
137 * gid=<int> : GID value to use when talking to the server.
138 * default it 65534 on Windows and getgid() on unixen.
139 */
140 /*
141 * Parse a complete NFS URL including, server, path and
142 * filename. Fail if any component is missing.
143 */
144 EXTERN struct nfs_url *nfs_parse_url_full(struct nfs_context *nfs, const char *url);
145
146 /*
147 * Parse an NFS URL, but do not split path and file. File
148 * in the resulting struct remains NULL.
149 */
150 EXTERN struct nfs_url *nfs_parse_url_dir(struct nfs_context *nfs, const char *url);
151
152 /*
153 * Parse an NFS URL, but do not fail if file, path or even server is missing.
154 * Check elements of the resulting struct for NULL.
155 */
156 EXTERN struct nfs_url *nfs_parse_url_incomplete(struct nfs_context *nfs, const char *url);
157
158
159 /*
160 * Free the URL struct returned by the nfs_parse_url_* functions.
161 */
162 EXTERN void nfs_destroy_url(struct nfs_url *url);
163
164
165 struct nfsfh;
166
167 /*
168 * Get the maximum supported READ3 size by the server
169 */
170 EXTERN uint64_t nfs_get_readmax(struct nfs_context *nfs);
171
172 /*
173 * Get the maximum supported WRITE3 size by the server
174 */
175 EXTERN uint64_t nfs_get_writemax(struct nfs_context *nfs);
176
177 /*
178 * MODIFY CONNECT PARAMTERS
179 */
180
181 EXTERN void nfs_set_tcp_syncnt(struct nfs_context *nfs, int v);
182 EXTERN void nfs_set_uid(struct nfs_context *nfs, int uid);
183 EXTERN void nfs_set_gid(struct nfs_context *nfs, int gid);
184
185 /*
186 * MOUNT THE EXPORT
187 */
188 /*
189 * Async nfs mount.
190 * Function returns
191 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
192 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
193 *
194 * When the callback is invoked, status indicates the result:
195 * 0 : Success.
196 * data is NULL
197 * -errno : An error occured.
198 * data is the error string.
199 */
200 EXTERN int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *exportname, nfs_cb cb, void *private_data);
201 /*
202 * Sync nfs mount.
203 * Function returns
204 * 0 : The operation was successfull.
205 * -errno : The command failed.
206 */
207 EXTERN int nfs_mount(struct nfs_context *nfs, const char *server, const char *exportname);
208
209
210
211
212 /*
213 * STAT()
214 */
215 /*
216 * Async stat(<filename>)
217 * Function returns
218 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
219 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
220 *
221 * When the callback is invoked, status indicates the result:
222 * 0 : Success.
223 * data is struct stat *
224 * -errno : An error occured.
225 * data is the error string.
226 */
227 struct stat;
228 EXTERN int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
229 /*
230 * Sync stat(<filename>)
231 * Function returns
232 * 0 : The operation was successfull.
233 * -errno : The command failed.
234 */
235 #ifdef WIN32
236 EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct __stat64 *st);
237 #else
238 EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st);
239 #endif
240
241 /*
242 * FSTAT()
243 */
244 /*
245 * Async fstat(nfsfh *)
246 * Function returns
247 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
248 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
249 *
250 * When the callback is invoked, status indicates the result:
251 * 0 : Success.
252 * data is struct stat *
253 * -errno : An error occured.
254 * data is the error string.
255 */
256 EXTERN int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
257 /*
258 * Sync fstat(nfsfh *)
259 * Function returns
260 * 0 : The operation was successfull.
261 * -errno : The command failed.
262 */
263 #ifdef WIN32
264 EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct __stat64 *st);
265 #else
266 EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
267 #endif
268
269
270
271 /*
272 * OPEN()
273 */
274 /*
275 * Async open(<filename>)
276 *
277 * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
278 *
279 * Function returns
280 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
281 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
282 *
283 * Supported flags are
284 * O_RDONLY
285 * O_WRONLY
286 * O_RDWR
287 * O_TRUNC (Only valid with O_RDWR or O_WRONLY. Ignored otherwise.)
288 *
289 * When the callback is invoked, status indicates the result:
290 * 0 : Success.
291 * data is a struct *nfsfh;
292 * The nfsfh is close using nfs_close().
293 * -errno : An error occured.
294 * data is the error string.
295 */
296 EXTERN int nfs_open_async(struct nfs_context *nfs, const char *path, int flags, nfs_cb cb, void *private_data);
297 /*
298 * Sync open(<filename>)
299 * Function returns
300 * 0 : The operation was successfull. *nfsfh is filled in.
301 * -errno : The command failed.
302 */
303 EXTERN int nfs_open(struct nfs_context *nfs, const char *path, int flags, struct nfsfh **nfsfh);
304
305
306
307
308 /*
309 * CLOSE
310 */
311 /*
312 * Async close(nfsfh)
313 *
314 * Function returns
315 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
316 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
317 *
318 * When the callback is invoked, status indicates the result:
319 * 0 : Success.
320 * data is NULL.
321 * -errno : An error occured.
322 * data is the error string.
323 */
324 EXTERN int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
325 /*
326 * Sync close(nfsfh)
327 * Function returns
328 * 0 : The operation was successfull.
329 * -errno : The command failed.
330 */
331 EXTERN int nfs_close(struct nfs_context *nfs, struct nfsfh *nfsfh);
332
333
334 /*
335 * PREAD()
336 */
337 /*
338 * Async pread()
339 *
340 * Function returns
341 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
342 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
343 *
344 * When the callback is invoked, status indicates the result:
345 * >=0 : Success.
346 * status is numer of bytes read.
347 * data is a pointer to the returned data.
348 * -errno : An error occured.
349 * data is the error string.
350 */
351 EXTERN int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, nfs_cb cb, void *private_data);
352 /*
353 * Sync pread()
354 * Function returns
355 * >=0 : numer of bytes read.
356 * -errno : An error occured.
357 */
358 EXTERN int nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
359
360
361
362 /*
363 * READ()
364 */
365 /*
366 * Async read()
367 *
368 * Function returns
369 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
370 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
371 *
372 * When the callback is invoked, status indicates the result:
373 * >=0 : Success.
374 * status is numer of bytes read.
375 * data is a pointer to the returned data.
376 * -errno : An error occured.
377 * data is the error string.
378 */
379 EXTERN int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, nfs_cb cb, void *private_data);
380 /*
381 * Sync read()
382 * Function returns
383 * >=0 : numer of bytes read.
384 * -errno : An error occured.
385 */
386 EXTERN int nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
387
388
389
390
391 /*
392 * PWRITE()
393 */
394 /*
395 * Async pwrite()
396 *
397 * Function returns
398 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
399 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
400 *
401 * When the callback is invoked, status indicates the result:
402 * >=0 : Success.
403 * status is numer of bytes written.
404 * -errno : An error occured.
405 * data is the error string.
406 */
407 EXTERN int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf, nfs_cb cb, void *private_data);
408 /*
409 * Sync pwrite()
410 * Function returns
411 * >=0 : numer of bytes written.
412 * -errno : An error occured.
413 */
414 EXTERN int nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
415
416
417 /*
418 * WRITE()
419 */
420 /*
421 * Async write()
422 *
423 * Function returns
424 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
425 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
426 *
427 * When the callback is invoked, status indicates the result:
428 * >=0 : Success.
429 * status is numer of bytes written.
430 * -errno : An error occured.
431 * data is the error string.
432 */
433 EXTERN int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf, nfs_cb cb, void *private_data);
434 /*
435 * Sync write()
436 * Function returns
437 * >=0 : numer of bytes written.
438 * -errno : An error occured.
439 */
440 EXTERN int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
441
442
443 /*
444 * LSEEK()
445 */
446 /*
447 * Async lseek()
448 *
449 * Function returns
450 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
451 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
452 *
453 * When the callback is invoked, status indicates the result:
454 * >=0 : Success.
455 * data is uint64_t * for the current position.
456 * -errno : An error occured.
457 * data is the error string.
458 */
459 EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, int whence, nfs_cb cb, void *private_data);
460 /*
461 * Sync lseek()
462 * Function returns
463 * >=0 : numer of bytes read.
464 * -errno : An error occured.
465 */
466 EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, int whence, uint64_t *current_offset);
467
468
469 /*
470 * FSYNC()
471 */
472 /*
473 * Async fsync()
474 *
475 * Function returns
476 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
477 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
478 *
479 * When the callback is invoked, status indicates the result:
480 * 0 : Success.
481 * -errno : An error occured.
482 * data is the error string.
483 */
484 EXTERN int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
485 /*
486 * Sync fsync()
487 * Function returns
488 * 0 : Success
489 * -errno : An error occured.
490 */
491 EXTERN int nfs_fsync(struct nfs_context *nfs, struct nfsfh *nfsfh);
492
493
494
495 /*
496 * TRUNCATE()
497 */
498 /*
499 * Async truncate()
500 *
501 * Function returns
502 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
503 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
504 *
505 * When the callback is invoked, status indicates the result:
506 * 0 : Success.
507 * -errno : An error occured.
508 * data is the error string.
509 */
510 EXTERN int nfs_truncate_async(struct nfs_context *nfs, const char *path, uint64_t length, nfs_cb cb, void *private_data);
511 /*
512 * Sync truncate()
513 * Function returns
514 * 0 : Success
515 * -errno : An error occured.
516 */
517 EXTERN int nfs_truncate(struct nfs_context *nfs, const char *path, uint64_t length);
518
519
520
521 /*
522 * FTRUNCATE()
523 */
524 /*
525 * Async ftruncate()
526 *
527 * Function returns
528 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
529 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
530 *
531 * When the callback is invoked, status indicates the result:
532 * 0 : Success.
533 * -errno : An error occured.
534 * data is the error string.
535 */
536 EXTERN int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length, nfs_cb cb, void *private_data);
537 /*
538 * Sync ftruncate()
539 * Function returns
540 * 0 : Success
541 * -errno : An error occured.
542 */
543 EXTERN int nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length);
544
545
546
547
548
549
550 /*
551 * MKDIR()
552 */
553 /*
554 * Async mkdir()
555 *
556 * Function returns
557 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
558 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
559 *
560 * When the callback is invoked, status indicates the result:
561 * 0 : Success.
562 * -errno : An error occured.
563 * data is the error string.
564 */
565 EXTERN int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
566 /*
567 * Sync mkdir()
568 * Function returns
569 * 0 : Success
570 * -errno : An error occured.
571 */
572 EXTERN int nfs_mkdir(struct nfs_context *nfs, const char *path);
573
574
575
576 /*
577 * RMDIR()
578 */
579 /*
580 * Async rmdir()
581 *
582 * Function returns
583 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
584 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
585 *
586 * When the callback is invoked, status indicates the result:
587 * 0 : Success.
588 * -errno : An error occured.
589 * data is the error string.
590 */
591 EXTERN int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
592 /*
593 * Sync rmdir()
594 * Function returns
595 * 0 : Success
596 * -errno : An error occured.
597 */
598 EXTERN int nfs_rmdir(struct nfs_context *nfs, const char *path);
599
600
601
602
603 /*
604 * CREAT()
605 */
606 /*
607 * Async creat()
608 *
609 * Function returns
610 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
611 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
612 *
613 * When the callback is invoked, status indicates the result:
614 * 0 : Success.
615 * data is a struct *nfsfh;
616 * -errno : An error occured.
617 * data is the error string.
618 */
619 EXTERN int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
620 /*
621 * Sync creat()
622 * Function returns
623 * 0 : Success
624 * -errno : An error occured.
625 */
626 EXTERN int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
627
628
629 /*
630 * MKNOD()
631 */
632 /*
633 * Async mknod()
634 *
635 * Function returns
636 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
637 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
638 *
639 * When the callback is invoked, status indicates the result:
640 * 0 : Success.
641 * -errno : An error occured.
642 * data is the error string.
643 */
644 EXTERN int nfs_mknod_async(struct nfs_context *nfs, const char *path, int mode, int dev, nfs_cb cb, void *private_data);
645 /*
646 * Sync mknod()
647 * Function returns
648 * 0 : Success
649 * -errno : An error occured.
650 */
651 EXTERN int nfs_mknod(struct nfs_context *nfs, const char *path, int mode, int dev);
652
653
654
655 /*
656 * UNLINK()
657 */
658 /*
659 * Async unlink()
660 *
661 * Function returns
662 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
663 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
664 *
665 * When the callback is invoked, status indicates the result:
666 * 0 : Success.
667 * data is NULL
668 * -errno : An error occured.
669 * data is the error string.
670 */
671 EXTERN int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
672 /*
673 * Sync unlink()
674 * Function returns
675 * 0 : Success
676 * -errno : An error occured.
677 */
678 EXTERN int nfs_unlink(struct nfs_context *nfs, const char *path);
679
680
681
682
683 /*
684 * OPENDIR()
685 */
686 struct nfsdir;
687 /*
688 * Async opendir()
689 *
690 * Function returns
691 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
692 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
693 *
694 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
695 *
696 * When the callback is invoked, status indicates the result:
697 * 0 : Success.
698 * data is struct nfsdir *
699 * -errno : An error occured.
700 * data is the error string.
701 */
702 EXTERN int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
703 /*
704 * Sync opendir()
705 * Function returns
706 * 0 : Success
707 * -errno : An error occured.
708 */
709 EXTERN int nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
710
711
712
713 /*
714 * READDIR()
715 */
716 struct nfsdirent {
717 struct nfsdirent *next;
718 char *name;
719 uint64_t inode;
720
721 /* Some extra fields we get for free through the READDIRPLUS3 call.
722 You need libnfs-raw-nfs.h for type/mode constants */
723 uint32_t type; /* NF3REG, NF3DIR, NF3BLK, ... */
724 uint32_t mode;
725 uint64_t size;
726 struct timeval atime;
727 struct timeval mtime;
728 struct timeval ctime;
729 uint32_t uid;
730 uint32_t gid;
731 };
732 /*
733 * nfs_readdir() never blocks, so no special sync/async versions are available
734 */
735 EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
736
737
738
739 /*
740 * CLOSEDIR()
741 */
742 /*
743 * nfs_closedir() never blocks, so no special sync/async versions are available
744 */
745 EXTERN void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
746
747
748 /*
749 * CHDIR()
750 */
751 /*
752 * Async chdir(<path>)
753 *
754 * Function returns
755 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
756 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
757 *
758 * When the callback is invoked, status indicates the result:
759 * 0 : Success.
760 * data is NULL;
761 * -errno : An error occured.
762 * data is the error string.
763 */
764 EXTERN int nfs_chdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
765 /*
766 * Sync chdir(<path>)
767 * Function returns
768 * 0 : The operation was successfull.
769 * -errno : The command failed.
770 */
771 EXTERN int nfs_chdir(struct nfs_context *nfs, const char *path);
772
773 /*
774 * GETCWD()
775 */
776 /*
777 * nfs_getcwd() never blocks, so no special sync/async versions are available
778 */
779 /*
780 * Sync getcwd()
781 * This function returns a pointer to the current working directory.
782 * This pointer is only stable until the next [f]chdir or when the
783 * context is destroyed.
784 *
785 * Function returns
786 * 0 : The operation was successfull and *cwd is filled in.
787 * -errno : The command failed.
788 */
789 EXTERN void nfs_getcwd(struct nfs_context *nfs, const char **cwd);
790
791
792 /*
793 * STATVFS()
794 */
795 /*
796 * Async statvfs(<dirname>)
797 * Function returns
798 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
799 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
800 *
801 * When the callback is invoked, status indicates the result:
802 * 0 : Success.
803 * data is struct statvfs *
804 * -errno : An error occured.
805 * data is the error string.
806 */
807 struct statvfs;
808 EXTERN int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
809 /*
810 * Sync statvfs(<dirname>)
811 * Function returns
812 * 0 : The operation was successfull.
813 * -errno : The command failed.
814 */
815 EXTERN int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
816
817
818 /*
819 * READLINK()
820 */
821 /*
822 * Async readlink(<name>)
823 * Function returns
824 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
825 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
826 *
827 * When the callback is invoked, status indicates the result:
828 * 0 : Success.
829 * data is a char *
830 * data is only valid during the callback and is automatically freed when the callback returns.
831 * -errno : An error occured.
832 * data is the error string.
833 */
834 struct statvfs;
835 EXTERN int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
836 /*
837 * Sync readlink(<name>)
838 * Function returns
839 * 0 : The operation was successfull.
840 * -errno : The command failed.
841 */
842 EXTERN int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
843
844
845
846 /*
847 * CHMOD()
848 */
849 /*
850 * Async chmod(<name>)
851 * Function returns
852 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
853 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
854 *
855 * When the callback is invoked, status indicates the result:
856 * 0 : Success.
857 * data is NULL
858 * -errno : An error occured.
859 * data is the error string.
860 */
861 EXTERN int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
862 /*
863 * Sync chmod(<name>)
864 * Function returns
865 * 0 : The operation was successfull.
866 * -errno : The command failed.
867 */
868 EXTERN int nfs_chmod(struct nfs_context *nfs, const char *path, int mode);
869
870
871
872 /*
873 * FCHMOD()
874 */
875 /*
876 * Async fchmod(<handle>)
877 * Function returns
878 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
879 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
880 *
881 * When the callback is invoked, status indicates the result:
882 * 0 : Success.
883 * data is NULL
884 * -errno : An error occured.
885 * data is the error string.
886 */
887 EXTERN int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
888 /*
889 * Sync fchmod(<handle>)
890 * Function returns
891 * 0 : The operation was successfull.
892 * -errno : The command failed.
893 */
894 EXTERN int nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
895
896
897
898 /*
899 * CHOWN()
900 */
901 /*
902 * Async chown(<name>)
903 * Function returns
904 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
905 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
906 *
907 * When the callback is invoked, status indicates the result:
908 * 0 : Success.
909 * data is NULL
910 * -errno : An error occured.
911 * data is the error string.
912 */
913 EXTERN int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
914 /*
915 * Sync chown(<name>)
916 * Function returns
917 * 0 : The operation was successfull.
918 * -errno : The command failed.
919 */
920 EXTERN int nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid);
921
922
923
924 /*
925 * FCHOWN()
926 */
927 /*
928 * Async fchown(<handle>)
929 * Function returns
930 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
931 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
932 *
933 * When the callback is invoked, status indicates the result:
934 * 0 : Success.
935 * data is NULL
936 * -errno : An error occured.
937 * data is the error string.
938 */
939 EXTERN int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
940 /*
941 * Sync fchown(<handle>)
942 * Function returns
943 * 0 : The operation was successfull.
944 * -errno : The command failed.
945 */
946 EXTERN int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
947
948
949
950
951 /*
952 * UTIMES()
953 */
954 /*
955 * Async utimes(<path>)
956 * Function returns
957 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
958 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
959 *
960 * When the callback is invoked, status indicates the result:
961 * 0 : Success.
962 * data is NULL
963 * -errno : An error occured.
964 * data is the error string.
965 */
966 EXTERN int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
967 /*
968 * Sync utimes(<path>)
969 * Function returns
970 * 0 : The operation was successfull.
971 * -errno : The command failed.
972 */
973 EXTERN int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times);
974
975
976 /*
977 * UTIME()
978 */
979 /*
980 * Async utime(<path>)
981 * Function returns
982 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
983 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
984 *
985 * When the callback is invoked, status indicates the result:
986 * 0 : Success.
987 * data is NULL
988 * -errno : An error occured.
989 * data is the error string.
990 */
991 struct utimbuf;
992 EXTERN int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
993 /*
994 * Sync utime(<path>)
995 * Function returns
996 * 0 : The operation was successfull.
997 * -errno : The command failed.
998 */
999 EXTERN int nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times);
1000
1001
1002
1003
1004 /*
1005 * ACCESS()
1006 */
1007 /*
1008 * Async access(<path>)
1009 * Function returns
1010 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1011 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1012 *
1013 * When the callback is invoked, status indicates the result:
1014 * 0 : Success.
1015 * data is NULL
1016 * -errno : An error occured.
1017 * data is the error string.
1018 */
1019 EXTERN int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
1020 /*
1021 * Sync access(<path>)
1022 * Function returns
1023 * 0 : The operation was successfull.
1024 * -errno : The command failed.
1025 */
1026 EXTERN int nfs_access(struct nfs_context *nfs, const char *path, int mode);
1027
1028
1029
1030
1031 /*
1032 * SYMLINK()
1033 */
1034 /*
1035 * Async symlink(<path>)
1036 * Function returns
1037 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1038 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1039 *
1040 * When the callback is invoked, status indicates the result:
1041 * 0 : Success.
1042 * data is NULL
1043 * -errno : An error occured.
1044 * data is the error string.
1045 */
1046 EXTERN int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1047 /*
1048 * Sync symlink(<path>)
1049 * Function returns
1050 * 0 : The operation was successfull.
1051 * -errno : The command failed.
1052 */
1053 EXTERN int nfs_symlink(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1054
1055
1056 /*
1057 * RENAME()
1058 */
1059 /*
1060 * Async rename(<oldpath>, <newpath>)
1061 * Function returns
1062 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1063 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1064 *
1065 * When the callback is invoked, status indicates the result:
1066 * 0 : Success.
1067 * data is NULL
1068 * -errno : An error occured.
1069 * data is the error string.
1070 */
1071 EXTERN int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1072 /*
1073 * Sync rename(<oldpath>, <newpath>)
1074 * Function returns
1075 * 0 : The operation was successfull.
1076 * -errno : The command failed.
1077 */
1078 EXTERN int nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1079
1080
1081
1082 /*
1083 * LINK()
1084 */
1085 /*
1086 * Async link(<oldpath>, <newpath>)
1087 * Function returns
1088 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1089 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1090 *
1091 * When the callback is invoked, status indicates the result:
1092 * 0 : Success.
1093 * data is NULL
1094 * -errno : An error occured.
1095 * data is the error string.
1096 */
1097 EXTERN int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1098 /*
1099 * Sync link(<oldpath>, <newpath>)
1100 * Function returns
1101 * 0 : The operation was successfull.
1102 * -errno : The command failed.
1103 */
1104 EXTERN int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1105
1106
1107 /*
1108 * GETEXPORTS()
1109 */
1110 /*
1111 * Async getexports()
1112 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
1113 * returned structures.
1114 *
1115 * This function will return the list of exports from an NFS server.
1116 *
1117 * Function returns
1118 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1119 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1120 *
1121 * When the callback is invoked, status indicates the result:
1122 * 0 : Success.
1123 * data is a pointer to an exports pointer:
1124 * exports export = *(exports *)data;
1125 * -errno : An error occured.
1126 * data is the error string.
1127 */
1128 EXTERN int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data);
1129 /*
1130 * Sync getexports(<server>)
1131 * Function returns
1132 * NULL : something failed
1133 * exports export : a linked list of exported directories
1134 *
1135 * returned data must be freed by calling mount_free_export_list(exportnode);
1136 */
1137 EXTERN struct exportnode *mount_getexports(const char *server);
1138
1139 EXTERN void mount_free_export_list(struct exportnode *exports);
1140
1141
1142 //qqq replace later with lseek(cur, 0)
1143 uint64_t nfs_get_current_offset(struct nfsfh *nfsfh);
1144
1145
1146
1147
1148
1149 struct nfs_server_list {
1150 struct nfs_server_list *next;
1151 char *addr;
1152 };
1153
1154 /*
1155 * Sync find_local_servers(<server>)
1156 * This function will probe all local networks for NFS server. This function will
1157 * block for one second while awaiting for all nfs servers to respond.
1158 *
1159 * Function returns
1160 * NULL : something failed
1161 *
1162 * struct nfs_server_list : a linked list of all discovered servers
1163 *
1164 * returned data must be freed by nfs_free_srvr_list(srv);
1165 */
1166 struct nfs_server_list *nfs_find_local_servers(void);
1167 void free_nfs_srvr_list(struct nfs_server_list *srv);
1168
1169 #ifdef __cplusplus
1170 }
1171 #endif
1172
1173 #endif /* !_LIBNFS_H_ */