diff --git a/include/client/gkfs_functions.hpp b/include/client/gkfs_functions.hpp index e83f33109375b54cb73a2566c0de0cd016171865..b7157ae4550d22092baa7ba16c1e61efe2d94376 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 32d9a0c496279f66890571f13f81848ddcadd65a..060d628c6371a4b56a0202bcdeb8683961ee8868 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 414d5d8f803a89b3691c27d7315cd640d23b7bc9..62202b30fa7b7b6b3c0e4aa5c142f19afca026f1 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 68862c9d2d8b51a18f73ad778749cdf9fda5b1f9..314e245de65a0f673bbccc3c5cd950f97a378f3e 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();