Repository navigation
usb: USB mass storage S1 (BOT/SCSI, block nodes, /dev/uevent v2, mount/2) - #170
Merged
Merged
Conversation
Add the transport half of USB mass storage: xHCI enumerates Bulk-Only Transport interfaces (class 8/subclass 6/protocol 0x50), GET_MAX_LUN, and a synchronous BOT command path (CBW 31 B, data stage, CSW 13 B, STALL/Reset Recovery, 30 s CSW wait), plus the SCSI commands Phase 1 needs (TUR, INQUIRY, READ CAPACITY(10), READ/WRITE(10), REQUEST SENSE, SYNCHRONIZE CACHE(10)). 4K logical blocks and >2 TiB capacities are refused explicitly with a reason, never truncated. A separate usb-storage thread runs probe and partition registration after poll() releases CONTROLLER: spinlocks are not reentrant, so BOT commands cannot run inside the port poll. Devices get monotonic usbN names that are never reused; hot-unplug is detected from PORTSC.CCS and marks the channel dead before the slot is released, so open descriptors get EIO instead of talking to a vanished endpoint. Pure wire/SCSI layouts live in usb_msc_proto.rs/usb_scsi.rs and are covered by host tests; QEMU usb-storage with a kernel-formatted GPT image enumerates usb0, reads INQUIRY/capacity, and shows usb0p1 as ext2.
Complete the kernel half of USB mass storage S1. S1b/S1c/S1d share one commit because procfs, VFS and the syscall layer are the same plumbing: splitting them would leave non-building intermediate trees. S1b: partitions (GPT/MBR) are reused from drivers::partition as usbNpM; usbN is monotonic and never reused; /proc/partitions renders DeviceManager (major 240, 16*N+M) and read-only /dev/block/<name> gives diagnostics without a raw write path that could bypass the WAL. GPT unique GUIDs and ext2 s_uuid/s_volume_name feed the event uuid/label fields. S1c: /dev/uevent v2 is a fixed 144-byte record (usb_uevent_abi, exact offset/version host tests) with a 256-entry ring, seq monotonic live events and seq=0 snapshots on open and PUEV_IOC_SNAPSHOT (0x5501). Open is exclusive (second reader EBUSY); read(count>=144) returns exactly one record, count<144 is EINVAL; poll returns POLLIN iff the ring is non-empty. ADD/REMOVE/CHANGE/ERROR/MOUNTED/UNMOUNTED carry mount[16] and uuid[16]. S1d: mount(2) nr 165 and umount2(2) nr 166 (ABI 168->170, SUPPORTED + independent EXPECTED). Root-only, ext2 only, source usbN/usbNpM, target exactly "/"+source and <=15 bytes (longer -> ENAMETOOLONG + bad_mount). Only a pagh volume mounts: mount_fs writes group descriptors and reserves the WAL, so foreign ext2 stays visible but EINVAL. umount2 does a busy scan of all fd tables, flushes with SYNCHRONIZE CACHE(10), and on surprise removal detaches with EIO + unclean, leaving safe_to_remove=0; MNT_FORCE is accepted only on a dead device. WAL replay happens in mount_fs and fails closed. ROOT_KEEPING_COMPONENTS gains the usb-prefix rule so /usb0p1 is not rewritten to /mnt/usb0p1; the boot /mnt flow is unchanged and the kernel never auto-mounts. Hot-unplug marks the channel dead before the slot is released, unregisters the block names, keeps a stale record until umount2 so UNMOUNTED can be emitted, and reuses the same storage thread for REMOVE. In-QEMU selftest covers the pure BOT/SCSI/uevent layouts and the /usb path rule. tools/usb_probe.c is the freestanding ring-3 probe for acceptance. QEMU usb-storage: 46/46 checks (mount/write/read/statfs, busy EBUSY, clean and surprise unmount, EBUSY/EBUSY, monotonic usb1/usb2/usb3 across QMP device_del/device_add, open-fd EIO after unplug, MNT_FORCE, WAL replay after surprise, bad target EINVAL). Host tests 872/0; six gates green.
A failed SYNCHRONIZE CACHE during umount2 keeps the mount in place (that was already true), but the event only carried error=flush_failed. The volume's durability is unproven until the next flush/replay, so mark it unclean and keep safe_to_remove=0; otherwise a UI reads a stale clean state after a failed eject.
Sync with dev=f76444c5 (#169 terminal full shell, tinygl PR3, VT routing). Conflict: src/test.rs appended routines at the same place. Kept both — the #169 terminal-session registry-command routine and the USB S1 BOT/SCSI/ uevent layout routine — so the merged suite runs 124 routines. Everything else auto-merged. USB S1 files (xhci/usb_msc/usb_scsi/usb_msc_proto/ usb_storage/usb_uevent*/vfs block nodes/mount syscalls) are untouched by #169; #169's VT/session/shell routing changes are preserved verbatim. Verified after merge: gates 6/6, QEMU usb-storage 46/46, release-kernel selftest 124 routines / 0 failed / 1 skipped (NVMe absent).
Sync with dev=e7f2bdc3 (#169 VT/session routing, #173 tinygl PR5, #174 vtfb1 respawn, docs). Conflicts, both at appended/summary text: - AGENTS.md: kept the USB S1 description for this branch (S1 is present here) and stated explicitly that it reaches dev only after this PR; #169/#173/#174 prose is kept verbatim. - src/test.rs: kept BOTH the new #174 "desktop-b::/dev/vtfb1 respawn after session exit (device path)" and the USB "usb::BOT/SCSI/uevent layouts and /usb root rule" routines. All USB S1 files (xhci/usb_msc/usb_scsi/usb_msc_proto/usb_storage/ usb_uevent*/vfs block nodes/mount syscalls) are untouched by dev; the dev-side terminal/tinygl/respawn changes are preserved. Post-merge evidence: gates 6/6 (host 872/0), QEMU usb-storage acceptance 46/46, release-kernel selftest 125 routines / 0 failed / 1 skipped (NVMe absent).
Sync with dev=c1e80933 (#147/#175/#176/#178: console grid from real framebuffer, scrollback/selection, rubberband fullscreen, os-identity, docs). Conflict: src/test.rs only — both sides appended routines/modules at the same two places. Resolution keeps BOTH: - dev qbug2 "console::text grid matches the framebuffer resolution" (console_grid_tests) and the USB "usb::BOT/SCSI/uevent layouts and /usb root rule" (usb_storage_prop_tests); - both modules are present and closed; all_tests registers 126 routines. All USB S1 files are untouched by these dev changes, and the dev framebuffer/console/scrollback/selection/os-identity work is preserved verbatim. AGENTS.md auto-merged and keeps the USB S1 gap text. Post-merge evidence: gates 6/6 (host 885/0), QEMU usb-storage acceptance 46/46, release-kernel selftest 126 routines / 0 failed / 1 skipped (NVMe absent), in one flocked run.
Sync with dev=c1853ad0 (#177 i8042/ppkg responsive + frame-stats, #174 vtfb1 respawn, terminal docs). Clean auto-merge: no textual or semantic conflicts; the only shared files (drivers/mod.rs listing the new i8042 driver, fs/ext2 with the volume-identity helper) merged without overlap. USB S1 files (xhci/usb_msc/usb_scsi/usb_msc_proto/usb_storage/ usb_uevent*/vfs block nodes/mount syscalls) are untouched by these dev changes; the dev i8042/ppkg/frame-stats/respawn work is preserved. Post-merge evidence: gates 6/6 (host 885/0), QEMU usb-storage acceptance 46/46, release-kernel selftest 126 routines / 0 failed / 1 skipped (NVMe absent), one flocked run.
Second sync in this round: dev moved from c1853ad to 7b3e5a7 with #172 terminal PTY job control on top of #177 i8042/ppkg, #174 respawn and the terminal docs. This merge closes the real DIRTY state: dev changed io_sys (per-session tty ioctl) and test.rs while both files also carry USB S1 hooks. Conflicts: - src/arch/x86_64/linux/io_sys.rs: kept the USB `/dev/uevent` ioctl arm and merged the dev per-session tty path — final order is fbdev, vtconsole, vtfb1, uevent, vtinput1, then Console/Stdin -> tty_ioctl(session::current(), ...). - src/test.rs: kept BOTH the dev per-session-tty selftest routine ("linux-tty::per-session foreground groups + winsize + SIGWINCH") and the USB "usb::BOT/SCSI/uevent layouts and /usb root rule" routine. USB S1 files are otherwise untouched; all dev i8042/ppkg/frame-stats/ PTY-job-control/respawn changes are preserved. Post-merge evidence: gates 6/6 (host 893/0), QEMU usb-storage acceptance 46/46, release-kernel selftest 127 routines / 0 failed / 1 skipped (NVMe absent), one flocked run.
Sync with dev=f1453f55 (#167 multi-session terminal lifecycle on top of #172 PTY job control): /dev/vtfbN, /dev/vtinputN and /dev/vtmouseN per session instead of the single-session vtfb1/vtinput1 pair. Conflicts: - src/arch/x86_64/linux/io_sys.rs (4 stops): merged the dev per-session accessors with the USB hooks. * read: `/dev/uevent` record path stays before the dev `vtconsole || vtfb_session().is_some()` snapshot path. * close: dev `closing_session` (vtfb/vtinput/vtmouse) and USB `closing_uevent` both release their reader/session. * stat mode: dev session accessors plus `is_uevent()` stay S_IFCHR. * ioctl: fbdev -> vtconsole -> vtfb_session -> uevent -> vtinput_session (with the dev VTINPUT_SET_FOCUS/tty_ioctl split) -> Console/Stdin. - src/vfs/mod.rs: dev terminal_devices loop (vtfb/vtinput/vtmouse per MAX_SESSIONS) is kept, and `/dev/block` + `/dev/uevent` are chained into the same DevDirectory children list. - src/arch/x86_64/linux/errno.rs auto-merged with a duplicate `EBUSY=16` (USB needed it, #167 added its own); collapsed to one variant with both documented meanings. - src/test.rs auto-merged; all three routines remain (console grid, linux-tty per-session, USB layout). The dead `vtinput1_ioctl` wrapper superseded by the dev inline session-aware branch is removed. Post-merge evidence: gates 6/6 (host 903/0), QEMU usb-storage acceptance 46/46, release-kernel selftest 129 routines / 0 failed / 1 skipped (NVMe absent), one flocked run.
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.
USB mass storage S1 (kernel)
Base
dev, branchfeat/usb-ms-s1. Spec:docs/usb-mass-storage-spec.md(fbec8f8)and
docs/usb-storage-files-ux.md(5198b01). Version intentionally not bumped.Stages
aa6ab747— xHCI MSC enumeration + BOT/SCSI.usb_desc::parse_msc_interfaces(class 8/subclass 6/protocol 0x50),
GET_MAX_LUN(STALL → LUN 0), CBW 31 B,data stage, CSW 13 B with a 30 s wait, STALL → ClearFeature+Reset Endpoint,
full Reset Recovery (Bulk-Only Reset + Reset Endpoint + Set TR Dequeue Pointer)
and one retry; three failures mark the channel dead. SCSI: TUR, INQUIRY,
READ CAPACITY(10), READ/WRITE(10), REQUEST SENSE, SYNCHRONIZE CACHE(10);
4K logical blocks and >2 TiB are explicit rejects (no truncation).
Synchronous BOT runs on the calling thread under
CONTROLLER; probe/registrationrun in a separate
usb-storagethread afterpoll()releases the lock.usbN/usbNpMviadrivers::partition(GPT/MBR), monotonicnon-reused names,
/proc/partitions(major 240,16*N+M), read-only/dev/block/<name>(S_IFBLK; raw write not offered), GPT unique GUID andext2
s_uuid/s_volume_namehelpers./dev/ueventv2: exactly 144 B (usb_uevent_abihost-tests everyoffset/version), ring 256, live
seq++,seq=0snapshots on open andPUEV_IOC_SNAPSHOT(0x5501); exclusive reader (EBUSY);read >= 144returns one record,
< 144isEINVAL;poll(POLLIN)iff non-empty.ADD/REMOVE/CHANGE/ERROR/MOUNTED/UNMOUNTED carry
mount[16]anduuid[16].mount(2)nr 165 /umount2(2)nr 166 (ABI 168→170;SUPPORTED_SYSCALLSand the independent
EXPECTEDlist). Root-only, ext2 only, sourceusbN/usbNpM,target exactly
"/" + sourceand ≤15 bytes (elseENAMETOOLONG+bad_mount).Only pagh volumes mount (mount writes group descriptors/WAL reservation; foreign
ext2 stays visible,
EINVAL). Busy scan of all fd tables →EBUSY; clean unmountflushes with
SYNCHRONIZE CACHE(10); surprise removal detaches withEIO,unclean=1,safe_to_remove=0;MNT_FORCEonly on dead devices; replay failureis fail-closed.
ROOT_KEEPING_COMPONENTSlearns theusbprefix so/usb0p1is not rewritten to
/mnt/usb0p1; the boot/mntflow is unchanged and thekernel never auto-mounts (userspace compositor policy).
Evidence
usb-storageacceptance: 46/46 checks (/tmp/serial-accept2.log):uevent snapshot ADD
usb0p1(fs=1, uuid),mount usb0p1 /usb0p1rc=0 + MOUNTED,write/read
hello,statfs, busy-fd umountEBUSY (-16), clean umount +UNMOUNTED (
flags=144),/proc/partitions+/dev/block/usb0, QMPdevice_del→ REMOVE,
device_add→usb1(monotonic) with the file still readable,open-fd read after surprise unplug →
EIO (-5), ERROR+REMOVE events,dirty umount
EIO (-5)+ UNMOUNTEDflags=224(unclean/detached/surprise),second surprise +
MNT_FORCE→ 0 +flags=240(safe/unclean/detached/surprise),re-add as
usb3→ mount does WAL replay, committed file readable,bad target
/mnt/usb3p1→-22, final clean umount.SELFTEST SUMMARY: 123 routines, 0 failed checks, 1 skipped(the skip is NVMe because this QEMU run has no NVMe device); new routine
usb::BOT/SCSI/uevent layouts and /usb root rulepasses.cargo fmt --all -- --check;tools/build.py build;tools/build.py build --release;tools/host_tests.py(872 passed, 0 failed);tools/check_safety.py;tools/check_agents_md.py.Honest limits (named, not hidden)
error=unsupported_block; LBA > 32 bits andGET_MAX_LUN > 0is logged and skipped.openon a stale surprise mount returnsENOENTbecause dentry lookupitself does I/O and
link_walkmaps lookup errors to not-found; an already-opendescriptor gets
EIO. This nuance is documented rather than papered over.QEMU hotplug note: with
-drive,device_deldrops the block backend and alater QMP
device_add ... drive=fails; acceptance uses-blockdev/node-name.