Skip to content

Commit 10ca6d5

Browse files
authored
Newfs (#331)
* Add partition management and filesystem detection - Implemented a new module for scanning GPT partition tables and detecting filesystem types. - Introduced structures for partition information and filesystem types. - Added functions for reading GPT headers and partition entries, detecting filesystem types, and creating filesystem instances. - Enhanced the root directory management to support mounting filesystems from detected partitions. - Integrated dynamic partition detection during root filesystem initialization. - Added clock drivers for Rockchip RK3568 and RK3588 SoCs, enabling clock management for eMMC and other peripherals. * refactor: update filesystem initialization and partition mounting logic * Replace lwext4_rust with rsext4 * refactor: update dependencies and clean up unused code in filesystem modules * Update dependencies and refactor filesystem mounting functions - Updated the `axio` dependency version from 0.1 to 0.2 in Cargo.toml. - Removed outdated documentation comments in lib.rs and replaced them with a concise description of AXFS. - Refactored the root filesystem initialization functions to rename `mounted_on_root_dir` to `mount_virtual_fs` for clarity and consistency. * refactor: update rsext4 dependency source and improve mkfile function parameters * Cancel the use of devfs
1 parent b9d6e15 commit 10ca6d5

File tree

19 files changed

+4237
-324
lines changed

19 files changed

+4237
-324
lines changed

Cargo.lock

Lines changed: 648 additions & 321 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ axalloc = {git = "https://github.com/arceos-org/arceos.git", tag = "dev-251216"}
4646
axconfig = {git = "https://github.com/arceos-org/arceos.git", tag = "dev-251216"}
4747
axdisplay = {git = "https://github.com/arceos-org/arceos.git", tag = "dev-251216"}
4848
axdriver = {git = "https://github.com/arceos-org/arceos.git", tag = "dev-251216"}
49-
axfs = {git = "https://github.com/arceos-org/arceos.git", tag = "dev-251216"}
5049
axhal = {git = "https://github.com/arceos-org/arceos.git", tag = "dev-251216"}
5150
axipi = {git = "https://github.com/arceos-org/arceos.git", tag = "dev-251216"}
5251
axlog = {git = "https://github.com/arceos-org/arceos.git", tag = "dev-251216"}
@@ -62,6 +61,7 @@ axaddrspace = "0.1.1"
6261
axhvc = {git = "https://github.com/arceos-hypervisor/axhvc.git"}
6362
axklib = {git = "https://github.com/arceos-hypervisor/axklib.git"}
6463
axruntime = {path = "modules/axruntime"}
64+
axfs = {path = "modules/axfs"}
6565
axvcpu = "0.1"
6666
axvm = {git = "https://github.com/arceos-hypervisor/axvm.git", branch = "next"}
6767

@@ -95,3 +95,4 @@ axvmconfig = {git = "https://github.com/arceos-hypervisor/axvmconfig.git", branc
9595
[patch."https://github.com/arceos-org/arceos"]
9696
axconfig = {path = "modules/axconfig"}
9797
axruntime = {path = "modules/axruntime"}
98+
axfs = {path = "modules/axfs"}

modules/axfs/Cargo.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "axfs"
3+
description = "Axvisor filesystem module"
4+
edition.workspace = true
5+
license.workspace = true
6+
version.workspace = true
7+
8+
[features]
9+
use-ramdisk = []
10+
11+
[dependencies]
12+
axdriver = {workspace = true, features = ["block"]}
13+
axdriver_block = {git = "https://github.com/arceos-org/axdriver_crates.git", tag = "v0.1.2"}
14+
axerrno = "0.1"
15+
axfs_ramfs = {version = "0.1"}
16+
axfs_vfs = "0.1"
17+
axio = {version = "0.2", features = ["alloc"]}
18+
cap_access = "0.1"
19+
lazyinit = "0.2"
20+
spin = "0.9"
21+
log = "0.4"
22+
rsext4 = {git = "https://github.com/Dirinkbottle/rsext4.git", tag = "dev-251222"}
23+
24+
[dependencies.fatfs]
25+
default-features = false
26+
features = [
27+
# no std
28+
"alloc",
29+
"lfn",
30+
"log_level_trace",
31+
"unicode",
32+
]
33+
git = "https://github.com/Josen-B/rust-fatfs.git"
34+
rev = "41122ef"
35+
36+
[dev-dependencies]
37+
axdriver = {workspace = true, features = ["block", "ramdisk"]}
38+
axdriver_block = {git = "https://github.com/arceos-org/axdriver_crates.git", tag = "v0.1.2", features = ["ramdisk"]}

modules/axfs/src/api/dir.rs

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
use alloc::string::String;
2+
use axio::Result;
3+
use core::fmt;
4+
5+
use super::FileType;
6+
use crate::fops;
7+
8+
/// Iterator over the entries in a directory.
9+
pub struct ReadDir<'a> {
10+
path: &'a str,
11+
inner: fops::Directory,
12+
buf_pos: usize,
13+
buf_end: usize,
14+
end_of_stream: bool,
15+
dirent_buf: [fops::DirEntry; 31],
16+
}
17+
18+
/// Entries returned by the [`ReadDir`] iterator.
19+
pub struct DirEntry<'a> {
20+
dir_path: &'a str,
21+
entry_name: String,
22+
entry_type: FileType,
23+
}
24+
25+
/// A builder used to create directories in various manners.
26+
#[derive(Default, Debug)]
27+
pub struct DirBuilder {
28+
recursive: bool,
29+
}
30+
31+
impl<'a> ReadDir<'a> {
32+
pub(super) fn new(path: &'a str) -> Result<Self> {
33+
let mut opts = fops::OpenOptions::new();
34+
opts.read(true);
35+
let inner = fops::Directory::open_dir(path, &opts)?;
36+
const EMPTY: fops::DirEntry = fops::DirEntry::default();
37+
let dirent_buf = [EMPTY; 31];
38+
Ok(ReadDir {
39+
path,
40+
inner,
41+
end_of_stream: false,
42+
buf_pos: 0,
43+
buf_end: 0,
44+
dirent_buf,
45+
})
46+
}
47+
}
48+
49+
impl<'a> Iterator for ReadDir<'a> {
50+
type Item = Result<DirEntry<'a>>;
51+
52+
fn next(&mut self) -> Option<Result<DirEntry<'a>>> {
53+
if self.end_of_stream {
54+
return None;
55+
}
56+
57+
loop {
58+
if self.buf_pos >= self.buf_end {
59+
match self.inner.read_dir(&mut self.dirent_buf) {
60+
Ok(n) => {
61+
if n == 0 {
62+
self.end_of_stream = true;
63+
return None;
64+
}
65+
self.buf_pos = 0;
66+
self.buf_end = n;
67+
}
68+
Err(e) => {
69+
self.end_of_stream = true;
70+
return Some(Err(e));
71+
}
72+
}
73+
}
74+
let entry = &self.dirent_buf[self.buf_pos];
75+
self.buf_pos += 1;
76+
let name_bytes = entry.name_as_bytes();
77+
if name_bytes == b"." || name_bytes == b".." {
78+
continue;
79+
}
80+
let entry_name = unsafe { core::str::from_utf8_unchecked(name_bytes).into() };
81+
let entry_type = entry.entry_type();
82+
83+
return Some(Ok(DirEntry {
84+
dir_path: self.path,
85+
entry_name,
86+
entry_type,
87+
}));
88+
}
89+
}
90+
}
91+
92+
impl DirEntry<'_> {
93+
/// Returns the full path to the file that this entry represents.
94+
///
95+
/// The full path is created by joining the original path to `read_dir`
96+
/// with the filename of this entry.
97+
pub fn path(&self) -> String {
98+
String::from(self.dir_path.trim_end_matches('/')) + "/" + &self.entry_name
99+
}
100+
101+
/// Returns the bare file name of this directory entry without any other
102+
/// leading path component.
103+
pub fn file_name(&self) -> String {
104+
self.entry_name.clone()
105+
}
106+
107+
/// Returns the file type for the file that this entry points at.
108+
pub fn file_type(&self) -> FileType {
109+
self.entry_type
110+
}
111+
}
112+
113+
impl fmt::Debug for DirEntry<'_> {
114+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
115+
f.debug_tuple("DirEntry").field(&self.path()).finish()
116+
}
117+
}
118+
119+
impl DirBuilder {
120+
/// Creates a new set of options with default mode/security settings for all
121+
/// platforms and also non-recursive.
122+
pub fn new() -> Self {
123+
Self { recursive: false }
124+
}
125+
126+
/// Indicates that directories should be created recursively, creating all
127+
/// parent directories. Parents that do not exist are created with the same
128+
/// security and permissions settings.
129+
pub fn recursive(&mut self, recursive: bool) -> &mut Self {
130+
self.recursive = recursive;
131+
self
132+
}
133+
134+
/// Creates the specified directory with the options configured in this
135+
/// builder.
136+
pub fn create(&self, path: &str) -> Result<()> {
137+
if self.recursive {
138+
self.create_dir_all(path)
139+
} else {
140+
crate::root::create_dir(None, path)
141+
}
142+
}
143+
144+
fn create_dir_all(&self, _path: &str) -> Result<()> {
145+
axerrno::ax_err!(
146+
Unsupported,
147+
"Recursive directory creation is not supported yet"
148+
)
149+
}
150+
}

0 commit comments

Comments
 (0)