From 1ea2f68e6a9af135e6cb3274fdf28d4ddc5812d5 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 1 Aug 2026 18:25:55 +0200 Subject: fix pi-lens warnings: unwraps, shell SC2046, dup code (fmtbuf/scripts/hexdump/cat/ahci/pci) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - memory.rs: self-test Layout::from_size_align no longer panics — the test fails cleanly on an invalid layout - fat.rs: v() no longer unwraps the active-volume slot — invariant violation logs + halts instead of panicking mid-disk-io - strbuf: shared FmtBuf replaces the duplicated PanicBuf/FmtBuf (main.rs + sched.rs) - test-disk.sh: SC2046 — conditional --fresh arg no longer relies on word splitting - scripts: boot.sh/boot-image.sh share lib-boot-args.sh (dup args loop) - shell: cat/hexdump stdin pairs unified with Option<&str> marker; hexdump format_row folded into format_partial - ahci: read/write_sectors unified behind dma_sectors - pci: config_read/write share config_addr --- rsnix/src/ahci.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'rsnix/src/ahci.rs') diff --git a/rsnix/src/ahci.rs b/rsnix/src/ahci.rs index 72da07d..a77b341 100644 --- a/rsnix/src/ahci.rs +++ b/rsnix/src/ahci.rs @@ -510,22 +510,24 @@ fn active() -> Option<&'static Disk> { disks().get(unsafe { ACTIVE }).and_then(|d| d.as_ref()) } -/// DMA `count` sectors starting at `lba` into the selected disk's buffer. -pub fn read_sectors(lba: u64, count: u32) -> Result<(), ()> { +/// Bounds-checked DMA of `count` sectors starting at `lba` into/out of the +/// selected disk's buffer (single code path for both directions). +fn dma_sectors(lba: u64, count: u32, cmd: u8, write: bool) -> Result<(), ()> { let d = active().ok_or(())?; if lba + count as u64 > d.sectors { return Err(()); } - issue(d, ATA_READ_DMA_EXT, lba, count, false) + issue(d, cmd, lba, count, write) +} + +/// DMA `count` sectors starting at `lba` into the selected disk's buffer. +pub fn read_sectors(lba: u64, count: u32) -> Result<(), ()> { + dma_sectors(lba, count, ATA_READ_DMA_EXT, false) } /// DMA `count` sectors starting at `lba` out of the selected disk's buffer. pub fn write_sectors(lba: u64, count: u32) -> Result<(), ()> { - let d = active().ok_or(())?; - if lba + count as u64 > d.sectors { - return Err(()); - } - issue(d, ATA_WRITE_DMA_EXT, lba, count, true) + dma_sectors(lba, count, ATA_WRITE_DMA_EXT, true) } /// Pointer to the selected disk's 4 KiB DMA buffer. -- cgit v1.2.3