#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) {
-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;
}
-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;
-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) {
return -1;
}
- memset(&args, 0, 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;
-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) {
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;
+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)
{
return 0;
}
-int rpc_nfs_readlink_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data)
+int rpc_nfs_readlink_async(struct rpc_context *rpc, rpc_cb cb, READLINK3args *args, void *private_data)
{
struct rpc_pdu *pdu;
- READLINK3args args;
pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READLINK, cb, private_data, (xdrproc_t)xdr_READLINK3res, sizeof(READLINK3res));
if (pdu == NULL) {
return -1;
}
- args.symlink.data.data_len = fh->data.data_len;
- args.symlink.data.data_val = fh->data.data_val;
-
- if (xdr_READLINK3args(&pdu->xdr, &args) == 0) {
+ if (xdr_READLINK3args(&pdu->xdr, args) == 0) {
rpc_set_error(rpc, "XDR error: Failed to encode READLINK3args");
rpc_free_pdu(rpc, pdu);
return -2;
}
-int rpc_nfs_symlink_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *newname, char *oldpath, void *private_data)
+int rpc_nfs_symlink_async(struct rpc_context *rpc, rpc_cb cb, SYMLINK3args *args, void *private_data)
{
struct rpc_pdu *pdu;
- SYMLINK3args args;
pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_SYMLINK, cb, private_data, (xdrproc_t)xdr_SYMLINK3res, sizeof(SYMLINK3res));
if (pdu == NULL) {
return -1;
}
- 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;
- args.symlink.symlink_attributes.mode.set_it = 1;
- args.symlink.symlink_attributes.mode.set_mode3_u.mode = S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH;
- args.symlink.symlink_data = oldpath;
-
- if (xdr_SYMLINK3args(&pdu->xdr, &args) == 0) {
+ if (xdr_SYMLINK3args(&pdu->xdr, args) == 0) {
rpc_set_error(rpc, "XDR error: Failed to encode SYMLINK3args");
rpc_free_pdu(rpc, pdu);
return -2;