mirror of
https://github.com/SerenityOS/serenity
synced 2026-04-26 01:25:22 +02:00
Kernel/VFS: Make filesystem implementations responsible for renames
Previously, the VFS layer would try to handle renames more-or-less by itself, which really only worked for ext2, and even that was only due to the replace_child kludge existing specifically for this purpose. This never worked properly for FATFS, since the VFS layer effectively depended on filesystems having some kind of reference-counting for inodes, which is something that simply doesn't exist on any FAT variant we support. To resolve various issues with the existing scheme, this commit makes filesystem implementations themselves responsible for the actual rename operation, while keeping all the existing validation inside the VFS layer. The only intended behavior change here is that rename operations should actually properly work on FATFS.
This commit is contained in:
committed by
Nico Weber
parent
666ba3b970
commit
0e94887b2c
@@ -812,18 +812,9 @@ ErrorOr<void> VirtualFileSystem::rename(VFSRootContext const& vfs_root_context,
|
||||
}
|
||||
if (new_inode.is_directory() && !old_inode.is_directory())
|
||||
return EISDIR;
|
||||
TRY(new_parent_inode.remove_child(new_basename));
|
||||
}
|
||||
|
||||
TRY(new_parent_inode.add_child(old_inode, new_basename, old_inode.mode()));
|
||||
TRY(old_parent_inode.remove_child(old_basename));
|
||||
|
||||
// If the inode that we moved is a directory and we changed parent
|
||||
// directories, then we also have to make .. point to the new parent inode,
|
||||
// because .. is its own inode.
|
||||
if (old_inode.is_directory() && old_parent_inode.index() != new_parent_inode.index()) {
|
||||
TRY(old_inode.replace_child(".."sv, new_parent_inode));
|
||||
}
|
||||
TRY(new_parent_inode.fs().rename(old_parent_inode, old_basename, new_parent_inode, new_basename));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user