93f8c3c06c1acf8c43625dcee7c52decdbf0dd19
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
25 * Used for interfacing the async version of the api into an external eventsystem
27 int nfs_get_fd(struct nfs_context
*nfs
);
28 int nfs_which_events(struct nfs_context
*nfs
);
29 int nfs_service(struct nfs_context
*nfs
, int revents
);
32 * Used if you need different credentials than the default for the current user.
35 void nfs_set_auth(struct nfs_context
*nfs
, struct AUTH
*auth
);
39 * When an operation failed, this function can extract a detailed error string.
41 char *nfs_get_error(struct nfs_context
*nfs
);
45 * Callback for all ASYNC nfs functions
47 typedef void (*nfs_cb
)(int err
, struct nfs_context
*nfs
, void *data
, void *private_data
);
56 * Create an NFS c, the context.
58 * NULL : Failed to create a context.
59 * *nfs : A pointer to an nfs context.
61 struct nfs_context
*nfs_init_context(void);
63 * Destroy an nfs context.
65 void nfs_destroy_context(struct nfs_context
*nfs
);
71 * Get the maximum supported READ3 size by the server
73 size_t nfs_get_readmax(struct nfs_context
*nfs
);
76 * Get the maximum supported WRITE3 size by the server
78 size_t nfs_get_writemax(struct nfs_context
*nfs
);
87 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
88 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
90 * When the callback is invoked, status indicates the result:
93 * -errno : An error occured.
94 * data is the error string.
96 int nfs_mount_async(struct nfs_context
*nfs
, const char *server
, const char *exportname
, nfs_cb cb
, void *private_data
);
100 * 0 : The operation was successfull.
101 * -errno : The command failed.
103 int nfs_mount_sync(struct nfs_context
*nfs
, const char *server
, const char *exportname
);
112 * Async stat(<filename>)
114 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
115 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
117 * When the callback is invoked, status indicates the result:
119 * data is struct stat *
120 * -errno : An error occured.
121 * data is the error string.
124 int nfs_stat_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
126 * Sync stat(<filename>)
128 * 0 : The operation was successfull.
129 * -errno : The command failed.
131 int nfs_stat_sync(struct nfs_context
*nfs
, const char *path
, struct stat
*st
);
138 * Async fstat(nfsfh *)
140 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
141 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
143 * When the callback is invoked, status indicates the result:
145 * data is struct stat *
146 * -errno : An error occured.
147 * data is the error string.
149 int nfs_fstat_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
151 * Sync fstat(nfsfh *)
153 * 0 : The operation was successfull.
154 * -errno : The command failed.
156 int nfs_fstat_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, struct stat
*st
);
164 * Async open(<filename>)
166 * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
169 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
170 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
172 * When the callback is invoked, status indicates the result:
174 * data is a struct *nfsfh;
175 * The nfsfh is close using nfs_close().
176 * -errno : An error occured.
177 * data is the error string.
179 int nfs_open_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
181 * Sync stat(<filename>)
183 * 0 : The operation was successfull. *nfsfh is filled in.
184 * -errno : The command failed.
186 int nfs_open_sync(struct nfs_context
*nfs
, const char *path
, int mode
, struct nfsfh
**nfsfh
);
198 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
199 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
201 * When the callback is invoked, status indicates the result:
204 * -errno : An error occured.
205 * data is the error string.
207 int nfs_close_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
211 * 0 : The operation was successfull.
212 * -errno : The command failed.
214 int nfs_close_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
);
224 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
225 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
227 * When the callback is invoked, status indicates the result:
229 * status is numer of bytes read.
230 * data is a pointer to the returned data.
231 * -errno : An error occured.
232 * data is the error string.
234 int nfs_pread_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, nfs_cb cb
, void *private_data
);
238 * >=0 : numer of bytes read.
239 * -errno : An error occured.
241 int nfs_pread_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, char *buf
);
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_read_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, nfs_cb cb
, void *private_data
);
266 * >=0 : numer of bytes read.
267 * -errno : An error occured.
269 int nfs_read_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
);
281 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
282 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
284 * When the callback is invoked, status indicates the result:
286 * status is numer of bytes written.
287 * -errno : An error occured.
288 * data is the error string.
290 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
);
294 * >=0 : numer of bytes written.
295 * -errno : An error occured.
297 int nfs_pwrite_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, char *buf
);
307 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
308 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
310 * When the callback is invoked, status indicates the result:
312 * status is numer of bytes written.
313 * -errno : An error occured.
314 * data is the error string.
316 int nfs_write_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
, nfs_cb cb
, void *private_data
);
320 * >=0 : numer of bytes written.
321 * -errno : An error occured.
323 int nfs_write_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
);
333 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
334 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
336 * When the callback is invoked, status indicates the result:
338 * data is off_t * for the current position.
339 * -errno : An error occured.
340 * data is the error string.
342 int nfs_lseek_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, int whence
, nfs_cb cb
, void *private_data
);
346 * >=0 : numer of bytes read.
347 * -errno : An error occured.
349 int nfs_lseek_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, int whence
, off_t
*current_offset
);
359 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
360 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
362 * When the callback is invoked, status indicates the result:
364 * -errno : An error occured.
365 * data is the error string.
367 int nfs_fsync_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
);
372 * -errno : An error occured.
374 int nfs_fsync_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
);
385 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
386 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
388 * When the callback is invoked, status indicates the result:
390 * -errno : An error occured.
391 * data is the error string.
393 int nfs_truncate_async(struct nfs_context
*nfs
, const char *path
, off_t length
, nfs_cb cb
, void *private_data
);
398 * -errno : An error occured.
400 int nfs_truncate_sync(struct nfs_context
*nfs
, const char *path
, off_t length
);
411 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
412 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
414 * When the callback is invoked, status indicates the result:
416 * -errno : An error occured.
417 * data is the error string.
419 int nfs_ftruncate_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t length
, nfs_cb cb
, void *private_data
);
424 * -errno : An error occured.
426 int nfs_ftruncate_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t length
);
440 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
441 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
443 * When the callback is invoked, status indicates the result:
445 * -errno : An error occured.
446 * data is the error string.
448 int nfs_mkdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
453 * -errno : An error occured.
455 int nfs_mkdir_sync(struct nfs_context
*nfs
, const char *path
);
466 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
467 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
469 * When the callback is invoked, status indicates the result:
471 * -errno : An error occured.
472 * data is the error string.
474 int nfs_rmdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
479 * -errno : An error occured.
481 int nfs_rmdir_sync(struct nfs_context
*nfs
, const char *path
);
493 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
494 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
496 * When the callback is invoked, status indicates the result:
498 * data is a struct *nfsfh;
499 * -errno : An error occured.
500 * data is the error string.
502 int nfs_creat_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
507 * -errno : An error occured.
509 int nfs_creat_sync(struct nfs_context
*nfs
, const char *path
, int mode
, struct nfsfh
**nfsfh
);
522 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
523 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
525 * When the callback is invoked, status indicates the result:
528 * -errno : An error occured.
529 * data is the error string.
531 int nfs_unlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
536 * -errno : An error occured.
538 int nfs_unlink_sync(struct nfs_context
*nfs
, const char *path
);
551 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
552 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
554 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
556 * When the callback is invoked, status indicates the result:
558 * data is struct nfsdir *
559 * -errno : An error occured.
560 * data is the error string.
562 int nfs_opendir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
567 * -errno : An error occured.
569 int nfs_opendir_sync(struct nfs_context
*nfs
, const char *path
, struct nfsdir
**nfsdir
);
577 struct nfsdirent
*next
;
582 * nfs_readdir() never blocks, so no special sync/async versions are available
584 struct nfsdirent
*nfs_readdir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
592 * nfs_closedir() never blocks, so no special sync/async versions are available
594 void nfs_closedir(struct nfs_context
*nfs
, struct nfsdir
*nfsdir
);
602 * Async statvfs(<dirname>)
604 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
605 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
607 * When the callback is invoked, status indicates the result:
609 * data is struct statvfs *
610 * -errno : An error occured.
611 * data is the error string.
614 int nfs_statvfs_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
616 * Sync statvfs(<dirname>)
618 * 0 : The operation was successfull.
619 * -errno : The command failed.
621 int nfs_statvfs_sync(struct nfs_context
*nfs
, const char *path
, struct statvfs
*svfs
);
628 * Async readlink(<name>)
630 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
631 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
633 * When the callback is invoked, status indicates the result:
636 * data is only valid during the callback and is automatically freed when the callback returns.
637 * -errno : An error occured.
638 * data is the error string.
641 int nfs_readlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
);
643 * Sync readlink(<name>)
645 * 0 : The operation was successfull.
646 * -errno : The command failed.
648 int nfs_readlink_sync(struct nfs_context
*nfs
, const char *path
, char *buf
, int bufsize
);
656 * Async chmod(<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 * -errno : An error occured.
665 * data is the error string.
667 int nfs_chmod_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
671 * 0 : The operation was successfull.
672 * -errno : The command failed.
674 int nfs_chmod_sync(struct nfs_context
*nfs
, const char *path
, int mode
);
682 * Async fchmod(<handle>)
684 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
685 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
687 * When the callback is invoked, status indicates the result:
690 * -errno : An error occured.
691 * data is the error string.
693 int nfs_fchmod_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
, nfs_cb cb
, void *private_data
);
695 * Sync fchmod(<handle>)
697 * 0 : The operation was successfull.
698 * -errno : The command failed.
700 int nfs_fchmod_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
);
708 * Async chown(<name>)
710 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
711 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
713 * When the callback is invoked, status indicates the result:
716 * -errno : An error occured.
717 * data is the error string.
719 int nfs_chown_async(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
723 * 0 : The operation was successfull.
724 * -errno : The command failed.
726 int nfs_chown_sync(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
);
734 * Async fchown(<handle>)
736 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
737 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
739 * When the callback is invoked, status indicates the result:
742 * -errno : An error occured.
743 * data is the error string.
745 int nfs_fchown_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
, nfs_cb cb
, void *private_data
);
747 * Sync fchown(<handle>)
749 * 0 : The operation was successfull.
750 * -errno : The command failed.
752 int nfs_fchown_sync(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
);
761 * Async utimes(<path>)
763 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
764 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
766 * When the callback is invoked, status indicates the result:
769 * -errno : An error occured.
770 * data is the error string.
772 int nfs_utimes_async(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
, nfs_cb cb
, void *private_data
);
774 * Sync utimes(<path>)
776 * 0 : The operation was successfull.
777 * -errno : The command failed.
779 int nfs_utimes_sync(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
);
786 * Async utime(<path>)
788 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
789 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
791 * When the callback is invoked, status indicates the result:
794 * -errno : An error occured.
795 * data is the error string.
798 int nfs_utime_async(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
, nfs_cb cb
, void *private_data
);
802 * 0 : The operation was successfull.
803 * -errno : The command failed.
805 int nfs_utime_sync(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
);
814 * Async access(<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.
825 int nfs_access_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
);
827 * Sync access(<path>)
829 * 0 : The operation was successfull.
830 * -errno : The command failed.
832 int nfs_access_sync(struct nfs_context
*nfs
, const char *path
, int mode
);
841 * Async symlink(<path>)
843 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
844 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
846 * When the callback is invoked, status indicates the result:
849 * -errno : An error occured.
850 * data is the error string.
852 int nfs_symlink_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
854 * Sync symlink(<path>)
856 * 0 : The operation was successfull.
857 * -errno : The command failed.
859 int nfs_symlink_sync(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
866 * Async rename(<oldpath>, <newpath>)
868 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
869 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
871 * When the callback is invoked, status indicates the result:
874 * -errno : An error occured.
875 * data is the error string.
877 int nfs_rename_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
879 * Sync rename(<oldpath>, <newpath>)
881 * 0 : The operation was successfull.
882 * -errno : The command failed.
884 int nfs_rename_sync(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
892 * Async link(<oldpath>, <newpath>)
894 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
895 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
897 * When the callback is invoked, status indicates the result:
900 * -errno : An error occured.
901 * data is the error string.
903 int nfs_link_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
);
905 * Sync link(<oldpath>, <newpath>)
907 * 0 : The operation was successfull.
908 * -errno : The command failed.
910 int nfs_link_sync(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
);
914 //qqq replace later with lseek(cur, 0)
915 off_t
nfs_get_current_offset(struct nfsfh
*nfsfh
);