2024-02-04 01:19:44 -06:00
|
|
|
#include "func_create_ff.hpp"
|
|
|
|
|
2024-02-04 13:27:47 -06:00
|
|
|
#include "fileinfo.hpp"
|
2024-02-04 01:19:44 -06:00
|
|
|
#include "fs_info.hpp"
|
|
|
|
#include "fs_open.hpp"
|
|
|
|
#include "ugid.hpp"
|
2024-02-04 21:39:17 -06:00
|
|
|
#include "func_open_create_utils.hpp"
|
2024-02-04 01:19:44 -06:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
|
|
Func::CreateFF::CreateFF()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Func::CreateFF::~CreateFF()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace l
|
|
|
|
{
|
|
|
|
static
|
|
|
|
int
|
|
|
|
create(Branches2 &branches_,
|
|
|
|
char const *fusepath_,
|
|
|
|
mode_t const mode_,
|
|
|
|
mode_t const umask_,
|
|
|
|
fuse_file_info_t *ffi_)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
fs::info_t info;
|
|
|
|
|
|
|
|
for(auto &tier : branches_)
|
|
|
|
{
|
|
|
|
for(auto &branch : tier)
|
|
|
|
{
|
|
|
|
if(branch.mode != +Branch2::Mode::RW)
|
|
|
|
continue;
|
|
|
|
rv = fs::info(branch.path,&info);
|
|
|
|
if(rv == -1)
|
|
|
|
continue;
|
|
|
|
if(info.readonly)
|
|
|
|
continue;
|
|
|
|
if(info.spaceavail < branch.min_free_space)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ghc::filesystem::path fullpath;
|
|
|
|
|
|
|
|
fullpath = branch.path / fusepath_;
|
|
|
|
|
2024-02-04 21:45:34 -06:00
|
|
|
if(!fs::acl::dir_has_defaults(fullpath))
|
|
|
|
mode_ &= ~umask_;
|
|
|
|
|
2024-02-04 01:19:44 -06:00
|
|
|
rv = fs::open(fullpath,ffi_->flags,mode_);
|
|
|
|
if((rv == -1) && (errno == EROFS))
|
|
|
|
{
|
|
|
|
branch.mode = Branch2::Mode::RO;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-02-04 13:27:40 -06:00
|
|
|
FileInfo *fi = new FileInfo(rv,fusepath_,ffi_->direct_io);
|
|
|
|
|
|
|
|
ffi_->fh = reinterpret_cast<uint64_t>(fi);
|
|
|
|
|
2024-02-04 13:51:48 -06:00
|
|
|
return 0;
|
2024-02-04 01:19:44 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Func::CreateFF::operator()(Branches2 &branches_,
|
|
|
|
char const *fusepath_,
|
|
|
|
mode_t const mode_,
|
|
|
|
fuse_file_info_t *ffi_)
|
|
|
|
{
|
|
|
|
int rv;
|
2024-02-04 21:41:34 -06:00
|
|
|
Config::Read cfg;
|
2024-02-04 01:19:44 -06:00
|
|
|
fuse_context const *fc = fuse_get_context();
|
|
|
|
ugid::Set const ugid(fc->uid,fc->gid);
|
|
|
|
|
2024-02-04 21:41:34 -06:00
|
|
|
utils::cfg_to_ffi_flags(cfg,fc->pid,ffi_);
|
2024-02-04 21:42:10 -06:00
|
|
|
if(cfg->writeback_cache)
|
|
|
|
utils::tweak_flags_writeback_cache(&ffi_->flags);
|
2024-02-04 21:42:31 -06:00
|
|
|
ffi_->noflush = !utils::calculate_flush(cfg->flushonclose,ffi_->flags);
|
2024-02-04 21:41:34 -06:00
|
|
|
|
2024-02-04 01:19:44 -06:00
|
|
|
rv = l::create(branches_,fusepath_,mode_,fc->umask,ffi_);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|