mirror of https://github.com/trapexit/mergerfs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.8 KiB
79 lines
1.8 KiB
#pragma message "using getdents"
|
|
|
|
#include "dirinfo.hpp"
|
|
#include "fs_close.hpp"
|
|
#include "fs_getdents64.hpp"
|
|
#include "fs_inode.hpp"
|
|
#include "fs_open.hpp"
|
|
#include "hashset.hpp"
|
|
#include "scope_guard.hpp"
|
|
|
|
#include "fuse_dirents.hpp"
|
|
#include "fuse_msgbuf.hpp"
|
|
|
|
|
|
static
|
|
int
|
|
_readdir(const Branches::Ptr &branches_,
|
|
const fs::path &rel_dirpath_,
|
|
fuse_dirents_t *dirents_)
|
|
{
|
|
HashSet names;
|
|
fs::path rel_filepath;
|
|
fs::path abs_dirpath;
|
|
fuse_msgbuf_t *buf;
|
|
|
|
fuse_dirents_reset(dirents_);
|
|
|
|
buf = msgbuf_alloc();
|
|
DEFER { msgbuf_free(buf); };
|
|
|
|
rel_filepath = rel_dirpath_ / "dummy";
|
|
for(const auto &branch : *branches_)
|
|
{
|
|
int rv;
|
|
int fd;
|
|
|
|
abs_dirpath = branch.path / rel_dirpath_;
|
|
|
|
fd = fs::open_dir_ro(abs_dirpath);
|
|
if(fd < 0)
|
|
continue;
|
|
DEFER{ fs::close(fd); };
|
|
|
|
rv = 0;
|
|
while(true)
|
|
{
|
|
ssize_t nread;
|
|
|
|
nread = fs::getdents64(fd,buf->mem,buf->size);
|
|
if(nread <= 0)
|
|
break;
|
|
|
|
for(ssize_t pos = 0; pos < nread;)
|
|
{
|
|
int namelen;
|
|
fs::dirent64 *d = reinterpret_cast<fs::dirent64*>(&buf->mem[pos]);
|
|
|
|
pos += d->d_reclen;
|
|
|
|
namelen = d->d_namelen();
|
|
rv = names.put(d->d_name,namelen);
|
|
if(rv == 0)
|
|
continue;
|
|
|
|
rel_filepath.replace_filename(d->d_name);
|
|
d->d_ino = fs::inode::calc(branch.path,
|
|
rel_filepath,
|
|
DTTOIF(d->d_type),
|
|
d->d_ino);
|
|
|
|
rv = fuse_dirents_add(dirents_,d,namelen);
|
|
if(rv)
|
|
return -ENOMEM;
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|