Browse Source

Misc fixes, mostly for FreeBSD (#1536)

pull/1537/head
trapexit 7 days ago
committed by GitHub
parent
commit
46f85c0f6d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      Makefile
  2. 14
      libfuse/include/fs_dirent64.hpp
  3. 12
      libfuse/include/fuse.h
  4. 6
      libfuse/include/thread_pool.hpp
  5. 6
      libfuse/lib/fuse_dirents.cpp
  6. 1
      libfuse/lib/mount_bsd.c
  7. 10
      src/dirinfo.hpp
  8. 10
      src/fileinfo.hpp
  9. 9
      src/fs_attr_unsupported.icpp
  10. 2
      src/fs_copy_file_range.cpp
  11. 12
      src/fs_copy_file_range.hpp
  12. 42
      src/fs_copy_file_range_linux.icpp
  13. 13
      src/fs_copy_file_range_unsupported.icpp
  14. 5
      src/fs_copyfile.cpp
  15. 2
      src/fs_getdents64.cpp
  16. 5
      src/fs_mounts.cpp
  17. 2
      src/fs_sendfile.hpp
  18. 40
      src/fuse_copy_file_range.cpp
  19. 4
      src/fuse_copy_file_range.hpp
  20. 16
      src/fuse_readdir_cor_getdents.icpp
  21. 16
      src/fuse_readdir_cosr_getdents.icpp
  22. 6
      src/fuse_readdir_cosr_readdir.icpp
  23. 16
      src/fuse_readdir_seq_getdents.icpp
  24. 4
      src/fuse_readdir_seq_readdir.icpp
  25. 23
      src/ioprio.cpp
  26. 4
      src/ioprio.hpp
  27. 2
      src/tofrom_wrapper.hpp

4
Makefile

@ -115,9 +115,7 @@ LIBFUSE := libfuse/$(BUILDDIR)/libfuse.a
LDFLAGS ?= LDFLAGS ?=
LDLIBS := \ LDLIBS := \
-lrt \ -lrt \
-latomic \
-pthread \
-lstdc++fs
-pthread
override LDLIBS += \ override LDLIBS += \
$(LIBFUSE) $(LIBFUSE)

14
libfuse/include/fs_dirent64.hpp

@ -8,16 +8,16 @@ namespace fs
struct dirent64 struct dirent64
{ {
public: public:
uint64_t d_ino;
int64_t d_off;
uint16_t d_reclen;
uint8_t d_type;
char d_name[];
uint64_t ino;
int64_t off;
uint16_t reclen;
uint8_t type;
char name[];
public: public:
int d_namelen() const
int namelen() const
{ {
return (d_reclen - offsetof(dirent64,d_name));
return (reclen - offsetof(dirent64,name));
} }
}; };
} }

12
libfuse/include/fuse.h

@ -526,12 +526,12 @@ struct fuse_operations
* destination. Effectively doing an inefficient copy of the * destination. Effectively doing an inefficient copy of the
* data. * data.
*/ */
ssize_t (*copy_file_range)(const fuse_file_info_t *fi_in,
off_t offset_in,
const fuse_file_info_t *fi_out,
off_t offset_out,
size_t size,
int flags);
ssize_t (*copy_file_range)(const fuse_file_info_t *src_fi,
off_t src_off,
const fuse_file_info_t *dst_fi,
off_t dst_off,
const size_t size,
const unsigned int flags);
ssize_t (*setupmapping)(uint64_t *fh_, ssize_t (*setupmapping)(uint64_t *fh_,
uint64_t foffset_, uint64_t foffset_,

6
libfuse/include/thread_pool.hpp

@ -77,7 +77,7 @@ public:
template<typename FuncType> template<typename FuncType>
[[nodiscard]] [[nodiscard]]
std::future<typename std::result_of<FuncType()>::type>
std::future<std::invoke_result_t<FuncType>>
enqueue_task(FuncType&& func_); enqueue_task(FuncType&& func_);
public: public:
@ -340,10 +340,10 @@ ThreadPool::enqueue_work(FuncType &&func_)
template<typename FuncType> template<typename FuncType>
[[nodiscard]] [[nodiscard]]
inline inline
std::future<typename std::result_of<FuncType()>::type>
std::future<std::invoke_result_t<FuncType>>
ThreadPool::enqueue_task(FuncType&& func_) ThreadPool::enqueue_task(FuncType&& func_)
{ {
using TaskReturnType = typename std::result_of<FuncType()>::type;
using TaskReturnType = std::invoke_result_t<FuncType>;
using Promise = std::promise<TaskReturnType>; using Promise = std::promise<TaskReturnType>;
Promise promise; Promise promise;

6
libfuse/lib/fuse_dirents.cpp

@ -122,10 +122,10 @@ fuse_dirents_add(fuse_dirents_t *d_,
d->off = kv_size(d_->offs); d->off = kv_size(d_->offs);
kv_push(uint32_t,d_->offs,kv_size(d_->data)); kv_push(uint32_t,d_->offs,kv_size(d_->data));
d->ino = de_->d_ino;
d->ino = de_->ino;
d->namelen = namelen_; d->namelen = namelen_;
d->type = de_->d_type;
memcpy(d->name,de_->d_name,namelen_);
d->type = de_->type;
memcpy(d->name,de_->name,namelen_);
return 0; return 0;
} }

1
libfuse/lib/mount_bsd.c

@ -7,7 +7,6 @@
*/ */
#include "fuse_i.h" #include "fuse_i.h"
#include "fuse_misc.h"
#include "fuse_opt.h" #include "fuse_opt.h"
#include <sys/stat.h> #include <sys/stat.h>

10
src/dirinfo.hpp

@ -18,14 +18,16 @@
#include "fh.hpp" #include "fh.hpp"
#include "int_types.h"
class DirInfo : public FH class DirInfo : public FH
{ {
public: public:
static DirInfo *from_fh(const uint64_t fh);
static DirInfo *from_fh(const u64 fh);
public: public:
uint64_t to_fh() const;
u64 to_fh() const;
public: public:
DirInfo(const fs::path &fusepath_) DirInfo(const fs::path &fusepath_)
@ -38,12 +40,12 @@ inline
uint64_t uint64_t
DirInfo::to_fh() const DirInfo::to_fh() const
{ {
return reinterpret_cast<uint64_t>(this);
return reinterpret_cast<u64>(this);
} }
inline inline
DirInfo* DirInfo*
DirInfo::from_fh(const uint64_t fh_)
DirInfo::from_fh(const u64 fh_)
{ {
return reinterpret_cast<DirInfo*>(fh_); return reinterpret_cast<DirInfo*>(fh_);
} }

10
src/fileinfo.hpp

@ -28,7 +28,7 @@
class FileInfo : public FH class FileInfo : public FH
{ {
public: public:
static FileInfo *from_fh(const uintptr_t fh);
static FileInfo *from_fh(const u64 fh);
public: public:
FileInfo(const int fd_, FileInfo(const int fd_,
@ -62,7 +62,7 @@ public:
} }
public: public:
uint64_t to_fh() const;
u64 to_fh() const;
public: public:
int fd; int fd;
@ -72,15 +72,15 @@ public:
}; };
inline inline
uintptr_t
u64
FileInfo::to_fh() const FileInfo::to_fh() const
{ {
return reinterpret_cast<uintptr_t>(this);
return reinterpret_cast<u64>(this);
} }
inline inline
FileInfo* FileInfo*
FileInfo::from_fh(const uintptr_t fh_)
FileInfo::from_fh(const u64 fh_)
{ {
return reinterpret_cast<FileInfo*>(fh_); return reinterpret_cast<FileInfo*>(fh_);
} }

9
src/fs_attr_unsupported.icpp

@ -20,15 +20,16 @@
int int
fs::attr::copy(const int fdin,
const int fdout)
fs::attr::copy(const int fdin_,
const int fdout_,
const u32 flags_)
{ {
return -ENOTSUP; return -ENOTSUP;
} }
int int
fs::attr::copy(const std::string &from,
const std::string &to)
fs::attr::copy(const std::string &from_,
const std::string &to_)
{ {
return -ENOTSUP; return -ENOTSUP;
} }

2
src/fs_copy_file_range.cpp

@ -16,6 +16,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "fs_copy_file_range.hpp"
#ifdef __linux__ #ifdef __linux__
#pragma message "using fs_copy_file_range_linux.icpp" #pragma message "using fs_copy_file_range_linux.icpp"
#include "fs_copy_file_range_linux.icpp" #include "fs_copy_file_range_linux.icpp"

12
src/fs_copy_file_range.hpp

@ -26,11 +26,11 @@
namespace fs namespace fs
{ {
int64_t
copy_file_range(const int fd_in,
int64_t *off_in,
const int fd_out,
int64_t *off_out,
const uint64_t len,
ssize_t
copy_file_range(const int src_fd_,
off_t *src_off_,
const int dst_fd_,
off_t *dst_off_,
const size_t len,
const unsigned int flags); const unsigned int flags);
} }

42
src/fs_copy_file_range_linux.icpp

@ -34,30 +34,30 @@
static static
int64_t
_copy_file_range_(int src_fd_,
int64_t *src_off_,
int tgt_fd_,
int64_t *tgt_off_,
const uint64_t len_,
ssize_t
_copy_file_range_(const int src_fd_,
off_t *src_off_,
const int dst_fd_,
off_t *dst_off_,
const size_t len_,
const unsigned int flags_) const unsigned int flags_)
{ {
#ifdef SYS_copy_file_range #ifdef SYS_copy_file_range
int64_t rv; int64_t rv;
loff_t src_off; loff_t src_off;
loff_t tgt_off;
loff_t dst_off;
loff_t *src_off_ptr; loff_t *src_off_ptr;
loff_t *tgt_off_ptr;
loff_t *dst_off_ptr;
src_off = ((src_off_ == NULL) ? 0 : *src_off_); src_off = ((src_off_ == NULL) ? 0 : *src_off_);
tgt_off = ((tgt_off_ == NULL) ? 0 : *tgt_off_);
dst_off = ((dst_off_ == NULL) ? 0 : *dst_off_);
src_off_ptr = ((src_off_ == NULL) ? NULL : &src_off); src_off_ptr = ((src_off_ == NULL) ? NULL : &src_off);
tgt_off_ptr = ((tgt_off_ == NULL) ? NULL : &tgt_off);
dst_off_ptr = ((dst_off_ == NULL) ? NULL : &dst_off);
rv = ::syscall(SYS_copy_file_range, rv = ::syscall(SYS_copy_file_range,
src_fd_, src_fd_,
src_off_ptr, src_off_ptr,
tgt_fd_,
tgt_off_ptr,
dst_fd_,
dst_off_ptr,
len_, len_,
flags_); flags_);
@ -65,8 +65,8 @@ _copy_file_range_(int src_fd_,
{ {
if(src_off_ != NULL) if(src_off_ != NULL)
*src_off_ = src_off; *src_off_ = src_off;
if(tgt_off_ != NULL)
*tgt_off_ = tgt_off;
if(dst_off_ != NULL)
*dst_off_ = dst_off;
} }
return ::to_neg_errno(rv); return ::to_neg_errno(rv);
@ -75,18 +75,18 @@ _copy_file_range_(int src_fd_,
#endif #endif
} }
int64_t
ssize_t
fs::copy_file_range(const int src_fd_, fs::copy_file_range(const int src_fd_,
int64_t *src_off_,
const int tgt_fd_,
int64_t *tgt_off_,
const uint64_t len_,
off_t *src_off_,
const int dst_fd_,
off_t *dst_off_,
const size_t len_,
const unsigned int flags_) const unsigned int flags_)
{ {
return ::_copy_file_range_(src_fd_, return ::_copy_file_range_(src_fd_,
src_off_, src_off_,
tgt_fd_,
tgt_off_,
dst_fd_,
dst_off_,
len_, len_,
flags_); flags_);
} }

13
src/fs_copy_file_range_unsupported.icpp

@ -28,18 +28,9 @@
ssize_t ssize_t
fs::copy_file_range(const int fd_in_, fs::copy_file_range(const int fd_in_,
int64_t *off_in_,
const int fd_out_,
int64_t *off_out_,
const size_t len_,
const unsigned int flags_)
{
return -EOPNOTSUPP;
}
ssize_t
fs::copy_file_range(const int fd_in_,
off_t *off_in_,
const int fd_out_, const int fd_out_,
off_t *off_out_,
const size_t len_, const size_t len_,
const unsigned int flags_) const unsigned int flags_)
{ {

5
src/fs_copyfile.cpp

@ -164,6 +164,11 @@ fs::copyfile(const int src_fd_,
return rv; return rv;
} }
// For FreeBSD
#ifndef O_NOATIME
#define O_NOATIME 0
#endif
s64 s64
fs::copyfile(const fs::path &src_filepath_, fs::copyfile(const fs::path &src_filepath_,
const fs::path &dst_filepath_, const fs::path &dst_filepath_,

2
src/fs_getdents64.cpp

@ -18,6 +18,8 @@
#include "to_neg_errno.hpp" #include "to_neg_errno.hpp"
#include <sys/types.h>
#if defined __linux__ #if defined __linux__
#include <unistd.h> #include <unistd.h>
#include <sys/syscall.h> #include <sys/syscall.h>

5
src/fs_mounts.cpp

@ -2,9 +2,9 @@
#include <cstdio> #include <cstdio>
#ifdef __linux__
#include <mntent.h> #include <mntent.h>
#ifdef __linux__
void void
fs::mounts(fs::MountVec &mounts_) fs::mounts(fs::MountVec &mounts_)
{ {
@ -29,9 +29,12 @@ fs::mounts(fs::MountVec &mounts_)
::endmntent(f); ::endmntent(f);
} }
#else #else
void void
fs::mounts(fs::MountVec &mounts_) fs::mounts(fs::MountVec &mounts_)
{ {
} }
#endif #endif

2
src/fs_sendfile.hpp

@ -16,6 +16,8 @@
#pragma once #pragma once
#include <sys/types.h>
namespace fs namespace fs
{ {

40
src/fuse_copy_file_range.cpp

@ -27,19 +27,19 @@
static static
ssize_t ssize_t
_copy_file_range(const int fd_in_,
off_t offset_in_,
const int fd_out_,
off_t offset_out_,
_copy_file_range(const int src_fd_,
off_t src_off_,
const int dst_fd_,
off_t dst_off_,
size_t size_, size_t size_,
int flags_) int flags_)
{ {
ssize_t rv; ssize_t rv;
rv = fs::copy_file_range(fd_in_,
&offset_in_,
fd_out_,
&offset_out_,
rv = fs::copy_file_range(src_fd_,
&src_off_,
dst_fd_,
&dst_off_,
size_, size_,
flags_); flags_);
@ -47,20 +47,20 @@ _copy_file_range(const int fd_in_,
} }
ssize_t ssize_t
FUSE::copy_file_range(const fuse_file_info_t *ffi_in_,
off_t offset_in_,
const fuse_file_info_t *ffi_out_,
off_t offset_out_,
size_t size_,
int flags_)
FUSE::copy_file_range(const fuse_file_info_t *src_ffi_,
off_t src_off_,
const fuse_file_info_t *dst_ffi_,
off_t dst_off_,
const size_t size_,
const unsigned int flags_)
{ {
FileInfo *fi_in = FileInfo::from_fh(ffi_in_->fh);
FileInfo *fi_out = FileInfo::from_fh(ffi_out_->fh);
FileInfo *src_fi = FileInfo::from_fh(src_ffi_->fh);
FileInfo *dst_fi = FileInfo::from_fh(dst_ffi_->fh);
return ::_copy_file_range(fi_in->fd,
offset_in_,
fi_out->fd,
offset_out_,
return ::_copy_file_range(src_fi->fd,
src_off_,
dst_fi->fd,
dst_off_,
size_, size_,
flags_); flags_);
} }

4
src/fuse_copy_file_range.hpp

@ -36,6 +36,6 @@ namespace FUSE
off_t offset_in, off_t offset_in,
const fuse_file_info_t *ffi_out, const fuse_file_info_t *ffi_out,
off_t offset_out, off_t offset_out,
size_t size,
int flags);
const size_t size,
const unsigned int flags);
} }

16
src/fuse_readdir_cor_getdents.icpp

@ -52,20 +52,20 @@ _readdir(const fs::path &branch_path_,
int namelen; int namelen;
fs::dirent64 *d = reinterpret_cast<fs::dirent64*>(&buf->mem[pos]); fs::dirent64 *d = reinterpret_cast<fs::dirent64*>(&buf->mem[pos]);
pos += d->d_reclen;
pos += d->reclen;
namelen = d->d_namelen();
namelen = d->namelen();
rv = names_.put(d->d_name,namelen);
rv = names_.put(d->name,namelen);
if(rv == 0) if(rv == 0)
continue; continue;
rel_filepath.replace_filename(d->d_name);
rel_filepath.replace_filename(d->name);
d->d_ino = fs::inode::calc(branch_path_,
rel_filepath,
DTTOIF(d->d_type),
d->d_ino);
d->ino = fs::inode::calc(branch_path_,
rel_filepath,
DTTOIF(d->type),
d->ino);
fuse_dirents_add(dirents_,d,namelen); fuse_dirents_add(dirents_,d,namelen);
} }

16
src/fuse_readdir_cosr_getdents.icpp

@ -101,20 +101,20 @@ _readdir(std::vector<std::future<DirRV>> &dh_futures_,
int namelen; int namelen;
fs::dirent64 *d = reinterpret_cast<fs::dirent64*>(&buf->mem[pos]); fs::dirent64 *d = reinterpret_cast<fs::dirent64*>(&buf->mem[pos]);
pos += d->d_reclen;
pos += d->reclen;
namelen = d->d_namelen();
namelen = d->namelen();
rv = names.put(d->d_name,namelen);
rv = names.put(d->name,namelen);
if(rv == 0) if(rv == 0)
continue; continue;
rel_filepath.replace_filename(d->d_name);
rel_filepath.replace_filename(d->name);
d->d_ino = fs::inode::calc(*dirrv.branch_path,
rel_filepath,
DTTOIF(d->d_type),
d->d_ino);
d->ino = fs::inode::calc(*dirrv.branch_path,
rel_filepath,
DTTOIF(d->type),
d->ino);
fuse_dirents_add(dirents_,d,namelen); fuse_dirents_add(dirents_,d,namelen);
} }

6
src/fuse_readdir_cosr_readdir.icpp

@ -73,9 +73,9 @@ _opendir(ThreadPool &tp_,
static static
inline inline
int int
_readdir(const std::vector<std::future<DirRV>> &dh_futures_,
const fs::path &rel_dirpath_,
fuse_dirents_t *dirents_)
_readdir(std::vector<std::future<DirRV>> &dh_futures_,
const fs::path &rel_dirpath_,
fuse_dirents_t *dirents_)
{ {
Err err; Err err;
HashSet names; HashSet names;

16
src/fuse_readdir_seq_getdents.icpp

@ -57,20 +57,20 @@ _readdir(const Branches::Ptr &branches_,
int namelen; int namelen;
fs::dirent64 *d = reinterpret_cast<fs::dirent64*>(&buf->mem[pos]); fs::dirent64 *d = reinterpret_cast<fs::dirent64*>(&buf->mem[pos]);
pos += d->d_reclen;
pos += d->reclen;
namelen = d->d_namelen();
namelen = d->namelen();
rv = names.put(d->d_name,namelen);
rv = names.put(d->name,namelen);
if(rv == 0) if(rv == 0)
continue; continue;
rel_filepath.replace_filename(d->d_name);
rel_filepath.replace_filename(d->name);
d->d_ino = fs::inode::calc(branch.path,
rel_filepath,
DTTOIF(d->d_type),
d->d_ino);
d->ino = fs::inode::calc(branch.path,
rel_filepath,
DTTOIF(d->type),
d->ino);
fuse_dirents_add(dirents_,d,namelen); fuse_dirents_add(dirents_,d,namelen);
} }

4
src/fuse_readdir_seq_readdir.icpp

@ -37,7 +37,7 @@ _readdir(const Branches::Ptr &branches_,
fs::path rel_filepath; fs::path rel_filepath;
fs::path abs_dirpath; fs::path abs_dirpath;
fuse_dirents_reset(buf_);
fuse_dirents_reset(dirents_);
rel_filepath = rel_dirpath_ / "dummy"; rel_filepath = rel_dirpath_ / "dummy";
for(const auto &branch : *branches_) for(const auto &branch : *branches_)
@ -73,7 +73,7 @@ _readdir(const Branches::Ptr &branches_,
DTTOIF(de->d_type), DTTOIF(de->d_type),
de->d_ino); de->d_ino);
fuse_dirents_add(buf_,de,namelen);
fuse_dirents_add(dirents_,de,namelen);
} }
} }

23
src/ioprio.cpp

@ -1,9 +1,10 @@
#include "ioprio.hpp" #include "ioprio.hpp"
#include <errno.h>
#ifdef __linux__ #ifdef __linux__
# include <sys/syscall.h> # include <sys/syscall.h>
# include <unistd.h> # include <unistd.h>
# include <errno.h>
#else #else
#warning "ioprio not supported on this platform" #warning "ioprio not supported on this platform"
#endif #endif
@ -17,33 +18,33 @@ thread_local int ioprio::SetFrom::thread_prio = -1;
bool _enabled = false; bool _enabled = false;
int int
ioprio::get(const int which_,
const int who_)
ioprio::get(const int who_)
{ {
#ifdef SYS_ioprio_get #ifdef SYS_ioprio_get
int rv; int rv;
const int which = IOPRIO_WHO_PROCESS;
rv = syscall(SYS_ioprio_get,which_,who_);
rv = syscall(SYS_ioprio_get,which,who_);
return ((rv == -1) ? -errno : rv); return ((rv == -1) ? -errno : rv);
#else #else
return -ENOSUP;
return -EOPNOTSUPP;
#endif #endif
} }
int int
ioprio::set(const int which_,
const int who_,
ioprio::set(const int who_,
const int ioprio_) const int ioprio_)
{ {
#ifdef SYS_ioprio_set #ifdef SYS_ioprio_set
int rv; int rv;
const int which = IOPRIO_WHO_PROCESS;
rv = syscall(SYS_ioprio_set,which_,who_,ioprio_);
rv = syscall(SYS_ioprio_set,which,who_,ioprio_);
return ((rv == -1) ? -errno : rv); return ((rv == -1) ? -errno : rv);
#else #else
return -ENOSUP;
return -EOPNOTSUPP;
#endif #endif
} }
@ -66,12 +67,12 @@ ioprio::SetFrom::SetFrom(const pid_t pid_)
if(!_enabled) if(!_enabled)
return; return;
client_prio = ioprio::get(IOPRIO_WHO_PROCESS,pid_);
client_prio = ioprio::get(pid_);
if(client_prio < 0) if(client_prio < 0)
return; return;
if(client_prio == thread_prio) if(client_prio == thread_prio)
return; return;
thread_prio = client_prio; thread_prio = client_prio;
ioprio::set(IOPRIO_WHO_PROCESS,0,client_prio);
ioprio::set(0,client_prio);
} }

4
src/ioprio.hpp

@ -8,8 +8,8 @@ namespace ioprio
void enable(const bool); void enable(const bool);
bool enabled(); bool enabled();
int get(const int which, const int who);
int set(const int which, const int who, const int ioprio);
int get(const int who);
int set(const int who, const int ioprio);
struct SetFrom struct SetFrom
{ {

2
src/tofrom_wrapper.hpp

@ -100,7 +100,7 @@ class ROToFromWrapper : public ToFromString
{ {
public: public:
int int
from_string(const std::string &s_) final
from_string(const std::string_view s_) final
{ {
return -EINVAL; return -EINVAL;
} }

Loading…
Cancel
Save