From 40e14d56a6cfecef461c08831a989279072209f7 Mon Sep 17 00:00:00 2001
From: pigeonmoelleux <pigeonmoelleux@crans.org>
Date: Thu, 25 May 2023 16:11:08 +0200
Subject: [PATCH] fix(fs): ext2 block group descriptor read

---
 src/fs/ext2/block.rs |  7 ++++---
 src/fs/ext2/inode.rs |  1 -
 src/fs/ext2/mod.rs   |  3 ---
 src/main.rs          | 17 +----------------
 4 files changed, 5 insertions(+), 23 deletions(-)

diff --git a/src/fs/ext2/block.rs b/src/fs/ext2/block.rs
index a40b262..aec0dbf 100644
--- a/src/fs/ext2/block.rs
+++ b/src/fs/ext2/block.rs
@@ -2,8 +2,6 @@
 //!
 //! See the [OSdev wiki](https://wiki.osdev.org/Ext2) for more informations
 
-use core::mem;
-
 use anyhow::{anyhow, Result};
 use bitflags::bitflags;
 use log::error;
@@ -19,6 +17,9 @@ const BLOCK_GROUP_DESCRIPTOR_TABLE_START_BYTE: usize = 2048;
 /// Ext2 signature, used to help confirm the presence of an Ext2 volume
 const EXT2_SIGNATURE: u16 = 0xef53;
 
+/// Size in bytes of a group block descriptor
+const GROUP_BLOCK_DESCRIPTOR_SIZE: usize = 32;
+
 /// Superblock of the Ext2 filesystem
 ///
 /// This implementation contains also the extended fields described [here](https://wiki.osdev.org/Ext2#Extended_Superblock_Fields)
@@ -344,6 +345,6 @@ impl BlockGroupDescriptor {
     /// Returns the `n`th block group descriptor
     pub fn new(n: usize) -> Result<Self> {
         // SAFETY: the given offset is coherent with the documentation
-        unsafe { read::<Self>(BLOCK_GROUP_DESCRIPTOR_TABLE_START_BYTE + n * mem::size_of::<Self>()) }
+        unsafe { read::<Self>(BLOCK_GROUP_DESCRIPTOR_TABLE_START_BYTE + n * GROUP_BLOCK_DESCRIPTOR_SIZE) }
     }
 }
diff --git a/src/fs/ext2/inode.rs b/src/fs/ext2/inode.rs
index 1573a7b..78bb973 100644
--- a/src/fs/ext2/inode.rs
+++ b/src/fs/ext2/inode.rs
@@ -7,7 +7,6 @@ use bitflags::bitflags;
 
 use super::block::{BlockGroupDescriptor, Superblock};
 use super::{read, SUPERBLOCK};
-use crate::println;
 
 /// Inode index of the root
 ///
diff --git a/src/fs/ext2/mod.rs b/src/fs/ext2/mod.rs
index e17112e..a2de47a 100644
--- a/src/fs/ext2/mod.rs
+++ b/src/fs/ext2/mod.rs
@@ -14,7 +14,6 @@ use self::block::Superblock;
 use self::inode::{Inode, ROOT_INODE_INDEX};
 use crate::fs::ext2::entry::Directory;
 use crate::kernel::device::storage::Device;
-use crate::println;
 
 #[allow(clippy::same_name_method)]
 mod block;
@@ -72,8 +71,6 @@ pub fn search(device: &Arc<Mutex<dyn Device + Send>>) -> Result<Arc<Mutex<dyn su
 
     let root = Directory::root(&root_inode)?;
 
-    // println!("{root:?}");
-
     info!("Found the root of the filesystem : {:?}", root);
 
     Ok(Arc::new(Mutex::new(root)))
diff --git a/src/main.rs b/src/main.rs
index e0bbeb4..4cdd3b9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -60,6 +60,7 @@
 #![feature(error_in_core)]
 #![feature(extend_one)]
 #![feature(int_roundings)]
+#![feature(iter_advance_by)]
 #![feature(new_uninit)]
 #![feature(no_coverage)]
 #![feature(strict_provenance)]
@@ -98,12 +99,9 @@ use test::exit;
 use user::tty::print_key;
 #[cfg(not(test))]
 use x86_64::instructions;
-use x86_64::structures::paging::PageTableFlags;
 
 use self::syslog::SYS_LOGGER;
 use crate::kernel::interrupt::cmos::CMOS;
-use crate::kernel::interrupt::pit::sleep;
-use crate::kernel::memory::vmm::VIRTUAL_MEMORY_MANAGER;
 
 /// Configuration of the bootloader
 ///
@@ -149,19 +147,6 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
     let rtc = CMOS.rtc();
     println!("It is currently : {:0>2}:{:0>2}:{:0>2} (UTC+0)", rtc.hour, rtc.minute, rtc.second);
 
-    // let page = VIRTUAL_MEMORY_MANAGER
-    //     .lock()
-    //     .as_mut()
-    //     .unwrap()
-    //     .new_page(PageTableFlags::PRESENT | PageTableFlags::WRITABLE);
-    // println!("{:?}", page);
-
-    // loop {
-    //     sleep(1000);
-    //     let rtc = CMOS.rtc();
-    //     println!("It is currently : {:0>2}:{:0>2}:{:0>2} (UTC+0)", rtc.hour, rtc.minute, rtc.second);
-    // }
-
     let mut executor = Executor::new();
     executor.spawn(Task::new(print_key()));
     executor.run();
-- 
GitLab