Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
21c6db6
feat: implement AnyByLayout for flexible data handling
AlixANNERAUD Dec 13, 2025
fd1310b
refactor: enhance control command handling with improved type safety …
AlixANNERAUD Dec 13, 2025
fd34167
refactor: improve control command handling with enhanced type safety …
AlixANNERAUD Dec 13, 2025
2c3371e
refactor: simplify memory management interface by removing unsafe met…
AlixANNERAUD Dec 13, 2025
345d6f1
refactor: update control command handling for block and partition dev…
AlixANNERAUD Dec 13, 2025
3fad678
refactor: remove unsafe keyword from get_used and get_free methods fo…
AlixANNERAUD Dec 13, 2025
0aabc69
refactor: remove unsafe keyword from get_used and get_free methods fo…
AlixANNERAUD Dec 13, 2025
2f01a48
refactor: update control command definitions and improve type handlin…
AlixANNERAUD Dec 13, 2025
6ba59b8
refactor: streamline control command handling and improve type safety…
AlixANNERAUD Dec 13, 2025
39f67af
refactor: improve type handling for block size and count in FileSyste…
AlixANNERAUD Dec 13, 2025
da44fd9
refactor: replace ControlCommand instantiation with define_command ma…
AlixANNERAUD Dec 13, 2025
9d88197
refactor: simplify algorithm setting in hash_password function
AlixANNERAUD Dec 13, 2025
97e6c08
refactor: simplify terminal check logic in xila_file_system_is_a_term…
AlixANNERAUD Dec 13, 2025
675fd57
refactor: add FileControlIterator for managing control commands in File
AlixANNERAUD Dec 13, 2025
bf276de
refactor: update control command handling to use ControlCommandIdenti…
AlixANNERAUD Dec 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions drivers/native/src/devices/window_screen/screen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use file_system::{DirectBaseOperations, DirectCharacterDevice, MountOperations, Size};
use file_system::{
ControlCommand, ControlCommandIdentifier, DirectBaseOperations, DirectCharacterDevice,
MountOperations, Size,
};
use graphics::{Area, GET_RESOLUTION, RenderingColor, SET_DRAWING_AREA, WAS_RESIZED};
use shared::align_slice_to;
use shared::{AnyByLayout, align_slice_to};

use crate::window_screen::inner_window::InnerWindow;

Expand Down Expand Up @@ -32,28 +35,23 @@ impl<'a> DirectBaseOperations for ScreenDevice<'a> {

fn control(
&self,
command: file_system::ControlCommand,
argument: &mut file_system::ControlArgument,
command: ControlCommandIdentifier,
input: &AnyByLayout,
output: &mut AnyByLayout,
) -> file_system::Result<()> {
match command {
SET_DRAWING_AREA => {
let area: &Area = argument
.cast()
.ok_or(file_system::Error::InvalidParameter)?;
SET_DRAWING_AREA::IDENTIFIER => {
let area: &Area = SET_DRAWING_AREA::cast_input(input)?;

task::block_on(self.0.set_drawing_area(*area)).unwrap();
}
GET_RESOLUTION => {
let resolution: &mut graphics::Point = argument
.cast()
.ok_or(file_system::Error::InvalidParameter)?;
GET_RESOLUTION::IDENTIFIER => {
let resolution: &mut graphics::Point = GET_RESOLUTION::cast_output(output)?;

*resolution = task::block_on(self.0.get_resolution()).unwrap();
}
WAS_RESIZED => {
let was_resized: &mut bool = argument
.cast()
.ok_or(file_system::Error::InvalidParameter)?;
WAS_RESIZED::IDENTIFIER => {
let was_resized: &mut bool = WAS_RESIZED::cast_output(output)?;

*was_resized = task::block_on(self.0.was_resized()).unwrap();
}
Expand Down
18 changes: 9 additions & 9 deletions drivers/shared/src/devices/hash.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use device::hash::{self, HashAlgorithm};
use device::hash::{self, HashAlgorithm, SET_ALGORITHM};
use file_system::{
BaseOperations, CharacterDevice, Context, ControlArgument, ControlCommand, Error,
BaseOperations, CharacterDevice, Context, ControlCommand, ControlCommandIdentifier, Error,
MountOperations, Result, Size,
};
use sha2::{Digest, Sha224, Sha256, Sha384, Sha512, Sha512_224, Sha512_256, digest::DynDigest};
use shared::AnyByLayout;

#[derive(Clone)]
struct HashDeviceContext {
Expand Down Expand Up @@ -69,22 +70,21 @@ impl BaseOperations for HashDevice {
fn control(
&self,
context: &mut Context,
command: ControlCommand,
argument: &mut ControlArgument,
command: ControlCommandIdentifier,
input: &AnyByLayout,
_: &mut AnyByLayout,
) -> Result<()> {
let hash_context = context
.get_private_data_mutable_of_type::<HashDeviceContext>()
.ok_or_else(|| file_system::Error::InvalidParameter)?;

match command {
hash::RESET => {
hash::RESET::IDENTIFIER => {
hash_context.hasher.reset();
Ok(())
}
hash::SET_ALGORITHM => {
let algorithm = argument
.cast::<HashAlgorithm>()
.ok_or_else(|| file_system::Error::InvalidParameter)?;
hash::SET_ALGORITHM::IDENTIFIER => {
let algorithm = SET_ALGORITHM::cast_input(input)?;

*hash_context = HashDeviceContext::new(*algorithm)?;
Ok(())
Expand Down
1 change: 1 addition & 0 deletions drivers/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ task = { workspace = true }
users = { workspace = true }
synchronization = { workspace = true }
virtual_file_system = { workspace = true }
shared = { workspace = true }

libc = { version = "0.2" }
linked_list_allocator = { version = "0.10", default-features = false, features = [
Expand Down
45 changes: 25 additions & 20 deletions drivers/std/src/console.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::io::{Read, Write, stderr, stdin, stdout};

use crate::io::map_error;
use file_system::{
ControlArgument, ControlCommand, DirectBaseOperations, DirectCharacterDevice, MountOperations,
Size, character_device,
ControlCommand, ControlCommandIdentifier, DirectBaseOperations, DirectCharacterDevice,
MountOperations, Size, character_device::IS_A_TERMINAL,
};

use crate::io::map_error;
use shared::AnyByLayout;
use std::io::{Read, Write, stderr, stdin, stdout};

pub struct StandardInDevice;

Expand All @@ -27,10 +26,11 @@ impl DirectBaseOperations for StandardInDevice {

fn control(
&self,
command: ControlCommand,
argument: &mut ControlArgument,
command: ControlCommandIdentifier,
input: &AnyByLayout,
output: &mut AnyByLayout,
) -> file_system::Result<()> {
control(command, argument)
control(command, input, output)
}
}

Expand All @@ -55,10 +55,11 @@ impl DirectBaseOperations for StandardOutDevice {

fn control(
&self,
command: ControlCommand,
argument: &mut ControlArgument,
command: ControlCommandIdentifier,
input: &AnyByLayout,
output: &mut AnyByLayout,
) -> file_system::Result<()> {
control(command, argument)
control(command, input, output)
}
}

Expand All @@ -83,23 +84,27 @@ impl DirectBaseOperations for StandardErrorDevice {

fn control(
&self,
command: ControlCommand,
argument: &mut ControlArgument,
command: ControlCommandIdentifier,
input: &AnyByLayout,
output: &mut AnyByLayout,
) -> file_system::Result<()> {
control(command, argument)
control(command, input, output)
}
}

impl MountOperations for StandardErrorDevice {}

impl DirectCharacterDevice for StandardErrorDevice {}

fn control(command: ControlCommand, argument: &mut ControlArgument) -> file_system::Result<()> {
fn control(
command: ControlCommandIdentifier,
_: &AnyByLayout,
output: &mut AnyByLayout,
) -> file_system::Result<()> {
match command {
character_device::IS_A_TERMINAL => {
*argument
.cast::<bool>()
.ok_or(file_system::Error::InvalidParameter)? = true;
IS_A_TERMINAL::IDENTIFIER => {
let output: &mut bool = IS_A_TERMINAL::cast_output(output)?;
*output = true;

Ok(())
}
Expand Down
23 changes: 13 additions & 10 deletions drivers/std/src/drive_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ use std::{
};

use file_system::{
ControlArgument, ControlCommand, DirectBaseOperations, DirectBlockDevice, Error,
MountOperations, Path, Position, Size, block_device, mount::MutexMountWrapper,
ControlCommand, ControlCommandIdentifier, DirectBaseOperations, DirectBlockDevice, Error,
MountOperations, Path, Position, Size,
block_device::{GET_BLOCK_COUNT, GET_BLOCK_SIZE},
mount::MutexMountWrapper,
};
use shared::AnyByLayout;
use synchronization::blocking_mutex::raw::CriticalSectionRawMutex;

use crate::io::map_error;
Expand Down Expand Up @@ -93,19 +96,19 @@ impl DirectBaseOperations for FileDriveDevice {

fn control(
&self,
command: ControlCommand,
argument: &mut ControlArgument,
command: ControlCommandIdentifier,
_: &AnyByLayout,
output: &mut AnyByLayout,
) -> file_system::Result<()> {
match command {
block_device::GET_BLOCK_SIZE => {
let block_size = argument.cast::<usize>().ok_or(Error::InvalidParameter)?;

GET_BLOCK_SIZE::IDENTIFIER => {
let block_size = GET_BLOCK_SIZE::cast_output(output)?;
*block_size = 512; // Fixed block size for file drive device

Ok(())
}
block_device::GET_BLOCK_COUNT => {
let block_count = argument.cast::<Size>().ok_or(Error::InvalidParameter)?;
GET_BLOCK_COUNT::IDENTIFIER => {
let block_count = GET_BLOCK_COUNT::cast_output(output)?;

let file_size = self
.0
Expand All @@ -115,7 +118,7 @@ impl DirectBaseOperations for FileDriveDevice {
.map_err(map_error)?
.len();

*block_count = file_size / 512; // Fixed block size for file drive device
*block_count = (file_size / 512) as _; // Fixed block size for file drive device

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/std/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl ManagerTrait for MemoryManager {
}
}

unsafe fn get_used(&self) -> usize {
fn get_used(&self) -> usize {
self.regions.lock(|regions| {
let regions = regions.borrow();
let mut used = 0;
Expand All @@ -133,7 +133,7 @@ impl ManagerTrait for MemoryManager {
})
}

unsafe fn get_free(&self) -> usize {
fn get_free(&self) -> usize {
self.regions.lock(|regions| {
let regions = regions.borrow();
let mut free = 0;
Expand Down
30 changes: 14 additions & 16 deletions drivers/wasm/src/devices/graphics/canvas_screen.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use core::slice;

use alloc::{boxed::Box, rc::Rc, string::String, vec::Vec};
use file_system::{DirectBaseOperations, DirectCharacterDevice, MountOperations, Size};
use file_system::{
ControlCommand, ControlCommandIdentifier, DirectBaseOperations, DirectCharacterDevice,
MountOperations, Size,
};
use graphics::{Area, GET_RESOLUTION, Point, RenderingColor, SET_DRAWING_AREA, WAS_RESIZED};
use shared::align_slice_to;
use shared::{AnyByLayout, align_slice_to};
use synchronization::{blocking_mutex::raw::CriticalSectionRawMutex, rwlock::RwLock};
use task::block_on;
use wasm_bindgen::{Clamped, JsCast, JsValue, prelude::Closure};
Expand Down Expand Up @@ -160,22 +163,19 @@ impl DirectBaseOperations for CanvasScreenDevice {

fn control(
&self,
command: file_system::ControlCommand,
argument: &mut file_system::ControlArgument,
command: ControlCommandIdentifier,
input: &AnyByLayout,
output: &mut AnyByLayout,
) -> file_system::Result<()> {
match command {
SET_DRAWING_AREA => {
let area: &mut Area = argument
.cast()
.ok_or(file_system::Error::InvalidParameter)?;
SET_DRAWING_AREA::IDENTIFIER => {
let area = SET_DRAWING_AREA::cast_input(input)?;

let mut inner = block_on(self.0.write());
inner.area = *area;
}
GET_RESOLUTION => {
let point: &mut Point = argument
.cast()
.ok_or(file_system::Error::InvalidParameter)?;
GET_RESOLUTION::IDENTIFIER => {
let point = GET_RESOLUTION::cast_output(output)?;

let inner = block_on(self.0.read());

Expand All @@ -185,10 +185,8 @@ impl DirectBaseOperations for CanvasScreenDevice {

*point = resolution;
}
WAS_RESIZED => {
let was_resized: &mut bool = argument
.cast()
.ok_or(file_system::Error::InvalidParameter)?;
WAS_RESIZED::IDENTIFIER => {
let was_resized = WAS_RESIZED::cast_output(output)?;

let mut inner = block_on(self.0.write());
*was_resized = inner.was_resized;
Expand Down
4 changes: 2 additions & 2 deletions drivers/wasm/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ impl ManagerTrait for MemoryManager {
.lock(|inner| unsafe { inner.borrow_mut().heap.deallocate(pointer, layout) });
}

unsafe fn get_used(&self) -> usize {
fn get_used(&self) -> usize {
self.0.lock(|inner| {
let inner = inner.borrow();
inner.heap.used()
})
}

unsafe fn get_free(&self) -> usize {
fn get_free(&self) -> usize {
self.0.lock(|inner| {
let inner = inner.borrow();
inner.heap.free()
Expand Down
14 changes: 7 additions & 7 deletions modules/abi/definitions/src/file_system/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ pub unsafe extern "C" fn xila_file_system_is_a_terminal(
Err(Error::InvalidParameter)?;
}

let is_a_terminal = unsafe { &mut *is_a_terminal };

context::get_instance()
.perform_operation_on_file(file.try_into()?, |file| {
file.control(character_device::IS_A_TERMINAL, is_a_terminal)
})
.ok_or(Error::InvalidIdentifier)??;
unsafe {
*is_a_terminal = context::get_instance()
.perform_operation_on_file(file.try_into()?, |file| {
file.control(character_device::IS_A_TERMINAL, &())
})
.ok_or(Error::InvalidIdentifier)??;
}

Ok(())
})
Expand Down
4 changes: 1 addition & 3 deletions modules/authentication/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ pub async fn hash_password(
.await
.map_err(Error::FailedToHashPassword)?;

let mut algorithm = HashAlgorithm::Sha512;

file.control(SET_ALGORITHM, &mut algorithm)
file.control(SET_ALGORITHM, &HashAlgorithm::Sha512)
.await
.map_err(Error::FailedToHashPassword)?;

Expand Down
7 changes: 3 additions & 4 deletions modules/device/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use file_system::{ControlCommand, ControlDirectionFlags};
use file_system::{ControlCommand, define_command};

#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand All @@ -13,6 +13,5 @@ pub enum HashAlgorithm {
Sha512_256 = 7,
}

pub const RESET: ControlCommand = ControlCommand::new::<()>(ControlDirectionFlags::Write, b'H', 0);
pub const SET_ALGORITHM: ControlCommand =
ControlCommand::new::<HashAlgorithm>(ControlDirectionFlags::Write, b'H', 1);
define_command!(RESET, Write, b'H', 0, (), ());
define_command!(SET_ALGORITHM, Write, b'H', 1, HashAlgorithm, ());
2 changes: 1 addition & 1 deletion modules/executable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ file_system = { workspace = true }
virtual_file_system = { workspace = true }
task = { workspace = true }
users = { workspace = true }

shared = { workspace = true }
log = { workspace = true }

[dev-dependencies]
Expand Down
4 changes: 1 addition & 3 deletions modules/executable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ pub async fn execute(
.get_file_name()
.ok_or(virtual_file_system::Error::InvalidPath)?;

let mut main_function: MainFunction = None;

file.control(GET_MAIN_FUNCTION, &mut main_function).await?;
let main_function: MainFunction = file.control(GET_MAIN_FUNCTION, &()).await?;

let main = main_function.ok_or(Error::FailedToGetMainFunction)?;

Expand Down
Loading