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