Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor and fix filesystem #152

Open
wants to merge 40 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
714a944
Merge pull request #76 from syswonder/dev
caodg Mar 28, 2024
1a47719
Merge pull request #102 from syswonder/dev
ken4647 May 8, 2024
c54f363
Merge pull request #120 from syswonder/dev
caodg Jun 6, 2024
b1f880b
Merge pull request #135 from syswonder/dev
TheSayOL Jul 5, 2024
d1e099f
fix: getdents
PKTH-Jx Oct 10, 2024
663ad3c
test: add test harness
PKTH-Jx Oct 10, 2024
767d892
fix: openat directory flag
PKTH-Jx Oct 16, 2024
0fdd5af
fix: open with absolute path
PKTH-Jx Oct 16, 2024
b93320d
refactor: define AbsPath and RelPath type
PKTH-Jx Oct 16, 2024
b26a067
refactor: devfs use new path defs
PKTH-Jx Oct 16, 2024
cacbb1f
refactor: ramfs use new path defs
PKTH-Jx Oct 24, 2024
fdd86e8
fix: ruxfs api and posix api
PKTH-Jx Oct 28, 2024
35f5349
refactor: implement simple ruxfs operations
PKTH-Jx Oct 29, 2024
29d9c53
refacotr: fs posix api
PKTH-Jx Oct 31, 2024
64fbfe7
fix: root directory lookup path
PKTH-Jx Oct 31, 2024
fb9becc
feat: rmdir mkdirat unlink unlinkat api
PKTH-Jx Oct 31, 2024
fa5ee1f
fix: unlinkat with removedir
PKTH-Jx Nov 6, 2024
0a452f9
test: use specific test dir
PKTH-Jx Nov 7, 2024
3bf32a5
feat: support fatfs and ext4 fs
PKTH-Jx Nov 14, 2024
fe343c1
feat: make ext4 fs scripts
PKTH-Jx Nov 14, 2024
f81ddc7
fix: path canonicalization
PKTH-Jx Nov 18, 2024
929d3ce
feat: vfs add link and setattr fn
PKTH-Jx Nov 18, 2024
1ef7442
fix: ramfs and devfs support new vfs trait
PKTH-Jx Nov 18, 2024
d0a8d58
refactor: ruxfs and posix_api compats with new vfs
PKTH-Jx Nov 21, 2024
ed49d89
feat: add inode number in vfsattr
PKTH-Jx Nov 21, 2024
49decb2
refactor: remove fops with relative path
PKTH-Jx Nov 25, 2024
aa6577a
fix: path lifetime
PKTH-Jx Nov 27, 2024
5ea965f
refactor: filelike path method
PKTH-Jx Nov 27, 2024
b48fff3
refactor: fs posix api with absolute path
PKTH-Jx Nov 27, 2024
b41482f
fix: FileLike stat
PKTH-Jx Nov 28, 2024
cb5165b
feat: directory check empty
PKTH-Jx Nov 28, 2024
076bd58
fix: unlinkat
PKTH-Jx Nov 28, 2024
33bf390
Update ruxfs dependencies
PKTH-Jx Nov 28, 2024
7852ddb
fix: blkfs features
PKTH-Jx Nov 28, 2024
a3f7b9a
feat: ruxfs high-level api
PKTH-Jx Nov 28, 2024
2abbac7
feat: fs arceos api
PKTH-Jx Nov 28, 2024
b4c419b
feat: axstd fs api
PKTH-Jx Nov 28, 2024
0b87e7c
fix: devfs and ramfs lookup
PKTH-Jx Nov 28, 2024
b0fa8f7
doc: axfs_vfs and ruxfs doc comments
PKTH-Jx Nov 28, 2024
9251a66
fix: remove harness from workspace
PKTH-Jx Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
713 changes: 343 additions & 370 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ members = [

"apps/display/basic_painting",
"apps/display/draw_map",
"apps/fs/shell",
"apps/fs/shell"
]

[profile.release]
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,20 @@ unittest:
unittest_no_fail_fast:
$(call unit_test,--no-fail-fast)

disk_img:
fat_img:
ifneq ($(wildcard $(DISK_IMG)),)
@printf "$(YELLOW_C)warning$(END_C): disk image \"$(DISK_IMG)\" already exists!\n"
else
$(call make_disk_image,fat32,$(DISK_IMG))
endif

ext4_img:
ifneq ($(wildcard $(DISK_IMG)),)
@printf "$(YELLOW_C)warning$(END_C): disk image \"$(DISK_IMG)\" already exists!\n"
else
$(call make_disk_image,ext4,$(DISK_IMG))
endif

clean: clean_c clean_musl
rm -rf $(APP)/*.bin $(APP)/*.elf
cargo clean
Expand Down
56 changes: 32 additions & 24 deletions api/arceos_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@

use alloc::string::String;
use axerrno::AxResult;
use ruxfs::fops::{Directory, File};
use ruxfs::{
api::{Directory, File},
AbsPath, RelPath,
};
use axio::{Read, Write, Seek};

pub use ruxfs::fops::DirEntry as AxDirEntry;
pub use ruxfs::fops::FileAttr as AxFileAttr;
pub use ruxfs::fops::FilePerm as AxFilePerm;
pub use ruxfs::fops::FileType as AxFileType;
pub use ruxfs::fops::OpenOptions as AxOpenOptions;
pub use axio::SeekFrom as AxSeekFrom;
pub use ruxfs::api::DirEntry as AxDirEntry;
pub use ruxfs::api::FileAttr as AxFileAttr;
pub use ruxfs::api::FilePerm as AxFilePerm;
pub use ruxfs::api::FileType as AxFileType;
pub use ruxfs::api::OpenOptions as AxOpenOptions;

#[cfg(feature = "myfs")]
pub use ruxfs::fops::{Disk as AxDisk, MyFileSystemIf};
Expand All @@ -28,29 +32,25 @@ pub struct AxFileHandle(File);
pub struct AxDirHandle(Directory);

pub fn ax_open_file(path: &str, opts: &AxOpenOptions) -> AxResult<AxFileHandle> {
Ok(AxFileHandle(File::open(path, opts)?))
Ok(AxFileHandle(opts.open(&parse_path(path)?)?))
}

pub fn ax_open_dir(path: &str, opts: &AxOpenOptions) -> AxResult<AxDirHandle> {
Ok(AxDirHandle(Directory::open_dir(path, opts)?))
pub fn ax_open_dir(path: &str, _opts: &AxOpenOptions) -> AxResult<AxDirHandle> {
Ok(AxDirHandle(Directory::open(parse_path(path)?)?))
}

pub fn ax_read_file(file: &mut AxFileHandle, buf: &mut [u8]) -> AxResult<usize> {
file.0.read(buf)
pub fn ax_get_attr(path: &str) -> AxResult<AxFileAttr> {
ruxfs::api::get_attr(&parse_path(path)?)
}

pub fn ax_read_file_at(file: &AxFileHandle, offset: u64, buf: &mut [u8]) -> AxResult<usize> {
file.0.read_at(offset, buf)
pub fn ax_read_file(file: &mut AxFileHandle, buf: &mut [u8]) -> AxResult<usize> {
file.0.read(buf)
}

pub fn ax_write_file(file: &mut AxFileHandle, buf: &[u8]) -> AxResult<usize> {
file.0.write(buf)
}

pub fn ax_write_file_at(file: &AxFileHandle, offset: u64, buf: &[u8]) -> AxResult<usize> {
file.0.write_at(offset, buf)
}

pub fn ax_truncate_file(file: &AxFileHandle, size: u64) -> AxResult {
file.0.truncate(size)
}
Expand All @@ -72,29 +72,37 @@ pub fn ax_read_dir(dir: &mut AxDirHandle, dirents: &mut [AxDirEntry]) -> AxResul
}

pub fn ax_create_dir(path: &str) -> AxResult {
ruxfs::api::create_dir(path)
ruxfs::api::create_dir(&parse_path(path)?)
}

pub fn ax_create_dir_all(path: &str) -> AxResult {
ruxfs::api::create_dir_all(path)
ruxfs::api::create_dir_all(&parse_path(path)?)
}

pub fn ax_remove_dir(path: &str) -> AxResult {
ruxfs::api::remove_dir(path)
ruxfs::api::remove_dir(&parse_path(path)?)
}

pub fn ax_remove_file(path: &str) -> AxResult {
ruxfs::api::remove_file(path)
ruxfs::api::remove_file(&parse_path(path)?)
}

pub fn ax_rename(old: &str, new: &str) -> AxResult {
ruxfs::api::rename(old, new)
ruxfs::api::rename(&parse_path(old)?, &parse_path(new)?)
}

pub fn ax_current_dir() -> AxResult<String> {
ruxfs::api::current_dir()
ruxfs::api::current_dir().map(|path| path.to_string())
}

pub fn ax_set_current_dir(path: &str) -> AxResult {
ruxfs::api::set_current_dir(path)
ruxfs::api::set_current_dir(parse_path(path)?)
}

fn parse_path(path: &str) -> AxResult<AbsPath<'static>> {
if path.starts_with('/') {
Ok(AbsPath::new_canonicalized(path))
} else {
ruxfs::api::current_dir().map(|cwd| cwd.join(&RelPath::new_canonicalized(path)))
}
}
11 changes: 2 additions & 9 deletions api/arceos_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,26 +174,19 @@ pub mod fs {
/// Opens a directory at the path relative to the current directory with
/// the options specified by `opts`.
pub fn ax_open_dir(path: &str, opts: &AxOpenOptions) -> AxResult<AxDirHandle>;
/// Returns attributes of a file or directory at the given path.
pub fn ax_get_attr(path: &str) -> AxResult<AxFileAttr>;

/// Reads the file at the current position, returns the number of bytes read.
///
/// After the read, the cursor will be advanced by the number of bytes read.
pub fn ax_read_file(file: &mut AxFileHandle, buf: &mut [u8]) -> AxResult<usize>;
/// Reads the file at the given position, returns the number of bytes read.
///
/// It does not update the file cursor.
pub fn ax_read_file_at(file: &AxFileHandle, offset: u64, buf: &mut [u8]) -> AxResult<usize>;
/// Writes the file at the current position, returns the number of bytes
/// written.
///
/// After the write, the cursor will be advanced by the number of bytes
/// written.
pub fn ax_write_file(file: &mut AxFileHandle, buf: &[u8]) -> AxResult<usize>;
/// Writes the file at the given position, returns the number of bytes
/// written.
///
/// It does not update the file cursor.
pub fn ax_write_file_at(file: &AxFileHandle, offset: u64, buf: &[u8]) -> AxResult<usize>;
/// Truncates the file to the specified size.
pub fn ax_truncate_file(file: &AxFileHandle, size: u64) -> AxResult;
/// Flushes the file, writes all buffered data to the underlying device.
Expand Down
6 changes: 5 additions & 1 deletion api/ruxfeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ sched_cfs = ["ruxtask/sched_cfs", "irq"]

# File system
fs = ["alloc", "dep:ruxfs", "ruxruntime/fs"]
blkfs = ["ruxdriver/virtio-blk", "ruxruntime/blkfs"]
blkfs = ["ruxdriver/virtio-blk", "ruxruntime/blkfs", "ruxfs/blkfs"]
myfs = ["ruxfs?/myfs"]
9pfs = []
fatfs = ["ruxfs?/fatfs"]
lwext4_rust = ["ruxfs?/lwext4_rust"]
ext4_rs = ["ruxfs?/ext4_rs"]
another_ext4 = ["ruxfs?/another_ext4"]

# Networking
net = ["alloc", "ruxdriver/virtio-net", "dep:ruxnet", "ruxruntime/net"]
Expand Down
1 change: 1 addition & 0 deletions api/ruxos_posix_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ lazy_static = { version = "1.4", features = ["spin_no_std"] }
flatten_objects = { path = "../../crates/flatten_objects" }
page_table = { path = "../../crates/page_table" }
crate_interface = "0.1.1"
capability = { path = "../../crates/capability" }

cfg-if = "1.0"
elf = { version = "0.7", default-features = false }
Expand Down
Loading
Loading