Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
e4f67d1
fix: getdents
Oct 10, 2024
5baf6cb
test: add test harness
Oct 10, 2024
e01d516
fix: openat directory flag
Oct 16, 2024
8a18da3
fix: open with absolute path
Oct 16, 2024
d99b6c9
refactor: define AbsPath and RelPath type
Oct 16, 2024
ec5095e
refactor: devfs use new path defs
Oct 16, 2024
86a14b3
refactor: ramfs use new path defs
Oct 24, 2024
fc064b8
fix: ruxfs api and posix api
Oct 28, 2024
90128f8
refactor: implement simple ruxfs operations
Oct 29, 2024
f90c2ea
refacotr: fs posix api
Oct 31, 2024
07e55ce
fix: root directory lookup path
Oct 31, 2024
ff00a8b
feat: rmdir mkdirat unlink unlinkat api
Oct 31, 2024
8265722
fix: unlinkat with removedir
Nov 6, 2024
50977bb
test: use specific test dir
Nov 7, 2024
f5d3a63
feat: support fatfs and ext4 fs
Nov 14, 2024
d51a242
feat: make ext4 fs scripts
Nov 14, 2024
ed5d31c
fix: path canonicalization
Nov 18, 2024
840dbdd
feat: vfs add link and setattr fn
Nov 18, 2024
6acc1c3
fix: ramfs and devfs support new vfs trait
Nov 18, 2024
c9c8ee6
refactor: ruxfs and posix_api compats with new vfs
Nov 21, 2024
c392acc
feat: add inode number in vfsattr
Nov 21, 2024
8af1c3e
refactor: remove fops with relative path
Nov 25, 2024
e3e07e3
fix: path lifetime
Nov 27, 2024
abf3a6c
refactor: filelike path method
Nov 27, 2024
0e806a0
refactor: fs posix api with absolute path
Nov 27, 2024
0b37197
fix: FileLike stat
Nov 28, 2024
8cf6918
feat: directory check empty
Nov 28, 2024
2bef77f
fix: unlinkat
Nov 28, 2024
41879f9
Update ruxfs dependencies
Nov 28, 2024
0e58f4e
fix: blkfs features
Nov 28, 2024
52247a2
feat: ruxfs high-level api
Nov 28, 2024
b80d765
feat: fs arceos api
Nov 28, 2024
c9c0963
feat: axstd fs api
Nov 28, 2024
a98c3e7
fix: devfs and ramfs lookup
Nov 28, 2024
454bb3d
doc: axfs_vfs and ruxfs doc comments
Nov 28, 2024
01e9eee
fix: remove harness from workspace
Nov 28, 2024
4a99179
refactor: remove test harness
Feb 15, 2025
18bc4a9
fix: incompatible interfaces
Feb 19, 2025
3e55f9e
style: ruxos_posix_api fs syscalls
Feb 20, 2025
c99c128
fix: make fs img
Feb 26, 2025
e8d90f6
fix: ruxruntime fs test
Feb 26, 2025
aa5895a
fix: unit test
Feb 27, 2025
790e423
fix: clippy
Feb 27, 2025
ee46070
fix: aarch64 & riscv64 openat
Feb 27, 2025
8c699bc
fix: build fs shell
Feb 27, 2025
9c9b775
fix: build iperf & redis
Feb 27, 2025
e3fdd09
fix: log dep version
Feb 27, 2025
e14b5fb
fix: temporarily remove lwext4_rust
Mar 4, 2025
287ed72
fix: update another_ext4 dep
Mar 4, 2025
c20a832
style: cargo format all
Mar 4, 2025
0f85878
fix: docs
Mar 4, 2025
f883f12
Merge branch 'dev'
Mar 4, 2025
b18325e
fix: getdents
Mar 5, 2025
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
Prev Previous commit
Next Next commit
fix: clippy
  • Loading branch information
liujingx committed Feb 27, 2025
commit 790e423be9fabc34d569a491d7b3d79492d345c2
2 changes: 1 addition & 1 deletion api/arceos_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fs = ["dep:ruxfs", "ruxfeat/fs"]
net = ["dep:ruxnet", "ruxfeat/net"]
lwip = ["ruxfeat/lwip"]
display = ["dep:ruxdisplay", "ruxfeat/display"]

blkfs = ["ruxfeat/blkfs"]
myfs = ["ruxfeat/myfs"]

# Use dummy functions if the feature is not enabled
Expand Down
15 changes: 13 additions & 2 deletions api/arceos_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ pub use ruxfs::api::FilePerm as AxFilePerm;
pub use ruxfs::api::FileType as AxFileType;
pub use ruxfs::api::OpenOptions as AxOpenOptions;

#[cfg(feature = "blkfs")]
pub use ruxfs::dev::Disk as AxDisk;

#[cfg(feature = "myfs")]
pub use ruxfs::fops::{Disk as AxDisk, MyFileSystemIf};
pub use ruxfs::MyFileSystemIf;

/// A handle to an opened file.
pub struct AxFileHandle(File);
Expand All @@ -36,7 +39,7 @@ pub fn ax_open_file(path: &str, opts: &AxOpenOptions) -> AxResult<AxFileHandle>
}

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

pub fn ax_get_attr(path: &str) -> AxResult<AxFileAttr> {
Expand Down Expand Up @@ -106,3 +109,11 @@ fn parse_path(path: &str) -> AxResult<AbsPath<'static>> {
ruxfs::api::current_dir().map(|cwd| cwd.join(&RelPath::new_canonicalized(path)))
}
}

impl Iterator for AxDirHandle {
type Item = AxResult<AxDirEntry>;

fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
}
2 changes: 1 addition & 1 deletion api/arceos_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub mod fs {
pub type AxFilePerm;
pub type AxDirEntry;
pub type AxSeekFrom;
#[cfg(feature = "myfs")]
#[cfg(feature = "blkfs")]
pub type AxDisk;
#[cfg(feature = "myfs")]
pub type MyFileSystemIf;
Expand Down
12 changes: 6 additions & 6 deletions api/ruxos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl ruxtask::fs::InitFs for InitFsImpl {
}

/// Convert open flags to [`OpenOptions`].
fn flags_to_options(flags: c_int, _mode: ctypes::mode_t) -> OpenOptions {
pub fn flags_to_options(flags: c_int, _mode: ctypes::mode_t) -> OpenOptions {
let flags = flags as u32;
let mut options = OpenOptions::new();
match flags & 0b11 {
Expand Down Expand Up @@ -246,10 +246,10 @@ pub unsafe fn sys_stat(path: *const c_char, buf: *mut core::ffi::c_void) -> c_in
let attr = node.get_attr()?;
let st: RuxStat = if attr.is_dir() {
let dir = fops::open_dir(&path, node, &OpenOptions::new())?;
Directory::new(dir, false).stat()?.into()
Directory::new(dir, false).stat()?
} else {
let file = fops::open_file(&path, node, &OpenOptions::new())?;
File::new(file).stat()?.into()
File::new(file).stat()?
};

#[cfg(not(feature = "musl"))]
Expand Down Expand Up @@ -441,7 +441,7 @@ pub fn sys_rmdir(pathname: *const c_char) -> c_int {
if !attr.is_dir() {
return Err(LinuxError::ENOTDIR);
}
if fops::is_mount_point(&path)? {
if fops::is_mount_point(&path) {
return Err(LinuxError::EPERM);
}
if !attr.perm().owner_writable() {
Expand Down Expand Up @@ -496,7 +496,7 @@ pub fn sys_unlinkat(fd: c_int, pathname: *const c_char, flags: c_int) -> c_int {
if !attr.is_dir() {
return Err(LinuxError::ENOTDIR);
}
if fops::is_mount_point(&path)? {
if fops::is_mount_point(&path) {
return Err(LinuxError::EPERM);
}
if !attr.perm().owner_writable() {
Expand Down Expand Up @@ -648,7 +648,7 @@ pub unsafe fn sys_getdents64(fd: c_int, dirp: *mut LinuxDirent64, count: ctypes:
dirent.d_name[..name_len].copy_from_slice(unsafe {
core::slice::from_raw_parts(name.as_ptr() as *const i8, name_len)
});
dirent.d_name[name_len] = 0 as i8;
dirent.d_name[name_len] = 0i8;

written += entry_size;
}
Expand Down
5 changes: 5 additions & 0 deletions api/ruxos_posix_api/src/imp/io_mpx/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use ruxhal::time::current_time;

use crate::{ctypes, imp::fs::flags_to_options};
use ruxtask::fs::{add_file_like, get_file_like};
use ruxfs::AbsPath;

pub struct EpollInstance {
events: Mutex<BTreeMap<usize, ctypes::epoll_event>>,
Expand Down Expand Up @@ -122,6 +123,10 @@ impl EpollInstance {
}

impl FileLike for EpollInstance {
fn path(&self) -> AbsPath {
AbsPath::new("/epoll")
}

fn read(&self, _buf: &mut [u8]) -> LinuxResult<usize> {
Err(LinuxError::ENOSYS)
}
Expand Down
2 changes: 1 addition & 1 deletion api/ruxos_posix_api/src/imp/mmap/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub(crate) fn release_pages_swaped(start: usize, end: usize) {
let mut off_pool = BITMAP_FREE.lock();

let mut removing_vaddr = Vec::new();
for (&vaddr, &ref swap_info) in swap_map.range(start..end) {
for (&vaddr, swap_info) in swap_map.range(start..end) {
removing_vaddr.push(vaddr);
off_pool.push(swap_info.offset);
}
Expand Down
8 changes: 6 additions & 2 deletions api/ruxos_posix_api/src/imp/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use alloc::{sync::Arc, vec, vec::Vec};
use core::ffi::{c_char, c_int, c_void};
use core::mem::size_of;
use core::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
use ruxfs::fops;
use ruxfs::{AbsPath, fops};

use axerrno::{LinuxError, LinuxResult};
use axio::PollState;
Expand Down Expand Up @@ -266,6 +266,10 @@ impl Socket {
}

impl FileLike for Socket {
fn path(&self) -> AbsPath {
AbsPath::new("/dev/socket")
}

fn read(&self, buf: &mut [u8]) -> LinuxResult<usize> {
self.recv(buf, 0)
}
Expand Down Expand Up @@ -564,7 +568,7 @@ pub unsafe fn sys_recvfrom(
UnifiedSocketAddress::Unix(addr) => unsafe {
let sockaddr_un_size = addr.get_addr_len();
let sockaddr_un = SocketAddrUnix {
sun_family: 1 as u16, // AF_UNIX
sun_family: 1u16, // AF_UNIX
sun_path: addr.sun_path,
};
let original_addrlen = *addrlen as usize;
Expand Down
6 changes: 5 additions & 1 deletion api/ruxos_posix_api/src/imp/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use alloc::sync::{Arc, Weak};
use core::ffi::c_int;
use ruxfs::fops;
use ruxfs::{fops, AbsPath};

use axerrno::{LinuxError, LinuxResult};
use axio::PollState;
Expand Down Expand Up @@ -123,6 +123,10 @@ impl Pipe {
}

impl FileLike for Pipe {
fn path(&self) -> AbsPath {
AbsPath::new("/dev/pipe")
}

fn read(&self, buf: &mut [u8]) -> LinuxResult<usize> {
if !self.readable() {
return Err(LinuxError::EPERM);
Expand Down
1 change: 1 addition & 0 deletions apps/c/filetest/features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ alloc
paging
fs
blkfs
fatfs
1 change: 1 addition & 0 deletions apps/c/sqlite3/features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ alloc
paging
fs
blkfs
fatfs
5 changes: 5 additions & 0 deletions crates/axfs_vfs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ impl<'a> RelPath<'a> {
pub fn new_trimmed(path: &'a str) -> Self {
Self(Cow::Borrowed(path.trim_start_matches('/')))
}

/// Convert this `RelPath` into a raw str slice.
pub fn as_str(&self) -> &str {
self.0.as_ref()
}
}

impl core::ops::Deref for RelPath<'_> {
Expand Down
53 changes: 26 additions & 27 deletions modules/rux9p/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::drv::{self, Drv9pOps};
use alloc::{string::String, string::ToString, sync::Arc, sync::Weak, vec::Vec};
use axfs_vfs::{
VfsDirEntry, VfsError, VfsNodeAttr, VfsNodeOps, VfsNodePerm, VfsNodeRef, VfsNodeType, VfsOps,
VfsResult,
VfsResult, AbsPath, RelPath
};
use log::*;
use spin::{once::Once, RwLock};
Expand Down Expand Up @@ -86,7 +86,7 @@ impl _9pFileSystem {
}

impl VfsOps for _9pFileSystem {
fn mount(&self, _path: &str, mount_point: VfsNodeRef) -> VfsResult {
fn mount(&self, _path: &AbsPath, mount_point: VfsNodeRef) -> VfsResult {
if let Some(parent) = mount_point.parent() {
self.root.set_parent(Some(self.parent.call_once(|| parent)));
} else {
Expand Down Expand Up @@ -177,12 +177,12 @@ impl CommonNode {
}

/// Checks whether a node with the given name exists in this directory.
fn exist(&self, path: &str) -> bool {
fn exist(&self, path: &RelPath) -> bool {
self.try_get(path).is_ok()
}

/// Creates a new node with the given name and type in this directory.
fn create_node(&self, name: &str, ty: VfsNodeType) -> VfsResult {
fn create_node(&self, name: &RelPath, ty: VfsNodeType) -> VfsResult {
if self.exist(name) {
error!("AlreadyExists {}", name);
return Err(VfsError::AlreadyExists);
Expand Down Expand Up @@ -235,18 +235,18 @@ impl CommonNode {
Ok(())
}

fn try_get(&self, path: &str) -> VfsResult<VfsNodeRef> {
fn try_get(&self, path: &RelPath) -> VfsResult<VfsNodeRef> {
let (name, rest) = split_path(path);
if name == ".." {
match self.parent() {
Some(parent) => return parent.lookup(rest.unwrap_or("")),
Some(parent) => return parent.lookup(&rest.unwrap_or(RelPath::new(""))),
None => {
error!("9pfs: try_get a directory out of 9pfs boundary");
return Err(VfsError::BadState);
}
}
} else if name == "." {
return self.try_get(rest.unwrap_or(""));
return self.try_get(&rest.unwrap_or(RelPath::new("")));
}

let fid = match self.inner.write().get_fid() {
Expand All @@ -273,7 +273,7 @@ impl CommonNode {
self.protocol.clone(),
);
match rest {
Some(rpath) => node.try_get(rpath),
Some(rpath) => node.try_get(&rpath),
None => Ok(node),
}
}
Expand Down Expand Up @@ -344,17 +344,17 @@ impl Drop for CommonNode {

impl VfsNodeOps for CommonNode {
/// Renames or moves existing file or directory.
fn rename(&self, src_path: &str, dst_path: &str) -> VfsResult {
fn rename(&self, src_path: &RelPath, dst_path: &RelPath) -> VfsResult {
let (src_prefixs, old_name) = if let Some(src_sindex) = src_path.rfind('/') {
(&src_path[..src_sindex], &src_path[src_sindex + 1..])
} else {
("", src_path)
("", src_path.as_str())
};

let (dst_prefixs, new_name) = if let Some(dst_sindex) = dst_path.rfind('/') {
(&dst_path[..dst_sindex], &dst_path[dst_sindex + 1..])
} else {
("", dst_path)
("", dst_path.as_str())
};

debug!(
Expand Down Expand Up @@ -390,7 +390,7 @@ impl VfsNodeOps for CommonNode {
dst_fnode.write_at(offset, &buffer[..length])?;
offset += length as u64;
}
src_fnode.remove("")?;
src_fnode.unlink(&RelPath::new(""))?;
}
Ok(())
}
Expand All @@ -401,13 +401,13 @@ impl VfsNodeOps for CommonNode {
debug!("get_attr {:?}", resp);
match resp {
Ok(stat) if stat.get_ftype() == 0o4 => {
let mut attr = VfsNodeAttr::new_dir(stat.get_size(), stat.get_blk_num());
let mut attr = VfsNodeAttr::new_dir(0, stat.get_size(), stat.get_blk_num());
let mode = stat.get_perm() as u16 & 0o777_u16;
attr.set_perm(VfsNodePerm::from_bits(mode).unwrap());
Ok(attr)
}
Ok(stat) if stat.get_ftype() == 0o10 => {
let mut attr = VfsNodeAttr::new_file(stat.get_size(), stat.get_blk_num());
let mut attr = VfsNodeAttr::new_file(0, stat.get_size(), stat.get_blk_num());
let mode = stat.get_perm() as u16 & 0o777_u16;
attr.set_perm(VfsNodePerm::from_bits(mode).unwrap());
Ok(attr)
Expand All @@ -418,13 +418,13 @@ impl VfsNodeOps for CommonNode {
let resp = self.inner.write().tstat(*self.fid);
match resp {
Ok(stat) if stat.get_ftype() == 0o4 => {
let mut attr = VfsNodeAttr::new_dir(stat.get_length(), stat.get_blk_num());
let mut attr = VfsNodeAttr::new_dir(0, stat.get_length(), stat.get_blk_num());
let mode = stat.get_perm() as u16 & 0o777_u16;
attr.set_perm(VfsNodePerm::from_bits(mode).unwrap());
Ok(attr)
}
Ok(stat) if stat.get_ftype() == 0o10 => {
let mut attr = VfsNodeAttr::new_file(stat.get_length(), stat.get_blk_num());
let mut attr = VfsNodeAttr::new_file(0, stat.get_length(), stat.get_blk_num());
let mode = stat.get_perm() as u16 & 0o777_u16;
attr.set_perm(VfsNodePerm::from_bits(mode).unwrap());
Ok(attr)
Expand All @@ -441,7 +441,7 @@ impl VfsNodeOps for CommonNode {
}

/// for 9p filesystem's directory, lookup() will return node in 9p if path existing in both 9p and mounted_map.
fn lookup(self: Arc<Self>, path: &str) -> VfsResult<VfsNodeRef> {
fn lookup(self: Arc<Self>, path: &RelPath) -> VfsResult<VfsNodeRef> {
debug!("lookup 9pfs: {}", path);
self.try_get(path)
}
Expand Down Expand Up @@ -501,25 +501,25 @@ impl VfsNodeOps for CommonNode {
Ok(vfs_dirents.len())
}

fn create(&self, path: &str, ty: VfsNodeType) -> VfsResult {
fn create(&self, path: &RelPath, ty: VfsNodeType) -> VfsResult {
debug!("create {:?} at 9pfs: {}", ty, path);

let (name, rest) = split_path(path);
if let Some(rpath) = rest {
self.try_get(name)?.create(rpath, ty)
self.try_get(&RelPath::new(name))?.create(&rpath, ty)
} else {
self.create_node(name, ty)
self.create_node(&RelPath::new(name), ty)
}
}

fn remove(&self, path: &str) -> VfsResult {
debug!("remove at 9pfs: {}", path);
fn unlink(&self, path: &RelPath) -> VfsResult {
debug!("unlink at 9pfs: {}", path);
match split_path(path) {
("", None) | (".", None) => match self.inner.write().tremove(*self.fid) {
Ok(_) => Ok(()),
Err(_) => Err(VfsError::BadState),
},
_ => self.try_get(path)?.remove(""),
_ => self.try_get(path)?.unlink(&RelPath::new("")),
}
}

Expand Down Expand Up @@ -608,9 +608,8 @@ impl VfsNodeOps for CommonNode {
}
}

fn split_path(path: &str) -> (&str, Option<&str>) {
let trimmed_path = path.trim_start_matches('/');
trimmed_path.find('/').map_or((trimmed_path, None), |n| {
(&trimmed_path[..n], Some(&trimmed_path[n + 1..]))
fn split_path<'a>(path: &'a RelPath) -> (&'a str, Option<RelPath<'a>>) {
path.find('/').map_or((path, None), |n| {
(&path[..n], Some(RelPath::new(&path[n + 1..])))
})
}
Loading