From 041e5443304fe69bf8be17f2e3d0a1879c5d6cd2 Mon Sep 17 00:00:00 2001 From: Julien THILLARD Date: Sun, 1 Mar 2026 16:12:02 +0100 Subject: [PATCH] Sync computers --- crates/bffs/src/dir.rs | 18 ++++++-------- crates/bffs/src/lib.rs | 12 ++++----- crates/bffs/src/path.rs | 47 ++++++++++++++++++++++++------------ crates/shared/src/syscall.rs | 4 +-- src/process.rs | 4 +-- src/syscall.rs | 4 +-- src/virtual_fs.rs | 11 ++++++--- 7 files changed, 59 insertions(+), 41 deletions(-) diff --git a/crates/bffs/src/dir.rs b/crates/bffs/src/dir.rs index cf606f6..b78042d 100644 --- a/crates/bffs/src/dir.rs +++ b/crates/bffs/src/dir.rs @@ -44,31 +44,29 @@ impl<'a, T> Dir<'a, T> { } } impl<'a, T: ReadSeek> Dir<'a, T> { - pub fn open_entry<'b, P: Into>>( + pub fn open_entry>( &self, path: P, ) -> Result, Error> { - let path = path.into(); - if path.is_absolute() { + if path.as_ref().is_absolute() { return self.fs.open_entry(path); } for file in self.iter() { let f = file?; - if f.name_is(path.as_str()) { + if f.name_is(path.as_ref().as_str()) { return Ok(f); } } Err(Error::NotFound) } - pub fn open_file<'b, P: Into>>( + pub fn open_file>( &self, path: P, ) -> Result, Error> { - let path = path.into(); - if path.is_absolute() { + if path.as_ref().is_absolute() { return self.fs.open_file(path); } - let (start, dirname) = path.split_path(); + let (start, dirname) = path.as_ref().split_path(); let entry = self.open_entry(start)?; match dirname { Some(name) => { @@ -85,8 +83,8 @@ impl<'a, T: ReadSeek> Dir<'a, T> { } } } - pub fn open_dir<'b, P: Into>>(&self, path: P) -> Result> { - let path = path.into(); + pub fn open_dir>(&self, path: P) -> Result> { + let path = path.as_ref(); if path.is_absolute() { return self.fs.open_dir(path); } diff --git a/crates/bffs/src/lib.rs b/crates/bffs/src/lib.rs index 96ed21e..610b25c 100644 --- a/crates/bffs/src/lib.rs +++ b/crates/bffs/src/lib.rs @@ -136,22 +136,22 @@ impl Fat32FileSystem { } } impl Fat32FileSystem { - pub fn open_entry<'b, P: Into>>( + pub fn open_entry>( &self, path: P, ) -> Result, Error> { - let path = path.into().as_str().trim_start_matches("/"); + let path = path.as_ref().as_str().trim_start_matches("/"); self.root_directory().open_entry(path) } - pub fn open_dir<'b, P: Into>>(&self, path: P) -> Result, Error> { - let path = path.into().as_str().trim_start_matches("/"); + pub fn open_dir>(&self, path: P) -> Result, Error> { + let path = path.as_ref().as_str().trim_start_matches("/"); self.root_directory().open_dir(path) } - pub fn open_file<'b, P: Into>>( + pub fn open_file>( &self, path: P, ) -> Result, Error> { - let path = path.into().as_str().trim_start_matches("/"); + let path = path.as_ref().as_str().trim_start_matches("/"); self.root_directory().open_file(path) } } diff --git a/crates/bffs/src/path.rs b/crates/bffs/src/path.rs index 37fd0dc..486f5e6 100644 --- a/crates/bffs/src/path.rs +++ b/crates/bffs/src/path.rs @@ -1,33 +1,46 @@ use core::ops::Deref; +#[cfg(feature = "alloc")] use alloc::string::String; #[repr(transparent)] -pub struct Path<'a> { - inner: &'a str, +pub struct Path { + inner: str, } -impl<'a> From<&'a str> for Path<'a> { - fn from(value: &'a str) -> Self { - Self { inner: value } +impl From<&str> for &Path { + fn from(value: &str) -> Self { + unsafe { &*(value as *const str as *const Path) } } } -impl<'a> AsRef for Path<'a> { +impl AsRef for str { + fn as_ref(&self) -> &Path { + unsafe { &*(self as *const str as *const Path) } + } +} + +impl AsRef for Path { + fn as_ref(&self) -> &Path { + self + } +} + +impl AsRef for Path { fn as_ref(&self) -> &str { - self.inner + self.as_str() } } -impl<'a> Path<'a> { - pub fn split_path(&self) -> (&'a str, Option>) { +impl Path { + pub fn split_path(&self) -> (&str, Option<&Path>) { if let Some((start, end)) = self.inner.split_once("/") { (start, Some(end.into())) } else { - (self.inner, None) + (&self.inner, None) } } - pub fn as_str(&self) -> &'a str { - self.inner + pub fn as_str(&self) -> &str { + &self.inner } pub fn is_absolute(&self) -> bool { self.inner.starts_with("/") @@ -37,12 +50,16 @@ impl<'a> Path<'a> { } } +#[cfg(feature = "alloc")] pub struct PathBuf { inner: String, } -impl<'a> Deref for PathBuf { - type Target = Path<'a>; +#[cfg(feature = "alloc")] +impl Deref for PathBuf { + type Target = Path; - fn deref(&self) -> &Self::Target {} + fn deref(&self) -> &Self::Target { + self.inner.as_str().into() + } } diff --git a/crates/shared/src/syscall.rs b/crates/shared/src/syscall.rs index 9c96ab5..2aa07b8 100644 --- a/crates/shared/src/syscall.rs +++ b/crates/shared/src/syscall.rs @@ -128,9 +128,9 @@ pub fn dealloc(ptr: *mut u8, layout: core::alloc::Layout) { syscall!(SysCall::Dealloc, ptr as u64, size as u64, align as u64); } } -pub fn open<'a, P: Into>>(path: P) -> u64 { +pub fn open>(path: P) -> u64 { unsafe { - let path_str = path.into().as_str(); + let path_str = path.as_ref().as_str(); let ptr = path_str.as_ptr(); let size = path_str.len(); let (fd, ..) = syscall!(SysCall::Open, ptr as u64, size as u64); diff --git a/src/process.rs b/src/process.rs index 9ec8d0d..c0cbb17 100644 --- a/src/process.rs +++ b/src/process.rs @@ -159,8 +159,8 @@ impl Scheduler { /// Attempts to open `path`, load its contents into memory and create a new /// kernel process that will execute the loaded binary. Returns the PID of the /// created process, or -1 on failure. - pub fn create_process_from_file<'a, T: Into>>(&mut self, path: T) -> i64 { - let path = path.into(); + pub fn create_process_from_file>(&mut self, path: T) -> i64 { + let path = path.as_ref(); let name = path.as_str(); // Open and read the binary file diff --git a/src/syscall.rs b/src/syscall.rs index 1722d16..4929ab7 100644 --- a/src/syscall.rs +++ b/src/syscall.rs @@ -16,11 +16,11 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: core::alloc::Layout) { unsafe { alloc::alloc::dealloc(ptr, layout) } } -pub fn open<'a, P: Into>>( +pub fn open>( path: P, in_kernel: bool, ) -> Result, Error<::Error>> { - let path = path.into(); + let path = path.as_ref(); let file = match path.split_path() { ("dev", path) => { todo!() diff --git a/src/virtual_fs.rs b/src/virtual_fs.rs index 32c5532..37ccaed 100644 --- a/src/virtual_fs.rs +++ b/src/virtual_fs.rs @@ -1,5 +1,5 @@ use alloc::boxed::Box; -use bffs::path::Path; +use bffs::path::{Path, PathBuf}; use hashbrown::HashMap; pub trait VirtualNode { @@ -7,15 +7,18 @@ pub trait VirtualNode { } pub trait VirtualFileSystem { - fn open<'a, P: Into>>(path: P) -> Result, ()>; + fn open(&mut self, path: &Path) -> Result, ()>; } pub struct MainFileSystem { - mounts: HashMap + mounts: HashMap>, } impl VirtualFileSystem for MainFileSystem { - fn open<'a, P: Into>>(path: P) -> Result, ()> { + fn open(&mut self, path: &Path) -> Result, ()> { + for mount in self.mounts.iter() { + + } todo!() } }