Skip to content

Commit

Permalink
port vufuse to fuse3
Browse files Browse the repository at this point in the history
  • Loading branch information
rd235 committed Nov 20, 2024
1 parent 445f9f2 commit b078ac2
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 132 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ include(GNUInstallDirs)
include(CheckIncludeFile)
include(CheckSymbolExists)

set(LIBS_REQUIRED stropt volatilestream execs vdeplug fuse)
set(HEADERS_REQUIRED stropt.h strcase.h volatilestream.h execs.h libvdeplug.h fuse.h pthread.h)
set(CMAKE_REQUIRED_DEFINITIONS -D_FILE_OFFSET_BITS=64)
set(LIBS_REQUIRED stropt volatilestream execs vdeplug fuse3)
set(HEADERS_REQUIRED stropt.h strcase.h volatilestream.h execs.h libvdeplug.h fuse3/fuse.h pthread.h)
# DFUSE_USE_VERSION 300 is just to test fuse3-dev availability
set(CMAKE_REQUIRED_DEFINITIONS -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=300)

foreach(THISLIB IN LISTS LIBS_REQUIRED)
find_library(LIB${THISLIB}_OK ${THISLIB})
Expand Down
2 changes: 1 addition & 1 deletion vufuse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.13)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=29")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=314")

include_directories(${VU_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR})

Expand Down
41 changes: 22 additions & 19 deletions vufuse/vufuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ int vu_vufuse_mount(const char *source, const char *target,
struct fuse_conn_info conn;
struct fuse_context fcx, *ofcx;
ofcx = fuse_push_context (&fcx);
new_fuse->private_data=new_fuse->fops.init(&conn);
struct fuse_config cfg; /* XXX */
memset(&cfg, 0, sizeof(cfg));
new_fuse->private_data=new_fuse->fops.init(&conn, &cfg);
fuse_pop_context(ofcx);
}

Expand Down Expand Up @@ -275,7 +277,7 @@ void fuse_pop_context(struct fuse_context *old) {
/*******************************************************************************************/
/* fuse related functions*/

int fuse_version(void) { return VUFUSE_FUSE_VERSION;}
int fuse_version(void) { return FUSE_USE_VERSION;}

struct fuse_context *fuse_get_context(void)
{
Expand All @@ -286,9 +288,9 @@ int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
size_t op_size, void *user_data)
{
struct fuse *f;
struct fuse_chan *fusechan = fuse_mount(NULL, NULL); /*options have been already parsed*/
if (fusechan != NULL) {
f = fuse_new(fusechan, NULL, op, op_size, user_data);
int res = fuse_mount(NULL, NULL); /*options have been already parsed*/
if (res != -1) {
f = fuse_new(NULL, op, op_size, user_data);

return fuse_loop(f);
} else
Expand All @@ -297,13 +299,12 @@ int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,

/* fuse_mount and fuse_unmount are dummy functions,
* the real mount operation has been done in vufuse_mount */
struct fuse_chan *fuse_mount(const char *mountpoint, struct fuse_args *args)
int fuse_mount(struct fuse *f, const char *mountpoint)
{
return vu_get_ht_private_data();
return 0;
}

void fuse_unmount(const char *mountpoint, struct fuse_chan *ch)
{
void fuse_unmount(struct fuse* f) {
return;
}

Expand All @@ -325,11 +326,11 @@ static void fopsmerge (const struct fuse_operations *fops, const struct fuse_ope
}
}

struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args,
struct fuse *fuse_new(struct fuse_args *args,
const struct fuse_operations *op, size_t op_size,
void *user_data)
{
struct fuse *fuse = (struct fuse *)ch;
struct fuse *fuse = vu_get_ht_private_data();
if (op_size != sizeof(struct fuse_operations)) {
printk(KERN_ERR "Fuse module vs vufuse support version mismatch\n");
return NULL;
Expand Down Expand Up @@ -379,12 +380,21 @@ void fuse_exit(struct fuse *f)

}

int fuse_loop_mt(struct fuse *f)
#if FUSE_USE_VERSION < 32
int fuse_loop_mt(struct fuse *f, int clone_fd)
{
//in fuselib is FUSE event loop with multiple threads,
//but hereeverything has multiple threads ;-)
return fuse_loop(f);
}
#else
int fuse_loop_mt(struct fuse *f, struct fuse_loop_config *config)
{
//in fuselib is FUSE event loop with multiple threads,
//but hereeverything has multiple threads ;-)
return fuse_loop(f);
}
#endif

/* other dummy functions. useless for vufuse */
struct fuse_session *fuse_get_session(struct fuse *f) {
Expand All @@ -410,13 +420,6 @@ int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
return 0;
}

int fuse_chan_fd(struct fuse_chan *ch) {
struct fuse *fuse = vu_get_ht_private_data();
if (fuse->fake_chan_fd == -1)
fuse->fake_chan_fd = open("/", O_PATH);
return fuse->fake_chan_fd;
}

/* constructor / destructor */
__attribute__((constructor))
static void init(void) {
Expand Down
5 changes: 1 addition & 4 deletions vufuse/vufuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@

#ifndef VUFUSE_H
#define VUFUSE_H
#include <fuse.h>

#ifndef VUFUSE_FUSE_VERSION
#define VUFUSE_FUSE_VERSION 29
#endif
#include <fuse3/fuse.h>

/** Enable hard remove */
#define FUSE_HARDREMOVE (1 << 0)
Expand Down
44 changes: 8 additions & 36 deletions vufuse/vufuse_default_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
*
*/

#include <fuse.h>
#include <fuse3/fuse.h>
#include <errno.h>
#include <stdio.h>
#include <libgen.h>
#include <vumodule.h>

/* Check fuse.h for the documentation*/

static int vustd_getattr (const char *path, struct stat *stat)
static int vustd_getattr (const char *path, struct stat *stat, struct fuse_file_info *fi)
{
printkdebug(F,"DEFAULT getattr %s\n", path);
return -ENOTSUP;
Expand All @@ -40,12 +40,6 @@ static int vustd_readlink (const char *path, char *link, size_t size)
return -EINVAL;
}

static int vustd_getdir (const char *path, fuse_dirh_t dir, fuse_dirfil_t dirf)
{
printkdebug(F,"DEFAULT getdir %s\n", path);
return -ENOSYS;
}

static int vustd_mknod (const char *path, mode_t mode, dev_t dev)
{
printkdebug(F,"DEFAULT mknod %s\n", path);
Expand Down Expand Up @@ -76,7 +70,7 @@ static int vustd_symlink (const char *path, const char *newpath)
return -ENOSYS;
}

static int vustd_rename (const char *path, const char *newpath)
static int vustd_rename (const char *path, const char *newpath, unsigned int flags)
{
printkdebug(F,"DEFAULT rename %s\n", path);
return -ENOSYS;
Expand All @@ -88,31 +82,25 @@ static int vustd_link (const char *path, const char *newpath)
return -ENOSYS;
}

static int vustd_chmod (const char *path, mode_t mode)
static int vustd_chmod (const char *path, mode_t mode, struct fuse_file_info *fi)
{
printkdebug(F,"DEFAULT chmod %s\n", path);
return -ENOSYS;
}

static int vustd_chown (const char *path, uid_t uid, gid_t gid)
static int vustd_chown (const char *path, uid_t uid, gid_t gid, struct fuse_file_info *fi)
{
printkdebug(F,"DEFAULT chown %s\n", path);
return -ENOSYS;
}

static int vustd_truncate (const char *path, off_t off)
static int vustd_truncate (const char *path, off_t off, struct fuse_file_info *fi)
{
printkdebug(F,"DEFAULT truncat %s\n", path);
return -ENOSYS;
}

static int vustd_utime (const char *path, struct utimbuf *timbuf)
{
printkdebug(F,"DEFAULT utime %s\n", path);
return -ENOSYS;
}

static int vustd_open (const char *path, struct fuse_file_info *fileinfo)
static int vustd_open (const char *path, struct fuse_file_info *fi)
{
printkdebug(F,"DEFAULT open %s\n", path);
return -ENOSYS;
Expand Down Expand Up @@ -222,25 +210,13 @@ static int vustd_create (const char *path, mode_t mode, struct fuse_file_info *f
return -ENOSYS;
}

static int vustd_ftruncate (const char *path, off_t length, struct fuse_file_info *fileinfo)
{
printkdebug(F,"DEFAULT ftruncate %s\n", path);
return -ENOSYS;
}

static int vustd_fgetattr (const char *path, struct stat *buf, struct fuse_file_info *fileinfo)
{
printkdebug(F,"DEFAULT ftruncate %s\n", path);
return -ENOSYS;
}

static int vustd_lock (const char *path, struct fuse_file_info *fileinfo, int cmd, struct flock *fl)
{
printkdebug(F,"DEFAULT lock %s\n", path);
return -ENOSYS;
}

static int vustd_utimens(const char *path, const struct timespec tv[2])
static int vustd_utimens(const char *path, const struct timespec tv[2], struct fuse_file_info *fi)
{
printkdebug(F,"DEFAULT utimens %s\n", path);
return -ENOSYS;
Expand All @@ -255,7 +231,6 @@ static int vustd_bmap (const char *path, size_t blocksize, uint64_t *idx)
struct fuse_operations vufuse_default_ops = {
.getattr = vustd_getattr,
.readlink = vustd_readlink,
.getdir = vustd_getdir,
.mknod = vustd_mknod,
.mkdir = vustd_mkdir,
.unlink = vustd_unlink,
Expand All @@ -266,7 +241,6 @@ struct fuse_operations vufuse_default_ops = {
.chmod = vustd_chmod,
.chown = vustd_chown,
.truncate = vustd_truncate,
.utime = vustd_utime,
.open = vustd_open,
.read = vustd_read,
.write = vustd_write,
Expand All @@ -287,8 +261,6 @@ struct fuse_operations vufuse_default_ops = {

.access = vustd_access,
.create = vustd_create,
.ftruncate = vustd_ftruncate,
.fgetattr = vustd_fgetattr,
.lock = vustd_lock,
.utimens = vustd_utimens,
.bmap = vustd_bmap,
Expand Down
2 changes: 1 addition & 1 deletion vufuse/vufuse_default_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifndef VUFUSE_DEFAULT_OPS_H
#define VUFUSE_DEFAULT_OPS_H

#include <fuse.h>
#include <fuse3/fuse.h>

extern struct fuse_operations vufuse_default_ops;

Expand Down
Loading

0 comments on commit b078ac2

Please sign in to comment.