Change getattr and statx to bespoke policies

* Provides: slight improvement in performance as it no longer will
need to find and then act on the files.
* It doesn't make sense to support all original policy types. Most
people used 'newest' or 'ff' and 'combine' is a better default which
has same runtime as 'newest' but with better output.
This commit is contained in:
Antonio SJ Musumeci 2025-11-13 20:45:52 -06:00
parent 965e26989c
commit b3b8e793f9
145 changed files with 3803 additions and 1192 deletions

View file

@ -16,7 +16,6 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "fuse_statx.hpp"
#include "config.hpp"
@ -30,49 +29,11 @@
#include "symlinkify.hpp"
#include "ugid.hpp"
#include "fmt/core.h"
#include "fuse.h"
#include <string>
static
void
_set_stat_if_leads_to_dir(const fs::path &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 fs::path &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_fake_root(struct fuse_statx *st_)
@ -113,82 +74,23 @@ _statx_controlfile(struct fuse_statx *st_)
return 0;
}
static
int
_statx(const Policy::Search &searchFunc_,
const Branches &branches_,
const fs::path &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;
fs::path fullpath;
std::vector<Branch*> branches;
rv = searchFunc_(branches_,fusepath_,branches);
if(rv < 0)
return rv;
fullpath = branches[0]->path / 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(branches[0]->path,
fusepath_,
st_);
return 0;
}
static
int
_statx(const fs::path &fusepath_,
const uint32_t flags_,
const uint32_t mask_,
const u32 flags_,
const u32 mask_,
struct fuse_statx *st_,
fuse_timeouts_t *timeout_)
{
int rv;
rv = ::_statx(cfg.func.getattr.policy,
cfg.branches,
fusepath_,
flags_,
mask_,
st_,
cfg.symlinkify,
cfg.symlinkify_timeout,
cfg.follow_symlinks);
rv = cfg.statx(cfg.branches,
fusepath_,
flags_,
mask_,
st_,
cfg.follow_symlinks,
cfg.symlinkify_timeout);
if((rv < 0) && Config::is_rootdir(fusepath_))
return ::_statx_fake_root(st_);
@ -203,8 +105,8 @@ _statx(const fs::path &fusepath_,
int
FUSE::statx(const fuse_req_ctx_t *ctx_,
const char *fusepath_,
const uint32_t flags_,
const uint32_t mask_,
const u32 flags_,
const u32 mask_,
struct fuse_statx *st_,
fuse_timeouts_t *timeout_)
{
@ -222,9 +124,9 @@ FUSE::statx(const fuse_req_ctx_t *ctx_,
int
FUSE::statx_fh(const fuse_req_ctx_t *ctx_,
const uint64_t fh_,
const uint32_t flags_,
const uint32_t mask_,
const u64 fh_,
const u32 flags_,
const u32 mask_,
struct fuse_statx *st_,
fuse_timeouts_t *timeout_)
{