From f3d411f821df3caf52a0272d920075655147b1f6 Mon Sep 17 00:00:00 2001 From: Moritz Gmeiner Date: Sun, 27 Jul 2025 13:17:04 +0200 Subject: [PATCH] moved low-level code into fat-bits subcrate --- .gitignore | 4 +- Cargo.lock | 10 ++- Cargo.toml | 19 +--- fat-bits/.gitignore | 2 + fat-bits/Cargo.lock | 130 ++++++++++++++++++++++++++++ fat-bits/Cargo.toml | 15 ++++ {src => fat-bits/src}/bpb.rs | 17 ++-- {src => fat-bits/src}/datetime.rs | 4 + {src => fat-bits/src}/dir.rs | 1 - {src => fat-bits/src}/fat.rs | 0 {src => fat-bits/src}/fs_info.rs | 1 + {src => fat-bits/src}/iter.rs | 0 {src => fat-bits/src}/lib.rs | 8 -- {src => fat-bits/src}/subslice.rs | 0 {src => fat-bits/src}/utils.rs | 0 fat-dump/Cargo.toml | 8 ++ src/dump.rs => fat-dump/src/main.rs | 14 +-- 17 files changed, 187 insertions(+), 46 deletions(-) create mode 100644 fat-bits/.gitignore create mode 100644 fat-bits/Cargo.lock create mode 100644 fat-bits/Cargo.toml rename {src => fat-bits/src}/bpb.rs (98%) rename {src => fat-bits/src}/datetime.rs (96%) rename {src => fat-bits/src}/dir.rs (99%) rename {src => fat-bits/src}/fat.rs (100%) rename {src => fat-bits/src}/fs_info.rs (98%) rename {src => fat-bits/src}/iter.rs (100%) rename {src => fat-bits/src}/lib.rs (96%) rename {src => fat-bits/src}/subslice.rs (100%) rename {src => fat-bits/src}/utils.rs (100%) create mode 100644 fat-dump/Cargo.toml rename src/dump.rs => fat-dump/src/main.rs (87%) diff --git a/.gitignore b/.gitignore index 54b52f6..0b00ca9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/target -/tests +target/ +tests/ diff --git a/Cargo.lock b/Cargo.lock index 958e3ac..6ee0b94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,7 +42,7 @@ dependencies = [ ] [[package]] -name = "fat-rs" +name = "fat-bits" version = "0.1.0" dependencies = [ "anyhow", @@ -53,6 +53,14 @@ dependencies = [ "thiserror", ] +[[package]] +name = "fat-dump" +version = "0.1.0" +dependencies = [ + "anyhow", + "fat-bits", +] + [[package]] name = "num-traits" version = "0.2.19" diff --git a/Cargo.toml b/Cargo.toml index ee5b3c7..15a1a97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,3 @@ -[package] -name = "fat-rs" -version = "0.1.0" -edition = "2024" - -[[bin]] -name = "dump" -path = "src/dump.rs" - -[dependencies] -anyhow = "1.0.98" -bitflags = "2.9.1" -chrono = { version = "0.4.41", default-features = false, features = ["alloc", "std"] } -enum_dispatch = "0.3.13" -static_assertions = "1.1.0" -thiserror = "2.0.12" +[workspace] +resolver = "3" +members = ["fat-bits", "fat-dump"] diff --git a/fat-bits/.gitignore b/fat-bits/.gitignore new file mode 100644 index 0000000..54b52f6 --- /dev/null +++ b/fat-bits/.gitignore @@ -0,0 +1,2 @@ +/target +/tests diff --git a/fat-bits/Cargo.lock b/fat-bits/Cargo.lock new file mode 100644 index 0000000..958e3ac --- /dev/null +++ b/fat-bits/Cargo.lock @@ -0,0 +1,130 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anyhow" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "bitflags" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" + +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "num-traits", +] + +[[package]] +name = "enum_dispatch" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd" +dependencies = [ + "once_cell", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "fat-rs" +version = "0.1.0" +dependencies = [ + "anyhow", + "bitflags", + "chrono", + "enum_dispatch", + "static_assertions", + "thiserror", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "syn" +version = "2.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" diff --git a/fat-bits/Cargo.toml b/fat-bits/Cargo.toml new file mode 100644 index 0000000..1986af5 --- /dev/null +++ b/fat-bits/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "fat-bits" +version = "0.1.0" +edition = "2024" + +[dependencies] +anyhow = "1.0.98" +bitflags = "2.9.1" +chrono = { version = "0.4.41", default-features = false, features = [ + "alloc", + "std", +] } +enum_dispatch = "0.3.13" +static_assertions = "1.1.0" +thiserror = "2.0.12" diff --git a/src/bpb.rs b/fat-bits/src/bpb.rs similarity index 98% rename from src/bpb.rs rename to fat-bits/src/bpb.rs index a1e42cf..26e4223 100644 --- a/src/bpb.rs +++ b/fat-bits/src/bpb.rs @@ -22,7 +22,7 @@ impl Display for ExtBpb { pub struct Bpb { fat_type: FatType, - jmp_boot: [u8; 3], + // jmp_boot: [u8; 3], oem_name: [u8; 8], bytes_per_sector: u16, sectors_per_cluster: u8, @@ -52,11 +52,11 @@ impl Display for Bpb { writeln!(f, "")?; - writeln!( - f, - " jmp_boot: [{:#X}, {:#X}, {:#X}]", - self.jmp_boot[0], self.jmp_boot[1], self.jmp_boot[2] - )?; + // writeln!( + // f, + // " jmp_boot: [{:#X}, {:#X}, {:#X}]", + // self.jmp_boot[0], self.jmp_boot[1], self.jmp_boot[2] + // )?; writeln!(f, " oem name: \"{}\"", self.oem_name_str().unwrap_or(""))?; writeln!(f, " bytes per sector: {}", self.bytes_per_sector())?; @@ -90,7 +90,8 @@ impl Bpb { pub fn load(bytes: &[u8]) -> anyhow::Result { anyhow::ensure!(bytes.len() >= 512, "invalid BPB of len {}", bytes.len()); - let jmp_boot = bytes[..3].try_into().unwrap(); + // let jmp_boot = bytes[..3].try_into().unwrap(); + let oem_name = bytes[3..][..8].try_into().unwrap(); let bytes_per_sector = load_u16_le(&bytes[11..][..2]); @@ -145,7 +146,7 @@ impl Bpb { let mut bpb = Bpb { fat_type, - jmp_boot, + // jmp_boot, oem_name, bytes_per_sector, sectors_per_cluster, diff --git a/src/datetime.rs b/fat-bits/src/datetime.rs similarity index 96% rename from src/datetime.rs rename to fat-bits/src/datetime.rs index 78cb507..b9672f2 100644 --- a/src/datetime.rs +++ b/fat-bits/src/datetime.rs @@ -22,6 +22,7 @@ impl Date { Ok(date) } + #[allow(dead_code)] pub fn from_day_month_year(day: u8, month: u8, year: u16) -> anyhow::Result { anyhow::ensure!(day <= 31, "invalid day: {}", day); anyhow::ensure!(month <= 12, "invalid month: {}", month); @@ -32,6 +33,7 @@ impl Date { Ok(Date { repr }) } + #[allow(dead_code)] pub fn from_system_time(time: SystemTime) -> anyhow::Result { let datetime: DateTime = time.into(); @@ -73,6 +75,7 @@ impl Time { Ok(time) } + #[allow(dead_code)] pub fn from_seconds_minutes_hours(seconds: u8, minutes: u8, hours: u8) -> anyhow::Result