Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复了ramfs中move_to的bug #673

Merged
merged 8 commits into from
Mar 31, 2024
Merged
27 changes: 21 additions & 6 deletions kernel/src/filesystem/ramfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use crate::{
driver::base::device::device_number::DeviceNumber,
filesystem::vfs::{core::generate_inode_id, FileType},
ipc::pipe::LockedPipeInode,
libs::casting::DowncastArc,
libs::spinlock::{SpinLock, SpinLockGuard},
time::TimeSpec,
};

use alloc::{
collections::BTreeMap,
string::String,
Expand Down Expand Up @@ -143,7 +145,6 @@ impl RamFS {
return Ok(fs);
}
}

#[distributed_slice(FSMAKER)]
static RAMFSMAKER: FileSystemMaker = FileSystemMaker::new(
"ramfs",
Expand Down Expand Up @@ -410,16 +411,30 @@ impl IndexNode for LockedRamFSInode {
target: &Arc<dyn IndexNode>,
new_name: &str,
) -> Result<(), SystemError> {
let old_inode: Arc<dyn IndexNode> = self.find(old_name)?;
let inode: Arc<dyn IndexNode> = self.find(old_name)?;
// 修改其对父节点的引用
inode
.downcast_ref::<LockedRamFSInode>()
.ok_or(SystemError::EPERM)?
.0
.lock()
.parent = Arc::downgrade(
&target
.clone()
.downcast_arc::<LockedRamFSInode>()
.ok_or(SystemError::EPERM)?,
);

// 在新的目录下创建一个硬链接
target.link(new_name, &old_inode)?;
target.link(new_name, &inode)?;

// 取消现有的目录下的这个硬链接
if let Err(err) = self.unlink(old_name) {
// 如果取消失败,那就取消新的目录下的硬链接
if let Err(e) = self.unlink(old_name) {
// 当操作失败时回退操作
target.unlink(new_name)?;
return Err(err);
return Err(e);
}

return Ok(());
}

Expand Down
Loading