Loading include/client/path.hpp +5 −3 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ namespace gkfs::path { enum class NormalizeStatus { ok, fd_unknown, fd_not_a_dir }; enum class NormalizeStatus { internal, external, fd_unknown, fd_not_a_dir }; unsigned int match_components(const std::string& path, unsigned int& path_components, Loading @@ -44,13 +44,15 @@ resolve(const std::string& path, std::string& resolved, NormalizeStatus normalize(int dirfd, const char* raw_path, std::string& normalized_path, bool resolve_last_link = true); int flags = 0, bool resolve_last_link = true); std::string normalize(const char* raw_path, bool resolve_last_link = true); bool is_in_gkfs(std::string& path, bool cut_mountdir_prefix = false); is_in_gkfs(std::string& path); std::string make_internal(std::string path); std::string get_sys_cwd(); Loading src/client/hooks.cpp +6 −7 Original line number Diff line number Diff line Loading @@ -77,11 +77,10 @@ hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) { case gkfs::path::NormalizeStatus::fd_not_a_dir: return -ENOTDIR; case gkfs::path::NormalizeStatus::ok: if(gkfs::path::is_in_gkfs(normalized_path, true)) return with_errno( gkfs::syscall::gkfs_open(normalized_path, mode, flags)); else case gkfs::path::NormalizeStatus::internal: gkfs::path::make_internal(normalized_path); return with_errno(gkfs::syscall::gkfs_open(normalized_path, mode, flags)); case gkfs::path::NormalizeStatus::external: return syscall_no_intercept_wrapper(SYS_openat, dirfd, normalized_path.c_str(), flags, mode); Loading Loading @@ -206,7 +205,7 @@ hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags) { __func__, cpath, dirfd, fmt::ptr(buf), flags); std::string normalized_path{}; auto status = gkfs::path::normalize(dirfd, cpath, normalized_path); auto status = gkfs::path::normalize(dirfd, cpath, normalized_path, flags); LOG(INFO, "{}() normalized path: \"{}\"", __func__, normalized_path); switch(status) { Loading src/client/path.cpp +19 −10 Original line number Diff line number Diff line Loading @@ -315,7 +315,7 @@ match_components(const string& path, unsigned int& path_components, } NormalizeStatus normalize(int dirfd, const char* raw_path, std::string& normalized_path, normalize(int dirfd, const char* raw_path, std::string& normalized_path, int flags, bool resolve_last_link) { // TODO when LEAF is available: return concated path and throw Status // instead. Relativize path should be called only after the library Loading @@ -337,6 +337,13 @@ normalize(int dirfd, const char* raw_path, std::string& normalized_path, } else { if(!CTX->file_map()->exist(dirfd)) { return NormalizeStatus::fd_unknown; } else { // check if we have the AT_EMPTY_PATH flag // for fstatat. if(flags & AT_EMPTY_PATH) { normalized_path = CTX->file_map()->get(dirfd)->path(); return NormalizeStatus::internal; } } // path is relative to fd auto dir = CTX->file_map()->get_dir(dirfd); Loading @@ -351,8 +358,12 @@ normalize(int dirfd, const char* raw_path, std::string& normalized_path, } else { path = raw_path; } normalized_path = ::normalize(path); return NormalizeStatus::ok; if(is_in_gkfs(normalized_path)) { return NormalizeStatus::internal; } else return NormalizeStatus::external; } std::string Loading Loading @@ -396,14 +407,12 @@ normalize(const char* raw_path, bool resolve_last_link) { * @return true if within gkfs namespace else false */ bool is_in_gkfs(std::string& path, bool cut_mountdir_prefix) { if(path.rfind(CTX->mountdir(), 0) != std::string::npos) { if(cut_mountdir_prefix) path.erase(1, CTX->mountdir().size()); return true; } else { return false; is_in_gkfs(std::string& path) { return path.rfind(CTX->mountdir(), 0) != std::string::npos; } inline void make_internal(string& path) { path.erase(1, CTX->mountdir().size()); } string Loading Loading
include/client/path.hpp +5 −3 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ namespace gkfs::path { enum class NormalizeStatus { ok, fd_unknown, fd_not_a_dir }; enum class NormalizeStatus { internal, external, fd_unknown, fd_not_a_dir }; unsigned int match_components(const std::string& path, unsigned int& path_components, Loading @@ -44,13 +44,15 @@ resolve(const std::string& path, std::string& resolved, NormalizeStatus normalize(int dirfd, const char* raw_path, std::string& normalized_path, bool resolve_last_link = true); int flags = 0, bool resolve_last_link = true); std::string normalize(const char* raw_path, bool resolve_last_link = true); bool is_in_gkfs(std::string& path, bool cut_mountdir_prefix = false); is_in_gkfs(std::string& path); std::string make_internal(std::string path); std::string get_sys_cwd(); Loading
src/client/hooks.cpp +6 −7 Original line number Diff line number Diff line Loading @@ -77,11 +77,10 @@ hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) { case gkfs::path::NormalizeStatus::fd_not_a_dir: return -ENOTDIR; case gkfs::path::NormalizeStatus::ok: if(gkfs::path::is_in_gkfs(normalized_path, true)) return with_errno( gkfs::syscall::gkfs_open(normalized_path, mode, flags)); else case gkfs::path::NormalizeStatus::internal: gkfs::path::make_internal(normalized_path); return with_errno(gkfs::syscall::gkfs_open(normalized_path, mode, flags)); case gkfs::path::NormalizeStatus::external: return syscall_no_intercept_wrapper(SYS_openat, dirfd, normalized_path.c_str(), flags, mode); Loading Loading @@ -206,7 +205,7 @@ hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags) { __func__, cpath, dirfd, fmt::ptr(buf), flags); std::string normalized_path{}; auto status = gkfs::path::normalize(dirfd, cpath, normalized_path); auto status = gkfs::path::normalize(dirfd, cpath, normalized_path, flags); LOG(INFO, "{}() normalized path: \"{}\"", __func__, normalized_path); switch(status) { Loading
src/client/path.cpp +19 −10 Original line number Diff line number Diff line Loading @@ -315,7 +315,7 @@ match_components(const string& path, unsigned int& path_components, } NormalizeStatus normalize(int dirfd, const char* raw_path, std::string& normalized_path, normalize(int dirfd, const char* raw_path, std::string& normalized_path, int flags, bool resolve_last_link) { // TODO when LEAF is available: return concated path and throw Status // instead. Relativize path should be called only after the library Loading @@ -337,6 +337,13 @@ normalize(int dirfd, const char* raw_path, std::string& normalized_path, } else { if(!CTX->file_map()->exist(dirfd)) { return NormalizeStatus::fd_unknown; } else { // check if we have the AT_EMPTY_PATH flag // for fstatat. if(flags & AT_EMPTY_PATH) { normalized_path = CTX->file_map()->get(dirfd)->path(); return NormalizeStatus::internal; } } // path is relative to fd auto dir = CTX->file_map()->get_dir(dirfd); Loading @@ -351,8 +358,12 @@ normalize(int dirfd, const char* raw_path, std::string& normalized_path, } else { path = raw_path; } normalized_path = ::normalize(path); return NormalizeStatus::ok; if(is_in_gkfs(normalized_path)) { return NormalizeStatus::internal; } else return NormalizeStatus::external; } std::string Loading Loading @@ -396,14 +407,12 @@ normalize(const char* raw_path, bool resolve_last_link) { * @return true if within gkfs namespace else false */ bool is_in_gkfs(std::string& path, bool cut_mountdir_prefix) { if(path.rfind(CTX->mountdir(), 0) != std::string::npos) { if(cut_mountdir_prefix) path.erase(1, CTX->mountdir().size()); return true; } else { return false; is_in_gkfs(std::string& path) { return path.rfind(CTX->mountdir(), 0) != std::string::npos; } inline void make_internal(string& path) { path.erase(1, CTX->mountdir().size()); } string Loading