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