Commit 03c6e619 authored by Marc Vef's avatar Marc Vef
Browse files

Preload: Adding rudimentary mkdir, rmdir support (atm handled as files)

parent bb3d6de1
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -17,7 +17,10 @@ extern void* libc_fopen64; // XXX Does not work with streaming pointers. If used

//extern void* libc_creat; //unused
//extern void* libc_creat64; //unused
extern void* libc_mkdir;
extern void* libc_mkdirat;
extern void* libc_unlink;
extern void* libc_rmdir;

extern void* libc_close;
//extern void* libc___close; //unused
+2 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ ino_t generate_inode_no() {
int create_node(const std::string& path, const uid_t uid, const gid_t gid, mode_t mode) {
    auto err = create_metadentry(path, mode); // XXX errorhandling

    // XXX Only do that for files and not for directories
    init_chunk_space(path);

    return err;
@@ -83,6 +84,7 @@ int remove_metadentry(const string& path) {

int remove_node(const string& path) {
    auto err = remove_metadentry(path);
    // XXX Only do that with a file. Directory needs to be handled differently
    if (err == 0)
        destroy_chunk_space(
                path); // XXX This removes only the data on that node. Leaving everything in inconsistent state
+32 −0
Original line number Diff line number Diff line
@@ -69,6 +69,28 @@ int creat64(const char* path, mode_t mode) {
    return open(path, O_CREAT | O_WRONLY | O_TRUNC | O_LARGEFILE, mode);
}

int mkdir(const char* path, mode_t mode) {
    init_passthrough_if_needed();
    ld_logger->trace("{}() called with path {} with mode {}", __func__, path, mode);
    if (ld_is_env_initialized() && is_fs_path(path)) {
        // XXX Possible don't use open here but a separate call to handle RPCs directly (unsure about O_DIRECTORY flag)
        return open(path, O_CREAT | O_DIRECTORY | O_WRONLY, mode);
    }
    return (reinterpret_cast<decltype(&mkdir)>(libc_mkdir))(path, mode);
}

int mkdirat(int dirfd, const char* path, mode_t mode) {
    init_passthrough_if_needed();
    ld_logger->trace("{}() called with path {} with mode {} with dirfd {}", __func__, path, mode, dirfd);
    if (ld_is_env_initialized() && is_fs_path(path)) {
        // not implemented
        ld_logger->trace("{}() not implemented.", __func__);
        return -1;
    }
    return (reinterpret_cast<decltype(&mkdirat)>(libc_mkdirat))(dirfd, path, mode);
}


int unlink(const char* path) __THROW {
    init_passthrough_if_needed();
    ld_logger->trace("{}() called with path {}", __func__, path);
@@ -78,6 +100,16 @@ int unlink(const char* path) __THROW {
    return (reinterpret_cast<decltype(&unlink)>(libc_unlink))(path);
}

int rmdir(const char* path) {
    init_passthrough_if_needed();
    ld_logger->trace("{}() called with path {}", __func__, path);
    if (ld_is_env_initialized() && is_fs_path(path)) {
        // XXX Possible need another call to specifically handle remove dirs. For now handle them the same as files
        return rpc_send_unlink(path);
    }
    return (reinterpret_cast<decltype(&rmdir)>(libc_rmdir))(path);
}

int close(int fd) {
    init_passthrough_if_needed();
    if (ld_is_env_initialized() && file_map.exist(fd)) {
+6 −0
Original line number Diff line number Diff line
@@ -21,7 +21,10 @@ void* libc_fopen64; // XXX Does not work with streaming pointers. If used will b

//void* libc_creat; //unused
//void* libc_creat64; //unused
void* libc_mkdir;
void* libc_mkdirat;
void* libc_unlink;
void* libc_rmdir;

void* libc_close;
//void* libc___close; //unused
@@ -61,8 +64,11 @@ void init_passthrough_() {
    libc_open = dlsym(libc, "open");
//    libc_fopen = dlsym(libc, "fopen");
//    libc_fopen64 = dlsym(libc, "fopen64");
    libc_mkdir = dlsym(libc, "mkdir");
    libc_mkdirat = dlsym(libc, "mkdirat");

    libc_unlink = dlsym(libc, "unlink");
    libc_rmdir = dlsym(libc, "rmdir");

    libc_close = dlsym(libc, "close");
//    libc___close = dlsym(libc, "__close");
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ int rpc_send_open(const std::string& path, const mode_t mode, const int flags) {
    in.path = path.c_str();
    in.mode = mode;

    // TODO handle all flags. currently only file create
    // TODO handle all flags. currently only file create. Directory are not handled differently than files XXX
    if (!(flags & O_CREAT)) {
        ld_logger->debug("{}() No create flag given, assuming file exists ...", __func__);
        return 0; // XXX This is a temporary quickfix for read. Look up if file exists. Do it on server end.