stdio/file: fix ftell_unlocked use of lseek - #536
julianuziemblo wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies ftell_unlocked in stdio/file.c to conditionally use SEEK_END or SEEK_CUR based on whether the stream is in append mode and has buffered data. However, the current condition stream->bufpos != stream->bufeof is problematic as it can cause incorrect offsets during read operations or when transitioning from reading to writing. It is recommended to instead check if the stream is in writing mode and has buffered write data.
When the file mode is O_APPEND and we're writing, we have to seek to the end of the file backing the stream. Tangently-related to phoenix-rtos/phoenix-rtos-project#1403, as a test disabled by this issue was not passing due to this bug. YT: RTOS-1474
c700ed3 to
d54a5e6
Compare
|
this should probably be fixed in kernel, as calling |
This is a fix to buffered writing in append mode, kernel has no idea about buffered I/O. If you mean a fix to concurrent writing in O_APPEND, it's done in other commits, attached to the related phoenix-rtos/phoenix-rtos-project#1403 |
what I'm hinting at - is that's not enough. In other PRs (concurrent appending) You're changing the The proper fix would be to either pass the value back to kernel or make kernel re-read it after updating (or maybe . Implementing it properly on kernel side would make this change not needed ( I think there are some problems with the files opened with O_RDWR ( IMHO:
|
nalajcie
left a comment
There was a problem hiding this comment.
as per my comment, this will break "a+" streams
yes, I'll be adding this shortly as I came to the same conclussion concurrently 😛
I will check it more thouroughly then and try to fix the cases and add more tests for them. |
This is false - doing |
Ack, still the fix is incomplete without tracking consistently when we have something in the buffer and when not (sometimes it's only F_WRITING, somethimes with bufpos, etc.) |
6b1a205 to
8c724a5
Compare
YT: RTOS-1474
8c724a5 to
48c4390
Compare
When the file mode is
O_APPENDand we're writing, we have to seek to the end of the file backing the stream.This PR also handles all places where we should exit the writing mode, e.g.
fflush,fseek, etc.Tangently-related to phoenix-rtos/phoenix-rtos-project#1403, as a test disabled by this issue was not passing due to this bug.
YT: RTOS-1474
Description
Motivation and Context
Types of changes
How Has This Been Tested?
Checklist:
Special treatment