mirror of https://github.com/trapexit/mergerfs.git
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 446 additions and 3 deletions
-
10libfuse/include/fuse.h
-
6libfuse/include/fuse_lowlevel.h
-
73libfuse/lib/fuse.cpp
-
16libfuse/lib/fuse_lowlevel.cpp
-
26src/fs_inode.cpp
-
11src/fs_inode.hpp
-
51src/fs_statx.hpp
-
186src/fuse_statx.cpp
-
38src/fuse_statx.hpp
-
3src/mergerfs.cpp
-
29src/symlinkify.hpp
@ -0,0 +1,51 @@ |
|||
#pragma once
|
|||
|
|||
#include "fuse_kernel.h"
|
|||
|
|||
#include <string>
|
|||
|
|||
#ifndef _GNU_SOURCE
|
|||
#define _GNU_SOURCE
|
|||
#endif
|
|||
|
|||
#include <fcntl.h>
|
|||
#include <sys/stat.h>
|
|||
|
|||
namespace fs |
|||
{ |
|||
static |
|||
inline |
|||
int |
|||
statx(const int dirfd_, |
|||
const char *pathname_, |
|||
const int flags_, |
|||
const unsigned int mask_, |
|||
struct fuse_statx *st_) |
|||
{ |
|||
#ifdef STATX_TYPE
|
|||
int rv; |
|||
|
|||
rv = ::statx(dirfd_, |
|||
pathname_, |
|||
flags_, |
|||
mask_, |
|||
(struct statx*)st_); |
|||
|
|||
return ((rv == -1) ? -errno : 0); |
|||
#else
|
|||
return -ENOSYS; |
|||
#endif
|
|||
} |
|||
|
|||
static |
|||
inline |
|||
int |
|||
statx(const int dirfd_, |
|||
const std::string &pathname_, |
|||
const int flags_, |
|||
const unsigned int mask_, |
|||
struct fuse_statx *st_) |
|||
{ |
|||
return fs::statx(dirfd_,pathname_.c_str(),flags_,mask_,st_); |
|||
} |
|||
} |
@ -0,0 +1,186 @@ |
|||
#include "fuse_statx.hpp"
|
|||
|
|||
#include "config.hpp"
|
|||
#include "errno.hpp"
|
|||
#include "fileinfo.hpp"
|
|||
#include "fs_inode.hpp"
|
|||
#include "fs_path.hpp"
|
|||
#include "fs_statx.hpp"
|
|||
#include "symlinkify.hpp"
|
|||
#include "ugid.hpp"
|
|||
|
|||
#include "fmt/core.h"
|
|||
|
|||
#include "fuse.h"
|
|||
|
|||
#include <string>
|
|||
|
|||
|
|||
static |
|||
void |
|||
_set_stat_if_leads_to_dir(const std::string &path_, |
|||
struct fuse_statx *st_) |
|||
{ |
|||
int rv; |
|||
struct fuse_statx st; |
|||
|
|||
rv = fs::statx(AT_FDCWD,path_,AT_SYMLINK_FOLLOW,STATX_TYPE,st_); |
|||
if(rv < 0) |
|||
return; |
|||
|
|||
if(S_ISDIR(st.mode)) |
|||
*st_ = st; |
|||
|
|||
return; |
|||
} |
|||
|
|||
static |
|||
void |
|||
_set_stat_if_leads_to_reg(const std::string &path_, |
|||
struct fuse_statx *st_) |
|||
{ |
|||
int rv; |
|||
struct fuse_statx st; |
|||
|
|||
rv = fs::statx(AT_FDCWD,path_,AT_SYMLINK_FOLLOW,STATX_TYPE,st_); |
|||
if(rv < 0) |
|||
return; |
|||
|
|||
if(S_ISREG(st.mode)) |
|||
*st_ = st; |
|||
|
|||
return; |
|||
} |
|||
|
|||
static |
|||
int |
|||
_statx_controlfile(struct fuse_statx *st_) |
|||
{ |
|||
static const uid_t uid = ::getuid(); |
|||
static const gid_t gid = ::getgid(); |
|||
static const time_t now = ::time(NULL); |
|||
|
|||
st_->ino = fs::inode::MAGIC; |
|||
st_->mode = (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); |
|||
st_->nlink = 1; |
|||
st_->uid = uid; |
|||
st_->gid = gid; |
|||
st_->size = 0; |
|||
st_->blocks = 0; |
|||
st_->atime.tv_sec = now; |
|||
st_->mtime.tv_sec = now; |
|||
st_->ctime.tv_sec = now; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
static |
|||
int |
|||
_statx(const Policy::Search &searchFunc_, |
|||
const Branches &branches_, |
|||
const char *fusepath_, |
|||
const uint32_t flags_, |
|||
const uint32_t mask_, |
|||
struct fuse_statx *st_, |
|||
const bool symlinkify_, |
|||
const time_t symlinkify_timeout_, |
|||
FollowSymlinks followsymlinks_) |
|||
{ |
|||
int rv; |
|||
std::string fullpath; |
|||
StrVec basepaths; |
|||
|
|||
rv = searchFunc_(branches_,fusepath_,&basepaths); |
|||
if(rv == -1) |
|||
return -errno; |
|||
|
|||
fullpath = fs::path::make(basepaths[0],fusepath_); |
|||
|
|||
switch(followsymlinks_) |
|||
{ |
|||
case FollowSymlinks::ENUM::NEVER: |
|||
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_); |
|||
break; |
|||
case FollowSymlinks::ENUM::DIRECTORY: |
|||
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_); |
|||
if((rv >= 0) && S_ISLNK(st_->mode)) |
|||
::_set_stat_if_leads_to_dir(fullpath,st_); |
|||
break; |
|||
case FollowSymlinks::ENUM::REGULAR: |
|||
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_); |
|||
if((rv >= 0) && S_ISLNK(st_->mode)) |
|||
::_set_stat_if_leads_to_reg(fullpath,st_); |
|||
break; |
|||
case FollowSymlinks::ENUM::ALL: |
|||
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_FOLLOW,mask_,st_); |
|||
if(rv < 0) |
|||
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_); |
|||
break; |
|||
} |
|||
|
|||
if(rv < 0) |
|||
return rv; |
|||
|
|||
if(symlinkify_ && symlinkify::can_be_symlink(*st_,symlinkify_timeout_)) |
|||
symlinkify::convert(fullpath,st_); |
|||
|
|||
fs::inode::calc(fusepath_,st_); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
static |
|||
int |
|||
_statx(const char *fusepath_, |
|||
const uint32_t flags_, |
|||
const uint32_t mask_, |
|||
struct fuse_statx *st_, |
|||
fuse_timeouts_t *timeout_) |
|||
{ |
|||
int rv; |
|||
Config::Read cfg; |
|||
const fuse_context *fc = fuse_get_context(); |
|||
const ugid::Set ugid(fc->uid,fc->gid); |
|||
|
|||
rv = ::_statx(cfg->func.getattr.policy, |
|||
cfg->branches, |
|||
fusepath_, |
|||
flags_, |
|||
mask_, |
|||
st_, |
|||
cfg->symlinkify, |
|||
cfg->symlinkify_timeout, |
|||
cfg->follow_symlinks); |
|||
|
|||
timeout_->entry = ((rv >= 0) ? |
|||
cfg->cache_entry : |
|||
cfg->cache_negative_entry); |
|||
timeout_->attr = cfg->cache_attr; |
|||
|
|||
return rv; |
|||
} |
|||
|
|||
int |
|||
FUSE::statx(const char *fusepath_, |
|||
const uint32_t flags_, |
|||
const uint32_t mask_, |
|||
struct fuse_statx *st_, |
|||
fuse_timeouts_t *timeout_) |
|||
{ |
|||
if(fusepath_ == CONTROLFILE) |
|||
return ::_statx_controlfile(st_); |
|||
|
|||
return ::_statx(fusepath_,flags_|AT_STATX_DONT_SYNC,mask_,st_,timeout_); |
|||
} |
|||
|
|||
int |
|||
FUSE::statx_fh(const uint64_t fh_, |
|||
const uint32_t flags_, |
|||
const uint32_t mask_, |
|||
struct fuse_statx *st_, |
|||
fuse_timeouts_t *timeout_) |
|||
{ |
|||
FileInfo *fi = reinterpret_cast<FileInfo*>(fh_); |
|||
|
|||
return ::_statx(fi->fusepath.c_str(),flags_,mask_,st_,timeout_); |
|||
} |
@ -0,0 +1,38 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2025, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
Permission to use, copy, modify, and/or distribute this software for any |
|||
purpose with or without fee is hereby granted, provided that the above |
|||
copyright notice and this permission notice appear in all copies. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include "fuse.h"
|
|||
#include "fuse_kernel.h"
|
|||
|
|||
#include <cstdint>
|
|||
|
|||
namespace FUSE |
|||
{ |
|||
int statx(const char *fusepath, |
|||
const uint32_t flags, |
|||
const uint32_t mask, |
|||
struct fuse_statx *st, |
|||
fuse_timeouts_t *timeout); |
|||
int statx_fh(const uint64_t fh, |
|||
const uint32_t flags, |
|||
const uint32_t mask, |
|||
struct fuse_statx *st, |
|||
fuse_timeouts_t *timeout); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue