Repository navigation
Fix O_APPEND, a getcwd() kernel panic, and console timestamps - #323
Merged
hexagonal-sun merged 3 commits intoOct 6, 2026
Merged
Conversation
Owner
|
LGTM! I fixed the clippy lint on |
ConsoleLogger printed `uptime.as_micros()` (total microseconds since boot) as the fractional part, so after the first second the timestamps are wrong, e.g. "[ 4.4015238]" instead of "[ 4.401523]". Use `subsec_micros()`, matching Linux's printk format.
OpenFlags::O_APPEND was defined but never checked, so every write went to the current file position. As a result, shell `>>` overwrote files instead of appending to them: / # echo a > /tmp/t; echo b >> /tmp/t; cat /tmp/t b RegFile::write now moves the cursor to the end of the file before each write when the file was opened with O_APPEND. writev goes through write, so it is covered too; pwrite keeps its explicit offset. Add a usertest that also checks that a seek before the write doesn't stop the append.
sys_getcwd returned KernelError::TooLarge when the cwd didn't fit in the user's buffer. TooLarge has no errno mapping, so kern_err_to_syscall() reached its `todo!()` and panicked the kernel. Any process could trigger this with getcwd(buf, 1). Return RangeError (ERANGE), which is what Linux returns in this case, and add a usertest.
Contributor
Author
|
Rebased onto master, thanks for the review! |
nrchnnas
force-pushed
the
fix/console-ts-o-append-getcwd
branch
from
October 6, 2026 05:02
256ff78 to
9a175b3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three small, independent fixes, found while running BusyBox on moss.
1.
fs: reg: honour O_APPENDBug:
OpenFlags::O_APPENDis defined but never checked, so every write goes to the current file position. As a result, shell>>overwrites the file instead of appending:Fix:
RegFile::writenow moves the cursor to the end of the file before each write when the file was opened withO_APPEND.writevgoes throughwrite, so it is covered too;pwritekeeps its explicit offset.Test: the new usertest
test_o_appendalso checks that seeking to 0 first doesn't stop the append.2.
fs: getcwd: return ERANGE when the buffer is too smallBug:
sys_getcwdreturnsKernelError::TooLarge. That has no errno mapping, sokern_err_to_syscall()reachestodo!(), and any process can panic the kernel withgetcwd(buf, 1):Fix: return
RangeError(ERANGE), which is what Linux returns in this case.Test: new usertest
test_getcwd_buffer_too_small.3.
console: fix the sub-second field of log timestampsBug: the console logger prints
uptime.as_micros(), the total microseconds, as the fractional part. After one second it prints[ 1.1737690](see the panic line above) instead of[ 1.173769].Fix: use
subsec_micros(), matching Linux's printk format.Testing
cargo fmt --all -- --checkpasses, and clippy reports nothing new in the changed files.cargo run -r -- --init /bin/usertestprintsAll tests passed, including both new tests.test_o_appendfails withleft: "third\n\n",right: "first\nsecond\nthird\n".