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