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