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