Commit 7128c21a authored by Marc Vef's avatar Marc Vef
Browse files

Preload: added fsync, fdatasync interception and passthrough

parent 3f13be30
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ extern void* libc_pread64;

extern void* libc_lseek;
extern void* libc_lseek64;
extern void* libc_fsync;
extern void* libc_fdatasync;

extern void* libc_truncate;
extern void* libc_ftruncate;
+18 −0
Original line number Diff line number Diff line
@@ -363,6 +363,24 @@ off64_t lseek64(int fd, off64_t offset, int whence) __THROW {
    return (reinterpret_cast<decltype(&lseek64)>(libc_lseek64))(fd, offset, whence);
}

int fsync(int fd) {
    init_passthrough_if_needed();
    if (ld_is_aux_loaded() && file_map.exist(fd)) {
        ld_logger->trace("{}() called with fd {} path {}", __func__, fd, file_map.get(fd)->path());
        return 0; // This is a noop for us atm. fsync is called implicitly because each chunk is closed after access
    }
    return (reinterpret_cast<decltype(&fsync)>(libc_fsync))(fd);
}

int fdatasync(int fd) {
    init_passthrough_if_needed();
    if (ld_is_aux_loaded() && file_map.exist(fd)) {
        ld_logger->trace("{}() called with fd {} path {}", __func__, fd, file_map.get(fd)->path());
        return 0; // This is a noop for us atm. fsync is called implicitly because each chunk is closed after access
    }
    return (reinterpret_cast<decltype(&fdatasync)>(libc_fdatasync))(fd);
}

int truncate(const char* path, off_t length) __THROW {
    init_passthrough_if_needed();
    return (reinterpret_cast<decltype(&truncate)>(libc_truncate))(path, length);
+5 −0
Original line number Diff line number Diff line
@@ -53,6 +53,9 @@ void* libc_pread64;
void* libc_lseek;
void* libc_lseek64;

void* libc_fsync;
void* libc_fdatasync;

void* libc_truncate;
void* libc_ftruncate;

@@ -101,6 +104,8 @@ void init_passthrough_() {

    libc_lseek = dlsym(libc, "lseek");
    libc_lseek64 = dlsym(libc, "lseek64");
    libc_fsync = dlsym(libc, "fsync");
    libc_fdatasync = dlsym(libc, "fdatasync");

    libc_truncate = dlsym(libc, "truncate");
    libc_ftruncate = dlsym(libc, "ftruncate");