Skip to content

Commit 6320d6b

Browse files
committed
rename
1 parent 779ee3f commit 6320d6b

File tree

8 files changed

+31
-6
lines changed

8 files changed

+31
-6
lines changed

arceos/axfs_ramfs/src/dir.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl DirNode {
4646
log::error!("AlreadyExists {}", name);
4747
return Err(VfsError::AlreadyExists);
4848
}
49+
log::debug!("Creating node {:?} {}", ty, name);
4950
let node: VfsNodeRef = match ty {
5051
VfsNodeType::File => Arc::new(FileNode::new()),
5152
VfsNodeType::Dir => Self::new(Some(self.this.clone())),
@@ -67,6 +68,22 @@ impl DirNode {
6768
children.remove(name);
6869
Ok(())
6970
}
71+
pub fn rename_node(&self, old_name: &str, new_name: &str) -> VfsResult {
72+
let mut children = self.children.write();
73+
74+
// 从/tmp/f1取出f1
75+
let old_name = old_name.split('/').last().unwrap();
76+
let new_name = new_name.split('/').last().unwrap();
77+
if !children.contains_key(old_name) {
78+
return Err(VfsError::NotFound);
79+
}
80+
if children.contains_key(new_name) {
81+
return Err(VfsError::AlreadyExists);
82+
}
83+
let node = children.remove(old_name).unwrap();
84+
children.insert(new_name.into(), node);
85+
Ok(())
86+
}
7087
}
7188

7289
impl VfsNodeOps for DirNode {
@@ -164,8 +181,11 @@ impl VfsNodeOps for DirNode {
164181
self.remove_node(name)
165182
}
166183
}
167-
168-
axfs_vfs::impl_vfs_dir_default! {}
184+
// axfs_vfs::impl_vfs_dir_default! {}
185+
fn rename(&self, src_path: &str, dst_path: &str) -> VfsResult {
186+
self.rename_node(src_path, dst_path)
187+
}
188+
169189
}
170190

171191
fn split_path(path: &str) -> (&str, Option<&str>) {

arceos/axfs_ramfs/src/file.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,5 @@ impl VfsNodeOps for FileNode {
5151
dst.copy_from_slice(&buf[..dst.len()]);
5252
Ok(buf.len())
5353
}
54-
5554
impl_vfs_non_dir_default! {}
5655
}

arceos/modules/axfs/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ homepage.workspace = true
99
repository = "https://github.com/arceos-org/arceos/tree/main/modules/axfs"
1010
documentation = "https://arceos-org.github.io/arceos/axfs/index.html"
1111

12+
[patch.crates-io]
13+
axfs_ramfs = {path = "../../axfs_ramfs"}
14+
1215
[features]
1316
devfs = ["dep:axfs_devfs"]
1417
ramfs = ["dep:axfs_ramfs"]
@@ -29,12 +32,14 @@ axio = { version = "0.1", features = ["alloc"] }
2932
axerrno = "0.1"
3033
axfs_vfs = "0.1"
3134
axfs_devfs = { version = "0.1", optional = true }
32-
axfs_ramfs = { version = "0.1", optional = true }
35+
axfs_ramfs = { path = "../../axfs_ramfs", optional = true }
3336
crate_interface = { version = "0.1", optional = true }
3437
axsync = { workspace = true }
3538
axdriver = { workspace = true, features = ["block"] }
3639
axdriver_block = { git = "https://github.com/arceos-org/axdriver_crates.git", tag = "v0.1.0" }
3740

41+
42+
3843
[dependencies.fatfs]
3944
git = "https://github.com/rafalh/rust-fatfs"
4045
rev = "85f06e0"

arceos/modules/axfs/src/api/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,6 @@ pub fn remove_file(path: &str) -> io::Result<()> {
8585
///
8686
/// This only works then the new path is in the same mounted fs.
8787
pub fn rename(old: &str, new: &str) -> io::Result<()> {
88+
log::debug!("******************************fs::rename from {} to {}", old, new);
8889
crate::root::rename(old, new)
8990
}

arceos/modules/axfs/src/root.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,6 @@ pub(crate) fn rename(old: &str, new: &str) -> AxResult {
306306
warn!("dst file already exist, now remove it");
307307
remove_file(None, new)?;
308308
}
309+
log::debug!("rename from {} to {}", old, new);
309310
parent_node_of(None, old).rename(old, new)
310311
}

course/.~lock.stage3-2.pptx#

Lines changed: 0 additions & 1 deletion
This file was deleted.

course/.~lock.stage3-3.pptx#

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
,zjt,zjt-Legion-R9000P-ARX8,06.11.2025 18:46,file:///home/zjt/.config/libreoffice/4;

test.output

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
test-ramfs_rename failed
21
test-sys_map failed
32
test-simple_hv failed

0 commit comments

Comments
 (0)