add offset argument to BlockGroupDescriptor::find_...

This commit is contained in:
Szymon Walter 2018-03-19 19:33:20 +01:00
parent 35170f2aee
commit 0fc2c934d9

View file

@ -56,14 +56,14 @@ impl BlockGroupDescriptor {
Ok(descr) Ok(descr)
} }
pub fn find_descriptor_table<'a, E>( pub unsafe fn find_descriptor_table<'a, E>(
haystack: &'a Buffer<u8, Error = E>, haystack: &'a Buffer<u8, Error = E>,
offset: usize,
count: usize, count: usize,
) -> Result<(Vec<BlockGroupDescriptor>, usize), Error> ) -> Result<(Vec<BlockGroupDescriptor>, usize), Error>
where where
Error: From<E>, Error: From<E>,
{ {
let offset = 2048; // TODO: this assumes a block size
let end = offset + count * mem::size_of::<BlockGroupDescriptor>(); let end = offset + count * mem::size_of::<BlockGroupDescriptor>();
if haystack.len() < end { if haystack.len() < end {
return Err(Error::OutOfBounds(end)); return Err(Error::OutOfBounds(end));
@ -88,7 +88,8 @@ mod tests {
#[test] #[test]
fn find() { fn find() {
let buffer = vec![0_u8; 4096]; let buffer = vec![0_u8; 4096];
let table = BlockGroupDescriptor::find_descriptor_table(&buffer, 8); let table =
BlockGroupDescriptor::find_descriptor_table(&buffer, 2048, 8);
assert!( assert!(
table.is_ok(), table.is_ok(),
"Err({:?})", "Err({:?})",