diff --git a/src/fs.rs b/src/fs.rs index c8b63cd..84f9862 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -29,7 +29,7 @@ where Error: From, { pub fn new(buffer: B) -> Result, Error> { - let superblock = Struct::from(Superblock::find(&buffer)?); + let superblock = unsafe { Struct::from(Superblock::find(&buffer)?) }; let block_size = superblock.inner.block_size(); let block_groups_offset = (superblock.inner.first_data_block as usize + 1) * block_size; @@ -38,11 +38,13 @@ where .block_group_count() .map(|count| count as usize) .map_err(|(a, b)| Error::BadBlockGroupCount(a, b))?; - let block_groups = BlockGroupDescriptor::find_descriptor_table( - &buffer, - block_groups_offset, - block_groups_count, - )?; + let block_groups = unsafe { + BlockGroupDescriptor::find_descriptor_table( + &buffer, + block_groups_offset, + block_groups_count, + )? + }; let block_groups = Struct::from(block_groups); Ok(Ext2 { buffer, diff --git a/src/sys/block_group.rs b/src/sys/block_group.rs index 05e0a95..4e5e65d 100644 --- a/src/sys/block_group.rs +++ b/src/sys/block_group.rs @@ -72,7 +72,7 @@ impl BlockGroupDescriptor { let mut vec = Vec::with_capacity(count); for i in 0..count { let offset = offset + i * mem::size_of::(); - vec.push(unsafe { + vec.push({ BlockGroupDescriptor::find_descriptor(haystack, offset)?.0 }); } @@ -88,8 +88,9 @@ mod tests { #[test] fn find() { let buffer = vec![0_u8; 4096]; - let table = - BlockGroupDescriptor::find_descriptor_table(&buffer, 2048, 8); + let table = unsafe { + BlockGroupDescriptor::find_descriptor_table(&buffer, 2048, 8) + }; assert!( table.is_ok(), "Err({:?})", diff --git a/src/sys/superblock.rs b/src/sys/superblock.rs index b18bd1e..3d16b05 100644 --- a/src/sys/superblock.rs +++ b/src/sys/superblock.rs @@ -157,7 +157,7 @@ impl Superblock { return Err(Error::OutOfBounds(end)); } - let superblock = unsafe { + let superblock = { haystack .slice_unchecked(offset..end) .dynamic_cast::() @@ -250,7 +250,7 @@ mod tests { // magic buffer[1024 + 56] = EXT2_MAGIC as u8; buffer[1024 + 57] = (EXT2_MAGIC >> 8) as u8; - let superblock = Superblock::find(&buffer); + let superblock = unsafe { Superblock::find(&buffer) }; assert!( superblock.is_ok(), "Err({:?})", @@ -265,7 +265,7 @@ mod tests { use std::fs::File; let file = RefCell::new(File::open("ext2.bin").unwrap()); - let superblock = Superblock::find(&file); + let superblock = unsafe { Superblock::find(&file) }; assert!( superblock.is_ok(), "Err({:?})",