Skip to content

Commit

Permalink
Change create_file and create_dir to return DirEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc committed Jan 22, 2020
1 parent 34cc209 commit ad2ea50
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/kernel/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -379,16 +379,15 @@ impl Dir {
None
}

pub fn create_file(&self, name: &str) -> Option<Block> {
pub fn create_file(&self, name: &str) -> Option<DirEntry> {
self.create_entry(FileType::File, name)
}

pub fn create_dir(&self, name: &str) -> Option<Block> {
pub fn create_dir(&self, name: &str) -> Option<DirEntry> {
self.create_entry(FileType::Dir, name)
}

// TODO: Return a DirEntry?
fn create_entry(&self, kind: FileType, name: &str) -> Option<Block> {
fn create_entry(&self, kind: FileType, name: &str) -> Option<DirEntry> {
if self.find(name).is_some() {
return None;
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ad2ea50

Please sign in to comment.