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