From 7af0771f9a3031acc36a6990d07bdb92a61c0c75 Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Wed, 29 Nov 2023 03:29:34 -0800 Subject: symlink, probably not working --- src/memory/dir_entry.rs | 68 ++----------------------------------------------- 1 file changed, 2 insertions(+), 66 deletions(-) (limited to 'src/memory/dir_entry.rs') diff --git a/src/memory/dir_entry.rs b/src/memory/dir_entry.rs index 08a82c5..5e030d3 100644 --- a/src/memory/dir_entry.rs +++ b/src/memory/dir_entry.rs @@ -88,6 +88,7 @@ impl AyaFS { } match self.access_block_mut::(parent_inode, block_index_within_inode) { Some(directory_block) => { + directory_block.block.allocate(entry_index_within_block); directory_block.block.entries[entry_index_within_block] = dir_entry; } None => { @@ -104,7 +105,7 @@ impl AyaFS { parent_index: usize, parent_inode: &mut Inode, name: &OsStr, - entry_index: u32, + _entry_index: u32, ) -> Result<(), c_int> { self.load_direntry_map(parent_index, parent_inode)?; if let Some(dir_entry_map) = self.dir_entry_map.get_mut(&parent_index) { @@ -116,22 +117,6 @@ impl AyaFS { } } else { Err(ENOENT) - // let block_index_within_inode = (entry_index / 15) as usize; - // let entry_index_within_block = (entry_index % 15) as usize; - // - // match self.access_block_mut::(parent_inode, block_index_within_inode) { - // Some(directory_block) => { - // if directory_block.block.query(entry_index_within_block) { - // directory_block.block.deallocate(entry_index_within_block); - // // directory_block.block.entries[entry_index_within_block] = - // // DirectoryEntry::default(); - // Ok(()) - // } else { - // Err(ENOENT) - // } - // } - // None => Err(ENOENT), - // } } } @@ -169,41 +154,6 @@ impl AyaFS { } else { Err(ENOENT) } - // // 找到第一个有空闲 DirEntry 的块, 从中分配一个 entry - // let mut block_index_within_inode: usize = 0; - // loop { - // // 所有已经分配的块都用完, 需要额外分配一个块了 - // if block_index_within_inode as u32 == parent_inode.n_blocks { - // if self.allocate_block_for(parent_inode).is_none() { - // return Err(ENOSPC); - // } - // } - // // 寻找当前块里有没有空闲空间 - // if let Some(directory_block) = - // self.access_block_mut::(parent_inode, block_index_within_inode) - // { - // if let Some(entry_index_within_block) = directory_block.block.allocate() { - // // 如果有空闲空间, 可以分配一个块 - // let name_len = child_inode_name.len() as u8; - // let mut name = [0u8; 256]; - // (&mut name[0..name_len as usize]) - // .copy_from_slice(child_inode_name.as_bytes()); - // - // let dir_entry = DirectoryEntry { - // inode: child_inode_index as u32, - // record_len: 264, - // name_len, - // file_type, - // name, - // }; - // directory_block.block.entries[entry_index_within_block] = dir_entry; - // let entry_index = block_index_within_inode * 15 + entry_index_within_block; - // parent_inode.size += 1; - // return Ok(entry_index as u32); - // } - // } - // block_index_within_inode += 1; - // } } pub(crate) fn get_direntry( &mut self, @@ -225,23 +175,9 @@ impl AyaFS { .ok_or(ENOENT) } else { Err(ENOENT) - // let block_index_within_inode = (entry_index / 15) as usize; - // let entry_index_within_block = (entry_index % 15) as usize; - // - // match self.access_block::(parent_inode, block_index_within_inode) { - // Some(directory_block) => { - // if directory_block.block.query(entry_index_within_block) { - // Ok(directory_block.block.entries[entry_index_within_block].clone()) - // } else { - // Err(ENOENT) - // } - // } - // None => Err(ENOENT), - // } } } - // TODO 实现一个带 cache 的版本 /// 返回 inode_index, inode 在 parent 里的 index, inode 本身 pub fn lookup_name( &mut self, -- cgit v1.2.3-70-g09d2