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: ruxruntime fs test
  • Loading branch information
liujingx committed Feb 26, 2025
commit e8d90f6d24cc033e49be8d024ef1ef90fd6750a1
6 changes: 6 additions & 0 deletions api/ruxos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ pub fn sys_rmdir(pathname: *const c_char) -> c_int {
if !attr.is_dir() {
return Err(LinuxError::ENOTDIR);
}
if fops::is_mount_point(&path)? {
return Err(LinuxError::EPERM);
}
if !attr.perm().owner_writable() {
return Err(LinuxError::EPERM);
}
Expand Down Expand Up @@ -493,6 +496,9 @@ 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)? {
return Err(LinuxError::EPERM);
}
if !attr.perm().owner_writable() {
return Err(LinuxError::EPERM);
}
Expand Down
5 changes: 3 additions & 2 deletions crates/axfs_vfs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ impl<'a> AbsPath<'a> {
AbsPath::new_owned(self.0.to_string())
}

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

/// Transform this `AbsPath` into a raw string.
/// Convert this `AbsPath` into a raw string.
#[allow(clippy::inherent_to_string_shadow_display)]
pub fn to_string(&self) -> String {
self.0.to_string()
}
Expand Down
50 changes: 29 additions & 21 deletions modules/ruxfs/src/api/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,56 @@
* See the Mulan PSL v2 for more details.
*/

use alloc::{borrow::ToOwned, string::String, vec};
use alloc::{borrow::ToOwned, string::String};
use axerrno::ax_err;
use axfs_vfs::{AbsPath, VfsError};
use axfs_vfs::{AbsPath, VfsDirEntry, VfsError};
use axio::Result;
use core::{fmt, str};
use core::{fmt, iter::Iterator, str};

use super::FileType;
use super::{FileAttr, FileType};
use crate::fops;

/// Iterator over the entries in a directory.
/// A wrapped directory type.
///
/// Provides a way to open a directory and iterate over its contents.
pub struct Directory {
inner: fops::Directory,
}

impl Directory {
/// Opens a directory for reading entries.
pub fn open(path: AbsPath<'static>) -> Result<Self> {
pub fn open(path: &AbsPath) -> Result<Self> {
let node = fops::lookup(&path)?;
let inner = fops::open_dir(&path, node, &fops::OpenOptions::new())?;
Ok(Self { inner })
}

/// Reads directory entries starts from the current position into the
/// given buffer, returns the number of entries read.
///
/// After the read, the cursor of the directory will be advanced by the
/// number of entries read.
pub fn read_dir(&mut self, buf: &mut [DirEntry]) -> Result<usize> {
let mut buffer = vec![fops::DirEntry::default(); buf.len()];
let len = self.inner.read_dir(&mut buffer)?;
for (i, entry) in buffer.iter().enumerate().take(len) {
buf[i] = DirEntry {
entry_name: unsafe { str::from_utf8_unchecked(entry.name_as_bytes()).to_owned() },
entry_type: entry.entry_type(),
};
/// Get attributes of the directory.
pub fn get_attr(&self) -> Result<FileAttr> {
self.inner.get_attr()
}
}

/// Implements the iterator trait for the directory.
impl Iterator for Directory {
type Item = Result<DirEntry>;

fn next(&mut self) -> Option<Self::Item> {
let mut buf = [VfsDirEntry::default()];
match self.inner.read_dir(buf.as_mut_slice()) {
Ok(0) => None,
Ok(1) => Some(Ok(DirEntry {
entry_name: unsafe { str::from_utf8_unchecked(buf[0].name_as_bytes()).to_owned() },
entry_type: buf[0].entry_type(),
})),
Ok(_) => unreachable!(),
Err(e) => Some(Err(e)),
}
Ok(len)
}
}

/// Entry type used by `Directory::read_dir`.
#[derive(Default)]
#[derive(Default, Clone)]
pub struct DirEntry {
entry_name: String,
entry_type: FileType,
Expand Down
58 changes: 29 additions & 29 deletions modules/ruxfs/src/api/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl OpenOptions {
return ax_err!(InvalidInput);
}
// Find node, check flag and attr
let node = match fops::lookup(&path) {
let node = match fops::lookup(path) {
Ok(node) => {
if self.0.create_new {
return ax_err!(AlreadyExists);
Expand All @@ -88,8 +88,8 @@ impl OpenOptions {
if !self.0.create && !self.0.create_new {
return ax_err!(NotFound);
}
fops::create_file(&path)?;
fops::lookup(&path)?
fops::create_file(path)?;
fops::lookup(path)?
}
Err(e) => return Err(e),
};
Expand All @@ -101,7 +101,32 @@ impl OpenOptions {
node.truncate(0)?;
}
// Open
fops::open_file(&path, node, &self.0).map(|inner| File { inner })
fops::open_file(path, node, &self.0).map(|inner| File { inner })
}
}

impl fmt::Debug for OpenOptions {
#[allow(unused_assignments)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut written = false;
macro_rules! fmt_opt {
($field: ident, $label: literal) => {
if self.0.$field {
if written {
write!(f, " | ")?;
}
write!(f, $label)?;
written = true;
}
};
}
fmt_opt!(read, "READ");
fmt_opt!(write, "WRITE");
fmt_opt!(append, "APPEND");
fmt_opt!(truncate, "TRUNC");
fmt_opt!(create, "CREATE");
fmt_opt!(create_new, "CREATE_NEW");
Ok(())
}
}

Expand Down Expand Up @@ -182,28 +207,3 @@ impl Seek for File {
self.inner.seek(pos)
}
}

impl fmt::Debug for OpenOptions {
#[allow(unused_assignments)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut written = false;
macro_rules! fmt_opt {
($field: ident, $label: literal) => {
if self.0.$field {
if written {
write!(f, " | ")?;
}
write!(f, $label)?;
written = true;
}
};
}
fmt_opt!(read, "READ");
fmt_opt!(write, "WRITE");
fmt_opt!(append, "APPEND");
fmt_opt!(truncate, "TRUNC");
fmt_opt!(create, "CREATE");
fmt_opt!(create_new, "CREATE_NEW");
Ok(())
}
}
12 changes: 10 additions & 2 deletions modules/ruxfs/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ pub fn set_current_dir(path: AbsPath<'static>) -> io::Result<()> {
fops::set_current_dir(path)
}

/// Return the canonicalized and absolute path of the specified path.
pub fn absolute_path(path: &str) -> io::Result<AbsPath<'static>> {
fops::absolute_path(path)
}

/// Get the attibutes of a file or directory.
pub fn get_attr(path: &AbsPath) -> io::Result<FileAttr> {
fops::lookup(path)?.get_attr()
Expand Down Expand Up @@ -83,6 +88,9 @@ pub fn remove_dir(path: &AbsPath) -> io::Result<()> {
if !attr.is_dir() {
return ax_err!(NotADirectory);
}
if fops::is_mount_point(path) {
return ax_err!(PermissionDenied);
}
if !attr.perm().owner_writable() {
return ax_err!(PermissionDenied);
}
Expand Down Expand Up @@ -112,8 +120,8 @@ pub fn remove_file(path: &AbsPath) -> io::Result<()> {
pub fn rename(old: &AbsPath, new: &AbsPath) -> io::Result<()> {
fops::lookup(old)?;
match fops::lookup(new) {
Ok(_) => return ax_err!(AlreadyExists),
Ok(_) => ax_err!(AlreadyExists),
Err(VfsError::NotFound) => fops::rename(old, new),
Err(e) => return ax_err!(e),
Err(e) => ax_err!(e),
}
}
14 changes: 11 additions & 3 deletions modules/ruxfs/src/fops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ pub fn get_attr(path: &AbsPath) -> AxResult<FileAttr> {
/// Open a node as a file, with permission checked.
pub fn open_file(path: &AbsPath, node: VfsNodeRef, opt: &OpenOptions) -> AxResult<File> {
let attr = node.get_attr()?;
if attr.is_dir() {
return ax_err!(IsADirectory);
}
if !perm_to_cap(attr.perm()).contains(opt.to_cap()) {
return ax_err!(PermissionDenied);
}
Expand All @@ -354,6 +357,9 @@ pub fn open_file(path: &AbsPath, node: VfsNodeRef, opt: &OpenOptions) -> AxResul
/// Open a node as a directory, with permission checked.
pub fn open_dir(path: &AbsPath, node: VfsNodeRef, opt: &OpenOptions) -> AxResult<Directory> {
let attr = node.get_attr()?;
if !attr.is_dir() {
return ax_err!(NotADirectory);
}
if !perm_to_cap(attr.perm()).contains(opt.to_cap()) {
return ax_err!(PermissionDenied);
}
Expand Down Expand Up @@ -409,12 +415,14 @@ pub fn remove_file(path: &AbsPath) -> AxResult {
/// This function will not check if the directory exists or is empty,
/// check it with [`lookup`] first.
pub fn remove_dir(path: &AbsPath) -> AxResult {
if root_dir().contains(path) {
return ax_err!(PermissionDenied);
}
root_dir().unlink(&path.to_rel())
}

/// Check if a directory is a mount point.
pub fn is_mount_point(path: &AbsPath) -> bool {
root_dir().contains(path)
}

/// Rename a file given an old and a new absolute path.
///
/// This function will not check if the old path or new path exists, check it with
Expand Down
2 changes: 1 addition & 1 deletion modules/ruxfs/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl RootDirectory {
idx = i;
}
}
return (idx, max_len);
(idx, max_len)
}

/// Check if path matches a mountpoint, dispatch the operation to the matched filesystem
Expand Down
Loading