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
feat: add inode number in vfsattr
  • Loading branch information
liujingx committed Feb 19, 2025
commit c392accc4ed4cd906153d3a9f76f844a949734e0
20 changes: 17 additions & 3 deletions crates/axfs_devfs/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,30 @@ use axfs_vfs::{RelPath, VfsDirEntry, VfsNodeAttr, VfsNodeOps, VfsNodeRef, VfsNod
use axfs_vfs::{VfsError, VfsResult};
use spin::RwLock;

use crate::InoAllocator;

/// The directory node in the device filesystem.
///
/// It implements [`axfs_vfs::VfsNodeOps`].
pub struct DirNode {
ino: u64,
parent: RwLock<Weak<dyn VfsNodeOps>>,
children: RwLock<BTreeMap<&'static str, VfsNodeRef>>,
ialloc: Weak<InoAllocator>,
}

impl DirNode {
pub(super) fn new(parent: Option<&VfsNodeRef>) -> Arc<Self> {
pub(super) fn new(
ino: u64,
parent: Option<&VfsNodeRef>,
ialloc: Weak<InoAllocator>,
) -> Arc<Self> {
let parent = parent.map_or(Weak::<Self>::new() as _, Arc::downgrade);
Arc::new(Self {
ino,
parent: RwLock::new(parent),
children: RwLock::new(BTreeMap::new()),
ialloc,
})
}

Expand All @@ -37,7 +47,11 @@ impl DirNode {
/// Create a subdirectory at this directory.
pub fn mkdir(self: &Arc<Self>, name: &'static str) -> Arc<Self> {
let parent = self.clone() as VfsNodeRef;
let node = Self::new(Some(&parent));
let node = Self::new(
self.ialloc.upgrade().unwrap().alloc(),
Some(&parent),
self.ialloc.clone(),
);
self.children.write().insert(name, node.clone());
node
}
Expand All @@ -50,7 +64,7 @@ impl DirNode {

impl VfsNodeOps for DirNode {
fn get_attr(&self) -> VfsResult<VfsNodeAttr> {
Ok(VfsNodeAttr::new_dir(4096, 0))
Ok(VfsNodeAttr::new_dir(self.ino, 4096, 0))
}

fn parent(&self) -> Option<VfsNodeRef> {
Expand Down
26 changes: 25 additions & 1 deletion crates/axfs_devfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,44 @@ pub use self::zero::ZeroDev;

use alloc::sync::Arc;
use axfs_vfs::{AbsPath, VfsNodeRef, VfsOps, VfsResult};
use core::sync::atomic::AtomicU64;
use spin::once::Once;

/// An auto-increasing inode number allocator.
pub struct InoAllocator {
current: AtomicU64,
}

impl InoAllocator {
/// Create a new allocator instance.
pub fn new(start: u64) -> Self {
Self {
current: AtomicU64::new(start),
}
}

/// Allocate a new inode number.
pub fn alloc(&self) -> u64 {
self.current
.fetch_add(1, core::sync::atomic::Ordering::SeqCst)
}
}

/// A device filesystem that implements [`axfs_vfs::VfsOps`].
pub struct DeviceFileSystem {
parent: Once<VfsNodeRef>,
root: Arc<DirNode>,
_ialloc: Arc<InoAllocator>,
}

impl DeviceFileSystem {
/// Create a new instance.
pub fn new() -> Self {
let ialloc = Arc::new(InoAllocator::new(10));
Self {
parent: Once::new(),
root: DirNode::new(None),
root: DirNode::new(2, None, Arc::downgrade(&ialloc)),
_ialloc: ialloc,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/axfs_devfs/src/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct NullDev;
impl VfsNodeOps for NullDev {
fn get_attr(&self) -> VfsResult<VfsNodeAttr> {
Ok(VfsNodeAttr::new(
3,
VfsNodePerm::default_file(),
VfsNodeType::CharDevice,
0,
Expand Down
1 change: 1 addition & 0 deletions crates/axfs_devfs/src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn rand_lcg32() -> u32 {
impl VfsNodeOps for RandomDev {
fn get_attr(&self) -> VfsResult<VfsNodeAttr> {
Ok(VfsNodeAttr::new(
6,
VfsNodePerm::default_file(),
VfsNodeType::CharDevice,
0,
Expand Down
1 change: 1 addition & 0 deletions crates/axfs_devfs/src/zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct ZeroDev;
impl VfsNodeOps for ZeroDev {
fn get_attr(&self) -> VfsResult<VfsNodeAttr> {
Ok(VfsNodeAttr::new(
4,
VfsNodePerm::default_file(),
VfsNodeType::CharDevice,
0,
Expand Down
21 changes: 17 additions & 4 deletions crates/axfs_ramfs/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,31 @@ use axfs_vfs::{VfsError, VfsResult};
use spin::rwlock::RwLock;

use crate::file::FileNode;
use crate::InoAllocator;

/// The directory node in the RAM filesystem.
///
/// It implements [`axfs_vfs::VfsNodeOps`].
pub struct DirNode {
ino: u64,
this: Weak<DirNode>,
parent: RwLock<Weak<dyn VfsNodeOps>>,
children: RwLock<BTreeMap<String, VfsNodeRef>>,
ialloc: Weak<InoAllocator>,
}

impl DirNode {
pub(super) fn new(parent: Option<Weak<dyn VfsNodeOps>>) -> Arc<Self> {
pub(super) fn new(
ino: u64,
parent: Option<Weak<dyn VfsNodeOps>>,
ialloc: Weak<InoAllocator>,
) -> Arc<Self> {
Arc::new_cyclic(|this| Self {
ino,
this: this.clone(),
parent: RwLock::new(parent.unwrap_or_else(|| Weak::<Self>::new())),
children: RwLock::new(BTreeMap::new()),
ialloc,
})
}

Expand All @@ -56,8 +65,12 @@ impl DirNode {
return Err(VfsError::AlreadyExists);
}
let node: VfsNodeRef = match ty {
VfsNodeType::File => Arc::new(FileNode::new()),
VfsNodeType::Dir => Self::new(Some(self.this.clone())),
VfsNodeType::File => Arc::new(FileNode::new(self.ialloc.upgrade().unwrap().alloc())),
VfsNodeType::Dir => Self::new(
self.ialloc.upgrade().unwrap().alloc(),
Some(self.this.clone()),
self.ialloc.clone(),
),
_ => return Err(VfsError::Unsupported),
};
self.children.write().insert(name.into(), node);
Expand All @@ -80,7 +93,7 @@ impl DirNode {

impl VfsNodeOps for DirNode {
fn get_attr(&self) -> VfsResult<VfsNodeAttr> {
Ok(VfsNodeAttr::new_dir(4096, 0))
Ok(VfsNodeAttr::new_dir(self.ino, 4096, 0))
}

fn parent(&self) -> Option<VfsNodeRef> {
Expand Down
10 changes: 8 additions & 2 deletions crates/axfs_ramfs/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ use spin::rwlock::RwLock;
///
/// It implements [`axfs_vfs::VfsNodeOps`].
pub struct FileNode {
ino: u64,
content: RwLock<Vec<u8>>,
}

impl FileNode {
pub(super) const fn new() -> Self {
pub(super) const fn new(ino: u64) -> Self {
Self {
ino,
content: RwLock::new(Vec::new()),
}
}
}

impl VfsNodeOps for FileNode {
fn get_attr(&self) -> VfsResult<VfsNodeAttr> {
Ok(VfsNodeAttr::new_file(self.content.read().len() as _, 0))
Ok(VfsNodeAttr::new_file(
self.ino,
self.content.read().len() as _,
0,
))
}

fn truncate(&self, size: u64) -> VfsResult {
Expand Down
26 changes: 25 additions & 1 deletion crates/axfs_ramfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,44 @@ pub use self::file::FileNode;

use alloc::sync::Arc;
use axfs_vfs::{AbsPath, VfsNodeRef, VfsOps, VfsResult};
use core::sync::atomic::AtomicU64;
use spin::once::Once;

/// An auto-increasing inode number allocator.
pub struct InoAllocator {
current: AtomicU64,
}

impl InoAllocator {
/// Create a new allocator instance.
pub fn new(start: u64) -> Self {
Self {
current: AtomicU64::new(start),
}
}

/// Allocate a new inode number.
pub fn alloc(&self) -> u64 {
self.current
.fetch_add(1, core::sync::atomic::Ordering::SeqCst)
}
}

/// A RAM filesystem that implements [`axfs_vfs::VfsOps`].
pub struct RamFileSystem {
parent: Once<VfsNodeRef>,
root: Arc<DirNode>,
_ialloc: Arc<InoAllocator>,
}

impl RamFileSystem {
/// Create a new instance.
pub fn new() -> Self {
let ialloc = Arc::new(InoAllocator::new(0));
Self {
parent: Once::new(),
root: DirNode::new(None),
root: DirNode::new(ialloc.alloc(), None, Arc::downgrade(&ialloc)),
_ialloc: ialloc,
}
}

Expand Down
20 changes: 14 additions & 6 deletions crates/axfs_vfs/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct FileSystemInfo;
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub struct VfsNodeAttr {
/// Inode number.
ino: u64,
/// File permission mode.
mode: VfsNodePerm,
/// File type.
Expand Down Expand Up @@ -206,11 +208,11 @@ impl VfsNodeType {
}

impl VfsNodeAttr {
/// Creates a new `VfsNodeAttr` with the given permission mode, type, size
/// inode number and number of blocks.
/// if node number is none, means fs do not have inode then vfs will allocate it
pub fn new(mode: VfsNodePerm, ty: VfsNodeType, size: u64, blocks: u64) -> Self {
/// Creates a new `VfsNodeAttr` with the given inode number, permission mode, type, size
/// and number of blocks.
pub const fn new(ino: u64, mode: VfsNodePerm, ty: VfsNodeType, size: u64, blocks: u64) -> Self {
Self {
ino,
mode,
ty,
size,
Expand All @@ -219,8 +221,9 @@ impl VfsNodeAttr {
}

/// Creates a new `VfsNodeAttr` for a file, with the default file permission.
pub fn new_file(size: u64, blocks: u64) -> Self {
pub const fn new_file(ino: u64, size: u64, blocks: u64) -> Self {
Self {
ino,
mode: VfsNodePerm::default_file(),
ty: VfsNodeType::File,
size,
Expand All @@ -230,15 +233,20 @@ impl VfsNodeAttr {

/// Creates a new `VfsNodeAttr` for a directory, with the default directory
/// permission.
pub fn new_dir(size: u64, blocks: u64) -> Self {
pub const fn new_dir(ino: u64, size: u64, blocks: u64) -> Self {
Self {
ino,
mode: VfsNodePerm::default_dir(),
ty: VfsNodeType::Dir,
size,
blocks,
}
}

/// Returns the inode number of the node.
pub const fn ino(&self) -> u64 {
self.ino
}
/// Returns the size of the node.
pub const fn size(&self) -> u64 {
self.size
Expand Down