Skip to content

Commit

Permalink
additional readdir refactor cleanup
Browse files Browse the repository at this point in the history
Differences between readdir and getdents is minimal at best. Leaving code
for now to allow for possible expansion later.
  • Loading branch information
trapexit committed Jun 28, 2020
1 parent 4160a8e commit dbdd3e2
Show file tree
Hide file tree
Showing 28 changed files with 453 additions and 177 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
ISC License

Copyright (c) 2019, Antonio SJ Musumeci <[email protected]>
Copyright (c) 2020, Antonio SJ Musumeci <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
18 changes: 9 additions & 9 deletions libfuse/include/fuse_dirents.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C" {
#include "fuse_dirent.h"
#include "fuse_direntplus.h"
#include "fuse_entry.h"
#include "linux_dirent64.h"
#include "linux_dirent.h"

#include <dirent.h>
#include <stdint.h>
Expand Down Expand Up @@ -63,14 +63,14 @@ int fuse_dirents_add_plus(fuse_dirents_t *d,
const uint64_t namelen,
const fuse_entry_t *entry,
const struct stat *st);
int fuse_dirents_add_linux(fuse_dirents_t *d,
const struct linux_dirent64 *de,
const uint64_t namelen);
int fuse_dirents_add_linux_plus(fuse_dirents_t *d,
const struct linux_dirent64 *de,
const uint64_t namelen,
const fuse_entry_t *entry,
const struct stat *st);
int fuse_dirents_add_linux(fuse_dirents_t *d,
const struct linux_dirent *de,
const uint64_t namelen);
int fuse_dirents_add_linux_plus(fuse_dirents_t *d,
const struct linux_dirent *de,
const uint64_t namelen,
const fuse_entry_t *entry,
const struct stat *st);

void *fuse_dirents_find(fuse_dirents_t *d,
const uint64_t ino);
Expand Down
9 changes: 9 additions & 0 deletions libfuse/include/linux_dirent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

struct linux_dirent
{
unsigned long ino;
unsigned long off;
unsigned short reclen;
char name[];
};
12 changes: 0 additions & 12 deletions libfuse/include/linux_dirent64.h

This file was deleted.

33 changes: 17 additions & 16 deletions libfuse/lib/fuse_dirents.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "fuse_direntplus.h"
#include "fuse_dirents.h"
#include "fuse_entry.h"
#include "linux_dirent64.h"
#include "linux_dirent.h"
#include "stat_utils.h"

#include <dirent.h>
Expand All @@ -16,7 +16,8 @@
#include <stdlib.h>
#include <string.h>

#define DEFAULT_SIZE (1024 * 16)
/* 32KB - same as glibc getdents buffer size */
#define DEFAULT_SIZE (1024 * 32)

static
uint64_t
Expand Down Expand Up @@ -308,9 +309,9 @@ fuse_dirents_add_plus(fuse_dirents_t *d_,
}

int
fuse_dirents_add_linux(fuse_dirents_t *d_,
const struct linux_dirent64 *dirent_,
const uint64_t namelen_)
fuse_dirents_add_linux(fuse_dirents_t *d_,
const struct linux_dirent *dirent_,
const uint64_t namelen_)
{
uint64_t size;
fuse_dirent_t *d;
Expand All @@ -332,21 +333,21 @@ fuse_dirents_add_linux(fuse_dirents_t *d_,
if(d == NULL)
return -ENOMEM;

d->ino = dirent_->d_ino;
d->ino = dirent_->ino;
d->off = d_->data_len;
d->namelen = namelen_;
d->type = dirent_->d_type;
memcpy(d->name,dirent_->d_name,namelen_);
d->type = *((char*)dirent_ + dirent_->reclen - 1);
memcpy(d->name,dirent_->name,namelen_);

return 0;
}

int
fuse_dirents_add_linux_plus(fuse_dirents_t *d_,
const struct linux_dirent64 *dirent_,
const uint64_t namelen_,
const fuse_entry_t *entry_,
const struct stat *st_)
fuse_dirents_add_linux_plus(fuse_dirents_t *d_,
const struct linux_dirent *dirent_,
const uint64_t namelen_,
const fuse_entry_t *entry_,
const struct stat *st_)
{
uint64_t size;
fuse_direntplus_t *d;
Expand All @@ -368,11 +369,11 @@ fuse_dirents_add_linux_plus(fuse_dirents_t *d_,
if(d == NULL)
return -ENOMEM;

d->dirent.ino = dirent_->d_ino;
d->dirent.ino = dirent_->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->dirent.type = *((char*)dirent_ + dirent_->reclen - 1);
memcpy(d->dirent.name,dirent_->name,namelen_);

d->entry = *entry_;

Expand Down
2 changes: 2 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Config::Config()
nullrw(false),
pid(::getpid()),
posix_acl(false),
readdir(ReadDir::ENUM::POSIX),
readdirplus(false),
security_capability(true),
srcmounts(branches),
Expand Down Expand Up @@ -149,6 +150,7 @@ Config::Config()
_map["nullrw"] = &nullrw;
_map["pid"] = &pid;
_map["posix_acl"] = &posix_acl;
// _map["readdir"] = &readdir;
_map["readdirplus"] = &readdirplus;
_map["security_capability"] = &security_capability;
_map["srcmounts"] = &srcmounts;
Expand Down
2 changes: 2 additions & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

#include "branch.hpp"
#include "config_readdir.hpp"
#include "enum.hpp"
#include "errno.hpp"
#include "func_category.hpp"
Expand Down Expand Up @@ -110,6 +111,7 @@ class Config
ConfigBOOL nullrw;
ConfigUINT64 pid;
ConfigBOOL posix_acl;
ReadDir readdir;
ConfigBOOL readdirplus;
ConfigBOOL security_capability;
SrcMounts srcmounts;
Expand Down
49 changes: 49 additions & 0 deletions src/config_readdir.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <[email protected]>
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 "config_readdir.hpp"
#include "ef.hpp"

template<>
int
ReadDir::from_string(const std::string &s_)
{
if(s_ == "posix")
_data = ReadDir::ENUM::POSIX;
ef(s_ == "linux")
_data = ReadDir::ENUM::LINUX;
else
return -EINVAL;

return 0;
}

template<>
std::string
ReadDir::to_string(void) const
{
switch(_data)
{
case ReadDir::ENUM::POSIX:
return "posix";
case ReadDir::ENUM::LINUX:
return "linux";
}

return "invalid";
}
29 changes: 29 additions & 0 deletions src/config_readdir.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <[email protected]>
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 "enum.hpp"

enum class ReadDirEnum
{
POSIX,
LINUX
};

typedef Enum<ReadDirEnum> ReadDir;
2 changes: 2 additions & 0 deletions src/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#pragma once

#include "tofrom_string.hpp"

#include <string>
Expand Down
2 changes: 2 additions & 0 deletions src/fs_base_fstatat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#pragma once

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
Expand Down
37 changes: 37 additions & 0 deletions src/fs_base_getdents.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <[email protected]>
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.
*/

#if defined __linux__
#include <unistd.h>
#include <sys/syscall.h>
#endif

namespace fs
{
int
getdents(unsigned int fd_,
void *dirp_,
unsigned int count_)
{
#if defined SYS_getdents64
return ::syscall(SYS_getdents,fd_,dirp_,count_);
#else
return (errno=ENOTSUP,-1);
#endif
}
}
27 changes: 27 additions & 0 deletions src/fs_base_getdents.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <[email protected]>
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

namespace fs
{
int
getdents(unsigned int fd,
void *dirp,
unsigned int count);
}
2 changes: 2 additions & 0 deletions src/fs_copydata_copy_file_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "fs_base_stat.hpp"
#include "fs_copy_file_range.hpp"

#include <stdint.h>

namespace l
{
int64_t
Expand Down
4 changes: 3 additions & 1 deletion src/fs_copydata_copy_file_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

#pragma once

#include <stdint.h>

namespace fs
{
int
int64_t
copydata_copy_file_range(const int src_fd,
const int dst_fd);
}
2 changes: 2 additions & 0 deletions src/fs_glob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#pragma once

#include <string>
#include <vector>

Expand Down
2 changes: 2 additions & 0 deletions src/fs_statvfs_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#pragma once

#include <stdint.h>
#include <sys/statvfs.h>

Expand Down
Loading

0 comments on commit dbdd3e2

Please sign in to comment.