2 Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
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 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
18 * This is the highlevel interface to access NFS resources using a posix-like interface
20 #include <sys/types.h>
23 typedef uint64_t nfs_off_t;
28 * Used for interfacing the async version of the api into an external eventsystem
30 int nfs_get_fd(struct nfs_context *nfs);
31 int nfs_which_events(struct nfs_context *nfs);
32 int nfs_service(struct nfs_context *nfs, int revents);
35 * Used if you need different credentials than the default for the current user.
38 void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth);
42 * When an operation failed, this function can extract a detailed error string.
44 char *nfs_get_error(struct nfs_context *nfs);
48 * Callback for all async nfs functions
50 typedef void (*nfs_cb)(int err, struct nfs_context *nfs, void *data, void *private_data);
59 * Create an NFS context.
61 * NULL : Failed to create a context.
62 * struct nfs_context * : A pointer to an nfs context.
64 struct nfs_context *nfs_init_context(void);
66 * Destroy an nfs context.
68 void nfs_destroy_context(struct nfs_context *nfs);
83 * This function will try to connect to the server and mount the export.
85 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
86 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
88 * When the callback is invoked, status indicates the result:
91 * -errno : An error occured.
92 * data is the error string.
94 int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *export, nfs_cb cb, void *private_data);
98 * 0 : The operation was successfull.
99 * -errno : The command failed.
101 int nfs_mount_sync(struct nfs_context *nfs, const char *server, const char *export);
110 * Async stat(<filename>)
112 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
113 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
115 * When the callback is invoked, status indicates the result:
117 * data is struct stat *
118 * -errno : An error occured.
119 * data is the error string.
122 int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
124 * Sync stat(<filename>)
126 * 0 : The operation was successfull.
127 * -errno : The command failed.
129 int nfs_stat_sync(struct nfs_context *nfs, const char *path, struct stat *st);
136 * Async fstat(nfsfh *)
138 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
139 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
141 * When the callback is invoked, status indicates the result:
143 * data is struct stat *
144 * -errno : An error occured.
145 * data is the error string.
147 int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
149 * Sync fstat(nfsfh *)
151 * 0 : The operation was successfull.
152 * -errno : The command failed.
154 int nfs_fstat_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
162 * Async open(<filename>)
164 * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
167 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
168 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
170 * When the callback is invoked, status indicates the result:
172 * data is a struct *nfsfh;
173 * The nfsfh is close using nfs_close().
174 * -errno : An error occured.
175 * data is the error string.
177 int nfs_open_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
179 * Sync open(<filename>)
181 * 0 : The operation was successfull. *nfsfh is filled in.
182 * -errno : The command failed.
184 int nfs_open_sync(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
196 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
197 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
199 * When the callback is invoked, status indicates the result:
202 * -errno : An error occured.
203 * data is the error string.
205 int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
209 * 0 : The operation was successfull.
210 * -errno : The command failed.
212 int nfs_close_sync(struct nfs_context *nfs, struct nfsfh *nfsfh);
222 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
223 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
225 * When the callback is invoked, status indicates the result:
227 * status is numer of bytes read.
228 * data is a pointer to the returned data.
229 * -errno : An error occured.
230 * data is the error string.
232 int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, nfs_cb cb, void *private_data);
236 * >=0 : numer of bytes read.
237 * -errno : An error occured.
239 int nfs_pread_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf);
250 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
251 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
253 * When the callback is invoked, status indicates the result:
255 * status is numer of bytes read.
256 * data is a pointer to the returned data.
257 * -errno : An error occured.
258 * data is the error string.
260 int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, nfs_cb cb, void *private_data);
264 * >=0 : numer of bytes read.
265 * -errno : An error occured.
267 int nfs_read_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf);
279 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
280 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
282 * When the callback is invoked, status indicates the result:
284 * status is numer of bytes written.
285 * -errno : An error occured.
286 * data is the error string.
288 int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf, nfs_cb cb, void *private_data);
292 * >=0 : numer of bytes written.
293 * -errno : An error occured.
295 int nfs_pwrite_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf);
305 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
306 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
308 * When the callback is invoked, status indicates the result:
310 * status is numer of bytes written.
311 * -errno : An error occured.
312 * data is the error string.
314 int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf, nfs_cb cb, void *private_data);
318 * >=0 : numer of bytes written.
319 * -errno : An error occured.
321 int nfs_write_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf);
331 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
332 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
334 * When the callback is invoked, status indicates the result:
336 * data is nfs_off_t * for the current position.
337 * -errno : An error occured.
338 * data is the error string.
340 int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, int whence, nfs_cb cb, void *private_data);
344 * >=0 : numer of bytes read.
345 * -errno : An error occured.
347 int nfs_lseek_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, int whence, nfs_off_t *current_offset);
357 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
358 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
360 * When the callback is invoked, status indicates the result:
362 * -errno : An error occured.
363 * data is the error string.
365 int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
370 * -errno : An error occured.
372 int nfs_fsync_sync(struct nfs_context *nfs, struct nfsfh *nfsfh);
383 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
384 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
386 * When the callback is invoked, status indicates the result:
388 * -errno : An error occured.
389 * data is the error string.
391 int nfs_truncate_async(struct nfs_context *nfs, const char *path, nfs_off_t length, nfs_cb cb, void *private_data);
396 * -errno : An error occured.
398 int nfs_truncate_sync(struct nfs_context *nfs, const char *path, nfs_off_t length);
409 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
410 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
412 * When the callback is invoked, status indicates the result:
414 * -errno : An error occured.
415 * data is the error string.
417 int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t length, nfs_cb cb, void *private_data);
422 * -errno : An error occured.
424 int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t length);
438 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
439 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
441 * When the callback is invoked, status indicates the result:
443 * -errno : An error occured.
444 * data is the error string.
446 int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
451 * -errno : An error occured.
453 int nfs_mkdir_sync(struct nfs_context *nfs, const char *path);
464 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
465 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
467 * When the callback is invoked, status indicates the result:
469 * -errno : An error occured.
470 * data is the error string.
472 int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
477 * -errno : An error occured.
479 int nfs_rmdir_sync(struct nfs_context *nfs, const char *path);
491 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
492 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
494 * When the callback is invoked, status indicates the result:
496 * data is a struct *nfsfh;
497 * -errno : An error occured.
498 * data is the error string.
500 int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
505 * -errno : An error occured.
507 int nfs_creat_sync(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
520 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
521 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
523 * When the callback is invoked, status indicates the result:
526 * -errno : An error occured.
527 * data is the error string.
529 int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
534 * -errno : An error occured.
536 int nfs_unlink_sync(struct nfs_context *nfs, const char *path);
549 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
550 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
552 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
554 * When the callback is invoked, status indicates the result:
556 * data is struct nfsdir *
557 * -errno : An error occured.
558 * data is the error string.
560 int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
565 * -errno : An error occured.
567 int nfs_opendir_sync(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
575 struct nfsdirent *next;
580 * nfs_readdir() never blocks, so no special sync/async versions are available
582 struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
590 * nfs_closedir() never blocks, so no special sync/async versions are available
592 void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
600 * Async statvfs(<dirname>)
602 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
603 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
605 * When the callback is invoked, status indicates the result:
607 * data is struct statvfs *
608 * -errno : An error occured.
609 * data is the error string.
612 int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
614 * Sync statvfs(<dirname>)
616 * 0 : The operation was successfull.
617 * -errno : The command failed.
619 int nfs_statvfs_sync(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
626 * Async readlink(<name>)
628 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
629 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
631 * When the callback is invoked, status indicates the result:
634 * data is only valid during the callback and is automatically freed when the callback returns.
635 * -errno : An error occured.
636 * data is the error string.
639 int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
641 * Sync readlink(<name>)
643 * 0 : The operation was successfull.
644 * -errno : The command failed.
646 int nfs_readlink_sync(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
654 * Async chmod(<name>)
656 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
657 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
659 * When the callback is invoked, status indicates the result:
662 * -errno : An error occured.
663 * data is the error string.
665 int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
669 * 0 : The operation was successfull.
670 * -errno : The command failed.
672 int nfs_chmod_sync(struct nfs_context *nfs, const char *path, int mode);
680 * Async fchmod(<handle>)
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.
685 * When the callback is invoked, status indicates the result:
688 * -errno : An error occured.
689 * data is the error string.
691 int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
693 * Sync fchmod(<handle>)
695 * 0 : The operation was successfull.
696 * -errno : The command failed.
698 int nfs_fchmod_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
706 * Async chown(<name>)
708 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
709 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
711 * When the callback is invoked, status indicates the result:
714 * -errno : An error occured.
715 * data is the error string.
717 int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
721 * 0 : The operation was successfull.
722 * -errno : The command failed.
724 int nfs_chown_sync(struct nfs_context *nfs, const char *path, int uid, int gid);
732 * Async fchown(<handle>)
734 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
735 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
737 * When the callback is invoked, status indicates the result:
740 * -errno : An error occured.
741 * data is the error string.
743 int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
745 * Sync fchown(<handle>)
747 * 0 : The operation was successfull.
748 * -errno : The command failed.
750 int nfs_fchown_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
759 * Async utimes(<path>)
761 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
762 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
764 * When the callback is invoked, status indicates the result:
767 * -errno : An error occured.
768 * data is the error string.
770 int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
772 * Sync utimes(<path>)
774 * 0 : The operation was successfull.
775 * -errno : The command failed.
777 int nfs_utimes_sync(struct nfs_context *nfs, const char *path, struct timeval *times);
784 * Async utime(<path>)
786 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
787 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
789 * When the callback is invoked, status indicates the result:
792 * -errno : An error occured.
793 * data is the error string.
796 int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
800 * 0 : The operation was successfull.
801 * -errno : The command failed.
803 int nfs_utime_sync(struct nfs_context *nfs, const char *path, struct utimbuf *times);
812 * Async access(<path>)
814 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
815 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
817 * When the callback is invoked, status indicates the result:
820 * -errno : An error occured.
821 * data is the error string.
823 int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
825 * Sync access(<path>)
827 * 0 : The operation was successfull.
828 * -errno : The command failed.
830 int nfs_access_sync(struct nfs_context *nfs, const char *path, int mode);
839 * Async symlink(<path>)
841 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
842 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
844 * When the callback is invoked, status indicates the result:
847 * -errno : An error occured.
848 * data is the error string.
850 int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
852 * Sync symlink(<path>)
854 * 0 : The operation was successfull.
855 * -errno : The command failed.
857 int nfs_symlink_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
864 * Async rename(<oldpath>, <newpath>)
866 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
867 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
869 * When the callback is invoked, status indicates the result:
872 * -errno : An error occured.
873 * data is the error string.
875 int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
877 * Sync rename(<oldpath>, <newpath>)
879 * 0 : The operation was successfull.
880 * -errno : The command failed.
882 int nfs_rename_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
890 * Async link(<oldpath>, <newpath>)
892 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
893 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
895 * When the callback is invoked, status indicates the result:
898 * -errno : An error occured.
899 * data is the error string.
901 int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
903 * Sync link(<oldpath>, <newpath>)
905 * 0 : The operation was successfull.
906 * -errno : The command failed.
908 int nfs_link_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
912 //qqq replace later with lseek(cur, 0)
913 nfs_off_t nfs_get_current_offset(struct nfsfh *nfsfh);