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