diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-08 18:29:52 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-08 20:16:00 +0200 |
commit | 524ef5e47596421ddc39d77830c651235f45c15f (patch) | |
tree | db6aa133427b386d5422e74f0be285b8c94421c4 | |
parent | bee2de4b3109221ed8376d74e811dddf072f8862 (diff) | |
download | serenity-524ef5e47596421ddc39d77830c651235f45c15f.zip |
Kernel: Add KBuffer::bytes() and use it
(Instead of hand-wrapping { data(), size() } in a bunch of places.)
-rw-r--r-- | Kernel/FileSystem/Inode.cpp | 3 | ||||
-rw-r--r-- | Kernel/FileSystem/Plan9FileSystem.cpp | 2 | ||||
-rw-r--r-- | Kernel/KBuffer.h | 3 | ||||
-rw-r--r-- | Kernel/KBufferBuilder.h | 2 | ||||
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 2 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.h | 2 | ||||
-rw-r--r-- | Kernel/Syscalls/module.cpp | 2 |
7 files changed, 9 insertions, 7 deletions
diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index a83b41d6e3..1261c0ef68 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -75,8 +75,7 @@ KResultOr<NonnullRefPtr<Custody>> Inode::resolve_as_link(Custody& base, RefPtr<C // contents as a path and resolves that. That is, it // behaves exactly how you would expect a symlink to work. auto contents = TRY(read_entire()); - auto path = StringView(contents->data(), contents->size()); - return VirtualFileSystem::the().resolve_path(path, base, out_parent, options, symlink_recursion_level); + return VirtualFileSystem::the().resolve_path(StringView { contents->bytes() }, base, out_parent, options, symlink_recursion_level); } Inode::Inode(FileSystem& fs, InodeIndex index) diff --git a/Kernel/FileSystem/Plan9FileSystem.cpp b/Kernel/FileSystem/Plan9FileSystem.cpp index 43bd3a4870..d239f4a741 100644 --- a/Kernel/FileSystem/Plan9FileSystem.cpp +++ b/Kernel/FileSystem/Plan9FileSystem.cpp @@ -333,7 +333,7 @@ Plan9FS::Message::Message(Plan9FS& fs, Type type) } Plan9FS::Message::Message(NonnullOwnPtr<KBuffer>&& buffer) - : m_built { move(buffer), Decoder({ buffer->data(), buffer->size() }) } + : m_built { move(buffer), Decoder({ buffer->bytes() }) } , m_have_been_built(true) { u32 size; diff --git a/Kernel/KBuffer.h b/Kernel/KBuffer.h index 0b161d3257..2a56410178 100644 --- a/Kernel/KBuffer.h +++ b/Kernel/KBuffer.h @@ -42,6 +42,9 @@ public: [[nodiscard]] size_t size() const { return m_size; } [[nodiscard]] size_t capacity() const { return m_region->size(); } + [[nodiscard]] ReadonlyBytes bytes() const { return { data(), size() }; } + [[nodiscard]] Bytes bytes() { return { data(), size() }; } + void set_size(size_t size) { VERIFY(size <= capacity()); diff --git a/Kernel/KBufferBuilder.h b/Kernel/KBufferBuilder.h index 7874bfb31a..06be3c0d6d 100644 --- a/Kernel/KBufferBuilder.h +++ b/Kernel/KBufferBuilder.h @@ -48,7 +48,7 @@ public: { if (!m_buffer) return {}; - return ReadonlyBytes { m_buffer->data(), m_buffer->size() }; + return m_buffer->bytes(); } private: diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 36b8750ca7..d8e7922ee0 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -372,7 +372,7 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(OpenFileDescription& descr return bytes_written; } - return protocol_receive(ReadonlyBytes { packet->data->data(), packet->data->size() }, buffer, buffer_length, flags); + return protocol_receive(packet->data->bytes(), buffer, buffer_length, flags); } KResultOr<size_t> IPv4Socket::recvfrom(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> user_addr, Userspace<socklen_t*> user_addr_length, Time& packet_timestamp) diff --git a/Kernel/Net/NetworkAdapter.h b/Kernel/Net/NetworkAdapter.h index 554ba49e8d..38894f6ff6 100644 --- a/Kernel/Net/NetworkAdapter.h +++ b/Kernel/Net/NetworkAdapter.h @@ -34,7 +34,7 @@ struct PacketWithTimestamp : public RefCounted<PacketWithTimestamp> { { } - ReadonlyBytes bytes() { return { buffer->data(), buffer->size() }; }; + ReadonlyBytes bytes() { return buffer->bytes(); } NonnullOwnPtr<KBuffer> buffer; Time timestamp; diff --git a/Kernel/Syscalls/module.cpp b/Kernel/Syscalls/module.cpp index 4b1b17c3e1..538c6846d8 100644 --- a/Kernel/Syscalls/module.cpp +++ b/Kernel/Syscalls/module.cpp @@ -27,7 +27,7 @@ KResultOr<FlatPtr> Process::sys$module_load(Userspace<const char*> user_path, si auto description = TRY(VirtualFileSystem::the().open(path->view(), O_RDONLY, 0, current_directory())); auto payload = TRY(description->read_entire_file()); - auto storage = TRY(KBuffer::try_create_with_bytes(ReadonlyBytes { payload->data(), payload->size() })); + auto storage = TRY(KBuffer::try_create_with_bytes(payload->bytes())); auto elf_image = try_make<ELF::Image>(storage->data(), storage->size()); if (!elf_image) |