From a8a1b85846aab042cd410bf59caf617a0951380e Mon Sep 17 00:00:00 2001 From: Memphiz Date: Thu, 1 Sep 2011 21:35:54 +0200 Subject: [PATCH] [win32] - make it compile on win32 --- examples/nfsclient-async.c | 12 ++++++++---- examples/nfsclient-raw.c | 6 +++++- examples/nfsclient-sync.c | 11 ++++++++--- lib/init.c | 9 ++++----- lib/libnfs-sync.c | 19 ++++++++++++++----- lib/libnfs.c | 26 ++++++++++++++------------ lib/pdu.c | 9 +++++---- lib/socket.c | 15 +++++++++++++-- mount/mount.c | 7 +++---- nfs/nfs.c | 22 ++++++++-------------- nfs/nfsacl.c | 6 +++++- portmap/portmap.c | 3 +++ rquota/rquota.c | 3 +++ 13 files changed, 93 insertions(+), 55 deletions(-) diff --git a/examples/nfsclient-async.c b/examples/nfsclient-async.c index d8420e1..c5d0df1 100644 --- a/examples/nfsclient-async.c +++ b/examples/nfsclient-async.c @@ -17,7 +17,14 @@ /* Example program using the highlevel async interface. */ - +#ifdef WIN32 +#include "win32_compat.h" +#else +#include +#include +#include +#endif + #define SERVER "10.1.1.27" #define EXPORT "/VIRTUAL" #define NFSFILE "/BOOKS/Classics/Dracula.djvu" @@ -27,10 +34,7 @@ #include #include #include -#include #include -#include -#include #include "libnfs.h" #include "libnfs-raw.h" #include "libnfs-raw-mount.h" diff --git a/examples/nfsclient-raw.c b/examples/nfsclient-raw.c index 7956781..948909f 100644 --- a/examples/nfsclient-raw.c +++ b/examples/nfsclient-raw.c @@ -19,13 +19,17 @@ * This allow accurate control of the exact commands that are being used. */ +#ifdef WIN32 +#include "win32_compat.h" +#else +#include +#endif #define SERVER "10.1.1.27" #define EXPORT "/shared" #include #include #include -#include #include "libnfs.h" #include "libnfs-raw.h" #include "libnfs-raw-mount.h" diff --git a/examples/nfsclient-sync.c b/examples/nfsclient-sync.c index 00e4c88..449d8e3 100644 --- a/examples/nfsclient-sync.c +++ b/examples/nfsclient-sync.c @@ -17,7 +17,14 @@ /* Example program using the highlevel sync interface */ - +#ifdef WIN32 +#include "win32_compat.h" +#else +#include +#include +#include +#endif + #define SERVER "10.1.1.27" #define EXPORT "/VIRTUAL" #define NFSFILE "/BOOKS/Classics/Dracula.djvu.truncated" @@ -28,8 +35,6 @@ #define _GNU_SOURCE #if defined(WIN32) -#include -typedef int off_t; #pragma comment(lib, "ws2_32.lib") WSADATA wsaData; #else diff --git a/lib/init.c b/lib/init.c index 7ef3292..45aa78d 100644 --- a/lib/init.c +++ b/lib/init.c @@ -12,14 +12,13 @@ along with this program; if not, see . */ -#define _GNU_SOURCE - -#if defined(WIN32) -#include +#ifdef WIN32 +#include "win32_compat.h" #else #include #include -#endif +#endif/*WIN32*/ +#define _GNU_SOURCE #include #include diff --git a/lib/libnfs-sync.c b/lib/libnfs-sync.c index 6f73a7e..c769835 100644 --- a/lib/libnfs-sync.c +++ b/lib/libnfs-sync.c @@ -17,9 +17,8 @@ /* * High level api to nfs filesystems */ - -#if defined (WIN32) -#include +#ifdef WIN32 +#include "win32_compat.h" #define DllExport #else #include @@ -43,9 +42,13 @@ #include #include #include + #ifdef HAVE_SYS_SOCKIO_H #include #endif + +#include +#include #include "libnfs.h" #include "libnfs-raw.h" #include "libnfs-raw-mount.h" @@ -713,8 +716,11 @@ static void statvfs_cb(int status, struct nfs_context *nfs, void *data, void *pr nfs_set_error(nfs, "statvfs call failed with \"%s\"", (char *)data); return; } - +#ifndef WIN32 memcpy(cb_data->return_data, data, sizeof(struct statvfs)); +#else + cb_data->return_data=NULL; +#endif/**/ } int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs) @@ -1254,6 +1260,7 @@ void callit_cb(struct rpc_context *rpc, int status, void *data _U_, void *privat srv_data->srvrs = srvr; } +#ifndef WIN32 static int send_nfsd_probes(struct rpc_context *rpc, struct ifconf *ifc, struct nfs_list_data *data) { char *ptr; @@ -1305,11 +1312,13 @@ static int send_nfsd_probes(struct rpc_context *rpc, struct ifconf *ifc, struct return 0; } +#endif/*WIN32 TODO implement this with win32api FIXME*/ struct nfs_server_list *nfs_find_local_servers(void) { struct rpc_context *rpc; struct nfs_list_data data = {0, NULL}; +#ifndef WIN32 struct timeval tv_start, tv_current; struct ifconf ifc; int size, loop; @@ -1386,7 +1395,7 @@ struct nfs_server_list *nfs_find_local_servers(void) free_nfs_srvr_list(data.srvrs); return NULL; } - +#endif/*WIN32 - FIXME redef it when send_nfsd_probes is implemented for win32*/ return data.srvrs; } #endif diff --git a/lib/libnfs.c b/lib/libnfs.c index d924c29..1f64bd0 100644 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -17,21 +17,17 @@ /* * High level api to nfs filesystems */ - -#define _GNU_SOURCE - -#if defined(WIN32) -#include +#ifdef WIN32 +#include "win32_compat.h" #define DllExport -#define O_SYNC 0 -typedef int uid_t; -typedef int gid_t; #else #include #include #include #include -#endif +#endif/*WIN32*/ + +#define _GNU_SOURCE #include #include @@ -681,10 +677,10 @@ static void nfs_stat_1_cb(struct rpc_context *rpc _U_, int status, void *command 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) +#ifndef WIN32 st.st_blksize = 4096; st.st_blocks = res->GETATTR3res_u.resok.obj_attributes.size / 4096; -#endif +#endif//WIN32 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; @@ -1900,7 +1896,9 @@ static void nfs_statvfs_1_cb(struct rpc_context *rpc _U_, int status, void *comm FSSTAT3res *res; struct nfs_cb_data *data = private_data; struct nfs_context *nfs = data->nfs; +#ifndef WIN32 struct statvfs svfs; +#endif/*WIN32*/ if (status == RPC_STATUS_ERROR) { data->cb(-EFAULT, nfs, command_data, data->private_data); @@ -1921,6 +1919,7 @@ static void nfs_statvfs_1_cb(struct rpc_context *rpc _U_, int status, void *comm return; } +#ifndef WIN32 svfs.f_bsize = 4096; svfs.f_frsize = 4096; svfs.f_blocks = res->FSSTAT3res_u.resok.tbytes/4096; @@ -1934,6 +1933,9 @@ static void nfs_statvfs_1_cb(struct rpc_context *rpc _U_, int status, void *comm svfs.f_namemax = 256; data->cb(0, nfs, &svfs, data->private_data); +#else + data->cb(0, nfs,NULL, data->private_data); +#endif/*WIN32*/ free_nfs_cb_data(data); } @@ -2918,7 +2920,7 @@ void nfs_set_error(struct nfs_context *nfs, char *error_string, ...) free(nfs->rpc->error_string); } nfs->rpc->error_string = str; - va_end(ap); + va_end(ap); } diff --git a/lib/pdu.c b/lib/pdu.c index 64a4af8..d7426ce 100644 --- a/lib/pdu.c +++ b/lib/pdu.c @@ -14,13 +14,14 @@ You should have received a copy of the GNU Lesser General Public License along with this program; if not, see . */ - -#if defined(WIN32) -#include +#ifdef WIN32 +#include "win32_compat.h" +#ifndef MSG_DONTWAIT #define MSG_DONTWAIT 0 +#endif #else #include -#endif +#endif/*WIN32*/ #include #include diff --git a/lib/socket.c b/lib/socket.c index f2943cd..fe2068c 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -14,6 +14,16 @@ You should have received a copy of the GNU Lesser General Public License along with this program; if not, see . */ +#ifdef WIN32 +#include "win32_compat.h" +#else +#include +#include +#include +#include +#include +#include +#endif/*WIN32*/ #if defined(WIN32) #include @@ -61,7 +71,7 @@ static void set_nonblocking(int fd) unsigned v; v = fcntl(fd, F_GETFL, 0); fcntl(fd, F_SETFL, v | O_NONBLOCK); -#endif +#endif //FIXME } int rpc_get_fd(struct rpc_context *rpc) @@ -140,6 +150,7 @@ static int rpc_read_from_socket(struct rpc_context *rpc) rpc_set_error(rpc, "Ioctl FIONREAD returned error : %d. Closing socket.", errno); return -1; } + if (available == 0) { rpc_set_error(rpc, "Socket has been closed"); return -1; @@ -254,7 +265,7 @@ static int rpc_read_from_socket(struct rpc_context *rpc) int rpc_service(struct rpc_context *rpc, int revents) { if (revents & POLLERR) { - int err = 0; + char err = 0; socklen_t err_size = sizeof(err); if (getsockopt(rpc->fd, SOL_SOCKET, SO_ERROR, diff --git a/mount/mount.c b/mount/mount.c index 6b6bf74..c530a68 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -15,9 +15,9 @@ along with this program; if not, see . */ -#if defined(WIN32) -#include -#endif +#ifdef WIN32 +#include "win32_compat.h" +#endif/*WIN32*/ #include #include @@ -28,7 +28,6 @@ #include "libnfs-private.h" #include "libnfs-raw-mount.h" - int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) { struct rpc_pdu *pdu; diff --git a/nfs/nfs.c b/nfs/nfs.c index 8e8baf4..50836ca 100644 --- a/nfs/nfs.c +++ b/nfs/nfs.c @@ -15,22 +15,14 @@ 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 +#ifdef WIN32 +#include "win32_compat.h" +#else +#include +#endif/*WIN32*/ #include #include -#include #include #include #include @@ -39,7 +31,9 @@ #include "libnfs-private.h" #include "libnfs-raw-nfs.h" - +#ifdef WIN32 +#define bzero(a,b) memset((a),(0),(b)) +#endif/*WIN32*/ char *nfsstat3_to_str(int error) { diff --git a/nfs/nfsacl.c b/nfs/nfsacl.c index 01e26c3..ba1ca12 100644 --- a/nfs/nfsacl.c +++ b/nfs/nfsacl.c @@ -14,6 +14,11 @@ You should have received a copy of the GNU Lesser General Public License along with this program; if not, see . */ +#ifdef WIN32 +#include "win32_compat.h" +#else +#include +#endif/*WIN32*/ #if defined(WIN32) #include @@ -21,7 +26,6 @@ #include #include -#include #include #include #include diff --git a/portmap/portmap.c b/portmap/portmap.c index 431fb15..29f13d0 100644 --- a/portmap/portmap.c +++ b/portmap/portmap.c @@ -14,6 +14,9 @@ You should have received a copy of the GNU Lesser General Public License along with this program; if not, see . */ +#ifdef WIN32 +#include "win32_compat.h" +#endif/*WIN32*/ #if defined(WIN32) #include diff --git a/rquota/rquota.c b/rquota/rquota.c index 55919d5..fa528c2 100644 --- a/rquota/rquota.c +++ b/rquota/rquota.c @@ -14,6 +14,9 @@ You should have received a copy of the GNU Lesser General Public License along with this program; if not, see . */ +#ifdef WIN32 +#include "win32_compat.h" +#endif/*WIN32*/ #if defined(WIN32) #include -- 2.34.1