X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=nfs%2Fnfs.c;h=099e291d4619df55e93cf9b3ddcbc3758b0b2891;hb=7edc9026db94f488f04e7a76bf332f1feabcc9aa;hp=a32521e4a8b1e6d24ab1b21ce978586ec89b0264;hpb=eecdc4f3cd5c464ae02823a823993e720664e465;p=deb_libnfs.git diff --git a/nfs/nfs.c b/nfs/nfs.c index a32521e..099e291 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,8 +31,6 @@ #include "libnfs-private.h" #include "libnfs-raw-nfs.h" - - char *nfsstat3_to_str(int error) { switch (error) { @@ -225,7 +215,7 @@ int rpc_nfs_access_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, -int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, off_t offset, size_t count, void *private_data) +int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t offset, uint64_t count, void *private_data) { struct rpc_pdu *pdu; READ3args args; @@ -257,7 +247,7 @@ int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, o } -int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, off_t offset, size_t count, int stable_how, void *private_data) +int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, uint64_t offset, uint64_t count, int stable_how, void *private_data) { struct rpc_pdu *pdu; WRITE3args args; @@ -352,10 +342,9 @@ int rpc_nfs_setattr_async(struct rpc_context *rpc, rpc_cb cb, SETATTR3args *args -int rpc_nfs_mkdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *dir, void *private_data) +int rpc_nfs_mkdir_async(struct rpc_context *rpc, rpc_cb cb, MKDIR3args *args, void *private_data) { struct rpc_pdu *pdu; - MKDIR3args args; pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_MKDIR, cb, private_data, (xdrproc_t)xdr_MKDIR3res, sizeof(MKDIR3res)); if (pdu == NULL) { @@ -363,14 +352,7 @@ int rpc_nfs_mkdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, return -1; } - bzero(&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; - args.attributes.mode.set_it = 1; - args.attributes.mode.set_mode3_u.mode = 0755; - - if (xdr_MKDIR3args(&pdu->xdr, &args) == 0) { + if (xdr_MKDIR3args(&pdu->xdr, args) == 0) { rpc_set_error(rpc, "XDR error: Failed to encode MKDIR3args"); rpc_free_pdu(rpc, pdu); return -2; @@ -399,7 +381,7 @@ int rpc_nfs_rmdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, return -1; } - bzero(&args, sizeof(RMDIR3args)); + memset(&args, 0, 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; @@ -421,10 +403,9 @@ int rpc_nfs_rmdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, -int rpc_nfs_create_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *file, int mode, void *private_data) +int rpc_nfs_create_async(struct rpc_context *rpc, rpc_cb cb, CREATE3args *args, void *private_data) { struct rpc_pdu *pdu; - CREATE3args args; pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_CREATE, cb, private_data, (xdrproc_t)xdr_CREATE3res, sizeof(CREATE3res)); if (pdu == NULL) { @@ -432,15 +413,7 @@ int rpc_nfs_create_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, return -1; } - bzero(&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; - args.how.mode = UNCHECKED; - args.how.createhow3_u.obj_attributes.mode.set_it = 1; - args.how.createhow3_u.obj_attributes.mode.set_mode3_u.mode = mode; - - if (xdr_CREATE3args(&pdu->xdr, &args) == 0) { + if (xdr_CREATE3args(&pdu->xdr, args) == 0) { rpc_set_error(rpc, "XDR error: Failed to encode CREATE3args"); rpc_free_pdu(rpc, pdu); return -2; @@ -457,6 +430,66 @@ int rpc_nfs_create_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, +int rpc_nfs_mknod_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *file, int mode, int major, int minor, void *private_data) +{ + struct rpc_pdu *pdu; + MKNOD3args args; + + pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_MKNOD, cb, private_data, (xdrproc_t)xdr_MKNOD3res, sizeof(MKNOD3res)); + if (pdu == NULL) { + rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/mknod call"); + return -1; + } + + memset(&args, 0, sizeof(MKNOD3args)); + args.where.dir.data.data_len = fh->data.data_len; + args.where.dir.data.data_val = fh->data.data_val; + args.where.name = file; + switch (mode & S_IFMT) { + case S_IFCHR: + args.what.type = NF3CHR; + args.what.mknoddata3_u.chr_device.dev_attributes.mode.set_it = 1; + args.what.mknoddata3_u.chr_device.dev_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); + args.what.mknoddata3_u.chr_device.spec.specdata1 = major; + args.what.mknoddata3_u.chr_device.spec.specdata2 = minor; + break; + case S_IFBLK: + args.what.type = NF3BLK; + args.what.mknoddata3_u.blk_device.dev_attributes.mode.set_it = 1; + args.what.mknoddata3_u.blk_device.dev_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); + args.what.mknoddata3_u.blk_device.spec.specdata1 = major; + args.what.mknoddata3_u.blk_device.spec.specdata2 = minor; + case S_IFSOCK: + args.what.type = NF3SOCK; + args.what.mknoddata3_u.sock_attributes.mode.set_it = 1; + args.what.mknoddata3_u.sock_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); + break; + case S_IFIFO: + args.what.type = NF3FIFO; + args.what.mknoddata3_u.pipe_attributes.mode.set_it = 1; + args.what.mknoddata3_u.pipe_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); + break; + default: + rpc_set_error(rpc, "Invalid file type for nfs/mknod call"); + rpc_free_pdu(rpc, pdu); + return -1; + } + + if (xdr_MKNOD3args(&pdu->xdr, &args) == 0) { + rpc_set_error(rpc, "XDR error: Failed to encode MKNOD3args"); + rpc_free_pdu(rpc, pdu); + return -2; + } + + if (rpc_queue_pdu(rpc, pdu) != 0) { + rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/mknod call"); + rpc_free_pdu(rpc, pdu); + return -3; + } + + return 0; +} + int rpc_nfs_remove_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *file, void *private_data) { @@ -469,7 +502,7 @@ int rpc_nfs_remove_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, return -1; } - bzero(&args, sizeof(REMOVE3args)); + memset(&args, 0, 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; @@ -489,7 +522,6 @@ int rpc_nfs_remove_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, return 0; } - int rpc_nfs_readdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data) { struct rpc_pdu *pdu; @@ -501,7 +533,7 @@ int rpc_nfs_readdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh return -1; } - bzero(&args, sizeof(READDIR3args)); + memset(&args, 0, sizeof(READDIR3args)); args.dir.data.data_len = fh->data.data_len; args.dir.data.data_val = fh->data.data_val; args.cookie = cookie; @@ -523,6 +555,40 @@ int rpc_nfs_readdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh return 0; } +int rpc_nfs_readdirplus_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data) +{ + struct rpc_pdu *pdu; + READDIRPLUS3args args; + + pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READDIRPLUS, cb, private_data, (xdrproc_t)xdr_READDIRPLUS3res, sizeof(READDIRPLUS3res)); + if (pdu == NULL) { + rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/readdirplus call"); + return -1; + } + + memset(&args, 0, sizeof(READDIRPLUS3args)); + args.dir.data.data_len = fh->data.data_len; + args.dir.data.data_val = fh->data.data_val; + args.cookie = cookie; + memcpy(&args.cookieverf, cookieverf, sizeof(cookieverf3)); + args.dircount = count; + args.maxcount = count; + + if (xdr_READDIRPLUS3args(&pdu->xdr, &args) == 0) { + rpc_set_error(rpc, "XDR error: Failed to encode READDIRPLUS3args"); + rpc_free_pdu(rpc, pdu); + return -2; + } + + if (rpc_queue_pdu(rpc, pdu) != 0) { + rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/readdirplus call"); + rpc_free_pdu(rpc, pdu); + return -3; + } + + return 0; +} + int rpc_nfs_fsstat_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data) { struct rpc_pdu *pdu; @@ -622,7 +688,7 @@ int rpc_nfs_symlink_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh return -1; } - bzero(&args, sizeof(SYMLINK3args)); + memset(&args, 0, 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; @@ -659,7 +725,7 @@ int rpc_nfs_rename_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *old return -1; } - bzero(&args, sizeof(RENAME3args)); + memset(&args, 0, 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; @@ -696,7 +762,7 @@ int rpc_nfs_link_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *file, return -1; } - bzero(&args, sizeof(LINK3args)); + memset(&args, 0, 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;