mirror of
https://github.com/falk-werner/webfuse
synced 2025-06-13 12:54:15 +00:00
moves mountpoint handling into filesystem: mountpoints are removed during session cleanup
This commit is contained in:
parent
1b15f30f2f
commit
d33f0f36cc
@ -3,6 +3,11 @@
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
@ -19,36 +24,44 @@ static struct fuse_lowlevel_ops const filesystem_operations =
|
||||
.read = &wf_impl_operation_read
|
||||
};
|
||||
|
||||
struct wf_impl_filesystem * wf_impl_filesystem_create(
|
||||
struct wf_impl_session * session,
|
||||
char const * mount_point)
|
||||
static char * wf_impl_filesystem_create_id(void)
|
||||
{
|
||||
struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem));
|
||||
if (NULL != filesystem)
|
||||
{
|
||||
bool success = wf_impl_filesystem_init(filesystem, session, mount_point);
|
||||
if (!success)
|
||||
{
|
||||
free(filesystem);
|
||||
filesystem = NULL;
|
||||
}
|
||||
}
|
||||
uuid_t uuid;
|
||||
uuid_generate(uuid);
|
||||
char id[UUID_STR_LEN];
|
||||
uuid_unparse(uuid, id);
|
||||
|
||||
return filesystem;
|
||||
return strdup(id);
|
||||
}
|
||||
|
||||
void wf_impl_filesystem_dispose(
|
||||
static void wf_impl_filesystem_cleanup(
|
||||
struct wf_impl_filesystem * filesystem)
|
||||
{
|
||||
wf_impl_filesystem_cleanup(filesystem);
|
||||
free(filesystem);
|
||||
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);
|
||||
|
||||
struct wf_impl_session * session = filesystem->user_data.session;
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s", session->mount_point, filesystem->user_data.name, filesystem->id);
|
||||
rmdir(path);
|
||||
|
||||
snprintf(path, PATH_MAX, "%s/%s", session->mount_point, filesystem->user_data.name);
|
||||
rmdir(path);
|
||||
|
||||
free(filesystem->user_data.name);
|
||||
free(filesystem->id);
|
||||
}
|
||||
|
||||
|
||||
bool wf_impl_filesystem_init(
|
||||
static bool wf_impl_filesystem_init(
|
||||
struct wf_impl_filesystem * filesystem,
|
||||
struct wf_impl_session * session,
|
||||
char const * mount_point)
|
||||
char const * name)
|
||||
{
|
||||
bool result = false;
|
||||
wf_dlist_item_init(&filesystem->item);
|
||||
@ -60,8 +73,17 @@ bool wf_impl_filesystem_init(
|
||||
|
||||
filesystem->user_data.session = session;
|
||||
filesystem->user_data.timeout = 1.0;
|
||||
filesystem->user_data.name = strdup(name);
|
||||
filesystem->id = wf_impl_filesystem_create_id();
|
||||
memset(&filesystem->buffer, 0, sizeof(struct fuse_buf));
|
||||
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, PATH_MAX, "%s/%s", session->mount_point, name);
|
||||
mkdir(path, 0755);
|
||||
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s", session->mount_point, name, filesystem->id);
|
||||
mkdir(path, 0755);
|
||||
|
||||
filesystem->session = fuse_session_new(
|
||||
&filesystem->args,
|
||||
&filesystem_operations,
|
||||
@ -69,7 +91,7 @@ bool wf_impl_filesystem_init(
|
||||
&filesystem->user_data);
|
||||
if (NULL != filesystem->session)
|
||||
{
|
||||
result = (0 == fuse_session_mount(filesystem->session, mount_point));
|
||||
result = (0 == fuse_session_mount(filesystem->session, path));
|
||||
}
|
||||
|
||||
if (result)
|
||||
@ -90,25 +112,29 @@ bool wf_impl_filesystem_init(
|
||||
return result;
|
||||
}
|
||||
|
||||
void wf_impl_filesystem_cleanup(
|
||||
struct wf_impl_filesystem * filesystem)
|
||||
struct wf_impl_filesystem * wf_impl_filesystem_create(
|
||||
struct wf_impl_session * session,
|
||||
char const * name)
|
||||
{
|
||||
if (NULL != filesystem->session)
|
||||
struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem));
|
||||
if (NULL != filesystem)
|
||||
{
|
||||
fuse_session_reset(filesystem->session);
|
||||
fuse_session_unmount(filesystem->session);
|
||||
fuse_session_destroy(filesystem->session);
|
||||
filesystem->session = NULL;
|
||||
bool success = wf_impl_filesystem_init(filesystem, session, name);
|
||||
if (!success)
|
||||
{
|
||||
free(filesystem);
|
||||
filesystem = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
free(filesystem->buffer.mem);
|
||||
fuse_opt_free_args(&filesystem->args);
|
||||
return filesystem;
|
||||
}
|
||||
|
||||
int wf_impl_filesystem_get_fd(
|
||||
void wf_impl_filesystem_dispose(
|
||||
struct wf_impl_filesystem * filesystem)
|
||||
{
|
||||
return fuse_session_fd(filesystem->session);
|
||||
wf_impl_filesystem_cleanup(filesystem);
|
||||
free(filesystem);
|
||||
}
|
||||
|
||||
void wf_impl_filesystem_process_request(
|
||||
|
@ -25,26 +25,17 @@ struct wf_impl_filesystem
|
||||
struct fuse_buf buffer;
|
||||
struct wf_impl_operations_context user_data;
|
||||
struct lws * wsi;
|
||||
char * name;
|
||||
char * id;
|
||||
};
|
||||
|
||||
extern struct wf_impl_filesystem * wf_impl_filesystem_create(
|
||||
struct wf_impl_session * session,
|
||||
char const * mount_point);
|
||||
char const * name);
|
||||
|
||||
extern void wf_impl_filesystem_dispose(
|
||||
struct wf_impl_filesystem * filesystem);
|
||||
|
||||
extern bool wf_impl_filesystem_init(
|
||||
struct wf_impl_filesystem * filesystem,
|
||||
struct wf_impl_session * session,
|
||||
char const * mount_point);
|
||||
|
||||
extern void wf_impl_filesystem_cleanup(
|
||||
struct wf_impl_filesystem * filesystem);
|
||||
|
||||
extern int wf_impl_filesystem_get_fd(
|
||||
struct wf_impl_filesystem * filesystem);
|
||||
|
||||
extern void wf_impl_filesystem_process_request(
|
||||
struct wf_impl_filesystem * filesystem);
|
||||
|
||||
|
@ -14,6 +14,7 @@ struct wf_impl_operations_context
|
||||
{
|
||||
struct wf_impl_session * session;
|
||||
double timeout;
|
||||
char * name;
|
||||
};
|
||||
|
||||
extern void wf_impl_operation_lookup (
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include "webfuse/core/container_of.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
@ -103,16 +101,7 @@ bool wf_impl_session_add_filesystem(
|
||||
struct wf_impl_session * session,
|
||||
char const * name)
|
||||
{
|
||||
uuid_t uuid;
|
||||
uuid_generate(uuid);
|
||||
char id[UUID_STR_LEN];
|
||||
uuid_unparse(uuid, id);
|
||||
|
||||
char mount_point[PATH_MAX];
|
||||
snprintf(mount_point, PATH_MAX, "%s/%s/%s", session->mount_point, name, id);
|
||||
mkdir(mount_point, 0755);
|
||||
|
||||
struct wf_impl_filesystem * filesystem = wf_impl_filesystem_create(session, mount_point);
|
||||
struct wf_impl_filesystem * filesystem = wf_impl_filesystem_create(session, name);
|
||||
wf_dlist_prepend(&session->filesystems, &filesystem->item);
|
||||
return (NULL != filesystem);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user