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
49 * Used for interfacing the async version of the api into an external eventsystem
51 int nfs_get_fd(struct nfs_context
*nfs
);
52 int nfs_which_events(struct nfs_context
*nfs
);
53 int nfs_service(struct nfs_context
*nfs
, int revents
);
56 * Used if you need different credentials than the default for the current user.
59 void nfs_set_auth(struct nfs_context
*nfs
, struct AUTH
*auth
);
63 * When an operation failed, this function can extract a detailed error string.
65 char *nfs_get_error(struct nfs_context
*nfs
);
69 * Callback for all ASYNC nfs functions
71 typedef void (*nfs_cb
)(int err
, struct nfs_context
*nfs
, void *data
, void *private_data
);
74 * Callback for all ASYNC rpc functions
76 typedef void (*rpc_cb
)(struct rpc_context
*rpc
, int status
, void *data
, void *private_data
);
84 * Create an NFS c, the context.
86 * NULL : Failed to create a context.
87 * *nfs : A pointer to an nfs context.
89 struct nfs_context
*nfs_init_context(void);
91 * Destroy an nfs context.
93 void nfs_destroy_context(struct nfs_context
*nfs
);
99 * Get the maximum supported READ3 size by the server
101 size_t nfs_get_readmax(struct nfs_context
*nfs
);
104 * Get the maximum supported WRITE3 size by the server
106 size_t nfs_get_writemax(struct nfs_context
*nfs
);
115 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
116 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
118 * When the callback is invoked, status indicates the result:
121 * -errno : An error occured.
122 * data is the error string.
124 int nfs_mount_async(struct nfs_context
*nfs
, const char *server
, const char *exportname
, nfs_cb cb
, void *private_data
);
128 * 0 : The operation was successfull.
129 * -errno : The command failed.
131 int nfs_mount(struct nfs_context
*nfs
, const char *server
, const char *exportname
);
140 * Async stat(<filename>)
142 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
143 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
145 * When the callback is invoked, status indicates the result:
147 * data is struct stat *
148 * -errno : An error occured.
149 * data is the error string.
152 int nfs_stat_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
154 * Sync stat(<filename>)
156 * 0 : The operation was successfull.
157 * -errno : The command failed.
159 int nfs_stat(struct nfs_context
*nfs
, const char *path
, struct stat
*st
);
166 * Async fstat(nfsfh *)
168 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
169 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
171 * When the callback is invoked, status indicates the result:
173 * data is struct stat *
174 * -errno : An error occured.
175 * data is the error string.
177 int nfs_fstat_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
179 * Sync fstat(nfsfh *)
181 * 0 : The operation was successfull.
182 * -errno : The command failed.
184 int nfs_fstat(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, struct stat
*st
);
192 * Async open(<filename>)
194 * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
197 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
198 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
200 * When the callback is invoked, status indicates the result:
202 * data is a struct *nfsfh;
203 * The nfsfh is close using nfs_close().
204 * -errno : An error occured.
205 * data is the error string.
207 int nfs_open_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
209 * Sync stat(<filename>)
211 * 0 : The operation was successfull. *nfsfh is filled in.
212 * -errno : The command failed.
214 int nfs_open(struct nfs_context
*nfs
, const char *path
, int mode
, struct nfsfh
**nfsfh
);
226 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
227 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
229 * When the callback is invoked, status indicates the result:
232 * -errno : An error occured.
233 * data is the error string.
235 int nfs_close_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
239 * 0 : The operation was successfull.
240 * -errno : The command failed.
242 int nfs_close(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
);
252 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
253 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
255 * When the callback is invoked, status indicates the result:
257 * status is numer of bytes read.
258 * data is a pointer to the returned data.
259 * -errno : An error occured.
260 * data is the error string.
262 int nfs_pread_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, nfs_cb cb
, void *private_data
);
266 * >=0 : numer of bytes read.
267 * -errno : An error occured.
269 int nfs_pread(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, char *buf
);
280 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
281 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
283 * When the callback is invoked, status indicates the result:
285 * status is numer of bytes read.
286 * data is a pointer to the returned data.
287 * -errno : An error occured.
288 * data is the error string.
290 int nfs_read_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, nfs_cb cb
, void *private_data
);
294 * >=0 : numer of bytes read.
295 * -errno : An error occured.
297 int nfs_read(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
);
309 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
310 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
312 * When the callback is invoked, status indicates the result:
314 * status is numer of bytes written.
315 * -errno : An error occured.
316 * data is the error string.
318 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
);
322 * >=0 : numer of bytes written.
323 * -errno : An error occured.
325 int nfs_pwrite(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, char *buf
);
335 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
336 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
338 * When the callback is invoked, status indicates the result:
340 * status is numer of bytes written.
341 * -errno : An error occured.
342 * data is the error string.
344 int nfs_write_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
, nfs_cb cb
, void *private_data
);
348 * >=0 : numer of bytes written.
349 * -errno : An error occured.
351 int nfs_write(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
);
361 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
362 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
364 * When the callback is invoked, status indicates the result:
366 * data is off_t * for the current position.
367 * -errno : An error occured.
368 * data is the error string.
370 int nfs_lseek_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, int whence
, nfs_cb cb
, void *private_data
);
374 * >=0 : numer of bytes read.
375 * -errno : An error occured.
377 int nfs_lseek(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, int whence
, off_t
*current_offset
);
387 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
388 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
390 * When the callback is invoked, status indicates the result:
392 * -errno : An error occured.
393 * data is the error string.
395 int nfs_fsync_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
400 * -errno : An error occured.
402 int nfs_fsync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
);
413 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
414 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
416 * When the callback is invoked, status indicates the result:
418 * -errno : An error occured.
419 * data is the error string.
421 int nfs_truncate_async(struct nfs_context
*nfs
, const char *path
, off_t length
, nfs_cb cb
, void *private_data
);
426 * -errno : An error occured.
428 int nfs_truncate(struct nfs_context
*nfs
, const char *path
, off_t length
);
439 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
440 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
442 * When the callback is invoked, status indicates the result:
444 * -errno : An error occured.
445 * data is the error string.
447 int nfs_ftruncate_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t length
, nfs_cb cb
, void *private_data
);
452 * -errno : An error occured.
454 int nfs_ftruncate(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t length
);
468 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
469 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
471 * When the callback is invoked, status indicates the result:
473 * -errno : An error occured.
474 * data is the error string.
476 int nfs_mkdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
481 * -errno : An error occured.
483 int nfs_mkdir(struct nfs_context
*nfs
, const char *path
);
494 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
495 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
497 * When the callback is invoked, status indicates the result:
499 * -errno : An error occured.
500 * data is the error string.
502 int nfs_rmdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
507 * -errno : An error occured.
509 int nfs_rmdir(struct nfs_context
*nfs
, const char *path
);
521 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
522 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
524 * When the callback is invoked, status indicates the result:
526 * data is a struct *nfsfh;
527 * -errno : An error occured.
528 * data is the error string.
530 int nfs_creat_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
535 * -errno : An error occured.
537 int nfs_creat(struct nfs_context
*nfs
, const char *path
, int mode
, struct nfsfh
**nfsfh
);
550 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
551 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
553 * When the callback is invoked, status indicates the result:
556 * -errno : An error occured.
557 * data is the error string.
559 int nfs_unlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
564 * -errno : An error occured.
566 int nfs_unlink(struct nfs_context
*nfs
, const char *path
);
579 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
580 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
582 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
584 * When the callback is invoked, status indicates the result:
586 * data is struct nfsdir *
587 * -errno : An error occured.
588 * data is the error string.
590 int nfs_opendir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
595 * -errno : An error occured.
597 int nfs_opendir(struct nfs_context
*nfs
, const char *path
, struct nfsdir
**nfsdir
);
605 struct nfsdirent
*next
;
610 * nfs_readdir() never blocks, so no special sync/async versions are available
612 struct nfsdirent
*nfs_readdir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
620 * nfs_closedir() never blocks, so no special sync/async versions are available
622 void nfs_closedir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
630 * Async statvfs(<dirname>)
632 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
633 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
635 * When the callback is invoked, status indicates the result:
637 * data is struct statvfs *
638 * -errno : An error occured.
639 * data is the error string.
642 int nfs_statvfs_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
644 * Sync statvfs(<dirname>)
646 * 0 : The operation was successfull.
647 * -errno : The command failed.
649 int nfs_statvfs(struct nfs_context
*nfs
, const char *path
, struct statvfs
*svfs
);
656 * Async readlink(<name>)
658 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
659 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
661 * When the callback is invoked, status indicates the result:
664 * data is only valid during the callback and is automatically freed when the callback returns.
665 * -errno : An error occured.
666 * data is the error string.
669 int nfs_readlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
671 * Sync readlink(<name>)
673 * 0 : The operation was successfull.
674 * -errno : The command failed.
676 int nfs_readlink(struct nfs_context
*nfs
, const char *path
, char *buf
, int bufsize
);
684 * Async chmod(<name>)
686 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
687 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
689 * When the callback is invoked, status indicates the result:
692 * -errno : An error occured.
693 * data is the error string.
695 int nfs_chmod_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
699 * 0 : The operation was successfull.
700 * -errno : The command failed.
702 int nfs_chmod(struct nfs_context
*nfs
, const char *path
, int mode
);
710 * Async fchmod(<handle>)
712 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
713 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
715 * When the callback is invoked, status indicates the result:
718 * -errno : An error occured.
719 * data is the error string.
721 int nfs_fchmod_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
, nfs_cb cb
, void *private_data
);
723 * Sync fchmod(<handle>)
725 * 0 : The operation was successfull.
726 * -errno : The command failed.
728 int nfs_fchmod(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
);
736 * Async chown(<name>)
738 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
739 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
741 * When the callback is invoked, status indicates the result:
744 * -errno : An error occured.
745 * data is the error string.
747 int nfs_chown_async(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
751 * 0 : The operation was successfull.
752 * -errno : The command failed.
754 int nfs_chown(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
);
762 * Async fchown(<handle>)
764 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
765 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
767 * When the callback is invoked, status indicates the result:
770 * -errno : An error occured.
771 * data is the error string.
773 int nfs_fchown_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
775 * Sync fchown(<handle>)
777 * 0 : The operation was successfull.
778 * -errno : The command failed.
780 int nfs_fchown(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
);
789 * Async utimes(<path>)
791 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
792 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
794 * When the callback is invoked, status indicates the result:
797 * -errno : An error occured.
798 * data is the error string.
800 int nfs_utimes_async(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
, nfs_cb cb
, void *private_data
);
802 * Sync utimes(<path>)
804 * 0 : The operation was successfull.
805 * -errno : The command failed.
807 int nfs_utimes(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
);
814 * Async utime(<path>)
816 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
817 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
819 * When the callback is invoked, status indicates the result:
822 * -errno : An error occured.
823 * data is the error string.
826 int nfs_utime_async(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
, nfs_cb cb
, void *private_data
);
830 * 0 : The operation was successfull.
831 * -errno : The command failed.
833 int nfs_utime(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
);
842 * Async access(<path>)
844 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
845 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
847 * When the callback is invoked, status indicates the result:
850 * -errno : An error occured.
851 * data is the error string.
853 int nfs_access_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
855 * Sync access(<path>)
857 * 0 : The operation was successfull.
858 * -errno : The command failed.
860 int nfs_access(struct nfs_context
*nfs
, const char *path
, int mode
);
869 * Async symlink(<path>)
871 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
872 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
874 * When the callback is invoked, status indicates the result:
877 * -errno : An error occured.
878 * data is the error string.
880 int nfs_symlink_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
882 * Sync symlink(<path>)
884 * 0 : The operation was successfull.
885 * -errno : The command failed.
887 int nfs_symlink(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
894 * Async rename(<oldpath>, <newpath>)
896 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
897 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
899 * When the callback is invoked, status indicates the result:
902 * -errno : An error occured.
903 * data is the error string.
905 int nfs_rename_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
907 * Sync rename(<oldpath>, <newpath>)
909 * 0 : The operation was successfull.
910 * -errno : The command failed.
912 int nfs_rename(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
920 * Async link(<oldpath>, <newpath>)
922 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
923 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
925 * When the callback is invoked, status indicates the result:
928 * -errno : An error occured.
929 * data is the error string.
931 int nfs_link_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
933 * Sync link(<oldpath>, <newpath>)
935 * 0 : The operation was successfull.
936 * -errno : The command failed.
938 int nfs_link(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
946 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
947 * returned structures.
949 * This function will return the list of exports from an NFS server.
952 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
953 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
955 * When the callback is invoked, status indicates the result:
957 * data is a pointer to an exports pointer:
958 * exports export = *(exports *)data;
959 * -errno : An error occured.
960 * data is the error string.
962 int mount_getexports_async(struct rpc_context
*rpc
, const char *server
, rpc_cb cb
, void *private_data
);
964 * Sync getexports(<server>)
966 * NULL : something failed
967 * exports export : a linked list of exported directories
969 * returned data must be freed by calling mount_free_export_list(exportnode);
971 struct exportnode
*mount_getexports(const char *server
);
973 void mount_free_export_list(struct exportnode
*exports
);
976 //qqq replace later with lseek(cur, 0)
977 off_t
nfs_get_current_offset(struct nfsfh
*nfsfh
);
983 struct nfs_server_list
{
984 struct nfs_server_list
*next
;
989 * Sync find_local_servers(<server>)
990 * This function will probe all local networks for NFS server. This function will
991 * block for one second while awaiting for all nfs servers to respond.
994 * NULL : something failed
996 * struct nfs_server_list : a linked list of all discovered servers
998 * returned data must be freed by nfs_free_srvr_list(srv);
1000 struct nfs_server_list
*nfs_find_local_servers(void);
1001 void free_nfs_srvr_list(struct nfs_server_list
*srv
);