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
25 * Used for interfacing the async version of the api into an external eventsystem
27 int nfs_get_fd(struct nfs_context *nfs);
28 int nfs_which_events(struct nfs_context *nfs);
29 int nfs_service(struct nfs_context *nfs, int revents);
32 * Used if you need different credentials than the default for the current user.
35 void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth);
39 * When an operation failed, this function can extract a detailed error string.
41 char *nfs_get_error(struct nfs_context *nfs);
45 * Callback for all async nfs functions
47 typedef void (*nfs_cb)(int err, struct nfs_context *nfs, void *data, void *private_data);
56 * Create an NFS context.
58 * NULL : Failed to create a context.
59 * struct nfs_context * : A pointer to an nfs context.
61 struct nfs_context *nfs_init_context(void);
63 * Destroy an nfs context.
65 void nfs_destroy_context(struct nfs_context *nfs);
80 * This function will try to connect to the server and mount the export.
82 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
83 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
85 * When the callback is invoked, status indicates the result:
88 * -errno : An error occured.
89 * data is the error string.
91 int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *export, nfs_cb cb, void *private_data);
95 * 0 : The operation was successfull.
96 * -errno : The command failed.
98 int nfs_mount_sync(struct nfs_context *nfs, const char *server, const char *export);
107 * Async stat(<filename>)
109 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
110 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
112 * When the callback is invoked, status indicates the result:
114 * data is struct stat *
115 * -errno : An error occured.
116 * data is the error string.
119 int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
121 * Sync stat(<filename>)
123 * 0 : The operation was successfull.
124 * -errno : The command failed.
126 int nfs_stat_sync(struct nfs_context *nfs, const char *path, struct stat *st);
133 * Async fstat(nfsfh *)
135 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
136 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
138 * When the callback is invoked, status indicates the result:
140 * data is struct stat *
141 * -errno : An error occured.
142 * data is the error string.
144 int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
146 * Sync fstat(nfsfh *)
148 * 0 : The operation was successfull.
149 * -errno : The command failed.
151 int nfs_fstat_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
159 * Async open(<filename>)
161 * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
164 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
165 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
167 * When the callback is invoked, status indicates the result:
169 * data is a struct *nfsfh;
170 * The nfsfh is close using nfs_close().
171 * -errno : An error occured.
172 * data is the error string.
174 int nfs_open_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
176 * Sync open(<filename>)
178 * 0 : The operation was successfull. *nfsfh is filled in.
179 * -errno : The command failed.
181 int nfs_open_sync(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
193 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
194 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
196 * When the callback is invoked, status indicates the result:
199 * -errno : An error occured.
200 * data is the error string.
202 int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
206 * 0 : The operation was successfull.
207 * -errno : The command failed.
209 int nfs_close_sync(struct nfs_context *nfs, struct nfsfh *nfsfh);
219 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
220 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
222 * When the callback is invoked, status indicates the result:
224 * status is numer of bytes read.
225 * data is a pointer to the returned data.
226 * -errno : An error occured.
227 * data is the error string.
229 int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, nfs_cb cb, void *private_data);
233 * >=0 : numer of bytes read.
234 * -errno : An error occured.
236 int nfs_pread_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf);
247 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
248 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
250 * When the callback is invoked, status indicates the result:
252 * status is numer of bytes read.
253 * data is a pointer to the returned data.
254 * -errno : An error occured.
255 * data is the error string.
257 int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, nfs_cb cb, void *private_data);
261 * >=0 : numer of bytes read.
262 * -errno : An error occured.
264 int nfs_read_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf);
276 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
277 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
279 * When the callback is invoked, status indicates the result:
281 * status is numer of bytes written.
282 * -errno : An error occured.
283 * data is the error string.
285 int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf, nfs_cb cb, void *private_data);
289 * >=0 : numer of bytes written.
290 * -errno : An error occured.
292 int nfs_pwrite_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf);
302 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
303 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
305 * When the callback is invoked, status indicates the result:
307 * status is numer of bytes written.
308 * -errno : An error occured.
309 * data is the error string.
311 int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf, nfs_cb cb, void *private_data);
315 * >=0 : numer of bytes written.
316 * -errno : An error occured.
318 int nfs_write_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf);
328 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
329 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
331 * When the callback is invoked, status indicates the result:
333 * data is off_t * for the current position.
334 * -errno : An error occured.
335 * data is the error string.
337 int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, nfs_cb cb, void *private_data);
341 * >=0 : numer of bytes read.
342 * -errno : An error occured.
344 int nfs_lseek_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, off_t *current_offset);
354 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
355 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
357 * When the callback is invoked, status indicates the result:
359 * -errno : An error occured.
360 * data is the error string.
362 int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
367 * -errno : An error occured.
369 int nfs_fsync_sync(struct nfs_context *nfs, struct nfsfh *nfsfh);
380 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
381 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
383 * When the callback is invoked, status indicates the result:
385 * -errno : An error occured.
386 * data is the error string.
388 int nfs_truncate_async(struct nfs_context *nfs, const char *path, off_t length, nfs_cb cb, void *private_data);
393 * -errno : An error occured.
395 int nfs_truncate_sync(struct nfs_context *nfs, const char *path, off_t length);
406 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
407 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
409 * When the callback is invoked, status indicates the result:
411 * -errno : An error occured.
412 * data is the error string.
414 int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length, nfs_cb cb, void *private_data);
419 * -errno : An error occured.
421 int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length);
435 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
436 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
438 * When the callback is invoked, status indicates the result:
440 * -errno : An error occured.
441 * data is the error string.
443 int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
448 * -errno : An error occured.
450 int nfs_mkdir_sync(struct nfs_context *nfs, const char *path);
461 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
462 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
464 * When the callback is invoked, status indicates the result:
466 * -errno : An error occured.
467 * data is the error string.
469 int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
474 * -errno : An error occured.
476 int nfs_rmdir_sync(struct nfs_context *nfs, const char *path);
488 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
489 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
491 * When the callback is invoked, status indicates the result:
493 * data is a struct *nfsfh;
494 * -errno : An error occured.
495 * data is the error string.
497 int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
502 * -errno : An error occured.
504 int nfs_creat_sync(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
517 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
518 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
520 * When the callback is invoked, status indicates the result:
523 * -errno : An error occured.
524 * data is the error string.
526 int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
531 * -errno : An error occured.
533 int nfs_unlink_sync(struct nfs_context *nfs, const char *path);
546 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
547 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
549 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
551 * When the callback is invoked, status indicates the result:
553 * data is struct nfsdir *
554 * -errno : An error occured.
555 * data is the error string.
557 int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
562 * -errno : An error occured.
564 int nfs_opendir_sync(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
572 struct nfsdirent *next;
577 * nfs_readdir() never blocks, so no special sync/async versions are available
579 struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
587 * nfs_closedir() never blocks, so no special sync/async versions are available
589 void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
597 * Async statvfs(<dirname>)
599 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
600 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
602 * When the callback is invoked, status indicates the result:
604 * data is struct statvfs *
605 * -errno : An error occured.
606 * data is the error string.
609 int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
611 * Sync statvfs(<dirname>)
613 * 0 : The operation was successfull.
614 * -errno : The command failed.
616 int nfs_statvfs_sync(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
623 * Async readlink(<name>)
625 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
626 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
628 * When the callback is invoked, status indicates the result:
631 * data is only valid during the callback and is automatically freed when the callback returns.
632 * -errno : An error occured.
633 * data is the error string.
636 int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
638 * Sync readlink(<name>)
640 * 0 : The operation was successfull.
641 * -errno : The command failed.
643 int nfs_readlink_sync(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
651 * Async chmod(<name>)
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.
656 * When the callback is invoked, status indicates the result:
659 * -errno : An error occured.
660 * data is the error string.
662 int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
666 * 0 : The operation was successfull.
667 * -errno : The command failed.
669 int nfs_chmod_sync(struct nfs_context *nfs, const char *path, int mode);
677 * Async fchmod(<handle>)
679 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
680 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
682 * When the callback is invoked, status indicates the result:
685 * -errno : An error occured.
686 * data is the error string.
688 int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
690 * Sync fchmod(<handle>)
692 * 0 : The operation was successfull.
693 * -errno : The command failed.
695 int nfs_fchmod_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
703 * Async chown(<name>)
705 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
706 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
708 * When the callback is invoked, status indicates the result:
711 * -errno : An error occured.
712 * data is the error string.
714 int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
718 * 0 : The operation was successfull.
719 * -errno : The command failed.
721 int nfs_chown_sync(struct nfs_context *nfs, const char *path, int uid, int gid);
729 * Async fchown(<handle>)
731 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
732 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
734 * When the callback is invoked, status indicates the result:
737 * -errno : An error occured.
738 * data is the error string.
740 int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
742 * Sync fchown(<handle>)
744 * 0 : The operation was successfull.
745 * -errno : The command failed.
747 int nfs_fchown_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
756 * Async utimes(<path>)
758 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
759 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
761 * When the callback is invoked, status indicates the result:
764 * -errno : An error occured.
765 * data is the error string.
767 int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
769 * Sync utimes(<path>)
771 * 0 : The operation was successfull.
772 * -errno : The command failed.
774 int nfs_utimes_sync(struct nfs_context *nfs, const char *path, struct timeval *times);
781 * Async utime(<path>)
783 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
784 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
786 * When the callback is invoked, status indicates the result:
789 * -errno : An error occured.
790 * data is the error string.
793 int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
797 * 0 : The operation was successfull.
798 * -errno : The command failed.
800 int nfs_utime_sync(struct nfs_context *nfs, const char *path, struct utimbuf *times);
809 * Async access(<path>)
811 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
812 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
814 * When the callback is invoked, status indicates the result:
817 * -errno : An error occured.
818 * data is the error string.
820 int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
822 * Sync access(<path>)
824 * 0 : The operation was successfull.
825 * -errno : The command failed.
827 int nfs_access_sync(struct nfs_context *nfs, const char *path, int mode);
836 * Async symlink(<path>)
838 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
839 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
841 * When the callback is invoked, status indicates the result:
844 * -errno : An error occured.
845 * data is the error string.
847 int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
849 * Sync symlink(<path>)
851 * 0 : The operation was successfull.
852 * -errno : The command failed.
854 int nfs_symlink_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
861 * Async rename(<oldpath>, <newpath>)
863 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
864 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
866 * When the callback is invoked, status indicates the result:
869 * -errno : An error occured.
870 * data is the error string.
872 int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
874 * Sync rename(<oldpath>, <newpath>)
876 * 0 : The operation was successfull.
877 * -errno : The command failed.
879 int nfs_rename_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
887 * Async link(<oldpath>, <newpath>)
889 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
890 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
892 * When the callback is invoked, status indicates the result:
895 * -errno : An error occured.
896 * data is the error string.
898 int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
900 * Sync link(<oldpath>, <newpath>)
902 * 0 : The operation was successfull.
903 * -errno : The command failed.
905 int nfs_link_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
909 //qqq replace later with lseek(cur, 0)
910 off_t nfs_get_current_offset(struct nfsfh *nfsfh);