Commit fe47e129 authored by Ramon Nou's avatar Ramon Nou
Browse files

adding getcwd and rewindir

parent f42f62ab
Loading
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
@@ -2388,3 +2388,53 @@ aio_error(const struct aiocb* aiocbp) {
    }
    GKFS_FALLBACK(aio_error, aiocbp)
}


DLSYM_WRAPPER(char*, getcwd, (char* buffer, size_t size), (buffer, size),
              "getcwd")

char*
getcwd(char* buffer, size_t size) {

    initializeGekko();
    if(CTX->interception_enabled()) {

        if(size == 0) {
            buffer = (char*) malloc(CTX->cwd().size());
            size = CTX->cwd().size();
        }
        if(CTX->cwd().size() + 1 > size) {
            LOG(ERROR, "{}() buffer too small to host current working dir",
                __func__);
            errno = ERANGE;
            return NULL;
        }
        DEBUG_INFO("[GKFS] Size: {} / CWD {}", size, CTX->cwd().c_str())
        strcpy(buffer, CTX->cwd().c_str());
        return buffer;
    }

    GKFS_FALLBACK(getcwd, buffer, size);
}


DLSYM_WRAPPER(void, rewinddir, (DIR * dirstream), (dirstream), "rewinddir")

void
rewinddir(DIR* dirstream) {

    log_argumentsx(dirstream->path);
    initializeGekko();
    if(CTX->interception_enabled() && is_gkfs_fd(dirstream->fd)) {
        DEBUG_INFO("[GKFS] {}", dirstream->fd);
        auto open_dir = CTX->file_map()->get_dir(dirstream->fd);
        if(open_dir == nullptr) {
            // Cast did not succeeded: open_file is a regular file
            errno = EBADF;
            return;
        }
        open_dir->pos(0);
        return;
    }
    GKFS_FALLBACK(rewinddir, dirstream)
}
+1 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ PreloadContext::PreloadContext()
    char host[255];
    gethostname(host, 255);
    hostname = host;
    cwd_ = gkfs::path::get_sys_cwd();
    PreloadContext::set_replicas(
            std::stoi(gkfs::env::get_var(gkfs::env::NUM_REPL, "0")));
}