Unverified Commit e77d0fce authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

intercept truncate, ftruncate

parent 72dc750d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ int hook_pwritev(unsigned long fd, const struct iovec * iov, unsigned long iovcn
int hook_unlinkat(int dirfd, const char * cpath, int flags);
int hook_access(const char* path, int mask);
int hook_lseek(unsigned int fd, off_t offset, unsigned int whence);
int hook_truncate(const char *path, long length);
int hook_ftruncate(unsigned int fd, unsigned long length);
int hook_dup(unsigned int fd);
int hook_dup2(unsigned int oldfd, unsigned int newfd);
int hook_dup3(unsigned int oldfd, unsigned int newfd, int flags);
+19 −0
Original line number Diff line number Diff line
@@ -237,6 +237,24 @@ int hook_lseek(unsigned int fd, off_t offset, unsigned int whence) {
   return syscall_no_intercept(SYS_lseek, fd, offset, whence);
}

int hook_truncate(const char* path, long length) {
    CTX->log()->trace("{}() called with path: {}, offset: {}", __func__, path, length);
    std::string rel_path;
    if (CTX->relativize_path(path, rel_path)) {
        return with_errno(adafs_truncate(rel_path, length));
    }
    return syscall_no_intercept(SYS_truncate, rel_path.c_str(), length);
}

int hook_ftruncate(unsigned int fd, unsigned long length) {
    CTX->log()->trace("{}() called  [fd: {}, offset: {}]", __func__, fd, length);
    if (CTX->file_map()->exist(fd)) {
        auto path = CTX->file_map()->get(fd)->path();
        return with_errno(adafs_truncate(path, length));
    }
    return syscall_no_intercept(SYS_ftruncate, fd, length);
}

int hook_dup(unsigned int fd) {
    CTX->log()->trace("{}() called with oldfd {}", __func__, fd);
    if (CTX->file_map()->exist(fd)) {
@@ -296,6 +314,7 @@ int hook_mkdirat(int dirfd, const char * cpath, mode_t mode) {
    }
}

    std::string resolved;
int hook_chdir(const char * path) {
    CTX->log()->trace("{}() called with path '{}'", __func__, path);
    std::string rel_path;
+10 −0
Original line number Diff line number Diff line
@@ -138,6 +138,16 @@ static inline int hook(long syscall_number,
                             static_cast<unsigned int>(arg2));
        break;

    case SYS_truncate:
        *result = hook_truncate(reinterpret_cast<const char*>(arg0),
                                static_cast<long>(arg1));
        break;

    case SYS_ftruncate:
        *result = hook_ftruncate(static_cast<unsigned int>(arg0),
                                 static_cast<unsigned long>(arg1));
        break;

    case SYS_dup:
        *result = hook_dup(static_cast<unsigned int>(arg0));
        break;