Skip to content
Merged
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
feat: rmdir mkdirat unlink unlinkat api
  • Loading branch information
liujingx committed Feb 19, 2025
commit ff00a8b08f99ab61c5d8858d014a3ab730c5b877
103 changes: 94 additions & 9 deletions api/ruxos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* See the Mulan PSL v2 for more details.
*/

use alloc::{sync::Arc, string::ToString};
use core::ffi::{c_char, c_int, c_long, c_void, CStr};
use alloc::{string::ToString, sync::Arc};
use core::{ffi::{c_char, c_int, c_long, c_void, CStr}, str};

use axerrno::{LinuxError, LinuxResult};
use axio::{Error, PollState, SeekFrom};
Expand Down Expand Up @@ -464,7 +464,29 @@ pub fn sys_rmdir(pathname: *const c_char) -> c_int {
syscall_body!(sys_rmdir, {
let path = char_ptr_to_path(pathname)?;
debug!("sys_rmdir <= path: {:?}", path);
fops::remove_dir(&path.to_abs())?;
match fops::lookup(&path.to_abs()) {
Ok(node) => {
let attr = node.get_attr()?;
if !attr.is_dir() {
return Err(LinuxError::ENOTDIR);
}
if !attr.perm().owner_writable() {
return Err(LinuxError::EPERM);
}
let mut buf = [
DirEntry::default(),
DirEntry::default(),
DirEntry::default(),
];
if let Ok(n) = node.read_dir(0, &mut buf) {
if n > 2 {
return Err(LinuxError::ENOTEMPTY);
}
}
fops::remove_dir(&path.to_abs())?;
}
Err(e) => return Err(e.into()),
}
Ok(0)
})
}
Expand All @@ -474,7 +496,19 @@ pub fn sys_unlink(pathname: *const c_char) -> c_int {
syscall_body!(sys_unlink, {
let path = char_ptr_to_path(pathname)?;
debug!("sys_unlink <= path: {:?}", path);
fops::remove_file(&path.to_abs())?;
match fops::lookup(&path.to_abs()) {
Ok(node) => {
let attr = node.get_attr()?;
if attr.is_dir() {
return Err(LinuxError::EISDIR);
}
if !attr.perm().owner_writable() {
return Err(LinuxError::EPERM);
}
fops::remove_file(&path.to_abs())?;
}
Err(e) => return Err(e.into()),
}
Ok(0)
})
}
Expand All @@ -490,7 +524,36 @@ pub fn sys_unlinkat(fd: c_int, pathname: *const c_char, flags: c_int) -> c_int {
if flags as u32 & ctypes::AT_REMOVEDIR != 0 {
return sys_rmdir(pathname);
}
sys_unlink(pathname)
syscall_body!(sys_unlinkat, {
let path = char_ptr_to_path(pathname)?;
let absolute = matches!(path, Path::Absolute(_)) || fd == ctypes::AT_FDCWD;
let node = if absolute {
fops::lookup(&path.to_abs())
} else {
Directory::from_fd(fd)?.inner.lock().lookup(&path.to_rel())
};
match node {
Ok(node) => {
let attr = node.get_attr()?;
if attr.is_dir() {
return Err(LinuxError::EISDIR);
}
if !attr.perm().owner_writable() {
return Err(LinuxError::EPERM);
}
if absolute {
fops::remove_file(&path.to_abs())?;
} else {
Directory::from_fd(fd)?
.inner
.lock()
.remove(&path.to_rel())?;
}
}
Err(e) => return Err(e.into()),
}
Ok(0)
})
}

/// Creates a new, empty directory at the provided path.
Expand All @@ -510,16 +573,37 @@ pub fn sys_mkdir(pathname: *const c_char, mode: ctypes::mode_t) -> c_int {
}

/// attempts to create a directory named pathname under directory pointed by `fd`
///
/// TODO: currently fd is not used
pub fn sys_mkdirat(fd: c_int, pathname: *const c_char, mode: ctypes::mode_t) -> c_int {
debug!(
"sys_mkdirat <= fd: {}, pathname: {:?}, mode: {:x?}",
fd,
char_ptr_to_path(pathname),
mode
);
sys_mkdir(pathname, mode)
syscall_body!(sys_mkdirat, {
let path = char_ptr_to_path(pathname)?;
let absolute = matches!(path, Path::Absolute(_)) || fd == ctypes::AT_FDCWD;
let node = if absolute {
fops::lookup(&path.to_abs())
} else {
Directory::from_fd(fd)?.inner.lock().lookup(&path.to_rel())
};
match node {
Ok(_) => return Err(LinuxError::EEXIST),
Err(Error::NotFound) => {
if absolute {
fops::create_dir(&path.to_abs())?;
} else {
Directory::from_fd(fd)?
.inner
.lock()
.create_dir(&path.to_rel())?;
}
}
Err(e) => return Err(e.into()),
}
Ok(0)
})
}

/// Changes the ownership of the file referred to by the open file descriptor fd
Expand Down Expand Up @@ -586,8 +670,9 @@ pub unsafe fn sys_getdents64(fd: c_int, dirp: *mut LinuxDirent64, count: ctypes:
let mut entry = [DirEntry::default()];
let offset = dir.inner.lock().entry_idx();
let n = dir.inner.lock().read_dir(&mut entry)?;
debug!("entry {:?}", str::from_utf8(entry[0].name_as_bytes()).unwrap());
if n == 0 {
return Ok(0);
return Ok(written as isize);
}
let entry = &entry[0];

Expand Down