1#![no_std]
8
9extern crate alloc;
10
11use alloc::{sync::Arc, vec::Vec};
12use core::fmt;
13
14pub use ext4_rs::{Ext4, Ext4Error};
16
17pub trait BlockDevice: Send + Sync {
22 fn read_offset(&self, offset: usize) -> Result<Vec<u8>, BlockDeviceError>;
24
25 fn write_offset(&mut self, offset: usize, data: &[u8]) -> Result<(), BlockDeviceError>;
27
28 fn size(&self) -> Result<usize, BlockDeviceError>;
30}
31
32#[derive(Debug)]
34pub enum BlockDeviceError {
35 Io,
37 InvalidOffset,
39 NotReady,
41 Other,
43}
44
45impl fmt::Display for BlockDeviceError {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 match self {
49 BlockDeviceError::Io => write!(f, "I/O error"),
50 BlockDeviceError::InvalidOffset => write!(f, "Invalid offset"),
51 BlockDeviceError::NotReady => write!(f, "Device not ready"),
52 BlockDeviceError::Other => write!(f, "Other error"),
53 }
54 }
55}
56
57pub struct Ext4FileSystem {
59 _marker: core::marker::PhantomData<()>,
61}
62
63impl Ext4FileSystem {
64 pub fn mount<D: BlockDevice + 'static>(_device: Arc<D>) -> Result<Self, ()> {
66 Ok(Self {
69 _marker: core::marker::PhantomData,
70 })
71 }
72}
73
74impl Ext4FileSystem {
76 pub fn read_dir(&self, _path: &str) -> Result<Vec<DirEntry>, ()> {
78 Err(())
80 }
81
82 pub fn open(&self, _path: &str) -> Result<File, ()> {
84 Err(())
86 }
87
88 pub fn create(&mut self, _path: &str) -> Result<File, ()> {
90 Err(())
92 }
93}
94
95#[derive(Debug)]
97pub struct DirEntry {
98 pub name: alloc::string::String,
99 pub inode: u64,
100 pub file_type: FileType,
101}
102
103#[derive(Debug, Clone, Copy, PartialEq, Eq)]
105pub enum FileType {
106 RegularFile,
107 Directory,
108 SymLink,
109 CharDevice,
110 BlockDevice,
111 Fifo,
112 Socket,
113 Unknown,
114}
115
116#[derive(Debug)]
118pub struct File {
119 _inode: u64,
120 size: u64,
121 offset: u64,
122}
123
124impl File {
125 pub fn read(&mut self, _buf: &mut [u8]) -> Result<usize, ()> {
127 Err(())
128 }
129
130 pub fn write(&mut self, _buf: &[u8]) -> Result<usize, ()> {
132 Err(())
133 }
134
135 pub fn seek(&mut self, pos: u64) -> Result<u64, ()> {
137 self.offset = pos;
138 Ok(self.offset)
139 }
140
141 pub fn size(&self) -> u64 {
143 self.size
144 }
145}