From: Ronnie Sahlberg Date: Sat, 3 Sep 2011 01:11:36 +0000 (+1000) Subject: Merge branch 'master' into win32-3 X-Git-Tag: upstream/1.9.6^2~325 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4ed97718b3699a76047741b9c21df7357d8fe513;hp=-c;p=deb_libnfs.git Merge branch 'master' into win32-3 --- 4ed97718b3699a76047741b9c21df7357d8fe513 diff --combined lib/init.c index d421797,d83e3ed..a247787 --- a/lib/init.c +++ b/lib/init.c @@@ -1,7 -1,10 +1,7 @@@ /* Copyright (C) 2010 by Ronnie Sahlberg - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@@ -13,17 -16,11 +13,17 @@@ */ #define _GNU_SOURCE + +#if defined(WIN32) +#include +#else +#include +#include +#endif + #include #include -#include #include -#include #include #include #include @@@ -40,7 -37,7 +40,7 @@@ struct rpc_context *rpc_init_context(vo if (rpc == NULL) { return NULL; } - bzero(rpc, sizeof(struct rpc_context)); + bzero((char *)rpc, sizeof(struct rpc_context)); rpc->encodebuflen = 65536; rpc->encodebuf = malloc(rpc->encodebuflen); @@@ -49,11 -46,7 +49,11 @@@ 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); @@@ -90,13 -83,14 +90,13 @@@ void rpc_set_auth(struct rpc_context *r void rpc_set_error(struct rpc_context *rpc, char *error_string, ...) { va_list ap; - char *str; if (rpc->error_string != NULL) { free(rpc->error_string); } va_start(ap, error_string); - vasprintf(&str, error_string, ap); - rpc->error_string = str; + rpc->error_string = malloc(1024); + vsnprintf(rpc->error_string, 1024, error_string, ap); va_end(ap); } @@@ -141,11 -135,7 +141,11 @@@ void rpc_destroy_context(struct rpc_con 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 --combined lib/libnfs.c index eee5d5a,c9ca8c6..a70e6ac --- a/lib/libnfs.c +++ b/lib/libnfs.c @@@ -19,27 -19,17 +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" @@@ -493,7 -483,7 +493,7 @@@ int nfs_mount_async(struct nfs_context rpc_set_error(nfs->rpc, "out of memory. failed to allocate memory for nfs mount data"); return -1; } - bzero(data, sizeof(struct nfs_cb_data)); + bzero((char *)data, sizeof(struct nfs_cb_data)); new_server = strdup(server); new_export = strdup(export); if (nfs->server != NULL) { @@@ -614,7 -604,7 +614,7 @@@ static int nfs_lookuppath_async(struct rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); return -1; } - bzero(data, sizeof(struct nfs_cb_data)); + bzero((char *)data, sizeof(struct nfs_cb_data)); data->nfs = nfs; data->cb = cb; data->continue_cb = continue_cb; @@@ -681,10 -671,8 +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; @@@ -779,7 -767,7 +779,7 @@@ static void nfs_open_cb(struct rpc_cont free_nfs_cb_data(data); return; } - bzero(nfsfh, sizeof(struct nfsfh)); + bzero((char *)nfsfh, sizeof(struct nfsfh)); if (data->continue_int & O_SYNC) { nfsfh->is_sync = 1; @@@ -933,7 -921,7 +933,7 @@@ int nfs_pread_async(struct nfs_context rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); return -1; } - bzero(data, sizeof(struct nfs_cb_data)); + bzero((char *)data, sizeof(struct nfs_cb_data)); data->nfs = nfs; data->cb = cb; data->private_data = private_data; @@@ -979,7 -967,7 +979,7 @@@ rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_mcb_data structure"); return -1; } - bzero(mdata, sizeof(struct nfs_mcb_data)); + bzero((char *)mdata, sizeof(struct nfs_mcb_data)); mdata->data = data; mdata->offset = offset; mdata->count = readcount; @@@ -1050,7 -1038,7 +1050,7 @@@ int nfs_pwrite_async(struct nfs_contex rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); return -1; } - bzero(data, sizeof(struct nfs_cb_data)); + bzero((char *)data, sizeof(struct nfs_cb_data)); data->nfs = nfs; data->cb = cb; data->private_data = private_data; @@@ -1109,7 -1097,7 +1109,7 @@@ int nfs_fstat_async(struct nfs_context rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); return -1; } - bzero(data, sizeof(struct nfs_cb_data)); + bzero((char *)data, sizeof(struct nfs_cb_data)); data->nfs = nfs; data->cb = cb; data->private_data = private_data; @@@ -1166,7 -1154,7 +1166,7 @@@ int nfs_fsync_async(struct nfs_context rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); return -1; } - bzero(data, sizeof(struct nfs_cb_data)); + bzero((char *)data, sizeof(struct nfs_cb_data)); data->nfs = nfs; data->cb = cb; data->private_data = private_data; @@@ -1225,12 -1213,12 +1225,12 @@@ int nfs_ftruncate_async(struct nfs_cont rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); return -1; } - bzero(data, sizeof(struct nfs_cb_data)); + bzero((char *)data, sizeof(struct nfs_cb_data)); data->nfs = nfs; data->cb = cb; data->private_data = private_data; - bzero(&args, sizeof(SETATTR3args)); + bzero((char *)&args, sizeof(SETATTR3args)); args.object.data.data_len = nfsfh->fh.data.data_len; args.object.data.data_val = nfsfh->fh.data.data_val; args.new_attributes.size.set_it = 1; @@@ -1483,7 -1471,7 +1483,7 @@@ static void nfs_create_2_cb(struct rpc_ free_nfs_cb_data(data); return; } - bzero(nfsfh, sizeof(struct nfsfh)); + bzero((char *)nfsfh, sizeof(struct nfsfh)); /* steal the filehandle */ nfsfh->fh.data.data_len = data->fh.data.data_len; @@@ -1666,7 -1654,7 +1666,7 @@@ static void nfs_opendir_cb(struct rpc_c 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 entryplus3 *entry; uint64_t cookie; @@@ -1707,7 -1695,7 +1707,7 @@@ free_nfs_cb_data(data); return; } - bzero(nfsdirent, sizeof(struct nfsdirent)); + bzero((char *)nfsdirent, sizeof(struct nfsdirent)); nfsdirent->name = strdup(entry->name); if (nfsdirent->name == NULL) { data->cb(-ENOMEM, nfs, "Failed to allocate dirent->name", data->private_data); @@@ -1761,7 -1749,7 +1761,7 @@@ static int nfs_opendir_continue_interna { cookieverf3 cv; - bzero(cv, sizeof(cookieverf3)); + bzero((char *)cv, sizeof(cookieverf3)); 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); @@@ -1780,7 -1768,7 +1780,7 @@@ int nfs_opendir_async(struct nfs_contex rpc_set_error(nfs->rpc, "failed to allocate buffer for nfsdir"); return -1; } - bzero(nfsdir, sizeof(struct nfsdir)); + bzero((char *)nfsdir, sizeof(struct nfsdir)); if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_opendir_continue_internal, nfsdir, free, 0) != 0) { rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); @@@ -2054,7 -2042,7 +2054,7 @@@ static int nfs_chmod_continue_internal( { SETATTR3args args; - bzero(&args, sizeof(SETATTR3args)); + bzero((char *)&args, sizeof(SETATTR3args)); args.object.data.data_len = data->fh.data.data_len; args.object.data.data_val = data->fh.data.data_val; args.new_attributes.mode.set_it = 1; @@@ -2092,7 -2080,7 +2092,7 @@@ int nfs_fchmod_async(struct nfs_contex rpc_set_error(nfs->rpc, "out of memory. failed to allocate memory for nfs mount data"); return -1; } - bzero(data, sizeof(struct nfs_cb_data)); + bzero((char *)data, sizeof(struct nfs_cb_data)); data->nfs = nfs; data->cb = cb; data->private_data = private_data; @@@ -2158,7 -2146,7 +2158,7 @@@ static int nfs_chown_continue_internal( SETATTR3args args; struct nfs_chown_data *chown_data = data->continue_data; - bzero(&args, sizeof(SETATTR3args)); + bzero((char *)&args, sizeof(SETATTR3args)); args.object.data.data_len = data->fh.data.data_len; args.object.data.data_val = data->fh.data.data_val; if (chown_data->uid != (uid_t)-1) { @@@ -2225,7 -2213,7 +2225,7 @@@ int nfs_fchown_async(struct nfs_contex rpc_set_error(nfs->rpc, "out of memory. failed to allocate memory for fchown data"); return -1; } - bzero(data, sizeof(struct nfs_cb_data)); + bzero((char *)data, sizeof(struct nfs_cb_data)); data->nfs = nfs; data->cb = cb; data->private_data = private_data; @@@ -2289,7 -2277,7 +2289,7 @@@ static int nfs_utimes_continue_internal SETATTR3args args; struct timeval *utimes_data = data->continue_data; - bzero(&args, sizeof(SETATTR3args)); + bzero((char *)&args, sizeof(SETATTR3args)); args.object.data.data_len = data->fh.data.data_len; args.object.data.data_val = data->fh.data.data_val; if (utimes_data != NULL) { @@@ -2537,7 -2525,7 +2537,7 @@@ int nfs_symlink_async(struct nfs_contex rpc_set_error(nfs->rpc, "Out of memory, failed to allocate buffer for symlink data"); return -1; } - bzero(symlink_data, sizeof(struct nfs_symlink_data)); + bzero((char *)symlink_data, sizeof(struct nfs_symlink_data)); symlink_data->oldpath = strdup(oldpath); if (symlink_data->oldpath == NULL) { @@@ -2691,7 -2679,7 +2691,7 @@@ int nfs_rename_async(struct nfs_contex rpc_set_error(nfs->rpc, "Out of memory, failed to allocate buffer for rename data"); return -1; } - bzero(rename_data, sizeof(struct nfs_rename_data)); + bzero((char *)rename_data, sizeof(struct nfs_rename_data)); rename_data->oldpath = strdup(oldpath); if (rename_data->oldpath == NULL) { @@@ -2847,7 -2835,7 +2847,7 @@@ int nfs_link_async(struct nfs_context * rpc_set_error(nfs->rpc, "Out of memory, failed to allocate buffer for link data"); return -1; } - bzero(link_data, sizeof(struct nfs_link_data)); + bzero((char *)link_data, sizeof(struct nfs_link_data)); link_data->oldpath = strdup(oldpath); if (link_data->oldpath == NULL) { @@@ -2912,8 -2900,7 +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); } @@@ -3067,7 -3054,7 +3067,7 @@@ int mount_getexports_async(struct rpc_c if (data == NULL) { return -1; } - bzero(data, sizeof(struct mount_cb_data)); + bzero((char *)data, sizeof(struct mount_cb_data)); data->cb = cb; data->private_data = private_data; data->server = strdup(server); @@@ -3095,36 -3082,3 +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/pdu.c index 6cb85ae,23698a8..135efcb --- a/lib/pdu.c +++ b/lib/pdu.c @@@ -15,14 -15,8 +15,14 @@@ along with this program; if not, see . */ -#include +#if defined(WIN32) +#include +#define MSG_DONTWAIT 0 +#else #include +#endif + +#include #include #include #include @@@ -47,7 -41,7 +47,7 @@@ struct rpc_pdu *rpc_allocate_pdu(struc rpc_set_error(rpc, "Out of memory: Failed to allocate pdu structure"); return NULL; } - bzero(pdu, sizeof(struct rpc_pdu)); + bzero((char *)pdu, sizeof(struct rpc_pdu)); pdu->xid = rpc->xid++; pdu->cb = cb; pdu->private_data = private_data; @@@ -59,7 -53,7 +59,7 @@@ xdr_setpos(&pdu->xdr, 4); /* skip past the record marker */ } - bzero(&msg, sizeof(struct rpc_msg)); + bzero((char *)&msg, sizeof(struct rpc_msg)); msg.rm_xid = pdu->xid; msg.rm_direction = CALL; msg.rm_call.cb_rpcvers = RPC_MSG_VERSION; @@@ -152,7 -146,7 +152,7 @@@ static int rpc_process_reply(struct rpc { struct rpc_msg msg; - bzero(&msg, sizeof(struct rpc_msg)); + bzero((char *)&msg, sizeof(struct rpc_msg)); msg.acpted_rply.ar_verf = _null_auth; if (pdu->xdr_decode_bufsize > 0) { if (pdu->xdr_decode_buf != NULL) { @@@ -164,7 -158,7 +164,7 @@@ pdu->cb(rpc, RPC_STATUS_ERROR, "Failed to allocate buffer for decoding of XDR reply", pdu->private_data); return 0; } - bzero(pdu->xdr_decode_buf, pdu->xdr_decode_bufsize); + bzero((char *)pdu->xdr_decode_buf, pdu->xdr_decode_bufsize); } msg.acpted_rply.ar_results.where = pdu->xdr_decode_buf; msg.acpted_rply.ar_results.proc = pdu->xdr_decode_fn; @@@ -216,7 -210,7 +216,7 @@@ int rpc_process_pdu(struct rpc_context int pos, recordmarker; unsigned int xid; - bzero(&xdr, sizeof(XDR)); + bzero((char *)&xdr, sizeof(XDR)); xdrmem_create(&xdr, buf, size, XDR_DECODE); if (rpc->is_udp == 0) { diff --combined nfs/nfs.c index 0c8ff79,1daaa56..015c6df --- a/nfs/nfs.c +++ b/nfs/nfs.c @@@ -15,19 -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 @@@ -363,7 -350,7 +363,7 @@@ int rpc_nfs_mkdir_async(struct rpc_cont return -1; } - bzero(&args, sizeof(MKDIR3args)); + bzero((char *)&args, sizeof(MKDIR3args)); args.where.dir.data.data_len = fh->data.data_len; args.where.dir.data.data_val = fh->data.data_val; args.where.name = dir; @@@ -399,7 -386,7 +399,7 @@@ int rpc_nfs_rmdir_async(struct rpc_cont return -1; } - bzero(&args, sizeof(RMDIR3args)); + bzero((char *)&args, sizeof(RMDIR3args)); args.object.dir.data.data_len = fh->data.data_len; args.object.dir.data.data_val = fh->data.data_val; args.object.name = dir; @@@ -432,7 -419,7 +432,7 @@@ int rpc_nfs_create_async(struct rpc_con return -1; } - bzero(&args, sizeof(CREATE3args)); + bzero((char *)&args, sizeof(CREATE3args)); args.where.dir.data.data_len = fh->data.data_len; args.where.dir.data.data_val = fh->data.data_val; args.where.name = file; @@@ -469,7 -456,7 +469,7 @@@ int rpc_nfs_remove_async(struct rpc_con return -1; } - bzero(&args, sizeof(REMOVE3args)); + bzero((char *)&args, sizeof(REMOVE3args)); args.object.dir.data.data_len = fh->data.data_len; args.object.dir.data.data_val = fh->data.data_val; args.object.name = file; @@@ -500,7 -487,7 +500,7 @@@ int rpc_nfs_readdir_async(struct rpc_co return -1; } - bzero(&args, sizeof(READDIR3args)); + bzero((char *)&args, sizeof(READDIR3args)); args.dir.data.data_len = fh->data.data_len; args.dir.data.data_val = fh->data.data_val; args.cookie = cookie; @@@ -533,7 -520,7 +533,7 @@@ int rpc_nfs_readdirplus_async(struct rp return -1; } - bzero(&args, sizeof(READDIRPLUS3args)); + bzero((char *)&args, sizeof(READDIRPLUS3args)); args.dir.data.data_len = fh->data.data_len; args.dir.data.data_val = fh->data.data_val; args.cookie = cookie; @@@ -655,7 -642,7 +655,7 @@@ int rpc_nfs_symlink_async(struct rpc_co return -1; } - bzero(&args, sizeof(SYMLINK3args)); + bzero((char *)&args, sizeof(SYMLINK3args)); args.where.dir.data.data_len = fh->data.data_len; args.where.dir.data.data_val = fh->data.data_val; args.where.name = newname; @@@ -692,7 -679,7 +692,7 @@@ int rpc_nfs_rename_async(struct rpc_con return -1; } - bzero(&args, sizeof(RENAME3args)); + bzero((char *)&args, sizeof(RENAME3args)); args.from.dir.data.data_len = olddir->data.data_len; args.from.dir.data.data_val = olddir->data.data_val; args.from.name = oldname; @@@ -729,7 -716,7 +729,7 @@@ int rpc_nfs_link_async(struct rpc_conte return -1; } - bzero(&args, sizeof(LINK3args)); + bzero((char *)&args, sizeof(LINK3args)); args.file.data.data_len = file->data.data_len; args.file.data.data_val = file->data.data_val; args.link.dir.data.data_len = newdir->data.data_len;