Sync computers
This commit is contained in:
9
crates/shared/src/fs.rs
Normal file
9
crates/shared/src/fs.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
pub struct File {
|
||||
fd: u64,
|
||||
}
|
||||
|
||||
impl File {
|
||||
pub unsafe fn new(fd: u64) -> Self {
|
||||
Self { fd }
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
#![no_std]
|
||||
|
||||
pub mod fs;
|
||||
pub mod syscall;
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use core::{alloc::Layout, time::Duration};
|
||||
|
||||
use bffs::path::Path;
|
||||
|
||||
#[repr(u64)]
|
||||
pub enum SysCall {
|
||||
Open = 2,
|
||||
Alloc = 40,
|
||||
Dealloc = 41,
|
||||
Exit = 60,
|
||||
@@ -14,6 +17,7 @@ pub enum SysCall {
|
||||
impl From<u64> for SysCall {
|
||||
fn from(value: u64) -> Self {
|
||||
match value {
|
||||
2 => SysCall::Open,
|
||||
40 => SysCall::Alloc,
|
||||
41 => SysCall::Dealloc,
|
||||
60 => SysCall::Exit,
|
||||
@@ -124,3 +128,12 @@ 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 {
|
||||
unsafe {
|
||||
let path_str = path.into().as_str();
|
||||
let ptr = path_str.as_ptr();
|
||||
let size = path_str.len();
|
||||
let (fd, ..) = syscall!(SysCall::Open, ptr as u64, size as u64);
|
||||
fd
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user