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 #define EXTERN __declspec( dllexport )
55 * Used for interfacing the async version of the api into an external eventsystem
57 EXTERN
int nfs_get_fd(struct nfs_context
*nfs
);
58 EXTERN
int nfs_which_events(struct nfs_context
*nfs
);
59 EXTERN
int nfs_service(struct nfs_context
*nfs
, int revents
);
62 * Used if you need different credentials than the default for the current user.
65 EXTERN
void nfs_set_auth(struct nfs_context
*nfs
, struct AUTH
*auth
);
69 * When an operation failed, this function can extract a detailed error string.
71 EXTERN
char *nfs_get_error(struct nfs_context
*nfs
);
75 * Callback for all ASYNC nfs functions
77 typedef void (*nfs_cb
)(int err
, struct nfs_context
*nfs
, void *data
, void *private_data
);
80 * Callback for all ASYNC rpc functions
82 typedef void (*rpc_cb
)(struct rpc_context
*rpc
, int status
, void *data
, void *private_data
);
90 * Create an NFS c, the context.
92 * NULL : Failed to create a context.
93 * *nfs : A pointer to an nfs context.
95 EXTERN
struct nfs_context
*nfs_init_context(void);
97 * Destroy an nfs context.
99 EXTERN
void nfs_destroy_context(struct nfs_context
*nfs
);
105 * Get the maximum supported READ3 size by the server
107 EXTERN
size_t nfs_get_readmax(struct nfs_context
*nfs
);
110 * Get the maximum supported WRITE3 size by the server
112 EXTERN
size_t nfs_get_writemax(struct nfs_context
*nfs
);
121 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
122 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
124 * When the callback is invoked, status indicates the result:
127 * -errno : An error occured.
128 * data is the error string.
130 EXTERN
int nfs_mount_async(struct nfs_context
*nfs
, const char *server
, const char *exportname
, nfs_cb cb
, void *private_data
);
134 * 0 : The operation was successfull.
135 * -errno : The command failed.
137 EXTERN
int nfs_mount(struct nfs_context
*nfs
, const char *server
, const char *exportname
);
146 * Async stat(<filename>)
148 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
149 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
151 * When the callback is invoked, status indicates the result:
153 * data is struct stat *
154 * -errno : An error occured.
155 * data is the error string.
158 EXTERN
int nfs_stat_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
160 * Sync stat(<filename>)
162 * 0 : The operation was successfull.
163 * -errno : The command failed.
165 EXTERN
int nfs_stat(struct nfs_context
*nfs
, const char *path
, struct stat
*st
);
172 * Async fstat(nfsfh *)
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 struct stat *
180 * -errno : An error occured.
181 * data is the error string.
183 EXTERN
int nfs_fstat_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
185 * Sync fstat(nfsfh *)
187 * 0 : The operation was successfull.
188 * -errno : The command failed.
190 EXTERN
int nfs_fstat(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, struct stat
*st
);
198 * Async open(<filename>)
200 * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
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:
208 * data is a struct *nfsfh;
209 * The nfsfh is close using nfs_close().
210 * -errno : An error occured.
211 * data is the error string.
213 EXTERN
int nfs_open_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
215 * Sync stat(<filename>)
217 * 0 : The operation was successfull. *nfsfh is filled in.
218 * -errno : The command failed.
220 EXTERN
int nfs_open(struct nfs_context
*nfs
, const char *path
, int mode
, struct nfsfh
**nfsfh
);
232 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
233 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
235 * When the callback is invoked, status indicates the result:
238 * -errno : An error occured.
239 * data is the error string.
241 EXTERN
int nfs_close_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
245 * 0 : The operation was successfull.
246 * -errno : The command failed.
248 EXTERN
int nfs_close(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
);
258 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
259 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
261 * When the callback is invoked, status indicates the result:
263 * status is numer of bytes read.
264 * data is a pointer to the returned data.
265 * -errno : An error occured.
266 * data is the error string.
268 EXTERN
int nfs_pread_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, nfs_cb cb
, void *private_data
);
272 * >=0 : numer of bytes read.
273 * -errno : An error occured.
275 EXTERN
int nfs_pread(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, 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 read.
292 * data is a pointer to the returned data.
293 * -errno : An error occured.
294 * data is the error string.
296 EXTERN
int nfs_read_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, nfs_cb cb
, void *private_data
);
300 * >=0 : numer of bytes read.
301 * -errno : An error occured.
303 EXTERN
int nfs_read(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
);
315 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
316 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
318 * When the callback is invoked, status indicates the result:
320 * status is numer of bytes written.
321 * -errno : An error occured.
322 * data is the error string.
324 EXTERN
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
);
328 * >=0 : numer of bytes written.
329 * -errno : An error occured.
331 EXTERN
int nfs_pwrite(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, char *buf
);
341 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
342 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
344 * When the callback is invoked, status indicates the result:
346 * status is numer of bytes written.
347 * -errno : An error occured.
348 * data is the error string.
350 EXTERN
int nfs_write_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
, nfs_cb cb
, void *private_data
);
354 * >=0 : numer of bytes written.
355 * -errno : An error occured.
357 EXTERN
int nfs_write(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
);
367 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
368 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
370 * When the callback is invoked, status indicates the result:
372 * data is off_t * for the current position.
373 * -errno : An error occured.
374 * data is the error string.
376 EXTERN
int nfs_lseek_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, int whence
, nfs_cb cb
, void *private_data
);
380 * >=0 : numer of bytes read.
381 * -errno : An error occured.
383 EXTERN
int nfs_lseek(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, int whence
, off_t
*current_offset
);
393 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
394 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
396 * When the callback is invoked, status indicates the result:
398 * -errno : An error occured.
399 * data is the error string.
401 EXTERN
int nfs_fsync_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
406 * -errno : An error occured.
408 EXTERN
int nfs_fsync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
);
419 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
420 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
422 * When the callback is invoked, status indicates the result:
424 * -errno : An error occured.
425 * data is the error string.
427 EXTERN
int nfs_truncate_async(struct nfs_context
*nfs
, const char *path
, off_t length
, nfs_cb cb
, void *private_data
);
432 * -errno : An error occured.
434 EXTERN
int nfs_truncate(struct nfs_context
*nfs
, const char *path
, 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 EXTERN
int nfs_ftruncate_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t length
, nfs_cb cb
, void *private_data
);
458 * -errno : An error occured.
460 EXTERN
int nfs_ftruncate(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t length
);
474 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
475 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
477 * When the callback is invoked, status indicates the result:
479 * -errno : An error occured.
480 * data is the error string.
482 EXTERN
int nfs_mkdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
487 * -errno : An error occured.
489 EXTERN
int nfs_mkdir(struct nfs_context
*nfs
, const char *path
);
500 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
501 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
503 * When the callback is invoked, status indicates the result:
505 * -errno : An error occured.
506 * data is the error string.
508 EXTERN
int nfs_rmdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
513 * -errno : An error occured.
515 EXTERN
int nfs_rmdir(struct nfs_context
*nfs
, const char *path
);
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:
532 * data is a struct *nfsfh;
533 * -errno : An error occured.
534 * data is the error string.
536 EXTERN
int nfs_creat_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
541 * -errno : An error occured.
543 EXTERN
int nfs_creat(struct nfs_context
*nfs
, const char *path
, int mode
, struct nfsfh
**nfsfh
);
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 the callback is invoked, status indicates the result:
562 * -errno : An error occured.
563 * data is the error string.
565 EXTERN
int nfs_unlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
570 * -errno : An error occured.
572 EXTERN
int nfs_unlink(struct nfs_context
*nfs
, const char *path
);
585 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
586 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
588 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
590 * When the callback is invoked, status indicates the result:
592 * data is struct nfsdir *
593 * -errno : An error occured.
594 * data is the error string.
596 EXTERN
int nfs_opendir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
601 * -errno : An error occured.
603 EXTERN
int nfs_opendir(struct nfs_context
*nfs
, const char *path
, struct nfsdir
**nfsdir
);
611 struct nfsdirent
*next
;
615 /* some extra fields we get for free through the READDIRPLUS3 call. You need libnfs-raw-nfs.h for these */
616 uint32_t type
; /* NF3REG, NF3DIR, NF3BLK, ... */
619 struct timeval atime
;
620 struct timeval mtime
;
621 struct timeval ctime
;
624 * nfs_readdir() never blocks, so no special sync/async versions are available
626 EXTERN
struct nfsdirent
*nfs_readdir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
634 * nfs_closedir() never blocks, so no special sync/async versions are available
636 EXTERN
void nfs_closedir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
644 * Async statvfs(<dirname>)
646 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
647 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
649 * When the callback is invoked, status indicates the result:
651 * data is struct statvfs *
652 * -errno : An error occured.
653 * data is the error string.
656 EXTERN
int nfs_statvfs_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
658 * Sync statvfs(<dirname>)
660 * 0 : The operation was successfull.
661 * -errno : The command failed.
663 EXTERN
int nfs_statvfs(struct nfs_context
*nfs
, const char *path
, struct statvfs
*svfs
);
670 * Async readlink(<name>)
672 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
673 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
675 * When the callback is invoked, status indicates the result:
678 * data is only valid during the callback and is automatically freed when the callback returns.
679 * -errno : An error occured.
680 * data is the error string.
683 EXTERN
int nfs_readlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
685 * Sync readlink(<name>)
687 * 0 : The operation was successfull.
688 * -errno : The command failed.
690 EXTERN
int nfs_readlink(struct nfs_context
*nfs
, const char *path
, char *buf
, int bufsize
);
698 * Async chmod(<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 EXTERN
int nfs_chmod_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
713 * 0 : The operation was successfull.
714 * -errno : The command failed.
716 EXTERN
int nfs_chmod(struct nfs_context
*nfs
, const char *path
, int mode
);
724 * Async fchmod(<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 EXTERN
int nfs_fchmod_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
, nfs_cb cb
, void *private_data
);
737 * Sync fchmod(<handle>)
739 * 0 : The operation was successfull.
740 * -errno : The command failed.
742 EXTERN
int nfs_fchmod(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
);
750 * Async chown(<name>)
752 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
753 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
755 * When the callback is invoked, status indicates the result:
758 * -errno : An error occured.
759 * data is the error string.
761 EXTERN
int nfs_chown_async(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
765 * 0 : The operation was successfull.
766 * -errno : The command failed.
768 EXTERN
int nfs_chown(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
);
776 * Async fchown(<handle>)
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.
787 EXTERN
int nfs_fchown_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
789 * Sync fchown(<handle>)
791 * 0 : The operation was successfull.
792 * -errno : The command failed.
794 EXTERN
int nfs_fchown(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
);
803 * Async utimes(<path>)
805 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
806 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
808 * When the callback is invoked, status indicates the result:
811 * -errno : An error occured.
812 * data is the error string.
814 EXTERN
int nfs_utimes_async(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
, nfs_cb cb
, void *private_data
);
816 * Sync utimes(<path>)
818 * 0 : The operation was successfull.
819 * -errno : The command failed.
821 EXTERN
int nfs_utimes(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
);
828 * Async utime(<path>)
830 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
831 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
833 * When the callback is invoked, status indicates the result:
836 * -errno : An error occured.
837 * data is the error string.
840 EXTERN
int nfs_utime_async(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
, nfs_cb cb
, void *private_data
);
844 * 0 : The operation was successfull.
845 * -errno : The command failed.
847 EXTERN
int nfs_utime(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
);
856 * Async access(<path>)
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 EXTERN
int nfs_access_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
869 * Sync access(<path>)
871 * 0 : The operation was successfull.
872 * -errno : The command failed.
874 EXTERN
int nfs_access(struct nfs_context
*nfs
, const char *path
, int mode
);
883 * Async symlink(<path>)
885 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
886 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
888 * When the callback is invoked, status indicates the result:
891 * -errno : An error occured.
892 * data is the error string.
894 EXTERN
int nfs_symlink_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
896 * Sync symlink(<path>)
898 * 0 : The operation was successfull.
899 * -errno : The command failed.
901 EXTERN
int nfs_symlink(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
908 * Async rename(<oldpath>, <newpath>)
910 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
911 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
913 * When the callback is invoked, status indicates the result:
916 * -errno : An error occured.
917 * data is the error string.
919 EXTERN
int nfs_rename_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
921 * Sync rename(<oldpath>, <newpath>)
923 * 0 : The operation was successfull.
924 * -errno : The command failed.
926 EXTERN
int nfs_rename(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
934 * Async link(<oldpath>, <newpath>)
936 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
937 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
939 * When the callback is invoked, status indicates the result:
942 * -errno : An error occured.
943 * data is the error string.
945 EXTERN
int nfs_link_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
947 * Sync link(<oldpath>, <newpath>)
949 * 0 : The operation was successfull.
950 * -errno : The command failed.
952 EXTERN
int nfs_link(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
960 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
961 * returned structures.
963 * This function will return the list of exports from an NFS server.
966 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
967 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
969 * When the callback is invoked, status indicates the result:
971 * data is a pointer to an exports pointer:
972 * exports export = *(exports *)data;
973 * -errno : An error occured.
974 * data is the error string.
976 EXTERN
int mount_getexports_async(struct rpc_context
*rpc
, const char *server
, rpc_cb cb
, void *private_data
);
978 * Sync getexports(<server>)
980 * NULL : something failed
981 * exports export : a linked list of exported directories
983 * returned data must be freed by calling mount_free_export_list(exportnode);
985 EXTERN
struct exportnode
*mount_getexports(const char *server
);
987 EXTERN
void mount_free_export_list(struct exportnode
*exports
);
990 //qqq replace later with lseek(cur, 0)
991 off_t
nfs_get_current_offset(struct nfsfh
*nfsfh
);
997 struct nfs_server_list
{
998 struct nfs_server_list
*next
;
1003 * Sync find_local_servers(<server>)
1004 * This function will probe all local networks for NFS server. This function will
1005 * block for one second while awaiting for all nfs servers to respond.
1008 * NULL : something failed
1010 * struct nfs_server_list : a linked list of all discovered servers
1012 * returned data must be freed by nfs_free_srvr_list(srv);
1014 struct nfs_server_list
*nfs_find_local_servers(void);
1015 void free_nfs_srvr_list(struct nfs_server_list
*srv
);