/*
* High level api to nfs filesystems
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef AROS
+#include "aros_compat.h"
+#endif
+
#ifdef WIN32
#include "win32_compat.h"
-#define DllExport
-#else
-#include <strings.h>
-#include <sys/statvfs.h>
+#endif
+
+#ifdef HAVE_UTIME_H
#include <utime.h>
-#include <unistd.h>
-#endif/*WIN32*/
+#endif
+
+#ifdef ANDROID
+#define statvfs statfs
+#endif
#define _GNU_SOURCE
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_SYS_VFS_H
+#include <sys/vfs.h>
+#endif
+
+#ifdef HAVE_SYS_STATVFS_H
+#include <sys/statvfs.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <netinet/in.h>
#include "libnfs-zdr.h"
#include "libnfs.h"
#include "libnfs-raw.h"
free(nfs);
}
+struct rpc_cb_data {
+ char *server;
+ uint32_t program;
+ uint32_t version;
+
+ rpc_cb cb;
+ void *private_data;
+};
+
+void free_rpc_cb_data(struct rpc_cb_data *data)
+{
+ free(data->server);
+ data->server = NULL;
+ free(data);
+}
+
+static void rpc_connect_program_4_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data)
+{
+ struct rpc_cb_data *data = private_data;
+
+ assert(rpc->magic == RPC_CONTEXT_MAGIC);
+
+ /* Dont want any more callbacks even if the socket is closed */
+ rpc->connect_cb = NULL;
+
+ if (status == RPC_STATUS_ERROR) {
+ data->cb(rpc, status, command_data, data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+ if (status == RPC_STATUS_CANCEL) {
+ data->cb(rpc, status, "Command was cancelled", data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+
+ data->cb(rpc, status, NULL, data->private_data);
+ free_rpc_cb_data(data);
+}
+
+static void rpc_connect_program_3_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data)
+{
+ struct rpc_cb_data *data = private_data;
+ uint32_t rpc_port;
+
+ assert(rpc->magic == RPC_CONTEXT_MAGIC);
+
+ if (status == RPC_STATUS_ERROR) {
+ data->cb(rpc, status, command_data, data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+ if (status == RPC_STATUS_CANCEL) {
+ data->cb(rpc, status, "Command was cancelled", data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+
+ rpc_port = *(uint32_t *)command_data;
+ if (rpc_port == 0) {
+ rpc_set_error(rpc, "RPC error. Program is not available on %s", data->server);
+ data->cb(rpc, RPC_STATUS_ERROR, rpc_get_error(rpc), data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+
+ rpc_disconnect(rpc, "normal disconnect");
+ if (rpc_connect_async(rpc, data->server, rpc_port, rpc_connect_program_4_cb, data) != 0) {
+ data->cb(rpc, status, command_data, data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+}
+
+static void rpc_connect_program_2_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data)
+{
+ struct rpc_cb_data *data = private_data;
+
+ assert(rpc->magic == RPC_CONTEXT_MAGIC);
+
+ if (status == RPC_STATUS_ERROR) {
+ data->cb(rpc, status, command_data, data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+ if (status == RPC_STATUS_CANCEL) {
+ data->cb(rpc, status, "Command was cancelled", data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+
+ if (rpc_pmap_getport_async(rpc, data->program, data->version, IPPROTO_TCP, rpc_connect_program_3_cb, private_data) != 0) {
+ data->cb(rpc, status, command_data, data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+}
+
+static void rpc_connect_program_1_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data)
+{
+ struct rpc_cb_data *data = private_data;
+
+ assert(rpc->magic == RPC_CONTEXT_MAGIC);
+
+ /* Dont want any more callbacks even if the socket is closed */
+ rpc->connect_cb = NULL;
+
+ if (status == RPC_STATUS_ERROR) {
+ data->cb(rpc, status, command_data, data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+ if (status == RPC_STATUS_CANCEL) {
+ data->cb(rpc, status, "Command was cancelled", data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+
+ if (rpc_pmap_null_async(rpc, rpc_connect_program_2_cb, data) != 0) {
+ data->cb(rpc, status, command_data, data->private_data);
+ free_rpc_cb_data(data);
+ return;
+ }
+}
+
+int rpc_connect_program_async(struct rpc_context *rpc, char *server, int program, int version, rpc_cb cb, void *private_data)
+{
+ struct rpc_cb_data *data;
+
+ data = malloc(sizeof(struct rpc_cb_data));
+ if (data == NULL) {
+ return -1;
+ }
+ memset(data, 0, sizeof(struct rpc_cb_data));
+ data->server = strdup(server);
+ data->program = program;
+ data->version = version;
+
+ data->cb = cb;
+ data->private_data = private_data;
+
+ if (rpc_connect_async(rpc, server, 111, rpc_connect_program_1_cb, data) != 0) {
+ rpc_set_error(rpc, "Failed to start connection");
+ free_rpc_cb_data(data);
+ return -1;
+ }
+ return 0;
+}
+
void free_nfs_cb_data(struct nfs_cb_data *data)
{
if (data->saved_path != NULL) {
{
struct nfs_cb_data *data;
- if (path[0] != '/') {
- rpc_set_error(nfs->rpc, "Pathname is not absulute %s", path);
+ if (path[0] != 0 && path[0] != '/') {
+ rpc_set_error(nfs->rpc, "Pathname is not absolute %s", path);
return -1;
}
/* trying to read more than maximum server read size, we has to chop it up into smaller
* reads and collect into a reassembly buffer.
- * we send all reads in parallell so that performance is still good.
+ * we send all reads in parallel so that performance is still good.
*/
data->max_offset = offset;
data->start_offset = offset;
/* trying to write more than maximum server write size, we has to chop it up into smaller
* chunks.
- * we send all writes in parallell so that performance is still good.
+ * we send all writes in parallel so that performance is still good.
*/
data->max_offset = offset;
data->start_offset = offset;
}
memset(nfsfh, 0, sizeof(struct nfsfh));
- /* steal the filehandle */
- nfsfh->fh.data.data_len = data->fh.data.data_len;
- nfsfh->fh.data.data_val = data->fh.data.data_val;
- data->fh.data.data_val = NULL;
+ /* copy the filehandle */
+ nfsfh->fh.data.data_len = res->LOOKUP3res_u.resok.object.data.data_len;
+ nfsfh->fh.data.data_val = malloc(nfsfh->fh.data.data_len);
+ memcpy(nfsfh->fh.data.data_val, res->LOOKUP3res_u.resok.object.data.data_val, nfsfh->fh.data.data_len);
data->cb(0, nfs, nfsfh, data->private_data);
free_nfs_cb_data(data);
str = &str[strlen(str) + 1];
-
memset(&args, 0, sizeof(CREATE3args));
args.where.dir.data.data_len = data->fh.data.data_len;
args.where.dir.data.data_val = data->fh.data.data_val;
}
*ptr = 0;
- /* new_path now points to the parent directory, and beyond the nul terminateor is the new directory to create */
+ /* new_path now points to the parent directory, and beyond the nul terminator is the new directory to create */
if (nfs_lookuppath_async(nfs, new_path, cb, private_data, nfs_creat_continue_internal, new_path, free, mode) != 0) {
rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components");
return -1;
svfs.f_bavail = res->FSSTAT3res_u.resok.abytes/4096;
svfs.f_files = res->FSSTAT3res_u.resok.tfiles;
svfs.f_ffree = res->FSSTAT3res_u.resok.ffiles;
+#if !defined(ANDROID)
svfs.f_favail = res->FSSTAT3res_u.resok.afiles;
svfs.f_fsid = 0;
svfs.f_flag = 0;
svfs.f_namemax = 256;
+#endif
data->cb(0, nfs, &svfs, data->private_data);
free_nfs_cb_data(data);
}
-
-
-
/*
* Async access()
*/
*/
uint64_t nfs_get_writemax(struct nfs_context *nfs)
{
- /* Some ZDR libraries can not marshall PDUs bigger than this */
- if (nfs->writemax < 32768) {
- return nfs->writemax;
- }
- return 32768;
+ return nfs->writemax;
}
void nfs_set_error(struct nfs_context *nfs, char *error_string, ...)