mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 22:38:51 +00:00
Kernel: Make Inode::read_entire() return a KBuffer (not ByteBuffer)
ByteBuffer is backed by kmalloc heap memory which is a scarce resource. This fixes an OOM panic when traversing a large directory.
This commit is contained in:
parent
ec93d6ffdc
commit
62ec6e5fe0
Notes:
sideshowbarker
2024-07-19 03:53:17 +09:00
Author: https://github.com/awesomekling
Commit: 62ec6e5fe0
7 changed files with 12 additions and 16 deletions
|
@ -31,6 +31,7 @@
|
|||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/FileSystem/InodeWatcher.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/KBufferBuilder.h>
|
||||
#include <Kernel/Net/LocalSocket.h>
|
||||
#include <Kernel/VM/SharedInodeVMObject.h>
|
||||
|
||||
|
@ -65,10 +66,9 @@ void Inode::sync()
|
|||
}
|
||||
}
|
||||
|
||||
KResultOr<ByteBuffer> Inode::read_entire(FileDescription* descriptor) const
|
||||
KResultOr<KBuffer> Inode::read_entire(FileDescription* descriptor) const
|
||||
{
|
||||
size_t initial_size = metadata().size ? metadata().size : 4096;
|
||||
StringBuilder builder(initial_size);
|
||||
KBufferBuilder builder;
|
||||
|
||||
ssize_t nread;
|
||||
u8 buffer[4096];
|
||||
|
@ -85,10 +85,10 @@ KResultOr<ByteBuffer> Inode::read_entire(FileDescription* descriptor) const
|
|||
}
|
||||
if (nread < 0) {
|
||||
klog() << "Inode::read_entire: ERROR: " << nread;
|
||||
return nullptr;
|
||||
return KResult(nread);
|
||||
}
|
||||
|
||||
return builder.to_byte_buffer();
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
KResultOr<NonnullRefPtr<Custody>> Inode::resolve_as_link(Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level) const
|
||||
|
@ -101,12 +101,6 @@ KResultOr<NonnullRefPtr<Custody>> Inode::resolve_as_link(Custody& base, RefPtr<C
|
|||
return contents_or.error();
|
||||
|
||||
auto& contents = contents_or.value();
|
||||
if (!contents) {
|
||||
if (out_parent)
|
||||
*out_parent = nullptr;
|
||||
return KResult(-ENOENT);
|
||||
}
|
||||
|
||||
auto path = StringView(contents.data(), contents.size());
|
||||
return VFS::the().resolve_path(path, base, out_parent, options, symlink_recursion_level);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue