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
style: ruxos_posix_api fs syscalls
  • Loading branch information
liujingx committed Feb 20, 2025
commit 3e55f9e04a5ad115a64634a17ff5997815594730
23 changes: 11 additions & 12 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`].
pub fn flags_to_options(flags: c_int, _mode: ctypes::mode_t) -> OpenOptions {
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 @@ -77,18 +77,17 @@ pub fn sys_open(filename: *const c_char, flags: c_int, mode: ctypes::mode_t) ->
syscall_body!(sys_open, {
let path = parse_path(filename)?;
let opts = flags_to_options(flags, mode);
let flags = flags as u32;
debug!("sys_open <= {:?} {:#o} {:#o}", path, flags, mode);
// Check flag and attr
let node = match fops::lookup(&path) {
Ok(node) => {
if flags & ctypes::O_EXCL != 0 {
if opts.create_new {
return Err(LinuxError::EEXIST);
}
node
}
Err(Error::NotFound) => {
if !(flags & ctypes::O_CREAT != 0) {
if !opts.create {
return Err(LinuxError::ENOENT);
}
fops::create_file(&path)?;
Expand All @@ -100,7 +99,7 @@ pub fn sys_open(filename: *const c_char, flags: c_int, mode: ctypes::mode_t) ->
return Err(LinuxError::EISDIR);
}
// Truncate
if flags & ctypes::O_TRUNC != 0 {
if opts.truncate {
node.truncate(0)?;
}
// Open
Expand All @@ -114,7 +113,8 @@ pub fn sys_openat(fd: c_int, path: *const c_char, flags: c_int, mode: ctypes::mo
syscall_body!(sys_openat, {
let path = parse_path_at(fd, path)?;
let opts = flags_to_options(flags, mode);
let flags = flags as u32;
let open_dir = flags as u32 & ctypes::O_DIRECTORY != 0;
let searchable = flags as u32 & ctypes::O_SEARCH != 0;
debug!(
"sys_openat <= {}, {:?}, {:#o}, {:#o}",
fd, path, flags, mode
Expand All @@ -124,23 +124,22 @@ pub fn sys_openat(fd: c_int, path: *const c_char, flags: c_int, mode: ctypes::mo
Ok(node) => {
let attr = node.get_attr()?;
// Node exists but O_EXCL is set
if flags & ctypes::O_EXCL != 0 {
debug!("exist {} {}", flags, ctypes::O_EXCL);
if opts.create_new {
return Err(LinuxError::EEXIST);
}
// Node is not a directory but O_DIRECTORY is set
if !attr.is_dir() && (flags & ctypes::O_DIRECTORY != 0) {
if !attr.is_dir() && open_dir {
return Err(LinuxError::ENOTDIR);
}
// Truncate
if attr.is_file() && (flags & ctypes::O_TRUNC != 0) {
if attr.is_file() && opts.truncate {
node.truncate(0)?;
}
node
}
Err(Error::NotFound) => {
// O_CREAT is not set or O_DIRECTORY is set
if (flags & ctypes::O_DIRECTORY != 0) || (flags & ctypes::O_CREAT == 0) {
if open_dir || !opts.create {
return Err(LinuxError::ENOENT);
}
// Create file
Expand All @@ -152,7 +151,7 @@ pub fn sys_openat(fd: c_int, path: *const c_char, flags: c_int, mode: ctypes::mo
// Open file or directory
if node.get_attr()?.is_dir() {
let dir = fops::open_dir(&path, node, &opts)?;
Directory::new(dir, flags & ctypes::O_SEARCH != 0).add_to_fd_table(opts)
Directory::new(dir, searchable).add_to_fd_table(opts)
} else {
let file = fops::open_file(&path, node, &opts)?;
File::new(file).add_to_fd_table(opts)
Expand Down
19 changes: 14 additions & 5 deletions modules/ruxfs/src/fops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* See the Mulan PSL v2 for more details.
*/

//! Low-level filesystem operations. Provided for [ruxfs::api] and [ruxos_posix_api::fs] modules.
//! Low-level filesystem operations. Provided for [`ruxfs::api`] and [`ruxos_posix_api::fs`] modules.
//!
//! - File: open, read, write, seek, truncate
//! - Directory: open, read, create, remove
Expand Down Expand Up @@ -37,6 +37,8 @@ pub type FileAttr = axfs_vfs::VfsNodeAttr;
pub type FilePerm = axfs_vfs::VfsNodePerm;

/// An opened file object, with open permissions and a cursor.
///
/// Providing basic file operations.
pub struct File {
path: AbsPath<'static>,
node: WithCap<VfsNodeRef>,
Expand Down Expand Up @@ -137,6 +139,8 @@ impl Drop for File {
}

/// An opened directory object, with open permissions and a cursor for entry reading.
///
/// Providing entry reading operations.
pub struct Directory {
path: AbsPath<'static>,
node: WithCap<VfsNodeRef>,
Expand Down Expand Up @@ -325,7 +329,7 @@ pub(crate) fn root_dir() -> Arc<RootDirectory> {
crate_interface::call_interface!(CurrentWorkingDirectoryOps::root_dir)
}

// File operations with absolute path.
/* File operations with absolute path. */

/// Look up a file given an absolute path.
pub fn lookup(path: &AbsPath) -> AxResult<VfsNodeRef> {
Expand Down Expand Up @@ -354,12 +358,17 @@ pub fn open_dir(path: &AbsPath, node: VfsNodeRef, opt: &OpenOptions) -> AxResult
return ax_err!(PermissionDenied);
}
node.open()?;
Ok(Directory::new(path.to_owned(), node, opt.to_cap() | Cap::EXECUTE))
Ok(Directory::new(
path.to_owned(),
node,
opt.to_cap() | Cap::EXECUTE,
))
}

/// Lookup and open a file at an arbitrary path.
///
///
/// If `path` is relative, it will be resolved against the current working directory.
/// If `path` is absolute, it will be used as is.
pub fn open(path: &str, opt: &OpenOptions) -> AxResult<File> {
let path = absolute_path(path)?;
let node = lookup(&path)?;
Expand Down Expand Up @@ -414,7 +423,7 @@ pub fn rename(old: &AbsPath, new: &AbsPath) -> AxResult {
root_dir().rename(&old.to_rel(), &new.to_rel())
}

pub fn perm_to_cap(perm: FilePerm) -> Cap {
fn perm_to_cap(perm: FilePerm) -> Cap {
let mut cap = Cap::empty();
if perm.owner_readable() {
cap |= Cap::READ;
Expand Down
4 changes: 3 additions & 1 deletion modules/ruxfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@
extern crate log;
extern crate alloc;

mod dev;
mod fs;
mod mounts;

#[cfg(feature = "blkfs")]
mod dev;
#[cfg(feature = "alloc")]
mod arch;

pub mod api;
pub mod fops;
pub mod root;

// Re-export `axfs_vfs` path types.
pub type AbsPath<'a> = axfs_vfs::AbsPath<'a>;
pub type RelPath<'a> = axfs_vfs::RelPath<'a>;

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 @@ -7,7 +7,7 @@
* See the Mulan PSL v2 for more details.
*/

//! Root directory of the filesystem. Filesystem operations are distributed to the
//! Root directory of the filesystem, where filesystem operations are distributed to the
//! appropriate filesystem based on the mount points.
//!
//! `RootDirectory::lookup_mounted_fs()` performs the distribution of operations.
Expand Down