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