2019-03-26 22:04:53 +00:00
|
|
|
#include "webfuse/adapter/impl/filesystem.h"
|
|
|
|
#include "webfuse/adapter/impl/operations.h"
|
2019-02-05 23:58:51 +00:00
|
|
|
|
2019-04-01 20:15:12 +00:00
|
|
|
#include <stdlib.h>
|
2019-02-05 23:58:51 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2019-03-26 14:35:33 +00:00
|
|
|
static struct fuse_lowlevel_ops const filesystem_operations =
|
2019-02-05 23:58:51 +00:00
|
|
|
{
|
2019-03-26 22:04:53 +00:00
|
|
|
.lookup = &wf_impl_operation_lookup,
|
|
|
|
.getattr = &wf_impl_operation_getattr,
|
|
|
|
.readdir = &wf_impl_operation_readdir,
|
|
|
|
.open = &wf_impl_operation_open,
|
|
|
|
.release = &wf_impl_operation_close,
|
|
|
|
.read = &wf_impl_operation_read
|
2019-02-05 23:58:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
bool wf_impl_filesystem_init(
|
|
|
|
struct wf_impl_filesystem * filesystem,
|
2019-04-01 20:15:12 +00:00
|
|
|
struct wf_impl_session_manager * session_manager,
|
2019-02-05 23:58:51 +00:00
|
|
|
char * mount_point)
|
|
|
|
{
|
2019-02-09 02:08:02 +00:00
|
|
|
bool result = false;
|
|
|
|
|
2019-02-05 23:58:51 +00:00
|
|
|
char * argv[] = {"", NULL};
|
|
|
|
filesystem->args.argc = 1;
|
|
|
|
filesystem->args.argv = argv;
|
|
|
|
filesystem->args.allocated = 0;
|
|
|
|
|
2019-04-01 20:15:12 +00:00
|
|
|
filesystem->user_data.session_manager = session_manager;
|
2019-02-05 23:58:51 +00:00
|
|
|
filesystem->user_data.timeout = 1.0;
|
|
|
|
memset(&filesystem->buffer, 0, sizeof(struct fuse_buf));
|
|
|
|
|
|
|
|
filesystem->session = fuse_session_new(
|
|
|
|
&filesystem->args,
|
2019-03-26 14:35:33 +00:00
|
|
|
&filesystem_operations,
|
|
|
|
sizeof(filesystem_operations),
|
2019-02-05 23:58:51 +00:00
|
|
|
&filesystem->user_data);
|
|
|
|
if (NULL != filesystem->session)
|
|
|
|
{
|
2019-02-09 02:08:02 +00:00
|
|
|
result = (0 == fuse_session_mount(filesystem->session, mount_point));
|
2019-02-05 23:58:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 02:08:02 +00:00
|
|
|
return result;
|
2019-02-05 23:58:51 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
void wf_impl_filesystem_cleanup(
|
|
|
|
struct wf_impl_filesystem * filesystem)
|
2019-02-05 23:58:51 +00:00
|
|
|
{
|
|
|
|
if (NULL != filesystem->session)
|
|
|
|
{
|
|
|
|
fuse_session_reset(filesystem->session);
|
|
|
|
fuse_session_unmount(filesystem->session);
|
|
|
|
fuse_session_destroy(filesystem->session);
|
|
|
|
filesystem->session = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(filesystem->buffer.mem);
|
|
|
|
fuse_opt_free_args(&filesystem->args);
|
|
|
|
}
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
int wf_impl_filesystem_get_fd(
|
|
|
|
struct wf_impl_filesystem * filesystem)
|
2019-02-05 23:58:51 +00:00
|
|
|
{
|
|
|
|
return fuse_session_fd(filesystem->session);
|
|
|
|
}
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
void wf_impl_filesystem_process_request(
|
|
|
|
struct wf_impl_filesystem * filesystem)
|
2019-02-05 23:58:51 +00:00
|
|
|
{
|
|
|
|
int const result = fuse_session_receive_buf(filesystem->session, &filesystem->buffer);
|
|
|
|
if (0 < result)
|
|
|
|
{
|
|
|
|
fuse_session_process_buf(filesystem->session, &filesystem->buffer);
|
|
|
|
}
|
|
|
|
else if (-EINTR != result)
|
|
|
|
{
|
|
|
|
// ToDo
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|