diff --git a/api/arceos_posix_api/src/imp/fd_ops.rs b/api/arceos_posix_api/src/imp/fd_ops.rs index 45175af427..2d20a74989 100644 --- a/api/arceos_posix_api/src/imp/fd_ops.rs +++ b/api/arceos_posix_api/src/imp/fd_ops.rs @@ -29,11 +29,7 @@ def_resource! { fd_table.add_at(0, Arc::new(stdin()) as _).unwrap(); // stdin fd_table.add_at(1, Arc::new(stdout()) as _).unwrap(); // stdout fd_table.add_at(2, Arc::new(stdout()) as _).unwrap(); // stderr - axlog::info!("fd_table initialized"); - unsafe{ - FD_TABLE.deref_auto_force().init_new(RwLock::new(fd_table)); - } - axlog::info!("fd_table initialized"); + FD_TABLE.deref_auto_force().init_new(RwLock::new(fd_table)); } } diff --git a/modules/axfs/Cargo.toml b/modules/axfs/Cargo.toml index d1562fa93e..9f6c425fc9 100644 --- a/modules/axfs/Cargo.toml +++ b/modules/axfs/Cargo.toml @@ -25,6 +25,7 @@ log = "0.4.21" cfg-if = "1.0" lazyinit = "0.2" cap_access = "0.1" +spin = "0.9" axio = { version = "0.1", features = ["alloc"] } axerrno = "0.1" axfs_vfs = "0.1" @@ -34,6 +35,8 @@ crate_interface = { version = "0.1", optional = true } axsync = { workspace = true } axdriver = { workspace = true, features = ["block"] } axdriver_block = { git = "https://github.com/arceos-org/axdriver_crates.git", tag = "v0.1.0" } +axns = { workspace = true } +axlog = { workspace = true } [dependencies.fatfs] git = "https://github.com/rafalh/rust-fatfs" diff --git a/modules/axfs/src/root.rs b/modules/axfs/src/root.rs index c1ddcd018a..afc58ade28 100644 --- a/modules/axfs/src/root.rs +++ b/modules/axfs/src/root.rs @@ -5,13 +5,18 @@ use alloc::{string::String, sync::Arc, vec::Vec}; use axerrno::{ax_err, AxError, AxResult}; use axfs_vfs::{VfsNodeAttr, VfsNodeOps, VfsNodeRef, VfsNodeType, VfsOps, VfsResult}; +use axns::{def_resource, AxResource}; use axsync::Mutex; use lazyinit::LazyInit; use crate::{api::FileType, fs, mounts}; -static CURRENT_DIR_PATH: Mutex = Mutex::new(String::new()); -static CURRENT_DIR: LazyInit> = LazyInit::new(); +def_resource! { + #[allow(non_camel_case_types)] + static CURRENT_DIR_PATH: AxResource> = AxResource::new(); + #[allow(non_camel_case_types)] + static CURRENT_DIR: AxResource> = AxResource::new(); +} struct MountPoint { path: &'static str, @@ -180,8 +185,8 @@ pub(crate) fn init_rootfs(disk: crate::dev::Disk) { .expect("fail to mount sysfs at /sys"); ROOT_DIR.init_once(Arc::new(root_dir)); - CURRENT_DIR.init_once(Mutex::new(ROOT_DIR.clone())); - *CURRENT_DIR_PATH.lock() = "/".into(); + CURRENT_DIR.init_new(Mutex::new(ROOT_DIR.clone())); + CURRENT_DIR_PATH.init_new(Mutex::new("/".into())); } fn parent_node_of(dir: Option<&VfsNodeRef>, path: &str) -> VfsNodeRef { diff --git a/modules/axns/src/lib.rs b/modules/axns/src/lib.rs index e2d5953178..76bb0dd0ad 100644 --- a/modules/axns/src/lib.rs +++ b/modules/axns/src/lib.rs @@ -272,10 +272,9 @@ macro_rules! def_resource { /// Dereference the resource from the global namespace, without /// checking if it is initialized. /// - /// # Safety - /// + /// # Notes /// The caller must ensure the resource has been initialized. - pub unsafe fn deref_auto_force(&self) -> &$ty { + pub fn deref_auto_force(&self) -> &$ty { unsafe { self.deref_from_base($crate::current_namespace_base()) } } }