mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-25 10:48:41 +00:00
Kernel: Add DirectoryEntryView for VFS directory traversal
Unlike DirectoryEntry (which is used when constructing directories), DirectoryEntryView does not manage storage for file names. Names are just StringViews. This is much more suited to the directory traversal API and makes it easier to implement this in file system classes since they no longer need to create temporary name copies while traversing.
This commit is contained in:
@@ -191,9 +191,9 @@ bool VFS::is_vfs_root(InodeIdentifier inode) const
|
||||
return inode == root_inode_id();
|
||||
}
|
||||
|
||||
KResult VFS::traverse_directory_inode(Inode& dir_inode, Function<bool(const FS::DirectoryEntry&)> callback)
|
||||
KResult VFS::traverse_directory_inode(Inode& dir_inode, Function<bool(const FS::DirectoryEntryView&)> callback)
|
||||
{
|
||||
return dir_inode.traverse_as_directory([&](const FS::DirectoryEntry& entry) {
|
||||
return dir_inode.traverse_as_directory([&](auto& entry) {
|
||||
InodeIdentifier resolved_inode;
|
||||
if (auto mount = find_mount_for_host(entry.inode))
|
||||
resolved_inode = mount->guest().identifier();
|
||||
@@ -202,13 +202,13 @@ KResult VFS::traverse_directory_inode(Inode& dir_inode, Function<bool(const FS::
|
||||
|
||||
// FIXME: This is now broken considering chroot and bind mounts.
|
||||
bool is_root_inode = dir_inode.identifier() == dir_inode.fs().root_inode()->identifier();
|
||||
if (is_root_inode && !is_vfs_root(dir_inode.identifier()) && !strcmp(entry.name, "..")) {
|
||||
if (is_root_inode && !is_vfs_root(dir_inode.identifier()) && entry.name == "..") {
|
||||
auto mount = find_mount_for_guest(dir_inode);
|
||||
ASSERT(mount);
|
||||
ASSERT(mount->host());
|
||||
resolved_inode = mount->host()->identifier();
|
||||
}
|
||||
callback(FS::DirectoryEntry(entry.name, entry.name_length, resolved_inode, entry.file_type));
|
||||
callback({ entry.name, resolved_inode, entry.file_type });
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user