mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-20 23:16:27 -05:00
Some checks are pending
mkdocs / deploy (push) Waiting to run
Run in an elevated credential mode (root) and let the kernel manage entitlements. Will result in slightly different behavior but should not be noticed by most.
122 lines
2.5 KiB
Text
122 lines
2.5 KiB
Text
#pragma message "using getdents"
|
|
|
|
#include "fs_inode.hpp"
|
|
#include "fs_getdents64.hpp"
|
|
#include "hashset.hpp"
|
|
#include "branches.hpp"
|
|
#include "error.hpp"
|
|
#include "fs_close.hpp"
|
|
#include "fs_open.hpp"
|
|
#include "fs_path.hpp"
|
|
#include "ugid.hpp"
|
|
#include "scope_guard.hpp"
|
|
|
|
#include "fuse_msgbuf.hpp"
|
|
#include "fuse_dirents.hpp"
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
struct DirRV
|
|
{
|
|
const fs::path *branch_path;
|
|
int fd;
|
|
};
|
|
|
|
static
|
|
inline
|
|
std::vector<std::future<DirRV>>
|
|
_opendir(ThreadPool &tp_,
|
|
const Branches::Ptr &branches_,
|
|
const fs::path &rel_dirpath_)
|
|
{
|
|
std::vector<std::future<DirRV>> futures;
|
|
|
|
futures.reserve(branches_->size());
|
|
|
|
for(const auto &branch : *branches_)
|
|
{
|
|
auto func =
|
|
[&branch,&rel_dirpath_]()
|
|
{
|
|
int fd;
|
|
fs::path abs_dirpath;
|
|
|
|
abs_dirpath = branch.path / rel_dirpath_;
|
|
|
|
fd = fs::open_dir_ro(abs_dirpath);
|
|
|
|
return DirRV{&branch.path,fd};
|
|
};
|
|
|
|
auto rv = tp_.enqueue_task(std::move(func));
|
|
|
|
futures.emplace_back(std::move(rv));
|
|
}
|
|
|
|
return futures;
|
|
}
|
|
|
|
static
|
|
inline
|
|
int
|
|
_readdir(std::vector<std::future<DirRV>> &dh_futures_,
|
|
const fs::path &rel_dirpath_,
|
|
fuse_dirents_t *dirents_)
|
|
{
|
|
Err err;
|
|
HashSet names;
|
|
fs::path rel_filepath;
|
|
fuse_msgbuf_t *buf;
|
|
|
|
buf = msgbuf_alloc();
|
|
DEFER { msgbuf_free(buf); };
|
|
|
|
rel_filepath = rel_dirpath_ / "dummy";
|
|
for(auto &dh_future : dh_futures_)
|
|
{
|
|
DirRV dirrv;
|
|
|
|
dirrv = dh_future.get();
|
|
|
|
err = dirrv.fd;
|
|
if(dirrv.fd < 0)
|
|
continue;
|
|
DEFER { fs::close(dirrv.fd); };
|
|
|
|
while(true)
|
|
{
|
|
ssize_t nread;
|
|
|
|
nread = fs::getdents64(dirrv.fd,buf->mem,buf->size);
|
|
if(nread <= 0)
|
|
break;
|
|
|
|
for(ssize_t pos = 0; pos < nread;)
|
|
{
|
|
int rv;
|
|
int namelen;
|
|
fs::dirent64 *d = reinterpret_cast<fs::dirent64*>(&buf->mem[pos]);
|
|
|
|
pos += d->reclen;
|
|
|
|
namelen = d->namelen();
|
|
|
|
rv = names.put(d->name,namelen);
|
|
if(rv == 0)
|
|
continue;
|
|
|
|
rel_filepath.replace_filename(d->name);
|
|
|
|
d->ino = fs::inode::calc(*dirrv.branch_path,
|
|
rel_filepath,
|
|
DTTOIF(d->type),
|
|
d->ino);
|
|
|
|
fuse_dirents_add(dirents_,d,namelen);
|
|
}
|
|
}
|
|
}
|
|
|
|
return err;
|
|
}
|