Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow building with fuse3 #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/getattr.cc
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/readdir.cc
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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());
Expand All @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions src/tmfs.hh
Original file line number Diff line number Diff line change
@@ -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 <sys/time.h>
#include <sys/types.h>
Expand Down Expand Up @@ -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);
Expand Down