From bd04f4bfa621f003e34cf8d8cd0523f505917f67 Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Sat, 3 Nov 2012 18:12:39 +0100 Subject: [PATCH] LD_ISCSI add pwite --- src/ld_iscsi.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ld_iscsi.c b/src/ld_iscsi.c index 7d2d5d6..7a740f2 100644 --- a/src/ld_iscsi.c +++ b/src/ld_iscsi.c @@ -488,6 +488,26 @@ ssize_t write(int fd, const void *buf, size_t count) return real_write(fd, buf, count); } +ssize_t (*real_pwrite)(int fd, const void *buf, size_t count, off_t offset); +ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) { + if ((iscsi_fd_list[fd].is_iscsi == 1 && iscsi_fd_list[fd].in_flight == 0)) { + off_t old_offset; + if ((old_offset = lseek(fd, 0, SEEK_CUR)) < 0) { + errno = EIO; + return -1; + } + if (lseek(fd, offset, SEEK_SET) < 0) { + return -1; + } + if (write(fd, buf, count) < 0) { + lseek(fd, old_offset, SEEK_SET); + return -1; + } + lseek(fd, old_offset, SEEK_SET); + return count; + } + return real_pwrite(fd, buf, count, offset); +} int (*real_dup2)(int oldfd, int newfd);