2019-01-27 02:45:03 +00:00
|
|
|
#include "wsfs/operations.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "wsfs/util.h"
|
2019-01-29 22:11:46 +00:00
|
|
|
#include "wsfs/jsonrpc.h"
|
2019-01-27 02:45:03 +00:00
|
|
|
|
|
|
|
static void* wsfs_operation_init(
|
|
|
|
struct fuse_conn_info * WSFS_UNUSED_PARAM(connection),
|
|
|
|
struct fuse_config * config)
|
|
|
|
{
|
|
|
|
struct fuse_context * const context = fuse_get_context();
|
|
|
|
config->kernel_cache = 1;
|
|
|
|
|
2019-01-29 22:11:46 +00:00
|
|
|
return context->private_data;
|
2019-01-27 11:01:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-02 08:37:18 +00:00
|
|
|
static void wsfs_operations_init(
|
2019-01-27 02:45:03 +00:00
|
|
|
struct fuse_operations * operations)
|
|
|
|
{
|
|
|
|
memset(operations, 0, sizeof(struct fuse_operations));
|
|
|
|
operations->init = &wsfs_operation_init;
|
|
|
|
operations->getattr = &wsfs_operation_getattr;
|
|
|
|
operations->readdir = &wsfs_operation_readdir;
|
2019-01-27 11:01:01 +00:00
|
|
|
operations->open = &wsfs_operation_open;
|
2019-01-29 22:47:08 +00:00
|
|
|
operations->release = &wsfs_operation_close;
|
2019-01-27 11:01:01 +00:00
|
|
|
operations->read = &wsfs_operation_read;
|
2019-01-27 02:45:03 +00:00
|
|
|
}
|
|
|
|
|
2019-02-02 08:37:18 +00:00
|
|
|
int wsfs_operations_loop(
|
|
|
|
char * mount_point,
|
|
|
|
struct wsfs_jsonrpc * rpc)
|
|
|
|
{
|
|
|
|
struct fuse_operations operations;
|
|
|
|
wsfs_operations_init(&operations);
|
|
|
|
|
|
|
|
char * fuse_args[] = { "app", "-s", "-f", mount_point, NULL };
|
|
|
|
int const result = fuse_main(4, fuse_args, &operations, rpc);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2019-02-02 10:45:38 +00:00
|
|
|
|
|
|
|
int wsfs_operations_loop_ll(
|
2019-02-02 11:34:07 +00:00
|
|
|
char * mount_point,
|
|
|
|
struct wsfs_jsonrpc * rpc)
|
2019-02-02 10:45:38 +00:00
|
|
|
{
|
|
|
|
struct fuse_lowlevel_ops operations;
|
|
|
|
memset(&operations, 0, sizeof(struct fuse_lowlevel_ops));
|
|
|
|
operations.lookup = &wsfs_operation_ll_lookup;
|
|
|
|
operations.getattr = &wsfs_operation_ll_getattr;
|
|
|
|
operations.readdir = &wsfs_operation_ll_readdir;
|
|
|
|
operations.open = &wsfs_operation_ll_open;
|
|
|
|
operations.release = &wsfs_operation_ll_close;
|
|
|
|
operations.read = &wsfs_operation_ll_read;
|
|
|
|
|
2019-02-02 11:34:07 +00:00
|
|
|
int result = 1;
|
|
|
|
const int argc = 1;
|
|
|
|
char * argv[] = {"", NULL};
|
|
|
|
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
|
2019-02-02 13:49:42 +00:00
|
|
|
struct wsfs_operations_context context = {
|
|
|
|
.rpc = rpc,
|
|
|
|
.timeout = 1.0
|
|
|
|
};
|
|
|
|
struct fuse_session * session = fuse_session_new(&args, &operations, sizeof(operations), &context);
|
2019-02-02 11:34:07 +00:00
|
|
|
if (NULL != session)
|
|
|
|
{
|
|
|
|
fuse_set_signal_handlers(session);
|
|
|
|
result = fuse_session_mount(session, mount_point);
|
|
|
|
if (0 == result)
|
|
|
|
{
|
|
|
|
result = fuse_session_loop(session);
|
|
|
|
fuse_session_unmount(session);
|
|
|
|
}
|
|
|
|
fuse_remove_signal_handlers(session);
|
|
|
|
fuse_session_destroy(session);
|
|
|
|
}
|
2019-02-02 10:45:38 +00:00
|
|
|
|
2019-02-02 11:34:07 +00:00
|
|
|
fuse_opt_free_args(&args);
|
2019-02-02 10:45:38 +00:00
|
|
|
return 0;
|
2019-02-02 11:34:07 +00:00
|
|
|
}
|