From 3997ec4d2d7d6f69b08d0c04ce8de0df03c52a45 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 21:29:49 +0200 Subject: ahci: scan all ports; fat: mount first valid FAT32 disk The kernel previously started only AHCI port 0, so any launch where the firmware/QEMU put something else on port 0 (e.g. the ESP from an implicit -drive file=fat:rw:esp) left the real disk unnoticed: 'unsupported sector size 0' and no mount. - ahci.rs: enumerate CAP.NP/PI ports, start every port that links up (empty ports settle at DET=0 and are skipped quickly), keep up to 8 disks, and expose disk_count()/select() for the filesystem - fat.rs: try each disk in port order and mount the first valid FAT32 volume; non-FAT disks are logged and skipped - scripts/boot.sh: attach the data disk on ide.0 and the ESP on ide.1 (DISK_IMG env var, default /tmp/disk.img), matching the Makefile - Verified with the disk on port 0 (Makefile style), port 5 (old-style command line), and with the ESP on port 0; fsck.fat stays clean --- rsnix/src/fat.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'rsnix/src/fat.rs') diff --git a/rsnix/src/fat.rs b/rsnix/src/fat.rs index 70fa688..616a08f 100644 --- a/rsnix/src/fat.rs +++ b/rsnix/src/fat.rs @@ -838,9 +838,30 @@ pub fn remove(parent_dir_cluster: u32, name: &str) -> Result<(), ()> { // --- mount ------------------------------------------------------------------- -/// Parse the BPB, cache the FAT and validate the volume. Returns true if -/// a usable FAT32 volume is mounted. +/// Try to mount a FAT32 volume on every attached disk, in port order, and +/// keep the first one that validates. Returns true if a usable FAT32 +/// volume is mounted. pub fn init() -> bool { + let disks = crate::ahci::disk_count(); + if disks == 0 { + crate::serial_println!("fat: no disk"); + return false; + } + for d in 0..disks { + if !crate::ahci::select(d) { + continue; + } + if try_mount() { + return true; + } + crate::serial_println!("fat: no FAT32 volume on disk {}", d); + } + false +} + +/// Parse the BPB of the selected disk, cache the FAT and validate the +/// volume. +fn try_mount() -> bool { let mut bpb = [0u8; SECTOR]; if read_sector(0, &mut bpb).is_err() { crate::serial_println!("fat: no disk"); -- cgit v1.2.3