From 7f7993883c95285601fd19bb07c0742e393b6bd4 Mon Sep 17 00:00:00 2001 From: Memphiz Date: Thu, 1 Sep 2011 21:31:56 +0200 Subject: [PATCH] [add] - win32 compat stuff --- README.win32.txt | 6 + lib/libnfs-win32.def | 76 ++++++++++++ win32/win32_compat.c | 270 +++++++++++++++++++++++++++++++++++++++++++ win32/win32_compat.h | 84 ++++++++++++++ win32/win32build.bat | 97 ++++++++++++++++ 5 files changed, 533 insertions(+) create mode 100644 README.win32.txt create mode 100644 lib/libnfs-win32.def create mode 100644 win32/win32_compat.c create mode 100644 win32/win32_compat.h create mode 100644 win32/win32build.bat diff --git a/README.win32.txt b/README.win32.txt new file mode 100644 index 0000000..6e482c8 --- /dev/null +++ b/README.win32.txt @@ -0,0 +1,6 @@ +1. checkout oncrpc-win32 project (branch hyper!) +2. build oncrpc-win32 project (see README.win32 in the projects dir) +3. checkout libnfs (branch win32) +4. adapt oncrpc-win32 path in win32/win32build.bat +4. build libnfs with cd win32;win32build.bat +5. copy lib/libnfs.dll and /win32/bin/liboncrpc.dll to the dir where the executable is... \ No newline at end of file diff --git a/lib/libnfs-win32.def b/lib/libnfs-win32.def new file mode 100644 index 0000000..e758a35 --- /dev/null +++ b/lib/libnfs-win32.def @@ -0,0 +1,76 @@ +LIBRARY libnfs +EXPORTS +mount_free_export_list +mount_getexports +mount_getexports_async +nfs_access +nfs_access_async +nfs_chmod +nfs_chmod_async +nfs_chown +nfs_chown_async +nfs_close +nfs_close_async +nfs_closedir +nfs_creat +nfs_creat_async +nfs_destroy_context +nfs_fchmod +nfs_fchmod_async +nfs_fchown +nfs_fchown_async +nfs_fstat +nfs_fstat_async +nfs_fsync +nfs_fsync_async +nfs_ftruncate +nfs_ftruncate_async +nfs_get_error +nfs_get_fd +nfs_get_readmax +nfs_get_writemax +nfs_init_context +nfs_link +nfs_link_async +nfs_lseek +nfs_lseek_async +nfs_mkdir +nfs_mkdir_async +nfs_mount +nfs_mount_async +nfs_open +nfs_open_async +nfs_opendir +nfs_opendir_async +nfs_pread +nfs_pread_async +nfs_pwrite +nfs_pwrite_async +nfs_read +nfs_read_async +nfs_readdir +nfs_readlink +nfs_readlink_async +nfs_rename +nfs_rename_async +nfs_rmdir +nfs_rmdir_async +nfs_service +nfs_set_auth +nfs_stat +nfs_stat_async +nfs_statvfs +nfs_statvfs_async +nfs_symlink +nfs_symlink_async +nfs_truncate +nfs_truncate_async +nfs_unlink +nfs_unlink_async +nfs_utime +nfs_utime_async +nfs_utimes +nfs_utimes_async +nfs_which_events +nfs_write +nfs_write_async diff --git a/win32/win32_compat.c b/win32/win32_compat.c new file mode 100644 index 0000000..b8d8680 --- /dev/null +++ b/win32/win32_compat.c @@ -0,0 +1,270 @@ +/* +Copyright (c) 2006 by Dan Kennedy. +Copyright (c) 2006 by Juliusz Chroboczek. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef WIN32 + +static int dummy ATTRIBUTE((unused)); + +#else +#include "win32_compat.h" +#include +#include +#undef poll +#undef socket +#undef connect +#undef accept +#undef shutdown +#undef getpeername +#undef sleep +#undef inet_aton +#undef gettimeofday +#undef stat +#define bzero(a,b) memset((a),(0),(b)) +#define assert(a) + +/* Windows needs this header file for the implementation of inet_aton() */ +#include + +int win32_inet_pton(int af, const char * src, void * dst) +{ + int temp = sizeof(struct sockaddr_in); + char *srcNonConst = (char *)malloc(strlen(src)+1); + strncpy(srcNonConst,src,strlen(src)); + WSAStringToAddress(srcNonConst,af,NULL,(LPSOCKADDR)dst,&temp); + return temp; +} + +/* + * Check whether "cp" is a valid ascii representation of an Internet address + * and convert to a binary address. Returns 1 if the address is valid, 0 if + * not. This replaces inet_addr, the return value from which cannot + * distinguish between failure and a local broadcast address. + * + * This implementation of the standard inet_aton() function was copied + * (with trivial modifications) from the OpenBSD project. + */ +int +win32_inet_aton(const char *cp, struct in_addr *addr) +{ + register unsigned int val; + register int base, n; + register char c; + unsigned int parts[4]; + register unsigned int *pp = parts; + + assert(sizeof(val) == 4); + + c = *cp; + while(1) { + /* + * Collect number up to ``.''. + * Values are specified as for C: + * 0x=hex, 0=octal, isdigit=decimal. + */ + if(!isdigit(c)) + return (0); + val = 0; base = 10; + if(c == '0') { + c = *++cp; + if(c == 'x' || c == 'X') + base = 16, c = *++cp; + else + base = 8; + } + while(1) { + if(isascii(c) && isdigit(c)) { + val = (val * base) + (c - '0'); + c = *++cp; + } else if(base == 16 && isascii(c) && isxdigit(c)) { + val = (val << 4) | + (c + 10 - (islower(c) ? 'a' : 'A')); + c = *++cp; + } else + break; + } + if(c == '.') { + /* + * Internet format: + * a.b.c.d + * a.b.c (with c treated as 16 bits) + * a.b (with b treated as 24 bits) + */ + if(pp >= parts + 3) + return (0); + *pp++ = val; + c = *++cp; + } else + break; + } + /* + * Check for trailing characters. + */ + if(c != '\0' && (!isascii(c) || !isspace(c))) + return (0); + /* + * Concoct the address according to + * the number of parts specified. + */ + n = pp - parts + 1; + switch(n) { + + case 0: + return (0); /* initial nondigit */ + + case 1: /* a -- 32 bits */ + break; + + case 2: /* a.b -- 8.24 bits */ + if((val > 0xffffff) || (parts[0] > 0xff)) + return (0); + val |= parts[0] << 24; + break; + + case 3: /* a.b.c -- 8.8.16 bits */ + if((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff)) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16); + break; + + case 4: /* a.b.c.d -- 8.8.8.8 bits */ + if((val > 0xff) || (parts[0] > 0xff) || + (parts[1] > 0xff) || (parts[2] > 0xff)) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + break; + } + if(addr) + addr->s_addr = htonl(val); + return (1); +} + +unsigned int +win32_sleep(unsigned int seconds) +{ + Sleep(seconds * 1000); + return 0; +} + +int win32_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); + ret = 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 ret; +} + +/*int win32_poll(struct pollfd *fds, unsigned int nfds, int timo) +{ + struct timeval timeout, *toptr; + fd_set ifds, ofds, efds, *ip, *op; + int i, rc; + + // Set up the file-descriptor sets in ifds, ofds and efds. + FD_ZERO(&ifds); + FD_ZERO(&ofds); + FD_ZERO(&efds); + for (i = 0, op = ip = 0; i < nfds; ++i) { + fds[i].revents = 0; + if(fds[i].events & (POLLIN|POLLPRI)) { + ip = &ifds; + FD_SET(fds[i].fd, ip); + } + if(fds[i].events & POLLOUT) { + op = &ofds; + FD_SET(fds[i].fd, op); + } + FD_SET(fds[i].fd, &efds); + } + + // Set up the timeval structure for the timeout parameter + if(timo < 0) { + toptr = 0; + } else { + toptr = &timeout; + timeout.tv_sec = timo / 1000; + timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; + } + +#ifdef DEBUG_POLL + printf("Entering select() sec=%ld usec=%ld ip=%lx op=%lx\n", + (long)timeout.tv_sec, (long)timeout.tv_usec, (long)ip, (long)op); +#endif + rc = select(0, ip, op, &efds, toptr); +#ifdef DEBUG_POLL + printf("Exiting select rc=%d\n", rc); +#endif + + if(rc <= 0) + return rc; + + if(rc > 0) { + for (i = 0; i < nfds; ++i) { + int fd = fds[i].fd; + if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds)) + fds[i].revents |= POLLIN; + if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds)) + fds[i].revents |= POLLOUT; + if(FD_ISSET(fd, &efds)) + // Some error was detected ... should be some way to know. + fds[i].revents |= POLLHUP; +#ifdef DEBUG_POLL + printf("%d %d %d revent = %x\n", + FD_ISSET(fd, &ifds), FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds), + fds[i].revents + ); +#endif + } + } + return rc; +} +*/ +#endif diff --git a/win32/win32_compat.h b/win32/win32_compat.h new file mode 100644 index 0000000..2ddb0ff --- /dev/null +++ b/win32/win32_compat.h @@ -0,0 +1,84 @@ +/* +Copyright (c) 2006 by Dan Kennedy. +Copyright (c) 2006 by Juliusz Chroboczek. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +/*Adaptions by memphiz@xbmc.org*/ + +#ifdef WIN32 +#ifndef win32_COMPAT_H_ +#define win32_COMPAT_H_ +#define NO_IPv6 1 + +#include +#include +#include +#include +#include + +typedef int uid_t; +typedef int gid_t; +typedef int socklen_t; + + +#define S_IRUSR 0000400 +#define S_IWUSR 0000200 +#define S_IXUSR 0000100 +#define S_IRWXG 0000070 /* RWX mask for group */ +#define S_IRGRP 0000040 +#define S_IWGRP 0000020 +#define S_IXGRP 0000010 +#define S_IRWXO 0000007 /* RWX mask for other */ +#define S_IROTH 0000004 +#define S_IWOTH 0000002 +#define S_IXOTH 0000001 + +#define F_GETFL 3 +#define F_SETFL 4 + +#define O_NONBLOCK 0x40000000 +#define O_SYNC 0 + +#define MSG_DONTWAIT 0 +#define ssize_t SSIZE_T + +#define POLLIN 0x0001 /* There is data to read */ +#define POLLPRI 0x0002 /* There is urgent data to read */ +#define POLLOUT 0x0004 /* Writing now will not block */ +#define POLLERR 0x0008 /* Error condition */ +#define POLLHUP 0x0010 /* Hung up */ +#define POLLNVAL 0x0020 /* Invalid request: fd not open */ + +struct pollfd { + SOCKET fd; /* file descriptor */ + short events; /* requested events */ + short revents; /* returned events */ +}; + +/* Wrapper macros to call misc. functions win32 is missing */ +#define poll(x, y, z) win32_poll(x, y, z) +#define inet_aton(x, y) win32_inet_aton(x, y) +#define inet_pton(x,y,z) win32_inet_pton(x,y,z) +int win32_inet_aton(const char *, struct in_addr *); +int win32_inet_pton(int af, const char * src, void * dst); +int win32_poll(struct pollfd *fds, int nfsd, int timeout); + +#endif//win32_COMPAT_H_ +#endif//WIN32 diff --git a/win32/win32build.bat b/win32/win32build.bat new file mode 100644 index 0000000..55317ec --- /dev/null +++ b/win32/win32build.bat @@ -0,0 +1,97 @@ +rem build script for win32 +rem set the +rem + +rem EDIT THESE +set ONCRPC_BASE_DIR=C:\MinGW\msys\1.0\home\Administrator\src\oncrpc-win32\ +set LIBNFS_BASE_DIR=.. +rem END EDIT + +set RPCINCLUDE="%ONCRPC_BASE_DIR%\win32\include" +set RPCDLL="%ONCRPC_BASE_DIR%\win32\bin\oncrpc.dll" +set RPCLIB="%ONCRPC_BASE_DIR%\win32\bin\oncrpc.lib" +set RPCGEN="%ONCRPC_BASE_DIR%\win32\bin\rpcgen.exe" + + +cd %LIBNFS_BASE_DIR% + +rem generate NFS from .x +rem +copy nfs\nfs.x nfs\libnfs-raw-nfs.x +%RPCGEN% -h nfs\libnfs-raw-nfs.x > nfs\libnfs-raw-nfs.h +%RPCGEN% -c nfs\libnfs-raw-nfs.x > nfs\libnfs-raw-nfs.c +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd nfs\libnfs-raw-nfs.c -Fonfs\libnfs-raw-nfs.obj +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd nfs\nfs.c -Fonfs\nfs.obj +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd nfs\nfsacl.c -Fonfs\nfsacl.obj + + + +rem +rem generate RQUOTA from .x +rem +copy rquota\rquota.x rquota\libnfs-raw-rquota.x +%RPCGEN% -h rquota\libnfs-raw-rquota.x > rquota\libnfs-raw-rquota.h +%RPCGEN% -c rquota\libnfs-raw-rquota.x > rquota\libnfs-raw-rquota.c +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd rquota\libnfs-raw-rquota.c -Forquota\libnfs-raw-rquota.obj +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd rquota\rquota.c -Forquota\rquota.obj + + + +rem +rem generate PORTMAP from .x +rem +copy portmap\portmap.x portmap\libnfs-raw-portmap.x +%RPCGEN% -h portmap\libnfs-raw-portmap.x > portmap\libnfs-raw-portmap.h +%RPCGEN% -c portmap\libnfs-raw-portmap.x > portmap\libnfs-raw-portmap.c +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd portmap\libnfs-raw-portmap.c -Foportmap\libnfs-raw-portmap.obj +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd portmap\portmap.c -Foportmap\portmap.obj + + +rem +rem generate MOUNT from .x +rem +copy mount\mount.x mount\libnfs-raw-mount.x +%RPCGEN% -h mount\libnfs-raw-mount.x > mount\libnfs-raw-mount.h +%RPCGEN% -c mount\libnfs-raw-mount.x > mount\libnfs-raw-mount.c +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd mount\libnfs-raw-mount.c -Fomount\libnfs-raw-mount.obj +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd mount\mount.c -Fomount\mount.obj + + + +rem +rem generate core part of library +rem +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd lib\init.c -Folib\init.obj +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd -D_U_="" lib\pdu.c -Folib\pdu.obj +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd -D_U_="" lib\socket.c -Folib\socket.obj +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% /Imount /Infs -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd -D_U_="" lib\libnfs.c -Folib\libnfs.obj +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% /Imount /Infs -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd -D_U_="" lib\libnfs-sync.c -Folib\libnfs-sync.obj + +rem +rem generate win32 compat layer +rem +cl /I. -Zi -Od -c -DWIN32 -D_WIN32_WINNT=0x0501 -MDd -D_U_="" win32\win32_compat.c -Fowin32\win32_compat.obj + + + +rem +rem create a linklibrary/dll +rem +lib /out:lib\libnfs.lib /def:lib\libnfs-win32.def nfs\nfs.obj nfs\nfsacl.obj nfs\libnfs-raw-nfs.obj rquota\rquota.obj rquota\libnfs-raw-rquota.obj mount\mount.obj mount\libnfs-raw-mount.obj portmap\portmap.obj portmap\libnfs-raw-portmap.obj lib\init.obj lib\pdu.obj lib\socket.obj lib\libnfs.obj lib\libnfs-sync.obj win32\win32_compat.obj + +link /DLL /out:lib\libnfs.dll /DEBUG /DEBUGTYPE:cv lib\libnfs.exp nfs\nfs.obj nfs\nfsacl.obj nfs\libnfs-raw-nfs.obj rquota\rquota.obj rquota\libnfs-raw-rquota.obj mount\mount.obj mount\libnfs-raw-mount.obj portmap\portmap.obj portmap\libnfs-raw-portmap.obj lib\init.obj lib\pdu.obj lib\socket.obj lib\libnfs.obj lib\libnfs-sync.obj win32\win32_compat.obj %RPCLIB% ws2_32.lib + + + +rem +rem build a test application +rem +cl /I. /Iinclude /Iwin32 /I%RPCINCLUDE% /Imount /Infs -Zi -Od -DWIN32 -D_WIN32_WINNT=0x0501 -MDd -D_U_="" examples\nfsclient-sync.c lib\libnfs.lib %RPCLIB% WS2_32.lib kernel32.lib mswsock.lib advapi32.lib wsock32.lib advapi32.lib + + + + + + + + -- 2.34.1