mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-23 00:16:31 -05:00
fix getdent name length calculation
This commit is contained in:
parent
b5fae4b356
commit
698c4147fc
9 changed files with 101 additions and 87 deletions
|
|
@ -26,6 +26,7 @@
|
|||
#include "fs_inode.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "hashset.hpp"
|
||||
#include "linux_dirent64.h"
|
||||
#include "mempools.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
|
@ -42,15 +43,6 @@
|
|||
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
|
||||
|
|
@ -84,6 +76,7 @@ namespace l
|
|||
char *buf;
|
||||
HashSet names;
|
||||
string basepath;
|
||||
uint64_t namelen;
|
||||
struct linux_dirent64 *d;
|
||||
|
||||
buf = (char*)g_DENTS_BUF_POOL.alloc();
|
||||
|
|
@ -116,14 +109,15 @@ namespace l
|
|||
for(int64_t pos = 0; pos < nread; pos += d->d_reclen)
|
||||
{
|
||||
d = (struct linux_dirent64*)(buf + pos);
|
||||
namelen = (strlen(d->d_name) + 1);
|
||||
|
||||
rv = names.put(d->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);
|
||||
rv = fuse_dirents_add_linux(buf_,d,namelen);
|
||||
if(rv)
|
||||
return close_free_ret_enomem(dirfd,buf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include "fs_inode.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "hashset.hpp"
|
||||
#include "linux_dirent64.h"
|
||||
#include "mempools.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
|
@ -43,15 +44,6 @@
|
|||
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
|
||||
|
|
@ -84,6 +76,7 @@ namespace l
|
|||
char *buf;
|
||||
HashSet names;
|
||||
string basepath;
|
||||
uint64_t namelen;
|
||||
struct stat st;
|
||||
fuse_entry_t entry;
|
||||
struct linux_dirent64 *d;
|
||||
|
|
@ -122,8 +115,9 @@ namespace l
|
|||
for(int64_t pos = 0; pos < nread; pos += d->d_reclen)
|
||||
{
|
||||
d = (struct linux_dirent64*)(buf + pos);
|
||||
namelen = (strlen(d->d_name) + 1);
|
||||
|
||||
rv = names.put(d->d_name);
|
||||
rv = names.put(d->d_name,namelen);
|
||||
if(rv == 0)
|
||||
continue;
|
||||
|
||||
|
|
@ -134,7 +128,7 @@ namespace l
|
|||
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);
|
||||
rv = fuse_dirents_add_linux_plus(buf_,d,namelen,&entry,&st);
|
||||
if(rv)
|
||||
return close_free_ret_enomem(dirfd,buf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,26 @@ using std::vector;
|
|||
|
||||
namespace l
|
||||
{
|
||||
static
|
||||
uint64_t
|
||||
dirent_exact_namelen(const struct dirent *d_)
|
||||
{
|
||||
#ifdef _D_EXACT_NAMLEN
|
||||
return _D_EXACT_NAMLEN(d_);
|
||||
#elif defined _DIRENT_HAVE_D_NAMLEN
|
||||
return d_->d_namlen;
|
||||
#else
|
||||
return strlen(d_->d_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
uint64_t
|
||||
dirent_alloc_namelen(const struct dirent *d_)
|
||||
{
|
||||
return (dirent_exact_namelen(d_) + 1);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
readdir_plus(const Branches &branches_,
|
||||
|
|
@ -55,6 +75,7 @@ namespace l
|
|||
HashSet names;
|
||||
string basepath;
|
||||
struct stat st;
|
||||
uint64_t namelen;
|
||||
fuse_entry_t entry;
|
||||
|
||||
entry.nodeid = 0;
|
||||
|
|
@ -83,7 +104,9 @@ namespace l
|
|||
rv = 0;
|
||||
for(struct dirent *de = fs::readdir(dh); de && !rv; de = fs::readdir(dh))
|
||||
{
|
||||
rv = names.put(de->d_name);
|
||||
namelen = l::dirent_alloc_namelen(de);
|
||||
|
||||
rv = names.put(de->d_name,namelen);
|
||||
if(rv == 0)
|
||||
continue;
|
||||
|
||||
|
|
@ -94,7 +117,7 @@ namespace l
|
|||
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);
|
||||
rv = fuse_dirents_add_plus(buf_,de,namelen,&entry,&st);
|
||||
if(rv)
|
||||
return (fs::closedir(dh),-ENOMEM);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,26 @@ using std::vector;
|
|||
|
||||
namespace l
|
||||
{
|
||||
static
|
||||
uint64_t
|
||||
dirent_exact_namelen(const struct dirent *d_)
|
||||
{
|
||||
#ifdef _D_EXACT_NAMLEN
|
||||
return _D_EXACT_NAMLEN(d_);
|
||||
#elif defined _DIRENT_HAVE_D_NAMLEN
|
||||
return d_->d_namlen;
|
||||
#else
|
||||
return strlen(d_->d_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
uint64_t
|
||||
dirent_alloc_namelen(const struct dirent *d_)
|
||||
{
|
||||
return (dirent_exact_namelen(d_) + 1);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
readdir(const Branches &branches_,
|
||||
|
|
@ -53,6 +73,7 @@ namespace l
|
|||
dev_t dev;
|
||||
HashSet names;
|
||||
string basepath;
|
||||
uint64_t namelen;
|
||||
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
|
|
@ -74,13 +95,15 @@ namespace l
|
|||
rv = 0;
|
||||
for(struct dirent *de = fs::readdir(dh); de && !rv; de = fs::readdir(dh))
|
||||
{
|
||||
rv = names.put(de->d_name);
|
||||
namelen = l::dirent_alloc_namelen(de);
|
||||
|
||||
rv = names.put(de->d_name,namelen);
|
||||
if(rv == 0)
|
||||
continue;
|
||||
|
||||
de->d_ino = fs::inode::recompute(de->d_ino,dev);
|
||||
|
||||
rv = fuse_dirents_add(buf_,de);
|
||||
rv = fuse_dirents_add(buf_,de,namelen);
|
||||
if(rv)
|
||||
return (fs::closedir(dh),-ENOMEM);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue