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 --- scripts/boot-image.sh | 25 ++----------------------- scripts/boot.sh | 22 +++++----------------- scripts/lib-boot-args.sh | 38 ++++++++++++++++++++++++++++++++++++++ scripts/test-disk.sh | 6 +++++- 4 files changed, 50 insertions(+), 41 deletions(-) create mode 100644 scripts/lib-boot-args.sh (limited to 'scripts') diff --git a/scripts/boot-image.sh b/scripts/boot-image.sh index 913e5cb..e8c093c 100755 --- a/scripts/boot-image.sh +++ b/scripts/boot-image.sh @@ -34,29 +34,8 @@ GUI="" DEBUG="" # ---- args ---- -while [ $# -gt 0 ]; do - case "$1" in - --gui | -g) GUI="-vga std" ;; - --debug | -d) DEBUG="-s -S" ;; - --mem) - shift - MEM="$1" - ;; - --smp) - shift - SMP="$1" - ;; - --help | -h) - head -20 "$0" | grep "^#" | sed 's/^# //' - exit 0 - ;; - *) - echo "unknown: $1" - exit 1 - ;; - esac - shift -done +source "$SCRIPT_DIR/lib-boot-args.sh" +parse_boot_args "$@" # ---- build image if missing ---- if [ ! -f "$IMAGE" ]; then diff --git a/scripts/boot.sh b/scripts/boot.sh index 99fd103..5b8e6fa 100755 --- a/scripts/boot.sh +++ b/scripts/boot.sh @@ -45,33 +45,21 @@ GUI="" DEBUG="" # ---- args ---- -while [ $# -gt 0 ]; do +source "$SCRIPT_DIR/lib-boot-args.sh" +# boot.sh-specific flags live here; everything else is shared. +handle_arg() { case "$1" in - --gui | -g) GUI="-vga std" ;; - --debug | -d) DEBUG="-s -S" ;; --release | -r) PROFILE="release" CARGO_FLAGS="--release" ;; - --mem) - shift - MEM="$1" - ;; - --smp) - shift - SMP="$1" - ;; - --help | -h) - head -20 "$0" | grep "^#" | sed 's/^# //' - exit 0 - ;; *) echo "unknown: $1" exit 1 ;; esac - shift -done +} +parse_boot_args "$@" OUT_DIR="target/x86_64-unknown-uefi/$PROFILE" KERNEL="$OUT_DIR/rsdos.efi" diff --git a/scripts/lib-boot-args.sh b/scripts/lib-boot-args.sh new file mode 100644 index 0000000..ec97500 --- /dev/null +++ b/scripts/lib-boot-args.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# +# scripts/lib-boot-args.sh — shared CLI parsing for the QEMU boot scripts. +# Sourced, not executed. The caller sets default values for GUI/DEBUG/ +# MEM/SMP first, then calls `parse_boot_args "$@"`. A caller with extra +# flags defines its own `handle_arg()` to intercept them before the +# shared cases run (unknown args still fail loudly). +set -euo pipefail + +parse_boot_args() { + while [ $# -gt 0 ]; do + case "$1" in + --gui | -g) GUI="-vga std" ;; + --debug | -d) DEBUG="-s -S" ;; + --mem) + shift + MEM="$1" + ;; + --smp) + shift + SMP="$1" + ;; + --help | -h) + head -20 "$0" | grep "^#" | sed 's/^# //' + exit 0 + ;; + *) handle_arg "$1" ;; + esac + shift + done +} + +# Default: no extra flags. A script with more defines its own before +# calling parse_boot_args. +handle_arg() { + echo "unknown: $1" + exit 1 +} diff --git a/scripts/test-disk.sh b/scripts/test-disk.sh index 11a9b05..0268fff 100755 --- a/scripts/test-disk.sh +++ b/scripts/test-disk.sh @@ -72,7 +72,11 @@ cargo build --package rsdos --target x86_64-unknown-uefi echo "==> 2/6 deploy to ESP + ensure disk image" mkdir -p "$ESP_DIR/EFI/BOOT" cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" -"$SCRIPT_DIR/mkdisk.sh" $([ "$FRESH" -eq 1 ] && echo --fresh) "$IMG" +if [ "$FRESH" -eq 1 ]; then + "$SCRIPT_DIR/mkdisk.sh" --fresh "$IMG" +else + "$SCRIPT_DIR/mkdisk.sh" "$IMG" +fi echo "==> 3/6 boot QEMU (headless)" kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true -- cgit v1.2.3