rpc_nfs_create_async, args is now a pointer, not a structur
[deb_libnfs.git] / nfs / nfs.c
index 50836ca12f6d1528e9374bc42afa57e8853388a1..ccbd2c1699b87036fc3bfd2f88073ae00cc5fcba 100644 (file)
--- a/nfs/nfs.c
+++ b/nfs/nfs.c
 #include "libnfs-private.h"
 #include "libnfs-raw-nfs.h"
 
-#ifdef WIN32
-#define bzero(a,b) memset((a),(0),(b))
-#endif/*WIN32*/
-
 char *nfsstat3_to_str(int error)
 {
        switch (error) {
@@ -219,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;
@@ -251,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;
@@ -415,10 +411,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) {
@@ -426,15 +421,7 @@ int rpc_nfs_create_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh,
                return -1;
        }
 
-       memset(&args, 0, 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;
@@ -451,6 +438,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)
 {