summaryrefslogtreecommitdiff
path: root/src/memory/dir_entry.rs
diff options
context:
space:
mode:
authorChuyan Zhang <me@zcy.moe>2023-11-29 03:29:34 -0800
committerChuyan Zhang <me@zcy.moe>2023-11-29 03:29:34 -0800
commit7af0771f9a3031acc36a6990d07bdb92a61c0c75 (patch)
tree3db3c79b8d385bc949c8486d97def8dadd4323e6 /src/memory/dir_entry.rs
parentceb83a7214000ccd048857b40cc0ebfc54290731 (diff)
downloadmyfs-7af0771f9a3031acc36a6990d07bdb92a61c0c75.tar.gz
myfs-7af0771f9a3031acc36a6990d07bdb92a61c0c75.zip
symlink, probably not working
Diffstat (limited to 'src/memory/dir_entry.rs')
-rw-r--r--src/memory/dir_entry.rs68
1 files changed, 2 insertions, 66 deletions
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::<DirectoryBlock>(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::<DirectoryBlock>(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::<DirectoryBlock>(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::<DirectoryBlock>(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,