diff --git a/src/lib.rs b/src/lib.rs index 6655547..3c380bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,13 +3,17 @@ extern crate alloc; use alloc::boxed::Box; +use alloc::vec::Vec; + +// i chose this arbitrarily, but i don't think that many people will need to access over 67 million terabytes of data from a disk +pub type Index = u64; /// # BlockDevice /// interface for accessing a block device, i.e. a device that can be randomly accessed in fixed-size blocks /// will be implemented in vapblock_* libraries pub trait BlockDevice { - /// moves the "cursor" to the given offset - fn seek(&mut self, offset: usize); + /// moves the "cursor" to the given offset, returns false on failure + fn seek(&mut self, offset: Index) -> bool; fn block_size(&self) -> usize; /// reads buf.len() bytes into buf, starting at the current offset /// returns the number of bytes read @@ -22,11 +26,33 @@ pub trait BlockDevice { fn write_blocks(&mut self, buf: &[u8]) -> usize; } +/// # BasicROPartition +/// interface for a partition from a `BasicROPartitionTable` +/// must implement `BlockDevice` +pub trait BasicROPartition: BlockDevice { + /// returns a `&str` of this partition's type + /// implementation-specific + fn partition_type<'a>(&self) -> &'a str; + /// returns this partition's size in bytes + fn size(&self) -> Index; +} + +/// # BasicROPartitionTable +/// interface for basic interactions with a partition table over a block device +pub trait BasicROPartitionTable { + /// must be called before any other methods + fn init(&mut self, block_device: &mut dyn BlockDevice); + /// returns number of partitions + fn partition_count(&self) -> usize; + /// returns Vec of (partiton_name: &str, partition: BasicROPartition) + fn partitions<'a>(&self) -> Vec<(&'a str, &'a mut T)>; +} + /// # BasicROFile /// interface for basic interactions with a file on a BasicROFileSystem pub trait BasicROFile { /// moves the "cursor" to the given offset - fn seek(&mut self, offset: usize); + fn seek(&mut self, offset: Index); /// reads buf.len() bytes into buf, starting at the current offset /// returns the number of bytes read /// may return less than buf.len() if the end of the file is reached