hrev54697 adds 1 changeset to branch 'master'
old head: b48159dce258fda4a5e570ff3485be0079e6e25f
new head: 26ab0d051c56a0cf0b0b80db465d13b8a5a4fa60
overview:
https://git.haiku-os.org/haiku/log/?qt=range&q=26ab0d051c56+%5Eb48159dce258
----------------------------------------------------------------------------
26ab0d051c56: kernel/fs: update position when user writing with O_APPEND
when appending, pos is passed unchanged to the write hook.
fix #16506
Change-Id: I102e8e00e635d7a32cf50f09d8bd3d28dc235f9b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3373
Reviewed-by: Jérôme Duval <jerome.duval@xxxxxxxxx>
[ Jérôme Duval <jerome.duval@xxxxxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev54697
Commit: 26ab0d051c56a0cf0b0b80db465d13b8a5a4fa60
URL: https://git.haiku-os.org/haiku/commit/?id=26ab0d051c56
Author: Jérôme Duval <jerome.duval@xxxxxxxxx>
Date: Sat Oct 31 13:51:28 2020 UTC
Ticket: https://dev.haiku-os.org/ticket/16506
----------------------------------------------------------------------------
1 file changed, 8 insertions(+), 3 deletions(-)
src/system/kernel/fs/fd.cpp | 11 ++++++++---
----------------------------------------------------------------------------
diff --git a/src/system/kernel/fs/fd.cpp b/src/system/kernel/fs/fd.cpp
index 91fe26c08b..ac94ff77e3 100644
--- a/src/system/kernel/fs/fd.cpp
+++ b/src/system/kernel/fs/fd.cpp
@@ -748,7 +748,7 @@ common_user_io(int fd, off_t pos, void* buffer, size_t
length, bool write)
}
bool movePosition = false;
- if (pos == -1) {
+ if (pos == -1 && (!write || (descriptor->open_mode & O_APPEND) == 0)) {
pos = descriptor->pos;
movePosition = true;
}
@@ -770,6 +770,8 @@ common_user_io(int fd, off_t pos, void* buffer, size_t
length, bool write)
if (movePosition)
descriptor->pos = pos + length;
+ else if (pos == -1)
+ descriptor->pos = descriptor->ops->fd_seek(descriptor, 0,
SEEK_END);
return length <= SSIZE_MAX ? (ssize_t)length : SSIZE_MAX;
}
@@ -808,7 +810,7 @@ common_user_vector_io(int fd, off_t pos, const iovec*
userVecs, size_t count,
return B_BAD_ADDRESS;
bool movePosition = false;
- if (pos == -1) {
+ if (pos == -1 && (!write || (descriptor->open_mode & O_APPEND) == 0)) {
pos = descriptor->pos;
movePosition = true;
}
@@ -852,7 +854,8 @@ common_user_vector_io(int fd, off_t pos, const iovec*
userVecs, size_t count,
else
bytesTransferred += (ssize_t)length;
- pos += length;
+ if (pos > -1)
+ pos += length;
if (length < vecs[i].iov_len)
break;
@@ -860,6 +863,8 @@ common_user_vector_io(int fd, off_t pos, const iovec*
userVecs, size_t count,
if (movePosition)
descriptor->pos = pos;
+ else if (pos == -1)
+ descriptor->pos = descriptor->ops->fd_seek(descriptor, 0,
SEEK_END);
return bytesTransferred;
}