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
26 * Used for interfacing the async version of the api into an external eventsystem
28 int nfs_get_fd(struct nfs_context
*nfs
);
29 int nfs_which_events(struct nfs_context
*nfs
);
30 int nfs_service(struct nfs_context
*nfs
, int revents
);
33 * Used if you need different credentials than the default for the current user.
36 void nfs_set_auth(struct nfs_context
*nfs
, struct AUTH
*auth
);
40 * When an operation failed, this function can extract a detailed error string.
42 char *nfs_get_error(struct nfs_context
*nfs
);
46 * Callback for all ASYNC nfs functions
48 typedef void (*nfs_cb
)(int err
, struct nfs_context
*nfs
, void *data
, void *private_data
);
51 * Callback for all ASYNC rpc functions
53 typedef void (*rpc_cb
)(struct rpc_context
*rpc
, int status
, void *data
, void *private_data
);
61 * Create an NFS c, the context.
63 * NULL : Failed to create a context.
64 * *nfs : A pointer to an nfs context.
66 struct nfs_context
*nfs_init_context(void);
68 * Destroy an nfs context.
70 void nfs_destroy_context(struct nfs_context
*nfs
);
76 * Get the maximum supported READ3 size by the server
78 size_t nfs_get_readmax(struct nfs_context
*nfs
);
81 * Get the maximum supported WRITE3 size by the server
83 size_t nfs_get_writemax(struct nfs_context
*nfs
);
92 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
93 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
95 * When the callback is invoked, status indicates the result:
98 * -errno : An error occured.
99 * data is the error string.
101 int nfs_mount_async(struct nfs_context
*nfs
, const char *server
, const char *exportname
, nfs_cb cb
, void *private_data
);
105 * 0 : The operation was successfull.
106 * -errno : The command failed.
108 int nfs_mount(struct nfs_context
*nfs
, const char *server
, const char *exportname
);
117 * Async stat(<filename>)
119 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
120 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
122 * When the callback is invoked, status indicates the result:
124 * data is struct stat *
125 * -errno : An error occured.
126 * data is the error string.
129 int nfs_stat_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
131 * Sync stat(<filename>)
133 * 0 : The operation was successfull.
134 * -errno : The command failed.
136 int nfs_stat(struct nfs_context
*nfs
, const char *path
, struct stat
*st
);
143 * Async fstat(nfsfh *)
145 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
146 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
148 * When the callback is invoked, status indicates the result:
150 * data is struct stat *
151 * -errno : An error occured.
152 * data is the error string.
154 int nfs_fstat_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
156 * Sync fstat(nfsfh *)
158 * 0 : The operation was successfull.
159 * -errno : The command failed.
161 int nfs_fstat(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, struct stat
*st
);
169 * Async open(<filename>)
171 * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
174 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
175 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
177 * When the callback is invoked, status indicates the result:
179 * data is a struct *nfsfh;
180 * The nfsfh is close using nfs_close().
181 * -errno : An error occured.
182 * data is the error string.
184 int nfs_open_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
186 * Sync stat(<filename>)
188 * 0 : The operation was successfull. *nfsfh is filled in.
189 * -errno : The command failed.
191 int nfs_open(struct nfs_context
*nfs
, const char *path
, int mode
, struct nfsfh
**nfsfh
);
203 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
204 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
206 * When the callback is invoked, status indicates the result:
209 * -errno : An error occured.
210 * data is the error string.
212 int nfs_close_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
216 * 0 : The operation was successfull.
217 * -errno : The command failed.
219 int nfs_close(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
);
229 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
230 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
232 * When the callback is invoked, status indicates the result:
234 * status is numer of bytes read.
235 * data is a pointer to the returned data.
236 * -errno : An error occured.
237 * data is the error string.
239 int nfs_pread_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, nfs_cb cb
, void *private_data
);
243 * >=0 : numer of bytes read.
244 * -errno : An error occured.
246 int nfs_pread(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, char *buf
);
257 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
258 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
260 * When the callback is invoked, status indicates the result:
262 * status is numer of bytes read.
263 * data is a pointer to the returned data.
264 * -errno : An error occured.
265 * data is the error string.
267 int nfs_read_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, nfs_cb cb
, void *private_data
);
271 * >=0 : numer of bytes read.
272 * -errno : An error occured.
274 int nfs_read(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
);
286 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
287 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
289 * When the callback is invoked, status indicates the result:
291 * status is numer of bytes written.
292 * -errno : An error occured.
293 * data is the error string.
295 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
);
299 * >=0 : numer of bytes written.
300 * -errno : An error occured.
302 int nfs_pwrite(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, char *buf
);
312 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
313 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
315 * When the callback is invoked, status indicates the result:
317 * status is numer of bytes written.
318 * -errno : An error occured.
319 * data is the error string.
321 int nfs_write_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
, nfs_cb cb
, void *private_data
);
325 * >=0 : numer of bytes written.
326 * -errno : An error occured.
328 int nfs_write(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
);
338 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
339 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
341 * When the callback is invoked, status indicates the result:
343 * data is off_t * for the current position.
344 * -errno : An error occured.
345 * data is the error string.
347 int nfs_lseek_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, int whence
, nfs_cb cb
, void *private_data
);
351 * >=0 : numer of bytes read.
352 * -errno : An error occured.
354 int nfs_lseek(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, int whence
, off_t
*current_offset
);
364 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
365 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
367 * When the callback is invoked, status indicates the result:
369 * -errno : An error occured.
370 * data is the error string.
372 int nfs_fsync_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
377 * -errno : An error occured.
379 int nfs_fsync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
);
390 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
391 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
393 * When the callback is invoked, status indicates the result:
395 * -errno : An error occured.
396 * data is the error string.
398 int nfs_truncate_async(struct nfs_context
*nfs
, const char *path
, off_t length
, nfs_cb cb
, void *private_data
);
403 * -errno : An error occured.
405 int nfs_truncate(struct nfs_context
*nfs
, const char *path
, off_t length
);
416 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
417 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
419 * When the callback is invoked, status indicates the result:
421 * -errno : An error occured.
422 * data is the error string.
424 int nfs_ftruncate_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t length
, nfs_cb cb
, void *private_data
);
429 * -errno : An error occured.
431 int nfs_ftruncate(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t length
);
445 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
446 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
448 * When the callback is invoked, status indicates the result:
450 * -errno : An error occured.
451 * data is the error string.
453 int nfs_mkdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
458 * -errno : An error occured.
460 int nfs_mkdir(struct nfs_context
*nfs
, const char *path
);
471 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
472 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
474 * When the callback is invoked, status indicates the result:
476 * -errno : An error occured.
477 * data is the error string.
479 int nfs_rmdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
484 * -errno : An error occured.
486 int nfs_rmdir(struct nfs_context
*nfs
, const char *path
);
498 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
499 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
501 * When the callback is invoked, status indicates the result:
503 * data is a struct *nfsfh;
504 * -errno : An error occured.
505 * data is the error string.
507 int nfs_creat_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
512 * -errno : An error occured.
514 int nfs_creat(struct nfs_context
*nfs
, const char *path
, int mode
, struct nfsfh
**nfsfh
);
527 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
528 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
530 * When the callback is invoked, status indicates the result:
533 * -errno : An error occured.
534 * data is the error string.
536 int nfs_unlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
541 * -errno : An error occured.
543 int nfs_unlink(struct nfs_context
*nfs
, const char *path
);
556 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
557 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
559 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
561 * When the callback is invoked, status indicates the result:
563 * data is struct nfsdir *
564 * -errno : An error occured.
565 * data is the error string.
567 int nfs_opendir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
572 * -errno : An error occured.
574 int nfs_opendir(struct nfs_context
*nfs
, const char *path
, struct nfsdir
**nfsdir
);
582 struct nfsdirent
*next
;
587 * nfs_readdir() never blocks, so no special sync/async versions are available
589 struct nfsdirent
*nfs_readdir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
597 * nfs_closedir() never blocks, so no special sync/async versions are available
599 void nfs_closedir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
607 * Async statvfs(<dirname>)
609 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
610 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
612 * When the callback is invoked, status indicates the result:
614 * data is struct statvfs *
615 * -errno : An error occured.
616 * data is the error string.
619 int nfs_statvfs_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
621 * Sync statvfs(<dirname>)
623 * 0 : The operation was successfull.
624 * -errno : The command failed.
626 int nfs_statvfs(struct nfs_context
*nfs
, const char *path
, struct statvfs
*svfs
);
633 * Async readlink(<name>)
635 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
636 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
638 * When the callback is invoked, status indicates the result:
641 * data is only valid during the callback and is automatically freed when the callback returns.
642 * -errno : An error occured.
643 * data is the error string.
646 int nfs_readlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
648 * Sync readlink(<name>)
650 * 0 : The operation was successfull.
651 * -errno : The command failed.
653 int nfs_readlink(struct nfs_context
*nfs
, const char *path
, char *buf
, int bufsize
);
661 * Async chmod(<name>)
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.
666 * When the callback is invoked, status indicates the result:
669 * -errno : An error occured.
670 * data is the error string.
672 int nfs_chmod_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
676 * 0 : The operation was successfull.
677 * -errno : The command failed.
679 int nfs_chmod(struct nfs_context
*nfs
, const char *path
, int mode
);
687 * Async fchmod(<handle>)
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.
692 * When the callback is invoked, status indicates the result:
695 * -errno : An error occured.
696 * data is the error string.
698 int nfs_fchmod_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
, nfs_cb cb
, void *private_data
);
700 * Sync fchmod(<handle>)
702 * 0 : The operation was successfull.
703 * -errno : The command failed.
705 int nfs_fchmod(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
);
713 * Async chown(<name>)
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.
718 * When the callback is invoked, status indicates the result:
721 * -errno : An error occured.
722 * data is the error string.
724 int nfs_chown_async(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
728 * 0 : The operation was successfull.
729 * -errno : The command failed.
731 int nfs_chown(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
);
739 * Async fchown(<handle>)
741 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
742 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
744 * When the callback is invoked, status indicates the result:
747 * -errno : An error occured.
748 * data is the error string.
750 int nfs_fchown_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
752 * Sync fchown(<handle>)
754 * 0 : The operation was successfull.
755 * -errno : The command failed.
757 int nfs_fchown(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
);
766 * Async utimes(<path>)
768 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
769 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
771 * When the callback is invoked, status indicates the result:
774 * -errno : An error occured.
775 * data is the error string.
777 int nfs_utimes_async(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
, nfs_cb cb
, void *private_data
);
779 * Sync utimes(<path>)
781 * 0 : The operation was successfull.
782 * -errno : The command failed.
784 int nfs_utimes(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
);
791 * Async utime(<path>)
793 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
794 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
796 * When the callback is invoked, status indicates the result:
799 * -errno : An error occured.
800 * data is the error string.
803 int nfs_utime_async(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
, nfs_cb cb
, void *private_data
);
807 * 0 : The operation was successfull.
808 * -errno : The command failed.
810 int nfs_utime(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
);
819 * Async access(<path>)
821 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
822 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
824 * When the callback is invoked, status indicates the result:
827 * -errno : An error occured.
828 * data is the error string.
830 int nfs_access_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
832 * Sync access(<path>)
834 * 0 : The operation was successfull.
835 * -errno : The command failed.
837 int nfs_access(struct nfs_context
*nfs
, const char *path
, int mode
);
846 * Async symlink(<path>)
848 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
849 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
851 * When the callback is invoked, status indicates the result:
854 * -errno : An error occured.
855 * data is the error string.
857 int nfs_symlink_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
859 * Sync symlink(<path>)
861 * 0 : The operation was successfull.
862 * -errno : The command failed.
864 int nfs_symlink(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
871 * Async rename(<oldpath>, <newpath>)
873 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
874 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
876 * When the callback is invoked, status indicates the result:
879 * -errno : An error occured.
880 * data is the error string.
882 int nfs_rename_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
884 * Sync rename(<oldpath>, <newpath>)
886 * 0 : The operation was successfull.
887 * -errno : The command failed.
889 int nfs_rename(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
897 * Async link(<oldpath>, <newpath>)
899 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
900 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
902 * When the callback is invoked, status indicates the result:
905 * -errno : An error occured.
906 * data is the error string.
908 int nfs_link_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
910 * Sync link(<oldpath>, <newpath>)
912 * 0 : The operation was successfull.
913 * -errno : The command failed.
915 int nfs_link(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
923 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
924 * returned structures.
926 * This function will return the list of exports from an NFS server.
929 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
930 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
932 * When the callback is invoked, status indicates the result:
934 * data is a pointer to an exports pointer:
935 * exports export = *(exports *)data;
936 * -errno : An error occured.
937 * data is the error string.
939 int mount_getexports_async(struct rpc_context
*rpc
, const char *server
, rpc_cb cb
, void *private_data
);
941 * Sync getexports(<server>)
943 * NULL : something failed
944 * exports export : a linked list of exported directories
946 * returned data must be freed by calling mount_free_export_list(exportnode);
948 struct exportnode
*mount_getexports(const char *server
);
950 void mount_free_export_list(struct exportnode
*exports
);
953 //qqq replace later with lseek(cur, 0)
954 off_t
nfs_get_current_offset(struct nfsfh
*nfsfh
);
960 struct nfs_server_list
{
961 struct nfs_server_list
*next
;
966 * Sync find_local_servers(<server>)
967 * This function will probe all local networks for NFS server. This function will
968 * block for one second while awaiting for all nfs servers to respond.
971 * NULL : something failed
973 * struct nfs_server_list : a linked list of all discovered servers
975 * returned data must be freed by nfs_free_srvr_list(srv);
977 struct nfs_server_list
*nfs_find_local_servers(void);
978 void free_nfs_srvr_list(struct nfs_server_list
*srv
);