Loading include/client/hooks.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ int hook_stat(const char* path, struct stat* buf); int hook_read(int fd, void* buf, size_t count); int hook_write(int fd, void* buf, size_t count); int hook_unlink(const char* path); int hook_access(const char* path, int mask); int hook_lseek(unsigned int fd, off_t offset, unsigned int whence); #endif src/client/adafs_functions.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -244,12 +244,15 @@ off64_t adafs_lseek(int fd, off64_t offset, int whence) { off64_t adafs_lseek(shared_ptr<OpenFile> adafs_fd, off64_t offset, int whence) { switch (whence) { case SEEK_SET: CTX->log()->debug("{}() whence is SEEK_SET", __func__); adafs_fd->pos(offset); break; case SEEK_CUR: CTX->log()->debug("{}() whence is SEEK_CUR", __func__); adafs_fd->pos(adafs_fd->pos() + offset); break; case SEEK_END: { CTX->log()->debug("{}() whence is SEEK_END", __func__); off64_t file_size; auto err = rpc_send::get_metadentry_size(adafs_fd->path(), file_size); if (err < 0) { Loading @@ -260,14 +263,17 @@ off64_t adafs_lseek(shared_ptr<OpenFile> adafs_fd, off64_t offset, int whence) { break; } case SEEK_DATA: CTX->log()->warn("{}() SEEK_DATA whence is not supported", __func__); // We do not support this whence yet errno = EINVAL; return -1; case SEEK_HOLE: CTX->log()->warn("{}() SEEK_HOLE whence is not supported", __func__); // We do not support this whence yet errno = EINVAL; return -1; default: CTX->log()->warn("{}() unknown whence {}", __func__, whence); errno = EINVAL; return -1; } Loading src/client/hooks.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -109,3 +109,32 @@ int hook_unlink(const char* path) { } return syscall_no_intercept(SYS_unlink, rel_path.c_str()); } int hook_access(const char* path, int mask) { CTX->log()->trace("{}() called path '{}', mask {}", __func__, path, mask); std::string rel_path; if (CTX->relativize_path(path, rel_path)) { auto ret = adafs_access(rel_path, mask); if(ret < 0) { return -errno; } return ret; } return syscall_no_intercept(SYS_access, rel_path.c_str(), mask); } int hook_lseek(unsigned int fd, off_t offset, unsigned int whence) { CTX->log()->trace("{}() called with fd {}, offset {}, whence {}", __func__, fd, offset, whence); if (CTX->file_map()->exist(fd)) { auto off_ret = adafs_lseek(fd, static_cast<off64_t>(offset), whence); if (off_ret > std::numeric_limits<off_t>::max()) { return -EOVERFLOW; } else if(off_ret < 0) { return -errno; } CTX->log()->trace("{}() returning {}", __func__, off_ret); return off_ret; } return syscall_no_intercept(SYS_lseek, fd, offset, whence); } src/client/intercept.cpp +11 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,17 @@ static inline int hook(long syscall_number, *result = hook_unlink(reinterpret_cast<char*>(arg0)); break; default: case SYS_access: *result = hook_access(reinterpret_cast<char*>(arg0), static_cast<int>(arg1)); break; case SYS_lseek: *result = hook_lseek(static_cast<unsigned int>(arg0), static_cast<off_t>(arg1), static_cast<unsigned int>(arg2)); break; /* * Ignore any other syscalls * i.e.: pass them on to the kernel Loading Loading
include/client/hooks.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ int hook_stat(const char* path, struct stat* buf); int hook_read(int fd, void* buf, size_t count); int hook_write(int fd, void* buf, size_t count); int hook_unlink(const char* path); int hook_access(const char* path, int mask); int hook_lseek(unsigned int fd, off_t offset, unsigned int whence); #endif
src/client/adafs_functions.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -244,12 +244,15 @@ off64_t adafs_lseek(int fd, off64_t offset, int whence) { off64_t adafs_lseek(shared_ptr<OpenFile> adafs_fd, off64_t offset, int whence) { switch (whence) { case SEEK_SET: CTX->log()->debug("{}() whence is SEEK_SET", __func__); adafs_fd->pos(offset); break; case SEEK_CUR: CTX->log()->debug("{}() whence is SEEK_CUR", __func__); adafs_fd->pos(adafs_fd->pos() + offset); break; case SEEK_END: { CTX->log()->debug("{}() whence is SEEK_END", __func__); off64_t file_size; auto err = rpc_send::get_metadentry_size(adafs_fd->path(), file_size); if (err < 0) { Loading @@ -260,14 +263,17 @@ off64_t adafs_lseek(shared_ptr<OpenFile> adafs_fd, off64_t offset, int whence) { break; } case SEEK_DATA: CTX->log()->warn("{}() SEEK_DATA whence is not supported", __func__); // We do not support this whence yet errno = EINVAL; return -1; case SEEK_HOLE: CTX->log()->warn("{}() SEEK_HOLE whence is not supported", __func__); // We do not support this whence yet errno = EINVAL; return -1; default: CTX->log()->warn("{}() unknown whence {}", __func__, whence); errno = EINVAL; return -1; } Loading
src/client/hooks.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -109,3 +109,32 @@ int hook_unlink(const char* path) { } return syscall_no_intercept(SYS_unlink, rel_path.c_str()); } int hook_access(const char* path, int mask) { CTX->log()->trace("{}() called path '{}', mask {}", __func__, path, mask); std::string rel_path; if (CTX->relativize_path(path, rel_path)) { auto ret = adafs_access(rel_path, mask); if(ret < 0) { return -errno; } return ret; } return syscall_no_intercept(SYS_access, rel_path.c_str(), mask); } int hook_lseek(unsigned int fd, off_t offset, unsigned int whence) { CTX->log()->trace("{}() called with fd {}, offset {}, whence {}", __func__, fd, offset, whence); if (CTX->file_map()->exist(fd)) { auto off_ret = adafs_lseek(fd, static_cast<off64_t>(offset), whence); if (off_ret > std::numeric_limits<off_t>::max()) { return -EOVERFLOW; } else if(off_ret < 0) { return -errno; } CTX->log()->trace("{}() returning {}", __func__, off_ret); return off_ret; } return syscall_no_intercept(SYS_lseek, fd, offset, whence); }
src/client/intercept.cpp +11 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,17 @@ static inline int hook(long syscall_number, *result = hook_unlink(reinterpret_cast<char*>(arg0)); break; default: case SYS_access: *result = hook_access(reinterpret_cast<char*>(arg0), static_cast<int>(arg1)); break; case SYS_lseek: *result = hook_lseek(static_cast<unsigned int>(arg0), static_cast<off_t>(arg1), static_cast<unsigned int>(arg2)); break; /* * Ignore any other syscalls * i.e.: pass them on to the kernel Loading