Skip to content

Commit

Permalink
✨ Feat: Create an ext4 file system compatible program entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbings committed May 28, 2024
1 parent fbad1b2 commit 281f710
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 12 deletions.
17 changes: 12 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
"cafs",
"libc",
"bootloader",
/* EFI */
"uefi",
"repr",
"proto",
/* ELF HEADER */
"e_phoff",
"e_shoff",
"e_ehsize",
Expand All @@ -35,13 +34,21 @@
"e_shentsize",
"e_shnum",
"e_shstrndx",
/* ELF PROGRAM HEADER TABLE */
"p_vaddr",
"p_paddr",
"p_filesz",
"p_memsz",
/* ELF SECTION HEADER TABLE */
"sh_addralign",
"sh_addralign",
"sh_entsize",
"inodes",
"wtime",
"lastcheck",
"checkinterval",
"resuid",
"resgid",
"incompat",
"prealloc",
"inum",
"kbytes"
],
}
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions canicula-common/src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::usize;

#[derive(Debug)]
pub enum OperateError {
InvalidFileDescriptor,
Expand All @@ -10,8 +8,3 @@ pub enum OperateError {
NotFoundDev,
TimeOut,
}

pub trait Fs {
fn read<const SIZE: usize>(path: &str) -> Result<[u8; SIZE], OperateError>;
fn write<const SIZE: usize>(path: &str, content: [u8; SIZE]) -> Result<usize, OperateError>;
}
1 change: 1 addition & 0 deletions canicula-ext4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ name = "canicula_ext4"
path = "src/ext4.rs"

[dependencies]
canicula-common = { path = "../canicula-common" }
28 changes: 28 additions & 0 deletions canicula-ext4/src/ext4.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
#![no_std]
#![no_main]

use canicula_common::fs::OperateError;
use types::super_block::SuperBlock;

mod types;

#[allow(unused)]
struct Ext4FS<const SIZE: usize> {
read_byte: fn(usize) -> Result<u8, OperateError>,
write_byte: fn(u8, usize) -> Result<usize, OperateError>,
super_block: Option<SuperBlock>,
}

#[allow(unused)]
impl<const SIZE: usize> Ext4FS<SIZE> {
pub fn new(
read_byte: fn(usize) -> Result<u8, OperateError>,
write_byte: fn(u8, usize) -> Result<usize, OperateError>,
) -> Self {
Ext4FS {
read_byte,
write_byte,
super_block: None,
}
}

pub fn init() {}
}
6 changes: 6 additions & 0 deletions canicula-ext4/src/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod data_block;
pub mod data_block_bitmap;
pub mod group_descriptors;
pub mod inode_bitmap;
pub mod inode_table;
pub mod super_block;
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
97 changes: 97 additions & 0 deletions canicula-ext4/src/types/super_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SuperBlock {
s_inodes_count: u32,
s_blocks_count_lo: u32,
s_r_blocks_count_lo: u32,
s_free_blocks_count_lo: u32,
s_free_inodes_count: u32,
s_first_data_block: u32,
s_log_block_size: u32,
s_log_cluster_size: u32,
s_blocks_per_group: u32,
s_clusters_per_group: u32,
s_inodes_per_group: u32,
s_mtime: u32,
s_wtime: u32,
s_mnt_count: u16,
s_max_mnt_count: u16,
s_magic: u16,
s_state: u16,
s_errors: u16,
s_minor_rev_level: u16,
s_lastcheck: u32,
s_checkinterval: u32,
s_creator_os: u32,
s_rev_level: u32,
s_def_resuid: u16,
s_def_resgid: u16,
s_first_ino: u32,
s_inode_size: u16,
s_block_group_nr: u16,
s_feature_compat: u32,
s_feature_incompat: u32,
s_feature_ro_compat: u32,
s_uuid: [u8; 16],
s_volume_name: [char; 16],
s_last_mounted: [char; 64],
s_algorithm_usage_bitmap: u32,
s_prealloc_blocks: u8,
s_prealloc_dir_blocks: u8,
s_reserved_gdt_blocks: u16,
s_journal_uuid: [u8; 16],
s_journal_inum: u32,
s_journal_dev: u32,
s_last_orphan: u32,
s_hash_seed: [u32; 4],
s_def_hash_version: u8,
s_jnl_backup_type: u8,
s_desc_size: u16,
s_default_mount_opts: u32,
s_first_meta_bg: u32,
s_mkfs_time: u32,
s_jnl_blocks: [u32; 17],
s_blocks_count_hi: u32,
s_r_blocks_count_hi: u32,
s_free_blocks_count_hi: u32,
s_min_extra_isize: u16,
s_want_extra_isize: u16,
s_flags: u32,
s_raid_stride: u16,
s_mmp_interval: u16,
s_mmp_block: u64,
s_raid_stripe_width: u32,
s_log_groups_per_flex: u8,
s_checksum_type: u8,
s_reserved_pad: u16,
s_kbytes_written: u64,
s_snapshot_inum: u32,
s_snapshot_id: u32,
s_snapshot_r_blocks_count: u64,
s_snapshot_list: u32,
s_error_count: u32,
s_first_error_time: u32,
s_first_error_ino: u32,
s_first_error_block: u64,
s_first_error_func: [u8; 32],
s_first_error_line: u32,
s_last_error_time: u32,
s_last_error_ino: u32,
s_last_error_line: u32,
s_last_error_block: u64,
s_last_error_func: [u8; 32],
s_mount_opts: [u8; 64],
s_usr_quota_inum: u32,
s_grp_quota_inum: u32,
s_overhead_blocks: u32,
s_backup_bgs: [u32; 2],
s_encrypt_algos: [u8; 4],
s_encrypt_pw_salt: [u8; 16],
s_lpf_ino: u32,
s_prj_quota_inum: u32,
s_checksum_seed: u32,
s_reserved: [u32; 98],
s_checksum: u32,
}

impl SuperBlock {}

0 comments on commit 281f710

Please sign in to comment.