Sync computers
This commit is contained in:
@@ -44,31 +44,29 @@ impl<'a, T> Dir<'a, T> {
|
||||
}
|
||||
}
|
||||
impl<'a, T: ReadSeek> Dir<'a, T> {
|
||||
pub fn open_entry<'b, P: Into<Path<'b>>>(
|
||||
pub fn open_entry<P: AsRef<Path>>(
|
||||
&self,
|
||||
path: P,
|
||||
) -> Result<DirEntry<'a, T>, Error<T::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<Path<'b>>>(
|
||||
pub fn open_file<P: AsRef<Path>>(
|
||||
&self,
|
||||
path: P,
|
||||
) -> Result<File<'a, T>, Error<T::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<Path<'b>>>(&self, path: P) -> Result<Self, Error<T::Error>> {
|
||||
let path = path.into();
|
||||
pub fn open_dir<P: AsRef<Path>>(&self, path: P) -> Result<Self, Error<T::Error>> {
|
||||
let path = path.as_ref();
|
||||
if path.is_absolute() {
|
||||
return self.fs.open_dir(path);
|
||||
}
|
||||
|
||||
@@ -136,22 +136,22 @@ impl<T> Fat32FileSystem<T> {
|
||||
}
|
||||
}
|
||||
impl<T: ReadSeek> Fat32FileSystem<T> {
|
||||
pub fn open_entry<'b, P: Into<Path<'b>>>(
|
||||
pub fn open_entry<P: AsRef<Path>>(
|
||||
&self,
|
||||
path: P,
|
||||
) -> Result<DirEntry<'_, T>, Error<T::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<Path<'b>>>(&self, path: P) -> Result<Dir<'_, T>, Error<T::Error>> {
|
||||
let path = path.into().as_str().trim_start_matches("/");
|
||||
pub fn open_dir<P: AsRef<Path>>(&self, path: P) -> Result<Dir<'_, T>, Error<T::Error>> {
|
||||
let path = path.as_ref().as_str().trim_start_matches("/");
|
||||
self.root_directory().open_dir(path)
|
||||
}
|
||||
pub fn open_file<'b, P: Into<Path<'b>>>(
|
||||
pub fn open_file<P: AsRef<Path>>(
|
||||
&self,
|
||||
path: P,
|
||||
) -> Result<File<'_, T>, Error<T::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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<str> for Path<'a> {
|
||||
impl AsRef<Path> for str {
|
||||
fn as_ref(&self) -> &Path {
|
||||
unsafe { &*(self as *const str as *const Path) }
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Path> for Path {
|
||||
fn as_ref(&self) -> &Path {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for Path {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.inner
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Path<'a> {
|
||||
pub fn split_path(&self) -> (&'a str, Option<Path<'a>>) {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<'a>>>(path: P) -> u64 {
|
||||
pub fn open<P: AsRef<Path>>(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);
|
||||
|
||||
@@ -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<Path<'a>>>(&mut self, path: T) -> i64 {
|
||||
let path = path.into();
|
||||
pub fn create_process_from_file<T: AsRef<Path>>(&mut self, path: T) -> i64 {
|
||||
let path = path.as_ref();
|
||||
let name = path.as_str();
|
||||
|
||||
// Open and read the binary file
|
||||
|
||||
@@ -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<Path<'a>>>(
|
||||
pub fn open<P: AsRef<Path>>(
|
||||
path: P,
|
||||
in_kernel: bool,
|
||||
) -> Result<Box<dyn VirtualNode + Send>, Error<<Disk as bffs::io::IoBase>::Error>> {
|
||||
let path = path.into();
|
||||
let path = path.as_ref();
|
||||
let file = match path.split_path() {
|
||||
("dev", path) => {
|
||||
todo!()
|
||||
|
||||
@@ -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<'a>>>(path: P) -> Result<Box<dyn VirtualNode + Send>, ()>;
|
||||
fn open(&mut self, path: &Path) -> Result<Box<dyn VirtualNode + Send>, ()>;
|
||||
}
|
||||
|
||||
pub struct MainFileSystem {
|
||||
mounts: HashMap<PathBuf>
|
||||
mounts: HashMap<PathBuf, Box<dyn VirtualFileSystem>>,
|
||||
}
|
||||
|
||||
impl VirtualFileSystem for MainFileSystem {
|
||||
fn open<'a, P: Into<Path<'a>>>(path: P) -> Result<Box<dyn VirtualNode + Send>, ()> {
|
||||
fn open(&mut self, path: &Path) -> Result<Box<dyn VirtualNode + Send>, ()> {
|
||||
for mount in self.mounts.iter() {
|
||||
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user