diff options
author | Chuyan Zhang <me@zcy.moe> | 2023-11-30 12:01:11 -0800 |
---|---|---|
committer | Chuyan Zhang <me@zcy.moe> | 2023-11-30 12:01:11 -0800 |
commit | fd125947c9db0b33761414e65e919f73d9bf1815 (patch) | |
tree | c4c66d95ba85601427928aa7f23659590055d464 /ayafs/src/disk/bitmap.rs | |
parent | 1eac97eea4ec0bcef0be061a2cba93a584355283 (diff) | |
download | myfs-fd125947c9db0b33761414e65e919f73d9bf1815.tar.gz myfs-fd125947c9db0b33761414e65e919f73d9bf1815.zip |
Refactor workspace
Diffstat (limited to 'ayafs/src/disk/bitmap.rs')
-rw-r--r-- | ayafs/src/disk/bitmap.rs | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/ayafs/src/disk/bitmap.rs b/ayafs/src/disk/bitmap.rs deleted file mode 100644 index b68c341..0000000 --- a/ayafs/src/disk/bitmap.rs +++ /dev/null @@ -1,48 +0,0 @@ -use crate::block_device::{BlockDevice, BLOCK_SIZE}; -use std::sync::Arc; - -pub struct Bitmap { - pub starting_block: usize, - pub length: usize, - pub device: Arc<dyn BlockDevice>, - pub data: Vec<u8>, -} - -impl Bitmap { - pub(crate) fn new(starting_block: usize, length: usize, device: Arc<dyn BlockDevice>) -> Self { - Self { - starting_block, - length, - device, - data: vec![0u8; length * BLOCK_SIZE], - } - } - pub(crate) fn allocate(&mut self) -> Option<usize> { - for (i, byte) in self.data.iter_mut().enumerate() { - let leading_ones = byte.leading_ones(); - if leading_ones != 8 { - *byte |= (1 << (7 - leading_ones)) as u8; - return Some(i * 8 + leading_ones as usize); - } - } - None - } - - pub(crate) fn query(&self, index: usize) -> bool { - if index == 0 { - false - } else { - self.data[index / 8] & ((1 << (7 - index % 8)) as u8) != 0 - } - } - - pub(crate) fn deallocate(&mut self, index: usize) -> bool { - if self.query(index) { - let mask = !(1u8 << (7 - index % 8)); - self.data[index / 8] &= mask; - true - } else { - false - } - } -} |