mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 10:51:52 -04:00
95 lines
2.4 KiB
Text
95 lines
2.4 KiB
Text
/*
|
|
ISC License
|
|
|
|
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
#pragma message "using getdents"
|
|
|
|
#include "fs_close.hpp"
|
|
#include "fs_getdents64.hpp"
|
|
#include "fs_inode.hpp"
|
|
#include "fs_open.hpp"
|
|
#include "fs_path.hpp"
|
|
#include "hashset.hpp"
|
|
|
|
#include "mutex.hpp"
|
|
#include "scope_guard/scope_guard.hpp"
|
|
|
|
#include "fuse_msgbuf.hpp"
|
|
#include "fuse_dirents.hpp"
|
|
|
|
|
|
static
|
|
inline
|
|
int
|
|
_readdir(const fs::path &branch_path_,
|
|
const fs::path &rel_dirpath_,
|
|
HashSet &names_,
|
|
fuse_dirents_t *dirents_,
|
|
mutex_t &mutex_)
|
|
{
|
|
int fd;
|
|
fuse_msgbuf_t *buf;
|
|
fs::path rel_filepath;
|
|
fs::path abs_dirpath;
|
|
|
|
abs_dirpath = branch_path_ / rel_dirpath_;
|
|
|
|
fd = fs::open_dir_ro(abs_dirpath);
|
|
if(fd < 0)
|
|
return fd;
|
|
DEFER{ fs::close(fd); };
|
|
|
|
buf = msgbuf_alloc();
|
|
DEFER{ msgbuf_free(buf); };
|
|
|
|
rel_filepath = rel_dirpath_ / "dummy";
|
|
while(true)
|
|
{
|
|
ssize_t nread;
|
|
|
|
nread = fs::getdents64(fd,buf->mem,buf->size);
|
|
if(nread <= 0)
|
|
return nread;
|
|
|
|
LockGuard lk(mutex_);
|
|
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(branch_path_,
|
|
rel_filepath,
|
|
DTTOIF(d->type),
|
|
d->ino);
|
|
|
|
fuse_dirents_add(dirents_,d,namelen);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|