mirror of https://github.com/trapexit/mergerfs.git
Browse Source
restructure readdir, add readdir_plus
restructure readdir, add readdir_plus
Does not enable READDIR_AUTO. Might add in the future.pull/720/head
Antonio SJ Musumeci
6 years ago
29 changed files with 1078 additions and 361 deletions
-
2LICENSE
-
1libfuse/Makefile
-
34libfuse/include/fuse.h
-
24libfuse/include/fuse_attr.h
-
37libfuse/include/fuse_common.h
-
9libfuse/include/fuse_compat.h
-
31libfuse/include/fuse_dirent.h
-
31libfuse/include/fuse_direntplus.h
-
71libfuse/include/fuse_dirents.h
-
14libfuse/include/fuse_entry.h
-
38libfuse/include/fuse_lowlevel.h
-
17libfuse/include/stat_utils.h
-
420libfuse/lib/fuse.c
-
346libfuse/lib/fuse_dirents.c
-
2libfuse/lib/fuse_loop.c
-
2libfuse/lib/fuse_loop_mt.c
-
51libfuse/lib/fuse_lowlevel.c
-
1src/config.cpp
-
1src/config.hpp
-
53src/fs_base_fstatat.hpp
-
18src/fs_inode.hpp
-
2src/fuse_init.cpp
-
41src/fuse_readdir.cpp
-
13src/fuse_readdir.hpp
-
138src/fuse_readdir_plus.cpp
-
30src/fuse_readdir_plus.hpp
-
5src/hashset.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,71 @@ |
|||
/* |
|||
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, |
|||
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); |
|||
|
|||
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,346 @@ |
|||
#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) |
|||
|
|||
#ifndef _D_EXACT_NAMLEN |
|||
# define _D_EXACT_NAMLEN(d) ((d)->d_namlen) |
|||
#endif |
|||
|
|||
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_, |
|||
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_EXACT_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_EXACT_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; |
|||
} |
|||
|
|||
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,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,138 @@ |
|||
/*
|
|||
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; |
|||
|
|||
#define NO_OFFSET 0
|
|||
|
|||
|
|||
static |
|||
int |
|||
dot_or_dotdot(const char *s_) |
|||
{ |
|||
return ((s_[0] == '.') && |
|||
((s_[1] == '\0') || |
|||
((s_[1] == '.') && (s_[2] == '\0')))); |
|||
} |
|||
|
|||
|
|||
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 = fs::inode::recompute(st.st_ino,dev); |
|||
|
|||
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,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_); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue