From 1dbf49175649d4025d2a95a40bf34339650e9bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Tue, 15 Oct 2024 18:23:19 +0200 Subject: [PATCH] Allow building with fuse3 --- CMakeLists.txt | 8 ++++++-- src/getattr.cc | 2 +- src/readdir.cc | 10 +++++----- src/tmfs.hh | 10 ++++++++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 074077e..95574f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,13 @@ project(TMFS CXX) set(CMAKE_CXX_STANDARD 17) find_package(PkgConfig) -pkg_check_modules(FUSE REQUIRED fuse) +pkg_check_modules(FUSE fuse3) +if(NOT FUSE_FOUND) + pkg_check_modules(FUSE REQUIRED fuse) +endif() +string(REGEX REPLACE "\\..*" "" FUSE_VERSION ${FUSE_VERSION}) -add_definitions(${FUSE_CFLAGS} -Wall) +add_definitions(${FUSE_CFLAGS} -DFUSE=${FUSE_VERSION} -Wall) include_directories(${Boost_INCLUDE_DIRS}) add_executable(tmfs diff --git a/src/getattr.cc b/src/getattr.cc index 636b936..5ac4211 100644 --- a/src/getattr.cc +++ b/src/getattr.cc @@ -1,6 +1,6 @@ #include "tmfs.hh" -int tmfs_getattr(const char *path, struct stat *stbuf) +int tmfs_getattr(const char *path, struct stat *stbuf FUSE3_ONLY(, struct fuse_file_info *)) { // get the real path std::string real_path = get_real_path(path); diff --git a/src/readdir.cc b/src/readdir.cc index 9961b74..14b3b2a 100644 --- a/src/readdir.cc +++ b/src/readdir.cc @@ -1,7 +1,7 @@ #include "tmfs.hh" int tmfs_readdir(const char * path, void * buf, fuse_fill_dir_t filler_cb, off_t offset, - struct fuse_file_info * fi) + struct fuse_file_info * fi FUSE3_ONLY(, enum fuse_readdir_flags)) { // get the real path std::string real_path = get_real_path(path); @@ -15,8 +15,8 @@ int tmfs_readdir(const char * path, void * buf, fuse_fill_dir_t filler_cb, off_t // report ./ and ../ stbuf.st_mode = S_IFDIR | 0755; stbuf.st_nlink = 2; - filler_cb(buf, ".", &stbuf, 0); - filler_cb(buf, "..", &stbuf, 0); + filler_cb(buf, ".", &stbuf, 0 FUSE3_ONLY(, FUSE_FILL_DIR_PLUS)); + filler_cb(buf, "..", &stbuf, 0 FUSE3_ONLY(, FUSE_FILL_DIR_PLUS)); // now iterate over the real directory DIR * dir = opendir(real_path.c_str()); @@ -28,11 +28,11 @@ int tmfs_readdir(const char * path, void * buf, fuse_fill_dir_t filler_cb, off_t { // stat the file pointed by entry auto file_path = fs::path(path) / entry->d_name; - if (tmfs_getattr(file_path.string().c_str(), &stbuf)) + if (tmfs_getattr(file_path.string().c_str(), &stbuf FUSE3_ONLY(, nullptr))) continue; stbuf.st_mode |= 0755; // report the entry - filler_cb(buf, entry->d_name, &stbuf, 0); + filler_cb(buf, entry->d_name, &stbuf, 0 FUSE3_ONLY(, FUSE_FILL_DIR_PLUS)); } closedir(dir); diff --git a/src/tmfs.hh b/src/tmfs.hh index 8c16b9f..eea2163 100644 --- a/src/tmfs.hh +++ b/src/tmfs.hh @@ -1,6 +1,12 @@ #pragma once +#if FUSE == 2 #define FUSE_USE_VERSION 26 +#define FUSE3_ONLY(...) +#else +#define FUSE_USE_VERSION FUSE_MAKE_VERSION(3, 14) +#define FUSE3_ONLY(...) __VA_ARGS__ +#endif #include #include @@ -38,9 +44,9 @@ std::string get_real_path(const std::string & path); /** fuse functions * @{ */ -int tmfs_getattr(const char * path, struct stat *stbuf); +int tmfs_getattr(const char * path, struct stat *stbuf FUSE3_ONLY(, struct fuse_file_info *)); int tmfs_readdir(const char * path, void * buf, fuse_fill_dir_t filler_callback, - off_t offset, struct fuse_file_info * fi); + off_t offset, struct fuse_file_info * fi FUSE3_ONLY(, enum fuse_readdir_flags)); int tmfs_read(const char * path, char * buf, size_t nbytes, off_t offset, struct fuse_file_info * fi); int tmfs_readlink(const char * path, char * buf, size_t size);