Verified Commit 1f95ba1d authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Add internal adafs_read function

Instead of using the more complex adafs_pread function now is possible
to use adafs_read when it is necessary to read starting from the current
file position
parent 95bd8b40
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ int adafs_dup2(int oldfd, int newfd);

ssize_t adafs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset);

ssize_t adafs_read(int fd, void* buf, size_t count);

ssize_t adafs_pread_ws(int fd, void* buf, size_t count, off64_t offset);

int adafs_opendir(const std::string& path);
+11 −0
Original line number Diff line number Diff line
@@ -309,6 +309,17 @@ ssize_t adafs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset) {
    return ret; // return written size or -1 as error
}

ssize_t adafs_read(int fd, void* buf, size_t count) {
            auto adafs_fd = CTX->file_map()->get(fd);
            auto pos = adafs_fd->pos(); //retrieve the current offset
            auto ret = adafs_pread_ws(fd, buf, count, pos);
            // Update offset in file descriptor in the file map
            if (ret > 0) {
                adafs_fd->pos(pos + ret);
            }
            return ret;
}

ssize_t adafs_pread_ws(int fd, void* buf, size_t count, off64_t offset) {
    init_ld_env_if_needed();
    auto adafs_fd = CTX->file_map()->get(fd);
+2 −12
Original line number Diff line number Diff line
@@ -189,12 +189,8 @@ size_t intcp_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) {
        auto fd = file_to_fd(stream);
        if (CTX->file_map()->exist(fd)) {
            CTX->log()->trace("{}() called with fd {}", __func__, fd);
            auto adafs_fd = CTX->file_map()->get(fd);
            auto pos = adafs_fd->pos(); //retrieve the current offset
            auto ret = adafs_pread_ws(fd, ptr, size*nmemb, pos);
            auto ret = adafs_read(fd, ptr, size*nmemb);
            if (ret > 0) {
                // Update offset in file descriptor in the file map
                adafs_fd->pos(pos + ret);
                return ret / size;
            }
            return ret;
@@ -916,13 +912,7 @@ ssize_t read(int fd, void* buf, size_t count) {
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called with fd {}, count {}", __func__, fd, count);
        if (CTX->file_map()->exist(fd)) {
            auto adafs_fd = CTX->file_map()->get(fd);
            auto pos = adafs_fd->pos(); //retrieve the current offset
            auto ret = adafs_pread_ws(fd, buf, count, pos);
            // Update offset in file descriptor in the file map
            if (ret > 0) {
                adafs_fd->pos(pos + ret);
            }
            auto ret = adafs_read(fd, buf, count);
            CTX->log()->trace("{}() returning {}", __func__, ret);
            return ret;
        }