diff --git a/pixie-shared/src/lib.rs b/pixie-shared/src/lib.rs index 6b362844..fa30b0cc 100644 --- a/pixie-shared/src/lib.rs +++ b/pixie-shared/src/lib.rs @@ -39,7 +39,7 @@ pub type ChunkHash = [u8; OUT_LEN]; pub type Offset = usize; /// Describes one chunk from a disk. -#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)] pub struct Chunk { pub hash: ChunkHash, pub start: Offset, diff --git a/pixie-uefi/Cargo.lock b/pixie-uefi/Cargo.lock index f6f6ab88..067ef4ed 100644 --- a/pixie-uefi/Cargo.lock +++ b/pixie-uefi/Cargo.lock @@ -22,9 +22,9 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "bit_field" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" +checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6" [[package]] name = "bitflags" @@ -34,9 +34,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "blake3" @@ -53,22 +53,22 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.20.0" +version = "1.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b37c88a63ffd85d15b406896cc343916d7cf57838a847b3a6f2ca5d39a5695a" +checksum = "1fbdf580320f38b612e485521afda1ee26d10cc9884efaaa750d383e13e3c5f4" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" -version = "1.8.0" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcfcc3cd946cb52f0bbfdbbcfa2f4e24f75ebb6c0e1002f7c25904fada18b9ec" +checksum = "f9abbd1bc6865053c427f7198e6af43bfdedc55ab791faed4fbd361d789575ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -88,9 +88,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cobs" @@ -148,7 +148,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -160,26 +160,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "derive_more" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" -dependencies = [ - "derive_more-impl", -] - -[[package]] -name = "derive_more-impl" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.90", -] - [[package]] name = "embedded-io" version = "0.4.0" @@ -236,7 +216,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -314,9 +294,9 @@ checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" [[package]] name = "lz4_flex" -version = "0.11.5" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08ab2867e3eeeca90e844d1940eab391c9dc5228783db2ed999acbc0a9ed375a" +checksum = "ab6473172471198271ff72e9379150e9dfd70d8e533e0752a27e515b48dd375e" [[package]] name = "managed" @@ -334,11 +314,31 @@ dependencies = [ "walkdir", ] +[[package]] +name = "pin-project" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" [[package]] name = "pin-utils" @@ -362,7 +362,6 @@ dependencies = [ "anstyle", "blake3", "core_detect", - "derive_more", "futures", "gpt_disk_io", "log", @@ -371,9 +370,8 @@ dependencies = [ "minicov", "pixie-shared", "postcard", - "rand", - "rand_xoshiro", "smoltcp", + "thingbuf", "uefi", ] @@ -408,71 +406,47 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" dependencies = [ "unicode-ident", ] [[package]] name = "ptr_meta" -version = "0.2.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcada80daa06c42ed5f48c9a043865edea5dc44cbf9ac009fda3b89526e28607" +checksum = "0b9a0cf95a1196af61d4f1cbdab967179516d9a4a4312af1f31948f8f6224a79" dependencies = [ "ptr_meta_derive", ] [[package]] name = "ptr_meta_derive" -version = "0.2.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca9224df2e20e7c5548aeb5f110a0f3b77ef05f8585139b7148b59056168ed2" +checksum = "7347867d0a7e1208d93b46767be83e2b8f978c3dad35f775ac8d8847551d6fe1" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "quote" -version = "1.0.37" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" - -[[package]] -name = "rand_xoshiro" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" -dependencies = [ - "rand_core", -] - [[package]] name = "same-file" version = "1.0.6" @@ -509,7 +483,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -540,9 +514,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" dependencies = [ "proc-macro2", "quote", @@ -550,14 +524,12 @@ dependencies = [ ] [[package]] -name = "syn" -version = "2.0.90" +name = "thingbuf" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +checksum = "662b54ef6f7b4e71f683dadc787bbb2d8e8ef2f91b682ebed3164a5a7abca905" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "pin-project", ] [[package]] @@ -577,7 +549,7 @@ checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -591,11 +563,11 @@ dependencies = [ [[package]] name = "uefi" -version = "0.33.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6679b7fc2f6d6d2ea2f67555ef3ed9d71d30c5021faf9193091a5192db7dc468" +checksum = "71fe9058b73ee2b6559524af9e33199c13b2485ddbf3ad1181b68051cdc50c17" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.10.0", "cfg-if", "log", "ptr_meta", @@ -607,40 +579,39 @@ dependencies = [ [[package]] name = "uefi-macros" -version = "0.17.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b24e77d3fc1e617051e630f99da24bcae6328abab37b8f9216bb68d06804f9a" +checksum = "4687412b5ac74d245d5bfb1733ede50c31be19bf8a4b6a967a29b451bab49e67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] name = "uefi-raw" -version = "0.9.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6d465de2c918779dafb769a5a4fe8d6e4fb7cc4cc6cb1a735f2f6ec68beea4" +checksum = "7f64fe59e11af447d12fd60a403c74106eb104309f34b4c6dbce6e927d97da9d" dependencies = [ - "bitflags 2.6.0", - "ptr_meta", + "bitflags 2.10.0", "uguid", ] [[package]] name = "uguid" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab14ea9660d240e7865ce9d54ecdbd1cd9fa5802ae6f4512f093c7907e921533" +checksum = "0c8352f8c05e47892e7eaf13b34abd76a7f4aeaf817b716e88789381927f199c" dependencies = [ "bytemuck", ] [[package]] name = "unicode-ident" -version = "1.0.14" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "walkdir" diff --git a/pixie-uefi/Cargo.toml b/pixie-uefi/Cargo.toml index 6cae3362..66cd29d3 100644 --- a/pixie-uefi/Cargo.toml +++ b/pixie-uefi/Cargo.toml @@ -16,18 +16,16 @@ coverage = ["dep:minicov"] anstyle = { version = "1.0.13", default-features = false } blake3 = { version = "1.8.2", default-features = false, features = ["prefer_intrinsics", "no_avx512", "pure"] } core_detect = "1.0.0" -derive_more = { version = "2.0.1", features = ["from"], default-features = false } -futures = { version = "0.3.29", default-features = false, features = ["alloc", "async-await"] } +futures = { version = "0.3.31", default-features = false, features = ["alloc", "async-await"] } gpt_disk_io = "0.16.2" log = "0.4.28" -lz4_flex = { version = "0.11.5", default-features = false } +lz4_flex = { version = "0.12.0", default-features = false } managed = { version = "0.8.0", default-features = false, features = ["alloc"] } minicov = { version = "0.3.7", optional = true } postcard = { version = "1.1.3", default-features = false, features = ["alloc"] } -rand = { version = "0.8.5", default-features = false } -rand_xoshiro = { version = "0.6.0", default-features = false } smoltcp = { version = "0.12.0", default-features = false, features = ["alloc", "proto-ipv4", "medium-ethernet", "socket-udp", "socket-tcp", "socket-dhcpv4", "async", "socket-tcp-cubic"] } -uefi = { version = "0.33.0", features = ["alloc", "global_allocator", "panic_handler"] } +thingbuf = { version = "0.1.6", default-features = false, features = ["alloc"] } +uefi = { version = "0.36.1", features = ["alloc", "global_allocator", "panic_handler"] } [dependencies.pixie-shared] path = "../pixie-shared" diff --git a/pixie-uefi/src/export_cov.rs b/pixie-uefi/src/export_cov.rs index e02bc46d..51da6f1e 100644 --- a/pixie-uefi/src/export_cov.rs +++ b/pixie-uefi/src/export_cov.rs @@ -1,4 +1,5 @@ -use crate::os::{disk::Disk, UefiOS}; +use crate::os::disk::Disk; +use crate::os::UefiOS; pub async fn export(os: UefiOS) { let mut disk = Disk::open_with_size(os, 500 << 20); diff --git a/pixie-uefi/src/flash.rs b/pixie-uefi/src/flash.rs index 3a8e9dec..377ff765 100644 --- a/pixie-uefi/src/flash.rs +++ b/pixie-uefi/src/flash.rs @@ -1,21 +1,23 @@ -use crate::{ - os::{ - error::{Error, Result}, - mpsc, TcpStream, UefiOS, PACKET_SIZE, - }, - MIN_MEMORY, -}; -use alloc::{boxed::Box, collections::BTreeMap, rc::Rc, string::ToString, vec::Vec}; -use core::{cell::RefCell, mem, net::SocketAddrV4}; +use alloc::boxed::Box; +use alloc::collections::BTreeMap; +use alloc::rc::Rc; +use alloc::vec::Vec; +use core::cell::RefCell; +use core::mem; +use core::net::SocketAddrV4; + use futures::future::{select, Either}; use log::info; use lz4_flex::decompress; -use pixie_shared::{ - chunk_codec::Decoder, util::BytesFmt, ChunkHash, Image, TcpRequest, UdpRequest, CHUNKS_PORT, - MAX_CHUNK_SIZE, -}; +use pixie_shared::chunk_codec::Decoder; +use pixie_shared::util::BytesFmt; +use pixie_shared::{ChunkHash, Image, TcpRequest, UdpRequest, CHUNKS_PORT, MAX_CHUNK_SIZE}; use uefi::proto::console::text::Color; +use crate::os::error::{Error, Result}; +use crate::os::{memory, TcpStream, UefiOS, PACKET_SIZE}; +use crate::MIN_MEMORY; + async fn fetch_image(stream: &TcpStream) -> Result { let req = TcpRequest::GetImage; let mut buf = postcard::to_allocvec(&req)?; @@ -64,7 +66,7 @@ fn handle_packet( received.remove(&hash).unwrap(); last_seen.retain(|x| x != &hash); - let data = decompress(&cdata, size).map_err(|e| Error::Generic(e.to_string()))?; + let data = decompress(&cdata, size)?; assert_eq!(data.len(), size); Ok(Some((pos, data))) @@ -162,16 +164,16 @@ pub async fn flash(os: UefiOS, server_addr: SocketAddrV4) -> Result<()> { let mut received = BTreeMap::new(); - let (tx, mut rx) = mpsc::channel(128); + let (tx, rx) = thingbuf::mpsc::channel(128); let task1 = async { - let mut tx = tx; + let tx = tx; let mut last_seen = Vec::new(); - let total_mem = os.get_total_mem(); - let max_chunks = (total_mem.saturating_sub(MIN_MEMORY) as usize / MAX_CHUNK_SIZE).max(128); + let free_mem = memory::stats().free; + let max_chunks = (free_mem.saturating_sub(MIN_MEMORY) as usize / MAX_CHUNK_SIZE).max(128); log::debug!( - "Total memory: {}. Max chunks in memory: {max_chunks}", - BytesFmt(total_mem) + "Free memory: {}. Max chunks in memory: {max_chunks}", + BytesFmt(free_mem) ); while !chunks_info.is_empty() { let recv = Box::pin(socket.recv(&mut buf)); @@ -184,7 +186,7 @@ pub async fn flash(os: UefiOS, server_addr: SocketAddrV4) -> Result<()> { let chunk = handle_packet(buf, &mut chunks_info, &mut received, &mut last_seen)?; if let Some((pos, data)) = chunk { - tx.send((pos, data)).await; + tx.send((pos, data)).await.expect("receiver was dropped"); } assert_eq!(last_seen.len(), received.len()); diff --git a/pixie-uefi/src/main.rs b/pixie-uefi/src/main.rs index e113e555..051c3cf1 100644 --- a/pixie-uefi/src/main.rs +++ b/pixie-uefi/src/main.rs @@ -5,22 +5,20 @@ #[macro_use] extern crate alloc; -use crate::{ - flash::flash, - os::{ - error::{Error, Result}, - TcpStream, UefiOS, PACKET_SIZE, - }, - reboot_to_os::reboot_to_os, - register::register, - store::store, -}; use alloc::boxed::Box; use core::net::{Ipv4Addr, SocketAddrV4}; + use futures::future::{self, Either}; use pixie_shared::{Action, TcpRequest, UdpRequest, ACTION_PORT, PING_PORT}; use uefi::{entry, Status}; +use crate::flash::flash; +use crate::os::error::{Error, Result}; +use crate::os::{TcpStream, UefiOS, PACKET_SIZE}; +use crate::reboot_to_os::reboot_to_os; +use crate::register::register; +use crate::store::store; + mod flash; mod os; mod parse_disk; @@ -31,7 +29,8 @@ mod store; #[cfg(feature = "coverage")] mod export_cov; -const MIN_MEMORY: u64 = 500 << 20; +// Memory to keep free for non-chunk storage. +const MIN_MEMORY: u64 = 32 << 20; async fn server_discover(os: UefiOS) -> Result { let socket = os.udp_bind(None).await?; diff --git a/pixie-uefi/src/os/boot_options.rs b/pixie-uefi/src/os/boot_options.rs index 89cae99b..e2e699bb 100644 --- a/pixie-uefi/src/os/boot_options.rs +++ b/pixie-uefi/src/os/boot_options.rs @@ -1,13 +1,11 @@ +use alloc::string::{String, ToString}; +use alloc::vec::Vec; + +use uefi::proto::device_path::DevicePath; +use uefi::runtime::{VariableAttributes, VariableVendor}; +use uefi::CString16; + use super::UefiOS; -use alloc::{ - string::{String, ToString}, - vec::Vec, -}; -use uefi::{ - proto::device_path::DevicePath, - runtime::{VariableAttributes, VariableVendor}, - CString16, -}; pub struct BootOptions { pub(super) os: UefiOS, diff --git a/pixie-uefi/src/os/disk.rs b/pixie-uefi/src/os/disk.rs index 6185a551..9d8c2516 100644 --- a/pixie-uefi/src/os/disk.rs +++ b/pixie-uefi/src/os/disk.rs @@ -1,20 +1,14 @@ -use super::{ - error::{Error, Result}, - UefiOS, -}; -use alloc::{ - string::{String, ToString}, - vec::Vec, -}; -use gpt_disk_io::{ - gpt_disk_types::{BlockSize, Lba}, - BlockIo, -}; -use uefi::{ - boot::{OpenProtocolParams, ScopedProtocol}, - proto::media::block::BlockIO, - Handle, -}; +use alloc::string::{String, ToString}; +use alloc::vec::Vec; + +use gpt_disk_io::gpt_disk_types::{BlockSize, Lba}; +use gpt_disk_io::BlockIo; +use uefi::boot::{OpenProtocolParams, ScopedProtocol}; +use uefi::proto::media::block::BlockIO; +use uefi::Handle; + +use super::error::Result; +use super::UefiOS; fn open_disk(handle: Handle) -> Result> { let image_handle = uefi::boot::image_handle(); @@ -170,19 +164,14 @@ impl Disk { pub fn partitions(&mut self) -> Result> { let block_size = self.block_size().to_u64(); - let mut disk = gpt_disk_io::Disk::new(self).map_err(|e| Error::Generic(e.to_string()))?; + let mut disk = gpt_disk_io::Disk::new(self)?; let mut buf = [0; 1 << 14]; - let header = disk - .read_primary_gpt_header(&mut buf) - .map_err(|e| Error::Generic(e.to_string()))?; + let header = disk.read_primary_gpt_header(&mut buf)?; // TODO(veluca): bubble up this error. - let part_array_layout = header - .get_partition_entry_array_layout() - .map_err(|e| Error::Generic(e.to_string()))?; + let part_array_layout = header.get_partition_entry_array_layout()?; let mut buf = [0; 1 << 14]; let x = disk - .gpt_partition_entry_array_iter(part_array_layout, &mut buf) - .map_err(|e| Error::Generic(e.to_string()))? + .gpt_partition_entry_array_iter(part_array_layout, &mut buf)? .filter_map(|part| { let part = if let Err(err) = part { return Some(Err(err)); @@ -201,8 +190,7 @@ impl Disk { None } }) - .collect::>() - .map_err(|e| Error::Generic(e.to_string()))?; + .collect::>()?; Ok(x) } diff --git a/pixie-uefi/src/os/error.rs b/pixie-uefi/src/os/error.rs index 9c010c22..a8f065f5 100644 --- a/pixie-uefi/src/os/error.rs +++ b/pixie-uefi/src/os/error.rs @@ -1,31 +1,41 @@ -use alloc::{borrow::ToOwned, string::String}; +use alloc::borrow::ToOwned; +use alloc::string::String; use core::fmt::{Display, Formatter}; -use derive_more::From; -use smoltcp::socket::{ - tcp::{self, ConnectError, RecvError}, - udp::{self, BindError}, -}; + +use gpt_disk_io::gpt_disk_types; pub type Result = core::result::Result; -#[derive(Debug, From)] -pub enum Error { - Connect(#[from] ConnectError), - TcpSend(#[from] tcp::SendError), - UdpSend(#[from] udp::SendError), - Recv(#[from] RecvError), - Bind(#[from] BindError), - Postcard(#[from] postcard::Error), - Uefi(#[from] uefi::Error), - Generic(String), -} +#[derive(Debug)] +pub struct Error(pub String); impl Error { pub fn msg(s: &str) -> Error { - Error::Generic(s.to_owned()) + Self(s.to_owned()) } } +macro_rules! err { + ($ty: ty) => { + impl From<$ty> for Error { + fn from(value: $ty) -> Self { + Self(format!("{}: {value}", stringify!($ty))) + } + } + }; +} + +err!(uefi::Error); +err!(smoltcp::socket::tcp::ConnectError); +err!(smoltcp::socket::tcp::RecvError); +err!(smoltcp::socket::tcp::SendError); +err!(smoltcp::socket::udp::BindError); +err!(smoltcp::socket::udp::SendError); +err!(postcard::Error); +err!(lz4_flex::block::DecompressError); +err!(gpt_disk_io::DiskError); +err!(gpt_disk_types::GptPartitionEntrySizeError); + impl Display for Error { fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), core::fmt::Error> { write!(fmt, "{self:?}") diff --git a/pixie-uefi/src/os/executor.rs b/pixie-uefi/src/os/executor.rs index b4a782a6..6b4a5afc 100644 --- a/pixie-uefi/src/os/executor.rs +++ b/pixie-uefi/src/os/executor.rs @@ -1,11 +1,14 @@ -use super::{sync::SyncRefCell, UefiOS}; -use alloc::{boxed::Box, collections::VecDeque, sync::Arc, task::Wake}; -use core::{ - cell::RefCell, - future::Future, - pin::Pin, - task::{Context, Waker}, -}; +use alloc::boxed::Box; +use alloc::collections::VecDeque; +use alloc::sync::Arc; +use alloc::task::Wake; +use core::cell::RefCell; +use core::future::Future; +use core::pin::Pin; +use core::task::{Context, Waker}; + +use super::sync::SyncRefCell; +use crate::os::timer::Timer; pub(super) type BoxFuture = Pin + 'static>>; @@ -63,7 +66,7 @@ pub struct Executor { } impl Executor { - pub fn run(os: UefiOS) -> ! { + pub fn run() -> ! { loop { let task = EXECUTOR .borrow_mut() @@ -75,9 +78,9 @@ impl Executor { let waker = Waker::from(task.clone()); let mut context = Context::from_waker(&waker); let mut fut = task.inner.borrow_mut().future.take().unwrap(); - let begin = os.timer().micros(); + let begin = Timer::micros(); let status = fut.as_mut().poll(&mut context); - let end = os.timer().micros(); + let end = Timer::micros(); task.inner.borrow_mut().micros += end - begin; if status.is_pending() { task.inner.borrow_mut().future = Some(fut); diff --git a/pixie-uefi/src/os/memory.rs b/pixie-uefi/src/os/memory.rs new file mode 100644 index 00000000..1321989f --- /dev/null +++ b/pixie-uefi/src/os/memory.rs @@ -0,0 +1,36 @@ +use uefi::boot::MemoryType; +use uefi::mem::memory_map::MemoryMap; + +#[derive(Debug)] +pub struct MemoryStats { + pub used: u64, + pub free: u64, + pub other: u64, +} + +pub fn stats() -> MemoryStats { + let mut stats = MemoryStats { + used: 0, + free: 0, + other: 0, + }; + const PAGE_SIZE: u64 = 4096; + uefi::boot::memory_map(MemoryType::LOADER_DATA) + .expect("Failed to get memory map") + .entries() + .for_each(|entry| { + let sz = entry.page_count * PAGE_SIZE; + match entry.ty { + MemoryType::LOADER_DATA | MemoryType::LOADER_CODE => { + stats.used += sz; + } + MemoryType::CONVENTIONAL => { + stats.free += sz; + } + _ => { + stats.other += sz; + } + } + }); + stats +} diff --git a/pixie-uefi/src/os/mod.rs b/pixie-uefi/src/os/mod.rs index 27af756e..4c3a3b47 100644 --- a/pixie-uefi/src/os/mod.rs +++ b/pixie-uefi/src/os/mod.rs @@ -1,64 +1,47 @@ -use self::{ - boot_options::BootOptions, - disk::Disk, - error::{Error, Result}, - executor::{Executor, Task}, - net::NetworkInterface, - rng::Rng, - sync::SyncRefCell, - timer::Timer, -}; -use alloc::{ - boxed::Box, - collections::VecDeque, - string::{String, ToString}, - sync::Arc, - vec::Vec, -}; -use core::{ - cell::{Ref, RefMut}, - ffi::c_void, - fmt::Write, - future::{poll_fn, Future}, - net::SocketAddrV4, - ptr::NonNull, - task::Poll, -}; +use alloc::boxed::Box; +use alloc::collections::VecDeque; +use alloc::string::{String, ToString}; +use alloc::sync::Arc; +use alloc::vec::Vec; +use core::cell::{Ref, RefMut}; +use core::ffi::c_void; +use core::fmt::Write; +use core::future::{poll_fn, Future}; +use core::net::SocketAddrV4; +use core::ptr::NonNull; +use core::task::Poll; + use pixie_shared::util::BytesFmt; -use uefi::{ - boot::{EventType, MemoryType, ScopedProtocol, TimerTrigger, Tpl}, - mem::memory_map::MemoryMap, - proto::{ - console::{ - serial::Serial, - text::{Color, Input, Key, Output}, - }, - device_path::{ - build::DevicePathBuilder, - text::{AllowShortcuts, DevicePathToText, DisplayOnly}, - DevicePath, - }, - Protocol, - }, - runtime::{VariableAttributes, VariableVendor}, - CStr16, Event, Handle, Status, -}; +use uefi::boot::{EventType, ScopedProtocol, TimerTrigger, Tpl}; +use uefi::proto::console::serial::Serial; +use uefi::proto::console::text::{Color, Input, Key, Output}; +use uefi::proto::device_path::build::DevicePathBuilder; +use uefi::proto::device_path::text::{AllowShortcuts, DevicePathToText, DisplayOnly}; +use uefi::proto::device_path::DevicePath; +use uefi::proto::Protocol; +use uefi::runtime::{VariableAttributes, VariableVendor}; +use uefi::{CStr16, Event, Handle, Status}; + +use self::boot_options::BootOptions; +use self::disk::Disk; +use self::error::{Error, Result}; +use self::executor::{Executor, Task}; +use self::net::NetworkInterface; +use self::sync::SyncRefCell; +use self::timer::Timer; mod boot_options; pub mod disk; pub mod error; mod executor; -pub mod mpsc; +pub mod memory; mod net; -mod rng; mod sync; mod timer; pub use net::{TcpStream, UdpHandle, PACKET_SIZE}; struct UefiOSImpl { - timer: Timer, - rng: Rng, tasks: Vec>, input: ScopedProtocol, vga: ScopedProtocol, @@ -163,8 +146,7 @@ impl UefiOS { .unwrap(); } - let timer = Timer::new(); - let rng = Rng::new(); + Timer::ensure_init(); let input_handles = uefi::boot::find_handles::().unwrap(); let input = uefi::boot::open_protocol_exclusive::(input_handles[0]).unwrap(); @@ -179,8 +161,6 @@ impl UefiOS { vga.clear().unwrap(); *OS.borrow_mut() = Some(UefiOSImpl { - timer, - rng, tasks: Vec::new(), input, vga, @@ -227,9 +207,8 @@ impl UefiOS { os.spawn( "[net_poll]", poll_fn(move |cx| { - let (mut net, timer) = - RefMut::map_split(os.borrow_mut(), |os| (&mut os.net, &mut os.timer)); - net.as_mut().unwrap().poll(&timer); + let mut os = os.borrow_mut(); + os.net.as_mut().unwrap().poll(); // TODO(veluca): figure out whether we can suspend the task. cx.waker().wake_by_ref(); Poll::Pending @@ -239,10 +218,10 @@ impl UefiOS { os.spawn("[net_speed]", async move { let mut prx = 0; let mut ptx = 0; - let mut ptm = os.timer().instant(); + let mut ptm = Timer::instant(); loop { { - let now = os.timer().instant(); + let now = Timer::instant(); let dt = (now - ptm).total_micros() as f64 / 1_000_000.0; ptm = now; @@ -263,7 +242,7 @@ impl UefiOS { } }); - Executor::run(os) + Executor::run() } fn borrow(&self) -> Ref<'static, UefiOSImpl> { @@ -274,14 +253,6 @@ impl UefiOS { RefMut::map(OS.borrow_mut(), |f| f.as_mut().unwrap()) } - pub fn timer(&self) -> Ref<'static, Timer> { - Ref::map(self.borrow(), |f| &f.timer) - } - - pub fn rng(&self) -> RefMut<'static, Rng> { - RefMut::map(self.borrow_mut(), |f| &mut f.rng) - } - fn tasks(&self) -> RefMut<'static, Vec>> { RefMut::map(self.borrow_mut(), |f| &mut f.tasks) } @@ -317,9 +288,9 @@ impl UefiOS { } pub fn sleep_us(self, us: u64) -> impl Future { - let tgt = self.timer().micros() as u64 + us; + let tgt = Timer::micros() as u64 + us; poll_fn(move |cx| { - let now = self.timer().micros() as u64; + let now = Timer::micros() as u64; if now >= tgt { Poll::Ready(()) } else { @@ -348,7 +319,7 @@ impl UefiOS { let mut name_buf = vec![0u16; name.len() * 2 + 16]; let name = CStr16::from_str_with_buf(name, &mut name_buf).unwrap(); let (var, attrs) = uefi::runtime::get_variable_boxed(name, vendor) - .map_err(|e| Error::Generic(format!("Error getting variable: {e:?}")))?; + .map_err(|e| Error(format!("Error getting variable: {e:?}")))?; Ok((var.to_vec(), attrs)) } @@ -363,7 +334,7 @@ impl UefiOS { let mut name_buf = vec![0u16; name.len() * 2 + 16]; let name = CStr16::from_str_with_buf(name, &mut name_buf).unwrap(); uefi::runtime::set_variable(name, vendor, attrs, data) - .map_err(|e| Error::Generic(format!("Error setting variable: {e:?}")))?; + .map_err(|e| Error(format!("Error setting variable: {e:?}")))?; Ok(()) } @@ -431,7 +402,7 @@ impl UefiOS { fn draw_ui(&self) { // Write the header. { - let time = self.timer().micros() as f32 * 0.000_001; + let time = Timer::micros() as f32 * 0.000_001; let ip = self.net().ip(); let mut os = self.borrow_mut(); @@ -556,14 +527,6 @@ impl UefiOS { pub fn shutdown(&self) -> ! { uefi::runtime::reset(uefi::runtime::ResetType::SHUTDOWN, Status::SUCCESS, None) } - - pub fn get_total_mem(&self) -> u64 { - uefi::boot::memory_map(MemoryType::LOADER_DATA) - .expect("Failed to get memory map") - .entries() - .map(|entry| entry.page_count * 4096) - .sum() - } } impl log::Log for UefiOS { @@ -572,7 +535,7 @@ impl log::Log for UefiOS { } fn log(&self, record: &log::Record) { - let now = self.timer().micros() as f64 * 0.000_001; + let now = Timer::micros() as f64 * 0.000_001; self.append_message( now, record.level(), diff --git a/pixie-uefi/src/os/mpsc.rs b/pixie-uefi/src/os/mpsc.rs deleted file mode 100644 index 256d95e4..00000000 --- a/pixie-uefi/src/os/mpsc.rs +++ /dev/null @@ -1,84 +0,0 @@ -use alloc::{collections::VecDeque, rc::Rc}; -use core::{cell::RefCell, future::poll_fn, task::Poll, task::Waker}; - -struct Data { - size: usize, - tx_count: usize, - tx_waker: Option, - rx_waker: Option, - queue: VecDeque, -} - -pub struct Sender { - inner: Rc>>, -} - -impl Sender { - pub async fn send(&mut self, value: T) { - let mut value = Some(value); - poll_fn(|cx| { - let mut inner = self.inner.borrow_mut(); - if inner.queue.len() < inner.size { - inner.queue.push_back(value.take().unwrap()); - if let Some(waker) = inner.rx_waker.take() { - waker.wake(); - } - Poll::Ready(()) - } else { - inner.tx_waker = Some(cx.waker().clone()); - Poll::Pending - } - }) - .await - } -} - -impl Drop for Sender { - fn drop(&mut self) { - let mut inner = self.inner.borrow_mut(); - inner.tx_count -= 1; - if let Some(waker) = inner.rx_waker.take() { - waker.wake(); - } - } -} - -pub struct Receiver { - inner: Rc>>, -} - -impl Receiver { - pub async fn recv(&mut self) -> Option { - poll_fn(|cx| { - let mut inner = self.inner.borrow_mut(); - if let Some(value) = inner.queue.pop_front() { - if let Some(waker) = inner.tx_waker.take() { - waker.wake(); - } - Poll::Ready(Some(value)) - } else if inner.tx_count == 0 { - Poll::Ready(None) - } else { - inner.rx_waker = Some(cx.waker().clone()); - Poll::Pending - } - }) - .await - } -} - -pub fn channel(size: usize) -> (Sender, Receiver) { - let inner = Rc::new(RefCell::new(Data { - size, - tx_count: 1, - tx_waker: None, - rx_waker: None, - queue: VecDeque::new(), - })); - ( - Sender { - inner: inner.clone(), - }, - Receiver { inner }, - ) -} diff --git a/pixie-uefi/src/os/net.rs b/pixie-uefi/src/os/net.rs index 7cad4af3..498915dc 100644 --- a/pixie-uefi/src/os/net.rs +++ b/pixie-uefi/src/os/net.rs @@ -1,32 +1,25 @@ -use super::{ - error::{Error, Result}, - timer::Timer, - UefiOS, -}; use alloc::boxed::Box; -use core::{ - future::poll_fn, - net::{IpAddr, Ipv4Addr, SocketAddrV4}, - task::Poll, -}; +use core::future::poll_fn; +use core::net::{IpAddr, Ipv4Addr, SocketAddrV4}; +use core::task::Poll; + use futures::future::select; -use smoltcp::{ - iface::{Config, Interface, PollResult, SocketHandle, SocketSet}, - phy::{Device, DeviceCapabilities, Medium, RxToken, TxToken}, - socket::{ - dhcpv4::{Event, Socket as Dhcpv4Socket}, - tcp::{Socket as TcpSocket, State}, - udp::{self, Socket as UdpSocket}, - }, - storage::RingBuffer, - time::{Duration, Instant}, - wire::{DhcpOption, HardwareAddress, IpCidr, IpEndpoint}, -}; -use uefi::{ - boot::ScopedProtocol, - proto::network::snp::{ReceiveFlags, SimpleNetwork}, - Status, -}; +use smoltcp::iface::{Config, Interface, PollResult, SocketHandle, SocketSet}; +use smoltcp::phy::{Device, DeviceCapabilities, Medium, RxToken, TxToken}; +use smoltcp::socket::dhcpv4::{Event, Socket as Dhcpv4Socket}; +use smoltcp::socket::tcp::{Socket as TcpSocket, State}; +use smoltcp::socket::udp::{self, Socket as UdpSocket}; +use smoltcp::storage::RingBuffer; +use smoltcp::time::{Duration, Instant}; +use smoltcp::wire::{DhcpOption, HardwareAddress, IpCidr, IpEndpoint}; +use uefi::boot::ScopedProtocol; +use uefi::proto::network::snp::{ReceiveFlags, SimpleNetwork}; +use uefi::Status; + +use super::error::{Error, Result}; +use super::timer::Timer; +use super::UefiOS; +use crate::os::timer::rdtsc; pub const PACKET_SIZE: usize = 1514; @@ -182,8 +175,8 @@ impl NetworkInterface { )); let mut interface_config = Config::new(hw_addr); - interface_config.random_seed = os.rng().rand_u64(); - let now = Instant::from_micros(os.timer().micros()); + interface_config.random_seed = rdtsc() as u64; + let now = Timer::instant(); let interface = Interface::new(interface_config, &mut device, now); let mut dhcp_socket = Dhcpv4Socket::new(); dhcp_socket.set_outgoing_options(&[DhcpOption { @@ -198,7 +191,7 @@ impl NetworkInterface { dhcp_socket_handle, device, socket_set, - ephemeral_port_counter: os.rng().rand_u64(), + ephemeral_port_counter: 0, rx: 0, tx: 0, vrx: 0, @@ -220,8 +213,8 @@ impl NetworkInterface { self.interface.ipv4_addr() } - pub(super) fn poll(&mut self, timer: &Timer) -> bool { - let now = timer.instant(); + pub(super) fn poll(&mut self) -> bool { + let now = Timer::instant(); let status = self .interface .poll(now, &mut self.device, &mut self.socket_set); @@ -341,7 +334,7 @@ impl TcpStream { let socket = net.socket_set.get_mut::(self.handle); let sent = socket.send_slice(&data[pos..]); if let Err(err) = sent { - return Poll::Ready(Err(Error::TcpSend(err))); + return Poll::Ready(Err(err.into())); } pos += sent.unwrap(); if pos < data.len() { @@ -374,7 +367,7 @@ impl TcpStream { return Poll::Ready(Ok(0)); } if let Err(err) = recvd { - return Poll::Ready(Err(Error::Recv(err))); + return Poll::Ready(Err(err.into())); } if recvd.unwrap() == 0 { socket.register_recv_waker(cx.waker()); diff --git a/pixie-uefi/src/os/rng.rs b/pixie-uefi/src/os/rng.rs deleted file mode 100644 index 70bec4ba..00000000 --- a/pixie-uefi/src/os/rng.rs +++ /dev/null @@ -1,46 +0,0 @@ -use core::arch::x86_64::{_rdseed64_step, _rdtsc}; -use rand::{distributions::Uniform, prelude::Distribution, SeedableRng}; -use rand_xoshiro::Xoshiro256StarStar; - -pub struct Rng { - rng: Xoshiro256StarStar, -} - -impl Default for Rng { - fn default() -> Self { - Self::new() - } -} - -impl Rng { - pub fn new() -> Rng { - // Try to generate a random number with rdseed up to 10 times, but if that fails, use - // the timestamp counter. - let mut seed = 0; - // SAFETY: modern x86 CPUs have _rdtsc. We use feature detection for rdseed. - unsafe { - if core_detect::is_x86_feature_detected!("rdseed") { - for _i in 0..10 { - if _rdseed64_step(&mut seed) == 1 { - break; - } else { - seed = _rdtsc(); - } - } - } else { - seed = _rdtsc(); - } - } - Rng { - rng: Xoshiro256StarStar::seed_from_u64(seed), - } - } - - pub fn rand>(&mut self, d: &D) -> T { - d.sample(&mut self.rng) - } - - pub fn rand_u64(&mut self) -> u64 { - self.rand(&Uniform::new_inclusive(0, u64::MAX)) - } -} diff --git a/pixie-uefi/src/os/sync.rs b/pixie-uefi/src/os/sync.rs index 4900c27c..5b310e13 100644 --- a/pixie-uefi/src/os/sync.rs +++ b/pixie-uefi/src/os/sync.rs @@ -1,4 +1,5 @@ -use core::{cell::RefCell, ops::Deref}; +use core::cell::RefCell; +use core::ops::Deref; pub struct SyncRefCell(RefCell); diff --git a/pixie-uefi/src/os/timer.rs b/pixie-uefi/src/os/timer.rs index 4fa2bafa..057be32c 100644 --- a/pixie-uefi/src/os/timer.rs +++ b/pixie-uefi/src/os/timer.rs @@ -1,43 +1,49 @@ use core::arch::x86_64::_rdtsc; +use core::sync::atomic::{AtomicBool, AtomicI64, Ordering}; +use core::time::Duration; + use smoltcp::time::Instant; -pub struct Timer { - ticks_at_start: i64, - ticks_per_micro: i64, +static TICKS_AT_START: AtomicI64 = AtomicI64::new(0); +static TICKS_PER_MICRO: AtomicI64 = AtomicI64::new(0); +static INITIALIZED: AtomicBool = AtomicBool::new(false); + +pub struct Timer {} + +pub(super) fn rdtsc() -> i64 { + // SAFETY: modern x86 CPUs have this instruction. + unsafe { _rdtsc() as i64 } } impl Timer { - fn rdtsc() -> i64 { - // SAFETY: modern x86 CPUs have this instruction. - unsafe { _rdtsc() as i64 } - } - - pub fn new() -> Timer { - // Read timer clock & wait to stabilize the counter. - Self::rdtsc(); - uefi::boot::stall(20000); - let tsc_before = Self::rdtsc(); - uefi::boot::stall(20000); - let tsc_after = Self::rdtsc(); - - Timer { - ticks_at_start: tsc_after, - // TICKS_PER_MICRO is a multiple of 10 on every reasonable system. - ticks_per_micro: (tsc_after - tsc_before) / (20000 * 10) * 10, + pub(super) fn ensure_init() { + if INITIALIZED.load(Ordering::Relaxed) { + return; } - } + // Read timer clock & wait to stabilize the counter. + rdtsc(); + uefi::boot::stall(Duration::from_micros(20000)); + let tsc_before = rdtsc(); + uefi::boot::stall(Duration::from_micros(20000)); + let tsc_after = rdtsc(); - pub fn micros(&self) -> i64 { - (Self::rdtsc() - self.ticks_at_start) / self.ticks_per_micro + TICKS_AT_START.store(tsc_after, Ordering::Relaxed); + // TICKS_PER_MICRO is a multiple of 10 on every reasonable system. + TICKS_PER_MICRO.store( + (tsc_after - tsc_before) / (20000 * 10) * 10, + Ordering::Relaxed, + ); + INITIALIZED.store(true, Ordering::Relaxed); } - pub fn instant(&self) -> Instant { - Instant::from_micros(self.micros()) + pub fn micros() -> i64 { + Self::ensure_init(); + let ticks_at_start = TICKS_AT_START.load(Ordering::Relaxed); + let ticks_per_micro = TICKS_PER_MICRO.load(Ordering::Relaxed); + (rdtsc() - ticks_at_start) / ticks_per_micro } -} -impl Default for Timer { - fn default() -> Self { - Self::new() + pub fn instant() -> Instant { + Instant::from_micros(Timer::micros()) } } diff --git a/pixie-uefi/src/parse_disk/ext4.rs b/pixie-uefi/src/parse_disk/ext4.rs index b249d2e6..5d069121 100644 --- a/pixie-uefi/src/parse_disk/ext4.rs +++ b/pixie-uefi/src/parse_disk/ext4.rs @@ -1,10 +1,10 @@ -use super::{le16, le32, le64_32_32}; -use crate::{ - os::{disk::Disk, error::Result}, - store::ChunkInfo, -}; use alloc::vec::Vec; +use super::{le16, le32, le64_32_32}; +use crate::os::disk::Disk; +use crate::os::error::Result; +use crate::store::ChunkInfo; + fn has_superblock(group: usize) -> bool { if group <= 1 { return true; diff --git a/pixie-uefi/src/parse_disk/fat.rs b/pixie-uefi/src/parse_disk/fat.rs index e5de4b05..e6fe96ba 100644 --- a/pixie-uefi/src/parse_disk/fat.rs +++ b/pixie-uefi/src/parse_disk/fat.rs @@ -1,10 +1,10 @@ -use super::{le16, le32}; -use crate::{ - os::{disk::Disk, error::Result}, - store::ChunkInfo, -}; use alloc::vec::Vec; +use super::{le16, le32}; +use crate::os::disk::Disk; +use crate::os::error::Result; +use crate::store::ChunkInfo; + #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum Type { Fat12, diff --git a/pixie-uefi/src/parse_disk/gpt.rs b/pixie-uefi/src/parse_disk/gpt.rs index d6bcffd1..974b19e2 100644 --- a/pixie-uefi/src/parse_disk/gpt.rs +++ b/pixie-uefi/src/parse_disk/gpt.rs @@ -1,11 +1,12 @@ -use crate::{ - os::{disk::Disk, error::Result}, - store::ChunkInfo, -}; use alloc::vec::Vec; + use log::info; use pixie_shared::util::BytesFmt; +use crate::os::disk::Disk; +use crate::os::error::Result; +use crate::store::ChunkInfo; + pub async fn parse_gpt(disk: &mut Disk) -> Result>> { let disk_size = disk.size() as usize; let partitions = match disk.partitions() { diff --git a/pixie-uefi/src/parse_disk/mod.rs b/pixie-uefi/src/parse_disk/mod.rs index b768d31d..f1c20c1c 100644 --- a/pixie-uefi/src/parse_disk/mod.rs +++ b/pixie-uefi/src/parse_disk/mod.rs @@ -1,10 +1,12 @@ -use crate::{ - os::{disk::Disk, error::Result}, - store::ChunkInfo, -}; use alloc::vec::Vec; + use log::info; -use pixie_shared::{util::BytesFmt, MAX_CHUNK_SIZE}; +use pixie_shared::util::BytesFmt; +use pixie_shared::MAX_CHUNK_SIZE; + +use crate::os::disk::Disk; +use crate::os::error::Result; +use crate::store::ChunkInfo; mod ext4; mod fat; diff --git a/pixie-uefi/src/parse_disk/ntfs.rs b/pixie-uefi/src/parse_disk/ntfs.rs index 50c8c8f1..8156b6e4 100644 --- a/pixie-uefi/src/parse_disk/ntfs.rs +++ b/pixie-uefi/src/parse_disk/ntfs.rs @@ -1,13 +1,10 @@ -use super::{le16, le32, le64}; -use crate::{ - os::{ - disk::Disk, - error::{Error, Result}, - }, - store::ChunkInfo, -}; use alloc::vec::Vec; +use super::{le16, le32, le64}; +use crate::os::disk::Disk; +use crate::os::error::Result; +use crate::store::ChunkInfo; + pub async fn get_ntfs_chunks(disk: &Disk, start: u64, end: u64) -> Result>> { if end - start < 512 { return Ok(None); @@ -42,8 +39,7 @@ pub async fn get_ntfs_chunks(disk: &Disk, start: u64, end: u64) -> Result