mirror of https://github.com/trapexit/mergerfs.git
trapexit
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 1826 additions and 440 deletions
-
2LICENSE
-
1libfuse/Makefile
-
34libfuse/include/fuse.h
-
24libfuse/include/fuse_attr.h
-
3libfuse/include/fuse_common.h
-
9libfuse/include/fuse_compat.h
-
31libfuse/include/fuse_dirent.h
-
31libfuse/include/fuse_direntplus.h
-
80libfuse/include/fuse_dirents.h
-
14libfuse/include/fuse_entry.h
-
38libfuse/include/fuse_lowlevel.h
-
17libfuse/include/stat_utils.h
-
364libfuse/lib/fuse.c
-
429libfuse/lib/fuse_dirents.c
-
2libfuse/lib/fuse_loop.c
-
2libfuse/lib/fuse_loop_mt.c
-
45libfuse/lib/fuse_lowlevel.c
-
1src/config.cpp
-
1src/config.hpp
-
87src/fixed_mem_pool.hpp
-
53src/fs_base_fstatat.hpp
-
8src/fs_base_open.hpp
-
18src/fs_inode.hpp
-
2src/fuse_getxattr.cpp
-
2src/fuse_init.cpp
-
1src/fuse_listxattr.cpp
-
111src/fuse_readdir.cpp
-
13src/fuse_readdir.hpp
-
161src/fuse_readdir_linux.icpp
-
23src/fuse_readdir_plus.cpp
-
30src/fuse_readdir_plus.hpp
-
172src/fuse_readdir_plus_linux.icpp
-
125src/fuse_readdir_plus_posix.icpp
-
111src/fuse_readdir_posix.icpp
-
5src/hashset.hpp
-
69src/locked_fixed_mem_pool.hpp
-
21src/mempools.cpp
-
23src/mempools.hpp
-
3src/mergerfs.cpp
-
4src/option_parser.cpp
@ -0,0 +1,24 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <stdint.h> |
||||
|
|
||||
|
typedef struct fuse_attr_s fuse_attr_t; |
||||
|
struct fuse_attr_s |
||||
|
{ |
||||
|
uint64_t ino; |
||||
|
uint64_t size; |
||||
|
uint64_t blocks; |
||||
|
uint64_t atime; |
||||
|
uint64_t mtime; |
||||
|
uint64_t ctime; |
||||
|
uint32_t atimensec; |
||||
|
uint32_t mtimensec; |
||||
|
uint32_t ctimensec; |
||||
|
uint32_t mode; |
||||
|
uint32_t nlink; |
||||
|
uint32_t uid; |
||||
|
uint32_t gid; |
||||
|
uint32_t rdev; |
||||
|
uint32_t blksize; |
||||
|
uint32_t _padding; |
||||
|
}; |
@ -0,0 +1,31 @@ |
|||||
|
/* |
||||
|
ISC License |
||||
|
|
||||
|
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. |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <stdint.h> |
||||
|
|
||||
|
typedef struct fuse_dirent_s fuse_dirent_t; |
||||
|
struct fuse_dirent_s |
||||
|
{ |
||||
|
uint64_t ino; |
||||
|
uint64_t off; |
||||
|
uint32_t namelen; |
||||
|
uint32_t type; |
||||
|
char name[]; |
||||
|
}; |
@ -0,0 +1,31 @@ |
|||||
|
/* |
||||
|
ISC License |
||||
|
|
||||
|
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. |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include "fuse_attr.h" |
||||
|
#include "fuse_dirent.h" |
||||
|
#include "fuse_entry.h" |
||||
|
|
||||
|
typedef struct fuse_direntplus_s fuse_direntplus_t; |
||||
|
struct fuse_direntplus_s |
||||
|
{ |
||||
|
fuse_entry_t entry; |
||||
|
fuse_attr_t attr; |
||||
|
fuse_dirent_t dirent; |
||||
|
}; |
@ -0,0 +1,80 @@ |
|||||
|
/* |
||||
|
ISC License |
||||
|
|
||||
|
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. |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
#include "fuse_dirent.h" |
||||
|
#include "fuse_direntplus.h" |
||||
|
#include "fuse_entry.h" |
||||
|
|
||||
|
#include <dirent.h> |
||||
|
#include <stdint.h> |
||||
|
#include <stdio.h> |
||||
|
#include <sys/stat.h> |
||||
|
#include <sys/types.h> |
||||
|
#include <unistd.h> |
||||
|
|
||||
|
enum fuse_dirents_type_e |
||||
|
{ |
||||
|
UNSET = 0, |
||||
|
NORMAL, |
||||
|
PLUS |
||||
|
}; |
||||
|
typedef enum fuse_dirents_type_e fuse_dirents_type_t; |
||||
|
|
||||
|
typedef struct fuse_dirents_s fuse_dirents_t; |
||||
|
struct fuse_dirents_s |
||||
|
{ |
||||
|
char *buf; |
||||
|
uint64_t buf_len; |
||||
|
uint64_t data_len; |
||||
|
fuse_dirents_type_t type; |
||||
|
}; |
||||
|
|
||||
|
int fuse_dirents_init(fuse_dirents_t *d); |
||||
|
void fuse_dirents_free(fuse_dirents_t *d); |
||||
|
void fuse_dirents_reset(fuse_dirents_t *d); |
||||
|
|
||||
|
int fuse_dirents_add(fuse_dirents_t *d, |
||||
|
const struct dirent *de); |
||||
|
int fuse_dirents_add_plus(fuse_dirents_t *d, |
||||
|
const struct dirent *de, |
||||
|
const fuse_entry_t *entry, |
||||
|
const struct stat *st); |
||||
|
#ifdef __linux__ |
||||
|
struct linux_dirent64; |
||||
|
int fuse_dirents_add_linux(fuse_dirents_t *d, |
||||
|
const struct linux_dirent64 *de); |
||||
|
int fuse_dirents_add_linux_plus(fuse_dirents_t *d, |
||||
|
const struct linux_dirent64 *de, |
||||
|
const fuse_entry_t *entry, |
||||
|
const struct stat *st); |
||||
|
#endif |
||||
|
|
||||
|
void *fuse_dirents_find(fuse_dirents_t *d, |
||||
|
const uint64_t ino); |
||||
|
|
||||
|
int fuse_dirents_convert_plus2normal(fuse_dirents_t *d); |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
} |
||||
|
#endif |
@ -0,0 +1,14 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <stdint.h> |
||||
|
|
||||
|
typedef struct fuse_entry_s fuse_entry_t; |
||||
|
struct fuse_entry_s |
||||
|
{ |
||||
|
uint64_t nodeid; |
||||
|
uint64_t generation; |
||||
|
uint64_t entry_valid; |
||||
|
uint64_t attr_valid; |
||||
|
uint32_t entry_valid_nsec; |
||||
|
uint32_t attr_valid_nsec; |
||||
|
}; |
@ -0,0 +1,17 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "config.h" |
||||
|
|
||||
|
#ifdef HAVE_STRUCT_STAT_ST_ATIM |
||||
|
#define ST_ATIM_NSEC(ST) ((ST)->st_atim.tv_nsec) |
||||
|
#define ST_CTIM_NSEC(ST) ((ST)->st_ctim.tv_nsec) |
||||
|
#define ST_MTIM_NSEC(ST) ((ST)->st_mtim.tv_nsec) |
||||
|
#elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC |
||||
|
#define ST_ATIM_NSEC(ST) ((ST)->st_atimespec.tv_nsec) |
||||
|
#define ST_CTIM_NSEC(ST) ((ST)->st_ctimespec.tv_nsec) |
||||
|
#define ST_MTIM_NSEC(ST) ((ST)->st_mtimespec.tv_nsec) |
||||
|
#else |
||||
|
#define ST_ATIM_NSEC(ST) 0 |
||||
|
#define ST_CTIM_NSEC(ST) 0 |
||||
|
#define ST_MTIM_NSEC(ST) 0 |
||||
|
#endif |
@ -0,0 +1,429 @@ |
|||||
|
#define _FILE_OFFSET_BITS 64 |
||||
|
|
||||
|
#include "fuse_attr.h" |
||||
|
#include "fuse_dirent.h" |
||||
|
#include "fuse_direntplus.h" |
||||
|
#include "fuse_dirents.h" |
||||
|
#include "fuse_entry.h" |
||||
|
#include "stat_utils.h" |
||||
|
|
||||
|
#include <dirent.h> |
||||
|
#include <errno.h> |
||||
|
#include <stddef.h> |
||||
|
#include <stdint.h> |
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
|
||||
|
#define DEFAULT_SIZE (1024 * 16) |
||||
|
|
||||
|
static |
||||
|
uint64_t |
||||
|
align_uint64_t(uint64_t v_) |
||||
|
{ |
||||
|
return ((v_ + sizeof(uint64_t) - 1) & ~(sizeof(uint64_t) - 1)); |
||||
|
} |
||||
|
|
||||
|
static |
||||
|
uint64_t |
||||
|
fuse_dirent_size(const uint64_t namelen_) |
||||
|
{ |
||||
|
uint64_t rv; |
||||
|
|
||||
|
rv = offsetof(fuse_dirent_t,name); |
||||
|
rv += namelen_; |
||||
|
rv = align_uint64_t(rv); |
||||
|
|
||||
|
return rv; |
||||
|
} |
||||
|
|
||||
|
static |
||||
|
uint64_t |
||||
|
fuse_direntplus_size(const uint64_t namelen_) |
||||
|
{ |
||||
|
uint64_t rv; |
||||
|
|
||||
|
rv = offsetof(fuse_direntplus_t,dirent.name); |
||||
|
rv += namelen_; |
||||
|
rv = align_uint64_t(rv); |
||||
|
|
||||
|
return rv; |
||||
|
} |
||||
|
|
||||
|
static |
||||
|
int |
||||
|
fuse_dirents_resize(fuse_dirents_t *d_, |
||||
|
uint64_t size_) |
||||
|
{ |
||||
|
void *p; |
||||
|
|
||||
|
if((d_->data_len + size_) >= d_->buf_len) |
||||
|
{ |
||||
|
p = realloc(d_->buf,(d_->buf_len * 2)); |
||||
|
if(p == NULL) |
||||
|
return -errno; |
||||
|
|
||||
|
d_->buf = p; |
||||
|
d_->buf_len *= 2; |
||||
|
} |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
static |
||||
|
void* |
||||
|
fuse_dirents_alloc(fuse_dirents_t *d_, |
||||
|
uint64_t size_) |
||||
|
{ |
||||
|
int rv; |
||||
|
fuse_dirent_t *d; |
||||
|
|
||||
|
rv = fuse_dirents_resize(d_,size_); |
||||
|
if(rv) |
||||
|
return NULL; |
||||
|
|
||||
|
d = (fuse_dirent_t*)&d_->buf[d_->data_len]; |
||||
|
|
||||
|
d_->data_len += size_; |
||||
|
|
||||
|
return d; |
||||
|
} |
||||
|
|
||||
|
static |
||||
|
void |
||||
|
fuse_dirents_fill_attr(fuse_attr_t *attr_, |
||||
|
const struct stat *st_) |
||||
|
{ |
||||
|
attr_->ino = st_->st_ino; |
||||
|
attr_->size = st_->st_size; |
||||
|
attr_->blocks = st_->st_blocks; |
||||
|
attr_->atime = st_->st_atime; |
||||
|
attr_->mtime = st_->st_mtime; |
||||
|
attr_->ctime = st_->st_ctime; |
||||
|
attr_->atimensec = ST_ATIM_NSEC(st_); |
||||
|
attr_->mtimensec = ST_MTIM_NSEC(st_); |
||||
|
attr_->ctimensec = ST_CTIM_NSEC(st_); |
||||
|
attr_->mode = st_->st_mode; |
||||
|
attr_->nlink = st_->st_nlink; |
||||
|
attr_->uid = st_->st_uid; |
||||
|
attr_->gid = st_->st_gid; |
||||
|
attr_->rdev = st_->st_rdev; |
||||
|
attr_->blksize = st_->st_blksize; |
||||
|
} |
||||
|
|
||||
|
fuse_dirent_t* |
||||
|
fuse_dirent_next(fuse_dirent_t *cur_) |
||||
|
{ |
||||
|
char *buf; |
||||
|
|
||||
|
buf = (char*)cur_; |
||||
|
buf += fuse_dirent_size(cur_->namelen); |
||||
|
|
||||
|
return (fuse_dirent_t*)buf; |
||||
|
} |
||||
|
|
||||
|
fuse_direntplus_t* |
||||
|
fuse_direntplus_next(fuse_direntplus_t *cur_) |
||||
|
{ |
||||
|
char *buf; |
||||
|
|
||||
|
buf = (char*)cur_; |
||||
|
buf += fuse_direntplus_size(cur_->dirent.namelen); |
||||
|
|
||||
|
return (fuse_direntplus_t*)buf; |
||||
|
} |
||||
|
|
||||
|
fuse_dirent_t* |
||||
|
fuse_dirent_find(fuse_dirents_t *d_, |
||||
|
const uint64_t ino_) |
||||
|
{ |
||||
|
fuse_dirent_t *cur; |
||||
|
fuse_dirent_t *end; |
||||
|
|
||||
|
if(d_->type != NORMAL) |
||||
|
return NULL; |
||||
|
|
||||
|
cur = (fuse_dirent_t*)&d_->buf[0]; |
||||
|
end = (fuse_dirent_t*)&d_->buf[d_->data_len]; |
||||
|
while(cur < end) |
||||
|
{ |
||||
|
if(cur->ino == ino_) |
||||
|
return cur; |
||||
|
|
||||
|
cur = fuse_dirent_next(cur); |
||||
|
} |
||||
|
|
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
fuse_direntplus_t* |
||||
|
fuse_direntplus_find(fuse_dirents_t *d_, |
||||
|
const uint64_t ino_) |
||||
|
{ |
||||
|
fuse_direntplus_t *cur; |
||||
|
fuse_direntplus_t *end; |
||||
|
|
||||
|
if(d_->type != PLUS) |
||||
|
return NULL; |
||||
|
|
||||
|
cur = (fuse_direntplus_t*)&d_->buf[0]; |
||||
|
end = (fuse_direntplus_t*)&d_->buf[d_->data_len]; |
||||
|
while(cur < end) |
||||
|
{ |
||||
|
if(cur->dirent.ino == ino_) |
||||
|
return cur; |
||||
|
|
||||
|
cur = fuse_direntplus_next(cur); |
||||
|
} |
||||
|
|
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
void* |
||||
|
fuse_dirents_find(fuse_dirents_t *d_, |
||||
|
const uint64_t ino_) |
||||
|
{ |
||||
|
switch(d_->type) |
||||
|
{ |
||||
|
default: |
||||
|
case UNSET: |
||||
|
return NULL; |
||||
|
case NORMAL: |
||||
|
return fuse_dirent_find(d_,ino_); |
||||
|
case PLUS: |
||||
|
return fuse_direntplus_find(d_,ino_); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int |
||||
|
fuse_dirents_convert_plus2normal(fuse_dirents_t *d_) |
||||
|
{ |
||||
|
int rv; |
||||
|
uint64_t size; |
||||
|
fuse_dirent_t *d; |
||||
|
fuse_dirents_t normal; |
||||
|
fuse_direntplus_t *cur; |
||||
|
fuse_direntplus_t *end; |
||||
|
|
||||
|
rv = fuse_dirents_init(&normal); |
||||
|
if(rv < 0) |
||||
|
return rv; |
||||
|
|
||||
|
cur = (fuse_direntplus_t*)&d_->buf[0]; |
||||
|
end = (fuse_direntplus_t*)&d_->buf[d_->data_len]; |
||||
|
while(cur < end) |
||||
|
{ |
||||
|
size = fuse_dirent_size(cur->dirent.namelen); |
||||
|
d = fuse_dirents_alloc(&normal,size); |
||||
|
if(d == NULL) |
||||
|
return -ENOMEM; |
||||
|
|
||||
|
memcpy(d,&cur->dirent,size); |
||||
|
d->off = normal.data_len;; |
||||
|
|
||||
|
cur = fuse_direntplus_next(cur); |
||||
|
} |
||||
|
|
||||
|
fuse_dirents_free(d_); |
||||
|
|
||||
|
normal.type = NORMAL; |
||||
|
*d_ = normal; |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
int |
||||
|
fuse_dirents_add(fuse_dirents_t *d_, |
||||
|
const struct dirent *dirent_) |
||||
|
{ |
||||
|
uint64_t size; |
||||
|
uint64_t namelen; |
||||
|
fuse_dirent_t *d; |
||||
|
|
||||
|
switch(d_->type) |
||||
|
{ |
||||
|
case UNSET: |
||||
|
d_->type = NORMAL; |
||||
|
break; |
||||
|
case NORMAL: |
||||
|
break; |
||||
|
case PLUS: |
||||
|
return -EINVAL; |
||||
|
} |
||||
|
|
||||
|
namelen = _D_ALLOC_NAMLEN(dirent_); |
||||
|
size = fuse_dirent_size(namelen); |
||||
|
|
||||
|
d = fuse_dirents_alloc(d_,size); |
||||
|
if(d == NULL) |
||||
|
return -ENOMEM; |
||||
|
|
||||
|
d->ino = dirent_->d_ino; |
||||
|
d->off = d_->data_len; |
||||
|
d->namelen = namelen; |
||||
|
d->type = dirent_->d_type; |
||||
|
memcpy(d->name,dirent_->d_name,namelen); |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
int |
||||
|
fuse_dirents_add_plus(fuse_dirents_t *d_, |
||||
|
const struct dirent *dirent_, |
||||
|
const fuse_entry_t *entry_, |
||||
|
const struct stat *st_) |
||||
|
{ |
||||
|
uint64_t size; |
||||
|
uint64_t namelen; |
||||
|
fuse_direntplus_t *d; |
||||
|
|
||||
|
switch(d_->type) |
||||
|
{ |
||||
|
case UNSET: |
||||
|
d_->type = PLUS; |
||||
|
break; |
||||
|
case NORMAL: |
||||
|
return -EINVAL; |
||||
|
case PLUS: |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
namelen = _D_ALLOC_NAMLEN(dirent_); |
||||
|
size = fuse_direntplus_size(namelen); |
||||
|
|
||||
|
d = fuse_dirents_alloc(d_,size); |
||||
|
if(d == NULL) |
||||
|
return -ENOMEM; |
||||
|
|
||||
|
d->dirent.ino = dirent_->d_ino; |
||||
|
d->dirent.off = d_->data_len; |
||||
|
d->dirent.namelen = namelen; |
||||
|
d->dirent.type = dirent_->d_type; |
||||
|
memcpy(d->dirent.name,dirent_->d_name,namelen); |
||||
|
|
||||
|
d->entry = *entry_; |
||||
|
|
||||
|
fuse_dirents_fill_attr(&d->attr,st_); |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
#ifdef __linux__ |
||||
|
struct linux_dirent64 |
||||
|
{ |
||||
|
uint64_t d_ino; |
||||
|
int64_t d_off; |
||||
|
uint16_t d_reclen; |
||||
|
uint8_t d_type; |
||||
|
char d_name[]; |
||||
|
}; |
||||
|
|
||||
|
int |
||||
|
fuse_dirents_add_linux(fuse_dirents_t *d_, |
||||
|
const struct linux_dirent64 *dirent_) |
||||
|
{ |
||||
|
uint64_t size; |
||||
|
uint64_t namelen; |
||||
|
fuse_dirent_t *d; |
||||
|
|
||||
|
switch(d_->type) |
||||
|
{ |
||||
|
case UNSET: |
||||
|
d_->type = NORMAL; |
||||
|
break; |
||||
|
case NORMAL: |
||||
|
break; |
||||
|
case PLUS: |
||||
|
return -EINVAL; |
||||
|
} |
||||
|
|
||||
|
namelen = (dirent_->d_reclen - offsetof(struct linux_dirent64,d_name)); |
||||
|
size = fuse_dirent_size(namelen); |
||||
|
|
||||
|
d = fuse_dirents_alloc(d_,size); |
||||
|
if(d == NULL) |
||||
|
return -ENOMEM; |
||||
|
|
||||
|
d->ino = dirent_->d_ino; |
||||
|
d->off = d_->data_len; |
||||
|
d->namelen = namelen; |
||||
|
d->type = dirent_->d_type; |
||||
|
memcpy(d->name,dirent_->d_name,namelen); |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
int |
||||
|
fuse_dirents_add_linux_plus(fuse_dirents_t *d_, |
||||
|
const struct linux_dirent64 *dirent_, |
||||
|
const fuse_entry_t *entry_, |
||||
|
const struct stat *st_) |
||||
|
{ |
||||
|
uint64_t size; |
||||
|
uint64_t namelen; |
||||
|
fuse_direntplus_t *d; |
||||
|
|
||||
|
switch(d_->type) |
||||
|
{ |
||||
|
case UNSET: |
||||
|
d_->type = PLUS; |
||||
|
break; |
||||
|
case NORMAL: |
||||
|
return -EINVAL; |
||||
|
case PLUS: |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
namelen = (dirent_->d_reclen - offsetof(struct linux_dirent64,d_name)); |
||||
|
size = fuse_direntplus_size(namelen); |
||||
|
|
||||
|
d = fuse_dirents_alloc(d_,size); |
||||
|
if(d == NULL) |
||||
|
return -ENOMEM; |
||||
|
|
||||
|
d->dirent.ino = dirent_->d_ino; |
||||
|
d->dirent.off = d_->data_len; |
||||
|
d->dirent.namelen = namelen; |
||||
|
d->dirent.type = dirent_->d_type; |
||||
|
memcpy(d->dirent.name,dirent_->d_name,namelen); |
||||
|
|
||||
|
d->entry = *entry_; |
||||
|
|
||||
|
fuse_dirents_fill_attr(&d->attr,st_); |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
void |
||||
|
fuse_dirents_reset(fuse_dirents_t *d_) |
||||
|
{ |
||||
|
d_->data_len = 0; |
||||
|
d_->type = UNSET; |
||||
|
} |
||||
|
|
||||
|
int |
||||
|
fuse_dirents_init(fuse_dirents_t *d_) |
||||
|
{ |
||||
|
void *buf; |
||||
|
|
||||
|
buf = calloc(DEFAULT_SIZE,1); |
||||
|
if(buf == NULL) |
||||
|
return -ENOMEM; |
||||
|
|
||||
|
d_->buf = buf; |
||||
|
d_->buf_len = DEFAULT_SIZE; |
||||
|
d_->data_len = 0; |
||||
|
d_->type = UNSET; |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
void |
||||
|
fuse_dirents_free(fuse_dirents_t *d_) |
||||
|
{ |
||||
|
d_->buf_len = 0; |
||||
|
d_->data_len = 0; |
||||
|
d_->type = UNSET; |
||||
|
free(d_->buf); |
||||
|
} |
@ -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,53 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
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. |
||||
|
*/ |
||||
|
|
||||
|
#include <sys/types.h>
|
||||
|
#include <sys/stat.h>
|
||||
|
#include <unistd.h>
|
||||
|
#include <fcntl.h>
|
||||
|
#include <sys/stat.h>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
static |
||||
|
inline |
||||
|
int |
||||
|
fstatat(const int dirfd, |
||||
|
const char *pathname, |
||||
|
struct stat *statbuf, |
||||
|
const int flags) |
||||
|
{ |
||||
|
return ::fstatat(dirfd, |
||||
|
pathname, |
||||
|
statbuf, |
||||
|
flags); |
||||
|
} |
||||
|
|
||||
|
static |
||||
|
inline |
||||
|
int |
||||
|
fstatat_nofollow(const int dirfd, |
||||
|
const char *pathname, |
||||
|
struct stat *statbuf) |
||||
|
{ |
||||
|
return fs::fstatat(dirfd, |
||||
|
pathname, |
||||
|
statbuf, |
||||
|
AT_SYMLINK_NOFOLLOW); |
||||
|
} |
||||
|
} |
@ -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,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. |
||||
|
*/ |
||||
|
|
||||
|
#ifdef __linux__
|
||||
|
# include "fuse_readdir_plus_linux.icpp"
|
||||
|
#else
|
||||
|
# include "fuse_readdir_plus_posix.icpp"
|
||||
|
#endif
|
@ -0,0 +1,30 @@ |
|||||
|
/*
|
||||
|
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. |
||||
|
*/ |
||||
|
|
||||
|
#pragma once
|
||||
|
|
||||
|
#include <fuse.h>
|
||||
|
|
||||
|
#include <sys/types.h>
|
||||
|
#include <sys/stat.h>
|
||||
|
#include <unistd.h>
|
||||
|
|
||||
|
namespace FUSE |
||||
|
{ |
||||
|
int |
||||
|
readdir_plus(fuse_file_info *ffi_, |
||||
|
fuse_dirents_t *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