Unverified Commit 082f4bbb authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

intercept statfs

parent 39d9fb59
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ int hook_readlinkat(int dirfd, const char * cpath, char * buf, int bufsiz);
int hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg);
int hook_renameat(int olddfd, const char * oldname, int newdfd, const char * newname,
                  unsigned int flags);
int hook_statfs(const char * path, struct statfs * buf);
int hook_fstatfs(unsigned int fd, struct statfs * buf);


#endif
+17 −0
Original line number Diff line number Diff line
@@ -626,3 +626,20 @@ int hook_renameat(int olddfd, const char * oldname,

   return syscall_no_intercept(SYS_renameat2, olddfd, oldpath_pass, newdfd, newpath_pass, flags);
}

int hook_statfs(const char * path, struct statfs * buf) {
    CTX->log()->trace("{}() called with path: {}", __func__, path);
    std::string rel_path;
    if (CTX->relativize_path(path, rel_path)) {
        return with_errno(adafs_statfs(buf));
    }
    return syscall_no_intercept(SYS_statfs, rel_path.c_str(), buf);
}

int hook_fstatfs(unsigned int fd, struct statfs * buf) {
    CTX->log()->trace("{}() called with fs: {}", __func__, fd);
    if (CTX->file_map()->exist(fd)) {
        return with_errno(adafs_statfs(buf));
    }
    return syscall_no_intercept(SYS_fstatfs, fd, buf);
}
+11 −1
Original line number Diff line number Diff line
@@ -286,6 +286,16 @@ static inline int hook(long syscall_number,
                                static_cast<unsigned int>(arg4));
        break;

    case SYS_fstatfs:
        *result = hook_fstatfs(static_cast<unsigned int>(arg0),
                               reinterpret_cast<struct statfs *>(arg1));
        break;

    case SYS_statfs:
        *result = hook_statfs(reinterpret_cast<const char *>(arg0),
                               reinterpret_cast<struct statfs *>(arg1));
        break;

    default:
        /*
         * Ignore any other syscalls