2debb8b7660e9a6130e1b50bd920c47a9081e478
2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
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.
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.
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/>.
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 c, the context.
58 * NULL : Failed to create a context.
59 * *nfs : 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
);
77 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
78 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
80 * When the callback is invoked, status indicates the result:
83 * -errno : An error occured.
84 * data is the error string.
86 int nfs_mount_async(struct nfs_context
*nfs
, const char *server
, const char *export
, nfs_cb cb
, void *private_data
);
90 * 0 : The operation was successfull.
91 * -errno : The command failed.
93 int nfs_mount_sync(struct nfs_context
*nfs
, const char *server
, const char *export
);
102 * Async stat(<filename>)
104 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
105 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
107 * When the callback is invoked, status indicates the result:
109 * data is struct stat *
110 * -errno : An error occured.
111 * data is the error string.
114 int nfs_stat_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
116 * Sync stat(<filename>)
118 * 0 : The operation was successfull.
119 * -errno : The command failed.
121 int nfs_stat_sync(struct nfs_context
*nfs
, const char *path
, struct stat
*st
);
128 * Async fstat(nfsfh *)
130 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
131 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
133 * When the callback is invoked, status indicates the result:
135 * data is struct stat *
136 * -errno : An error occured.
137 * data is the error string.
139 int nfs_fstat_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
141 * Sync fstat(nfsfh *)
143 * 0 : The operation was successfull.
144 * -errno : The command failed.
146 int nfs_fstat_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, struct stat
*st
);
154 * Async open(<filename>)
156 * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
159 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
160 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
162 * When the callback is invoked, status indicates the result:
164 * data is a struct *nfsfh;
165 * The nfsfh is close using nfs_close().
166 * -errno : An error occured.
167 * data is the error string.
169 int nfs_open_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
171 * Sync stat(<filename>)
173 * 0 : The operation was successfull. *nfsfh is filled in.
174 * -errno : The command failed.
176 int nfs_open_sync(struct nfs_context
*nfs
, const char *path
, int mode
, struct nfsfh
**nfsfh
);
188 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
189 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
191 * When the callback is invoked, status indicates the result:
194 * -errno : An error occured.
195 * data is the error string.
197 int nfs_close_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
201 * 0 : The operation was successfull.
202 * -errno : The command failed.
204 int nfs_close_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
);
214 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
215 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
217 * When the callback is invoked, status indicates the result:
219 * status is numer of bytes read.
220 * data is a pointer to the returned data.
221 * -errno : An error occured.
222 * data is the error string.
224 int nfs_pread_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, nfs_cb cb
, void *private_data
);
228 * >=0 : numer of bytes read.
229 * -errno : An error occured.
231 int nfs_pread_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, char *buf
);
242 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
243 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
245 * When the callback is invoked, status indicates the result:
247 * status is numer of bytes read.
248 * data is a pointer to the returned data.
249 * -errno : An error occured.
250 * data is the error string.
252 int nfs_read_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, nfs_cb cb
, void *private_data
);
256 * >=0 : numer of bytes read.
257 * -errno : An error occured.
259 int nfs_read_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
);
271 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
272 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
274 * When the callback is invoked, status indicates the result:
276 * status is numer of bytes written.
277 * -errno : An error occured.
278 * data is the error string.
280 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
);
284 * >=0 : numer of bytes written.
285 * -errno : An error occured.
287 int nfs_pwrite_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, char *buf
);
297 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
298 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
300 * When the callback is invoked, status indicates the result:
302 * status is numer of bytes written.
303 * -errno : An error occured.
304 * data is the error string.
306 int nfs_write_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
, nfs_cb cb
, void *private_data
);
310 * >=0 : numer of bytes written.
311 * -errno : An error occured.
313 int nfs_write_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
);
323 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
324 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
326 * When the callback is invoked, status indicates the result:
328 * data is off_t * for the current position.
329 * -errno : An error occured.
330 * data is the error string.
332 int nfs_lseek_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, int whence
, nfs_cb cb
, void *private_data
);
336 * >=0 : numer of bytes read.
337 * -errno : An error occured.
339 int nfs_lseek_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, int whence
, off_t
*current_offset
);
349 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
350 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
352 * When the callback is invoked, status indicates the result:
354 * -errno : An error occured.
355 * data is the error string.
357 int nfs_fsync_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
362 * -errno : An error occured.
364 int nfs_fsync_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
);
375 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
376 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
378 * When the callback is invoked, status indicates the result:
380 * -errno : An error occured.
381 * data is the error string.
383 int nfs_truncate_async(struct nfs_context
*nfs
, const char *path
, off_t length
, nfs_cb cb
, void *private_data
);
388 * -errno : An error occured.
390 int nfs_truncate_sync(struct nfs_context
*nfs
, const char *path
, off_t length
);
401 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
402 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
404 * When the callback is invoked, status indicates the result:
406 * -errno : An error occured.
407 * data is the error string.
409 int nfs_ftruncate_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t length
, nfs_cb cb
, void *private_data
);
414 * -errno : An error occured.
416 int nfs_ftruncate_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t length
);
430 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
431 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
433 * When the callback is invoked, status indicates the result:
435 * -errno : An error occured.
436 * data is the error string.
438 int nfs_mkdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
443 * -errno : An error occured.
445 int nfs_mkdir_sync(struct nfs_context
*nfs
, const char *path
);
456 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
457 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
459 * When the callback is invoked, status indicates the result:
461 * -errno : An error occured.
462 * data is the error string.
464 int nfs_rmdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
469 * -errno : An error occured.
471 int nfs_rmdir_sync(struct nfs_context
*nfs
, const char *path
);
483 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
484 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
486 * When the callback is invoked, status indicates the result:
488 * data is a struct *nfsfh;
489 * -errno : An error occured.
490 * data is the error string.
492 int nfs_creat_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
497 * -errno : An error occured.
499 int nfs_creat_sync(struct nfs_context
*nfs
, const char *path
, int mode
, struct nfsfh
**nfsfh
);
512 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
513 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
515 * When the callback is invoked, status indicates the result:
518 * -errno : An error occured.
519 * data is the error string.
521 int nfs_unlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
526 * -errno : An error occured.
528 int nfs_unlink_sync(struct nfs_context
*nfs
, const char *path
);
541 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
542 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
544 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
546 * When the callback is invoked, status indicates the result:
548 * data is struct nfsdir *
549 * -errno : An error occured.
550 * data is the error string.
552 int nfs_opendir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
557 * -errno : An error occured.
559 int nfs_opendir_sync(struct nfs_context
*nfs
, const char *path
, struct nfsdir
**nfsdir
);
567 struct nfsdirent
*next
;
572 * nfs_readdir() never blocks, so no special sync/async versions are available
574 struct nfsdirent
*nfs_readdir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
582 * nfs_closedir() never blocks, so no special sync/async versions are available
584 void nfs_closedir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
592 * Async statvfs(<dirname>)
594 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
595 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
597 * When the callback is invoked, status indicates the result:
599 * data is struct statvfs *
600 * -errno : An error occured.
601 * data is the error string.
604 int nfs_statvfs_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
606 * Sync statvfs(<dirname>)
608 * 0 : The operation was successfull.
609 * -errno : The command failed.
611 int nfs_statvfs_sync(struct nfs_context
*nfs
, const char *path
, struct statvfs
*svfs
);
618 * Async readlink(<name>)
620 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
621 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
623 * When the callback is invoked, status indicates the result:
626 * data is only valid during the callback and is automatically freed when the callback returns.
627 * -errno : An error occured.
628 * data is the error string.
631 int nfs_readlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
633 * Sync readlink(<name>)
635 * 0 : The operation was successfull.
636 * -errno : The command failed.
638 int nfs_readlink_sync(struct nfs_context
*nfs
, const char *path
, char *buf
, int bufsize
);
646 * Async chmod(<name>)
648 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
649 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
651 * When the callback is invoked, status indicates the result:
654 * -errno : An error occured.
655 * data is the error string.
657 int nfs_chmod_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
661 * 0 : The operation was successfull.
662 * -errno : The command failed.
664 int nfs_chmod_sync(struct nfs_context
*nfs
, const char *path
, int mode
);
672 * Async fchmod(<handle>)
674 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
675 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
677 * When the callback is invoked, status indicates the result:
680 * -errno : An error occured.
681 * data is the error string.
683 int nfs_fchmod_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
, nfs_cb cb
, void *private_data
);
685 * Sync fchmod(<handle>)
687 * 0 : The operation was successfull.
688 * -errno : The command failed.
690 int nfs_fchmod_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
);
698 * Async chown(<name>)
700 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
701 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
703 * When the callback is invoked, status indicates the result:
706 * -errno : An error occured.
707 * data is the error string.
709 int nfs_chown_async(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
713 * 0 : The operation was successfull.
714 * -errno : The command failed.
716 int nfs_chown_sync(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
);
724 * Async fchown(<handle>)
726 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
727 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
729 * When the callback is invoked, status indicates the result:
732 * -errno : An error occured.
733 * data is the error string.
735 int nfs_fchown_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
737 * Sync fchown(<handle>)
739 * 0 : The operation was successfull.
740 * -errno : The command failed.
742 int nfs_fchown_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
);
751 * Async utimes(<path>)
753 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
754 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
756 * When the callback is invoked, status indicates the result:
759 * -errno : An error occured.
760 * data is the error string.
762 int nfs_utimes_async(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
, nfs_cb cb
, void *private_data
);
764 * Sync utimes(<path>)
766 * 0 : The operation was successfull.
767 * -errno : The command failed.
769 int nfs_utimes_sync(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
);
776 * Async utime(<path>)
778 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
779 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
781 * When the callback is invoked, status indicates the result:
784 * -errno : An error occured.
785 * data is the error string.
788 int nfs_utime_async(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
, nfs_cb cb
, void *private_data
);
792 * 0 : The operation was successfull.
793 * -errno : The command failed.
795 int nfs_utime_sync(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
);
804 * Async access(<path>)
806 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
807 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
809 * When the callback is invoked, status indicates the result:
812 * -errno : An error occured.
813 * data is the error string.
815 int nfs_access_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
817 * Sync access(<path>)
819 * 0 : The operation was successfull.
820 * -errno : The command failed.
822 int nfs_access_sync(struct nfs_context
*nfs
, const char *path
, int mode
);
831 * Async symlink(<path>)
833 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
834 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
836 * When the callback is invoked, status indicates the result:
839 * -errno : An error occured.
840 * data is the error string.
842 int nfs_symlink_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
844 * Sync symlink(<path>)
846 * 0 : The operation was successfull.
847 * -errno : The command failed.
849 int nfs_symlink_sync(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
856 * Async rename(<oldpath>, <newpath>)
858 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
859 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
861 * When the callback is invoked, status indicates the result:
864 * -errno : An error occured.
865 * data is the error string.
867 int nfs_rename_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
869 * Sync rename(<oldpath>, <newpath>)
871 * 0 : The operation was successfull.
872 * -errno : The command failed.
874 int nfs_rename_sync(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
882 * Async link(<oldpath>, <newpath>)
884 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
885 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
887 * When the callback is invoked, status indicates the result:
890 * -errno : An error occured.
891 * data is the error string.
893 int nfs_link_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
895 * Sync link(<oldpath>, <newpath>)
897 * 0 : The operation was successfull.
898 * -errno : The command failed.
900 int nfs_link_sync(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
904 //qqq replace later with lseek(cur, 0)
905 off_t
nfs_get_current_offset(struct nfsfh
*nfsfh
);