diff --git a/libfuse/include/base_types.h b/libfuse/include/base_types.h new file mode 100644 index 00000000..057a9ac0 --- /dev/null +++ b/libfuse/include/base_types.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +typedef uint32_t u32; +typedef int32_t s32; +typedef uint64_t u64; +typedef int64_t s64; + +typedef const uint32_t cu32; +typedef const int32_t cs32; +typedef const uint64_t cu64; +typedef const int64_t cs64; + +typedef float f32; +typedef double f64; +typedef long double f80; +typedef char assertion_f32_is_32bit[sizeof(f32) == 4 ? 1 : -1]; +typedef char assertion_f64_is_64bit[sizeof(f64) == 8 ? 1 : -1]; +typedef char assertion_f80_is_at_least_64bit[sizeof(f64) >= 8 ? 1 : -1]; + +typedef const float cf32; +typedef const double cf64; +typedef const long double cf80; diff --git a/libfuse/include/fuse_cfg.hpp b/libfuse/include/fuse_cfg.hpp index 21296c12..20f77bc6 100644 --- a/libfuse/include/fuse_cfg.hpp +++ b/libfuse/include/fuse_cfg.hpp @@ -1,6 +1,6 @@ #pragma once -#include "int_types.h" +#include "base_types.h" #include #include diff --git a/libfuse/include/fuse_msgbuf.hpp b/libfuse/include/fuse_msgbuf.hpp index 8872d302..345df805 100644 --- a/libfuse/include/fuse_msgbuf.hpp +++ b/libfuse/include/fuse_msgbuf.hpp @@ -18,7 +18,7 @@ #pragma once -#include "int_types.h" +#include "base_types.h" #include "fuse_msgbuf_t.h" u32 msgbuf_get_pagesize(); diff --git a/libfuse/include/int_types.h b/libfuse/include/int_types.h deleted file mode 100644 index 177d80d1..00000000 --- a/libfuse/include/int_types.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -typedef uint64_t u32; -typedef int64_t s32; -typedef uint64_t u64; -typedef int64_t s64; - -typedef const uint64_t cu32; -typedef const int64_t cs32; -typedef const uint64_t cu64; -typedef const int64_t cs64; diff --git a/src/branch.hpp b/src/branch.hpp index f0d07110..b30549f0 100644 --- a/src/branch.hpp +++ b/src/branch.hpp @@ -18,7 +18,7 @@ #pragma once -#include "int_types.h" +#include "base_types.h" #include "strvec.hpp" #include "tofrom_string.hpp" #include "fs_path.hpp" diff --git a/src/branches.cpp b/src/branches.cpp index 41e916b1..d4d60bb6 100644 --- a/src/branches.cpp +++ b/src/branches.cpp @@ -23,7 +23,7 @@ #include "fs_glob.hpp" #include "fs_is_rofs.hpp" #include "fs_realpathize.hpp" -#include "int_types.h" +#include "base_types.h" #include "num.hpp" #include "str.hpp" #include "syslog.hpp" diff --git a/src/dirinfo.hpp b/src/dirinfo.hpp index c9c71ad4..9661b95e 100644 --- a/src/dirinfo.hpp +++ b/src/dirinfo.hpp @@ -18,7 +18,7 @@ #include "fh.hpp" -#include "int_types.h" +#include "base_types.h" class DirInfo : public FH diff --git a/src/fileinfo.hpp b/src/fileinfo.hpp index f45ecefe..9a435edb 100644 --- a/src/fileinfo.hpp +++ b/src/fileinfo.hpp @@ -20,9 +20,9 @@ #include "fh.hpp" #include "fs_path.hpp" -#include +#include "base_types.h" -#include "int_types.h" +#include class FileInfo : public FH diff --git a/src/fs_attr.hpp b/src/fs_attr.hpp index aae829ae..1f603702 100644 --- a/src/fs_attr.hpp +++ b/src/fs_attr.hpp @@ -18,7 +18,7 @@ #include -#include "int_types.h" +#include "base_types.h" #define FS_ATTR_NONE (0) #define FS_ATTR_CLEAR_IMMUTABLE (1 << 0) diff --git a/src/fs_copydata.hpp b/src/fs_copydata.hpp index 44100353..d588322c 100644 --- a/src/fs_copydata.hpp +++ b/src/fs_copydata.hpp @@ -18,7 +18,7 @@ #pragma once -#include "int_types.h" +#include "base_types.h" namespace fs diff --git a/src/fs_copydata_copy_file_range.cpp b/src/fs_copydata_copy_file_range.cpp index e0d829d7..cd3fb08c 100644 --- a/src/fs_copydata_copy_file_range.cpp +++ b/src/fs_copydata_copy_file_range.cpp @@ -20,7 +20,7 @@ #include "fs_copy_file_range.hpp" #include "fs_fstat.hpp" -#include "int_types.h" +#include "base_types.h" static diff --git a/src/fs_copydata_copy_file_range.hpp b/src/fs_copydata_copy_file_range.hpp index 70d12eda..7fb14f59 100644 --- a/src/fs_copydata_copy_file_range.hpp +++ b/src/fs_copydata_copy_file_range.hpp @@ -16,7 +16,7 @@ #pragma once -#include "int_types.h" +#include "base_types.h" namespace fs diff --git a/src/fs_copydata_readwrite.hpp b/src/fs_copydata_readwrite.hpp index 8f329067..403c2384 100644 --- a/src/fs_copydata_readwrite.hpp +++ b/src/fs_copydata_readwrite.hpp @@ -16,7 +16,7 @@ #pragma once -#include "int_types.h" +#include "base_types.h" namespace fs { diff --git a/src/fs_copyfile.hpp b/src/fs_copyfile.hpp index a45d0469..d7541224 100644 --- a/src/fs_copyfile.hpp +++ b/src/fs_copyfile.hpp @@ -1,6 +1,6 @@ #pragma once -#include "int_types.h" +#include "base_types.h" #include "fs_path.hpp" #include diff --git a/src/fs_movefile_and_open.cpp b/src/fs_movefile_and_open.cpp index f59103cd..a42324ab 100644 --- a/src/fs_movefile_and_open.cpp +++ b/src/fs_movefile_and_open.cpp @@ -16,6 +16,7 @@ #include "fs_movefile_and_open.hpp" +#include "base_types.h" #include "errno.hpp" #include "fs_clonepath.hpp" #include "fs_close.hpp" @@ -30,7 +31,6 @@ #include "fs_rename.hpp" #include "fs_stat.hpp" #include "fs_unlink.hpp" -#include "int_types.h" #include "policy.hpp" #include "ugid.hpp" diff --git a/src/fs_pread.hpp b/src/fs_pread.hpp index a6407893..47443c7d 100644 --- a/src/fs_pread.hpp +++ b/src/fs_pread.hpp @@ -18,7 +18,7 @@ #pragma once -#include "int_types.h" +#include "base_types.h" #include "to_neg_errno.hpp" #include diff --git a/src/mergerfs_fsck.cpp b/src/mergerfs_fsck.cpp index 41e9222a..ec84fc36 100644 --- a/src/mergerfs_fsck.cpp +++ b/src/mergerfs_fsck.cpp @@ -1,20 +1,21 @@ #include "mergerfs_fsck.hpp" +#include "fs_close.hpp" +#include "fs_copyfile.hpp" #include "fs_lchmod.hpp" #include "fs_lchown.hpp" -#include "fs_close.hpp" #include "fs_lgetxattr.hpp" #include "fs_lstat.hpp" #include "fs_open.hpp" -#include "int_types.h" -#include "str.hpp" -#include "fs_copyfile.hpp" #include "mergerfs_api.hpp" +#include "str.hpp" #include "fmt/core.h" #include "fmt/chrono.h" #include "CLI11.hpp" +#include "base_types.h" + #include namespace FS = std::filesystem; diff --git a/src/mergerfs_ioctl.hpp b/src/mergerfs_ioctl.hpp index bcad8d24..ea31f02a 100644 --- a/src/mergerfs_ioctl.hpp +++ b/src/mergerfs_ioctl.hpp @@ -1,6 +1,6 @@ #pragma once -#include "int_types.h" +#include "base_types.h" #include diff --git a/src/policy_lup.cpp b/src/policy_lup.cpp index a29de06d..1c083aff 100644 --- a/src/policy_lup.cpp +++ b/src/policy_lup.cpp @@ -26,6 +26,8 @@ #include "policy_error.hpp" #include "rwlock.hpp" +#include "base_types.h" + #include #include @@ -33,60 +35,61 @@ using std::string; static int -_action(const Branches::Ptr &branches_, - const fs::path &fusepath_, - std::vector &paths_) +_action(const Branches::Ptr &branches_, + const fs::path &fusepath_, + std::vector &paths_) { int rv; int error; fs::info_t info; Branch *obranch; + u64 best_used; + u64 best_total; + best_used = 0; + best_total = 1; obranch = nullptr; error = ENOENT; - uint64_t best_used = 0; - uint64_t best_total = 1; - - for (auto &branch : *branches_) - { - if (branch.ro()) - error_and_continue(error, EROFS); - if (!fs::exists(branch.path, fusepath_)) - error_and_continue(error, ENOENT); - rv = fs::info(branch.path, &info); - if (rv < 0) - error_and_continue(error, ENOENT); - if (info.readonly) - error_and_continue(error, EROFS); - - uint64_t used = info.spaceused; - uint64_t total = info.spaceused + info.spaceavail; - if (total == 0) + for(auto &branch : *branches_) { - used = 0; - total = 1; - } + if(branch.ro()) + error_and_continue(error,EROFS); + if(!fs::exists(branch.path,fusepath_)) + error_and_continue(error,ENOENT); + rv = fs::info(branch.path,&info); + if(rv < 0) + error_and_continue(error,ENOENT); + if(info.readonly) + error_and_continue(error,EROFS); + + u64 used = info.spaceused; + u64 total = info.spaceused + info.spaceavail; + if(total == 0) + { + used = 0; + total = 1; + } + + if(obranch == nullptr) + { + best_used = used; + best_total = total; + obranch = &branch; + continue; + } + + f80 lhs = (f80)used * (f80)best_total; + f80 rhs = (f80)best_used * (f80)total; + if(lhs >= rhs) + continue; - if (obranch == nullptr) - { best_used = used; best_total = total; obranch = &branch; - continue; } - unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total; - unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total; - if (lhs >= rhs) - continue; - - best_used = used; - best_total = total; - obranch = &branch; - } - - if (obranch == nullptr) + if(obranch == nullptr) return -error; paths_.push_back(obranch); @@ -101,51 +104,53 @@ _search(const Branches::Ptr &branches_, std::vector &paths_) { int rv; - uint64_t used; - uint64_t avail; - uint64_t best_used = 0; - uint64_t best_total = 1; + u64 used; + u64 avail; + u64 best_used; + u64 best_total; Branch *obranch; + best_used = 0; + best_total = 1; obranch = nullptr; - for (auto &branch : *branches_) - { - if (!fs::exists(branch.path, fusepath_)) - continue; - rv = fs::statvfs_cache_spaceused(branch.path, &used); - if (rv < 0) - continue; - rv = fs::statvfs_cache_spaceavail(branch.path, &avail); - if (rv < 0) - continue; - - uint64_t total = used + avail; - if (total == 0) + for(auto &branch : *branches_) { - used = 0; - total = 1; - } + if(!fs::exists(branch.path,fusepath_)) + continue; + rv = fs::statvfs_cache_spaceused(branch.path,&used); + if(rv < 0) + continue; + rv = fs::statvfs_cache_spaceavail(branch.path,&avail); + if(rv < 0) + continue; + + u64 total = used + avail; + if(total == 0) + { + used = 0; + total = 1; + } + + if(obranch == nullptr) + { + best_used = used; + best_total = total; + obranch = &branch; + continue; + } + + f80 lhs = (f80)used * (f80)best_total; + f80 rhs = (f80)best_used * (f80)total; + if(lhs >= rhs) + continue; - if (obranch == nullptr) - { best_used = used; best_total = total; obranch = &branch; - continue; } - unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total; - unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total; - if (lhs >= rhs) - continue; - - best_used = used; - best_total = total; - obranch = &branch; - } - - if (obranch == nullptr) + if(obranch == nullptr) return -ENOENT; paths_.push_back(obranch); @@ -155,59 +160,60 @@ _search(const Branches::Ptr &branches_, static int -_create(const Branches::Ptr &branches_, - std::vector &paths_) +_create(const Branches::Ptr &branches_, + std::vector &paths_) { int rv; int error; + u64 best_used; + u64 best_total; fs::info_t info; Branch *obranch; + best_used = 0; + best_total = 1; obranch = nullptr; error = ENOENT; - uint64_t best_used = 0; - uint64_t best_total = 1; - - for (auto &branch : *branches_) - { - if (branch.ro_or_nc()) - error_and_continue(error, EROFS); - rv = fs::info(branch.path, &info); - if (rv < 0) - error_and_continue(error, ENOENT); - if (info.readonly) - error_and_continue(error, EROFS); - if (info.spaceavail < branch.minfreespace()) - error_and_continue(error, ENOSPC); - - uint64_t used = info.spaceused; - uint64_t total = info.spaceused + info.spaceavail; - if (total == 0) + for(auto &branch : *branches_) { - used = 0; - total = 1; - } + if(branch.ro_or_nc()) + error_and_continue(error,EROFS); + rv = fs::info(branch.path,&info); + if(rv < 0) + error_and_continue(error,ENOENT); + if(info.readonly) + error_and_continue(error,EROFS); + if(info.spaceavail < branch.minfreespace()) + error_and_continue(error,ENOSPC); + + u64 used = info.spaceused; + u64 total = info.spaceused + info.spaceavail; + if(total == 0) + { + used = 0; + total = 1; + } + + if(obranch == nullptr) + { + best_used = used; + best_total = total; + obranch = &branch; + continue; + } + + f80 lhs = (f80)used * (f80)best_total; + f80 rhs = (f80)best_used * (f80)total; + if(lhs >= rhs) + continue; - if (obranch == nullptr) - { best_used = used; best_total = total; obranch = &branch; - continue; } - unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total; - unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total; - if (lhs >= rhs) - continue; - - best_used = used; - best_total = total; - obranch = &branch; - } - - if (obranch == nullptr) + if(obranch == nullptr) return -error; paths_.push_back(obranch); @@ -216,25 +222,25 @@ _create(const Branches::Ptr &branches_, } int -Policy::LUP::Action::operator()(const Branches::Ptr &branches_, - const fs::path &fusepath_, - std::vector &paths_) const +Policy::LUP::Action::operator()(const Branches::Ptr &branches_, + const fs::path &fusepath_, + std::vector &paths_) const { - return ::_action(branches_, fusepath_, paths_); + return ::_action(branches_,fusepath_,paths_); } int -Policy::LUP::Create::operator()(const Branches::Ptr &branches_, - const fs::path &fusepath_, - std::vector &paths_) const +Policy::LUP::Create::operator()(const Branches::Ptr &branches_, + const fs::path &fusepath_, + std::vector &paths_) const { - return ::_create(branches_, paths_); + return ::_create(branches_,paths_); } int -Policy::LUP::Search::operator()(const Branches::Ptr &branches_, - const fs::path &fusepath_, - std::vector &paths_) const +Policy::LUP::Search::operator()(const Branches::Ptr &branches_, + const fs::path &fusepath_, + std::vector &paths_) const { - return ::_search(branches_, fusepath_, paths_); + return ::_search(branches_,fusepath_,paths_); } diff --git a/src/symlinkify.hpp b/src/symlinkify.hpp index 590003b2..6cdc4a13 100644 --- a/src/symlinkify.hpp +++ b/src/symlinkify.hpp @@ -19,7 +19,8 @@ #pragma once #include "fuse_kernel.h" -#include "int_types.h" + +#include "base_types.h" #include