mirror of
https://github.com/trapexit/mergerfs.git
synced 2024-11-22 13:47:03 +08:00
compute inode in readdir
This commit is contained in:
parent
ea403b4f5a
commit
67b48fcb3a
36
src/fs_base_dirfd.hpp
Normal file
36
src/fs_base_dirfd.hpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, 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.
|
||||
*/
|
||||
|
||||
#ifndef __FS_DIRFD_HPP__
|
||||
#define __FS_DIRFD_HPP__
|
||||
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
dirfd(DIR *dirp)
|
||||
{
|
||||
return ::dirfd(dirp);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
45
src/fs_devid.hpp
Normal file
45
src/fs_devid.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, 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.
|
||||
*/
|
||||
|
||||
#ifndef __FS_DEVID_HPP__
|
||||
#define __FS_DEVID_HPP__
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
dev_t
|
||||
devid(const int fd)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
|
||||
rv = ::fstat(fd,&st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return st.st_dev;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -25,9 +25,11 @@
|
|||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_closedir.hpp"
|
||||
#include "fs_base_dirfd.hpp"
|
||||
#include "fs_base_opendir.hpp"
|
||||
#include "fs_base_readdir.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_devid.hpp"
|
||||
#include "fs_inode.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "readdir.hpp"
|
||||
|
@ -48,13 +50,14 @@ _readdir(const vector<string> &srcmounts,
|
|||
void *buf,
|
||||
const fuse_fill_dir_t filler)
|
||||
{
|
||||
StrSet names;
|
||||
string basepath;
|
||||
struct stat st = {0};
|
||||
StrSet names;
|
||||
|
||||
st.st_ino = fs::inode::MAGIC;
|
||||
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
int dirfd;
|
||||
DIR *dh;
|
||||
|
||||
fs::path::make(&srcmounts[i],dirname,basepath);
|
||||
|
@ -63,18 +66,26 @@ _readdir(const vector<string> &srcmounts,
|
|||
if(!dh)
|
||||
continue;
|
||||
|
||||
for(struct dirent *de = fs::readdir(dh); de != NULL; de = fs::readdir(dh))
|
||||
{
|
||||
int rv;
|
||||
dirfd = fs::dirfd(dh);
|
||||
st.st_dev = fs::devid(dirfd);
|
||||
if(st.st_dev == (dev_t)-1)
|
||||
st.st_dev = i;
|
||||
|
||||
rv = 0;
|
||||
for(struct dirent *de = fs::readdir(dh); de && !rv; de = fs::readdir(dh))
|
||||
{
|
||||
rv = names.put(de->d_name);
|
||||
if(rv == 0)
|
||||
continue;
|
||||
|
||||
st.st_ino = de->d_ino;
|
||||
st.st_mode = DTTOIF(de->d_type);
|
||||
|
||||
fs::inode::recompute(st);
|
||||
|
||||
rv = filler(buf,de->d_name,&st,NO_OFFSET);
|
||||
if(rv)
|
||||
return -ENOMEM;
|
||||
return (fs::closedir(dh),-ENOMEM);
|
||||
}
|
||||
|
||||
fs::closedir(dh);
|
||||
|
|
Loading…
Reference in New Issue
Block a user