From: Ronnie Sahlberg Date: Sun, 28 Aug 2011 09:24:18 +0000 (+1000) Subject: Win32 changes, include files we need when compiling under win32 X-Git-Tag: upstream/1.9.6^2~326^2~13 X-Git-Url: https://git.piment-noir.org/?p=deb_libnfs.git;a=commitdiff_plain;h=eecdc4f3cd5c464ae02823a823993e720664e465 Win32 changes, include files we need when compiling under win32 and some socket ops are slightly different --- diff --git a/examples/nfsclient-sync.c b/examples/nfsclient-sync.c index 322bfa2..00e4c88 100644 --- a/examples/nfsclient-sync.c +++ b/examples/nfsclient-sync.c @@ -26,13 +26,22 @@ #define NFSDIR "/BOOKS/Classics/" #define _GNU_SOURCE + +#if defined(WIN32) +#include +typedef int off_t; +#pragma comment(lib, "ws2_32.lib") +WSADATA wsaData; +#else +#include +#include +#endif + #include #include #include #include #include -#include -#include #include #include "libnfs.h" #include /* for authunix_create() */ @@ -53,18 +62,25 @@ int main(int argc _U_, char *argv[] _U_) { struct nfs_context *nfs; int i, ret; + off_t offset; struct client client; struct stat st; struct nfsfh *nfsfh; struct nfsdir *nfsdir; struct nfsdirent *nfsdirent; - client.server = SERVER; - client.export = EXPORT; - client.is_finished = 0; - off_t offset; struct statvfs svfs; exports export, tmp; +#if defined(WIN32) + if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) { + printf("Failed to start Winsock2\n"); + exit(10); + } +#endif + + client.server = SERVER; + client.export = EXPORT; + client.is_finished = 0; export = mount_getexports(SERVER); if (export != NULL) { printf("exports on server %s\n", SERVER); @@ -198,11 +214,10 @@ int main(int argc _U_, char *argv[] _U_) exit(10); } while((nfsdirent = nfs_readdir(nfs, nfsdir)) != NULL) { - char *filename = NULL; + char filename[1024]; printf("Inode:%d Name:%s ", (int)nfsdirent->inode, nfsdirent->name); - asprintf(&filename, "%s/%s", NFSDIR, nfsdirent->name); + sprintf(&filename, "%s/%s", NFSDIR, nfsdirent->name); ret = nfs_open(nfs, filename, O_RDONLY, &nfsfh); - free(filename); if (ret != 0) { printf("Failed to open(%s) %s\n", filename, nfs_get_error(nfs)); exit(10); diff --git a/include/libnfs.h b/include/libnfs.h index 0676efa..2038d8a 100644 --- a/include/libnfs.h +++ b/include/libnfs.h @@ -22,6 +22,29 @@ struct nfs_context; struct rpc_context; +#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 */ diff --git a/lib/init.c b/lib/init.c index 5663f25..536a56c 100644 --- a/lib/init.c +++ b/lib/init.c @@ -16,11 +16,17 @@ */ #define _GNU_SOURCE + +#if defined(WIN32) +#include +#else +#include +#include +#endif + #include #include -#include #include -#include #include #include #include @@ -46,7 +52,11 @@ struct rpc_context *rpc_init_context(void) return NULL; } - rpc->auth = authunix_create_default(); +#if defined(WIN32) + rpc->auth = authunix_create("LibNFS", 65535, 65535, 0, NULL); +#else + rpc->auth = authunix_create_default(); +#endif if (rpc->auth == NULL) { free(rpc->encodebuf); free(rpc); @@ -135,7 +145,11 @@ void rpc_destroy_context(struct rpc_context *rpc) rpc->auth =NULL; if (rpc->fd != -1) { - close(rpc->fd); +#if defined(WIN32) + closesocket(rpc->fd); +#else + close(rpc->fd); +#endif } if (rpc->encodebuf != NULL) { diff --git a/lib/libnfs-sync.c b/lib/libnfs-sync.c index 5d46e70..3d3692b 100644 --- a/lib/libnfs-sync.c +++ b/lib/libnfs-sync.c @@ -18,22 +18,31 @@ * 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 #include "libnfs.h" #include "libnfs-raw.h" #include "libnfs-raw-mount.h" @@ -1171,7 +1180,7 @@ void mount_free_export_list(struct exportnode *exports) - +#if !defined(WIN32) void free_nfs_srvr_list(struct nfs_server_list *srv) { while (srv != NULL) { @@ -1377,3 +1386,4 @@ struct nfs_server_list *nfs_find_local_servers(void) return data.srvrs; } +#endif diff --git a/mount/mount.c b/mount/mount.c index 525c852..6b6bf74 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -15,6 +15,10 @@ along with this program; if not, see . */ +#if defined(WIN32) +#include +#endif + #include #include #include diff --git a/nfs/nfs.c b/nfs/nfs.c index a9775e7..a32521e 100644 --- a/nfs/nfs.c +++ b/nfs/nfs.c @@ -15,6 +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 diff --git a/nfs/nfsacl.c b/nfs/nfsacl.c index 797745c..01e26c3 100644 --- a/nfs/nfsacl.c +++ b/nfs/nfsacl.c @@ -15,6 +15,10 @@ along with this program; if not, see . */ +#if defined(WIN32) +#include +#endif + #include #include #include diff --git a/portmap/portmap.c b/portmap/portmap.c index 07aa912..431fb15 100644 --- a/portmap/portmap.c +++ b/portmap/portmap.c @@ -15,6 +15,10 @@ along with this program; if not, see . */ +#if defined(WIN32) +#include +#endif + #include #include #include diff --git a/rquota/rquota.c b/rquota/rquota.c index 30abc67..55919d5 100644 --- a/rquota/rquota.c +++ b/rquota/rquota.c @@ -15,6 +15,10 @@ along with this program; if not, see . */ +#if defined(WIN32) +#include +#endif + #include #include #include