Loading ifs/include/preload/hooks.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,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); Loading ifs/src/preload/hooks.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -224,6 +224,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)) { Loading Loading @@ -283,6 +301,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; Loading ifs/src/preload/intercept.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,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; Loading Loading
ifs/include/preload/hooks.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,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); Loading
ifs/src/preload/hooks.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -224,6 +224,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)) { Loading Loading @@ -283,6 +301,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; Loading
ifs/src/preload/intercept.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,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; Loading