rename block
to sector
to better reflect its purpose
This commit is contained in:
parent
6e86749246
commit
ab069b60e6
|
@ -7,7 +7,7 @@ use alloc::boxed::Box;
|
||||||
use alloc::borrow::{Cow, ToOwned};
|
use alloc::borrow::{Cow, ToOwned};
|
||||||
|
|
||||||
use error::Infallible;
|
use error::Infallible;
|
||||||
use block::{Address, Size};
|
use sector::{Address, Size};
|
||||||
|
|
||||||
pub mod length;
|
pub mod length;
|
||||||
use self::length::Length;
|
use self::length::Length;
|
||||||
|
@ -283,7 +283,7 @@ mod file {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use block::{Address, Size};
|
use sector::{Address, Size};
|
||||||
|
|
||||||
use super::{Buffer, BufferCommit, BufferSlice};
|
use super::{Buffer, BufferCommit, BufferSlice};
|
||||||
use super::length::Length;
|
use super::length::Length;
|
||||||
|
@ -355,7 +355,7 @@ mod file {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use block::{Address, Size512};
|
use sector::{Address, Size512};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -4,7 +4,7 @@ use core::marker::PhantomData;
|
||||||
use alloc::Vec;
|
use alloc::Vec;
|
||||||
|
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use block::{Address, Size};
|
use sector::{Address, Size};
|
||||||
use buffer::{Buffer, BufferSlice};
|
use buffer::{Buffer, BufferSlice};
|
||||||
use sys::superblock::Superblock;
|
use sys::superblock::Superblock;
|
||||||
use sys::block_group::BlockGroupDescriptor;
|
use sys::block_group::BlockGroupDescriptor;
|
||||||
|
@ -221,7 +221,7 @@ mod tests {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use block::{Address, Size512};
|
use sector::{Address, Size512};
|
||||||
use buffer::Buffer;
|
use buffer::Buffer;
|
||||||
|
|
||||||
use super::Ext2;
|
use super::Ext2;
|
||||||
|
|
|
@ -15,7 +15,7 @@ extern crate core;
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod sys;
|
pub mod sys;
|
||||||
pub mod block;
|
pub mod sector;
|
||||||
pub mod buffer;
|
pub mod buffer;
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use core::fmt::{self, Debug, Display, LowerHex};
|
||||||
use core::iter::Step;
|
use core::iter::Step;
|
||||||
|
|
||||||
pub trait Size: PartialOrd {
|
pub trait Size: PartialOrd {
|
||||||
// log_block_size = log_2(block_size)
|
// log_sector_size = log_2(sector_size)
|
||||||
const LOG_SIZE: u32;
|
const LOG_SIZE: u32;
|
||||||
const SIZE: usize = 1 << Self::LOG_SIZE;
|
const SIZE: usize = 1 << Self::LOG_SIZE;
|
||||||
const OFFSET_MASK: usize = Self::SIZE - 1;
|
const OFFSET_MASK: usize = Self::SIZE - 1;
|
||||||
|
@ -32,26 +32,26 @@ impl Size for Size4096 {
|
||||||
/// Address in a physical sector
|
/// Address in a physical sector
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
pub struct Address<S: Size> {
|
pub struct Address<S: Size> {
|
||||||
block: usize,
|
sector: usize,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
_phantom: PhantomData<S>,
|
_phantom: PhantomData<S>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Size> Address<S> {
|
impl<S: Size> Address<S> {
|
||||||
pub unsafe fn new_unchecked(block: usize, offset: usize) -> Address<S> {
|
pub unsafe fn new_unchecked(sector: usize, offset: usize) -> Address<S> {
|
||||||
assert!(offset < S::SIZE, "offset out of block bounds");
|
assert!(offset < S::SIZE, "offset out of sector bounds");
|
||||||
let _phantom = PhantomData;
|
let _phantom = PhantomData;
|
||||||
Address {
|
Address {
|
||||||
block,
|
sector,
|
||||||
offset,
|
offset,
|
||||||
_phantom,
|
_phantom,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(block: usize, offset: isize) -> Address<S> {
|
pub fn new(sector: usize, offset: isize) -> Address<S> {
|
||||||
let block = (block as isize + (offset >> S::LOG_SIZE)) as usize;
|
let sector = (sector as isize + (offset >> S::LOG_SIZE)) as usize;
|
||||||
let offset = offset.abs() as usize & S::OFFSET_MASK;
|
let offset = offset.abs() as usize & S::OFFSET_MASK;
|
||||||
unsafe { Address::new_unchecked(block, offset) }
|
unsafe { Address::new_unchecked(sector, offset) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_block_size(
|
pub fn with_block_size(
|
||||||
|
@ -62,30 +62,30 @@ impl<S: Size> Address<S> {
|
||||||
let log_diff = log_block_size as isize - S::LOG_SIZE as isize;
|
let log_diff = log_block_size as isize - S::LOG_SIZE as isize;
|
||||||
let top_offset = offset >> S::LOG_SIZE;
|
let top_offset = offset >> S::LOG_SIZE;
|
||||||
let offset = offset & ((1 << log_block_size) - 1);
|
let offset = offset & ((1 << log_block_size) - 1);
|
||||||
let block = block << log_diff | top_offset;
|
let sector = block << log_diff | top_offset;
|
||||||
Address::new(block, offset as isize)
|
Address::new(sector, offset as isize)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index64(&self) -> u64 {
|
pub fn index64(&self) -> u64 {
|
||||||
((self.block as u64) << S::LOG_SIZE) + self.offset as u64
|
((self.sector as u64) << S::LOG_SIZE) + self.offset as u64
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_index(&self) -> Option<usize> {
|
pub fn into_index(&self) -> Option<usize> {
|
||||||
self.block
|
self.sector
|
||||||
.checked_shl(S::LOG_SIZE)
|
.checked_shl(S::LOG_SIZE)
|
||||||
.and_then(|block| block.checked_add(self.offset))
|
.and_then(|sector| sector.checked_add(self.offset))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn block_size(&self) -> usize {
|
pub const fn sector_size(&self) -> usize {
|
||||||
S::SIZE
|
S::SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn log_block_size(&self) -> u32 {
|
pub const fn log_sector_size(&self) -> u32 {
|
||||||
S::LOG_SIZE
|
S::LOG_SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn block(&self) -> usize {
|
pub fn sector(&self) -> usize {
|
||||||
self.block
|
self.sector
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn offset(&self) -> usize {
|
pub fn offset(&self) -> usize {
|
||||||
|
@ -95,8 +95,8 @@ impl<S: Size> Address<S> {
|
||||||
|
|
||||||
impl<S: Size + Clone + PartialOrd> Step for Address<S> {
|
impl<S: Size + Clone + PartialOrd> Step for Address<S> {
|
||||||
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
|
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
|
||||||
if end.block >= start.block {
|
if end.sector >= start.sector {
|
||||||
Some(end.block - start.block)
|
Some(end.sector - start.sector)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -111,17 +111,17 @@ impl<S: Size + Clone + PartialOrd> Step for Address<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_one(&self) -> Self {
|
fn add_one(&self) -> Self {
|
||||||
Address::new(self.block + 1, 0)
|
Address::new(self.sector + 1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sub_one(&self) -> Self {
|
fn sub_one(&self) -> Self {
|
||||||
Address::new(self.block - 1, 0)
|
Address::new(self.sector - 1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_usize(&self, n: usize) -> Option<Self> {
|
fn add_usize(&self, n: usize) -> Option<Self> {
|
||||||
self.block
|
self.sector
|
||||||
.checked_add(n)
|
.checked_add(n)
|
||||||
.map(|block| Address::new(block, 0))
|
.map(|sector| Address::new(sector, 0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ impl<S: Size> Debug for Address<S> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let name = format!("Address<{}>", S::SIZE);
|
let name = format!("Address<{}>", S::SIZE);
|
||||||
f.debug_struct(&name)
|
f.debug_struct(&name)
|
||||||
.field("block", &self.block)
|
.field("sector", &self.sector)
|
||||||
.field("offset", &self.offset)
|
.field("offset", &self.offset)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
@ -137,29 +137,29 @@ impl<S: Size> Debug for Address<S> {
|
||||||
|
|
||||||
impl<S: Size> Display for Address<S> {
|
impl<S: Size> Display for Address<S> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}:{}", self.block, self.offset)
|
write!(f, "{}:{}", self.sector, self.offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Size> LowerHex for Address<S> {
|
impl<S: Size> LowerHex for Address<S> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{:x}:{:x}", self.block, self.offset)
|
write!(f, "{:x}:{:x}", self.sector, self.offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Size> From<u64> for Address<S> {
|
impl<S: Size> From<u64> for Address<S> {
|
||||||
fn from(idx: u64) -> Address<S> {
|
fn from(idx: u64) -> Address<S> {
|
||||||
let block = idx >> S::LOG_SIZE;
|
let sector = idx >> S::LOG_SIZE;
|
||||||
let offset = idx & S::OFFSET_MASK as u64;
|
let offset = idx & S::OFFSET_MASK as u64;
|
||||||
Address::new(block as usize, offset as isize)
|
Address::new(sector as usize, offset as isize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Size> From<usize> for Address<S> {
|
impl<S: Size> From<usize> for Address<S> {
|
||||||
fn from(idx: usize) -> Address<S> {
|
fn from(idx: usize) -> Address<S> {
|
||||||
let block = idx >> S::LOG_SIZE;
|
let sector = idx >> S::LOG_SIZE;
|
||||||
let offset = idx & S::OFFSET_MASK;
|
let offset = idx & S::OFFSET_MASK;
|
||||||
Address::new(block, offset as isize)
|
Address::new(sector, offset as isize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ impl<S: Size> Add for Address<S> {
|
||||||
type Output = Address<S>;
|
type Output = Address<S>;
|
||||||
fn add(self, rhs: Address<S>) -> Address<S> {
|
fn add(self, rhs: Address<S>) -> Address<S> {
|
||||||
Address::new(
|
Address::new(
|
||||||
self.block + rhs.block,
|
self.sector + rhs.sector,
|
||||||
(self.offset + rhs.offset) as isize,
|
(self.offset + rhs.offset) as isize,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ impl<S: Size> Sub for Address<S> {
|
||||||
type Output = Address<S>;
|
type Output = Address<S>;
|
||||||
fn sub(self, rhs: Address<S>) -> Address<S> {
|
fn sub(self, rhs: Address<S>) -> Address<S> {
|
||||||
Address::new(
|
Address::new(
|
||||||
self.block - rhs.block,
|
self.sector - rhs.sector,
|
||||||
self.offset as isize - rhs.offset as isize,
|
self.offset as isize - rhs.offset as isize,
|
||||||
)
|
)
|
||||||
}
|
}
|
|
@ -4,7 +4,7 @@ use core::fmt::{self, Debug};
|
||||||
use alloc::Vec;
|
use alloc::Vec;
|
||||||
|
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use block::{Address, Size};
|
use sector::{Address, Size};
|
||||||
use buffer::Buffer;
|
use buffer::Buffer;
|
||||||
|
|
||||||
/// The Block Group Descriptor Table contains a descriptor for each block group
|
/// The Block Group Descriptor Table contains a descriptor for each block group
|
||||||
|
@ -66,9 +66,9 @@ impl BlockGroupDescriptor {
|
||||||
offset + Address::from(mem::size_of::<BlockGroupDescriptor>());
|
offset + Address::from(mem::size_of::<BlockGroupDescriptor>());
|
||||||
if haystack.len() < end {
|
if haystack.len() < end {
|
||||||
return Err(Error::AddressOutOfBounds(
|
return Err(Error::AddressOutOfBounds(
|
||||||
end.block(),
|
end.sector(),
|
||||||
end.offset(),
|
end.offset(),
|
||||||
end.block_size(),
|
end.sector_size(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +94,9 @@ impl BlockGroupDescriptor {
|
||||||
+ Address::from(count * mem::size_of::<BlockGroupDescriptor>());
|
+ Address::from(count * mem::size_of::<BlockGroupDescriptor>());
|
||||||
if haystack.len() < end {
|
if haystack.len() < end {
|
||||||
return Err(Error::AddressOutOfBounds(
|
return Err(Error::AddressOutOfBounds(
|
||||||
end.block(),
|
end.sector(),
|
||||||
end.offset(),
|
end.offset(),
|
||||||
end.block_size(),
|
end.sector_size(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ impl BlockGroupDescriptor {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use block::{Address, Size512};
|
use sector::{Address, Size512};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -2,7 +2,7 @@ use core::mem;
|
||||||
use core::fmt::{self, Debug};
|
use core::fmt::{self, Debug};
|
||||||
|
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use block::{Address, Size};
|
use sector::{Address, Size};
|
||||||
use buffer::Buffer;
|
use buffer::Buffer;
|
||||||
|
|
||||||
/// An inode is a structure on the disk that represents a file, directory,
|
/// An inode is a structure on the disk that represents a file, directory,
|
||||||
|
@ -115,9 +115,9 @@ impl Inode {
|
||||||
let end = offset + Address::from(size);
|
let end = offset + Address::from(size);
|
||||||
if haystack.len() < end {
|
if haystack.len() < end {
|
||||||
return Err(Error::AddressOutOfBounds(
|
return Err(Error::AddressOutOfBounds(
|
||||||
end.block(),
|
end.sector(),
|
||||||
end.offset(),
|
end.offset(),
|
||||||
end.block_size(),
|
end.sector_size(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use core::mem;
|
||||||
use core::fmt::{self, Debug};
|
use core::fmt::{self, Debug};
|
||||||
|
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use block::{Address, Size};
|
use sector::{Address, Size};
|
||||||
use buffer::Buffer;
|
use buffer::Buffer;
|
||||||
|
|
||||||
/// Ext2 signature (0xef53), used to help confirm the presence of Ext2 on a
|
/// Ext2 signature (0xef53), used to help confirm the presence of Ext2 on a
|
||||||
|
@ -205,9 +205,9 @@ impl Superblock {
|
||||||
let end = offset + Address::from(mem::size_of::<Superblock>());
|
let end = offset + Address::from(mem::size_of::<Superblock>());
|
||||||
if haystack.len() < end {
|
if haystack.len() < end {
|
||||||
return Err(Error::AddressOutOfBounds(
|
return Err(Error::AddressOutOfBounds(
|
||||||
end.block(),
|
end.sector(),
|
||||||
end.offset(),
|
end.offset(),
|
||||||
end.block_size(),
|
end.sector_size(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ bitflags! {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use block::Size512;
|
use sector::Size512;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Reference in a new issue