#ifndef __ZVFS_HOOK_RW_H__
#define __ZVFS_HOOK_RW_H__

#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <stdio.h>

/*
 * read / write 族。
 *
 * 所有变体最终收敛到两个内部实现：
 *   zvfs_pread_impl (fd, buf, count, offset)
 *   zvfs_pwrite_impl(fd, buf, count, offset)
 *
 * offset 语义：
 *   - pread/pwrite 系列：直接使用传入 offset，不修改 of->offset
 *   - read/write   系列：使用 of->offset，完成后更新
 *   - O_APPEND write    ：每次写前持 inode->mu 取 logical_size 作为 offset
 *
 * iov 系列（readv/writev/preadv/pwritev）：
 *   展开 iovec 后逐段调用 pread/pwrite impl，合并结果。
 *   这样不需要在 SPDK 层实现 scatter/gather，实现最简单。
 *   如果将来 SPDK 层支持 SGL 可以直接换掉这一层。
 */

/* read 族 */
ssize_t read(int fd, void *buf, size_t count);
ssize_t pread(int fd, void *buf, size_t count, off_t offset);
ssize_t pread64(int fd, void *buf, size_t count, off_t offset);
ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset);
ssize_t preadv64(int fd, const struct iovec *iov, int iovcnt, off_t offset);
ssize_t preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset,
                int flags);

/* write 族 */
ssize_t write(int fd, const void *buf, size_t count);
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
ssize_t pwrite64(int fd, const void *buf, size_t count, off_t offset);
ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset);
ssize_t pwritev64(int fd, const struct iovec *iov, int iovcnt, off_t offset);
ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset,
                 int flags);

/* glibc 别名 */
ssize_t __read(int fd, void *buf, size_t count);
ssize_t __libc_read(int fd, void *buf, size_t count);
ssize_t __read_nocancel(int fd, void *buf, size_t count);
ssize_t __pread64(int fd, void *buf, size_t count, off_t offset);
ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset);
ssize_t __pread64_nocancel(int fd, void *buf, size_t count, off_t offset);
ssize_t __read_chk(int fd, void *buf, size_t count, size_t buflen);
ssize_t __pread_chk(int fd, void *buf, size_t count, off_t offset, size_t buflen);
ssize_t __pread64_chk(int fd, void *buf, size_t count, off_t offset, size_t buflen);
ssize_t __write(int fd, const void *buf, size_t count);
ssize_t __libc_write(int fd, const void *buf, size_t count);
size_t fread_unlocked(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
int fscanf(FILE *stream, const char *format, ...);

#endif // __ZVFS_HOOK_RW_H__
