From 95d8d84eef645b52d92fd3fb8fdea7aed1f6d474 Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Fri, 17 Nov 2023 11:40:33 -0800 Subject: Layer 1 incomplete --- src/disk/bitmap.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/disk/bitmap.rs') diff --git a/src/disk/bitmap.rs b/src/disk/bitmap.rs index a5a9cc4..d5a8fe9 100644 --- a/src/disk/bitmap.rs +++ b/src/disk/bitmap.rs @@ -19,20 +19,25 @@ impl Bitmap { dirty_blocks: Vec::new(), } } - pub fn allocate(&mut self) -> usize { + pub fn allocate(&mut self) -> Option { 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; self.dirty_blocks.push(i / BLOCK_SIZE); - return i * 8 + leading_ones as usize; + return Some(i * 8 + leading_ones as usize); } } - panic!("No more space for allocation!") + None + // panic!("No more space for allocation!") } pub fn query(&self, index: usize) -> bool { - self.data[index / 8] & ((1 << (7 - index % 8)) as u8) != 0 + if index == 0 { + false + } else { + self.data[index / 8] & ((1 << (7 - index % 8)) as u8) != 0 + } } fn write_back(&mut self) { -- cgit v1.2.3-70-g09d2