diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp index 964e682afb..dff77e36ea 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/FileDescription.cpp @@ -163,7 +163,7 @@ bool FileDescription::can_read() const return m_file->can_read(*this, offset()); } -KResultOr FileDescription::read_entire_file() +KResultOr FileDescription::read_entire_file() { // HACK ALERT: (This entire function) ASSERT(m_file->is_inode()); diff --git a/Kernel/FileSystem/FileDescription.h b/Kernel/FileSystem/FileDescription.h index ead0bb1fc3..3b7d36d202 100644 --- a/Kernel/FileSystem/FileDescription.h +++ b/Kernel/FileSystem/FileDescription.h @@ -71,7 +71,7 @@ public: ssize_t get_dir_entries(u8* buffer, ssize_t); - KResultOr read_entire_file(); + KResultOr read_entire_file(); String absolute_path() const; diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index 8d4f76a6ad..b88dd8b490 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -65,10 +66,9 @@ void Inode::sync() } } -KResultOr Inode::read_entire(FileDescription* descriptor) const +KResultOr 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 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> Inode::resolve_as_link(Custody& base, RefPtr* out_parent, int options, int symlink_recursion_level) const @@ -101,12 +101,6 @@ KResultOr> Inode::resolve_as_link(Custody& base, RefPtr read_entire(FileDescription* = nullptr) const; + KResultOr read_entire(FileDescription* = nullptr) const; virtual ssize_t read_bytes(off_t, ssize_t, u8* buffer, FileDescription*) const = 0; virtual KResult traverse_as_directory(Function) const = 0; diff --git a/Kernel/KBuffer.h b/Kernel/KBuffer.h index 6e03518607..b6369f1839 100644 --- a/Kernel/KBuffer.h +++ b/Kernel/KBuffer.h @@ -105,6 +105,9 @@ public: size_t size() const { return m_impl->size(); } size_t capacity() const { return m_impl->capacity(); } + void* end_pointer() { return data() + size(); } + const void* end_pointer() const { return data() + size(); } + void set_size(size_t size) { m_impl->set_size(size); } const KBufferImpl& impl() const { return m_impl; } diff --git a/Kernel/KSyms.cpp b/Kernel/KSyms.cpp index 401431412e..bd1e8e3d1c 100644 --- a/Kernel/KSyms.cpp +++ b/Kernel/KSyms.cpp @@ -69,7 +69,7 @@ const KernelSymbol* symbolicate_kernel_address(u32 address) return nullptr; } -static void load_kernel_sybols_from_data(const ByteBuffer& buffer) +static void load_kernel_sybols_from_data(const KBuffer& buffer) { g_lowest_kernel_symbol_address = 0xffffffff; g_highest_kernel_symbol_address = 0; diff --git a/Kernel/Syscalls/module.cpp b/Kernel/Syscalls/module.cpp index 5d3617244c..6da8ff8144 100644 --- a/Kernel/Syscalls/module.cpp +++ b/Kernel/Syscalls/module.cpp @@ -56,7 +56,6 @@ int Process::sys$module_load(Userspace user_path, size_t path_lengt auto payload = payload_or_error.value(); auto storage = KBuffer::create_with_size(payload.size()); memcpy(storage.data(), payload.data(), payload.size()); - payload.clear(); auto elf_image = make(storage.data(), storage.size()); if (!elf_image->parse())