danos/system/services
Daniel Samson f52c591f5e
Persist the kernel boot log to the USB FAT volume
On a headless or real board nothing captures serial, so the boot log — the whole
diagnostic stream — is lost at power-off. This retains it in the kernel and copies
it to the boot USB volume as /mnt/usb/DANOS.LOG, the on-disk equivalent of QEMU's
`-serial file:`. Pull the stick, read DANOS.LOG on another machine.

How it fits together:
- Kernel RAM sink (log.zig): a fixed 256 KiB in-image buffer registered as a log
  sink in kmain, right after serial. Because userspace debug_write funnels through
  log.write, it captures the entire stream — kernel lines and every service's
  output — from the first line. Fills linearly and stops when full (earliest boot
  output, the most valuable, is kept); no allocation, so it is panic-safe.
- klog_read syscall (32): copies that buffer out to a user buffer, the mirror of
  debug_write — same overflow-safe user-half bounds check, kernel -> user copy,
  under the kernel lock so the snapshot can't grow mid-copy. Wrapped by
  runtime.system.klogRead.
- log-flush (new one-shot, in the initial-ramdisk): waits for the fat server to
  mount /mnt/usb, then copies the whole log to /mnt/usb/DANOS.LOG. init spawns it
  once the boot services are up (fire-and-forget; it polls the mount itself). If
  no volume is mounted — no stick, or the no-VFS ramdisk sweep — it exits silently.
- init shutdown flush: init repeats the copy inline at the top of shutDown(),
  BEFORE it tears down the storage services (the fat server is stopped first), so
  a clean poweroff captures the fullest log while /mnt/usb is still writable.
- unistd.writeAll: loops write() past the 224-byte VFS payload cap; both flush
  paths use it.

The filename is 8.3 (DANOS.LOG) at the mount root — the FAT short-name rule, and
there is no mkdir on the FAT path yet. Extend-only writes mean the two same-session
flushes never leave stale bytes (the shutdown log is a superset of the boot log);
a shorter log on a later boot of the same stick can leave a stale tail — a noted,
cosmetic limitation, not worth pulling O_TRUNC into the FAT write path for now.

Verified end to end under QEMU: a new `log-flush` case (reusing the orderly-shutdown
build) asserts both markers then S5, and DANOS.LOG is read back out of the image
afterwards (11804 bytes, containing the kernel init line, the FAT mount line, and
the boot flush marker). Regression stays green: zig build, zig build test, zig
build check-fat-image, and a sequential QEMU sweep — smoke, init, initial-ramdisk
(log-flush silent in the bare sweep), orderly-shutdown, fat-mount, usb-storage,
usb-hid, vfs, input, device-manager, process, signals, dma, fault-pf.
2026-07-13 18:18:34 +01:00
..
acpi Add runtime.time, drop demo drivers, harden TSC timekeeping 2026-07-13 11:56:43 +01:00
args-echo Pass arguments to main via runtime.process.Init, dispatched on signature 2026-07-11 14:22:48 +01:00
block USB driver stack: xHCI transfers, HID keyboard/mouse, mass storage 2026-07-13 14:11:00 +01:00
crash-test The device manager supervises: hello, backoff, and the crash-loop cap (M18.1) 2026-07-13 00:19:30 +01:00
device-list The application surface: enumerate, subscribe, and device-list (M18.3) 2026-07-13 00:49:03 +01:00
device-manager USB driver stack: xHCI transfers, HID keyboard/mouse, mass storage 2026-07-13 14:11:00 +01:00
fat M6: FAT read/write filesystem server, mounted into the VFS 2026-07-13 15:05:53 +01:00
fdt Add runtime.time, drop demo drivers, harden TSC timekeeping 2026-07-13 11:56:43 +01:00
init Persist the kernel boot log to the USB FAT volume 2026-07-13 18:18:34 +01:00
input fix / debug 2026-07-13 05:41:05 +01:00
input-source Generalize input module to mouse and joystick/gamepad events 2026-07-11 15:21:09 +01:00
input-test Generalize input module to mouse and joystick/gamepad events 2026-07-11 15:21:09 +01:00
log-flush Persist the kernel boot log to the USB FAT volume 2026-07-13 18:18:34 +01:00
power Add runtime.time, drop demo drivers, harden TSC timekeeping 2026-07-13 11:56:43 +01:00
process-test The application surface: enumerate, subscribe, and device-list (M18.3) 2026-07-13 00:49:03 +01:00
vfs M6: FAT read/write filesystem server, mounted into the VFS 2026-07-13 15:05:53 +01:00