Loading ifs/include/preload/adafs_functions.hpp +4 −2 Original line number Diff line number Diff line Loading @@ -52,9 +52,11 @@ int adafs_dup(int oldfd); int adafs_dup2(int oldfd, int newfd); ssize_t adafs_write(int fd, void* buf, size_t count); ssize_t adafs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset); ssize_t adafs_pwrite_ws(int fd, const char * buf, size_t count, off64_t offset); ssize_t adafs_write(int fd, const char * buf, size_t count); ssize_t adafs_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset); ssize_t adafs_writev(int fd, const struct iovec * iov, int iovcnt); ssize_t adafs_read(int fd, void* buf, size_t count); Loading ifs/include/preload/hooks.hpp +5 −1 Original line number Diff line number Diff line Loading @@ -11,8 +11,12 @@ int hook_lstat(const char* path, struct stat* buf); int hook_fstat(unsigned int fd, struct stat* buf); int hook_fstatat(int dirfd, const char * cpath, struct stat * buf, int flags); int hook_read(unsigned int fd, void* buf, size_t count); int hook_write(unsigned int fd, void* buf, size_t count); int hook_pread(unsigned int fd, char * buf, size_t count, loff_t pos); int hook_write(unsigned int fd, const char * buf, size_t count); int hook_pwrite(unsigned int fd, const char * buf, size_t count, loff_t pos); int hook_writev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt); int hook_pwritev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt, unsigned long pos_l, unsigned long pos_h); int hook_unlinkat(int dirfd, const char * cpath, int flags); int hook_access(const char* path, int mask); int hook_faccessat(int dirfd, const char * cpath, int mode); Loading ifs/src/preload/adafs_functions.cpp +67 −22 Original line number Diff line number Diff line Loading @@ -304,20 +304,7 @@ int adafs_dup2(const int oldfd, const int newfd) { return CTX->file_map()->dup2(oldfd, newfd); } ssize_t adafs_write(int fd, void* buf, size_t count) { auto adafs_fd = CTX->file_map()->get(fd); auto pos = adafs_fd->pos(); //retrieve the current offset if (adafs_fd->get_flag(OpenFile_flags::append)) adafs_lseek(adafs_fd, 0, SEEK_END); auto ret = adafs_pwrite_ws(fd, buf, count, pos); // Update offset in file descriptor in the file map if (ret > 0) { adafs_fd->pos(pos + count); } return ret; } ssize_t adafs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset) { ssize_t adafs_pwrite_ws(int fd, const char * buf, size_t count, off64_t offset) { auto adafs_fd = CTX->file_map()->get(fd); auto path = make_shared<string>(adafs_fd->path()); CTX->log()->trace("{}() fd: {}, count: {}, offset: {}", __func__, fd, count, offset); Loading @@ -337,6 +324,64 @@ 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_write(int fd, const char * buf, size_t count) { auto adafs_fd = CTX->file_map()->get(fd); auto pos = adafs_fd->pos(); //retrieve the current offset if (adafs_fd->get_flag(OpenFile_flags::append)) adafs_lseek(adafs_fd, 0, SEEK_END); auto ret = adafs_pwrite_ws(fd, buf, count, pos); // Update offset in file descriptor in the file map if (ret > 0) { adafs_fd->pos(pos + count); } return ret; } ssize_t adafs_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset) { CTX->log()->trace("{}() called with fd {}, op num {}, offset {}", __func__, fd, iovcnt, offset); auto pos = offset; // keep truck of current position ssize_t written = 0; ssize_t ret; for (int i = 0; i < iovcnt; ++i) { auto count = (iov+i)->iov_len; if (count == 0) { continue; } auto buf = (iov+i)->iov_base; ret = adafs_pwrite_ws(fd, reinterpret_cast<char *>(buf), count, pos); if (ret == -1) { break; } written += ret; pos += ret; if (static_cast<size_t>(ret) < count) { break; } } if (written == 0) { return -1; } return written; } ssize_t adafs_writev(int fd, const struct iovec * iov, int iovcnt) { CTX->log()->trace("{}() called with fd {}, ops num {}", __func__, fd, iovcnt); auto adafs_fd = CTX->file_map()->get(fd); auto pos = adafs_fd->pos(); // retrieve the current offset auto ret = adafs_pwritev(fd, iov, iovcnt, pos); assert(ret != 0); if (ret < 0) { return -1; } adafs_fd->pos(pos + ret); return ret; } 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 Loading ifs/src/preload/hooks.cpp +34 −29 Original line number Diff line number Diff line Loading @@ -115,7 +115,17 @@ int hook_read(unsigned int fd, void* buf, size_t count) { return syscall_no_intercept(SYS_read, fd, buf, count); } int hook_write(unsigned int fd, void* buf, size_t count) { int hook_pread(unsigned int fd, char * buf, size_t count, loff_t pos) { CTX->log()->trace("{}() called with fd {}, count {}, pos {}", __func__, fd, count, pos); if (CTX->file_map()->exist(fd)) { return with_errno(adafs_pread_ws(fd, buf, count, pos)); } /* Since kernel 2.6: pread() became pread64(), and pwrite() became pwrite64(). */ return syscall_no_intercept(SYS_pread64, fd, buf, count, pos); } int hook_write(unsigned int fd, const char * buf, size_t count) { CTX->log()->trace("{}() called with fd {}, count {}", __func__, fd, count); if (CTX->file_map()->exist(fd)) { return with_errno(adafs_write(fd, buf, count)); Loading @@ -123,38 +133,33 @@ int hook_write(unsigned int fd, void* buf, size_t count) { return syscall_no_intercept(SYS_write, fd, buf, count); } int hook_writev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt) { CTX->log()->trace("{}() called with fd {}", __func__, fd); int hook_pwrite(unsigned int fd, const char * buf, size_t count, loff_t pos) { CTX->log()->trace("{}() called with fd {}, count {}, pos {}", __func__, fd, count, pos); if (CTX->file_map()->exist(fd)) { auto adafs_fd = CTX->file_map()->get(fd); auto pos = adafs_fd->pos(); // retrieve the current offset ssize_t written = 0; ssize_t ret; for (unsigned long i = 0; i < iovcnt; ++i){ auto count = (iov+i)->iov_len; if(count == 0) { continue; } auto buf = (iov+i)->iov_base; ret = adafs_pwrite_ws(fd, buf, count, pos); if(ret == -1) { break; return with_errno(adafs_pwrite_ws(fd, buf, count, pos)); } /* Since kernel 2.6: pread() became pread64(), and pwrite() became pwrite64(). */ return syscall_no_intercept(SYS_pwrite64, fd, buf, count, pos); } written += ret; pos += ret; if(static_cast<size_t>(ret) < count){ break; int hook_writev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt) { CTX->log()->trace("{}() called with fd {}, ops_num {}", __func__, fd, iovcnt); if (CTX->file_map()->exist(fd)) { return with_errno(adafs_writev(fd, iov, iovcnt)); } return syscall_no_intercept(SYS_writev, fd, iov, iovcnt); } if(written == 0){ return -1; } adafs_fd->pos(pos); return written; int hook_pwritev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt, unsigned long pos_l, unsigned long pos_h) { CTX->log()->trace("{}() called with fd {}, ops_num {}, low position {}," "high postion {}", __func__, fd, iovcnt, pos_l, pos_h); if (CTX->file_map()->exist(fd)) { CTX->log()->warn("{}() Not supported", __func__); return -ENOTSUP; } return syscall_no_intercept(SYS_writev, fd, iov, iovcnt); return syscall_no_intercept(SYS_pwritev, fd, iov, iovcnt); } int hook_unlinkat(int dirfd, const char * cpath, int flags) { Loading ifs/src/preload/intercept.cpp +22 −1 Original line number Diff line number Diff line Loading @@ -69,9 +69,22 @@ static inline int hook(long syscall_number, static_cast<size_t>(arg2)); break; case SYS_pread64: *result = hook_pread(static_cast<unsigned int>(arg0), reinterpret_cast<char *>(arg1), static_cast<size_t>(arg2), static_cast<loff_t>(arg3)); break; case SYS_pwrite64: *result = hook_pwrite(static_cast<unsigned int>(arg0), reinterpret_cast<const char *>(arg1), static_cast<size_t>(arg2), static_cast<loff_t>(arg3)); break; case SYS_write: *result = hook_write(static_cast<unsigned int>(arg0), reinterpret_cast<void*>(arg1), reinterpret_cast<const char *>(arg1), static_cast<size_t>(arg2)); break; Loading @@ -81,6 +94,14 @@ static inline int hook(long syscall_number, static_cast<unsigned long>(arg2)); break; case SYS_pwritev: *result = hook_pwritev(static_cast<unsigned long>(arg0), reinterpret_cast<const struct iovec *>(arg1), static_cast<unsigned long>(arg2), static_cast<unsigned long>(arg3), static_cast<unsigned long>(arg4)); break; case SYS_unlink: *result = hook_unlinkat(AT_FDCWD, reinterpret_cast<const char *>(arg0), Loading Loading
ifs/include/preload/adafs_functions.hpp +4 −2 Original line number Diff line number Diff line Loading @@ -52,9 +52,11 @@ int adafs_dup(int oldfd); int adafs_dup2(int oldfd, int newfd); ssize_t adafs_write(int fd, void* buf, size_t count); ssize_t adafs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset); ssize_t adafs_pwrite_ws(int fd, const char * buf, size_t count, off64_t offset); ssize_t adafs_write(int fd, const char * buf, size_t count); ssize_t adafs_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset); ssize_t adafs_writev(int fd, const struct iovec * iov, int iovcnt); ssize_t adafs_read(int fd, void* buf, size_t count); Loading
ifs/include/preload/hooks.hpp +5 −1 Original line number Diff line number Diff line Loading @@ -11,8 +11,12 @@ int hook_lstat(const char* path, struct stat* buf); int hook_fstat(unsigned int fd, struct stat* buf); int hook_fstatat(int dirfd, const char * cpath, struct stat * buf, int flags); int hook_read(unsigned int fd, void* buf, size_t count); int hook_write(unsigned int fd, void* buf, size_t count); int hook_pread(unsigned int fd, char * buf, size_t count, loff_t pos); int hook_write(unsigned int fd, const char * buf, size_t count); int hook_pwrite(unsigned int fd, const char * buf, size_t count, loff_t pos); int hook_writev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt); int hook_pwritev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt, unsigned long pos_l, unsigned long pos_h); int hook_unlinkat(int dirfd, const char * cpath, int flags); int hook_access(const char* path, int mask); int hook_faccessat(int dirfd, const char * cpath, int mode); Loading
ifs/src/preload/adafs_functions.cpp +67 −22 Original line number Diff line number Diff line Loading @@ -304,20 +304,7 @@ int adafs_dup2(const int oldfd, const int newfd) { return CTX->file_map()->dup2(oldfd, newfd); } ssize_t adafs_write(int fd, void* buf, size_t count) { auto adafs_fd = CTX->file_map()->get(fd); auto pos = adafs_fd->pos(); //retrieve the current offset if (adafs_fd->get_flag(OpenFile_flags::append)) adafs_lseek(adafs_fd, 0, SEEK_END); auto ret = adafs_pwrite_ws(fd, buf, count, pos); // Update offset in file descriptor in the file map if (ret > 0) { adafs_fd->pos(pos + count); } return ret; } ssize_t adafs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset) { ssize_t adafs_pwrite_ws(int fd, const char * buf, size_t count, off64_t offset) { auto adafs_fd = CTX->file_map()->get(fd); auto path = make_shared<string>(adafs_fd->path()); CTX->log()->trace("{}() fd: {}, count: {}, offset: {}", __func__, fd, count, offset); Loading @@ -337,6 +324,64 @@ 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_write(int fd, const char * buf, size_t count) { auto adafs_fd = CTX->file_map()->get(fd); auto pos = adafs_fd->pos(); //retrieve the current offset if (adafs_fd->get_flag(OpenFile_flags::append)) adafs_lseek(adafs_fd, 0, SEEK_END); auto ret = adafs_pwrite_ws(fd, buf, count, pos); // Update offset in file descriptor in the file map if (ret > 0) { adafs_fd->pos(pos + count); } return ret; } ssize_t adafs_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset) { CTX->log()->trace("{}() called with fd {}, op num {}, offset {}", __func__, fd, iovcnt, offset); auto pos = offset; // keep truck of current position ssize_t written = 0; ssize_t ret; for (int i = 0; i < iovcnt; ++i) { auto count = (iov+i)->iov_len; if (count == 0) { continue; } auto buf = (iov+i)->iov_base; ret = adafs_pwrite_ws(fd, reinterpret_cast<char *>(buf), count, pos); if (ret == -1) { break; } written += ret; pos += ret; if (static_cast<size_t>(ret) < count) { break; } } if (written == 0) { return -1; } return written; } ssize_t adafs_writev(int fd, const struct iovec * iov, int iovcnt) { CTX->log()->trace("{}() called with fd {}, ops num {}", __func__, fd, iovcnt); auto adafs_fd = CTX->file_map()->get(fd); auto pos = adafs_fd->pos(); // retrieve the current offset auto ret = adafs_pwritev(fd, iov, iovcnt, pos); assert(ret != 0); if (ret < 0) { return -1; } adafs_fd->pos(pos + ret); return ret; } 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 Loading
ifs/src/preload/hooks.cpp +34 −29 Original line number Diff line number Diff line Loading @@ -115,7 +115,17 @@ int hook_read(unsigned int fd, void* buf, size_t count) { return syscall_no_intercept(SYS_read, fd, buf, count); } int hook_write(unsigned int fd, void* buf, size_t count) { int hook_pread(unsigned int fd, char * buf, size_t count, loff_t pos) { CTX->log()->trace("{}() called with fd {}, count {}, pos {}", __func__, fd, count, pos); if (CTX->file_map()->exist(fd)) { return with_errno(adafs_pread_ws(fd, buf, count, pos)); } /* Since kernel 2.6: pread() became pread64(), and pwrite() became pwrite64(). */ return syscall_no_intercept(SYS_pread64, fd, buf, count, pos); } int hook_write(unsigned int fd, const char * buf, size_t count) { CTX->log()->trace("{}() called with fd {}, count {}", __func__, fd, count); if (CTX->file_map()->exist(fd)) { return with_errno(adafs_write(fd, buf, count)); Loading @@ -123,38 +133,33 @@ int hook_write(unsigned int fd, void* buf, size_t count) { return syscall_no_intercept(SYS_write, fd, buf, count); } int hook_writev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt) { CTX->log()->trace("{}() called with fd {}", __func__, fd); int hook_pwrite(unsigned int fd, const char * buf, size_t count, loff_t pos) { CTX->log()->trace("{}() called with fd {}, count {}, pos {}", __func__, fd, count, pos); if (CTX->file_map()->exist(fd)) { auto adafs_fd = CTX->file_map()->get(fd); auto pos = adafs_fd->pos(); // retrieve the current offset ssize_t written = 0; ssize_t ret; for (unsigned long i = 0; i < iovcnt; ++i){ auto count = (iov+i)->iov_len; if(count == 0) { continue; } auto buf = (iov+i)->iov_base; ret = adafs_pwrite_ws(fd, buf, count, pos); if(ret == -1) { break; return with_errno(adafs_pwrite_ws(fd, buf, count, pos)); } /* Since kernel 2.6: pread() became pread64(), and pwrite() became pwrite64(). */ return syscall_no_intercept(SYS_pwrite64, fd, buf, count, pos); } written += ret; pos += ret; if(static_cast<size_t>(ret) < count){ break; int hook_writev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt) { CTX->log()->trace("{}() called with fd {}, ops_num {}", __func__, fd, iovcnt); if (CTX->file_map()->exist(fd)) { return with_errno(adafs_writev(fd, iov, iovcnt)); } return syscall_no_intercept(SYS_writev, fd, iov, iovcnt); } if(written == 0){ return -1; } adafs_fd->pos(pos); return written; int hook_pwritev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt, unsigned long pos_l, unsigned long pos_h) { CTX->log()->trace("{}() called with fd {}, ops_num {}, low position {}," "high postion {}", __func__, fd, iovcnt, pos_l, pos_h); if (CTX->file_map()->exist(fd)) { CTX->log()->warn("{}() Not supported", __func__); return -ENOTSUP; } return syscall_no_intercept(SYS_writev, fd, iov, iovcnt); return syscall_no_intercept(SYS_pwritev, fd, iov, iovcnt); } int hook_unlinkat(int dirfd, const char * cpath, int flags) { Loading
ifs/src/preload/intercept.cpp +22 −1 Original line number Diff line number Diff line Loading @@ -69,9 +69,22 @@ static inline int hook(long syscall_number, static_cast<size_t>(arg2)); break; case SYS_pread64: *result = hook_pread(static_cast<unsigned int>(arg0), reinterpret_cast<char *>(arg1), static_cast<size_t>(arg2), static_cast<loff_t>(arg3)); break; case SYS_pwrite64: *result = hook_pwrite(static_cast<unsigned int>(arg0), reinterpret_cast<const char *>(arg1), static_cast<size_t>(arg2), static_cast<loff_t>(arg3)); break; case SYS_write: *result = hook_write(static_cast<unsigned int>(arg0), reinterpret_cast<void*>(arg1), reinterpret_cast<const char *>(arg1), static_cast<size_t>(arg2)); break; Loading @@ -81,6 +94,14 @@ static inline int hook(long syscall_number, static_cast<unsigned long>(arg2)); break; case SYS_pwritev: *result = hook_pwritev(static_cast<unsigned long>(arg0), reinterpret_cast<const struct iovec *>(arg1), static_cast<unsigned long>(arg2), static_cast<unsigned long>(arg3), static_cast<unsigned long>(arg4)); break; case SYS_unlink: *result = hook_unlinkat(AT_FDCWD, reinterpret_cast<const char *>(arg0), Loading