diff options
Diffstat (limited to 'src/disk/bitmap.rs')
-rw-r--r-- | src/disk/bitmap.rs | 13 |
1 files changed, 9 insertions, 4 deletions
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<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; 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) { |