From: Ronnie Sahlberg Date: Sat, 3 Sep 2011 00:57:42 +0000 (+1000) Subject: Merge branch 'win32' into win32-3 X-Git-Tag: upstream/1.9.6^2~326 X-Git-Url: https://git.piment-noir.org/?p=deb_libnfs.git;a=commitdiff_plain;h=41d82d7d825b9b4e73bb227f5b2fafa86067cba0;hp=-c Merge branch 'win32' into win32-3 --- 41d82d7d825b9b4e73bb227f5b2fafa86067cba0 diff --combined include/libnfs.h index 3a8304a,c72b7cf..dd63f96 --- a/include/libnfs.h +++ b/include/libnfs.h @@@ -22,24 -22,53 +22,53 @@@ struct nfs_context; struct rpc_context; + #if defined(WIN32) + #define EXTERN __declspec( dllexport ) + #else + #define EXTERN + #endif + + #if defined(WIN32) + struct statvfs { + uint32_t f_bsize; + uint32_t f_frsize; + uint64_t f_blocks; + uint64_t f_bfree; + uint64_t f_bavail; + uint32_t f_files; + uint32_t f_ffree; + uint32_t f_favail; + uint32_t f_fsid; + uint32_t f_flag; + uint32_t f_namemax; + }; + struct utimbuf { + time_t actime; + time_t modtime; + }; + #define R_OK 4 + #define W_OK 2 + #define X_OK 1 + #endif + /* * Used for interfacing the async version of the api into an external eventsystem */ - int nfs_get_fd(struct nfs_context *nfs); - int nfs_which_events(struct nfs_context *nfs); - int nfs_service(struct nfs_context *nfs, int revents); + EXTERN int nfs_get_fd(struct nfs_context *nfs); + EXTERN int nfs_which_events(struct nfs_context *nfs); + EXTERN int nfs_service(struct nfs_context *nfs, int revents); /* * Used if you need different credentials than the default for the current user. */ struct AUTH; - void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth); + EXTERN void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth); /* * When an operation failed, this function can extract a detailed error string. */ - char *nfs_get_error(struct nfs_context *nfs); + EXTERN char *nfs_get_error(struct nfs_context *nfs); /* @@@ -63,11 -92,11 +92,11 @@@ typedef void (*rpc_cb)(struct rpc_conte * NULL : Failed to create a context. * *nfs : A pointer to an nfs context. */ - struct nfs_context *nfs_init_context(void); + EXTERN struct nfs_context *nfs_init_context(void); /* * Destroy an nfs context. */ - void nfs_destroy_context(struct nfs_context *nfs); + EXTERN void nfs_destroy_context(struct nfs_context *nfs); struct nfsfh; @@@ -75,12 -104,12 +104,12 @@@ /* * Get the maximum supported READ3 size by the server */ - size_t nfs_get_readmax(struct nfs_context *nfs); + EXTERN size_t nfs_get_readmax(struct nfs_context *nfs); /* * Get the maximum supported WRITE3 size by the server */ - size_t nfs_get_writemax(struct nfs_context *nfs); + EXTERN size_t nfs_get_writemax(struct nfs_context *nfs); /* @@@ -98,14 -127,14 +127,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *exportname, nfs_cb cb, void *private_data); + EXTERN int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *exportname, nfs_cb cb, void *private_data); /* * Sync nfs mount. * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_mount(struct nfs_context *nfs, const char *server, const char *exportname); + EXTERN int nfs_mount(struct nfs_context *nfs, const char *server, const char *exportname); @@@ -126,14 -155,14 +155,14 @@@ * data is the error string. */ struct stat; - int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); + EXTERN int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); /* * Sync stat() * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st); + EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st); /* @@@ -151,14 -180,14 +180,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data); + EXTERN int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data); /* * Sync fstat(nfsfh *) * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st); + EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st); @@@ -181,14 -210,14 +210,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_open_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data); + EXTERN int nfs_open_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data); /* * Sync stat() * Function returns * 0 : The operation was successfull. *nfsfh is filled in. * -errno : The command failed. */ - int nfs_open(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh); + EXTERN int nfs_open(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh); @@@ -209,14 -238,14 +238,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data); + EXTERN int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data); /* * Sync close(nfsfh) * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_close(struct nfs_context *nfs, struct nfsfh *nfsfh); + EXTERN int nfs_close(struct nfs_context *nfs, struct nfsfh *nfsfh); /* @@@ -236,14 -265,14 +265,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, nfs_cb cb, void *private_data); + EXTERN int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, nfs_cb cb, void *private_data); /* * Sync pread() * Function returns * >=0 : numer of bytes read. * -errno : An error occured. */ - int nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf); + EXTERN int nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf); @@@ -264,14 -293,14 +293,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, nfs_cb cb, void *private_data); + EXTERN int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, nfs_cb cb, void *private_data); /* * Sync read() * Function returns * >=0 : numer of bytes read. * -errno : An error occured. */ - int nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf); + EXTERN int nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf); @@@ -292,14 -321,14 +321,14 @@@ * -errno : An error occured. * data is the error string. */ - 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); + 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); /* * Sync pwrite() * Function returns * >=0 : numer of bytes written. * -errno : An error occured. */ - int nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf); + EXTERN int nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf); /* @@@ -318,14 -347,14 +347,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf, nfs_cb cb, void *private_data); + EXTERN int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf, nfs_cb cb, void *private_data); /* * Sync write() * Function returns * >=0 : numer of bytes written. * -errno : An error occured. */ - int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf); + EXTERN int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf); /* @@@ -344,14 -373,14 +373,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, nfs_cb cb, void *private_data); + EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, nfs_cb cb, void *private_data); /* * Sync lseek() * Function returns * >=0 : numer of bytes read. * -errno : An error occured. */ - int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, off_t *current_offset); + EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, off_t *current_offset); /* @@@ -369,14 -398,14 +398,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data); + EXTERN int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data); /* * Sync fsync() * Function returns * 0 : Success * -errno : An error occured. */ - int nfs_fsync(struct nfs_context *nfs, struct nfsfh *nfsfh); + EXTERN int nfs_fsync(struct nfs_context *nfs, struct nfsfh *nfsfh); @@@ -395,14 -424,14 +424,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_truncate_async(struct nfs_context *nfs, const char *path, off_t length, nfs_cb cb, void *private_data); + EXTERN int nfs_truncate_async(struct nfs_context *nfs, const char *path, off_t length, nfs_cb cb, void *private_data); /* * Sync truncate() * Function returns * 0 : Success * -errno : An error occured. */ - int nfs_truncate(struct nfs_context *nfs, const char *path, off_t length); + EXTERN int nfs_truncate(struct nfs_context *nfs, const char *path, off_t length); @@@ -421,14 -450,14 +450,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length, nfs_cb cb, void *private_data); + EXTERN int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length, nfs_cb cb, void *private_data); /* * Sync ftruncate() * Function returns * 0 : Success * -errno : An error occured. */ - int nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length); + EXTERN int nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length); @@@ -450,14 -479,14 +479,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); + EXTERN int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); /* * Sync mkdir() * Function returns * 0 : Success * -errno : An error occured. */ - int nfs_mkdir(struct nfs_context *nfs, const char *path); + EXTERN int nfs_mkdir(struct nfs_context *nfs, const char *path); @@@ -476,14 -505,14 +505,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); + EXTERN int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); /* * Sync rmdir() * Function returns * 0 : Success * -errno : An error occured. */ - int nfs_rmdir(struct nfs_context *nfs, const char *path); + EXTERN int nfs_rmdir(struct nfs_context *nfs, const char *path); @@@ -504,14 -533,14 +533,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data); + EXTERN int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data); /* * Sync creat() * Function returns * 0 : Success * -errno : An error occured. */ - int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh); + EXTERN int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh); @@@ -533,14 -562,14 +562,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); + EXTERN int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); /* * Sync unlink() * Function returns * 0 : Success * -errno : An error occured. */ - int nfs_unlink(struct nfs_context *nfs, const char *path); + EXTERN int nfs_unlink(struct nfs_context *nfs, const char *path); @@@ -564,14 -593,14 +593,14 @@@ struct nfsdir * -errno : An error occured. * data is the error string. */ - int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); + EXTERN int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); /* * Sync opendir() * Function returns * 0 : Success * -errno : An error occured. */ - int nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir); + EXTERN int nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir); @@@ -582,19 -611,11 +611,19 @@@ struct nfsdirent struct nfsdirent *next; char *name; uint64_t inode; + + /* some extra fields we get for free through the READDIRPLUS3 call. You need libnfs-raw-nfs.h for these */ + uint32_t type; /* NF3REG, NF3DIR, NF3BLK, ... */ + uint32_t mode; + uint64_t size; + struct timeval atime; + struct timeval mtime; + struct timeval ctime; }; /* * nfs_readdir() never blocks, so no special sync/async versions are available */ - struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir); + EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir); @@@ -604,7 -625,7 +633,7 @@@ /* * nfs_closedir() never blocks, so no special sync/async versions are available */ - void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir); + EXTERN void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir); @@@ -624,14 -645,14 +653,14 @@@ * data is the error string. */ struct statvfs; - int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); + EXTERN int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); /* * Sync statvfs() * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs); + EXTERN int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs); /* @@@ -651,14 -672,14 +680,14 @@@ * data is the error string. */ struct statvfs; - int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); + EXTERN int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); /* * Sync readlink() * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize); + EXTERN int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize); @@@ -677,14 -698,14 +706,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data); + EXTERN int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data); /* * Sync chmod() * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_chmod(struct nfs_context *nfs, const char *path, int mode); + EXTERN int nfs_chmod(struct nfs_context *nfs, const char *path, int mode); @@@ -703,14 -724,14 +732,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data); + EXTERN int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data); /* * Sync fchmod() * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode); + EXTERN int nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode); @@@ -729,14 -750,14 +758,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data); + EXTERN int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data); /* * Sync chown() * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid); + EXTERN int nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid); @@@ -755,14 -776,14 +784,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data); + EXTERN int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data); /* * Sync fchown() * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid); + EXTERN int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid); @@@ -782,14 -803,14 +811,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data); + EXTERN int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data); /* * Sync utimes() * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times); + EXTERN int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times); /* @@@ -808,14 -829,14 +837,14 @@@ * data is the error string. */ struct utimbuf; - int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data); + EXTERN int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data); /* * Sync utime() * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times); + EXTERN int nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times); @@@ -835,14 -856,14 +864,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data); + EXTERN int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data); /* * Sync access() * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_access(struct nfs_context *nfs, const char *path, int mode); + EXTERN int nfs_access(struct nfs_context *nfs, const char *path, int mode); @@@ -862,14 -883,14 +891,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data); + EXTERN int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data); /* * Sync symlink() * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_symlink(struct nfs_context *nfs, const char *oldpath, const char *newpath); + EXTERN int nfs_symlink(struct nfs_context *nfs, const char *oldpath, const char *newpath); /* @@@ -887,14 -908,14 +916,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data); + EXTERN int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data); /* * Sync rename(, ) * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath); + EXTERN int nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath); @@@ -913,14 -934,14 +942,14 @@@ * -errno : An error occured. * data is the error string. */ - int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data); + EXTERN int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data); /* * Sync link(, ) * Function returns * 0 : The operation was successfull. * -errno : The command failed. */ - int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath); + EXTERN int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath); /* @@@ -944,7 -965,7 +973,7 @@@ * -errno : An error occured. * data is the error string. */ - int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data); + EXTERN int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data); /* * Sync getexports() * Function returns @@@ -953,9 -974,9 +982,9 @@@ * * returned data must be freed by calling mount_free_export_list(exportnode); */ - struct exportnode *mount_getexports(const char *server); + EXTERN struct exportnode *mount_getexports(const char *server); - void mount_free_export_list(struct exportnode *exports); + EXTERN void mount_free_export_list(struct exportnode *exports); //qqq replace later with lseek(cur, 0) diff --combined lib/libnfs-sync.c index 510772f,3d3692b..cfeb575 --- a/lib/libnfs-sync.c +++ b/lib/libnfs-sync.c @@@ -18,25 -18,31 +18,38 @@@ * High level api to nfs filesystems */ + #if defined (WIN32) + #include + #define DllExport + #else + #include + #include + #include + #include + #include + #include + #include + #include + #endif + + #ifdef HAVE_CONFIG_H #include "config.h" + #endif + #include #include #include - #include #include #include - #include - #include - #include #include #include +#include +#include +#include +#include +#ifdef HAVE_SYS_SOCKIO_H +#include +#endif #include "libnfs.h" #include "libnfs-raw.h" #include "libnfs-raw-mount.h" @@@ -1174,7 -1180,7 +1187,7 @@@ void mount_free_export_list(struct expo - + #if !defined(WIN32) void free_nfs_srvr_list(struct nfs_server_list *srv) { while (srv != NULL) { @@@ -1380,3 -1386,4 +1393,4 @@@ struct nfs_server_list *nfs_find_local_ return data.srvrs; } + #endif diff --combined lib/libnfs.c index 7537235,df8ae80..eee5d5a --- a/lib/libnfs.c +++ b/lib/libnfs.c @@@ -19,17 -19,27 +19,27 @@@ */ #define _GNU_SOURCE + + #if defined(WIN32) + #include + #define DllExport + #define O_SYNC 0 + typedef int uid_t; + typedef int gid_t; + #else + #include + #include + #include + #include + #endif + #include #include #include #include - #include #include #include #include - #include - #include - #include #include #include "libnfs.h" #include "libnfs-raw.h" @@@ -671,8 -681,10 +681,10 @@@ static void nfs_stat_1_cb(struct rpc_co st.st_gid = res->GETATTR3res_u.resok.obj_attributes.gid; st.st_rdev = 0; st.st_size = res->GETATTR3res_u.resok.obj_attributes.size; + #if !defined(WIN32) st.st_blksize = 4096; st.st_blocks = res->GETATTR3res_u.resok.obj_attributes.size / 4096; + #endif st.st_atime = res->GETATTR3res_u.resok.obj_attributes.atime.seconds; st.st_mtime = res->GETATTR3res_u.resok.obj_attributes.mtime.seconds; st.st_ctime = res->GETATTR3res_u.resok.obj_attributes.ctime.seconds; @@@ -1651,13 -1663,13 +1663,13 @@@ int nfs_unlink_async(struct nfs_contex */ static void nfs_opendir_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) { - READDIR3res *res; + READDIRPLUS3res *res; struct nfs_cb_data *data = private_data; struct nfs_context *nfs = data->nfs; - struct nfsdir *nfsdir = data->continue_data;; + struct nfsdir *nfsdir = data->continue_data; - struct entry3 *entry; + struct entryplus3 *entry; uint64_t cookie; - + if (status == RPC_STATUS_ERROR) { data->cb(-EFAULT, nfs, command_data, data->private_data); nfs_free_nfsdir(nfsdir); @@@ -1683,7 -1695,7 +1695,7 @@@ return; } - entry =res->READDIR3res_u.resok.reply.entries; + entry =res->READDIRPLUS3res_u.resok.reply.entries; while (entry != NULL) { struct nfsdirent *nfsdirent; @@@ -1705,19 -1717,6 +1717,19 @@@ return; } nfsdirent->inode = entry->fileid; + if (entry->name_attributes.attributes_follow) { + nfsdirent->type = entry->name_attributes.post_op_attr_u.attributes.type; + nfsdirent->mode = entry->name_attributes.post_op_attr_u.attributes.mode; + nfsdirent->size = entry->name_attributes.post_op_attr_u.attributes.size; + + nfsdirent->atime.tv_sec = entry->name_attributes.post_op_attr_u.attributes.atime.seconds; + nfsdirent->atime.tv_usec = entry->name_attributes.post_op_attr_u.attributes.atime.nseconds/1000; + nfsdirent->mtime.tv_sec = entry->name_attributes.post_op_attr_u.attributes.mtime.seconds; + nfsdirent->mtime.tv_usec = entry->name_attributes.post_op_attr_u.attributes.mtime.nseconds/1000; + nfsdirent->ctime.tv_sec = entry->name_attributes.post_op_attr_u.attributes.ctime.seconds; + nfsdirent->ctime.tv_usec = entry->name_attributes.post_op_attr_u.attributes.ctime.nseconds/1000; + } + nfsdirent->next = nfsdir->entries; nfsdir->entries = nfsdirent; @@@ -1725,9 -1724,9 +1737,9 @@@ entry = entry->nextentry; } - if (res->READDIR3res_u.resok.reply.eof == 0) { - if (rpc_nfs_readdir_async(nfs->rpc, nfs_opendir_cb, &data->fh, cookie, res->READDIR3res_u.resok.cookieverf, 20000, data) != 0) { - rpc_set_error(nfs->rpc, "RPC error: Failed to send READDIR call for %s", data->path); + if (res->READDIRPLUS3res_u.resok.reply.eof == 0) { + if (rpc_nfs_readdirplus_async(nfs->rpc, nfs_opendir_cb, &data->fh, cookie, res->READDIRPLUS3res_u.resok.cookieverf, 8192, data) != 0) { + rpc_set_error(nfs->rpc, "RPC error: Failed to send READDIRPLUS call for %s", data->path); data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); nfs_free_nfsdir(nfsdir); data->continue_data = NULL; @@@ -1750,8 -1749,8 +1762,8 @@@ static int nfs_opendir_continue_interna cookieverf3 cv; bzero(cv, sizeof(cookieverf3)); - if (rpc_nfs_readdir_async(nfs->rpc, nfs_opendir_cb, &data->fh, 0, (char *)&cv, 20000, data) != 0) { - rpc_set_error(nfs->rpc, "RPC error: Failed to send READDIR call for %s", data->path); + if (rpc_nfs_readdirplus_async(nfs->rpc, nfs_opendir_cb, &data->fh, 0, (char *)&cv, 8192, data) != 0) { + rpc_set_error(nfs->rpc, "RPC error: Failed to send READDIRPLUS call for %s", data->path); data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); free_nfs_cb_data(data); return -1; @@@ -2900,7 -2899,8 +2912,8 @@@ void nfs_set_error(struct nfs_context * char *str = NULL; va_start(ap, error_string); - vasprintf(&str, error_string, ap); + str = malloc(1024); + vsnprintf(str, 1024, error_string, ap); if (nfs->rpc->error_string != NULL) { free(nfs->rpc->error_string); } @@@ -3082,3 -3082,35 +3095,36 @@@ const char *nfs_get_server(struct nfs_c const char *nfs_get_export(struct nfs_context *nfs) { return nfs->export; } + + + #if defined(WIN32) + int poll(struct pollfd *fds, int nfsd, int timeout) + { + fd_set rfds, wfds, efds; + int ret; + + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_ZERO(&efds); + if (fds->events & POLLIN) { + FD_SET(fds->fd, &rfds); + } + if (fds->events & POLLOUT) { + FD_SET(fds->fd, &wfds); + } + FD_SET(fds->fd, &efds); + select(fds->fd + 1, &rfds, &wfds, &efds, NULL); + fds->revents = 0; + if (FD_ISSET(fds->fd, &rfds)) { + fds->revents |= POLLIN; + } + if (FD_ISSET(fds->fd, &wfds)) { + fds->revents |= POLLOUT; + } + if (FD_ISSET(fds->fd, &efds)) { + fds->revents |= POLLHUP; + } ++ return 1; + } + #endif + diff --combined lib/socket.c index e96636a,4d4859e..e9c103e --- a/lib/socket.c +++ b/lib/socket.c @@@ -15,29 -15,35 +15,38 @@@ along with this program; if not, see . */ + #if defined(WIN32) + #include + #include + #include + #define ssize_t SSIZE_T + #define MSG_DONTWAIT 0 + #else + #include + #include + #include + #include + #include + #include + #endif + #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include - #include #include - #include #include #include #include #include - #include #ifdef HAVE_SYS_FILIO_H #include #endif +#ifdef HAVE_SYS_SOCKIO_H +#include +#endif - #include #include - #include - #include #include "libnfs.h" #include "libnfs-raw.h" #include "libnfs-private.h" @@@ -47,9 -53,12 +56,12 @@@ static int rpc_disconnect_requeue(struc static void set_nonblocking(int fd) { + #if defined(WIN32) + #else unsigned v; v = fcntl(fd, F_GETFL, 0); fcntl(fd, F_SETFL, v | O_NONBLOCK); + #endif } int rpc_get_fd(struct rpc_context *rpc) @@@ -89,7 -98,11 +101,11 @@@ static int rpc_write_to_socket(struct r total = rpc->outqueue->outdata.size; + #if defined(WIN32) + count = send(rpc->fd, rpc->outqueue->outdata.data + rpc->outqueue->written, total - rpc->outqueue->written, 0); + #else count = write(rpc->fd, rpc->outqueue->outdata.data + rpc->outqueue->written, total - rpc->outqueue->written); + #endif if (count == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { return 0; @@@ -116,7 -129,11 +132,11 @@@ static int rpc_read_from_socket(struct int pdu_size; ssize_t count; + #if defined(WIN32) + if (ioctlsocket(rpc->fd, FIONREAD, &available) != 0) { + #else if (ioctl(rpc->fd, FIONREAD, &available) != 0) { + #endif rpc_set_error(rpc, "Ioctl FIONREAD returned error : %d. Closing socket.", errno); return -1; } @@@ -160,7 -177,11 +180,11 @@@ if (rpc->inpos < 4) { size = 4 - rpc->inpos; + #if defined(WIN32) + count = recv(rpc->fd, rpc->inbuf + rpc->inpos, size, 0); + #else count = read(rpc->fd, rpc->inbuf + rpc->inpos, size); + #endif if (count == -1) { if (errno == EINTR) { return 0; @@@ -196,7 -217,11 +220,11 @@@ size = rpc->insize - rpc->inpos; } + #if defined(WIN32) + count = recv(rpc->fd, rpc->inbuf + rpc->inpos, size, 0); + #else count = read(rpc->fd, rpc->inbuf + rpc->inpos, size); + #endif if (count == -1) { if (errno == EINTR) { return 0; @@@ -319,7 -344,7 +347,7 @@@ int rpc_connect_async(struct rpc_contex #ifdef HAVE_SOCKADDR_LEN sin->sin_len = socksize; #endif - rpc->fd = socket(AF_INET, SOCK_STREAM, 0); + rpc->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); break; } @@@ -344,7 -369,11 +372,11 @@@ int rpc_disconnect(struct rpc_context *rpc, char *error) { if (rpc->fd != -1) { + #if defined(WIN32) + closesocket(rpc->fd); + #else close(rpc->fd); + #endif } rpc->fd = -1; @@@ -361,7 -390,11 +393,11 @@@ static int rpc_disconnect_requeue(struc struct rpc_pdu *pdu; if (rpc->fd != -1) { + #if defined(WIN32) + closesocket(rpc->fd); + #else close(rpc->fd); + #endif } rpc->fd = -1; @@@ -389,7 -422,7 +425,7 @@@ int rpc_bind_udp(struct rpc_context *rp return -1; } - snprintf(service, 6, "%d", port); + sprintf(service, "%d", port); if (getaddrinfo(addr, service, NULL, &ai) != 0) { rpc_set_error(rpc, "Invalid address:%s. " "Can not resolv into IPv4/v6 structure."); @@@ -432,7 -465,7 +468,7 @@@ int rpc_set_udp_destination(struct rpc_ return -1; } - snprintf(service, 6, "%d", port); + sprintf(service, "%d", port); if (getaddrinfo(addr, service, NULL, &ai) != 0) { rpc_set_error(rpc, "Invalid address:%s. " "Can not resolv into IPv4/v6 structure."); diff --combined nfs/nfs.c index 5b655cb,a32521e..0c8ff79 --- a/nfs/nfs.c +++ b/nfs/nfs.c @@@ -15,6 -15,19 +15,19 @@@ along with this program; if not, see . */ + #if defined(WIN32) + #include + #define S_IRUSR 0000400 + #define S_IWUSR 0000200 + #define S_IXUSR 0000100 + #define S_IRGRP 0000040 + #define S_IWGRP 0000020 + #define S_IXGRP 0000010 + #define S_IROTH 0000004 + #define S_IWOTH 0000002 + #define S_IXOTH 0000001 + #endif + #include #include #include @@@ -476,6 -489,7 +489,6 @@@ int rpc_nfs_remove_async(struct rpc_con return 0; } - int rpc_nfs_readdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data) { struct rpc_pdu *pdu; @@@ -509,40 -523,6 +522,40 @@@ return 0; } +int rpc_nfs_readdirplus_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data) +{ + struct rpc_pdu *pdu; + READDIRPLUS3args args; + + pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READDIRPLUS, cb, private_data, (xdrproc_t)xdr_READDIRPLUS3res, sizeof(READDIRPLUS3res)); + if (pdu == NULL) { + rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/readdirplus call"); + return -1; + } + + bzero(&args, sizeof(READDIRPLUS3args)); + args.dir.data.data_len = fh->data.data_len; + args.dir.data.data_val = fh->data.data_val; + args.cookie = cookie; + memcpy(&args.cookieverf, cookieverf, sizeof(cookieverf3)); + args.dircount = count; + args.maxcount = count; + + if (xdr_READDIRPLUS3args(&pdu->xdr, &args) == 0) { + rpc_set_error(rpc, "XDR error: Failed to encode READDIRPLUS3args"); + rpc_free_pdu(rpc, pdu); + return -2; + } + + if (rpc_queue_pdu(rpc, pdu) != 0) { + rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/readdirplus call"); + rpc_free_pdu(rpc, pdu); + return -3; + } + + return 0; +} + int rpc_nfs_fsstat_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data) { struct rpc_pdu *pdu;