minor fixes
This commit is contained in:
parent
096cc865a4
commit
c5f0edeabc
|
@ -11,7 +11,6 @@
|
|||
/// Remember that blocks are numbered starting at 0, and that block numbers
|
||||
/// don't usually correspond to physical block addresses.
|
||||
#[repr(C, packed)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct BlockGroupDescriptor {
|
||||
/// Block address of block usage bitmap
|
||||
block_usage_addr: u32,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#[repr(C, packed)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Inode {
|
||||
/// Type and Permissions (see below)
|
||||
type_perm: u16,
|
||||
|
|
|
@ -47,7 +47,6 @@ pub const OS_LITE: u32 = 4;
|
|||
/// 512 byte sectors, the Superblock will begin at LBA 2 and will occupy all of
|
||||
/// sector 2 and 3.
|
||||
#[repr(C, packed)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Superblock {
|
||||
// taken from https://wiki.osdev.org/Ext2
|
||||
/// Total number of inodes in file system
|
||||
|
@ -163,8 +162,8 @@ impl Superblock {
|
|||
}
|
||||
|
||||
let superblock: &mut Superblock = unsafe {
|
||||
let ptr =
|
||||
haystack.as_ptr().offset(offset as isize) as *mut Superblock;
|
||||
let ptr = haystack.as_mut_ptr().offset(offset as isize)
|
||||
as *mut Superblock;
|
||||
ptr.as_mut().unwrap()
|
||||
};
|
||||
|
||||
|
@ -190,7 +189,7 @@ impl Superblock {
|
|||
}
|
||||
|
||||
let ptr = unsafe {
|
||||
haystack.as_ptr().offset(offset as isize)
|
||||
haystack.as_mut_ptr().offset(offset as isize)
|
||||
as *mut BlockGroupDescriptor
|
||||
};
|
||||
let slice = unsafe { slice::from_raw_parts_mut(ptr, count) };
|
||||
|
@ -266,3 +265,24 @@ bitflags! {
|
|||
const RONLY_BTREE_DIRECTORY = 0x0004;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn find() {
|
||||
let mut buffer = vec![0_u8; 4096];
|
||||
let addr = &buffer[1024] as *const _ as usize;
|
||||
// magic
|
||||
buffer[1024 + 56] = EXT2_MAGIC as u8;
|
||||
buffer[1024 + 57] = (EXT2_MAGIC >> 8) as u8;
|
||||
let superblock = Superblock::find(&mut buffer);
|
||||
assert!(
|
||||
superblock.is_ok(),
|
||||
"Err({:?})",
|
||||
superblock.err().unwrap_or_else(|| unreachable!()),
|
||||
);
|
||||
assert_eq!(superblock.unwrap() as *const _ as usize, addr);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue