Skip to content

Commit

Permalink
Changing DISKNO type and updating debugfs commands to match the new i…
Browse files Browse the repository at this point in the history
…nterface
Harthann committed Nov 16, 2023
1 parent 0ca0f03 commit d15b989
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions srcs/cli/commands/debugfs.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ use crate::utils::path::Path;
pub static ROOT_INODE: usize = 2;
pub static CURRENTDIR_INODE: Mutex<usize> = Mutex::new(ROOT_INODE);
pub static PWD: Mutex<Option<Path>> = Mutex::new(None);
pub static DISKNO: Mutex<i8> = Mutex::new(-1);
pub static DISKNO: Mutex<Option<ext2::Ext2>> = Mutex::new(None);

fn help() {
crate::kprintln!(
@@ -55,7 +55,7 @@ fn rm(command: Vec<String>) {
return;
}
ext2::remove_file(
*DISKNO.lock() as u8,
DISKNO.lock().as_mut().unwrap(),
command[1].as_str(),
*CURRENTDIR_INODE.lock()
);
@@ -67,7 +67,7 @@ fn stat(command: Vec<String>) {
return;
}
ext2::show_inode_info(
*DISKNO.lock() as u8,
DISKNO.lock().as_ref().unwrap(),
command[1].as_str(),
*CURRENTDIR_INODE.lock()
);
@@ -79,7 +79,7 @@ fn mkdir(command: Vec<String>) {
return;
}
ext2::create_dir(
*DISKNO.lock() as u8,
DISKNO.lock().as_mut().unwrap(),
command[1].as_str(),
*CURRENTDIR_INODE.lock()
);
@@ -91,7 +91,7 @@ fn touch(command: Vec<String>) {
return;
}
ext2::create_file(
*DISKNO.lock() as u8,
DISKNO.lock().as_mut().unwrap(),
command[1].as_str(),
*CURRENTDIR_INODE.lock()
);
@@ -103,7 +103,7 @@ fn cat(command: Vec<String>) {
return;
}
let file_content = ext2::get_file_content(
*DISKNO.lock() as u8,
DISKNO.lock().as_ref().unwrap(),
command[1].as_str(),
*CURRENTDIR_INODE.lock()
);
@@ -113,13 +113,15 @@ fn cat(command: Vec<String>) {
}

fn test() {
let mut ext2 = ext2::Ext2::new(*DISKNO.lock() as u8)
.expect("Disk is not a ext2 filesystem.");
/*
let binding = DISKNO.lock();
let ext2 = binding.as_ref().unwrap();
// let mut dentry = crate::fs::ext2::inode::Dentry::default();
let _node = ext2.alloc_node(0);
let _block = ext2.alloc_block(0);
crate::dprintln!("Node {}", _node);
*/
}

fn ls(command: Vec<String>) {
@@ -129,7 +131,7 @@ fn ls(command: Vec<String>) {
};
crate::dprintln!("Ls: {}", path);
let dentries =
ext2::list_dir(*DISKNO.lock() as u8, path, *CURRENTDIR_INODE.lock());
ext2::list_dir(DISKNO.lock().as_ref().unwrap(), path, *CURRENTDIR_INODE.lock());

for i in dentries {
crate::kprint!("{} ", i.name);
@@ -143,8 +145,8 @@ fn cd(command: Vec<String>) {
_ => command[1].as_str()
};
let path = Path::new(path);
let ext2 = ext2::Ext2::new(*DISKNO.lock() as u8)
.expect("Disk is not a ext2 filesystem.");
let binding = DISKNO.lock();
let ext2 = binding.as_ref().unwrap();
let lookup = ext2.recurs_find(path.as_str(), *CURRENTDIR_INODE.lock());
match lookup {
None => crate::kprintln!("Dir not found"),
@@ -174,8 +176,8 @@ fn imap(command: Vec<String>) {
1 => "/",
_ => command[1].as_str()
};
let ext2 = ext2::Ext2::new(*DISKNO.lock() as u8)
.expect("Disk is not a ext2 filesystem.");
let binding = DISKNO.lock();
let ext2 = binding.as_ref().unwrap();
let lookup = ext2.get_inode_of(path);
match lookup {
None => crate::kprintln!("File not found"),

0 comments on commit d15b989

Please sign in to comment.