libnfs: Set as much stat information as possible
[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 uint64_t nfs_atime_nsec;
274 uint64_t nfs_mtime_nsec;
275 uint64_t nfs_ctime_nsec;
276 uint64_t nfs_used;
277 };
278
279 /*
280 * Async stat(<filename>)
281 * Function returns
282 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
283 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
284 *
285 * When the callback is invoked, status indicates the result:
286 * 0 : Success.
287 * data is struct nfs_stat_64 *
288 * -errno : An error occured.
289 * data is the error string.
290 */
291 EXTERN int nfs_stat64_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
292 /*
293 * Sync stat(<filename>)
294 * Function returns
295 * 0 : The operation was successfull.
296 * -errno : The command failed.
297 */
298 EXTERN int nfs_stat64(struct nfs_context *nfs, const char *path, struct nfs_stat_64 *st);
299
300 /*
301 * FSTAT()
302 */
303 /*
304 * Async fstat(nfsfh *)
305 * Function returns
306 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
307 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
308 *
309 * When the callback is invoked, status indicates the result:
310 * 0 : Success.
311 * data is struct stat *
312 * -errno : An error occured.
313 * data is the error string.
314 */
315 EXTERN int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
316 /*
317 * Sync fstat(nfsfh *)
318 * Function returns
319 * 0 : The operation was successfull.
320 * -errno : The command failed.
321 */
322 #ifdef WIN32
323 EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct __stat64 *st);
324 #else
325 EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
326 #endif
327
328
329
330 /*
331 * OPEN()
332 */
333 /*
334 * Async open(<filename>)
335 *
336 * mode is a combination of the flags :
337 * O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC, O_APPEND
338 *
339 * Function returns
340 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
341 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
342 *
343 * Supported flags are
344 * O_APPEND
345 * O_RDONLY
346 * O_WRONLY
347 * O_RDWR
348 * O_TRUNC (Only valid with O_RDWR or O_WRONLY. Ignored otherwise.)
349 *
350 * When the callback is invoked, status indicates the result:
351 * 0 : Success.
352 * data is a struct *nfsfh;
353 * The nfsfh is close using nfs_close().
354 * -errno : An error occured.
355 * data is the error string.
356 */
357 EXTERN int nfs_open_async(struct nfs_context *nfs, const char *path, int flags, nfs_cb cb, void *private_data);
358 /*
359 * Sync open(<filename>)
360 * Function returns
361 * 0 : The operation was successfull. *nfsfh is filled in.
362 * -errno : The command failed.
363 */
364 EXTERN int nfs_open(struct nfs_context *nfs, const char *path, int flags, struct nfsfh **nfsfh);
365
366
367
368
369 /*
370 * CLOSE
371 */
372 /*
373 * Async close(nfsfh)
374 *
375 * Function returns
376 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
377 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
378 *
379 * When the callback is invoked, status indicates the result:
380 * 0 : Success.
381 * data is NULL.
382 * -errno : An error occured.
383 * data is the error string.
384 */
385 EXTERN int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
386 /*
387 * Sync close(nfsfh)
388 * Function returns
389 * 0 : The operation was successfull.
390 * -errno : The command failed.
391 */
392 EXTERN int nfs_close(struct nfs_context *nfs, struct nfsfh *nfsfh);
393
394
395 /*
396 * PREAD()
397 */
398 /*
399 * Async pread()
400 *
401 * Function returns
402 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
403 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
404 *
405 * When the callback is invoked, status indicates the result:
406 * >=0 : Success.
407 * status is numer of bytes read.
408 * data is a pointer to the returned data.
409 * -errno : An error occured.
410 * data is the error string.
411 */
412 EXTERN int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, nfs_cb cb, void *private_data);
413 /*
414 * Sync pread()
415 * Function returns
416 * >=0 : numer of bytes read.
417 * -errno : An error occured.
418 */
419 EXTERN int nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
420
421
422
423 /*
424 * READ()
425 */
426 /*
427 * Async read()
428 *
429 * Function returns
430 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
431 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
432 *
433 * When the callback is invoked, status indicates the result:
434 * >=0 : Success.
435 * status is numer of bytes read.
436 * data is a pointer to the returned data.
437 * -errno : An error occured.
438 * data is the error string.
439 */
440 EXTERN int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, nfs_cb cb, void *private_data);
441 /*
442 * Sync read()
443 * Function returns
444 * >=0 : numer of bytes read.
445 * -errno : An error occured.
446 */
447 EXTERN int nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
448
449
450
451
452 /*
453 * PWRITE()
454 */
455 /*
456 * Async pwrite()
457 *
458 * Function returns
459 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
460 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
461 *
462 * When the callback is invoked, status indicates the result:
463 * >=0 : Success.
464 * status is numer of bytes written.
465 * -errno : An error occured.
466 * data is the error string.
467 */
468 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);
469 /*
470 * Sync pwrite()
471 * Function returns
472 * >=0 : numer of bytes written.
473 * -errno : An error occured.
474 */
475 EXTERN int nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
476
477
478 /*
479 * WRITE()
480 */
481 /*
482 * Async write()
483 *
484 * Function returns
485 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
486 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
487 *
488 * When the callback is invoked, status indicates the result:
489 * >=0 : Success.
490 * status is numer of bytes written.
491 * -errno : An error occured.
492 * data is the error string.
493 */
494 EXTERN int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf, nfs_cb cb, void *private_data);
495 /*
496 * Sync write()
497 * Function returns
498 * >=0 : numer of bytes written.
499 * -errno : An error occured.
500 */
501 EXTERN int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
502
503
504 /*
505 * LSEEK()
506 */
507 /*
508 * Async lseek()
509 *
510 * Function returns
511 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
512 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
513 *
514 * When the callback is invoked, status indicates the result:
515 * >=0 : Success.
516 * data is uint64_t * for the current position.
517 * -errno : An error occured.
518 * data is the error string.
519 */
520 EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, nfs_cb cb, void *private_data);
521 /*
522 * Sync lseek()
523 * Function returns
524 * >=0 : numer of bytes read.
525 * -errno : An error occured.
526 */
527 EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, uint64_t *current_offset);
528
529
530 /*
531 * FSYNC()
532 */
533 /*
534 * Async fsync()
535 *
536 * Function returns
537 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
538 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
539 *
540 * When the callback is invoked, status indicates the result:
541 * 0 : Success.
542 * -errno : An error occured.
543 * data is the error string.
544 */
545 EXTERN int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
546 /*
547 * Sync fsync()
548 * Function returns
549 * 0 : Success
550 * -errno : An error occured.
551 */
552 EXTERN int nfs_fsync(struct nfs_context *nfs, struct nfsfh *nfsfh);
553
554
555
556 /*
557 * TRUNCATE()
558 */
559 /*
560 * Async truncate()
561 *
562 * Function returns
563 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
564 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
565 *
566 * When the callback is invoked, status indicates the result:
567 * 0 : Success.
568 * -errno : An error occured.
569 * data is the error string.
570 */
571 EXTERN int nfs_truncate_async(struct nfs_context *nfs, const char *path, uint64_t length, nfs_cb cb, void *private_data);
572 /*
573 * Sync truncate()
574 * Function returns
575 * 0 : Success
576 * -errno : An error occured.
577 */
578 EXTERN int nfs_truncate(struct nfs_context *nfs, const char *path, uint64_t length);
579
580
581
582 /*
583 * FTRUNCATE()
584 */
585 /*
586 * Async ftruncate()
587 *
588 * Function returns
589 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
590 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
591 *
592 * When the callback is invoked, status indicates the result:
593 * 0 : Success.
594 * -errno : An error occured.
595 * data is the error string.
596 */
597 EXTERN int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length, nfs_cb cb, void *private_data);
598 /*
599 * Sync ftruncate()
600 * Function returns
601 * 0 : Success
602 * -errno : An error occured.
603 */
604 EXTERN int nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length);
605
606
607
608
609
610
611 /*
612 * MKDIR()
613 */
614 /*
615 * Async mkdir()
616 *
617 * Function returns
618 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
619 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
620 *
621 * When the callback is invoked, status indicates the result:
622 * 0 : Success.
623 * -errno : An error occured.
624 * data is the error string.
625 */
626 EXTERN int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
627 /*
628 * Sync mkdir()
629 * Function returns
630 * 0 : Success
631 * -errno : An error occured.
632 */
633 EXTERN int nfs_mkdir(struct nfs_context *nfs, const char *path);
634
635
636
637 /*
638 * RMDIR()
639 */
640 /*
641 * Async rmdir()
642 *
643 * Function returns
644 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
645 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
646 *
647 * When the callback is invoked, status indicates the result:
648 * 0 : Success.
649 * -errno : An error occured.
650 * data is the error string.
651 */
652 EXTERN int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
653 /*
654 * Sync rmdir()
655 * Function returns
656 * 0 : Success
657 * -errno : An error occured.
658 */
659 EXTERN int nfs_rmdir(struct nfs_context *nfs, const char *path);
660
661
662
663
664 /*
665 * CREAT()
666 */
667 /*
668 * Async creat()
669 *
670 * Function returns
671 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
672 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
673 *
674 * When the callback is invoked, status indicates the result:
675 * 0 : Success.
676 * data is a struct *nfsfh;
677 * -errno : An error occured.
678 * data is the error string.
679 */
680 EXTERN int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
681 /*
682 * Sync creat()
683 * Function returns
684 * 0 : Success
685 * -errno : An error occured.
686 */
687 EXTERN int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
688
689 /*
690 * Async create()
691 *
692 * Same as nfs_creat_async but allows passing flags:
693 * O_APPEND
694 * O_SYNC
695 * O_EXCL
696 *
697 * Function returns
698 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
699 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
700 *
701 * When the callback is invoked, status indicates the result:
702 * 0 : Success.
703 * data is a struct *nfsfh;
704 * -errno : An error occured.
705 * data is the error string.
706 */
707 EXTERN int nfs_create_async(struct nfs_context *nfs, const char *path, int flags, int mode, nfs_cb cb, void *private_data);
708 /*
709 * Sync create()
710 * Function returns
711 * 0 : Success
712 * -errno : An error occured.
713 */
714 EXTERN int nfs_create(struct nfs_context *nfs, const char *path, int flags, int mode, struct nfsfh **nfsfh);
715
716
717 /*
718 * MKNOD()
719 */
720 /*
721 * Async mknod()
722 *
723 * Function returns
724 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
725 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
726 *
727 * When the callback is invoked, status indicates the result:
728 * 0 : Success.
729 * -errno : An error occured.
730 * data is the error string.
731 */
732 EXTERN int nfs_mknod_async(struct nfs_context *nfs, const char *path, int mode, int dev, nfs_cb cb, void *private_data);
733 /*
734 * Sync mknod()
735 * Function returns
736 * 0 : Success
737 * -errno : An error occured.
738 */
739 EXTERN int nfs_mknod(struct nfs_context *nfs, const char *path, int mode, int dev);
740
741
742
743 /*
744 * UNLINK()
745 */
746 /*
747 * Async unlink()
748 *
749 * Function returns
750 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
751 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
752 *
753 * When the callback is invoked, status indicates the result:
754 * 0 : Success.
755 * data is NULL
756 * -errno : An error occured.
757 * data is the error string.
758 */
759 EXTERN int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
760 /*
761 * Sync unlink()
762 * Function returns
763 * 0 : Success
764 * -errno : An error occured.
765 */
766 EXTERN int nfs_unlink(struct nfs_context *nfs, const char *path);
767
768
769
770
771 /*
772 * OPENDIR()
773 */
774 struct nfsdir;
775 /*
776 * Async opendir()
777 *
778 * Function returns
779 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
780 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
781 *
782 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
783 *
784 * When the callback is invoked, status indicates the result:
785 * 0 : Success.
786 * data is struct nfsdir *
787 * -errno : An error occured.
788 * data is the error string.
789 */
790 EXTERN int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
791 /*
792 * Sync opendir()
793 * Function returns
794 * 0 : Success
795 * -errno : An error occured.
796 */
797 EXTERN int nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
798
799
800
801 /*
802 * READDIR()
803 */
804 struct nfsdirent {
805 struct nfsdirent *next;
806 char *name;
807 uint64_t inode;
808
809 /* Some extra fields we get for free through the READDIRPLUS3 call.
810 You need libnfs-raw-nfs.h for type/mode constants */
811 uint32_t type; /* NF3REG, NF3DIR, NF3BLK, ... */
812 uint32_t mode;
813 uint64_t size;
814 struct timeval atime;
815 struct timeval mtime;
816 struct timeval ctime;
817 uint32_t uid;
818 uint32_t gid;
819 uint32_t nlink;
820 uint64_t dev;
821 uint64_t rdev;
822 uint64_t blksize;
823 uint64_t blocks;
824 uint64_t used;
825 uint32_t atime_nsec;
826 uint32_t mtime_nsec;
827 uint32_t ctime_nsec;
828 };
829 /*
830 * nfs_readdir() never blocks, so no special sync/async versions are available
831 */
832 EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
833
834
835
836 /*
837 * CLOSEDIR()
838 */
839 /*
840 * nfs_closedir() never blocks, so no special sync/async versions are available
841 */
842 EXTERN void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
843
844
845 /*
846 * CHDIR()
847 */
848 /*
849 * Async chdir(<path>)
850 *
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_chdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
862 /*
863 * Sync chdir(<path>)
864 * Function returns
865 * 0 : The operation was successfull.
866 * -errno : The command failed.
867 */
868 EXTERN int nfs_chdir(struct nfs_context *nfs, const char *path);
869
870 /*
871 * GETCWD()
872 */
873 /*
874 * nfs_getcwd() never blocks, so no special sync/async versions are available
875 */
876 /*
877 * Sync getcwd()
878 * This function returns a pointer to the current working directory.
879 * This pointer is only stable until the next [f]chdir or when the
880 * context is destroyed.
881 *
882 * Function returns
883 * 0 : The operation was successfull and *cwd is filled in.
884 * -errno : The command failed.
885 */
886 EXTERN void nfs_getcwd(struct nfs_context *nfs, const char **cwd);
887
888
889 /*
890 * STATVFS()
891 */
892 /*
893 * Async statvfs(<dirname>)
894 * Function returns
895 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
896 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
897 *
898 * When the callback is invoked, status indicates the result:
899 * 0 : Success.
900 * data is struct statvfs *
901 * -errno : An error occured.
902 * data is the error string.
903 */
904 struct statvfs;
905 EXTERN int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
906 /*
907 * Sync statvfs(<dirname>)
908 * Function returns
909 * 0 : The operation was successfull.
910 * -errno : The command failed.
911 */
912 EXTERN int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
913
914
915 /*
916 * READLINK()
917 */
918 /*
919 * Async readlink(<name>)
920 * Function returns
921 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
922 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
923 *
924 * When the callback is invoked, status indicates the result:
925 * 0 : Success.
926 * data is a char *
927 * data is only valid during the callback and is automatically freed when the callback returns.
928 * -errno : An error occured.
929 * data is the error string.
930 */
931 struct statvfs;
932 EXTERN int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
933 /*
934 * Sync readlink(<name>)
935 * Function returns
936 * 0 : The operation was successfull.
937 * -errno : The command failed.
938 */
939 EXTERN int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
940
941
942
943 /*
944 * CHMOD()
945 */
946 /*
947 * Async chmod(<name>)
948 * Function returns
949 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
950 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
951 *
952 * When the callback is invoked, status indicates the result:
953 * 0 : Success.
954 * data is NULL
955 * -errno : An error occured.
956 * data is the error string.
957 */
958 EXTERN int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
959 /*
960 * Sync chmod(<name>)
961 * Function returns
962 * 0 : The operation was successfull.
963 * -errno : The command failed.
964 */
965 EXTERN int nfs_chmod(struct nfs_context *nfs, const char *path, int mode);
966
967
968
969 /*
970 * FCHMOD()
971 */
972 /*
973 * Async fchmod(<handle>)
974 * Function returns
975 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
976 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
977 *
978 * When the callback is invoked, status indicates the result:
979 * 0 : Success.
980 * data is NULL
981 * -errno : An error occured.
982 * data is the error string.
983 */
984 EXTERN int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
985 /*
986 * Sync fchmod(<handle>)
987 * Function returns
988 * 0 : The operation was successfull.
989 * -errno : The command failed.
990 */
991 EXTERN int nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
992
993
994
995 /*
996 * CHOWN()
997 */
998 /*
999 * Async chown(<name>)
1000 * Function returns
1001 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1002 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1003 *
1004 * When the callback is invoked, status indicates the result:
1005 * 0 : Success.
1006 * data is NULL
1007 * -errno : An error occured.
1008 * data is the error string.
1009 */
1010 EXTERN int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
1011 /*
1012 * Sync chown(<name>)
1013 * Function returns
1014 * 0 : The operation was successfull.
1015 * -errno : The command failed.
1016 */
1017 EXTERN int nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid);
1018
1019
1020
1021 /*
1022 * FCHOWN()
1023 */
1024 /*
1025 * Async fchown(<handle>)
1026 * Function returns
1027 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1028 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1029 *
1030 * When the callback is invoked, status indicates the result:
1031 * 0 : Success.
1032 * data is NULL
1033 * -errno : An error occured.
1034 * data is the error string.
1035 */
1036 EXTERN int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
1037 /*
1038 * Sync fchown(<handle>)
1039 * Function returns
1040 * 0 : The operation was successfull.
1041 * -errno : The command failed.
1042 */
1043 EXTERN int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
1044
1045
1046
1047
1048 /*
1049 * UTIMES()
1050 */
1051 /*
1052 * Async utimes(<path>)
1053 * Function returns
1054 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1055 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1056 *
1057 * When the callback is invoked, status indicates the result:
1058 * 0 : Success.
1059 * data is NULL
1060 * -errno : An error occured.
1061 * data is the error string.
1062 */
1063 EXTERN int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
1064 /*
1065 * Sync utimes(<path>)
1066 * Function returns
1067 * 0 : The operation was successfull.
1068 * -errno : The command failed.
1069 */
1070 EXTERN int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times);
1071
1072
1073 /*
1074 * UTIME()
1075 */
1076 /*
1077 * Async utime(<path>)
1078 * Function returns
1079 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1080 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1081 *
1082 * When the callback is invoked, status indicates the result:
1083 * 0 : Success.
1084 * data is NULL
1085 * -errno : An error occured.
1086 * data is the error string.
1087 */
1088 struct utimbuf;
1089 EXTERN int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
1090 /*
1091 * Sync utime(<path>)
1092 * Function returns
1093 * 0 : The operation was successfull.
1094 * -errno : The command failed.
1095 */
1096 EXTERN int nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times);
1097
1098
1099
1100
1101 /*
1102 * ACCESS()
1103 */
1104 /*
1105 * Async access(<path>)
1106 * Function returns
1107 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1108 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1109 *
1110 * When the callback is invoked, status indicates the result:
1111 * 0 : Success.
1112 * data is NULL
1113 * -errno : An error occured.
1114 * data is the error string.
1115 */
1116 EXTERN int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
1117 /*
1118 * Sync access(<path>)
1119 * Function returns
1120 * 0 : The operation was successfull.
1121 * -errno : The command failed.
1122 */
1123 EXTERN int nfs_access(struct nfs_context *nfs, const char *path, int mode);
1124
1125
1126
1127
1128 /*
1129 * SYMLINK()
1130 */
1131 /*
1132 * Async symlink(<path>)
1133 * Function returns
1134 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1135 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1136 *
1137 * When the callback is invoked, status indicates the result:
1138 * 0 : Success.
1139 * data is NULL
1140 * -errno : An error occured.
1141 * data is the error string.
1142 */
1143 EXTERN int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1144 /*
1145 * Sync symlink(<path>)
1146 * Function returns
1147 * 0 : The operation was successfull.
1148 * -errno : The command failed.
1149 */
1150 EXTERN int nfs_symlink(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1151
1152
1153 /*
1154 * RENAME()
1155 */
1156 /*
1157 * Async rename(<oldpath>, <newpath>)
1158 * Function returns
1159 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1160 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1161 *
1162 * When the callback is invoked, status indicates the result:
1163 * 0 : Success.
1164 * data is NULL
1165 * -errno : An error occured.
1166 * data is the error string.
1167 */
1168 EXTERN int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1169 /*
1170 * Sync rename(<oldpath>, <newpath>)
1171 * Function returns
1172 * 0 : The operation was successfull.
1173 * -errno : The command failed.
1174 */
1175 EXTERN int nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1176
1177
1178
1179 /*
1180 * LINK()
1181 */
1182 /*
1183 * Async link(<oldpath>, <newpath>)
1184 * Function returns
1185 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1186 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1187 *
1188 * When the callback is invoked, status indicates the result:
1189 * 0 : Success.
1190 * data is NULL
1191 * -errno : An error occured.
1192 * data is the error string.
1193 */
1194 EXTERN int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1195 /*
1196 * Sync link(<oldpath>, <newpath>)
1197 * Function returns
1198 * 0 : The operation was successfull.
1199 * -errno : The command failed.
1200 */
1201 EXTERN int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1202
1203
1204 /*
1205 * GETEXPORTS()
1206 */
1207 /*
1208 * Async getexports()
1209 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
1210 * returned structures.
1211 *
1212 * This function will return the list of exports from an NFS server.
1213 *
1214 * Function returns
1215 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1216 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1217 *
1218 * When the callback is invoked, status indicates the result:
1219 * 0 : Success.
1220 * data is a pointer to an exports pointer:
1221 * exports export = *(exports *)data;
1222 * -errno : An error occured.
1223 * data is the error string.
1224 */
1225 EXTERN int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data);
1226 /*
1227 * Sync getexports(<server>)
1228 * Function returns
1229 * NULL : something failed
1230 * exports export : a linked list of exported directories
1231 *
1232 * returned data must be freed by calling mount_free_export_list(exportnode);
1233 */
1234 EXTERN struct exportnode *mount_getexports(const char *server);
1235
1236 EXTERN void mount_free_export_list(struct exportnode *exports);
1237
1238
1239 //qqq replace later with lseek(cur, 0)
1240 uint64_t nfs_get_current_offset(struct nfsfh *nfsfh);
1241
1242
1243
1244
1245
1246 struct nfs_server_list {
1247 struct nfs_server_list *next;
1248 char *addr;
1249 };
1250
1251 /*
1252 * Sync find_local_servers(<server>)
1253 * This function will probe all local networks for NFS server. This function will
1254 * block for one second while awaiting for all nfs servers to respond.
1255 *
1256 * Function returns
1257 * NULL : something failed
1258 *
1259 * struct nfs_server_list : a linked list of all discovered servers
1260 *
1261 * returned data must be freed by nfs_free_srvr_list(srv);
1262 */
1263 struct nfs_server_list *nfs_find_local_servers(void);
1264 void free_nfs_srvr_list(struct nfs_server_list *srv);
1265
1266 #ifdef __cplusplus
1267 }
1268 #endif
1269
1270 #endif /* !_LIBNFS_H_ */