MCPcopy Create free account
hub / github.com/chyyuu/os_kernel_lab / alloc

Method alloc

easy-fs/src/bitmap.rs:28–54  ·  view source on GitHub ↗
(&self, block_device: &Arc<dyn BlockDevice>)

Source from the content-addressed store, hash-verified

26 }
27
28 pub fn alloc(&self, block_device: &Arc<dyn BlockDevice>) -> Option<usize> {
29 for block_id in 0..self.blocks {
30 let pos = get_block_cache(
31 block_id + self.start_block_id as usize,
32 Arc::clone(block_device),
33 )
34 .lock()
35 .modify(0, |bitmap_block: &mut BitmapBlock| {
36 if let Some((bits64_pos, inner_pos)) = bitmap_block
37 .iter()
38 .enumerate()
39 .find(|(_, bits64)| **bits64 != u64::MAX)
40 .map(|(bits64_pos, bits64)| (bits64_pos, bits64.trailing_ones() as usize))
41 {
42 // modify cache
43 bitmap_block[bits64_pos] |= 1u64 << inner_pos;
44 Some(block_id * BLOCK_BITS + bits64_pos * 64 + inner_pos as usize)
45 } else {
46 None
47 }
48 });
49 if pos.is_some() {
50 return pos;
51 }
52 }
53 None
54 }
55
56 pub fn dealloc(&self, block_device: &Arc<dyn BlockDevice>, bit: usize) {
57 let (block_pos, bits64_pos, inner_pos) = decomposition(bit);

Callers 2

alloc_inodeMethod · 0.45
alloc_dataMethod · 0.45

Calls 6

get_block_cacheFunction · 0.85
cloneFunction · 0.85
modifyMethod · 0.80
lockMethod · 0.80
findMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected