diff --git a/bios/stage-2/src/fat.rs b/bios/stage-2/src/fat.rs index 9ce41d6f..0f24e0b4 100644 --- a/bios/stage-2/src/fat.rs +++ b/bios/stage-2/src/fat.rs @@ -48,16 +48,14 @@ impl Bpb { let root_cluster; let fat_size_32; - if (total_sectors_16 == 0) && (total_sectors_32 != 0) { + if fat_size_16 == 0 { // FAT32 fat_size_32 = u32::from_le_bytes(raw[36..40].try_into().unwrap()); root_cluster = u32::from_le_bytes(raw[44..48].try_into().unwrap()); - } else if (total_sectors_16 != 0) && (total_sectors_32 == 0) { + } else { // FAT12 or FAT16 fat_size_32 = 0; root_cluster = 0; - } else { - panic!("ExactlyOneTotalSectorsFieldMustBeZero"); } Self { diff --git a/tests/ramdisk.rs b/tests/ramdisk.rs index 08c86f9b..668a10c3 100644 --- a/tests/ramdisk.rs +++ b/tests/ramdisk.rs @@ -1,6 +1,8 @@ use std::path::Path; use bootloader_test_runner::run_test_kernel_with_ramdisk; +use tempfile::NamedTempFile; + static RAMDISK_PATH: &str = "tests/ramdisk.txt"; #[test] @@ -26,3 +28,15 @@ fn memory_map() { Some(Path::new(RAMDISK_PATH)), ); } + +#[test] +fn large_ramdisk() { + // Create a large file to act as the RAM disk. + let ramdisk = NamedTempFile::new().unwrap(); + ramdisk.as_file().set_len(1024 * 1024 * 16).unwrap(); + + run_test_kernel_with_ramdisk( + env!("CARGO_BIN_FILE_TEST_KERNEL_RAMDISK_large_ramdisk"), + Some(ramdisk.as_ref()), + ); +} diff --git a/tests/test_kernels/ramdisk/src/bin/large_ramdisk.rs b/tests/test_kernels/ramdisk/src/bin/large_ramdisk.rs new file mode 100644 index 00000000..2962e147 --- /dev/null +++ b/tests/test_kernels/ramdisk/src/bin/large_ramdisk.rs @@ -0,0 +1,24 @@ +#![no_std] // don't link the Rust standard library +#![no_main] // disable all Rust-level entry points + +use bootloader_api::{BootInfo, entry_point}; +use core::fmt::Write; +use test_kernel_ramdisk::{QemuExitCode, exit_qemu, serial}; + +entry_point!(kernel_main); + +fn kernel_main(boot_info: &'static mut BootInfo) -> ! { + writeln!(serial(), "Boot info: {boot_info:?}").unwrap(); + assert!(boot_info.ramdisk_addr.into_option().is_some()); + writeln!(serial(), "RAM disk size: {}", boot_info.ramdisk_len).unwrap(); + + exit_qemu(QemuExitCode::Success); +} + +/// This function is called on panic. +#[cfg(not(test))] +#[panic_handler] +fn panic(info: &core::panic::PanicInfo) -> ! { + let _ = writeln!(test_kernel_ramdisk::serial(), "PANIC: {info}"); + exit_qemu(QemuExitCode::Failed); +}