add a helper function nfs_set_error() to use instead of the printfs
int rpc_process_pdu(struct rpc_context *rpc, char *buf, int size);
void rpc_error_all_pdus(struct rpc_context *rpc, char *error);
int rpc_process_pdu(struct rpc_context *rpc, char *buf, int size);
void rpc_error_all_pdus(struct rpc_context *rpc, char *error);
+void rpc_set_error(struct rpc_context *rpc, char *error_string, ...);
+void nfs_set_error(struct nfs_context *nfs, char *error_string, ...);
+
+
*/
int rpc_disconnect(struct rpc_context *rpc, char *error);
*/
int rpc_disconnect(struct rpc_context *rpc, char *error);
-void rpc_set_error(struct rpc_context *rpc, char *error_string, ...);
-
rpc = malloc(sizeof(struct rpc_context));
if (rpc == NULL) {
rpc = malloc(sizeof(struct rpc_context));
if (rpc == NULL) {
- printf("Failed to allocate rpc context\n");
return NULL;
}
bzero(rpc, sizeof(struct rpc_context));
return NULL;
}
bzero(rpc, sizeof(struct rpc_context));
rpc->encodebuflen = 65536;
rpc->encodebuf = malloc(rpc->encodebuflen);
if (rpc->encodebuf == NULL) {
rpc->encodebuflen = 65536;
rpc->encodebuf = malloc(rpc->encodebuflen);
if (rpc->encodebuf == NULL) {
- printf("Failed to allocate a buffer for rpc encoding\n");
free(rpc);
return NULL;
}
rpc->auth = authunix_create_default();
if (rpc->auth == NULL) {
free(rpc);
return NULL;
}
rpc->auth = authunix_create_default();
if (rpc->auth == NULL) {
- printf("failed to create authunix\n");
free(rpc->encodebuf);
free(rpc);
return NULL;
free(rpc->encodebuf);
free(rpc);
return NULL;
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
#include "libnfs-raw-nfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
#include "libnfs-raw-nfs.h"
+#include "libnfs-private.h"
struct sync_cb_data {
int is_finished;
struct sync_cb_data {
int is_finished;
pfd.events = nfs_which_events(nfs);
if (poll(&pfd, 1, -1) < 0) {
pfd.events = nfs_which_events(nfs);
if (poll(&pfd, 1, -1) < 0) {
+ nfs_set_error(nfs, "Poll failed");
cb_data->status = -EIO;
break;
}
if (nfs_service(nfs, pfd.revents) < 0) {
cb_data->status = -EIO;
break;
}
if (nfs_service(nfs, pfd.revents) < 0) {
- printf("nfs_service failed\n");
+ nfs_set_error(nfs, "nfs_service failed");
cb_data->status = -EIO;
break;
}
cb_data->status = -EIO;
break;
}
/*
* connect to the server and mount the export
*/
/*
* connect to the server and mount the export
*/
-static void mount_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void mount_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("mount/mnt call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "mount/mnt call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_mount_async(nfs, server, export, mount_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_mount_async(nfs, server, export, mount_cb, &cb_data) != 0) {
- printf("nfs_mount_async failed\n");
+ nfs_set_error(nfs, "nfs_mount_async failed");
-static void stat_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void stat_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("stat call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "stat call failed with \"%s\"", (char *)data);
cb_data.return_data = st;
if (nfs_stat_async(nfs, path, stat_cb, &cb_data) != 0) {
cb_data.return_data = st;
if (nfs_stat_async(nfs, path, stat_cb, &cb_data) != 0) {
- printf("nfs_stat_async failed\n");
+ nfs_set_error(nfs, "nfs_stat_async failed");
-static void open_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void open_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
struct nfsfh *fh, **nfsfh;
{
struct sync_cb_data *cb_data = private_data;
struct nfsfh *fh, **nfsfh;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("open call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "open call failed with \"%s\"", (char *)data);
cb_data.return_data = nfsfh;
if (nfs_open_async(nfs, path, mode, open_cb, &cb_data) != 0) {
cb_data.return_data = nfsfh;
if (nfs_open_async(nfs, path, mode, open_cb, &cb_data) != 0) {
- printf("nfs_open_async failed\n");
+ nfs_set_error(nfs, "nfs_open_async failed");
-static void pread_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void pread_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
char *buffer;
{
struct sync_cb_data *cb_data = private_data;
char *buffer;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("pread call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "pread call failed with \"%s\"", (char *)data);
cb_data.return_data = buffer;
if (nfs_pread_async(nfs, nfsfh, offset, count, pread_cb, &cb_data) != 0) {
cb_data.return_data = buffer;
if (nfs_pread_async(nfs, nfsfh, offset, count, pread_cb, &cb_data) != 0) {
- printf("nfs_pread_async failed\n");
+ nfs_set_error(nfs, "nfs_pread_async failed");
-static void close_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void close_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
- printf("close call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "close call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_close_async(nfs, nfsfh, close_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_close_async(nfs, nfsfh, close_cb, &cb_data) != 0) {
- printf("nfs_close_async failed\n");
+ nfs_set_error(nfs, "nfs_close_async failed");
cb_data.return_data = st;
if (nfs_fstat_async(nfs, nfsfh, stat_cb, &cb_data) != 0) {
cb_data.return_data = st;
if (nfs_fstat_async(nfs, nfsfh, stat_cb, &cb_data) != 0) {
- printf("nfs_fstat_async failed\n");
+ nfs_set_error(nfs, "nfs_fstat_async failed");
-static void pwrite_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void pwrite_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
- printf("pwrite call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "pwrite call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_pwrite_async(nfs, nfsfh, offset, count, buf, pwrite_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_pwrite_async(nfs, nfsfh, offset, count, buf, pwrite_cb, &cb_data) != 0) {
- printf("nfs_pwrite_async failed\n");
+ nfs_set_error(nfs, "nfs_pwrite_async failed");
-static void fsync_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void fsync_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
- printf("fsync call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "fsync call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_fsync_async(nfs, nfsfh, fsync_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_fsync_async(nfs, nfsfh, fsync_cb, &cb_data) != 0) {
- printf("nfs_fsync_async failed\n");
+ nfs_set_error(nfs, "nfs_fsync_async failed");
-static void ftruncate_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void ftruncate_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
- printf("ftruncate call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "ftruncate call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_ftruncate_async(nfs, nfsfh, length, ftruncate_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_ftruncate_async(nfs, nfsfh, length, ftruncate_cb, &cb_data) != 0) {
- printf("nfs_ftruncate_async failed\n");
+ nfs_set_error(nfs, "nfs_ftruncate_async failed");
-static void truncate_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void truncate_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
- printf("truncate call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "truncate call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_truncate_async(nfs, path, length, truncate_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_truncate_async(nfs, path, length, truncate_cb, &cb_data) != 0) {
- printf("nfs_ftruncate_async failed\n");
+ nfs_set_error(nfs, "nfs_ftruncate_async failed");
-static void mkdir_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void mkdir_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
- printf("mkdir call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "mkdir call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_mkdir_async(nfs, path, mkdir_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_mkdir_async(nfs, path, mkdir_cb, &cb_data) != 0) {
- printf("nfs_mkdir_async failed\n");
+ nfs_set_error(nfs, "nfs_mkdir_async failed");
-static void rmdir_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void rmdir_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
if (status < 0) {
- printf("rmdir call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "rmdir call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_rmdir_async(nfs, path, rmdir_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_rmdir_async(nfs, path, rmdir_cb, &cb_data) != 0) {
- printf("nfs_rmdir_async failed\n");
+ nfs_set_error(nfs, "nfs_rmdir_async failed");
-static void creat_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void creat_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
struct nfsfh *fh, **nfsfh;
{
struct sync_cb_data *cb_data = private_data;
struct nfsfh *fh, **nfsfh;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("creat call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "creat call failed with \"%s\"", (char *)data);
cb_data.return_data = nfsfh;
if (nfs_creat_async(nfs, path, mode, creat_cb, &cb_data) != 0) {
cb_data.return_data = nfsfh;
if (nfs_creat_async(nfs, path, mode, creat_cb, &cb_data) != 0) {
- printf("nfs_creat_async failed\n");
+ nfs_set_error(nfs, "nfs_creat_async failed");
-static void unlink_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void unlink_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("unlink call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "unlink call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_unlink_async(nfs, path, unlink_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_unlink_async(nfs, path, unlink_cb, &cb_data) != 0) {
- printf("nfs_unlink_async failed\n");
+ nfs_set_error(nfs, "nfs_unlink_async failed");
-static void opendir_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void opendir_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
struct nfsdir *dir, **nfsdir;
{
struct sync_cb_data *cb_data = private_data;
struct nfsdir *dir, **nfsdir;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("opendir call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "opendir call failed with \"%s\"", (char *)data);
cb_data.return_data = nfsdir;
if (nfs_opendir_async(nfs, path, opendir_cb, &cb_data) != 0) {
cb_data.return_data = nfsdir;
if (nfs_opendir_async(nfs, path, opendir_cb, &cb_data) != 0) {
- printf("nfs_opendir_async failed\n");
+ nfs_set_error(nfs, "nfs_opendir_async failed");
-static void lseek_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void lseek_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("lseek call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "lseek call failed with \"%s\"", (char *)data);
cb_data.return_data = current_offset;
if (nfs_lseek_async(nfs, nfsfh, offset, whence, lseek_cb, &cb_data) != 0) {
cb_data.return_data = current_offset;
if (nfs_lseek_async(nfs, nfsfh, offset, whence, lseek_cb, &cb_data) != 0) {
- printf("nfs_lseek_async failed\n");
+ nfs_set_error(nfs, "nfs_lseek_async failed");
-static void statvfs_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void statvfs_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("statvfs call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "statvfs call failed with \"%s\"", (char *)data);
cb_data.return_data = svfs;
if (nfs_statvfs_async(nfs, path, statvfs_cb, &cb_data) != 0) {
cb_data.return_data = svfs;
if (nfs_statvfs_async(nfs, path, statvfs_cb, &cb_data) != 0) {
- printf("nfs_statvfs_async failed\n");
+ nfs_set_error(nfs, "nfs_statvfs_async failed");
-static void readlink_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void readlink_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("readlink call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "readlink call failed with \"%s\"", (char *)data);
return;
}
if (strlen(data) > (size_t)cb_data->return_int) {
return;
}
if (strlen(data) > (size_t)cb_data->return_int) {
- printf("Too small buffer for readlink\n");
+ nfs_set_error(nfs, "Too small buffer for readlink");
cb_data->status = -ENAMETOOLONG;
return;
}
cb_data->status = -ENAMETOOLONG;
return;
}
cb_data.return_int = bufsize;
if (nfs_readlink_async(nfs, path, readlink_cb, &cb_data) != 0) {
cb_data.return_int = bufsize;
if (nfs_readlink_async(nfs, path, readlink_cb, &cb_data) != 0) {
- printf("nfs_readlink_async failed\n");
+ nfs_set_error(nfs, "nfs_readlink_async failed");
-static void chmod_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void chmod_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("chmod call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "chmod call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_chmod_async(nfs, path, mode, chmod_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_chmod_async(nfs, path, mode, chmod_cb, &cb_data) != 0) {
- printf("nfs_chmod_async failed\n");
+ nfs_set_error(nfs, "nfs_chmod_async failed");
-static void fchmod_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void fchmod_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("fchmod call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "fchmod call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_fchmod_async(nfs, nfsfh, mode, fchmod_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_fchmod_async(nfs, nfsfh, mode, fchmod_cb, &cb_data) != 0) {
- printf("nfs_fchmod_async failed\n");
+ nfs_set_error(nfs, "nfs_fchmod_async failed");
-static void chown_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void chown_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("chown call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "chown call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_chown_async(nfs, path, uid, gid, chown_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_chown_async(nfs, path, uid, gid, chown_cb, &cb_data) != 0) {
- printf("nfs_chown_async failed\n");
+ nfs_set_error(nfs, "nfs_chown_async failed");
-static void fchown_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void fchown_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("fchown call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "fchown call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_fchown_async(nfs, nfsfh, uid, gid, fchown_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_fchown_async(nfs, nfsfh, uid, gid, fchown_cb, &cb_data) != 0) {
- printf("nfs_fchown_async failed\n");
+ nfs_set_error(nfs, "nfs_fchown_async failed");
-static void utimes_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void utimes_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("utimes call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "utimes call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_utimes_async(nfs, path, times, utimes_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_utimes_async(nfs, path, times, utimes_cb, &cb_data) != 0) {
- printf("nfs_utimes_async failed\n");
+ nfs_set_error(nfs, "nfs_utimes_async failed");
-static void utime_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void utime_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("utime call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "utime call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_utime_async(nfs, path, times, utime_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_utime_async(nfs, path, times, utime_cb, &cb_data) != 0) {
- printf("nfs_utimes_async failed\n");
+ nfs_set_error(nfs, "nfs_utimes_async failed");
-static void access_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void access_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("access call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "access call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_access_async(nfs, path, mode, access_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_access_async(nfs, path, mode, access_cb, &cb_data) != 0) {
- printf("nfs_access_async failed\n");
+ nfs_set_error(nfs, "nfs_access_async failed");
-static void symlink_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void symlink_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("symlink call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "symlink call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_symlink_async(nfs, oldpath, newpath, symlink_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_symlink_async(nfs, oldpath, newpath, symlink_cb, &cb_data) != 0) {
- printf("nfs_symlink_async failed\n");
+ nfs_set_error(nfs, "nfs_symlink_async failed");
-static void rename_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void rename_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("rename call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "rename call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_rename_async(nfs, oldpath, newpath, rename_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_rename_async(nfs, oldpath, newpath, rename_cb, &cb_data) != 0) {
- printf("nfs_rename_async failed\n");
+ nfs_set_error(nfs, "nfs_rename_async failed");
-static void link_cb(int status, struct nfs_context *nfs _U_, void *data, void *private_data)
+static void link_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
{
struct sync_cb_data *cb_data = private_data;
cb_data->status = status;
if (status < 0) {
cb_data->status = status;
if (status < 0) {
- printf("link call failed with \"%s\"\n", (char *)data);
+ nfs_set_error(nfs, "link call failed with \"%s\"", (char *)data);
cb_data.is_finished = 0;
if (nfs_link_async(nfs, oldpath, newpath, link_cb, &cb_data) != 0) {
cb_data.is_finished = 0;
if (nfs_link_async(nfs, oldpath, newpath, link_cb, &cb_data) != 0) {
- printf("nfs_link_async failed\n");
+ nfs_set_error(nfs, "nfs_link_async failed");
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
#include "libnfs-raw-nfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
#include "libnfs-raw-nfs.h"
+#include "libnfs-private.h"
+
+struct nfsdir {
+ struct nfsdirent *entries;
+ struct nfsdirent *current;
+};
struct nfsfh {
struct nfs_fh3 fh;
struct nfsfh {
struct nfs_fh3 fh;
-struct nfsdir {
- struct nfsdirent *entries;
- struct nfsdirent *current;
+struct nfs_context {
+ struct rpc_context *rpc;
+ char *server;
+ char *export;
+ struct nfs_fh3 rootfh;
+ size_t readmax;
+ size_t writemax;
};
void nfs_free_nfsdir(struct nfsdir *nfsdir)
};
void nfs_free_nfsdir(struct nfsdir *nfsdir)
-struct nfs_context {
- struct rpc_context *rpc;
- char *server;
- char *export;
- struct nfs_fh3 rootfh;
- size_t readmax;
- size_t writemax;
-};
-
struct nfs_cb_data;
typedef int (*continue_func)(struct nfs_context *nfs, struct nfs_cb_data *data);
struct nfs_cb_data;
typedef int (*continue_func)(struct nfs_context *nfs, struct nfs_cb_data *data);
{
return nfs->writemax;
}
{
return nfs->writemax;
}
+
+void nfs_set_error(struct nfs_context *nfs, char *error_string, ...)
+{
+ va_list ap;
+ char *str;
+
+ if (nfs->rpc->error_string != NULL) {
+ free(nfs->rpc->error_string);
+ }
+ va_start(ap, error_string);
+ vasprintf(&str, error_string, ap);
+ nfs->rpc->error_string = str;
+ va_end(ap);
+}
struct rpc_msg msg;
if (rpc == NULL) {
struct rpc_msg msg;
if (rpc == NULL) {
- printf("trying to allocate rpc pdu on NULL context\n");
return NULL;
}
pdu = malloc(sizeof(struct rpc_pdu));
if (pdu == NULL) {
return NULL;
}
pdu = malloc(sizeof(struct rpc_pdu));
if (pdu == NULL) {
- printf("Failed to allocate pdu structure\n");
+ rpc_set_error(rpc, "Out of memory: Failed to allocate pdu structure");
return NULL;
}
bzero(pdu, sizeof(struct rpc_pdu));
return NULL;
}
bzero(pdu, sizeof(struct rpc_pdu));
msg.rm_call.cb_verf = rpc->auth->ah_verf;
if (xdr_callmsg(&pdu->xdr, &msg) == 0) {
msg.rm_call.cb_verf = rpc->auth->ah_verf;
if (xdr_callmsg(&pdu->xdr, &msg) == 0) {
- printf("xdr_callmsg failed\n");
+ rpc_set_error(rpc, "xdr_callmsg failed");
xdr_destroy(&pdu->xdr);
free(pdu);
return NULL;
xdr_destroy(&pdu->xdr);
free(pdu);
return NULL;
size = ntohl(*(uint32_t *)buf);
if ((size & 0x80000000) == 0) {
size = ntohl(*(uint32_t *)buf);
if ((size & 0x80000000) == 0) {
- printf("cant handle oncrpc fragments\n");
+ /* cant handle oncrpc fragments */
if (pdu->xdr_decode_bufsize > 0) {
pdu->xdr_decode_buf = malloc(pdu->xdr_decode_bufsize);
if (pdu->xdr_decode_buf == NULL) {
if (pdu->xdr_decode_bufsize > 0) {
pdu->xdr_decode_buf = malloc(pdu->xdr_decode_bufsize);
if (pdu->xdr_decode_buf == NULL) {
- printf("xdr_replymsg failed in portmap_getport_reply\n");
+ rpc_set_error(rpc, "xdr_replymsg failed in portmap_getport_reply");
pdu->cb(rpc, RPC_STATUS_ERROR, "Failed to allocate buffer for decoding of XDR reply", pdu->private_data);
return 0;
}
pdu->cb(rpc, RPC_STATUS_ERROR, "Failed to allocate buffer for decoding of XDR reply", pdu->private_data);
return 0;
}
msg.acpted_rply.ar_results.proc = pdu->xdr_decode_fn;
if (xdr_replymsg(xdr, &msg) == 0) {
msg.acpted_rply.ar_results.proc = pdu->xdr_decode_fn;
if (xdr_replymsg(xdr, &msg) == 0) {
- printf("xdr_replymsg failed in portmap_getport_reply\n");
+ rpc_set_error(rpc, "xdr_replymsg failed in portmap_getport_reply");
pdu->cb(rpc, RPC_STATUS_ERROR, "Message rejected by server", pdu->private_data);
if (pdu->xdr_decode_buf != NULL) {
free(pdu->xdr_decode_buf);
pdu->cb(rpc, RPC_STATUS_ERROR, "Message rejected by server", pdu->private_data);
if (pdu->xdr_decode_buf != NULL) {
free(pdu->xdr_decode_buf);
xdrmem_create(&xdr, buf, size, XDR_DECODE);
if (xdr_int(&xdr, &recordmarker) == 0) {
xdrmem_create(&xdr, buf, size, XDR_DECODE);
if (xdr_int(&xdr, &recordmarker) == 0) {
- printf("xdr_int reading recordmarker failed\n");
+ rpc_set_error(rpc, "xdr_int reading recordmarker failed");
xdr_destroy(&xdr);
return -1;
}
pos = xdr_getpos(&xdr);
if (xdr_int(&xdr, (int *)&xid) == 0) {
xdr_destroy(&xdr);
return -1;
}
pos = xdr_getpos(&xdr);
if (xdr_int(&xdr, (int *)&xid) == 0) {
- printf("xdr_int reading xid failed\n");
+ rpc_set_error(rpc, "xdr_int reading xid failed");
xdr_destroy(&xdr);
return -1;
}
xdr_destroy(&xdr);
return -1;
}
}
SLIST_REMOVE(&rpc->waitpdu, pdu);
if (rpc_process_reply(rpc, pdu, &xdr) != 0) {
}
SLIST_REMOVE(&rpc->waitpdu, pdu);
if (rpc_process_reply(rpc, pdu, &xdr) != 0) {
- printf("rpc_procdess_reply failed\n");
+ rpc_set_error(rpc, "rpc_procdess_reply failed");
}
xdr_destroy(&xdr);
rpc_free_pdu(rpc, pdu);
return 0;
}
}
xdr_destroy(&xdr);
rpc_free_pdu(rpc, pdu);
return 0;
}
- printf("No matching pdu found for xid:%d\n", xid);
+ rpc_set_error(rpc, "No matching pdu found for xid:%d", xid);
xdr_destroy(&xdr);
return -1;
}
xdr_destroy(&xdr);
return -1;
}
ssize_t count;
if (rpc == NULL) {
ssize_t count;
if (rpc == NULL) {
- printf("trying to write to socket for NULL context\n");
return -1;
}
if (rpc->fd == -1) {
return -1;
}
if (rpc->fd == -1) {
- printf("trying to write but not connected\n");
- return -2;
+ rpc_set_error(rpc, "trying to write but not connected");
+ return -1;
}
while (rpc->outqueue != NULL) {
}
while (rpc->outqueue != NULL) {
count = write(rpc->fd, rpc->outqueue->outdata.data + rpc->outqueue->written, total - rpc->outqueue->written);
if (count == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
count = write(rpc->fd, rpc->outqueue->outdata.data + rpc->outqueue->written, total - rpc->outqueue->written);
if (count == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
- printf("socket would block, return from write to socket\n");
- printf("Error when writing to socket :%s(%d)\n", strerror(errno), errno);
- return -3;
+ rpc_set_error(rpc, "Error when writing to socket :%s(%d)", strerror(errno), errno);
+ return -1;
}
rpc->outqueue->written += count;
}
rpc->outqueue->written += count;
}
if (available == 0) {
rpc_set_error(rpc, "Socket has been closed");
}
if (available == 0) {
rpc_set_error(rpc, "Socket has been closed");
}
size = rpc->insize - rpc->inpos + available;
buf = malloc(size);
if (buf == NULL) {
rpc_set_error(rpc, "Out of memory: failed to allocate %d bytes for input buffer. Closing socket.", size);
}
size = rpc->insize - rpc->inpos + available;
buf = malloc(size);
if (buf == NULL) {
rpc_set_error(rpc, "Out of memory: failed to allocate %d bytes for input buffer. Closing socket.", size);
}
if (rpc->insize > rpc->inpos) {
memcpy(buf, rpc->inbuf + rpc->inpos, rpc->insize - rpc->inpos);
}
if (rpc->insize > rpc->inpos) {
memcpy(buf, rpc->inbuf + rpc->inpos, rpc->insize - rpc->inpos);
rpc_set_error(rpc, "Read from socket failed, errno:%d. Closing socket.", errno);
free(buf);
buf = NULL;
rpc_set_error(rpc, "Read from socket failed, errno:%d. Closing socket.", errno);
free(buf);
buf = NULL;
}
if (rpc->inbuf != NULL) {
}
if (rpc->inbuf != NULL) {
}
if (rpc_process_pdu(rpc, rpc->inbuf + rpc->inpos, count) != 0) {
rpc_set_error(rpc, "Invalid/garbage pdu received from server. Closing socket");
}
if (rpc_process_pdu(rpc, rpc->inbuf + rpc->inpos, count) != 0) {
rpc_set_error(rpc, "Invalid/garbage pdu received from server. Closing socket");
}
rpc->inpos += count;
if (rpc->inpos == rpc->insize) {
}
rpc->inpos += count;
if (rpc->inpos == rpc->insize) {
return -1;
}
if (revents & POLLHUP) {
return -1;
}
if (revents & POLLHUP) {
- printf("rpc_service: POLLHUP, socket error\n");
rpc_set_error(rpc, "Socket failed with POLLHUP");
rpc->connect_cb(rpc, RPC_STATUS_ERROR, rpc->error_string, rpc->connect_data);
rpc_set_error(rpc, "Socket failed with POLLHUP");
rpc->connect_cb(rpc, RPC_STATUS_ERROR, rpc->error_string, rpc->connect_data);
}
if (rpc->is_connected == 0 && rpc->fd != -1 && revents&POLLOUT) {
}
if (rpc->is_connected == 0 && rpc->fd != -1 && revents&POLLOUT) {
if (revents & POLLOUT && rpc->outqueue != NULL) {
if (rpc_write_to_socket(rpc) != 0) {
if (revents & POLLOUT && rpc->outqueue != NULL) {
if (rpc_write_to_socket(rpc) != 0) {
- printf("write to socket failed\n");
- return -3;
+ rpc_set_error(rpc, "write to socket failed");
+ return -1;
}
}
if (revents & POLLIN) {
if (rpc_read_from_socket(rpc) != 0) {
rpc_disconnect(rpc, rpc_get_error(rpc));
}
}
if (revents & POLLIN) {
if (rpc_read_from_socket(rpc) != 0) {
rpc_disconnect(rpc, rpc_get_error(rpc));
if (rpc->fd != -1) {
rpc_set_error(rpc, "Trying to connect while already connected");
if (rpc->fd != -1) {
rpc_set_error(rpc, "Trying to connect while already connected");
- printf("%s\n", rpc->error_string);
sin->sin_port = htons(port);
if (inet_pton(AF_INET, server, &sin->sin_addr) != 1) {
rpc_set_error(rpc, "Not a valid server ip address");
sin->sin_port = htons(port);
if (inet_pton(AF_INET, server, &sin->sin_addr) != 1) {
rpc_set_error(rpc, "Not a valid server ip address");
- printf("%s\n", rpc->error_string);
- return -2;
if (rpc->fd == -1) {
rpc_set_error(rpc, "Failed to open socket");
if (rpc->fd == -1) {
rpc_set_error(rpc, "Failed to open socket");
- printf("%s\n", rpc->error_string);
- return -3;
if (connect(rpc->fd, (struct sockaddr *)&s, socksize) != 0 && errno != EINPROGRESS) {
rpc_set_error(rpc, "connect() to server failed");
if (connect(rpc->fd, (struct sockaddr *)&s, socksize) != 0 && errno != EINPROGRESS) {
rpc_set_error(rpc, "connect() to server failed");
- printf("%s\n", rpc->error_string);
- return -4;
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/null call");
rpc_free_pdu(rpc, pdu);
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/null call");
rpc_free_pdu(rpc, pdu);
if (xdr_dirpath(&pdu->xdr, &export) == 0) {
rpc_set_error(rpc, "XDR error. Failed to encode mount/mnt call");
rpc_free_pdu(rpc, pdu);
if (xdr_dirpath(&pdu->xdr, &export) == 0) {
rpc_set_error(rpc, "XDR error. Failed to encode mount/mnt call");
rpc_free_pdu(rpc, pdu);
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/mnt call");
rpc_free_pdu(rpc, pdu);
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/mnt call");
rpc_free_pdu(rpc, pdu);
pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_DUMP, cb, private_data, (xdrproc_t)xdr_mountlist, sizeof(mountlist));
if (pdu == NULL) {
pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_DUMP, cb, private_data, (xdrproc_t)xdr_mountlist, sizeof(mountlist));
if (pdu == NULL) {
- printf("Failed to allocate pdu for mount/dump\n");
+ rpc_set_error(rpc, "Failed to allocate pdu for mount/dump");
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
- printf("Failed to queue mount/dump pdu\n");
+ rpc_set_error(rpc, "Failed to queue mount/dump pdu");
pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNT, cb, private_data, (xdrproc_t)xdr_void, 0);
if (pdu == NULL) {
pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNT, cb, private_data, (xdrproc_t)xdr_void, 0);
if (pdu == NULL) {
- printf("Failed to allocate pdu for mount/umnt\n");
+ rpc_set_error(rpc, "Failed to allocate pdu for mount/umnt");
return -1;
}
if (xdr_dirpath(&pdu->xdr, &export) == 0) {
return -1;
}
if (xdr_dirpath(&pdu->xdr, &export) == 0) {
- printf("failed to encode dirpath for mount/umnt\n");
+ rpc_set_error(rpc, "failed to encode dirpath for mount/umnt");
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
- printf("Failed to queue mount/umnt pdu\n");
+ rpc_set_error(rpc, "Failed to queue mount/umnt pdu");
pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNTALL, cb, private_data, (xdrproc_t)xdr_void, 0);
if (pdu == NULL) {
pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNTALL, cb, private_data, (xdrproc_t)xdr_void, 0);
if (pdu == NULL) {
- printf("Failed to allocate pdu for mount/umntall\n");
+ rpc_set_error(rpc, "Failed to allocate pdu for mount/umntall");
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
- printf("Failed to queue mount/umntall pdu\n");
+ rpc_set_error(rpc, "Failed to queue mount/umntall pdu");
pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_EXPORT, cb, private_data, (xdrproc_t)xdr_exports, sizeof(exports));
if (pdu == NULL) {
pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_EXPORT, cb, private_data, (xdrproc_t)xdr_exports, sizeof(exports));
if (pdu == NULL) {
- printf("Failed to allocate pdu for mount/export\n");
+ rpc_set_error(rpc, "Failed to allocate pdu for mount/export");
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
- printf("Failed to queue mount/export pdu\n");
+ rpc_set_error(rpc, "Failed to queue mount/export pdu");
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Out of memory. Failed to queue pdu for portmap/null call");
rpc_free_pdu(rpc, pdu);
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Out of memory. Failed to queue pdu for portmap/null call");
rpc_free_pdu(rpc, pdu);
if (xdr_mapping(&pdu->xdr, &m) == 0) {
rpc_set_error(rpc, "XDR error: Failed to encode data for portmap/getport call");
rpc_free_pdu(rpc, pdu);
if (xdr_mapping(&pdu->xdr, &m) == 0) {
rpc_set_error(rpc, "XDR error: Failed to encode data for portmap/getport call");
rpc_free_pdu(rpc, pdu);
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
- printf("Failed to queue portmap/getport pdu\n");
+ rpc_set_error(rpc, "Failed to queue portmap/getport pdu");