From 5c0ec2a1da701976ee59a382099b9d745f01cd85 Mon Sep 17 00:00:00 2001 From: Julius Athenstaedt Date: Thu, 17 Apr 2025 16:45:32 +0200 Subject: [PATCH] gkfs_libc remove functionality --- include/client/gkfs_functions.hpp | 3 +++ include/client/user_functions.hpp | 4 ++++ src/client/gkfs_functions.cpp | 18 ++++++++++++++++++ src/client/gkfs_libc.cpp | 10 +++++++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/client/gkfs_functions.hpp b/include/client/gkfs_functions.hpp index e83f33109..b7157ae45 100644 --- a/include/client/gkfs_functions.hpp +++ b/include/client/gkfs_functions.hpp @@ -55,6 +55,9 @@ gkfs_open(const std::string& path, mode_t mode, int flags); int gkfs_create(const std::string& path, mode_t mode); +int +gkfs_libcremove(const std::string& path); + int gkfs_remove(const std::string& path); diff --git a/include/client/user_functions.hpp b/include/client/user_functions.hpp index 32d9a0c49..060d628c6 100644 --- a/include/client/user_functions.hpp +++ b/include/client/user_functions.hpp @@ -62,6 +62,8 @@ gkfs_open(const std::string& path, mode_t mode, int flags); int gkfs_create(const std::string& path, mode_t mode); +int +gkfs_libcremove(const std::string& path); int gkfs_remove(const std::string& path); int @@ -106,6 +108,8 @@ int gkfs_statx(int dirfs, const std::string& path, int flags, unsigned int mask, struct statx* buf, bool follow_links = true); +int +gkfs_libcremove(const std::string& path); int gkfs_remove(const std::string& path); diff --git a/src/client/gkfs_functions.cpp b/src/client/gkfs_functions.cpp index 414d5d8f8..62202b30f 100644 --- a/src/client/gkfs_functions.cpp +++ b/src/client/gkfs_functions.cpp @@ -393,6 +393,24 @@ gkfs_create(const std::string& path, mode_t mode) { return 0; } +/** + * gkfs wrapper for remove() libc call + * removes files with unlink(), see gkfs_remove() + * and directories with rmdir(), see gkfs_rmdir() + */ +int +gkfs_libcremove(const std::string& path) { + auto md = gkfs::utils::get_metadata(path); + if(!md) { + return -1; + } + if(S_ISDIR(md->mode())) { + return gkfs_rmdir(path); + } else { + return gkfs_remove(path); + } +} + /** * gkfs wrapper for unlink() system calls * errno may be set diff --git a/src/client/gkfs_libc.cpp b/src/client/gkfs_libc.cpp index 68862c9d2..314e245de 100644 --- a/src/client/gkfs_libc.cpp +++ b/src/client/gkfs_libc.cpp @@ -313,7 +313,7 @@ DLSYM_WRAPPER(int, renameat2, (int olddirfd, const char* oldpath, int newdirfd, const char* newpath, unsigned int flags), (olddirfd, oldpath, newdirfd, newpath, flags), "renameat2") -DLSYM_WRAPPER(int, remove, (char* path), (path), "remove") +DLSYM_WRAPPER(int, remove, (const char* path), (path), "remove") DLSYM_WRAPPER(int, unlink, (const char* path), (path), "unlink") DLSYM_WRAPPER(DIR*, opendir, (const char* dirname), (dirname), "opendir") DLSYM_WRAPPER(DIR*, opendir64, (const char* dirname), (dirname), "opendir64") @@ -902,6 +902,14 @@ pwrite64(int fd, const void* buf, size_t count, off64_t offset) { GKFS_FALLBACK(pwrite64, fd, buf, count, offset); } +int +remove(const char* path) { + initializeGekko(); + + GKFS_PATH_OPERATION1(libcremove, AT_FDCWD, path) + GKFS_FALLBACK(remove, path); +} + int unlink(const char* path) { initializeGekko(); -- GitLab