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
;
586 /* some extra fields we get for free through the READDIRPLUS3 call. You need libnfs-raw-nfs.h for these */
587 uint32_t type
; /* NF3REG, NF3DIR, NF3BLK, ... */
590 struct timeval atime
;
591 struct timeval mtime
;
592 struct timeval ctime
;
595 * nfs_readdir() never blocks, so no special sync/async versions are available
597 struct nfsdirent
*nfs_readdir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
605 * nfs_closedir() never blocks, so no special sync/async versions are available
607 void nfs_closedir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
615 * Async statvfs(<dirname>)
617 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
618 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
620 * When the callback is invoked, status indicates the result:
622 * data is struct statvfs *
623 * -errno : An error occured.
624 * data is the error string.
627 int nfs_statvfs_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
629 * Sync statvfs(<dirname>)
631 * 0 : The operation was successfull.
632 * -errno : The command failed.
634 int nfs_statvfs(struct nfs_context
*nfs
, const char *path
, struct statvfs
*svfs
);
641 * Async readlink(<name>)
643 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
644 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
646 * When the callback is invoked, status indicates the result:
649 * data is only valid during the callback and is automatically freed when the callback returns.
650 * -errno : An error occured.
651 * data is the error string.
654 int nfs_readlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
656 * Sync readlink(<name>)
658 * 0 : The operation was successfull.
659 * -errno : The command failed.
661 int nfs_readlink(struct nfs_context
*nfs
, const char *path
, char *buf
, int bufsize
);
669 * Async chmod(<name>)
671 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
672 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
674 * When the callback is invoked, status indicates the result:
677 * -errno : An error occured.
678 * data is the error string.
680 int nfs_chmod_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
684 * 0 : The operation was successfull.
685 * -errno : The command failed.
687 int nfs_chmod(struct nfs_context
*nfs
, const char *path
, int mode
);
695 * Async fchmod(<handle>)
697 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
698 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
700 * When the callback is invoked, status indicates the result:
703 * -errno : An error occured.
704 * data is the error string.
706 int nfs_fchmod_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
, nfs_cb cb
, void *private_data
);
708 * Sync fchmod(<handle>)
710 * 0 : The operation was successfull.
711 * -errno : The command failed.
713 int nfs_fchmod(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
);
721 * Async chown(<name>)
723 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
724 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
726 * When the callback is invoked, status indicates the result:
729 * -errno : An error occured.
730 * data is the error string.
732 int nfs_chown_async(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
736 * 0 : The operation was successfull.
737 * -errno : The command failed.
739 int nfs_chown(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
);
747 * Async fchown(<handle>)
749 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
750 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
752 * When the callback is invoked, status indicates the result:
755 * -errno : An error occured.
756 * data is the error string.
758 int nfs_fchown_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
760 * Sync fchown(<handle>)
762 * 0 : The operation was successfull.
763 * -errno : The command failed.
765 int nfs_fchown(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
);
774 * Async utimes(<path>)
776 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
777 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
779 * When the callback is invoked, status indicates the result:
782 * -errno : An error occured.
783 * data is the error string.
785 int nfs_utimes_async(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
, nfs_cb cb
, void *private_data
);
787 * Sync utimes(<path>)
789 * 0 : The operation was successfull.
790 * -errno : The command failed.
792 int nfs_utimes(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
);
799 * Async utime(<path>)
801 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
802 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
804 * When the callback is invoked, status indicates the result:
807 * -errno : An error occured.
808 * data is the error string.
811 int nfs_utime_async(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
, nfs_cb cb
, void *private_data
);
815 * 0 : The operation was successfull.
816 * -errno : The command failed.
818 int nfs_utime(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
);
827 * Async access(<path>)
829 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
830 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
832 * When the callback is invoked, status indicates the result:
835 * -errno : An error occured.
836 * data is the error string.
838 int nfs_access_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
840 * Sync access(<path>)
842 * 0 : The operation was successfull.
843 * -errno : The command failed.
845 int nfs_access(struct nfs_context
*nfs
, const char *path
, int mode
);
854 * Async symlink(<path>)
856 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
857 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
859 * When the callback is invoked, status indicates the result:
862 * -errno : An error occured.
863 * data is the error string.
865 int nfs_symlink_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
867 * Sync symlink(<path>)
869 * 0 : The operation was successfull.
870 * -errno : The command failed.
872 int nfs_symlink(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
879 * Async rename(<oldpath>, <newpath>)
881 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
882 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
884 * When the callback is invoked, status indicates the result:
887 * -errno : An error occured.
888 * data is the error string.
890 int nfs_rename_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
892 * Sync rename(<oldpath>, <newpath>)
894 * 0 : The operation was successfull.
895 * -errno : The command failed.
897 int nfs_rename(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
905 * Async link(<oldpath>, <newpath>)
907 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
908 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
910 * When the callback is invoked, status indicates the result:
913 * -errno : An error occured.
914 * data is the error string.
916 int nfs_link_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
918 * Sync link(<oldpath>, <newpath>)
920 * 0 : The operation was successfull.
921 * -errno : The command failed.
923 int nfs_link(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
931 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
932 * returned structures.
934 * This function will return the list of exports from an NFS server.
937 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
938 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
940 * When the callback is invoked, status indicates the result:
942 * data is a pointer to an exports pointer:
943 * exports export = *(exports *)data;
944 * -errno : An error occured.
945 * data is the error string.
947 int mount_getexports_async(struct rpc_context
*rpc
, const char *server
, rpc_cb cb
, void *private_data
);
949 * Sync getexports(<server>)
951 * NULL : something failed
952 * exports export : a linked list of exported directories
954 * returned data must be freed by calling mount_free_export_list(exportnode);
956 struct exportnode
*mount_getexports(const char *server
);
958 void mount_free_export_list(struct exportnode
*exports
);
961 //qqq replace later with lseek(cur, 0)
962 off_t
nfs_get_current_offset(struct nfsfh
*nfsfh
);
968 struct nfs_server_list
{
969 struct nfs_server_list
*next
;
974 * Sync find_local_servers(<server>)
975 * This function will probe all local networks for NFS server. This function will
976 * block for one second while awaiting for all nfs servers to respond.
979 * NULL : something failed
981 * struct nfs_server_list : a linked list of all discovered servers
983 * returned data must be freed by nfs_free_srvr_list(srv);
985 struct nfs_server_list
*nfs_find_local_servers(void);
986 void free_nfs_srvr_list(struct nfs_server_list
*srv
);