Skip to content

Commit

Permalink
Cargo format
Browse files Browse the repository at this point in the history
  • Loading branch information
0x050f committed Oct 4, 2023
1 parent 004ca56 commit 5b344eb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
9 changes: 6 additions & 3 deletions srcs/cli/commands/debugfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ fn cat(command: Vec<String>) {
}

fn test(command: Vec<String>) {
let mut ext2 = ext2::Ext2::new(unsafe { ext2::DISKNO as u8 }).expect("Disk is not a ext2 filesystem.");
let mut ext2 = ext2::Ext2::new(unsafe { ext2::DISKNO as u8 })
.expect("Disk is not a ext2 filesystem.");
// let mut dentry = crate::fs::ext2::inode::Dentry::default();

let node = ext2.alloc_node(0);
Expand Down Expand Up @@ -100,7 +101,8 @@ fn cd(command: Vec<String>) {
if root {
path.insert_str(0, "/");
}
let ext2 = ext2::Ext2::new(unsafe { ext2::DISKNO as u8 }).expect("Disk is not a ext2 filesystem.");
let ext2 = ext2::Ext2::new(unsafe { ext2::DISKNO as u8 })
.expect("Disk is not a ext2 filesystem.");
let lookup = ext2.recurs_find(&path, unsafe { CURRENTDIR_INODE });
match lookup {
None => crate::kprintln!("Dir not found"),
Expand Down Expand Up @@ -156,7 +158,8 @@ fn imap(command: Vec<String>) {
1 => "/",
_ => command[1].as_str()
};
let ext2 = ext2::Ext2::new(unsafe { ext2::DISKNO as u8 }).expect("Disk is not a ext2 filesystem.");
let ext2 = ext2::Ext2::new(unsafe { ext2::DISKNO as u8 })
.expect("Disk is not a ext2 filesystem.");
let lookup = ext2.get_inode_of(path);
match lookup {
None => crate::kprintln!("File not found"),
Expand Down
39 changes: 21 additions & 18 deletions srcs/fs/ext2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,18 @@ impl Ext2 {
return Err(1);
}
match device.unwrap().r#type {
x if x == ide::IDEType::ATA as u16 => {
ide::ata::SECTOR_SIZE
},
x if x == ide::IDEType::ATAPI as u16 => {
ide::atapi::SECTOR_SIZE
x if x == ide::IDEType::ATA as u16 => ide::ata::SECTOR_SIZE,
x if x == ide::IDEType::ATAPI as u16 => ide::atapi::SECTOR_SIZE,
_ => {
panic!("Unrecognized disk.")
}
_ => {panic!("Unrecognized disk.")}
}
};
Ok(
Self {
diskno: diskno,
sector_size: sector_size as usize,
sblock: read_superblock(diskno, sector_size as usize)?
}
)
Ok(Self {
diskno: diskno,
sector_size: sector_size as usize,
sblock: read_superblock(diskno, sector_size as usize)?
})
}

pub fn is_valid(&self) -> bool {
Expand Down Expand Up @@ -457,10 +453,14 @@ impl Ext2 {

use crate::pci::ide;

pub fn read_superblock(diskno: u8, sector_size: usize) -> Result<block::BaseSuperblock, u8> {
pub fn read_superblock(
diskno: u8,
sector_size: usize
) -> Result<block::BaseSuperblock, u8> {
let buffer: Vec<u8> = vec![0; sector_size];

IDE.lock().read_sectors(diskno, 1, 2, buffer.as_ptr() as u32)?;
IDE.lock()
.read_sectors(diskno, 1, 2, buffer.as_ptr() as u32)?;
let mut sblock = block::BaseSuperblock::from(&buffer[0..84]);
if sblock.version().0 >= 1 {
sblock.set_extension(block::ExtendedSuperblock::from(&buffer[84..236]));
Expand All @@ -483,7 +483,8 @@ fn get_block_content(block: Vec<u8>, size: usize) -> Vec<char> {
/// Does not yet check if found entry is really a file.
/// Does not yet take into account file bigger than 4096
pub fn get_file_content(path: &str, inode: usize) -> Vec<char> {
let ext2 = Ext2::new(unsafe { DISKNO as u8 }).expect("Disk is not a ext2 filesystem.");
let ext2 = Ext2::new(unsafe { DISKNO as u8 })
.expect("Disk is not a ext2 filesystem.");
let opt = ext2.recurs_find(path, inode);
match opt {
None => Vec::new(),
Expand Down Expand Up @@ -537,7 +538,8 @@ pub fn get_file_content(path: &str, inode: usize) -> Vec<char> {
/// Helper function to list all entries in a directory
/// Does not yet check if found entry is a directory or not
pub fn list_dir(path: &str, inode: usize) -> crate::vec::Vec<inode::Dentry> {
let ext2 = Ext2::new(unsafe { DISKNO as u8 }).expect("Disk is not a ext2 filesystem.");
let ext2 = Ext2::new(unsafe { DISKNO as u8 })
.expect("Disk is not a ext2 filesystem.");
let inode = ext2.recurs_find(path, inode);
return match inode {
None => crate::vec::Vec::new(),
Expand All @@ -562,7 +564,8 @@ pub fn list_dir(path: &str, inode: usize) -> crate::vec::Vec<inode::Dentry> {

/// Helper function to create a folder at a given path
pub fn create_dir(path: &str, inode_no: usize) {
let mut ext2 = Ext2::new(unsafe { DISKNO as u8 }).expect("Disk is not a ext2 filesystem.");
let mut ext2 = Ext2::new(unsafe { DISKNO as u8 })
.expect("Disk is not a ext2 filesystem.");
let root = path.starts_with('/');
let mut splited: Vec<&str> = path.split("/").collect();
splited.retain(|a| a.len() != 0);
Expand Down
2 changes: 1 addition & 1 deletion srcs/kmain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub extern "C" fn kmain() -> ! {
if unsafe { ext2::DISKNO == -1 } {
todo!("No ext2 disk found.");
}
// poc::insertion_poc();
// poc::insertion_poc();
kprintln!("Hello World of {}!", 42);
change_color!(Color::Red, Color::White);
let workspace_msg = string::String::from(
Expand Down
3 changes: 2 additions & 1 deletion srcs/pci/ide/atapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ impl ATAPI {
}

// (((Last LBA + 1) * Block size) / (SECTOR_SIZE / 2)) * 2
Ok((((buffer[0].to_be() + 1) * buffer[1].to_be()) / (SECTOR_SIZE / 2)) * 2)
Ok((((buffer[0].to_be() + 1) * buffer[1].to_be()) / (SECTOR_SIZE / 2))
* 2)
}

pub fn read(
Expand Down
4 changes: 2 additions & 2 deletions srcs/pci/ide/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl IDEChannelRegisters {
}

pub struct IDEDevice {
reserved: u8, // 0 (Empty) or 1 (This Drive really exists)
reserved: u8, // 0 (Empty) or 1 (This Drive really exists)
channel: Option<Arcm<IDEChannelRegisters>>,
drive: u8, // 0 (Master Drive) or 1 (Slave Drive)
pub r#type: u16, // 0: ATA, 1:ATAPI
Expand Down Expand Up @@ -91,7 +91,7 @@ impl IDEController {
}

pub fn get_device(&self, num: u8) -> Option<&IDEDevice> {
if num > 3 || self.devices[num as usize].reserved == 0{
if num > 3 || self.devices[num as usize].reserved == 0 {
return None;
}
Some(&self.devices[num as usize])
Expand Down

0 comments on commit 5b344eb

Please sign in to comment.