kernel/fs: fix previous commit logic
fix #16598 Change-Id: Ie34c1563bd34dbe9c6cda92e41a2d5a96d20c3b1 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3383 Reviewed-by: Jacob Secunda <[email protected]> Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
+11
-12
@@ -748,7 +748,7 @@ common_user_io(int fd, off_t pos, void* buffer, size_t length, bool write)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool movePosition = false;
|
bool movePosition = false;
|
||||||
if (pos == -1 && (!write || (descriptor->open_mode & O_APPEND) == 0)) {
|
if (pos == -1) {
|
||||||
pos = descriptor->pos;
|
pos = descriptor->pos;
|
||||||
movePosition = true;
|
movePosition = true;
|
||||||
}
|
}
|
||||||
@@ -768,10 +768,10 @@ common_user_io(int fd, off_t pos, void* buffer, size_t length, bool write)
|
|||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
if (movePosition)
|
if (movePosition) {
|
||||||
descriptor->pos = pos + length;
|
descriptor->pos = write && (descriptor->open_mode & O_APPEND) != 0
|
||||||
else if (pos == -1)
|
? descriptor->ops->fd_seek(descriptor, 0, SEEK_END) : pos + length;
|
||||||
descriptor->pos = descriptor->ops->fd_seek(descriptor, 0, SEEK_END);
|
}
|
||||||
|
|
||||||
return length <= SSIZE_MAX ? (ssize_t)length : SSIZE_MAX;
|
return length <= SSIZE_MAX ? (ssize_t)length : SSIZE_MAX;
|
||||||
}
|
}
|
||||||
@@ -810,7 +810,7 @@ common_user_vector_io(int fd, off_t pos, const iovec* userVecs, size_t count,
|
|||||||
return B_BAD_ADDRESS;
|
return B_BAD_ADDRESS;
|
||||||
|
|
||||||
bool movePosition = false;
|
bool movePosition = false;
|
||||||
if (pos == -1 && (!write || (descriptor->open_mode & O_APPEND) == 0)) {
|
if (pos == -1) {
|
||||||
pos = descriptor->pos;
|
pos = descriptor->pos;
|
||||||
movePosition = true;
|
movePosition = true;
|
||||||
}
|
}
|
||||||
@@ -854,17 +854,16 @@ common_user_vector_io(int fd, off_t pos, const iovec* userVecs, size_t count,
|
|||||||
else
|
else
|
||||||
bytesTransferred += (ssize_t)length;
|
bytesTransferred += (ssize_t)length;
|
||||||
|
|
||||||
if (pos > -1)
|
pos += length;
|
||||||
pos += length;
|
|
||||||
|
|
||||||
if (length < vecs[i].iov_len)
|
if (length < vecs[i].iov_len)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (movePosition)
|
if (movePosition) {
|
||||||
descriptor->pos = pos;
|
descriptor->pos = write && (descriptor->open_mode & O_APPEND) != 0
|
||||||
else if (pos == -1)
|
? descriptor->ops->fd_seek(descriptor, 0, SEEK_END) : pos;
|
||||||
descriptor->pos = descriptor->ops->fd_seek(descriptor, 0, SEEK_END);
|
}
|
||||||
|
|
||||||
return bytesTransferred;
|
return bytesTransferred;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user