Skip to content

Commit

Permalink
[feat] Wrap cwd with axresourece to share between thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Azure-stars committed Oct 23, 2024
1 parent f5e485b commit cf8361d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
6 changes: 1 addition & 5 deletions api/arceos_posix_api/src/imp/fd_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
3 changes: 3 additions & 0 deletions modules/axfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
13 changes: 9 additions & 4 deletions modules/axfs/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = Mutex::new(String::new());
static CURRENT_DIR: LazyInit<Mutex<VfsNodeRef>> = LazyInit::new();
def_resource! {
#[allow(non_camel_case_types)]
static CURRENT_DIR_PATH: AxResource<Mutex<String>> = AxResource::new();
#[allow(non_camel_case_types)]
static CURRENT_DIR: AxResource<Mutex<VfsNodeRef>> = AxResource::new();
}

struct MountPoint {
path: &'static str,
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions modules/axns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
}
}
Expand Down

0 comments on commit cf8361d

Please sign in to comment.