Commit 59c05137 authored by Julius Athenstaedt's avatar Julius Athenstaedt
Browse files

gkfs_libc remove functionality

parent bbc48c09
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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);

+4 −0
Original line number Diff line number Diff line
@@ -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);

+18 −0
Original line number Diff line number Diff line
@@ -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
+9 −1
Original line number Diff line number Diff line
@@ -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();