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
;
616 * nfs_readdir() never blocks, so no special sync/async versions are available
618 EXTERN
struct nfsdirent
*nfs_readdir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
626 * nfs_closedir() never blocks, so no special sync/async versions are available
628 EXTERN
void nfs_closedir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
636 * Async statvfs(<dirname>)
638 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
639 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
641 * When the callback is invoked, status indicates the result:
643 * data is struct statvfs *
644 * -errno : An error occured.
645 * data is the error string.
648 EXTERN
int nfs_statvfs_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
650 * Sync statvfs(<dirname>)
652 * 0 : The operation was successfull.
653 * -errno : The command failed.
655 EXTERN
int nfs_statvfs(struct nfs_context
*nfs
, const char *path
, struct statvfs
*svfs
);
662 * Async readlink(<name>)
664 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
665 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
667 * When the callback is invoked, status indicates the result:
670 * data is only valid during the callback and is automatically freed when the callback returns.
671 * -errno : An error occured.
672 * data is the error string.
675 EXTERN
int nfs_readlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
677 * Sync readlink(<name>)
679 * 0 : The operation was successfull.
680 * -errno : The command failed.
682 EXTERN
int nfs_readlink(struct nfs_context
*nfs
, const char *path
, char *buf
, int bufsize
);
690 * Async chmod(<name>)
692 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
693 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
695 * When the callback is invoked, status indicates the result:
698 * -errno : An error occured.
699 * data is the error string.
701 EXTERN
int nfs_chmod_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
705 * 0 : The operation was successfull.
706 * -errno : The command failed.
708 EXTERN
int nfs_chmod(struct nfs_context
*nfs
, const char *path
, int mode
);
716 * Async fchmod(<handle>)
718 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
719 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
721 * When the callback is invoked, status indicates the result:
724 * -errno : An error occured.
725 * data is the error string.
727 EXTERN
int nfs_fchmod_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
, nfs_cb cb
, void *private_data
);
729 * Sync fchmod(<handle>)
731 * 0 : The operation was successfull.
732 * -errno : The command failed.
734 EXTERN
int nfs_fchmod(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
);
742 * Async chown(<name>)
744 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
745 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
747 * When the callback is invoked, status indicates the result:
750 * -errno : An error occured.
751 * data is the error string.
753 EXTERN
int nfs_chown_async(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
757 * 0 : The operation was successfull.
758 * -errno : The command failed.
760 EXTERN
int nfs_chown(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
);
768 * Async fchown(<handle>)
770 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
771 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
773 * When the callback is invoked, status indicates the result:
776 * -errno : An error occured.
777 * data is the error string.
779 EXTERN
int nfs_fchown_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
781 * Sync fchown(<handle>)
783 * 0 : The operation was successfull.
784 * -errno : The command failed.
786 EXTERN
int nfs_fchown(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
);
795 * Async utimes(<path>)
797 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
798 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
800 * When the callback is invoked, status indicates the result:
803 * -errno : An error occured.
804 * data is the error string.
806 EXTERN
int nfs_utimes_async(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
, nfs_cb cb
, void *private_data
);
808 * Sync utimes(<path>)
810 * 0 : The operation was successfull.
811 * -errno : The command failed.
813 EXTERN
int nfs_utimes(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
);
820 * Async utime(<path>)
822 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
823 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
825 * When the callback is invoked, status indicates the result:
828 * -errno : An error occured.
829 * data is the error string.
832 EXTERN
int nfs_utime_async(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
, nfs_cb cb
, void *private_data
);
836 * 0 : The operation was successfull.
837 * -errno : The command failed.
839 EXTERN
int nfs_utime(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
);
848 * Async access(<path>)
850 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
851 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
853 * When the callback is invoked, status indicates the result:
856 * -errno : An error occured.
857 * data is the error string.
859 EXTERN
int nfs_access_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
861 * Sync access(<path>)
863 * 0 : The operation was successfull.
864 * -errno : The command failed.
866 EXTERN
int nfs_access(struct nfs_context
*nfs
, const char *path
, int mode
);
875 * Async symlink(<path>)
877 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
878 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
880 * When the callback is invoked, status indicates the result:
883 * -errno : An error occured.
884 * data is the error string.
886 EXTERN
int nfs_symlink_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
888 * Sync symlink(<path>)
890 * 0 : The operation was successfull.
891 * -errno : The command failed.
893 EXTERN
int nfs_symlink(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
900 * Async rename(<oldpath>, <newpath>)
902 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
903 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
905 * When the callback is invoked, status indicates the result:
908 * -errno : An error occured.
909 * data is the error string.
911 EXTERN
int nfs_rename_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
913 * Sync rename(<oldpath>, <newpath>)
915 * 0 : The operation was successfull.
916 * -errno : The command failed.
918 EXTERN
int nfs_rename(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
926 * Async link(<oldpath>, <newpath>)
928 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
929 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
931 * When the callback is invoked, status indicates the result:
934 * -errno : An error occured.
935 * data is the error string.
937 EXTERN
int nfs_link_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
939 * Sync link(<oldpath>, <newpath>)
941 * 0 : The operation was successfull.
942 * -errno : The command failed.
944 EXTERN
int nfs_link(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
952 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
953 * returned structures.
955 * This function will return the list of exports from an NFS server.
958 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
959 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
961 * When the callback is invoked, status indicates the result:
963 * data is a pointer to an exports pointer:
964 * exports export = *(exports *)data;
965 * -errno : An error occured.
966 * data is the error string.
968 EXTERN
int mount_getexports_async(struct rpc_context
*rpc
, const char *server
, rpc_cb cb
, void *private_data
);
970 * Sync getexports(<server>)
972 * NULL : something failed
973 * exports export : a linked list of exported directories
975 * returned data must be freed by calling mount_free_export_list(exportnode);
977 EXTERN
struct exportnode
*mount_getexports(const char *server
);
979 EXTERN
void mount_free_export_list(struct exportnode
*exports
);
982 //qqq replace later with lseek(cur, 0)
983 off_t
nfs_get_current_offset(struct nfsfh
*nfsfh
);
989 struct nfs_server_list
{
990 struct nfs_server_list
*next
;
995 * Sync find_local_servers(<server>)
996 * This function will probe all local networks for NFS server. This function will
997 * block for one second while awaiting for all nfs servers to respond.
1000 * NULL : something failed
1002 * struct nfs_server_list : a linked list of all discovered servers
1004 * returned data must be freed by nfs_free_srvr_list(srv);
1006 struct nfs_server_list
*nfs_find_local_servers(void);
1007 void free_nfs_srvr_list(struct nfs_server_list
*srv
);