From ad2ea50c0f0fb681de0dcd6b029d561dcc430933 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Wed, 22 Jan 2020 23:07:04 +0100 Subject: [PATCH] Change create_file and create_dir to return DirEntry --- src/kernel/fs.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/kernel/fs.rs b/src/kernel/fs.rs index db6910ee..8ddbcf39 100644 --- a/src/kernel/fs.rs +++ b/src/kernel/fs.rs @@ -38,8 +38,8 @@ impl File { let dirname = dirname(pathname); let filename = filename(pathname); if let Some(dir) = Dir::open(dirname) { - if let Some(block) = dir.create_file(filename) { - return Some(Self { addr: block.addr }); + if let Some(dir_entry) = dir.create_file(filename) { + return Some(Self { addr: dir_entry.addr }); } } None @@ -337,8 +337,8 @@ impl Dir { let dirname = dirname(pathname); let filename = filename(pathname); if let Some(dir) = Dir::open(dirname) { - if let Some(block) = dir.create_dir(filename) { - return Some(Self { addr: block.addr }); + if let Some(dir_entry) = dir.create_dir(filename) { + return Some(dir_entry.to_dir()) } } None @@ -379,16 +379,15 @@ impl Dir { None } - pub fn create_file(&self, name: &str) -> Option { + pub fn create_file(&self, name: &str) -> Option { self.create_entry(FileType::File, name) } - pub fn create_dir(&self, name: &str) -> Option { + pub fn create_dir(&self, name: &str) -> Option { self.create_entry(FileType::Dir, name) } - // TODO: Return a DirEntry? - fn create_entry(&self, kind: FileType, name: &str) -> Option { + fn create_entry(&self, kind: FileType, name: &str) -> Option { if self.find(name).is_some() { return None; } @@ -429,7 +428,7 @@ impl Dir { } read_dir.block.write(); - Some(new_block) + Some(DirEntry::new(kind, entry_addr, entry_size, name)) } // Deleting an entry is done by setting the entry address to 0