Win32 changes, include files we need when compiling under win32
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Sun, 28 Aug 2011 09:24:18 +0000 (19:24 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Sun, 28 Aug 2011 09:24:18 +0000 (19:24 +1000)
and some socket ops are slightly different

examples/nfsclient-sync.c
include/libnfs.h
lib/init.c
lib/libnfs-sync.c
mount/mount.c
nfs/nfs.c
nfs/nfsacl.c
portmap/portmap.c
rquota/rquota.c

index 322bfa28676eef526760c11b2b54e300a2a04863..00e4c88042eba4a3e50553acb8e79460eb11c03d 100644 (file)
 #define NFSDIR "/BOOKS/Classics/"
 
 #define _GNU_SOURCE
+
+#if defined(WIN32)
+#include <winsock2.h>
+typedef int off_t;
+#pragma comment(lib, "ws2_32.lib")
+WSADATA wsaData;
+#else
+#include <sys/statvfs.h>
+#include <unistd.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/statvfs.h>
-#include <unistd.h>
 #include <fcntl.h>
 #include "libnfs.h"
 #include <rpc/rpc.h>            /* 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);
index 0676efa787c58e83aba834986be3363919b0e3b2..2038d8a0a335800217dba3b080f594e94c12464e 100644 (file)
 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
  */
index 5663f250123ef1b6bccf24b0b84feae768083961..536a56c605ac75111b10ba0e142d7690c1b41649 100644 (file)
 */
 
 #define _GNU_SOURCE
+
+#if defined(WIN32)
+#include <winsock2.h>
+#else
+#include <unistd.h>
+#include <strings.h>
+#endif
+
 #include <stdio.h>
 #include <stdarg.h>
-#include <unistd.h>
 #include <string.h>
-#include <strings.h>
 #include <stdlib.h>
 #include <rpc/rpc.h>
 #include <rpc/xdr.h>
@@ -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) {
index 5d46e70b935d445166f4c2d8d7fed64f307c22fa..3d3692b403ebcf18c1d117b890f3984bb1b50cd9 100644 (file)
  * High level api to nfs filesystems
  */
 
+#if defined (WIN32)
+#include <winsock2.h>
+#define DllExport
+#else
+#include <strings.h>
+#include <unistd.h>
+#include <sys/statvfs.h>
+#include <poll.h>
+#include <sys/ioctl.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#endif
+
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <strings.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/statvfs.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <poll.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <netdb.h>
 #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
index 525c8526a5fd12e94e80da5d463c9b2e88105570..6b6bf743252f93347bc7f4075a97c0f9abbee402 100644 (file)
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#if defined(WIN32)
+#include <winsock2.h>
+#endif
+
 #include <stdio.h>
 #include <errno.h>
 #include <rpc/rpc.h>
index a9775e7f3ab3d4cf5f9cc8a9c9287bd3c2c68490..a32521e4a8b1e6d24ab1b21ce978586ec89b0264 100644 (file)
--- a/nfs/nfs.c
+++ b/nfs/nfs.c
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#if defined(WIN32)
+#include <winsock2.h>
+#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 <stdio.h>
 #include <errno.h>
 #include <sys/stat.h>
index 797745c1f514b5a7e33964700df1d5359d723293..01e26c302d1a0f2d386c02fd28eced2dc63b26ea 100644 (file)
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#if defined(WIN32)
+#include <winsock2.h>
+#endif
+
 #include <stdio.h>
 #include <errno.h>
 #include <sys/stat.h>
index 07aa91276ea07ce06c9653cd56f851c4b22ee4d1..431fb1560b9e0d94a636f779bfc07b24d447cab6 100644 (file)
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#if defined(WIN32)
+#include <winsock2.h>
+#endif
+
 #include <stdio.h>
 #include <rpc/rpc.h>
 #include <rpc/xdr.h>
index 30abc679ee017ee32d3a2ec613212b90c91ac661..55919d54eb035215a8f7d5416cd17648097bc2e0 100644 (file)
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#if defined(WIN32)
+#include <winsock2.h>
+#endif
+
 #include <stdio.h>
 #include <errno.h>
 #include <sys/stat.h>