diff options
| author | salmonik <salmonik@tuta.io> | 2026-08-01 14:09:14 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-08-01 14:09:14 +0200 |
| commit | c7540c31d45dac68fa1852f5d25645d569b2da9d (patch) | |
| tree | c102aacb40f99d4f9bb87ab2a996cb08df0dfae0 /rsnix/src/fs.rs | |
| parent | shell: cat <path> TIL <marker> sugar + precise ordering errors (diff) | |
| download | rs-dos-c7540c31d45dac68fa1852f5d25645d569b2da9d.tar.gz rs-dos-c7540c31d45dac68fa1852f5d25645d569b2da9d.zip | |
klog: kernel log ring + /dev/klog + klog shell command
- rsnix/src/klog.rs: RAM ring of the last 128 serial log lines (128
chars each), fed by serial_println! so every boot/low-level message
is captured for free. Sequence numbers per line, wrap/drop
accounting; the ring never allocates (const-constructible static).
- /dev/klog char device; shell 'klog' is a thin alias for cat
/dev/klog with the same filters/redirection, so 'klog -t 5',
'klog -g fat' and 'klog WRITING /disk/.../boot.log' all work.
klog rejects positional args (usage) and input keywords.
- Shell user-facing output (banner, prompt, term_print/term_println,
pipeline sink, halt/poweroff) now writes to serial directly instead
of through serial_println!, keeping echo/cat output out of the boot
log (a streaming cat /dev/mem would otherwise wrap the ring).
- serial_println! macro hooks klog::append_fmt via format_args! (no
alloc at call sites); klog::dump formats the log for the device.
Verified in QEMU: 28 boot lines captured (seq 0..27), shell output
absent from the ring, klog WRITING persists a boot log (mtype-checked),
wrap verified with a temporary 140-line boot loop (128 kept / 40
dropped, seq 40..167, oldest-live correct; loop reverted); full
test-disk round trip still fsck-clean.
Diffstat (limited to '')
| -rw-r--r-- | rsnix/src/fs.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/rsnix/src/fs.rs b/rsnix/src/fs.rs index a71e51a..063560a 100644 --- a/rsnix/src/fs.rs +++ b/rsnix/src/fs.rs | |||
| @@ -41,6 +41,7 @@ enum CharDevice { | |||
| 41 | Pci, | 41 | Pci, |
| 42 | Version, | 42 | Version, |
| 43 | Meminfo, | 43 | Meminfo, |
| 44 | Klog, | ||
| 44 | Null, | 45 | Null, |
| 45 | Zero, | 46 | Zero, |
| 46 | Console, | 47 | Console, |
| @@ -141,6 +142,12 @@ pub fn init() -> (usize, usize) { | |||
| 141 | NodeData::Char(CharDevice::Meminfo), | 142 | NodeData::Char(CharDevice::Meminfo), |
| 142 | ); | 143 | ); |
| 143 | add( | 144 | add( |
| 145 | "klog", | ||
| 146 | Some(dev), | ||
| 147 | FileType::Char, | ||
| 148 | NodeData::Char(CharDevice::Klog), | ||
| 149 | ); | ||
| 150 | add( | ||
| 144 | "null", | 151 | "null", |
| 145 | Some(dev), | 152 | Some(dev), |
| 146 | FileType::Char, | 153 | FileType::Char, |
| @@ -650,6 +657,7 @@ fn dev_text(dev: CharDevice, _pos: u64) -> String { | |||
| 650 | CharDevice::Pci => pci_listing(), | 657 | CharDevice::Pci => pci_listing(), |
| 651 | CharDevice::Version => version_text(), | 658 | CharDevice::Version => version_text(), |
| 652 | CharDevice::Meminfo => meminfo_text(), | 659 | CharDevice::Meminfo => meminfo_text(), |
| 660 | CharDevice::Klog => crate::klog::dump(), | ||
| 653 | CharDevice::Null | CharDevice::Console | CharDevice::Serial => String::new(), | 661 | CharDevice::Null | CharDevice::Console | CharDevice::Serial => String::new(), |
| 654 | CharDevice::Zero => String::new(), | 662 | CharDevice::Zero => String::new(), |
| 655 | } | 663 | } |
