From 26404b4a0de82b7af7e76fe057f5756669e7432f Mon Sep 17 00:00:00 2001 From: Yu Chen Date: Wed, 30 Mar 2022 20:49:54 +0800 Subject: [PATCH] update comments in easy_fs --- os/src/fs/easy_fs/bitmap.rs | 3 +++ os/src/fs/easy_fs/block_cache.rs | 5 +++++ os/src/fs/easy_fs/layout.rs | 10 +++++++++- os/src/fs/easy_fs/vfs.rs | 5 +++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/os/src/fs/easy_fs/bitmap.rs b/os/src/fs/easy_fs/bitmap.rs index 2cea613e..d8848c8d 100644 --- a/os/src/fs/easy_fs/bitmap.rs +++ b/os/src/fs/easy_fs/bitmap.rs @@ -19,6 +19,7 @@ fn decomposition(mut bit: usize) -> (usize, usize, usize) { impl Bitmap { pub fn new(start_block_id: usize, blocks: usize) -> Self { + kprintln!("[KERN EASYFS] bitmap::Bitmap::new() begin"); Self { start_block_id, blocks, @@ -26,6 +27,7 @@ impl Bitmap { } pub fn alloc(&self, block_device: &Arc) -> Option { + kprintln!("[KERN EASYFS] bitmap::Bitmap::alloc() begin"); for block_id in 0..self.blocks { let pos = get_block_cache( block_id + self.start_block_id as usize, @@ -54,6 +56,7 @@ impl Bitmap { } pub fn dealloc(&self, block_device: &Arc, bit: usize) { + kprintln!("[KERN EASYFS] bitmap::Bitmap::dealloc() begin"); let (block_pos, bits64_pos, inner_pos) = decomposition(bit); get_block_cache(block_pos + self.start_block_id, Arc::clone(block_device)) .lock() diff --git a/os/src/fs/easy_fs/block_cache.rs b/os/src/fs/easy_fs/block_cache.rs index 4b90294a..19dbac59 100644 --- a/os/src/fs/easy_fs/block_cache.rs +++ b/os/src/fs/easy_fs/block_cache.rs @@ -14,6 +14,7 @@ pub struct BlockCache { impl BlockCache { /// Load a new BlockCache from disk. pub fn new(block_id: usize, block_device: Arc) -> Self { + //kprintln!("[KERN EASYFS] block_cache::BlockCache::new() begin"); let mut cache = [0u8; BLOCK_SZ]; block_device.read_block(block_id, &mut cache); Self { @@ -79,6 +80,7 @@ pub struct BlockCacheManager { impl BlockCacheManager { pub fn new() -> Self { + kprintln!("[KERN EASYFS] block_cache::BlockCacheManager::new() begin"); Self { queue: VecDeque::new(), } @@ -89,6 +91,7 @@ impl BlockCacheManager { block_id: usize, block_device: Arc, ) -> Arc> { + //kprintln!("[KERN EASYFS] block_cache::BlockCacheManager::get_block_cache() begin"); if let Some(pair) = self.queue.iter().find(|pair| pair.0 == block_id) { Arc::clone(&pair.1) } else { @@ -126,12 +129,14 @@ pub fn get_block_cache( block_id: usize, block_device: Arc, ) -> Arc> { + //kprintln!("[KERN EASYFS] block_cache::get_block_cache() begin"); BLOCK_CACHE_MANAGER .lock() .get_block_cache(block_id, block_device) } pub fn block_cache_sync_all() { + kprintln!("[KERN EASYFS] block_cache::block_cache_sync_all() begin"); let manager = BLOCK_CACHE_MANAGER.lock(); for (_, cache) in manager.queue.iter() { cache.lock().sync(); diff --git a/os/src/fs/easy_fs/layout.rs b/os/src/fs/easy_fs/layout.rs index da25cd91..5c35b95b 100644 --- a/os/src/fs/easy_fs/layout.rs +++ b/os/src/fs/easy_fs/layout.rs @@ -44,6 +44,7 @@ impl SuperBlock { data_bitmap_blocks: u32, data_area_blocks: u32, ) { + kprintln!("[KERN EASYFS] layout::SuperBlock::initialize() begin"); *self = Self { magic: EFS_MAGIC, total_blocks, @@ -79,6 +80,7 @@ pub struct DiskInode { impl DiskInode { /// indirect1 and indirect2 block are allocated only when they are needed. pub fn initialize(&mut self, type_: DiskInodeType) { + kprintln!("[KERN EASYFS] layout::DiskInode::initialize() begin"); self.size = 0; self.direct.iter_mut().for_each(|v| *v = 0); self.indirect1 = 0; @@ -121,6 +123,7 @@ impl DiskInode { Self::total_blocks(new_size) - Self::total_blocks(self.size) } pub fn get_block_id(&self, inner_id: u32, block_device: &Arc) -> u32 { + //kprintln!("[KERN EASYFS] layout::DiskInode::get_block_id() begin"); let inner_id = inner_id as usize; if inner_id < INODE_DIRECT_COUNT { self.direct[inner_id] @@ -150,6 +153,7 @@ impl DiskInode { new_blocks: Vec, block_device: &Arc, ) { + kprintln!("[KERN EASYFS] layout::DiskInode::increase_size() begin"); let mut current_blocks = self.data_blocks(); self.size = new_size; let mut total_blocks = self.data_blocks(); @@ -221,7 +225,7 @@ impl DiskInode { /// /// We will clear the block contents to zero later. pub fn clear_size(&mut self, block_device: &Arc) -> Vec { - kprintln!("[KERN EASYFS] layout::EasyFileSystem::create() begin"); + kprintln!("[KERN EASYFS] layout::DiskInode::clear_size() begin"); let mut v: Vec = Vec::new(); let mut data_blocks = self.data_blocks() as usize; self.size = 0; @@ -290,6 +294,7 @@ impl DiskInode { } }); self.indirect2 = 0; + kprintln!("[KERN EASYFS] layout::DiskInode::clear_size() end"); v } pub fn read_at( @@ -298,6 +303,7 @@ impl DiskInode { buf: &mut [u8], block_device: &Arc, ) -> usize { + //kprintln!("[KERN EASYFS] layout::DiskInode::read_at() begin"); let mut start = offset; let end = (offset + buf.len()).min(self.size as usize); if start >= end { @@ -338,6 +344,7 @@ impl DiskInode { buf: &[u8], block_device: &Arc, ) -> usize { + kprintln!("[KERN EASYFS] layout::DiskInode::write_at() begin"); let mut start = offset; let end = (offset + buf.len()).min(self.size as usize); assert!(start <= end); @@ -387,6 +394,7 @@ impl DirEntry { } } pub fn new(name: &str, inode_number: u32) -> Self { + kprintln!("[KERN EASYFS] layout::DirEntry::new() begin"); let mut bytes = [0u8; NAME_LENGTH_LIMIT + 1]; bytes[..name.len()].copy_from_slice(name.as_bytes()); Self { diff --git a/os/src/fs/easy_fs/vfs.rs b/os/src/fs/easy_fs/vfs.rs index a69bb033..0b713688 100644 --- a/os/src/fs/easy_fs/vfs.rs +++ b/os/src/fs/easy_fs/vfs.rs @@ -32,7 +32,7 @@ impl Inode { } fn read_disk_inode(&self, f: impl FnOnce(&DiskInode) -> V) -> V { - kprintln!("[KERN EASYFS] vfs::Inode::read_disk_inode() begin"); + //kprintln!("[KERN EASYFS] vfs::Inode::read_disk_inode() begin"); get_block_cache(self.block_id, Arc::clone(&self.block_device)) .lock() .read(self.block_offset, f) @@ -85,6 +85,7 @@ impl Inode { disk_inode: &mut DiskInode, fs: &mut MutexGuard, ) { + kprintln!("[KERN EASYFS] vfs::Inode::increase_size() begin"); if new_size < disk_inode.size { return; } @@ -165,7 +166,7 @@ impl Inode { } pub fn read_at(&self, offset: usize, buf: &mut [u8]) -> usize { - kprintln!("[KERN EASYFS] vfs::Inode::read_at() begin"); + //kprintln!("[KERN EASYFS] vfs::Inode::read_at() begin"); let _fs = self.fs.lock(); self.read_disk_inode(|disk_inode| disk_inode.read_at(offset, buf, &self.block_device)) }