mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 15:54:58 +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:
parent
8abf5048b8
commit
eeaba41d13
16 changed files with 61 additions and 53 deletions
|
@ -798,7 +798,7 @@ void Plan9FSInode::flush_metadata()
|
|||
KResultOr<size_t> Plan9FSInode::directory_entry_count() const
|
||||
{
|
||||
size_t count = 0;
|
||||
KResult result = traverse_as_directory([&count](const FS::DirectoryEntry&) {
|
||||
KResult result = traverse_as_directory([&count](auto&) {
|
||||
count++;
|
||||
return true;
|
||||
});
|
||||
|
@ -809,7 +809,7 @@ KResultOr<size_t> Plan9FSInode::directory_entry_count() const
|
|||
return count;
|
||||
}
|
||||
|
||||
KResult Plan9FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)> callback) const
|
||||
KResult Plan9FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntryView&)> callback) const
|
||||
{
|
||||
KResult result = KSuccess;
|
||||
|
||||
|
@ -857,17 +857,7 @@ KResult Plan9FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEnt
|
|||
u8 type;
|
||||
StringView name;
|
||||
decoder >> qid >> offset >> type >> name;
|
||||
|
||||
FS::DirectoryEntry entry {
|
||||
"",
|
||||
name.length(),
|
||||
{ fsid(), fs().allocate_fid() },
|
||||
0
|
||||
};
|
||||
size_t size_to_copy = min(sizeof(entry.name) - 1, name.length());
|
||||
memcpy(entry.name, name.characters_without_null_termination(), size_to_copy);
|
||||
entry.name[size_to_copy] = 0;
|
||||
callback(entry);
|
||||
callback({ name, { fsid(), fs().allocate_fid() }, 0 });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue