libnfs: Add lchown
[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 * Async chown(<name>)
1052 *
1053 * Like chown except if the destination is a symbolic link, it acts on the
1054 * symbolic link itself.
1055 *
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_lchown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
1067 /*
1068 * Sync chown(<name>)
1069 *
1070 * Like chown except if the destination is a symbolic link, it acts on the
1071 * symbolic link itself.
1072 *
1073 * Function returns
1074 * 0 : The operation was successfull.
1075 * -errno : The command failed.
1076 */
1077 EXTERN int nfs_lchown(struct nfs_context *nfs, const char *path, int uid, int gid);
1078
1079
1080
1081 /*
1082 * FCHOWN()
1083 */
1084 /*
1085 * Async fchown(<handle>)
1086 * Function returns
1087 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1088 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1089 *
1090 * When the callback is invoked, status indicates the result:
1091 * 0 : Success.
1092 * data is NULL
1093 * -errno : An error occured.
1094 * data is the error string.
1095 */
1096 EXTERN int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
1097 /*
1098 * Sync fchown(<handle>)
1099 * Function returns
1100 * 0 : The operation was successfull.
1101 * -errno : The command failed.
1102 */
1103 EXTERN int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
1104
1105
1106
1107
1108 /*
1109 * UTIMES()
1110 */
1111 /*
1112 * Async utimes(<path>)
1113 * Function returns
1114 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1115 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1116 *
1117 * When the callback is invoked, status indicates the result:
1118 * 0 : Success.
1119 * data is NULL
1120 * -errno : An error occured.
1121 * data is the error string.
1122 */
1123 EXTERN int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
1124 /*
1125 * Sync utimes(<path>)
1126 * Function returns
1127 * 0 : The operation was successfull.
1128 * -errno : The command failed.
1129 */
1130 EXTERN int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times);
1131
1132
1133 /*
1134 * UTIME()
1135 */
1136 /*
1137 * Async utime(<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 struct utimbuf;
1149 EXTERN int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
1150 /*
1151 * Sync utime(<path>)
1152 * Function returns
1153 * 0 : The operation was successfull.
1154 * -errno : The command failed.
1155 */
1156 EXTERN int nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times);
1157
1158
1159
1160
1161 /*
1162 * ACCESS()
1163 */
1164 /*
1165 * Async access(<path>)
1166 * Function returns
1167 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1168 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1169 *
1170 * When the callback is invoked, status indicates the result:
1171 * 0 : Success.
1172 * data is NULL
1173 * -errno : An error occured.
1174 * data is the error string.
1175 */
1176 EXTERN int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
1177 /*
1178 * Sync access(<path>)
1179 * Function returns
1180 * 0 : The operation was successfull.
1181 * -errno : The command failed.
1182 */
1183 EXTERN int nfs_access(struct nfs_context *nfs, const char *path, int mode);
1184
1185
1186
1187
1188 /*
1189 * SYMLINK()
1190 */
1191 /*
1192 * Async symlink(<path>)
1193 * Function returns
1194 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1195 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1196 *
1197 * When the callback is invoked, status indicates the result:
1198 * 0 : Success.
1199 * data is NULL
1200 * -errno : An error occured.
1201 * data is the error string.
1202 */
1203 EXTERN int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1204 /*
1205 * Sync symlink(<path>)
1206 * Function returns
1207 * 0 : The operation was successfull.
1208 * -errno : The command failed.
1209 */
1210 EXTERN int nfs_symlink(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1211
1212
1213 /*
1214 * RENAME()
1215 */
1216 /*
1217 * Async rename(<oldpath>, <newpath>)
1218 * Function returns
1219 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1220 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1221 *
1222 * When the callback is invoked, status indicates the result:
1223 * 0 : Success.
1224 * data is NULL
1225 * -errno : An error occured.
1226 * data is the error string.
1227 */
1228 EXTERN int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1229 /*
1230 * Sync rename(<oldpath>, <newpath>)
1231 * Function returns
1232 * 0 : The operation was successfull.
1233 * -errno : The command failed.
1234 */
1235 EXTERN int nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1236
1237
1238
1239 /*
1240 * LINK()
1241 */
1242 /*
1243 * Async link(<oldpath>, <newpath>)
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 NULL
1251 * -errno : An error occured.
1252 * data is the error string.
1253 */
1254 EXTERN int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1255 /*
1256 * Sync link(<oldpath>, <newpath>)
1257 * Function returns
1258 * 0 : The operation was successfull.
1259 * -errno : The command failed.
1260 */
1261 EXTERN int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1262
1263
1264 /*
1265 * GETEXPORTS()
1266 */
1267 /*
1268 * Async getexports()
1269 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
1270 * returned structures.
1271 *
1272 * This function will return the list of exports from an NFS server.
1273 *
1274 * Function returns
1275 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1276 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1277 *
1278 * When the callback is invoked, status indicates the result:
1279 * 0 : Success.
1280 * data is a pointer to an exports pointer:
1281 * exports export = *(exports *)data;
1282 * -errno : An error occured.
1283 * data is the error string.
1284 */
1285 EXTERN int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data);
1286 /*
1287 * Sync getexports(<server>)
1288 * Function returns
1289 * NULL : something failed
1290 * exports export : a linked list of exported directories
1291 *
1292 * returned data must be freed by calling mount_free_export_list(exportnode);
1293 */
1294 EXTERN struct exportnode *mount_getexports(const char *server);
1295
1296 EXTERN void mount_free_export_list(struct exportnode *exports);
1297
1298
1299 //qqq replace later with lseek(cur, 0)
1300 uint64_t nfs_get_current_offset(struct nfsfh *nfsfh);
1301
1302
1303
1304
1305
1306 struct nfs_server_list {
1307 struct nfs_server_list *next;
1308 char *addr;
1309 };
1310
1311 /*
1312 * Sync find_local_servers(<server>)
1313 * This function will probe all local networks for NFS server. This function will
1314 * block for one second while awaiting for all nfs servers to respond.
1315 *
1316 * Function returns
1317 * NULL : something failed
1318 *
1319 * struct nfs_server_list : a linked list of all discovered servers
1320 *
1321 * returned data must be freed by nfs_free_srvr_list(srv);
1322 */
1323 struct nfs_server_list *nfs_find_local_servers(void);
1324 void free_nfs_srvr_list(struct nfs_server_list *srv);
1325
1326 #ifdef __cplusplus
1327 }
1328 #endif
1329
1330 #endif /* !_LIBNFS_H_ */