support setting of inodes (using use_ino option)

creates a 64bit inode value from the underlying device value + original inode

final_ino = orig_ino | (dev << 32)

not perfect but given few filesystems use 64bit inodes nor is st_dev more than 16bit usually it should be fine
This commit is contained in:
Antonio SJ Musumeci 2016-12-11 18:27:52 -05:00
parent 365e153ae7
commit c8fa51c81a
6 changed files with 101 additions and 25 deletions

View file

@ -19,6 +19,7 @@
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_base_stat.hpp"
#include "fs_inode.hpp"
static
int
@ -28,8 +29,12 @@ _fgetattr(const int fd,
int rv;
rv = fs::fstat(fd,st);
if(rv == -1)
return -errno;
return ((rv == -1) ? -errno : 0);
fs::inode::recompute(st);
return 0;
}
namespace mergerfs
@ -43,8 +48,7 @@ namespace mergerfs
{
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _fgetattr(fi->fd,
*st);
return _fgetattr(fi->fd,*st);
}
}
}

42
src/fs_inode.hpp Normal file
View file

@ -0,0 +1,42 @@
/*
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_INODE_HPP__
#define __FS_INODE_HPP__
#include <sys/stat.h>
namespace fs
{
namespace inode
{
enum
{
MAGIC = 0x7472617065786974
};
inline
void
recompute(struct stat &st)
{
st.st_ino |= (st.st_dev << 32);
}
}
}
#endif

View file

@ -22,6 +22,7 @@
#include "config.hpp"
#include "errno.hpp"
#include "fs_base_stat.hpp"
#include "fs_inode.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
@ -32,25 +33,25 @@ using mergerfs::Policy;
static
int
_getattr_controlfile(struct stat &buf)
_getattr_controlfile(struct stat &st)
{
static const uid_t uid = ::getuid();
static const gid_t gid = ::getgid();
static const time_t now = ::time(NULL);
buf.st_dev = 0;
buf.st_ino = 0;
buf.st_mode = (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
buf.st_nlink = 1;
buf.st_uid = uid;
buf.st_gid = gid;
buf.st_rdev = 0;
buf.st_size = 0;
buf.st_blksize = 1024;
buf.st_blocks = 0;
buf.st_atime = now;
buf.st_mtime = now;
buf.st_ctime = now;
st.st_dev = 0;
st.st_ino = fs::inode::MAGIC;
st.st_mode = (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
st.st_nlink = 1;
st.st_uid = uid;
st.st_gid = gid;
st.st_rdev = 0;
st.st_size = 0;
st.st_blksize = 512;
st.st_blocks = 0;
st.st_atime = now;
st.st_mtime = now;
st.st_ctime = now;
return 0;
}
@ -61,7 +62,7 @@ _getattr(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const uint64_t minfreespace,
const char *fusepath,
struct stat &buf)
struct stat &st)
{
int rv;
string fullpath;
@ -73,9 +74,13 @@ _getattr(Policy::Func::Search searchFunc,
fs::path::make(basepaths[0],fusepath,fullpath);
rv = fs::lstat(fullpath,buf);
rv = fs::lstat(fullpath,st);
if(rv == -1)
return -errno;
return ((rv == -1) ? -errno : 0);
fs::inode::recompute(st);
return 0;
}
namespace mergerfs

View file

@ -27,6 +27,8 @@
#include "fs_base_closedir.hpp"
#include "fs_base_opendir.hpp"
#include "fs_base_readdir.hpp"
#include "fs_base_stat.hpp"
#include "fs_inode.hpp"
#include "fs_path.hpp"
#include "readdir.hpp"
#include "rwlock.hpp"
@ -50,6 +52,7 @@ _readdir(const vector<string> &srcmounts,
struct stat st = {0};
StrSet names;
st.st_ino = fs::inode::MAGIC;
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
{
DIR *dh;