Skip to content

Commit

Permalink
Split file system into 3 distinct crate (module)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlixANNERAUD committed Oct 9, 2024
1 parent 7c1395a commit e797536
Show file tree
Hide file tree
Showing 27 changed files with 201 additions and 200 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ members = [
"Modules/Memory",
"Modules/Time",
"Modules/ABI",
"Modules/Virtual_file_system",
"Modules/LittleFS",
]
exclude = [
"Build_tool",
Expand Down
5 changes: 0 additions & 5 deletions Modules/File_system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
littlefs2-sys = "0.2.0"
Task = { path = "../Task" }
Users = { path = "../Users" }
Shared = { path = "../Shared" }
Expand All @@ -16,7 +15,3 @@ Drivers = { path = "../Drivers" }
[features]
std = []
default = ["std"]

[[test]]
name = "Integration"
path = "Tests/Integration.rs"
File renamed without changes.
3 changes: 2 additions & 1 deletion Modules/File_system/src/Error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum Error_type {
Not_initialized,
Failed_to_get_users_manager_instance,
Failed_to_get_task_manager_instance,
Invalid_input,
Invalid_parameter,
Invalid_flags,
Not_directory,
Is_directory,
Expand All @@ -42,6 +42,7 @@ pub enum Error_type {
Name_too_long,
Corrupted,
No_memory,
No_space_left,
Other,
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/File_system/src/Fundamentals/Metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Metadata_type {

let Group = match Users_instance
.Get_user_primary_group(Owner)
.map_err(|_| Error_type::Invalid_input)
.map_err(|_| Error_type::Invalid_parameter)
{
Ok(Group) => Group,
Err(_) => return None,
Expand Down
11 changes: 11 additions & 0 deletions Modules/File_system/src/Fundamentals/Type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum Type_type {
File,
Directory,
Block_device,
Character_device,
Pipe,
Socket,
Symbolic_link,
}
2 changes: 2 additions & 0 deletions Modules/File_system/src/Fundamentals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod Permission;
mod Position;
mod Size;
mod Statistics;
mod Type;

pub use Entry::*;
pub use Flags::*;
Expand All @@ -17,6 +18,7 @@ pub use Permission::*;
pub use Position::*;
pub use Size::*;
pub use Statistics::*;
pub use Type::*;

#[repr(transparent)]
pub struct Block_type(pub [u8; 512]);
Expand Down
6 changes: 0 additions & 6 deletions Modules/File_system/src/Pipe/mod.rs

This file was deleted.

12 changes: 5 additions & 7 deletions Modules/File_system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]

///! File system module
///
/// This module contains basic file system types, traits and functions.
///
mod Device;
mod Error;
mod File;
mod File_system;
mod Fundamentals;
mod Pipe;
mod Time;
mod Virtual_file_system;

pub mod LittleFS;

pub use Device::{Device_trait, Device_type};
pub use Error::*;
pub use File::*;

pub use File_system::*;
pub use Fundamentals::*;
pub use Time::*;
pub use Virtual_file_system::*;
14 changes: 14 additions & 0 deletions Modules/LittleFS/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "LittleFS"
version = "0.1.0"
edition = "2021"

[dependencies]
File_system = { path = "../File_system" }
Task = { path = "../Task" }
Users = { path = "../Users" }
Time = { path = "../Time" }
littlefs2-sys = "0.2.0"

[dev-dependencies]
Drivers = { path = "../Drivers" }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::ffi::c_int;
use std::mem::forget;

use crate::{Device::Device_type, Error_type, Position_type};
use File_system::{Device_type, Error_type, Position_type};

use super::littlefs;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{ffi::c_void, mem::forget};

use crate::Device::Device_type;
use File_system::Device_type;

use super::{littlefs, Callbacks};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::{
rc::Rc,
};

use crate::{Entry_type, Inode_type, Path_type, Size_type, Type_type};
use File_system::{Entry_type, Inode_type, Path_type, Result_type, Size_type, Type_type};

use super::{littlefs, Convert_result, Result_type};
use super::{littlefs, Convert_result};

struct Inner_type {
Directory: littlefs::lfs_dir_t,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::PoisonError;

use super::littlefs;
use File_system::{Error_type, Result_type};

/*
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum Error_type {
// LittleFS errors
Expand All @@ -25,19 +25,18 @@ pub enum Error_type {
Poisoned_lock, // Poisoned lock
Invalid_identifier, // Invalid file identifier
}

pub type Result_type<T> = core::result::Result<T, Error_type>;
*/

pub(crate) fn Convert_result(Error: i32) -> Result_type<u32> {
match Error {
littlefs::lfs_error_LFS_ERR_IO => Err(Error_type::Input_output),
littlefs::lfs_error_LFS_ERR_CORRUPT => Err(Error_type::Corrupted),
littlefs::lfs_error_LFS_ERR_NOENT => Err(Error_type::No_Entry),
littlefs::lfs_error_LFS_ERR_EXIST => Err(Error_type::Entry_exists),
littlefs::lfs_error_LFS_ERR_NOENT => Err(Error_type::Not_found),
littlefs::lfs_error_LFS_ERR_EXIST => Err(Error_type::Already_exists),
littlefs::lfs_error_LFS_ERR_NOTDIR => Err(Error_type::Not_directory),
littlefs::lfs_error_LFS_ERR_ISDIR => Err(Error_type::Is_directory),
littlefs::lfs_error_LFS_ERR_NOTEMPTY => Err(Error_type::Directory_not_empty),
littlefs::lfs_error_LFS_ERR_BADF => Err(Error_type::Bad_file_number),
littlefs::lfs_error_LFS_ERR_BADF => Err(Error_type::Invalid_identifier),
littlefs::lfs_error_LFS_ERR_FBIG => Err(Error_type::File_too_large),
littlefs::lfs_error_LFS_ERR_INVAL => Err(Error_type::Invalid_parameter),
littlefs::lfs_error_LFS_ERR_NOSPC => Err(Error_type::No_space_left),
Expand All @@ -53,7 +52,7 @@ pub(crate) fn Convert_result(Error: i32) -> Result_type<u32> {
}
}
}

/*
impl From<Error_type> for crate::Error_type {
fn from(Error: Error_type) -> Self {
match Error {
Expand Down Expand Up @@ -83,4 +82,4 @@ impl<T> From<PoisonError<T>> for Error_type {
fn from(_: PoisonError<T>) -> Self {
Error_type::Poisoned_lock
}
}
}*/
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use std::{

use Task::Task_identifier_type;

use crate::{
File_system_identifier_type, Flags_type, Inode_type, Metadata_type, Mode_type, Path_type,
Position_type, Size_type, Statistics_type, Type_type,
use File_system::{
Error_type, File_system_identifier_type, Flags_type, Inode_type, Metadata_type, Mode_type,
Path_type, Position_type, Result_type, Size_type, Statistics_type, Type_type,
};

use super::{littlefs, Convert_flags, Convert_result, Error_type, Result_type};
use super::{littlefs, Convert_flags, Convert_result};

fn Convert_position(Position: &Position_type) -> (i32, i32) {
match Position {
Expand Down
Loading

0 comments on commit e797536

Please sign in to comment.