Skip to main content

strat9_components_api/
lib.rs

1//! Strat9-OS Component API
2//!
3//! Defines the common traits, types, and IPC message structures that all
4//! userspace component servers use to communicate with each other and with
5//! the Bedrock kernel.
6//!
7//! This crate is `no_std` + `alloc`-compatible for use in freestanding
8//! component binaries.
9
10#![no_std]
11
12extern crate alloc;
13
14use alloc::sync::Arc;
15
16// ---------------------------------------------------------------------------
17// Filesystem abstractions — re-exported from strate-fs-abstraction
18// ---------------------------------------------------------------------------
19
20pub use strate_fs_abstraction::error::{FsError, FsResult};
21
22#[derive(Debug, Clone, Copy)]
23pub enum FileType {
24    Regular,
25    Directory,
26    Symlink,
27    Other,
28}
29
30#[derive(Debug)]
31pub struct FileStat {
32    pub size: u64,
33    pub file_type: FileType,
34    pub permissions: u8,
35    pub modified: u64,
36}
37
38pub trait BlockDevice: Send + Sync {
39    /// Reads at.
40    fn read_at(&self, offset: u64, buf: &mut [u8]) -> FsResult<usize>;
41    /// Writes at.
42    fn write_at(&self, offset: u64, data: &[u8]) -> FsResult<usize>;
43    /// Implements size.
44    fn size(&self) -> u64;
45}
46
47pub trait FileSystem: Send + Sync {
48    /// Implements mount.
49    fn mount(&mut self, device: Arc<dyn BlockDevice>) -> FsResult<()>;
50    /// Implements unmount.
51    fn unmount(&mut self) -> FsResult<()>;
52    /// Implements lookup.
53    fn lookup(&self, path: &str) -> FsResult<u64>;
54    /// Implements read.
55    fn read(&self, ino: u64, offset: u64, buf: &mut [u8]) -> FsResult<usize>;
56    /// Implements write.
57    fn write(&mut self, ino: u64, offset: u64, buf: &[u8]) -> FsResult<usize>;
58    /// Implements create.
59    fn create(&mut self, parent: u64, name: &str, file_type: FileType) -> FsResult<u64>;
60    /// Implements remove.
61    fn remove(&mut self, parent: u64, name: &str) -> FsResult<()>;
62    /// Implements stat.
63    fn stat(&self, ino: u64) -> FsResult<FileStat>;
64    /// Implements readdir.
65    fn readdir(&self, ino: u64) -> FsResult<alloc::vec::Vec<(alloc::string::String, u64)>>;
66}
67
68pub struct FileHandle {
69    pub ino: u64,
70    pub offset: u64,
71}