mirror of https://github.com/trapexit/mergerfs.git
Antonio SJ Musumeci
5 years ago
15 changed files with 898 additions and 229 deletions
-
13libfuse/include/fuse_dirents.h
-
99libfuse/lib/fuse_dirents.c
-
87src/fixed_mem_pool.hpp
-
8src/fs_base_open.hpp
-
2src/fuse_getxattr.cpp
-
1src/fuse_listxattr.cpp
-
104src/fuse_readdir.cpp
-
161src/fuse_readdir_linux.icpp
-
131src/fuse_readdir_plus.cpp
-
172src/fuse_readdir_plus_linux.icpp
-
125src/fuse_readdir_plus_posix.icpp
-
111src/fuse_readdir_posix.icpp
-
69src/locked_fixed_mem_pool.hpp
-
21src/mempools.cpp
-
23src/mempools.hpp
@ -0,0 +1,87 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, 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 once
|
||||
|
|
||||
|
#include <stdlib.h>
|
||||
|
#include <stdint.h>
|
||||
|
|
||||
|
typedef struct fixed_mem_pool_t fixed_mem_pool_t; |
||||
|
struct fixed_mem_pool_t |
||||
|
{ |
||||
|
fixed_mem_pool_t *next; |
||||
|
}; |
||||
|
|
||||
|
template<uint64_t SIZE> |
||||
|
class FixedMemPool |
||||
|
{ |
||||
|
public: |
||||
|
FixedMemPool() |
||||
|
{ |
||||
|
list.next = NULL; |
||||
|
} |
||||
|
|
||||
|
~FixedMemPool() |
||||
|
{ |
||||
|
void *mem; |
||||
|
while(!empty()) |
||||
|
{ |
||||
|
mem = alloc(); |
||||
|
::free(mem); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
bool |
||||
|
empty(void) |
||||
|
{ |
||||
|
return (list.next == NULL); |
||||
|
} |
||||
|
|
||||
|
uint64_t |
||||
|
size(void) |
||||
|
{ |
||||
|
return SIZE; |
||||
|
} |
||||
|
|
||||
|
void* |
||||
|
alloc(void) |
||||
|
{ |
||||
|
void *rv; |
||||
|
|
||||
|
if(list.next == NULL) |
||||
|
return malloc(SIZE); |
||||
|
|
||||
|
rv = (void*)list.next; |
||||
|
list.next = list.next->next; |
||||
|
|
||||
|
return rv; |
||||
|
} |
||||
|
|
||||
|
void |
||||
|
free(void *mem_) |
||||
|
{ |
||||
|
fixed_mem_pool_t *next; |
||||
|
|
||||
|
next = (fixed_mem_pool_t*)mem_; |
||||
|
next->next = list.next; |
||||
|
list.next = next; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
fixed_mem_pool_t list; |
||||
|
}; |
@ -0,0 +1,161 @@ |
|||||
|
/* |
||||
|
Copyright (c) 2019, 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. |
||||
|
*/ |
||||
|
|
||||
|
#define _DEFAULT_SOURCE |
||||
|
|
||||
|
#include "config.hpp" |
||||
|
#include "dirinfo.hpp" |
||||
|
#include "errno.hpp" |
||||
|
#include "fs_base_close.hpp" |
||||
|
#include "fs_base_open.hpp" |
||||
|
#include "fs_base_stat.hpp" |
||||
|
#include "fs_devid.hpp" |
||||
|
#include "fs_inode.hpp" |
||||
|
#include "fs_path.hpp" |
||||
|
#include "hashset.hpp" |
||||
|
#include "mempools.hpp" |
||||
|
#include "rwlock.hpp" |
||||
|
#include "ugid.hpp" |
||||
|
|
||||
|
#include <fuse.h> |
||||
|
#include <fuse_dirents.h> |
||||
|
|
||||
|
#include <string> |
||||
|
#include <vector> |
||||
|
|
||||
|
#include <stddef.h> |
||||
|
#include <sys/syscall.h> |
||||
|
|
||||
|
using std::string; |
||||
|
using std::vector; |
||||
|
|
||||
|
struct linux_dirent64 |
||||
|
{ |
||||
|
uint64_t d_ino; |
||||
|
int64_t d_off; |
||||
|
uint16_t d_reclen; |
||||
|
uint8_t d_type; |
||||
|
char d_name[]; |
||||
|
}; |
||||
|
|
||||
|
namespace l |
||||
|
{ |
||||
|
static |
||||
|
inline |
||||
|
int |
||||
|
getdents64(unsigned int fd_, |
||||
|
char *dirp_, |
||||
|
unsigned int count_) |
||||
|
{ |
||||
|
return syscall(SYS_getdents64,fd_,dirp_,count_); |
||||
|
} |
||||
|
|
||||
|
static |
||||
|
int |
||||
|
close_free_ret_enomem(int fd_, |
||||
|
void *buf_) |
||||
|
{ |
||||
|
fs::close(fd_); |
||||
|
g_DENTS_BUF_POOL.free(buf_); |
||||
|
return -ENOMEM; |
||||
|
} |
||||
|
|
||||
|
static |
||||
|
int |
||||
|
readdir(const Branches &branches_, |
||||
|
const char *dirname_, |
||||
|
fuse_dirents_t *buf_) |
||||
|
{ |
||||
|
int rv; |
||||
|
dev_t dev; |
||||
|
char *buf; |
||||
|
HashSet names; |
||||
|
string basepath; |
||||
|
struct linux_dirent64 *d; |
||||
|
|
||||
|
buf = (char*)g_DENTS_BUF_POOL.alloc(); |
||||
|
if(buf == NULL) |
||||
|
return -ENOMEM; |
||||
|
|
||||
|
for(size_t i = 0, ei = branches_.size(); i != ei; i++) |
||||
|
{ |
||||
|
int dirfd; |
||||
|
int64_t nread; |
||||
|
uint64_t namelen; |
||||
|
|
||||
|
basepath = fs::path::make(&branches_[i].path,dirname_); |
||||
|
|
||||
|
dirfd = fs::open_dir_ro(basepath); |
||||
|
if(dirfd == -1) |
||||
|
continue; |
||||
|
|
||||
|
dev = fs::devid(dirfd); |
||||
|
if(dev == (dev_t)-1) |
||||
|
dev = i; |
||||
|
|
||||
|
for(;;) |
||||
|
{ |
||||
|
nread = l::getdents64(dirfd,buf,g_DENTS_BUF_POOL.size()); |
||||
|
if(nread == -1) |
||||
|
break; |
||||
|
if(nread == 0) |
||||
|
break; |
||||
|
|
||||
|
for(int64_t pos = 0; pos < nread;) |
||||
|
{ |
||||
|
d = (struct linux_dirent64*)(buf + pos); |
||||
|
namelen = (d->d_reclen - offsetof(struct linux_dirent64,d_name)); |
||||
|
|
||||
|
rv = names.put(d->d_name,namelen); |
||||
|
if(rv == 0) |
||||
|
continue; |
||||
|
|
||||
|
d->d_ino = fs::inode::recompute(d->d_ino,dev); |
||||
|
|
||||
|
rv = fuse_dirents_add_linux(buf_,d); |
||||
|
if(rv) |
||||
|
return close_free_ret_enomem(dirfd,buf); |
||||
|
|
||||
|
pos += d->d_reclen; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
fs::close(dirfd); |
||||
|
} |
||||
|
|
||||
|
g_DENTS_BUF_POOL.free(buf); |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
namespace FUSE |
||||
|
{ |
||||
|
int |
||||
|
readdir(fuse_file_info *ffi_, |
||||
|
fuse_dirents_t *buf_) |
||||
|
{ |
||||
|
DirInfo *di = reinterpret_cast<DirInfo*>(ffi_->fh); |
||||
|
const fuse_context *fc = fuse_get_context(); |
||||
|
const Config &config = Config::get(fc); |
||||
|
const ugid::Set ugid(fc->uid,fc->gid); |
||||
|
const rwlock::ReadGuard readlock(&config.branches_lock); |
||||
|
|
||||
|
return l::readdir(config.branches, |
||||
|
di->fusepath.c_str(), |
||||
|
buf_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,172 @@ |
|||||
|
/* |
||||
|
Copyright (c) 2019, 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. |
||||
|
*/ |
||||
|
|
||||
|
#define _DEFAULT_SOURCE |
||||
|
|
||||
|
#include "config.hpp" |
||||
|
#include "dirinfo.hpp" |
||||
|
#include "errno.hpp" |
||||
|
#include "fs_base_close.hpp" |
||||
|
#include "fs_base_fstatat.hpp" |
||||
|
#include "fs_base_open.hpp" |
||||
|
#include "fs_base_stat.hpp" |
||||
|
#include "fs_devid.hpp" |
||||
|
#include "fs_inode.hpp" |
||||
|
#include "fs_path.hpp" |
||||
|
#include "hashset.hpp" |
||||
|
#include "mempools.hpp" |
||||
|
#include "rwlock.hpp" |
||||
|
#include "ugid.hpp" |
||||
|
|
||||
|
#include <fuse.h> |
||||
|
#include <fuse_dirents.h> |
||||
|
|
||||
|
#include <string> |
||||
|
#include <vector> |
||||
|
|
||||
|
#include <stddef.h> |
||||
|
#include <sys/syscall.h> |
||||
|
|
||||
|
using std::string; |
||||
|
using std::vector; |
||||
|
|
||||
|
struct linux_dirent64 |
||||
|
{ |
||||
|
uint64_t d_ino; |
||||
|
int64_t d_off; |
||||
|
uint16_t d_reclen; |
||||
|
uint8_t d_type; |
||||
|
char d_name[]; |
||||
|
}; |
||||
|
|
||||
|
namespace l |
||||
|
{ |
||||
|
static |
||||
|
inline |
||||
|
int |
||||
|
getdents64(unsigned int fd_, |
||||
|
char *dirp_, |
||||
|
unsigned int count_) |
||||
|
{ |
||||
|
return syscall(SYS_getdents64,fd_,dirp_,count_); |
||||
|
} |
||||
|
|
||||
|
int |
||||
|
close_free_ret_enomem(int fd_, |
||||
|
void *buf_) |
||||
|
{ |
||||
|
fs::close(fd_); |
||||
|
g_DENTS_BUF_POOL.free(buf_); |
||||
|
return -ENOMEM; |
||||
|
} |
||||
|
|
||||
|
static |
||||
|
int |
||||
|
readdir_plus(const Branches &branches_, |
||||
|
const char *dirname_, |
||||
|
fuse_dirents_t *buf_) |
||||
|
{ |
||||
|
int rv; |
||||
|
dev_t dev; |
||||
|
char *buf; |
||||
|
HashSet names; |
||||
|
string basepath; |
||||
|
struct stat st; |
||||
|
fuse_entry_t entry; |
||||
|
struct linux_dirent64 *d; |
||||
|
|
||||
|
buf = (char*)g_DENTS_BUF_POOL.alloc(); |
||||
|
|
||||
|
entry.nodeid = 0; |
||||
|
entry.generation = 0; |
||||
|
entry.entry_valid = 1; |
||||
|
entry.attr_valid = 1; |
||||
|
entry.entry_valid_nsec = 0; |
||||
|
entry.attr_valid_nsec = 0; |
||||
|
for(size_t i = 0, ei = branches_.size(); i != ei; i++) |
||||
|
{ |
||||
|
int dirfd; |
||||
|
int64_t nread; |
||||
|
uint64_t namelen; |
||||
|
|
||||
|
basepath = fs::path::make(&branches_[i].path,dirname_); |
||||
|
|
||||
|
dirfd = fs::open_dir_ro(basepath); |
||||
|
if(dirfd == -1) |
||||
|
continue; |
||||
|
|
||||
|
dev = fs::devid(dirfd); |
||||
|
if(dev == (dev_t)-1) |
||||
|
dev = i; |
||||
|
|
||||
|
for(;;) |
||||
|
{ |
||||
|
nread = l::getdents64(dirfd,buf,g_DENTS_BUF_POOL.size()); |
||||
|
if(nread == -1) |
||||
|
break; |
||||
|
if(nread == 0) |
||||
|
break; |
||||
|
|
||||
|
for(int64_t pos = 0; pos < nread;) |
||||
|
{ |
||||
|
d = (struct linux_dirent64*)(buf + pos); |
||||
|
namelen = (d->d_reclen - offsetof(struct linux_dirent64,d_name)); |
||||
|
|
||||
|
rv = names.put(d->d_name,namelen); |
||||
|
if(rv == 0) |
||||
|
continue; |
||||
|
|
||||
|
rv = fs::fstatat_nofollow(dirfd,d->d_name,&st); |
||||
|
if(rv == -1) |
||||
|
memset(&st,0,sizeof(st)); |
||||
|
|
||||
|
d->d_ino = fs::inode::recompute(d->d_ino,dev); |
||||
|
st.st_ino = d->d_ino; |
||||
|
|
||||
|
rv = fuse_dirents_add_linux_plus(buf_,d,&entry,&st); |
||||
|
if(rv) |
||||
|
return close_free_ret_enomem(dirfd,buf); |
||||
|
|
||||
|
pos += d->d_reclen; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
fs::close(dirfd); |
||||
|
} |
||||
|
|
||||
|
g_DENTS_BUF_POOL.free(buf); |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
namespace FUSE |
||||
|
{ |
||||
|
int |
||||
|
readdir_plus(fuse_file_info *ffi_, |
||||
|
fuse_dirents_t *buf_) |
||||
|
{ |
||||
|
DirInfo *di = reinterpret_cast<DirInfo*>(ffi_->fh); |
||||
|
const fuse_context *fc = fuse_get_context(); |
||||
|
const Config &config = Config::get(fc); |
||||
|
const ugid::Set ugid(fc->uid,fc->gid); |
||||
|
const rwlock::ReadGuard readlock(&config.branches_lock); |
||||
|
|
||||
|
return l::readdir_plus(config.branches, |
||||
|
di->fusepath.c_str(), |
||||
|
buf_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,125 @@ |
|||||
|
/* |
||||
|
Copyright (c) 2019, 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. |
||||
|
*/ |
||||
|
|
||||
|
#define _DEFAULT_SOURCE |
||||
|
|
||||
|
#include "config.hpp" |
||||
|
#include "dirinfo.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_fstatat.hpp" |
||||
|
#include "fs_base_stat.hpp" |
||||
|
#include "fs_devid.hpp" |
||||
|
#include "fs_inode.hpp" |
||||
|
#include "fs_path.hpp" |
||||
|
#include "hashset.hpp" |
||||
|
#include "rwlock.hpp" |
||||
|
#include "ugid.hpp" |
||||
|
|
||||
|
#include <fuse.h> |
||||
|
#include <fuse_dirents.h> |
||||
|
|
||||
|
#include <string> |
||||
|
#include <vector> |
||||
|
|
||||
|
#include <dirent.h> |
||||
|
|
||||
|
using std::string; |
||||
|
using std::vector; |
||||
|
|
||||
|
namespace l |
||||
|
{ |
||||
|
static |
||||
|
int |
||||
|
readdir_plus(const Branches &branches_, |
||||
|
const char *dirname_, |
||||
|
fuse_dirents_t *buf_) |
||||
|
{ |
||||
|
dev_t dev; |
||||
|
HashSet names; |
||||
|
string basepath; |
||||
|
struct stat st; |
||||
|
fuse_entry_t entry; |
||||
|
|
||||
|
entry.nodeid = 0; |
||||
|
entry.generation = 0; |
||||
|
entry.entry_valid = 1; |
||||
|
entry.attr_valid = 1; |
||||
|
entry.entry_valid_nsec = 0; |
||||
|
entry.attr_valid_nsec = 0; |
||||
|
for(size_t i = 0, ei = branches_.size(); i != ei; i++) |
||||
|
{ |
||||
|
int rv; |
||||
|
int dirfd; |
||||
|
DIR *dh; |
||||
|
|
||||
|
basepath = fs::path::make(&branches_[i].path,dirname_); |
||||
|
|
||||
|
dh = fs::opendir(basepath); |
||||
|
if(!dh) |
||||
|
continue; |
||||
|
|
||||
|
dirfd = fs::dirfd(dh); |
||||
|
dev = fs::devid(dirfd); |
||||
|
if(dev == (dev_t)-1) |
||||
|
dev = i; |
||||
|
|
||||
|
rv = 0; |
||||
|
for(struct dirent *de = fs::readdir(dh); de && !rv; de = fs::readdir(dh)) |
||||
|
{ |
||||
|
rv = names.put(de->d_name,_D_EXACT_NAMLEN(de)); |
||||
|
if(rv == 0) |
||||
|
continue; |
||||
|
|
||||
|
rv = fs::fstatat_nofollow(dirfd,de->d_name,&st); |
||||
|
if(rv == -1) |
||||
|
memset(&st,0,sizeof(st)); |
||||
|
|
||||
|
de->d_ino = fs::inode::recompute(de->d_ino,dev); |
||||
|
st.st_ino = de->d_ino; |
||||
|
|
||||
|
rv = fuse_dirents_add_plus(buf_,de,&entry,&st); |
||||
|
if(rv) |
||||
|
return (fs::closedir(dh),-ENOMEM); |
||||
|
} |
||||
|
|
||||
|
fs::closedir(dh); |
||||
|
} |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
namespace FUSE |
||||
|
{ |
||||
|
int |
||||
|
readdir_plus(fuse_file_info *ffi_, |
||||
|
fuse_dirents_t *buf_) |
||||
|
{ |
||||
|
DirInfo *di = reinterpret_cast<DirInfo*>(ffi_->fh); |
||||
|
const fuse_context *fc = fuse_get_context(); |
||||
|
const Config &config = Config::get(fc); |
||||
|
const ugid::Set ugid(fc->uid,fc->gid); |
||||
|
const rwlock::ReadGuard readlock(&config.branches_lock); |
||||
|
|
||||
|
return l::readdir_plus(config.branches, |
||||
|
di->fusepath.c_str(), |
||||
|
buf_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,111 @@ |
|||||
|
/* |
||||
|
Copyright (c) 2019, 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. |
||||
|
*/ |
||||
|
|
||||
|
#define _DEFAULT_SOURCE |
||||
|
|
||||
|
#include "config.hpp" |
||||
|
#include "dirinfo.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 "hashset.hpp" |
||||
|
#include "rwlock.hpp" |
||||
|
#include "ugid.hpp" |
||||
|
|
||||
|
#include <fuse.h> |
||||
|
#include <fuse_dirents.h> |
||||
|
|
||||
|
#include <string> |
||||
|
#include <vector> |
||||
|
|
||||
|
#include <dirent.h> |
||||
|
|
||||
|
using std::string; |
||||
|
using std::vector; |
||||
|
|
||||
|
namespace l |
||||
|
{ |
||||
|
static |
||||
|
int |
||||
|
readdir(const Branches &branches_, |
||||
|
const char *dirname_, |
||||
|
fuse_dirents_t *buf_) |
||||
|
{ |
||||
|
dev_t dev; |
||||
|
HashSet names; |
||||
|
string basepath; |
||||
|
|
||||
|
for(size_t i = 0, ei = branches_.size(); i != ei; i++) |
||||
|
{ |
||||
|
int rv; |
||||
|
int dirfd; |
||||
|
DIR *dh; |
||||
|
|
||||
|
basepath = fs::path::make(&branches_[i].path,dirname_); |
||||
|
|
||||
|
dh = fs::opendir(basepath); |
||||
|
if(!dh) |
||||
|
continue; |
||||
|
|
||||
|
dirfd = fs::dirfd(dh); |
||||
|
dev = fs::devid(dirfd); |
||||
|
if(dev == (dev_t)-1) |
||||
|
dev = i; |
||||
|
|
||||
|
rv = 0; |
||||
|
for(struct dirent *de = fs::readdir(dh); de && !rv; de = fs::readdir(dh)) |
||||
|
{ |
||||
|
rv = names.put(de->d_name,_D_EXACT_NAMLEN(de)); |
||||
|
if(rv == 0) |
||||
|
continue; |
||||
|
|
||||
|
de->d_ino = fs::inode::recompute(de->d_ino,dev); |
||||
|
|
||||
|
rv = fuse_dirents_add(buf_,de); |
||||
|
if(rv) |
||||
|
return (fs::closedir(dh),-ENOMEM); |
||||
|
} |
||||
|
|
||||
|
fs::closedir(dh); |
||||
|
} |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
namespace FUSE |
||||
|
{ |
||||
|
int |
||||
|
readdir(fuse_file_info *ffi_, |
||||
|
fuse_dirents_t *buf_) |
||||
|
{ |
||||
|
DirInfo *di = reinterpret_cast<DirInfo*>(ffi_->fh); |
||||
|
const fuse_context *fc = fuse_get_context(); |
||||
|
const Config &config = Config::get(fc); |
||||
|
const ugid::Set ugid(fc->uid,fc->gid); |
||||
|
const rwlock::ReadGuard readlock(&config.branches_lock); |
||||
|
|
||||
|
return l::readdir(config.branches, |
||||
|
di->fusepath.c_str(), |
||||
|
buf_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,69 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, 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 once
|
||||
|
|
||||
|
#include "fixed_mem_pool.hpp"
|
||||
|
|
||||
|
#include <pthread.h>
|
||||
|
|
||||
|
template<size_t SIZE> |
||||
|
class LockedFixedMemPool |
||||
|
{ |
||||
|
public: |
||||
|
LockedFixedMemPool() |
||||
|
{ |
||||
|
pthread_mutex_init(&_mutex,NULL); |
||||
|
} |
||||
|
|
||||
|
~LockedFixedMemPool() |
||||
|
{ |
||||
|
pthread_mutex_destroy(&_mutex); |
||||
|
} |
||||
|
|
||||
|
public: |
||||
|
void* |
||||
|
alloc(void) |
||||
|
{ |
||||
|
void *mem; |
||||
|
|
||||
|
pthread_mutex_lock(&_mutex); |
||||
|
mem = _fmp.alloc(); |
||||
|
pthread_mutex_unlock(&_mutex); |
||||
|
|
||||
|
return mem; |
||||
|
} |
||||
|
|
||||
|
void |
||||
|
free(void *mem_) |
||||
|
{ |
||||
|
pthread_mutex_lock(&_mutex); |
||||
|
_fmp.free(mem_); |
||||
|
pthread_mutex_unlock(&_mutex); |
||||
|
} |
||||
|
|
||||
|
uint64_t |
||||
|
size(void) |
||||
|
{ |
||||
|
return _fmp.size(); |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
FixedMemPool<SIZE> _fmp; |
||||
|
pthread_mutex_t _mutex; |
||||
|
}; |
@ -0,0 +1,21 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, 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. |
||||
|
*/ |
||||
|
|
||||
|
#include "locked_fixed_mem_pool.hpp"
|
||||
|
|
||||
|
LockedFixedMemPool<128 * 1024> g_DENTS_BUF_POOL; |
@ -0,0 +1,23 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, 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 once
|
||||
|
|
||||
|
#include "locked_fixed_mem_pool.hpp"
|
||||
|
|
||||
|
extern LockedFixedMemPool<128 * 1024> g_DENTS_BUF_POOL; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue