mergerfs/src/func_mknod_ff.cpp

64 lines
1.4 KiB
C++
Raw Normal View History

2025-12-29 10:58:37 -06:00
#include "func_mknod_ff.hpp"
#include "errno.hpp"
#include "error.hpp"
#include "fs_acl.hpp"
#include "fs_clonepath.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_mknod_as.hpp"
#include "fs_path.hpp"
#include "ugid.hpp"
std::string_view
Func2::MknodFF::name() const
{
return "ff";
}
int
Func2::MknodFF::operator()(const ugid_t &ugid_,
const Branches &branches_,
const fs::path &fusepath_,
const mode_t mode_,
const mode_t umask_,
const dev_t dev_)
{
int rv;
2025-12-29 11:20:50 -06:00
fs::info_t info;
2025-12-29 18:10:30 -06:00
fs::path path;
2025-12-29 10:58:37 -06:00
2025-12-29 18:06:16 -06:00
for(const auto &dst_branch : branches_)
2025-12-29 10:58:37 -06:00
{
2025-12-29 18:06:21 -06:00
if(dst_branch.ro_or_nc())
2025-12-29 10:58:37 -06:00
continue;
2025-12-29 18:06:26 -06:00
rv = fs::info(dst_branch.path,&info);
2025-12-29 10:58:37 -06:00
if(rv < 0)
continue;
if(info.readonly)
continue;
if(info.spaceavail < branch.minfreespace())
continue;
2025-12-29 18:08:30 -06:00
dst_fullpath = dst_branch.path / fusepath_;
2025-12-29 11:24:54 -06:00
2025-12-29 11:24:08 -06:00
rv = fs::mknod_as(ugid_,fullpath,mode_,dev_);
2025-12-29 11:25:40 -06:00
if(rv == 0)
return 0;
2025-12-29 11:35:20 -06:00
if(rv != -ENOENT)
continue;
2025-12-29 18:09:57 -06:00
fullpath = fusepath_.parent_path();
2025-12-29 18:06:05 -06:00
for(const auto &src_branch : branches_)
2025-12-29 13:48:35 -06:00
{
2025-12-29 18:06:05 -06:00
rv = fs::clonepath(src_branch.path,
2025-12-29 18:06:08 -06:00
dst_branch.path,
2025-12-29 18:10:02 -06:00
fullpath);
2025-12-29 13:48:40 -06:00
if(rv == 0)
break;
2025-12-29 13:48:35 -06:00
}
2025-12-29 10:58:37 -06:00
}
2025-12-29 11:25:10 -06:00
return 0;
2025-12-29 11:12:19 -06:00
}