Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>

We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace!
This was a slightly tedious refactoring that took a long time, so it's
not unlikely that some bugs crept in.

Nevertheless, it does pass basic functionality testing, and it's just
real nice to finally see the same pattern in all contexts. :^)
This commit is contained in:
Andreas Kling 2021-11-08 00:51:39 +01:00
parent 7ee10c6926
commit 79fa9765ca
Notes: sideshowbarker 2024-07-18 01:23:06 +09:00
262 changed files with 2415 additions and 2600 deletions

View file

@ -6,13 +6,9 @@
#pragma once
#include <AK/Error.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/RefCounted.h>
#ifdef KERNEL
# include <Kernel/API/KResult.h>
#else
# include <AK/Error.h>
#endif
#define OWNPTR_SCRUB_BYTE 0xf0
@ -209,16 +205,6 @@ inline OwnPtr<T> adopt_own_if_nonnull(T* object)
return {};
}
#ifdef KERNEL
template<typename T>
inline Kernel::KResultOr<NonnullOwnPtr<T>> adopt_nonnull_own_or_enomem(T* object)
{
auto result = adopt_own_if_nonnull(object);
if (!result)
return ENOMEM;
return result.release_nonnull();
}
#else
template<typename T>
inline ErrorOr<NonnullOwnPtr<T>> adopt_nonnull_own_or_enomem(T* object)
{
@ -227,7 +213,6 @@ inline ErrorOr<NonnullOwnPtr<T>> adopt_nonnull_own_or_enomem(T* object)
return ENOMEM;
return result.release_nonnull();
}
#endif
template<typename T, class... Args>
requires(IsConstructible<T, Args...>) inline OwnPtr<T> try_make(Args&&... args)

View file

@ -7,7 +7,7 @@
#pragma once
// NOTE: This macro works with any result type that has the expected APIs.
// It's designed with AK::Result and Kernel::KResult in mind.
// It's designed with AK::Result and AK::Error in mind.
#define TRY(expression) \
({ \

View file

@ -1,199 +0,0 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Assertions.h>
#include <AK/Format.h>
#include <AK/Platform.h>
#include <AK/StdLibExtras.h>
#include <AK/Try.h>
#include <LibC/errno_numbers.h>
namespace Kernel {
enum KSuccessTag {
KSuccess
};
class [[nodiscard]] KResult {
public:
KResult(ErrnoCode error)
: m_error(-error)
{
}
KResult(KSuccessTag)
: m_error(0)
{
}
[[nodiscard]] int error() const { return m_error; }
[[nodiscard]] bool is_success() const { return m_error == 0; }
[[nodiscard]] bool is_error() const { return !is_success(); }
bool operator==(ErrnoCode error) const { return is_error() && m_error == -error; }
bool operator!=(ErrnoCode error) const { return !is_error() || m_error != -error; }
bool operator!=(KSuccessTag) const { return is_error(); }
bool operator==(KSuccessTag) const { return !is_error(); }
// NOTE: These are here to make KResult usable with TRY()
KResult release_error() { return *this; }
void release_value() { }
private:
template<typename T>
friend class KResultOr;
KResult() = default;
int m_error { 0 };
};
template<typename T>
class [[nodiscard]] KResultOr {
public:
KResultOr(KResult error)
: m_error(error)
, m_is_error(true)
{
}
KResultOr(ErrnoCode error)
: m_error(error)
, m_is_error(true)
{
}
ALWAYS_INLINE KResultOr(T&& value)
: m_have_storage(true)
{
new (&m_storage) T(move(value));
}
ALWAYS_INLINE KResultOr(const T& value)
: m_have_storage(true)
{
new (&m_storage) T(value);
}
template<typename U>
ALWAYS_INLINE KResultOr(U&& value) requires(!IsSame<RemoveCVReference<U>, KResultOr<T>>)
: m_have_storage(true)
{
new (&m_storage) T(forward<U>(value));
}
KResultOr(KResultOr&& other)
{
m_is_error = other.m_is_error;
if (m_is_error) {
m_error = other.m_error;
} else {
if (other.m_have_storage) {
new (&m_storage) T(move(other.value()));
m_have_storage = true;
other.value().~T();
other.m_have_storage = false;
}
}
other.m_is_error = true;
other.m_error = KSuccess;
}
KResultOr& operator=(KResultOr&& other)
{
if (&other == this)
return *this;
if (!m_is_error && m_have_storage) {
value().~T();
m_have_storage = false;
}
m_is_error = other.m_is_error;
if (m_is_error) {
m_error = other.m_error;
} else {
if (other.m_have_storage) {
new (&m_storage) T(move(other.value()));
m_have_storage = true;
other.value().~T();
other.m_have_storage = false;
}
}
other.m_is_error = true;
other.m_error = KSuccess;
return *this;
}
~KResultOr()
{
if (!m_is_error && m_have_storage)
value().~T();
}
[[nodiscard]] bool is_error() const { return m_is_error; }
[[nodiscard]] ALWAYS_INLINE KResult error() const
{
VERIFY(m_is_error);
return m_error;
}
KResult result() const { return m_is_error ? m_error : KSuccess; }
[[nodiscard]] ALWAYS_INLINE T& value() &
{
VERIFY(!m_is_error);
return *reinterpret_cast<T*>(&m_storage);
}
[[nodiscard]] ALWAYS_INLINE T const& value() const&
{
VERIFY(!m_is_error);
return *reinterpret_cast<T*>(&m_storage);
}
T value() && = delete;
[[nodiscard]] ALWAYS_INLINE T release_value()
{
VERIFY(!m_is_error);
VERIFY(m_have_storage);
T released_value(move(*reinterpret_cast<T*>(&m_storage)));
value().~T();
m_have_storage = false;
return released_value;
}
KResult release_error()
{
VERIFY(m_is_error);
return m_error;
}
private:
union {
alignas(T) char m_storage[sizeof(T)];
KResult m_error;
};
bool m_is_error { false };
bool m_have_storage { false };
};
}
using Kernel::KResult;
using Kernel::KResultOr;
using Kernel::KSuccess;
template<>
struct AK::Formatter<KResult> : Formatter<FormatString> {
void format(FormatBuilder& builder, Kernel::KResult value)
{
if (value.is_error())
return AK::Formatter<FormatString>::format(builder, "KResult({})", value.error());
return AK::Formatter<FormatString>::format(builder, "KResult(success)");
}
};

View file

@ -44,7 +44,7 @@ namespace Kernel {
void dump_backtrace(PrintToScreen) { }
// KString.cpp
KResultOr<NonnullOwnPtr<KString>> KString::try_create_uninitialized(size_t, char*&) { return ENOMEM; }
ErrorOr<NonnullOwnPtr<KString>> KString::try_create_uninitialized(size_t, char*&) { return ENOMEM; }
void KString::operator delete(void*) { }
// SafeMem.h

View file

@ -5,8 +5,8 @@
*/
#include <AK/ByteReader.h>
#include <AK/Error.h>
#include <AK/HashTable.h>
#include <Kernel/API/KResult.h>
#include <Kernel/Arch/x86/IO.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Debug.h>

View file

@ -59,19 +59,19 @@ PCIDeviceAttributeSysFSComponent::PCIDeviceAttributeSysFSComponent(String name,
{
}
KResultOr<size_t> PCIDeviceAttributeSysFSComponent::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const
ErrorOr<size_t> PCIDeviceAttributeSysFSComponent::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const
{
auto blob = TRY(try_to_generate_buffer());
if ((size_t)offset >= blob->size())
return KSuccess;
return 0;
ssize_t nread = min(static_cast<off_t>(blob->size() - offset), static_cast<off_t>(count));
TRY(buffer.write(blob->data() + offset, nread));
return nread;
}
KResultOr<NonnullOwnPtr<KBuffer>> PCIDeviceAttributeSysFSComponent::try_to_generate_buffer() const
ErrorOr<NonnullOwnPtr<KBuffer>> PCIDeviceAttributeSysFSComponent::try_to_generate_buffer() const
{
String value;
switch (m_field_bytes_width) {

View file

@ -37,11 +37,11 @@ class PCIDeviceAttributeSysFSComponent : public SysFSComponent {
public:
static NonnullRefPtr<PCIDeviceAttributeSysFSComponent> create(String name, const PCIDeviceSysFSDirectory& device, PCI::RegisterOffset offset, size_t field_bytes_width);
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override;
virtual ~PCIDeviceAttributeSysFSComponent() {};
protected:
KResultOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const;
ErrorOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const;
PCIDeviceAttributeSysFSComponent(String name, const PCIDeviceSysFSDirectory& device, PCI::RegisterOffset offset, size_t field_bytes_width);
NonnullRefPtr<PCIDeviceSysFSDirectory> m_device;
PCI::RegisterOffset m_offset;

View file

@ -23,7 +23,7 @@ SysFSUSBDeviceInformation::~SysFSUSBDeviceInformation()
{
}
KResult SysFSUSBDeviceInformation::try_generate(KBufferBuilder& builder)
ErrorOr<void> SysFSUSBDeviceInformation::try_generate(KBufferBuilder& builder)
{
VERIFY(m_lock.is_locked());
JsonArraySerializer array { builder };
@ -44,10 +44,10 @@ KResult SysFSUSBDeviceInformation::try_generate(KBufferBuilder& builder)
obj.add("num_configurations", m_device->device_descriptor().num_configurations);
obj.finish();
array.finish();
return KSuccess;
return {};
}
KResult SysFSUSBDeviceInformation::refresh_data(OpenFileDescription& description) const
ErrorOr<void> SysFSUSBDeviceInformation::refresh_data(OpenFileDescription& description) const
{
MutexLocker lock(m_lock);
auto& cached_data = description.data();
@ -60,10 +60,10 @@ KResult SysFSUSBDeviceInformation::refresh_data(OpenFileDescription& description
typed_cached_data.buffer = builder.build();
if (!typed_cached_data.buffer)
return ENOMEM;
return KSuccess;
return {};
}
KResultOr<size_t> SysFSUSBDeviceInformation::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const
ErrorOr<size_t> SysFSUSBDeviceInformation::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const
{
dbgln_if(PROCFS_DEBUG, "SysFSUSBDeviceInformation @ {}: read_bytes offset: {} count: {}", name(), offset, count);
@ -71,13 +71,13 @@ KResultOr<size_t> SysFSUSBDeviceInformation::read_bytes(off_t offset, size_t cou
VERIFY(buffer.user_or_kernel_ptr());
if (!description)
return KResult(EIO);
return Error::from_errno(EIO);
MutexLocker locker(m_lock);
if (!description->data()) {
dbgln("SysFSUSBDeviceInformation: Do not have cached data!");
return KResult(EIO);
return Error::from_errno(EIO);
}
auto& typed_cached_data = static_cast<SysFSInodeData&>(*description->data());
@ -91,7 +91,7 @@ KResultOr<size_t> SysFSUSBDeviceInformation::read_bytes(off_t offset, size_t cou
return nread;
}
KResult SysFSUSBBusDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> SysFSUSBBusDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
SpinlockLocker lock(m_lock);
// Note: if the parent directory is null, it means something bad happened as this should not happen for the USB directory.
@ -103,7 +103,7 @@ KResult SysFSUSBBusDirectory::traverse_as_directory(unsigned fsid, Function<bool
InodeIdentifier identifier = { fsid, device_node.component_index() };
callback({ device_node.name(), identifier, 0 });
}
return KSuccess;
return {};
}
RefPtr<SysFSComponent> SysFSUSBBusDirectory::lookup(StringView name)

View file

@ -26,15 +26,15 @@ public:
protected:
explicit SysFSUSBDeviceInformation(USB::Device& device);
virtual KResultOr<size_t> read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual ErrorOr<size_t> read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
IntrusiveListNode<SysFSUSBDeviceInformation, RefPtr<SysFSUSBDeviceInformation>> m_list_node;
NonnullRefPtr<USB::Device> m_device;
private:
KResult try_generate(KBufferBuilder&);
virtual KResult refresh_data(OpenFileDescription& description) const override;
ErrorOr<void> try_generate(KBufferBuilder&);
virtual ErrorOr<void> refresh_data(OpenFileDescription& description) const override;
mutable Mutex m_lock { "SysFSUSBDeviceInformation" };
};
@ -46,7 +46,7 @@ public:
void plug(USB::Device&);
void unplug(USB::Device&);
virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
private:

View file

@ -62,7 +62,7 @@ static constexpr u16 UCHI_PORTSC_NON_WRITE_CLEAR_BIT_MASK = 0x1FF5; // This is u
static constexpr u8 UHCI_NUMBER_OF_ISOCHRONOUS_TDS = 128;
static constexpr u16 UHCI_NUMBER_OF_FRAMES = 1024;
KResultOr<NonnullRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
ErrorOr<NonnullRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
{
// NOTE: This assumes that address is pointing to a valid UHCI controller.
auto controller = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) UHCIController(pci_device_identifier)));
@ -70,7 +70,7 @@ KResultOr<NonnullRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::
return controller;
}
KResult UHCIController::initialize()
ErrorOr<void> UHCIController::initialize()
{
dmesgln("UHCI: Controller found {} @ {}", PCI::get_hardware_id(pci_address()), pci_address());
dmesgln("UHCI: I/O base {}", m_io_base);
@ -93,7 +93,7 @@ UNMAP_AFTER_INIT UHCIController::~UHCIController()
{
}
KResult UHCIController::reset()
ErrorOr<void> UHCIController::reset()
{
TRY(stop());
@ -126,10 +126,10 @@ KResult UHCIController::reset()
write_usbintr(0);
dbgln("UHCI: Reset completed");
return KSuccess;
return {};
}
UNMAP_AFTER_INIT KResult UHCIController::create_structures()
UNMAP_AFTER_INIT ErrorOr<void> UHCIController::create_structures()
{
m_queue_head_pool = TRY(UHCIDescriptorPool<QueueHead>::try_create("Queue Head Pool"sv));
@ -173,7 +173,7 @@ UNMAP_AFTER_INIT KResult UHCIController::create_structures()
m_transfer_descriptor_pool->print_pool_information();
}
return KSuccess;
return {};
}
UNMAP_AFTER_INIT void UHCIController::setup_schedule()
@ -245,7 +245,7 @@ TransferDescriptor* UHCIController::allocate_transfer_descriptor()
return m_transfer_descriptor_pool->try_take_free_descriptor();
}
KResult UHCIController::stop()
ErrorOr<void> UHCIController::stop()
{
write_usbcmd(read_usbcmd() & ~UHCI_USBCMD_RUN);
// FIXME: Timeout
@ -253,10 +253,10 @@ KResult UHCIController::stop()
if (read_usbsts() & UHCI_USBSTS_HOST_CONTROLLER_HALTED)
break;
}
return KSuccess;
return {};
}
KResult UHCIController::start()
ErrorOr<void> UHCIController::start()
{
write_usbcmd(read_usbcmd() | UHCI_USBCMD_RUN);
// FIXME: Timeout
@ -268,7 +268,7 @@ KResult UHCIController::start()
m_root_hub = TRY(UHCIRootHub::try_create(*this));
TRY(m_root_hub->setup({}));
return KSuccess;
return {};
}
TransferDescriptor* UHCIController::create_transfer_descriptor(Pipe& pipe, PacketID direction, size_t data_len)
@ -303,7 +303,7 @@ TransferDescriptor* UHCIController::create_transfer_descriptor(Pipe& pipe, Packe
return td;
}
KResult UHCIController::create_chain(Pipe& pipe, PacketID direction, Ptr32<u8>& buffer_address, size_t max_size, size_t transfer_size, TransferDescriptor** td_chain, TransferDescriptor** last_td)
ErrorOr<void> UHCIController::create_chain(Pipe& pipe, PacketID direction, Ptr32<u8>& buffer_address, size_t max_size, size_t transfer_size, TransferDescriptor** td_chain, TransferDescriptor** last_td)
{
// We need to create `n` transfer descriptors based on the max
// size of each transfer (which we've learned from the device already by reading
@ -345,7 +345,7 @@ KResult UHCIController::create_chain(Pipe& pipe, PacketID direction, Ptr32<u8>&
*last_td = current_td;
*td_chain = first_td;
return KSuccess;
return {};
}
void UHCIController::free_descriptor_chain(TransferDescriptor* first_descriptor)
@ -361,7 +361,7 @@ void UHCIController::free_descriptor_chain(TransferDescriptor* first_descriptor)
}
}
KResultOr<size_t> UHCIController::submit_control_transfer(Transfer& transfer)
ErrorOr<size_t> UHCIController::submit_control_transfer(Transfer& transfer)
{
Pipe& pipe = transfer.pipe(); // Short circuit the pipe related to this transfer
bool direction_in = (transfer.request().request_type & USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST) == USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST;
@ -589,7 +589,7 @@ void UHCIController::reset_port(u8 port)
m_port_reset_change_statuses |= (1 << port);
}
KResult UHCIController::set_port_feature(Badge<UHCIRootHub>, u8 port, HubFeatureSelector feature_selector)
ErrorOr<void> UHCIController::set_port_feature(Badge<UHCIRootHub>, u8 port, HubFeatureSelector feature_selector)
{
// The check is done by UHCIRootHub.
VERIFY(port < NUMBER_OF_ROOT_PORTS);
@ -621,10 +621,10 @@ KResult UHCIController::set_port_feature(Badge<UHCIRootHub>, u8 port, HubFeature
return EINVAL;
}
return KSuccess;
return {};
}
KResult UHCIController::clear_port_feature(Badge<UHCIRootHub>, u8 port, HubFeatureSelector feature_selector)
ErrorOr<void> UHCIController::clear_port_feature(Badge<UHCIRootHub>, u8 port, HubFeatureSelector feature_selector)
{
// The check is done by UHCIRootHub.
VERIFY(port < NUMBER_OF_ROOT_PORTS);
@ -670,7 +670,7 @@ KResult UHCIController::clear_port_feature(Badge<UHCIRootHub>, u8 port, HubFeatu
else
write_portsc2(port_data);
return KSuccess;
return {};
}
}

View file

@ -33,24 +33,24 @@ class UHCIController final
public:
static constexpr u8 NUMBER_OF_ROOT_PORTS = 2;
static KResultOr<NonnullRefPtr<UHCIController>> try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier);
static ErrorOr<NonnullRefPtr<UHCIController>> try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier);
virtual ~UHCIController() override;
virtual StringView purpose() const override { return "UHCI"sv; }
virtual KResult initialize() override;
virtual KResult reset() override;
virtual KResult stop() override;
virtual KResult start() override;
virtual ErrorOr<void> initialize() override;
virtual ErrorOr<void> reset() override;
virtual ErrorOr<void> stop() override;
virtual ErrorOr<void> start() override;
void spawn_port_proc();
void do_debug_transfer();
virtual KResultOr<size_t> submit_control_transfer(Transfer& transfer) override;
virtual ErrorOr<size_t> submit_control_transfer(Transfer& transfer) override;
void get_port_status(Badge<UHCIRootHub>, u8, HubStatus&);
KResult set_port_feature(Badge<UHCIRootHub>, u8, HubFeatureSelector);
KResult clear_port_feature(Badge<UHCIRootHub>, u8, HubFeatureSelector);
ErrorOr<void> set_port_feature(Badge<UHCIRootHub>, u8, HubFeatureSelector);
ErrorOr<void> clear_port_feature(Badge<UHCIRootHub>, u8, HubFeatureSelector);
private:
explicit UHCIController(PCI::DeviceIdentifier const& pci_device_identifier);
@ -75,12 +75,12 @@ private:
virtual bool handle_irq(const RegisterState&) override;
KResult create_structures();
ErrorOr<void> create_structures();
void setup_schedule();
size_t poll_transfer_queue(QueueHead& transfer_queue);
TransferDescriptor* create_transfer_descriptor(Pipe& pipe, PacketID direction, size_t data_len);
KResult create_chain(Pipe& pipe, PacketID direction, Ptr32<u8>& buffer_address, size_t max_size, size_t transfer_size, TransferDescriptor** td_chain, TransferDescriptor** last_td);
ErrorOr<void> create_chain(Pipe& pipe, PacketID direction, Ptr32<u8>& buffer_address, size_t max_size, size_t transfer_size, TransferDescriptor** td_chain, TransferDescriptor** last_td);
void free_descriptor_chain(TransferDescriptor* first_descriptor);
QueueHead* allocate_queue_head();

View file

@ -28,7 +28,7 @@ class UHCIDescriptorPool {
static_assert(sizeof(T) <= PAGE_SIZE);
public:
static KResultOr<NonnullOwnPtr<UHCIDescriptorPool<T>>> try_create(StringView name)
static ErrorOr<NonnullOwnPtr<UHCIDescriptorPool<T>>> try_create(StringView name)
{
auto pool_memory_block = TRY(MM.allocate_kernel_region(PAGE_SIZE, "UHCI Descriptor Pool", Memory::Region::Access::ReadWrite));
return adopt_nonnull_own_or_enomem(new (nothrow) UHCIDescriptorPool(move(pool_memory_block), name));

View file

@ -83,7 +83,7 @@ static USBHubDescriptor uhci_root_hub_hub_descriptor = {
0x0, // Self-powered
};
KResultOr<NonnullOwnPtr<UHCIRootHub>> UHCIRootHub::try_create(NonnullRefPtr<UHCIController> uhci_controller)
ErrorOr<NonnullOwnPtr<UHCIRootHub>> UHCIRootHub::try_create(NonnullRefPtr<UHCIController> uhci_controller)
{
return adopt_nonnull_own_or_enomem(new (nothrow) UHCIRootHub(uhci_controller));
}
@ -93,7 +93,7 @@ UHCIRootHub::UHCIRootHub(NonnullRefPtr<UHCIController> uhci_controller)
{
}
KResult UHCIRootHub::setup(Badge<UHCIController>)
ErrorOr<void> UHCIRootHub::setup(Badge<UHCIController>)
{
m_hub = TRY(Hub::try_create_root_hub(m_uhci_controller, Device::DeviceSpeed::FullSpeed));
@ -104,10 +104,10 @@ KResult UHCIRootHub::setup(Badge<UHCIController>)
// NOTE: The root hub is no longer on the default address.
TRY(m_hub->enumerate_and_power_on_hub());
return KSuccess;
return {};
}
KResultOr<size_t> UHCIRootHub::handle_control_transfer(Transfer& transfer)
ErrorOr<size_t> UHCIRootHub::handle_control_transfer(Transfer& transfer)
{
auto& request = transfer.request();
auto* request_data = transfer.buffer().as_ptr() + sizeof(USBRequestData);

View file

@ -6,9 +6,9 @@
#pragma once
#include <AK/Error.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/NonnullRefPtr.h>
#include <Kernel/API/KResult.h>
#include <Kernel/Bus/USB/USBHub.h>
#include <Kernel/Bus/USB/USBTransfer.h>
@ -18,16 +18,16 @@ class UHCIController;
class UHCIRootHub {
public:
static KResultOr<NonnullOwnPtr<UHCIRootHub>> try_create(NonnullRefPtr<UHCIController>);
static ErrorOr<NonnullOwnPtr<UHCIRootHub>> try_create(NonnullRefPtr<UHCIController>);
UHCIRootHub(NonnullRefPtr<UHCIController>);
~UHCIRootHub() = default;
KResult setup(Badge<UHCIController>);
ErrorOr<void> setup(Badge<UHCIController>);
u8 device_address() const { return m_hub->address(); }
KResultOr<size_t> handle_control_transfer(Transfer& transfer);
ErrorOr<size_t> handle_control_transfer(Transfer& transfer);
void check_for_port_updates() { m_hub->check_for_port_updates(); }

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/Error.h>
#include <AK/RefCounted.h>
#include <Kernel/API/KResult.h>
#include <Kernel/Bus/USB/USBDevice.h>
#include <Kernel/Bus/USB/USBTransfer.h>
@ -17,13 +17,13 @@ class USBController : public RefCounted<USBController> {
public:
virtual ~USBController() = default;
virtual KResult initialize() = 0;
virtual ErrorOr<void> initialize() = 0;
virtual KResult reset() = 0;
virtual KResult stop() = 0;
virtual KResult start() = 0;
virtual ErrorOr<void> reset() = 0;
virtual ErrorOr<void> stop() = 0;
virtual ErrorOr<void> start() = 0;
virtual KResultOr<size_t> submit_control_transfer(Transfer&) = 0;
virtual ErrorOr<size_t> submit_control_transfer(Transfer&) = 0;
u8 allocate_address();

View file

@ -16,7 +16,7 @@
namespace Kernel::USB {
KResultOr<NonnullRefPtr<Device>> Device::try_create(USBController const& controller, u8 port, DeviceSpeed speed)
ErrorOr<NonnullRefPtr<Device>> Device::try_create(USBController const& controller, u8 port, DeviceSpeed speed)
{
auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0));
auto device = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Device(controller, port, speed, move(pipe))));
@ -56,7 +56,7 @@ Device::~Device()
{
}
KResult Device::enumerate_device()
ErrorOr<void> Device::enumerate_device()
{
USBDeviceDescriptor dev_descriptor {};
@ -118,7 +118,7 @@ KResult Device::enumerate_device()
dbgln_if(USB_DEBUG, "USB Device: Set address to {}", m_address);
memcpy(&m_device_descriptor, &dev_descriptor, sizeof(USBDeviceDescriptor));
return KSuccess;
return {};
}
}

View file

@ -27,13 +27,13 @@ public:
};
public:
static KResultOr<NonnullRefPtr<Device>> try_create(USBController const&, u8, DeviceSpeed);
static ErrorOr<NonnullRefPtr<Device>> try_create(USBController const&, u8, DeviceSpeed);
Device(USBController const&, u8, DeviceSpeed, NonnullOwnPtr<Pipe> default_pipe);
Device(Device const& device, NonnullOwnPtr<Pipe> default_pipe);
virtual ~Device();
KResult enumerate_device();
ErrorOr<void> enumerate_device();
u8 port() const { return m_device_port; }
DeviceSpeed speed() const { return m_device_speed; }

View file

@ -14,7 +14,7 @@
namespace Kernel::USB {
KResultOr<NonnullRefPtr<Hub>> Hub::try_create_root_hub(NonnullRefPtr<USBController> controller, DeviceSpeed device_speed)
ErrorOr<NonnullRefPtr<Hub>> Hub::try_create_root_hub(NonnullRefPtr<USBController> controller, DeviceSpeed device_speed)
{
// NOTE: Enumeration does not happen here, as the controller must know what the device address is at all times during enumeration to intercept requests.
auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0));
@ -22,7 +22,7 @@ KResultOr<NonnullRefPtr<Hub>> Hub::try_create_root_hub(NonnullRefPtr<USBControll
return hub;
}
KResultOr<NonnullRefPtr<Hub>> Hub::try_create_from_device(Device const& device)
ErrorOr<NonnullRefPtr<Hub>> Hub::try_create_from_device(Device const& device)
{
auto pipe = TRY(Pipe::try_create_pipe(device.controller(), Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, device.device_descriptor().max_packet_size, device.address()));
auto hub = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Hub(device, move(pipe))));
@ -40,7 +40,7 @@ Hub::Hub(Device const& device, NonnullOwnPtr<Pipe> default_pipe)
{
}
KResult Hub::enumerate_and_power_on_hub()
ErrorOr<void> Hub::enumerate_and_power_on_hub()
{
// USBDevice::enumerate_device must be called before this.
VERIFY(m_address > 0);
@ -85,11 +85,11 @@ KResult Hub::enumerate_and_power_on_hub()
memcpy(&m_hub_descriptor, &descriptor, sizeof(USBHubDescriptor));
return KSuccess;
return {};
}
// USB 2.0 Specification Section 11.24.2.7
KResult Hub::get_port_status(u8 port, HubStatus& hub_status)
ErrorOr<void> Hub::get_port_status(u8 port, HubStatus& hub_status)
{
// Ports are 1-based.
if (port == 0 || port > m_hub_descriptor.number_of_downstream_ports)
@ -103,29 +103,29 @@ KResult Hub::get_port_status(u8 port, HubStatus& hub_status)
return EIO;
}
return KSuccess;
return {};
}
// USB 2.0 Specification Section 11.24.2.2
KResult Hub::clear_port_feature(u8 port, HubFeatureSelector feature_selector)
ErrorOr<void> Hub::clear_port_feature(u8 port, HubFeatureSelector feature_selector)
{
// Ports are 1-based.
if (port == 0 || port > m_hub_descriptor.number_of_downstream_ports)
return EINVAL;
TRY(m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_REQUEST_RECIPIENT_OTHER, HubRequest::CLEAR_FEATURE, feature_selector, port, 0, nullptr));
return KSuccess;
return {};
}
// USB 2.0 Specification Section 11.24.2.13
KResult Hub::set_port_feature(u8 port, HubFeatureSelector feature_selector)
ErrorOr<void> Hub::set_port_feature(u8 port, HubFeatureSelector feature_selector)
{
// Ports are 1-based.
if (port == 0 || port > m_hub_descriptor.number_of_downstream_ports)
return EINVAL;
TRY(m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_REQUEST_RECIPIENT_OTHER, HubRequest::SET_FEATURE, feature_selector, port, 0, nullptr));
return KSuccess;
return {};
}
void Hub::remove_children_from_sysfs()
@ -140,16 +140,14 @@ void Hub::check_for_port_updates()
dbgln_if(USB_DEBUG, "USB Hub: Checking for port updates on port {}...", port_number);
HubStatus port_status {};
auto result = get_port_status(port_number, port_status);
if (result.is_error()) {
if (auto result = get_port_status(port_number, port_status); result.is_error()) {
dbgln("USB Hub: Error occurred when getting status for port {}: {}. Checking next port instead.", port_number, result.error());
continue;
}
if (port_status.change & PORT_STATUS_CONNECT_STATUS_CHANGED) {
// Clear the connection status change notification.
result = clear_port_feature(port_number, HubFeatureSelector::C_PORT_CONNECTION);
if (result.is_error()) {
if (auto result = clear_port_feature(port_number, HubFeatureSelector::C_PORT_CONNECTION); result.is_error()) {
dbgln("USB Hub: Error occurred when clearing port connection change for port {}: {}.", port_number, result.error());
return;
}
@ -174,8 +172,7 @@ void Hub::check_for_port_updates()
IO::delay(debounce_disconnect_check_interval);
debounce_timer += debounce_disconnect_check_interval;
result = get_port_status(port_number, port_status);
if (result.is_error()) {
if (auto result = get_port_status(port_number, port_status); result.is_error()) {
dbgln("USB Hub: Error occurred when getting status while debouncing port {}: {}.", port_number, result.error());
return;
}
@ -185,8 +182,8 @@ void Hub::check_for_port_updates()
dbgln_if(USB_DEBUG, "USB Hub: Connection status changed while debouncing, resetting debounce timer.");
debounce_timer = 0;
result = clear_port_feature(port_number, HubFeatureSelector::C_PORT_CONNECTION);
if (result.is_error()) {
if (auto result = clear_port_feature(port_number, HubFeatureSelector::C_PORT_CONNECTION); result.is_error()) {
dbgln("USB Hub: Error occurred when clearing port connection change while debouncing port {}: {}.", port_number, result.error());
return;
}
@ -194,8 +191,7 @@ void Hub::check_for_port_updates()
// Reset the port
dbgln_if(USB_DEBUG, "USB Hub: Debounce finished. Driving reset...");
result = set_port_feature(port_number, HubFeatureSelector::PORT_RESET);
if (result.is_error()) {
if (auto result = set_port_feature(port_number, HubFeatureSelector::PORT_RESET); result.is_error()) {
dbgln("USB Hub: Error occurred when resetting port {}: {}.", port_number, result.error());
return;
}
@ -207,8 +203,7 @@ void Hub::check_for_port_updates()
constexpr u16 reset_delay = 10 * 1000;
IO::delay(reset_delay);
result = get_port_status(port_number, port_status);
if (result.is_error()) {
if (auto result = get_port_status(port_number, port_status); result.is_error()) {
dbgln("USB Hub: Error occurred when getting status while resetting port {}: {}.", port_number, result.error());
return;
}
@ -218,8 +213,8 @@ void Hub::check_for_port_updates()
}
// Stop asserting reset. This also causes the port to become enabled.
result = clear_port_feature(port_number, HubFeatureSelector::C_PORT_RESET);
if (result.is_error()) {
if (auto result = clear_port_feature(port_number, HubFeatureSelector::C_PORT_RESET); result.is_error()) {
dbgln("USB Hub: Error occurred when resetting port {}: {}.", port_number, result.error());
return;
}
@ -233,8 +228,7 @@ void Hub::check_for_port_updates()
// The port is ready to go. This is where we start communicating with the device to set up a driver for it.
result = get_port_status(port_number, port_status);
if (result.is_error()) {
if (auto result = get_port_status(port_number, port_status); result.is_error()) {
dbgln("USB Hub: Error occurred when getting status for port {} after reset: {}.", port_number, result.error());
return;
}

View file

@ -80,18 +80,18 @@ static constexpr u16 PORT_STATUS_RESET_CHANGED = (1 << 4);
class Hub : public Device {
public:
static KResultOr<NonnullRefPtr<Hub>> try_create_root_hub(NonnullRefPtr<USBController>, DeviceSpeed);
static KResultOr<NonnullRefPtr<Hub>> try_create_from_device(Device const&);
static ErrorOr<NonnullRefPtr<Hub>> try_create_root_hub(NonnullRefPtr<USBController>, DeviceSpeed);
static ErrorOr<NonnullRefPtr<Hub>> try_create_from_device(Device const&);
virtual ~Hub() override = default;
KResult enumerate_and_power_on_hub();
ErrorOr<void> enumerate_and_power_on_hub();
KResult get_port_status(u8, HubStatus&);
KResult clear_port_feature(u8, HubFeatureSelector);
KResult set_port_feature(u8, HubFeatureSelector);
ErrorOr<void> get_port_status(u8, HubStatus&);
ErrorOr<void> clear_port_feature(u8, HubFeatureSelector);
ErrorOr<void> set_port_feature(u8, HubFeatureSelector);
KResult reset_port(u8);
ErrorOr<void> reset_port(u8);
void check_for_port_updates();

View file

@ -11,7 +11,7 @@
namespace Kernel::USB {
KResultOr<NonnullOwnPtr<Pipe>> Pipe::try_create_pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval)
ErrorOr<NonnullOwnPtr<Pipe>> Pipe::try_create_pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval)
{
return adopt_nonnull_own_or_enomem(new (nothrow) Pipe(controller, type, direction, endpoint_address, max_packet_size, poll_interval, device_address));
}
@ -47,7 +47,7 @@ Pipe::Pipe(USBController const& controller, Type type, Direction direction, u8 e
{
}
KResultOr<size_t> Pipe::control_transfer(u8 request_type, u8 request, u16 value, u16 index, u16 length, void* data)
ErrorOr<size_t> Pipe::control_transfer(u8 request_type, u8 request, u16 value, u16 index, u16 length, void* data)
{
USBRequestData usb_request;

View file

@ -41,7 +41,7 @@ public:
};
public:
static KResultOr<NonnullOwnPtr<Pipe>> try_create_pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval = 0);
static ErrorOr<NonnullOwnPtr<Pipe>> try_create_pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval = 0);
Type type() const { return m_type; }
Direction direction() const { return m_direction; }
@ -57,7 +57,7 @@ public:
void set_toggle(bool toggle) { m_data_toggle = toggle; }
void set_device_address(i8 addr) { m_device_address = addr; }
KResultOr<size_t> control_transfer(u8 request_type, u8 request, u16 value, u16 index, u16 length, void* data);
ErrorOr<size_t> control_transfer(u8 request_type, u8 request, u16 value, u16 index, u16 length, void* data);
Pipe(USBController const& controller, Type type, Direction direction, u16 max_packet_size);
Pipe(USBController const& controller, Type type, Direction direction, USBEndpointDescriptor& endpoint);

View file

@ -9,7 +9,7 @@
namespace Kernel::USB {
KResultOr<NonnullRefPtr<Transfer>> Transfer::try_create(Pipe& pipe, u16 length)
ErrorOr<NonnullRefPtr<Transfer>> Transfer::try_create(Pipe& pipe, u16 length)
{
// Initialize data buffer for transfer
// This will definitely need to be refactored in the future, I doubt this will scale well...

View file

@ -19,7 +19,7 @@ namespace Kernel::USB {
class Transfer : public RefCounted<Transfer> {
public:
static KResultOr<NonnullRefPtr<Transfer>> try_create(Pipe&, u16 length);
static ErrorOr<NonnullRefPtr<Transfer>> try_create(Pipe&, u16 length);
public:
Transfer() = delete;

View file

@ -90,7 +90,7 @@ bool ConsolePort::can_read(const OpenFileDescription&, size_t) const
return m_receive_buffer->used_bytes() > 0;
}
KResultOr<size_t> ConsolePort::read(OpenFileDescription& desc, u64, UserOrKernelBuffer& buffer, size_t size)
ErrorOr<size_t> ConsolePort::read(OpenFileDescription& desc, u64, UserOrKernelBuffer& buffer, size_t size)
{
if (!size)
return 0;
@ -100,10 +100,7 @@ KResultOr<size_t> ConsolePort::read(OpenFileDescription& desc, u64, UserOrKernel
if (!can_read(desc, size))
return EAGAIN;
auto bytes_copied_or_error = m_receive_buffer->copy_data_out(size, buffer);
if (bytes_copied_or_error.is_error())
return bytes_copied_or_error.error();
auto bytes_copied = bytes_copied_or_error.release_value();
auto bytes_copied = TRY(m_receive_buffer->copy_data_out(size, buffer));
m_receive_buffer->reclaim_space(m_receive_buffer->start_of_used(), bytes_copied);
if (m_receive_buffer_exhausted && m_receive_buffer->used_bytes() == 0) {
@ -123,7 +120,7 @@ bool ConsolePort::can_write(const OpenFileDescription&, size_t) const
return m_console.get_queue(m_transmit_queue).has_free_slots() && m_transmit_buffer->has_space();
}
KResultOr<size_t> ConsolePort::write(OpenFileDescription& desc, u64, const UserOrKernelBuffer& data, size_t size)
ErrorOr<size_t> ConsolePort::write(OpenFileDescription& desc, u64, const UserOrKernelBuffer& data, size_t size)
{
if (!size)
return 0;
@ -157,7 +154,7 @@ KResultOr<size_t> ConsolePort::write(OpenFileDescription& desc, u64, const UserO
return total_bytes_copied;
}
KResultOr<NonnullRefPtr<OpenFileDescription>> ConsolePort::open(int options)
ErrorOr<NonnullRefPtr<OpenFileDescription>> ConsolePort::open(int options)
{
if (!m_open)
m_console.send_open_control_message(m_port, true);

View file

@ -38,10 +38,10 @@ private:
virtual StringView class_name() const override { return "VirtIOConsolePort"sv; }
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual bool can_write(const OpenFileDescription&, size_t) const override;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual KResultOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
static unsigned next_device_id;
u16 m_receive_queue {};

View file

@ -30,7 +30,7 @@ namespace Kernel {
return region.name().starts_with("LibJS:"sv) || region.name().starts_with("malloc:"sv);
}
KResultOr<NonnullOwnPtr<Coredump>> Coredump::try_create(NonnullRefPtr<Process> process, StringView output_path)
ErrorOr<NonnullOwnPtr<Coredump>> Coredump::try_create(NonnullRefPtr<Process> process, StringView output_path)
{
if (!process->is_dumpable()) {
dbgln("Refusing to generate coredump for non-dumpable process {}", process->pid().value());
@ -56,7 +56,7 @@ Coredump::Coredump(NonnullRefPtr<Process> process, NonnullRefPtr<OpenFileDescrip
++m_num_program_headers; // +1 for NOTE segment
}
KResultOr<NonnullRefPtr<OpenFileDescription>> Coredump::try_create_target_file(Process const& process, StringView output_path)
ErrorOr<NonnullRefPtr<OpenFileDescription>> Coredump::try_create_target_file(Process const& process, StringView output_path)
{
auto output_directory = KLexicalPath::dirname(output_path);
auto dump_directory = TRY(VirtualFileSystem::the().open_directory(output_directory, VirtualFileSystem::the().root_custody()));
@ -73,7 +73,7 @@ KResultOr<NonnullRefPtr<OpenFileDescription>> Coredump::try_create_target_file(P
UidAndGid { process.uid(), process.gid() }));
}
KResult Coredump::write_elf_header()
ErrorOr<void> Coredump::write_elf_header()
{
ElfW(Ehdr) elf_file_header;
elf_file_header.e_ident[EI_MAG0] = 0x7f;
@ -115,10 +115,10 @@ KResult Coredump::write_elf_header()
TRY(m_description->write(UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<uint8_t*>(&elf_file_header)), sizeof(ElfW(Ehdr))));
return KSuccess;
return {};
}
KResult Coredump::write_program_headers(size_t notes_size)
ErrorOr<void> Coredump::write_program_headers(size_t notes_size)
{
size_t offset = sizeof(ElfW(Ehdr)) + m_num_program_headers * sizeof(ElfW(Phdr));
for (auto& region : m_process->address_space().regions()) {
@ -162,10 +162,10 @@ KResult Coredump::write_program_headers(size_t notes_size)
TRY(m_description->write(UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<uint8_t*>(&notes_pheader)), sizeof(ElfW(Phdr))));
return KSuccess;
return {};
}
KResult Coredump::write_regions()
ErrorOr<void> Coredump::write_regions()
{
for (auto& region : m_process->address_space().regions()) {
VERIFY(!region->is_kernel());
@ -195,16 +195,16 @@ KResult Coredump::write_regions()
TRY(m_description->write(src_buffer.value(), PAGE_SIZE));
}
}
return KSuccess;
return {};
}
KResult Coredump::write_notes_segment(ReadonlyBytes notes_segment)
ErrorOr<void> Coredump::write_notes_segment(ReadonlyBytes notes_segment)
{
TRY(m_description->write(UserOrKernelBuffer::for_kernel_buffer(const_cast<u8*>(notes_segment.data())), notes_segment.size()));
return KSuccess;
return {};
}
KResult Coredump::create_notes_process_data(auto& builder) const
ErrorOr<void> Coredump::create_notes_process_data(auto& builder) const
{
ELF::Core::ProcessInfo info {};
info.header.type = ELF::Core::NotesEntryHeader::Type::ProcessInfo;
@ -230,10 +230,10 @@ KResult Coredump::create_notes_process_data(auto& builder) const
}
TRY(builder.append('\0'));
return KSuccess;
return {};
}
KResult Coredump::create_notes_threads_data(auto& builder) const
ErrorOr<void> Coredump::create_notes_threads_data(auto& builder) const
{
for (auto& thread : m_process->threads_for_coredump({})) {
ELF::Core::ThreadInfo info {};
@ -245,10 +245,10 @@ KResult Coredump::create_notes_threads_data(auto& builder) const
TRY(builder.append_bytes(ReadonlyBytes { &info, sizeof(info) }));
}
return KSuccess;
return {};
}
KResult Coredump::create_notes_regions_data(auto& builder) const
ErrorOr<void> Coredump::create_notes_regions_data(auto& builder) const
{
size_t region_index = 0;
for (auto& region : m_process->address_space().regions()) {
@ -274,10 +274,10 @@ KResult Coredump::create_notes_regions_data(auto& builder) const
else
TRY(builder.append(name.characters_without_null_termination(), name.length() + 1));
}
return KSuccess;
return {};
}
KResult Coredump::create_notes_metadata_data(auto& builder) const
ErrorOr<void> Coredump::create_notes_metadata_data(auto& builder) const
{
ELF::Core::Metadata metadata {};
metadata.header.type = ELF::Core::NotesEntryHeader::Type::Metadata;
@ -290,10 +290,10 @@ KResult Coredump::create_notes_metadata_data(auto& builder) const
});
}
TRY(builder.append('\0'));
return KSuccess;
return {};
}
KResult Coredump::create_notes_segment_data(auto& builder) const
ErrorOr<void> Coredump::create_notes_segment_data(auto& builder) const
{
TRY(create_notes_process_data(builder));
TRY(create_notes_threads_data(builder));
@ -304,10 +304,10 @@ KResult Coredump::create_notes_segment_data(auto& builder) const
null_entry.type = ELF::Core::NotesEntryHeader::Type::Null;
TRY(builder.append(ReadonlyBytes { &null_entry, sizeof(null_entry) }));
return KSuccess;
return {};
}
KResult Coredump::write()
ErrorOr<void> Coredump::write()
{
SpinlockLocker lock(m_process->address_space().get_lock());
ScopedAddressSpaceSwitcher switcher(m_process);

View file

@ -15,25 +15,25 @@ namespace Kernel {
class Coredump {
public:
static KResultOr<NonnullOwnPtr<Coredump>> try_create(NonnullRefPtr<Process>, StringView output_path);
static ErrorOr<NonnullOwnPtr<Coredump>> try_create(NonnullRefPtr<Process>, StringView output_path);
~Coredump() = default;
KResult write();
ErrorOr<void> write();
private:
Coredump(NonnullRefPtr<Process>, NonnullRefPtr<OpenFileDescription>);
static KResultOr<NonnullRefPtr<OpenFileDescription>> try_create_target_file(Process const&, StringView output_path);
static ErrorOr<NonnullRefPtr<OpenFileDescription>> try_create_target_file(Process const&, StringView output_path);
KResult write_elf_header();
KResult write_program_headers(size_t notes_size);
KResult write_regions();
KResult write_notes_segment(ReadonlyBytes);
ErrorOr<void> write_elf_header();
ErrorOr<void> write_program_headers(size_t notes_size);
ErrorOr<void> write_regions();
ErrorOr<void> write_notes_segment(ReadonlyBytes);
KResult create_notes_segment_data(auto&) const;
KResult create_notes_process_data(auto&) const;
KResult create_notes_threads_data(auto&) const;
KResult create_notes_regions_data(auto&) const;
KResult create_notes_metadata_data(auto&) const;
ErrorOr<void> create_notes_segment_data(auto&) const;
ErrorOr<void> create_notes_process_data(auto&) const;
ErrorOr<void> create_notes_threads_data(auto&) const;
ErrorOr<void> create_notes_regions_data(auto&) const;
ErrorOr<void> create_notes_metadata_data(auto&) const;
NonnullRefPtr<Process> m_process;
NonnullRefPtr<OpenFileDescription> m_description;

View file

@ -81,7 +81,7 @@ public:
void* get_private() const { return m_private; }
template<typename... Args>
KResult write_to_buffer(UserOrKernelBuffer& buffer, Args... args)
ErrorOr<void> write_to_buffer(UserOrKernelBuffer& buffer, Args... args)
{
if (in_target_context(buffer))
return buffer.write(forward<Args>(args)...);
@ -90,7 +90,7 @@ public:
}
template<size_t BUFFER_BYTES, typename... Args>
KResultOr<size_t> write_to_buffer_buffered(UserOrKernelBuffer& buffer, Args... args)
ErrorOr<size_t> write_to_buffer_buffered(UserOrKernelBuffer& buffer, Args... args)
{
if (in_target_context(buffer))
return buffer.write_buffered<BUFFER_BYTES>(forward<Args>(args)...);
@ -99,7 +99,7 @@ public:
}
template<typename... Args>
KResult read_from_buffer(const UserOrKernelBuffer& buffer, Args... args)
ErrorOr<void> read_from_buffer(const UserOrKernelBuffer& buffer, Args... args)
{
if (in_target_context(buffer))
return buffer.read(forward<Args>(args)...);
@ -108,7 +108,7 @@ public:
}
template<size_t BUFFER_BYTES, typename... Args>
KResultOr<size_t> read_from_buffer_buffered(const UserOrKernelBuffer& buffer, Args... args)
ErrorOr<size_t> read_from_buffer_buffered(const UserOrKernelBuffer& buffer, Args... args)
{
if (in_target_context(buffer))
return buffer.read_buffered<BUFFER_BYTES>(forward<Args>(args)...);

View file

@ -37,14 +37,14 @@ bool ConsoleDevice::can_read(const Kernel::OpenFileDescription&, size_t) const
return false;
}
Kernel::KResultOr<size_t> ConsoleDevice::read(OpenFileDescription&, u64, Kernel::UserOrKernelBuffer&, size_t)
ErrorOr<size_t> ConsoleDevice::read(OpenFileDescription&, u64, Kernel::UserOrKernelBuffer&, size_t)
{
// FIXME: Implement reading from the console.
// Maybe we could use a ring buffer for this device?
return 0;
}
Kernel::KResultOr<size_t> ConsoleDevice::write(OpenFileDescription&, u64, const Kernel::UserOrKernelBuffer& data, size_t size)
ErrorOr<size_t> ConsoleDevice::write(OpenFileDescription&, u64, const Kernel::UserOrKernelBuffer& data, size_t size)
{
if (!size)
return 0;

View file

@ -24,8 +24,8 @@ public:
// ^CharacterDevice
virtual bool can_read(const Kernel::OpenFileDescription&, size_t) const override;
virtual bool can_write(const Kernel::OpenFileDescription&, size_t) const override { return true; }
virtual Kernel::KResultOr<size_t> read(OpenFileDescription&, u64, Kernel::UserOrKernelBuffer&, size_t) override;
virtual Kernel::KResultOr<size_t> write(OpenFileDescription&, u64, const Kernel::UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, Kernel::UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const Kernel::UserOrKernelBuffer&, size_t) override;
virtual StringView class_name() const override { return "Console"sv; }
void put_char(char);

View file

@ -44,7 +44,7 @@ SysFSBlockDevicesDirectory::SysFSBlockDevicesDirectory(SysFSDevicesDirectory con
: SysFSDirectory("block"sv, devices_directory)
{
}
KResult SysFSBlockDevicesDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> SysFSBlockDevicesDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
VERIFY(m_parent_directory);
callback({ ".", { fsid, component_index() }, 0 });
@ -57,7 +57,7 @@ KResult SysFSBlockDevicesDirectory::traverse_as_directory(unsigned fsid, Functio
callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 });
}
});
return KSuccess;
return {};
}
RefPtr<SysFSComponent> SysFSBlockDevicesDirectory::lookup(StringView name)
{
@ -80,7 +80,7 @@ SysFSCharacterDevicesDirectory::SysFSCharacterDevicesDirectory(SysFSDevicesDirec
: SysFSDirectory("char"sv, devices_directory)
{
}
KResult SysFSCharacterDevicesDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> SysFSCharacterDevicesDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
VERIFY(m_parent_directory);
callback({ ".", { fsid, component_index() }, 0 });
@ -93,7 +93,7 @@ KResult SysFSCharacterDevicesDirectory::traverse_as_directory(unsigned fsid, Fun
callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 });
}
});
return KSuccess;
return {};
}
RefPtr<SysFSComponent> SysFSCharacterDevicesDirectory::lookup(StringView name)
{
@ -140,7 +140,7 @@ Device::~Device()
VERIFY(m_state == State::BeingRemoved);
}
KResultOr<NonnullOwnPtr<KString>> Device::pseudo_path(const OpenFileDescription&) const
ErrorOr<NonnullOwnPtr<KString>> Device::pseudo_path(const OpenFileDescription&) const
{
return KString::try_create(String::formatted("device:{},{}", major(), minor()));
}

View file

@ -15,10 +15,10 @@
// - BlockDevice (random access)
// - CharacterDevice (sequential)
#include <AK/DoublyLinkedList.h>
#include <AK/Error.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/RefPtr.h>
#include <Kernel/API/KResult.h>
#include <Kernel/Devices/AsyncDeviceRequest.h>
#include <Kernel/FileSystem/File.h>
#include <Kernel/FileSystem/SysFS.h>
@ -40,7 +40,7 @@ public:
unsigned major() const { return m_major; }
unsigned minor() const { return m_minor; }
virtual KResultOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
UserID uid() const { return m_uid; }
GroupID gid() const { return m_gid; }
@ -51,7 +51,7 @@ public:
void process_next_queued_request(Badge<AsyncDeviceRequest>, const AsyncDeviceRequest&);
template<typename AsyncRequestType, typename... Args>
KResultOr<NonnullRefPtr<AsyncRequestType>> try_make_request(Args&&... args)
ErrorOr<NonnullRefPtr<AsyncRequestType>> try_make_request(Args&&... args)
{
auto request = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AsyncRequestType(*this, forward<Args>(args)...)));
SpinlockLocker lock(m_requests_lock);

View file

@ -7,12 +7,12 @@
#pragma once
#include <AK/Badge.h>
#include <AK/Error.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Time.h>
#include <AK/Types.h>
#include <Kernel/API/KResult.h>
#include <Kernel/API/TimePage.h>
#include <Kernel/Arch/RegisterState.h>
#include <Kernel/Devices/ConsoleDevice.h>
@ -51,7 +51,7 @@ public:
ConsoleDevice& console_device();
template<typename DeviceType, typename... Args>
static inline KResultOr<NonnullRefPtr<DeviceType>> try_create_device(Args&&... args)
static inline ErrorOr<NonnullRefPtr<DeviceType>> try_create_device(Args&&... args)
{
auto device = TRY(adopt_nonnull_ref_or_enomem(new DeviceType(forward<Args>(args)...)));
device->after_inserting();

View file

@ -34,13 +34,13 @@ bool FullDevice::can_read(const OpenFileDescription&, size_t) const
return true;
}
KResultOr<size_t> FullDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
ErrorOr<size_t> FullDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
{
TRY(buffer.memset(0, size));
return size;
}
KResultOr<size_t> FullDevice::write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t size)
ErrorOr<size_t> FullDevice::write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t size)
{
if (size == 0)
return 0;

View file

@ -22,8 +22,8 @@ private:
FullDevice();
// ^CharacterDevice
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; }
virtual StringView class_name() const override { return "FullDevice"sv; }

View file

@ -8,11 +8,11 @@
#include <AK/Atomic.h>
#include <AK/CircularQueue.h>
#include <AK/Error.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/RefPtr.h>
#include <AK/Time.h>
#include <AK/Types.h>
#include <Kernel/API/KResult.h>
#include <Kernel/API/KeyCode.h>
#include <Kernel/API/MousePacket.h>
#include <Kernel/Locking/Spinlock.h>

View file

@ -278,7 +278,7 @@ bool KeyboardDevice::can_read(const OpenFileDescription&, size_t) const
return !m_queue.is_empty();
}
KResultOr<size_t> KeyboardDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
ErrorOr<size_t> KeyboardDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
{
size_t nread = 0;
SpinlockLocker lock(m_queue_lock);
@ -292,13 +292,11 @@ KResultOr<size_t> KeyboardDevice::read(OpenFileDescription&, u64, UserOrKernelBu
lock.unlock();
auto result = buffer.write_buffered<sizeof(Event)>(sizeof(Event), [&](Bytes bytes) {
auto result = TRY(buffer.write_buffered<sizeof(Event)>(sizeof(Event), [&](Bytes bytes) {
memcpy(bytes.data(), &event, sizeof(Event));
return bytes.size();
});
if (result.is_error())
return result.error();
VERIFY(result.value() == sizeof(Event));
}));
VERIFY(result == sizeof(Event));
nread += sizeof(Event);
lock.lock();
@ -306,7 +304,7 @@ KResultOr<size_t> KeyboardDevice::read(OpenFileDescription&, u64, UserOrKernelBu
return nread;
}
KResult KeyboardDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
ErrorOr<void> KeyboardDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
{
switch (request) {
case KEYBOARD_IOCTL_GET_NUM_LOCK: {
@ -319,7 +317,7 @@ KResult KeyboardDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<
if (num_lock_value != 0 && num_lock_value != 1)
return EINVAL;
m_num_lock_on = !!num_lock_value;
return KSuccess;
return {};
}
case KEYBOARD_IOCTL_GET_CAPS_LOCK: {
auto output = static_ptr_cast<bool*>(arg);
@ -330,7 +328,7 @@ KResult KeyboardDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<
if (caps_lock_value != 0 && caps_lock_value != 1)
return EINVAL;
m_caps_lock_on = !!caps_lock_value;
return KSuccess;
return {};
}
default:
return EINVAL;

View file

@ -25,16 +25,16 @@ public:
virtual ~KeyboardDevice() override;
// ^CharacterDevice
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; }
// ^HIDDevice
virtual Type instrument_type() const override { return Type::Keyboard; }
// ^File
virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
void update_modifier(u8 modifier, bool state)
{

View file

@ -24,7 +24,7 @@ bool MouseDevice::can_read(const OpenFileDescription&, size_t) const
return !m_queue.is_empty();
}
KResultOr<size_t> MouseDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
ErrorOr<size_t> MouseDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
{
VERIFY(size > 0);
size_t nread = 0;

View file

@ -23,9 +23,9 @@ public:
virtual ~MouseDevice() override;
// ^CharacterDevice
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; }
// ^HIDDevice

View file

@ -65,7 +65,7 @@ void KCOVDevice::free_process()
delete kcov_instance;
}
KResultOr<NonnullRefPtr<OpenFileDescription>> KCOVDevice::open(int options)
ErrorOr<NonnullRefPtr<OpenFileDescription>> KCOVDevice::open(int options)
{
auto pid = Process::current().pid();
if (proc_instance->get(pid).has_value())
@ -77,9 +77,8 @@ KResultOr<NonnullRefPtr<OpenFileDescription>> KCOVDevice::open(int options)
return File::open(options);
}
KResult KCOVDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
ErrorOr<void> KCOVDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
{
KResult return_value = KSuccess;
auto thread = Thread::current();
auto tid = thread->tid();
auto pid = thread->pid();
@ -90,48 +89,34 @@ KResult KCOVDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<void
SpinlockLocker locker(kcov_instance->spinlock());
switch (request) {
case KCOV_SETBUFSIZE: {
if (kcov_instance->state() >= KCOVInstance::TRACING) {
return_value = EBUSY;
break;
}
return_value = kcov_instance->buffer_allocate((FlatPtr)arg.unsafe_userspace_ptr());
break;
}
case KCOV_ENABLE: {
if (kcov_instance->state() >= KCOVInstance::TRACING) {
return_value = EBUSY;
break;
}
if (!kcov_instance->has_buffer()) {
return_value = ENOBUFS;
break;
}
case KCOV_SETBUFSIZE:
if (kcov_instance->state() >= KCOVInstance::TRACING)
return EBUSY;
return kcov_instance->buffer_allocate((FlatPtr)arg.unsafe_userspace_ptr());
case KCOV_ENABLE:
if (kcov_instance->state() >= KCOVInstance::TRACING)
return EBUSY;
if (!kcov_instance->has_buffer())
return ENOBUFS;
VERIFY(kcov_instance->state() == KCOVInstance::OPENED);
kcov_instance->set_state(KCOVInstance::TRACING);
thread_instance->set(tid, kcov_instance);
break;
}
return {};
case KCOV_DISABLE: {
auto maybe_kcov_instance = thread_instance->get(tid);
if (!maybe_kcov_instance.has_value()) {
return_value = ENOENT;
break;
}
if (!maybe_kcov_instance.has_value())
return ENOENT;
VERIFY(kcov_instance->state() == KCOVInstance::TRACING);
kcov_instance->set_state(KCOVInstance::OPENED);
thread_instance->remove(tid);
break;
return {};
}
default: {
return_value = EINVAL;
default:
return EINVAL;
}
};
return return_value;
}
KResultOr<Memory::Region*> KCOVDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
ErrorOr<Memory::Region*> KCOVDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
{
auto pid = process.pid();
auto maybe_kcov_instance = proc_instance->get(pid);

View file

@ -23,8 +23,8 @@ public:
static void free_process();
// ^File
KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
KResultOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
ErrorOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
protected:
KCOVDevice();
@ -34,9 +34,9 @@ protected:
virtual bool can_read(const OpenFileDescription&, size_t) const override final { return true; }
virtual bool can_write(const OpenFileDescription&, size_t) const override final { return true; }
virtual void start_request(AsyncBlockDeviceRequest& request) override final { request.complete(AsyncDeviceRequest::Failure); }
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; }
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; }
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
};
}

View file

@ -14,7 +14,7 @@ KCOVInstance::KCOVInstance(ProcessID pid)
m_pid = pid;
}
KResult KCOVInstance::buffer_allocate(size_t buffer_size_in_entries)
ErrorOr<void> KCOVInstance::buffer_allocate(size_t buffer_size_in_entries)
{
if (buffer_size_in_entries < 2 || buffer_size_in_entries > KCOV_MAX_ENTRIES)
return EINVAL;
@ -34,7 +34,7 @@ KResult KCOVInstance::buffer_allocate(size_t buffer_size_in_entries)
Memory::Region::Access::ReadWrite));
m_buffer = (u64*)m_kernel_region->vaddr().as_ptr();
return KSuccess;
return {};
}
void KCOVInstance::buffer_add_pc(u64 pc)

View file

@ -31,7 +31,7 @@ class KCOVInstance final {
public:
explicit KCOVInstance(ProcessID pid);
KResult buffer_allocate(size_t buffer_size_in_entries);
ErrorOr<void> buffer_allocate(size_t buffer_size_in_entries);
bool has_buffer() const { return m_buffer != nullptr; }
void buffer_add_pc(u64 pc);

View file

@ -31,7 +31,7 @@ UNMAP_AFTER_INIT MemoryDevice::~MemoryDevice()
{
}
KResultOr<size_t> MemoryDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t)
ErrorOr<size_t> MemoryDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t)
{
TODO();
}
@ -41,7 +41,7 @@ void MemoryDevice::did_seek(OpenFileDescription&, off_t)
TODO();
}
KResultOr<Memory::Region*> MemoryDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
ErrorOr<Memory::Region*> MemoryDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
{
auto viewed_address = PhysicalAddress(offset);

View file

@ -21,7 +21,7 @@ public:
static NonnullRefPtr<MemoryDevice> must_create();
~MemoryDevice();
virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
virtual ErrorOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
private:
MemoryDevice();
@ -30,8 +30,8 @@ private:
virtual bool can_read(const OpenFileDescription&, size_t) const override { return true; }
virtual bool can_write(const OpenFileDescription&, size_t) const override { return false; }
virtual bool is_seekable() const override { return true; }
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
virtual void did_seek(OpenFileDescription&, off_t) override;

View file

@ -33,12 +33,12 @@ bool NullDevice::can_read(const OpenFileDescription&, size_t) const
return true;
}
KResultOr<size_t> NullDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t)
ErrorOr<size_t> NullDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t)
{
return 0;
}
KResultOr<size_t> NullDevice::write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t buffer_size)
ErrorOr<size_t> NullDevice::write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t buffer_size)
{
return buffer_size;
}

View file

@ -22,8 +22,8 @@ public:
private:
NullDevice();
// ^CharacterDevice
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; }
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual StringView class_name() const override { return "NullDevice"sv; }

View file

@ -33,7 +33,7 @@ bool RandomDevice::can_read(const OpenFileDescription&, size_t) const
return true;
}
KResultOr<size_t> RandomDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
ErrorOr<size_t> RandomDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
{
return buffer.write_buffered<256>(size, [&](Bytes bytes) {
get_good_random_bytes(bytes);
@ -41,7 +41,7 @@ KResultOr<size_t> RandomDevice::read(OpenFileDescription&, u64, UserOrKernelBuff
});
}
KResultOr<size_t> RandomDevice::write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t size)
ErrorOr<size_t> RandomDevice::write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t size)
{
// FIXME: Use input for entropy? I guess that could be a neat feature?
return size;

View file

@ -22,8 +22,8 @@ private:
RandomDevice();
// ^CharacterDevice
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; }
virtual StringView class_name() const override { return "RandomDevice"sv; }

View file

@ -113,7 +113,7 @@ UNMAP_AFTER_INIT void SB16::initialize()
set_sample_rate(m_sample_rate);
}
KResult SB16::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
ErrorOr<void> SB16::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
{
switch (request) {
case SOUNDCARD_IOCTL_GET_SAMPLE_RATE: {
@ -126,7 +126,7 @@ KResult SB16::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg
return EINVAL;
if (m_sample_rate != sample_rate_value)
set_sample_rate(sample_rate_value);
return KSuccess;
return {};
}
default:
return EINVAL;
@ -186,7 +186,7 @@ bool SB16::can_read(OpenFileDescription const&, size_t) const
return false;
}
KResultOr<size_t> SB16::read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t)
ErrorOr<size_t> SB16::read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t)
{
return 0;
}
@ -246,7 +246,7 @@ void SB16::wait_for_irq()
disable_irq();
}
KResultOr<size_t> SB16::write(OpenFileDescription&, u64, UserOrKernelBuffer const& data, size_t length)
ErrorOr<size_t> SB16::write(OpenFileDescription&, u64, UserOrKernelBuffer const& data, size_t length)
{
if (!m_dma_region) {
auto page = MM.allocate_supervisor_physical_page();

View file

@ -27,13 +27,13 @@ public:
// ^CharacterDevice
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; }
virtual StringView purpose() const override { return class_name(); }
virtual KResult ioctl(OpenFileDescription&, unsigned, Userspace<void*>) override;
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned, Userspace<void*>) override;
private:
SB16();

View file

@ -61,7 +61,7 @@ bool SerialDevice::can_read(const OpenFileDescription&, size_t) const
return (get_line_status() & DataReady) != 0;
}
KResultOr<size_t> SerialDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
ErrorOr<size_t> SerialDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
{
if (!size)
return 0;
@ -82,7 +82,7 @@ bool SerialDevice::can_write(const OpenFileDescription&, size_t) const
return (get_line_status() & EmptyTransmitterHoldingRegister) != 0;
}
KResultOr<size_t> SerialDevice::write(OpenFileDescription& description, u64, const UserOrKernelBuffer& buffer, size_t size)
ErrorOr<size_t> SerialDevice::write(OpenFileDescription& description, u64, const UserOrKernelBuffer& buffer, size_t size)
{
if (!size)
return 0;

View file

@ -22,9 +22,9 @@ public:
// ^CharacterDevice
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual bool can_write(const OpenFileDescription&, size_t) const override;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
void put_char(char);

View file

@ -33,13 +33,13 @@ bool ZeroDevice::can_read(const OpenFileDescription&, size_t) const
return true;
}
KResultOr<size_t> ZeroDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
ErrorOr<size_t> ZeroDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
{
TRY(buffer.memset(0, size));
return size;
}
KResultOr<size_t> ZeroDevice::write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t size)
ErrorOr<size_t> ZeroDevice::write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t size)
{
return size;
}

View file

@ -22,8 +22,8 @@ private:
ZeroDevice();
// ^CharacterDevice
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; }
virtual StringView class_name() const override { return "ZeroDevice"sv; }

View file

@ -17,7 +17,7 @@ inline void DoubleBuffer::compute_lockfree_metadata()
m_space_for_writing = m_capacity - m_write_buffer->size;
}
KResultOr<NonnullOwnPtr<DoubleBuffer>> DoubleBuffer::try_create(size_t capacity)
ErrorOr<NonnullOwnPtr<DoubleBuffer>> DoubleBuffer::try_create(size_t capacity)
{
auto storage = TRY(KBuffer::try_create_with_size(capacity * 2, Memory::Region::Access::ReadWrite, "DoubleBuffer"));
return adopt_nonnull_own_or_enomem(new (nothrow) DoubleBuffer(capacity, move(storage)));
@ -45,7 +45,7 @@ void DoubleBuffer::flip()
compute_lockfree_metadata();
}
KResultOr<size_t> DoubleBuffer::write(const UserOrKernelBuffer& data, size_t size)
ErrorOr<size_t> DoubleBuffer::write(const UserOrKernelBuffer& data, size_t size)
{
if (!size)
return 0;
@ -60,7 +60,7 @@ KResultOr<size_t> DoubleBuffer::write(const UserOrKernelBuffer& data, size_t siz
return bytes_to_write;
}
KResultOr<size_t> DoubleBuffer::read(UserOrKernelBuffer& data, size_t size)
ErrorOr<size_t> DoubleBuffer::read(UserOrKernelBuffer& data, size_t size)
{
if (!size)
return 0;
@ -78,7 +78,7 @@ KResultOr<size_t> DoubleBuffer::read(UserOrKernelBuffer& data, size_t size)
return nread;
}
KResultOr<size_t> DoubleBuffer::peek(UserOrKernelBuffer& data, size_t size)
ErrorOr<size_t> DoubleBuffer::peek(UserOrKernelBuffer& data, size_t size)
{
if (!size)
return 0;

View file

@ -16,20 +16,20 @@ namespace Kernel {
class DoubleBuffer {
public:
static KResultOr<NonnullOwnPtr<DoubleBuffer>> try_create(size_t capacity = 65536);
KResultOr<size_t> write(const UserOrKernelBuffer&, size_t);
KResultOr<size_t> write(const u8* data, size_t size)
static ErrorOr<NonnullOwnPtr<DoubleBuffer>> try_create(size_t capacity = 65536);
ErrorOr<size_t> write(const UserOrKernelBuffer&, size_t);
ErrorOr<size_t> write(const u8* data, size_t size)
{
return write(UserOrKernelBuffer::for_kernel_buffer(const_cast<u8*>(data)), size);
}
KResultOr<size_t> read(UserOrKernelBuffer&, size_t);
KResultOr<size_t> read(u8* data, size_t size)
ErrorOr<size_t> read(UserOrKernelBuffer&, size_t);
ErrorOr<size_t> read(u8* data, size_t size)
{
auto buffer = UserOrKernelBuffer::for_kernel_buffer(data);
return read(buffer, size);
}
KResultOr<size_t> peek(UserOrKernelBuffer&, size_t);
KResultOr<size_t> peek(u8* data, size_t size)
ErrorOr<size_t> peek(UserOrKernelBuffer&, size_t);
ErrorOr<size_t> peek(u8* data, size_t size)
{
auto buffer = UserOrKernelBuffer::for_kernel_buffer(data);
return peek(buffer, size);

View file

@ -19,7 +19,7 @@ AnonymousFile::~AnonymousFile()
{
}
KResultOr<Memory::Region*> AnonymousFile::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
ErrorOr<Memory::Region*> AnonymousFile::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
{
if (offset != 0)
return EINVAL;
@ -30,7 +30,7 @@ KResultOr<Memory::Region*> AnonymousFile::mmap(Process& process, OpenFileDescrip
return process.address_space().allocate_region_with_vmobject(range, m_vmobject, offset, {}, prot, shared);
}
KResultOr<NonnullOwnPtr<KString>> AnonymousFile::pseudo_path(const OpenFileDescription&) const
ErrorOr<NonnullOwnPtr<KString>> AnonymousFile::pseudo_path(const OpenFileDescription&) const
{
return KString::try_create(":anonymous-file:"sv);
}

View file

@ -13,22 +13,22 @@ namespace Kernel {
class AnonymousFile final : public File {
public:
static KResultOr<NonnullRefPtr<AnonymousFile>> try_create(NonnullRefPtr<Memory::AnonymousVMObject> vmobject)
static ErrorOr<NonnullRefPtr<AnonymousFile>> try_create(NonnullRefPtr<Memory::AnonymousVMObject> vmobject)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) AnonymousFile(move(vmobject)));
}
virtual ~AnonymousFile() override;
virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
virtual ErrorOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
private:
virtual StringView class_name() const override { return "AnonymousFile"sv; }
virtual KResultOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const;
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const;
virtual bool can_read(const OpenFileDescription&, size_t) const override { return false; }
virtual bool can_write(const OpenFileDescription&, size_t) const override { return false; }
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return ENOTSUP; }
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return ENOTSUP; }
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return ENOTSUP; }
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return ENOTSUP; }
explicit AnonymousFile(NonnullRefPtr<Memory::AnonymousVMObject>);

View file

@ -114,7 +114,7 @@ BlockBasedFileSystem::~BlockBasedFileSystem()
{
}
KResult BlockBasedFileSystem::initialize()
ErrorOr<void> BlockBasedFileSystem::initialize()
{
VERIFY(block_size() != 0);
auto cached_block_data = TRY(KBuffer::try_create_with_size(DiskCache::EntryCount * block_size()));
@ -124,22 +124,22 @@ KResult BlockBasedFileSystem::initialize()
m_cache.with_exclusive([&](auto& cache) {
cache = move(disk_cache);
});
return KSuccess;
return {};
}
KResult BlockBasedFileSystem::write_block(BlockIndex index, const UserOrKernelBuffer& data, size_t count, size_t offset, bool allow_cache)
ErrorOr<void> BlockBasedFileSystem::write_block(BlockIndex index, const UserOrKernelBuffer& data, size_t count, size_t offset, bool allow_cache)
{
VERIFY(m_logical_block_size);
VERIFY(offset + count <= block_size());
dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::write_block {}, size={}", index, count);
return m_cache.with_exclusive([&](auto& cache) -> KResult {
return m_cache.with_exclusive([&](auto& cache) -> ErrorOr<void> {
if (!allow_cache) {
flush_specific_block_if_needed(index);
auto base_offset = index.value() * block_size() + offset;
auto nwritten = TRY(file_description().write(base_offset, data, count));
VERIFY(nwritten == count);
return KSuccess;
return {};
}
auto& entry = cache->get(index);
@ -151,7 +151,7 @@ KResult BlockBasedFileSystem::write_block(BlockIndex index, const UserOrKernelBu
cache->mark_dirty(entry);
entry.has_data = true;
return KSuccess;
return {};
});
}
@ -195,29 +195,29 @@ bool BlockBasedFileSystem::raw_write_blocks(BlockIndex index, size_t count, cons
return true;
}
KResult BlockBasedFileSystem::write_blocks(BlockIndex index, unsigned count, const UserOrKernelBuffer& data, bool allow_cache)
ErrorOr<void> BlockBasedFileSystem::write_blocks(BlockIndex index, unsigned count, const UserOrKernelBuffer& data, bool allow_cache)
{
VERIFY(m_logical_block_size);
dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::write_blocks {}, count={}", index, count);
for (unsigned i = 0; i < count; ++i) {
TRY(write_block(BlockIndex { index.value() + i }, data.offset(i * block_size()), block_size(), 0, allow_cache));
}
return KSuccess;
return {};
}
KResult BlockBasedFileSystem::read_block(BlockIndex index, UserOrKernelBuffer* buffer, size_t count, size_t offset, bool allow_cache) const
ErrorOr<void> BlockBasedFileSystem::read_block(BlockIndex index, UserOrKernelBuffer* buffer, size_t count, size_t offset, bool allow_cache) const
{
VERIFY(m_logical_block_size);
VERIFY(offset + count <= block_size());
dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::read_block {}", index);
return m_cache.with_exclusive([&](auto& cache) -> KResult {
return m_cache.with_exclusive([&](auto& cache) -> ErrorOr<void> {
if (!allow_cache) {
const_cast<BlockBasedFileSystem*>(this)->flush_specific_block_if_needed(index);
auto base_offset = index.value() * block_size() + offset;
auto nread = TRY(file_description().read(*buffer, base_offset, count));
VERIFY(nread == count);
return KSuccess;
return {};
}
auto& entry = cache->get(index);
@ -230,11 +230,11 @@ KResult BlockBasedFileSystem::read_block(BlockIndex index, UserOrKernelBuffer* b
}
if (buffer)
TRY(buffer->write(entry.data + offset, count));
return KSuccess;
return {};
});
}
KResult BlockBasedFileSystem::read_blocks(BlockIndex index, unsigned count, UserOrKernelBuffer& buffer, bool allow_cache) const
ErrorOr<void> BlockBasedFileSystem::read_blocks(BlockIndex index, unsigned count, UserOrKernelBuffer& buffer, bool allow_cache) const
{
VERIFY(m_logical_block_size);
if (!count)
@ -247,7 +247,7 @@ KResult BlockBasedFileSystem::read_blocks(BlockIndex index, unsigned count, User
out = out.offset(block_size());
}
return KSuccess;
return {};
}
void BlockBasedFileSystem::flush_specific_block_if_needed(BlockIndex index)

View file

@ -16,7 +16,7 @@ public:
TYPEDEF_DISTINCT_ORDERED_ID(u64, BlockIndex);
virtual ~BlockBasedFileSystem() override;
virtual KResult initialize() override;
virtual ErrorOr<void> initialize() override;
u64 logical_block_size() const { return m_logical_block_size; };
@ -26,8 +26,8 @@ public:
protected:
explicit BlockBasedFileSystem(OpenFileDescription&);
KResult read_block(BlockIndex, UserOrKernelBuffer*, size_t count, size_t offset = 0, bool allow_cache = true) const;
KResult read_blocks(BlockIndex, unsigned count, UserOrKernelBuffer&, bool allow_cache = true) const;
ErrorOr<void> read_block(BlockIndex, UserOrKernelBuffer*, size_t count, size_t offset = 0, bool allow_cache = true) const;
ErrorOr<void> read_blocks(BlockIndex, unsigned count, UserOrKernelBuffer&, bool allow_cache = true) const;
bool raw_read(BlockIndex, UserOrKernelBuffer&);
bool raw_write(BlockIndex, const UserOrKernelBuffer&);
@ -35,8 +35,8 @@ protected:
bool raw_read_blocks(BlockIndex index, size_t count, UserOrKernelBuffer&);
bool raw_write_blocks(BlockIndex index, size_t count, const UserOrKernelBuffer&);
KResult write_block(BlockIndex, const UserOrKernelBuffer&, size_t count, size_t offset = 0, bool allow_cache = true);
KResult write_blocks(BlockIndex, unsigned count, const UserOrKernelBuffer&, bool allow_cache = true);
ErrorOr<void> write_block(BlockIndex, const UserOrKernelBuffer&, size_t count, size_t offset = 0, bool allow_cache = true);
ErrorOr<void> write_blocks(BlockIndex, unsigned count, const UserOrKernelBuffer&, bool allow_cache = true);
u64 m_logical_block_size { 512 };

View file

@ -21,15 +21,15 @@ static MutexProtected<Custody::AllCustodiesList>& all_custodies()
return s_all_custodies;
}
KResultOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringView name, Inode& inode, int mount_flags)
ErrorOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringView name, Inode& inode, int mount_flags)
{
return all_custodies().with_exclusive([&](auto& all_custodies) -> KResultOr<NonnullRefPtr<Custody>> {
return all_custodies().with_exclusive([&](auto& all_custodies) -> ErrorOr<NonnullRefPtr<Custody>> {
for (Custody& custody : all_custodies) {
if (custody.parent() == parent
&& custody.name() == name
&& &custody.inode() == &inode
&& custody.mount_flags() == mount_flags) {
return custody;
return NonnullRefPtr { custody };
}
}
@ -66,7 +66,7 @@ Custody::~Custody()
{
}
KResultOr<NonnullOwnPtr<KString>> Custody::try_serialize_absolute_path() const
ErrorOr<NonnullOwnPtr<KString>> Custody::try_serialize_absolute_path() const
{
if (!parent())
return KString::try_create("/"sv);

View file

@ -6,11 +6,11 @@
#pragma once
#include <AK/Error.h>
#include <AK/IntrusiveList.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <Kernel/API/KResult.h>
#include <Kernel/Forward.h>
#include <Kernel/Heap/SlabAllocator.h>
#include <Kernel/KString.h>
@ -24,7 +24,7 @@ class Custody : public RefCountedBase {
public:
bool unref() const;
static KResultOr<NonnullRefPtr<Custody>> try_create(Custody* parent, StringView name, Inode&, int mount_flags);
static ErrorOr<NonnullRefPtr<Custody>> try_create(Custody* parent, StringView name, Inode&, int mount_flags);
~Custody();
@ -33,7 +33,7 @@ public:
Inode& inode() { return *m_inode; }
Inode const& inode() const { return *m_inode; }
StringView name() const { return m_name->view(); }
KResultOr<NonnullOwnPtr<KString>> try_serialize_absolute_path() const;
ErrorOr<NonnullOwnPtr<KString>> try_serialize_absolute_path() const;
String absolute_path() const;
int mount_flags() const { return m_mount_flags; }

View file

@ -12,7 +12,7 @@
namespace Kernel {
KResultOr<NonnullRefPtr<DevPtsFS>> DevPtsFS::try_create()
ErrorOr<NonnullRefPtr<DevPtsFS>> DevPtsFS::try_create()
{
return adopt_nonnull_ref_or_enomem(new (nothrow) DevPtsFS);
}
@ -25,7 +25,7 @@ DevPtsFS::~DevPtsFS()
{
}
KResult DevPtsFS::initialize()
ErrorOr<void> DevPtsFS::initialize()
{
m_root_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevPtsFSInode(*this, 1, nullptr)));
m_root_inode->m_metadata.inode = { fsid(), 1 };
@ -34,7 +34,7 @@ KResult DevPtsFS::initialize()
m_root_inode->m_metadata.gid = 0;
m_root_inode->m_metadata.size = 0;
m_root_inode->m_metadata.mtime = mepoch;
return KSuccess;
return {};
}
static unsigned inode_index_to_pty_index(InodeIndex inode_index)
@ -53,7 +53,7 @@ Inode& DevPtsFS::root_inode()
return *m_root_inode;
}
KResultOr<NonnullRefPtr<Inode>> DevPtsFS::get_inode(InodeIdentifier inode_id) const
ErrorOr<NonnullRefPtr<Inode>> DevPtsFS::get_inode(InodeIdentifier inode_id) const
{
if (inode_id.index() == 1)
return *m_root_inode;
@ -85,12 +85,12 @@ DevPtsFSInode::~DevPtsFSInode()
{
}
KResultOr<size_t> DevPtsFSInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const
ErrorOr<size_t> DevPtsFSInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const
{
VERIFY_NOT_REACHED();
}
KResultOr<size_t> DevPtsFSInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*)
ErrorOr<size_t> DevPtsFSInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*)
{
VERIFY_NOT_REACHED();
}
@ -105,7 +105,7 @@ InodeMetadata DevPtsFSInode::metadata() const
return m_metadata;
}
KResult DevPtsFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> DevPtsFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
if (identifier().index() > 1)
return ENOTDIR;
@ -121,10 +121,10 @@ KResult DevPtsFSInode::traverse_as_directory(Function<bool(FileSystem::Directory
}
});
return KSuccess;
return {};
}
KResultOr<NonnullRefPtr<Inode>> DevPtsFSInode::lookup(StringView name)
ErrorOr<NonnullRefPtr<Inode>> DevPtsFSInode::lookup(StringView name)
{
VERIFY(identifier().index() == 1);
@ -135,7 +135,7 @@ KResultOr<NonnullRefPtr<Inode>> DevPtsFSInode::lookup(StringView name)
if (!pty_index.has_value())
return ENOENT;
return SlavePTY::all_instances().with([&](auto& list) -> KResultOr<NonnullRefPtr<Inode>> {
return SlavePTY::all_instances().with([&](auto& list) -> ErrorOr<NonnullRefPtr<Inode>> {
for (SlavePTY& slave_pty : list) {
if (slave_pty.index() != pty_index.value())
continue;
@ -145,32 +145,32 @@ KResultOr<NonnullRefPtr<Inode>> DevPtsFSInode::lookup(StringView name)
});
}
KResult DevPtsFSInode::flush_metadata()
ErrorOr<void> DevPtsFSInode::flush_metadata()
{
return KSuccess;
return {};
}
KResult DevPtsFSInode::add_child(Inode&, const StringView&, mode_t)
ErrorOr<void> DevPtsFSInode::add_child(Inode&, const StringView&, mode_t)
{
return EROFS;
}
KResultOr<NonnullRefPtr<Inode>> DevPtsFSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
ErrorOr<NonnullRefPtr<Inode>> DevPtsFSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
{
return EROFS;
}
KResult DevPtsFSInode::remove_child(const StringView&)
ErrorOr<void> DevPtsFSInode::remove_child(const StringView&)
{
return EROFS;
}
KResult DevPtsFSInode::chmod(mode_t)
ErrorOr<void> DevPtsFSInode::chmod(mode_t)
{
return EROFS;
}
KResult DevPtsFSInode::chown(UserID, GroupID)
ErrorOr<void> DevPtsFSInode::chown(UserID, GroupID)
{
return EROFS;
}

View file

@ -20,16 +20,16 @@ class DevPtsFS final : public FileSystem {
public:
virtual ~DevPtsFS() override;
static KResultOr<NonnullRefPtr<DevPtsFS>> try_create();
static ErrorOr<NonnullRefPtr<DevPtsFS>> try_create();
virtual KResult initialize() override;
virtual ErrorOr<void> initialize() override;
virtual StringView class_name() const override { return "DevPtsFS"sv; }
virtual Inode& root_inode() override;
private:
DevPtsFS();
KResultOr<NonnullRefPtr<Inode>> get_inode(InodeIdentifier) const;
ErrorOr<NonnullRefPtr<Inode>> get_inode(InodeIdentifier) const;
RefPtr<DevPtsFSInode> m_root_inode;
};
@ -47,17 +47,17 @@ private:
DevPtsFSInode(DevPtsFS&, InodeIndex, SlavePTY*);
// ^Inode
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual InodeMetadata metadata() const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual KResult flush_metadata() override;
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual KResult add_child(Inode&, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(UserID, GroupID) override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual ErrorOr<void> add_child(Inode&, const StringView& name, mode_t) override;
virtual ErrorOr<void> remove_child(const StringView& name) override;
virtual ErrorOr<void> chmod(mode_t) override;
virtual ErrorOr<void> chown(UserID, GroupID) override;
WeakPtr<SlavePTY> m_pty;
InodeMetadata m_metadata;

View file

@ -11,7 +11,7 @@
namespace Kernel {
KResultOr<NonnullRefPtr<DevTmpFS>> DevTmpFS::try_create()
ErrorOr<NonnullRefPtr<DevTmpFS>> DevTmpFS::try_create()
{
return adopt_nonnull_ref_or_enomem(new (nothrow) DevTmpFS);
}
@ -32,10 +32,10 @@ DevTmpFS::~DevTmpFS()
{
}
KResult DevTmpFS::initialize()
ErrorOr<void> DevTmpFS::initialize()
{
m_root_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevTmpFSRootDirectoryInode(*this)));
return KSuccess;
return {};
}
Inode& DevTmpFS::root_inode()
@ -55,37 +55,37 @@ DevTmpFSInode::DevTmpFSInode(DevTmpFS& fs, unsigned major_number, unsigned minor
{
}
KResultOr<size_t> DevTmpFSInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const
ErrorOr<size_t> DevTmpFSInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const
{
VERIFY_NOT_REACHED();
}
KResult DevTmpFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
ErrorOr<void> DevTmpFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
{
VERIFY_NOT_REACHED();
}
KResultOr<NonnullRefPtr<Inode>> DevTmpFSInode::lookup(StringView)
ErrorOr<NonnullRefPtr<Inode>> DevTmpFSInode::lookup(StringView)
{
VERIFY_NOT_REACHED();
}
KResult DevTmpFSInode::flush_metadata()
ErrorOr<void> DevTmpFSInode::flush_metadata()
{
return KSuccess;
return {};
}
KResultOr<size_t> DevTmpFSInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*)
ErrorOr<size_t> DevTmpFSInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*)
{
VERIFY_NOT_REACHED();
}
KResultOr<NonnullRefPtr<Inode>> DevTmpFSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
ErrorOr<NonnullRefPtr<Inode>> DevTmpFSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
{
VERIFY_NOT_REACHED();
}
KResult DevTmpFSInode::add_child(Inode&, const StringView&, mode_t)
ErrorOr<void> DevTmpFSInode::add_child(Inode&, const StringView&, mode_t)
{
VERIFY_NOT_REACHED();
}
@ -134,30 +134,30 @@ InodeMetadata DevTmpFSInode::metadata() const
return metadata;
}
KResult DevTmpFSInode::remove_child(const StringView&)
ErrorOr<void> DevTmpFSInode::remove_child(const StringView&)
{
VERIFY_NOT_REACHED();
}
KResult DevTmpFSInode::chmod(mode_t mode)
ErrorOr<void> DevTmpFSInode::chmod(mode_t mode)
{
MutexLocker locker(m_inode_lock);
mode &= 0777;
if (m_mode == mode)
return KSuccess;
return {};
m_mode = mode;
return KSuccess;
return {};
}
KResult DevTmpFSInode::chown(UserID uid, GroupID gid)
ErrorOr<void> DevTmpFSInode::chown(UserID uid, GroupID gid)
{
MutexLocker locker(m_inode_lock);
m_uid = uid;
m_gid = gid;
return KSuccess;
return {};
}
KResult DevTmpFSInode::truncate(u64)
ErrorOr<void> DevTmpFSInode::truncate(u64)
{
return EPERM;
}
@ -177,7 +177,7 @@ DevTmpFSLinkInode::DevTmpFSLinkInode(DevTmpFS& fs, NonnullOwnPtr<KString> name)
{
}
KResultOr<size_t> DevTmpFSLinkInode::read_bytes(off_t offset, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const
ErrorOr<size_t> DevTmpFSLinkInode::read_bytes(off_t offset, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const
{
MutexLocker locker(m_inode_lock);
VERIFY(offset == 0);
@ -186,7 +186,7 @@ KResultOr<size_t> DevTmpFSLinkInode::read_bytes(off_t offset, size_t, UserOrKern
return m_link->length();
}
KResultOr<size_t> DevTmpFSLinkInode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& buffer, OpenFileDescription*)
ErrorOr<size_t> DevTmpFSLinkInode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& buffer, OpenFileDescription*)
{
auto new_string = TRY(buffer.try_copy_into_kstring(count));
@ -210,7 +210,7 @@ DevTmpFSDirectoryInode::~DevTmpFSDirectoryInode()
{
}
KResult DevTmpFSDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> DevTmpFSDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(m_inode_lock);
callback({ ".", identifier(), 0 });
@ -219,10 +219,10 @@ KResult DevTmpFSDirectoryInode::traverse_as_directory(Function<bool(FileSystem::
InodeIdentifier identifier = { fsid(), node.index() };
callback({ node.name(), identifier, 0 });
}
return KSuccess;
return {};
}
KResultOr<NonnullRefPtr<Inode>> DevTmpFSDirectoryInode::lookup(StringView name)
ErrorOr<NonnullRefPtr<Inode>> DevTmpFSDirectoryInode::lookup(StringView name)
{
MutexLocker locker(m_inode_lock);
for (auto& node : m_nodes) {
@ -230,27 +230,27 @@ KResultOr<NonnullRefPtr<Inode>> DevTmpFSDirectoryInode::lookup(StringView name)
return node;
}
}
return KResult(ENOENT);
return Error::from_errno(ENOENT);
}
KResult DevTmpFSDirectoryInode::remove_child(const StringView& name)
ErrorOr<void> DevTmpFSDirectoryInode::remove_child(const StringView& name)
{
MutexLocker locker(m_inode_lock);
for (auto& node : m_nodes) {
if (node.name() == name) {
m_nodes.remove(node);
return KSuccess;
return {};
}
}
return KResult(ENOENT);
return Error::from_errno(ENOENT);
}
KResultOr<NonnullRefPtr<Inode>> DevTmpFSDirectoryInode::create_child(StringView name, mode_t mode, dev_t device_mode, UserID, GroupID)
ErrorOr<NonnullRefPtr<Inode>> DevTmpFSDirectoryInode::create_child(StringView name, mode_t mode, dev_t device_mode, UserID, GroupID)
{
MutexLocker locker(m_inode_lock);
for (auto& node : m_nodes) {
if (node.name() == name)
return KResult(EEXIST);
return Error::from_errno(EEXIST);
}
InodeMetadata metadata;
@ -288,12 +288,12 @@ DevTmpFSRootDirectoryInode::DevTmpFSRootDirectoryInode(DevTmpFS& fs)
DevTmpFSRootDirectoryInode::~DevTmpFSRootDirectoryInode()
{
}
KResult DevTmpFSRootDirectoryInode::chmod(mode_t)
ErrorOr<void> DevTmpFSRootDirectoryInode::chmod(mode_t)
{
return EPERM;
}
KResult DevTmpFSRootDirectoryInode::chown(UserID, GroupID)
ErrorOr<void> DevTmpFSRootDirectoryInode::chown(UserID, GroupID)
{
return EPERM;
}
@ -314,30 +314,30 @@ StringView DevTmpFSDeviceInode::name() const
return m_name->view();
}
KResultOr<size_t> DevTmpFSDeviceInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const
ErrorOr<size_t> DevTmpFSDeviceInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const
{
MutexLocker locker(m_inode_lock);
VERIFY(!!description);
RefPtr<Device> device = DeviceManagement::the().get_device(m_major_number, m_minor_number);
if (!device)
return KResult(ENODEV);
return Error::from_errno(ENODEV);
if (!device->can_read(*description, offset))
return KResult(ENOTIMPL);
return Error::from_errno(ENOTIMPL);
auto result = const_cast<Device&>(*device).read(*description, offset, buffer, count);
if (result.is_error())
return result;
return result.value();
}
KResultOr<size_t> DevTmpFSDeviceInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& buffer, OpenFileDescription* description)
ErrorOr<size_t> DevTmpFSDeviceInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& buffer, OpenFileDescription* description)
{
MutexLocker locker(m_inode_lock);
VERIFY(!!description);
RefPtr<Device> device = DeviceManagement::the().get_device(m_major_number, m_minor_number);
if (!device)
return KResult(ENODEV);
return Error::from_errno(ENODEV);
if (!device->can_write(*description, offset))
return KResult(ENOTIMPL);
return Error::from_errno(ENOTIMPL);
auto result = const_cast<Device&>(*device).write(*description, offset, buffer, count);
if (result.is_error())
return result;

View file

@ -20,9 +20,9 @@ class DevTmpFS final : public FileSystem {
public:
virtual ~DevTmpFS() override;
static KResultOr<NonnullRefPtr<DevTmpFS>> try_create();
static ErrorOr<NonnullRefPtr<DevTmpFS>> try_create();
virtual KResult initialize() override;
virtual ErrorOr<void> initialize() override;
virtual StringView class_name() const override { return "DevTmpFS"sv; }
virtual Inode& root_inode() override;
@ -48,18 +48,18 @@ public:
protected:
explicit DevTmpFSInode(DevTmpFS&);
DevTmpFSInode(DevTmpFS&, unsigned, unsigned);
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual KResult flush_metadata() override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual InodeMetadata metadata() const override final;
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual KResult add_child(Inode&, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(UserID, GroupID) override;
virtual KResult truncate(u64) override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual ErrorOr<void> add_child(Inode&, const StringView& name, mode_t) override;
virtual ErrorOr<void> remove_child(const StringView& name) override;
virtual ErrorOr<void> chmod(mode_t) override;
virtual ErrorOr<void> chown(UserID, GroupID) override;
virtual ErrorOr<void> truncate(u64) override;
mode_t m_mode { 0600 };
UserID m_uid { 0 };
@ -96,8 +96,8 @@ private:
virtual Type node_type() const override { return m_block_device ? Type::BlockDevice : Type::CharacterDevice; }
// ^Inode
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
NonnullOwnPtr<KString> m_name;
const bool m_block_device;
@ -117,8 +117,8 @@ protected:
virtual Type node_type() const override { return Type::Link; }
// ^Inode
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
NonnullOwnPtr<KString> m_name;
OwnPtr<KString> m_link;
@ -136,10 +136,10 @@ protected:
// ^DevTmpFSInode
virtual Type node_type() const override { return Type::Directory; }
virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual KResult remove_child(const StringView& name) override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual ErrorOr<void> remove_child(const StringView& name) override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
DevTmpFSDirectoryInode(DevTmpFS&, NonnullOwnPtr<KString> name);
// ^Inode
OwnPtr<KString> m_name;
@ -161,8 +161,8 @@ private:
virtual Type node_type() const override { return Type::Directory; }
explicit DevTmpFSRootDirectoryInode(DevTmpFS&);
virtual KResult chmod(mode_t) override;
virtual KResult chown(UserID, GroupID) override;
virtual ErrorOr<void> chmod(mode_t) override;
virtual ErrorOr<void> chown(UserID, GroupID) override;
};
}

View file

@ -54,7 +54,7 @@ static unsigned divide_rounded_up(unsigned a, unsigned b)
return (a / b) + (a % b != 0);
}
KResultOr<NonnullRefPtr<Ext2FS>> Ext2FS::try_create(OpenFileDescription& file_description)
ErrorOr<NonnullRefPtr<Ext2FS>> Ext2FS::try_create(OpenFileDescription& file_description)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) Ext2FS(file_description));
}
@ -86,7 +86,7 @@ const ext2_group_desc& Ext2FS::group_descriptor(GroupIndex group_index) const
return block_group_descriptors()[group_index.value() - 1];
}
KResult Ext2FS::initialize()
ErrorOr<void> Ext2FS::initialize()
{
MutexLocker locker(m_lock);
@ -144,7 +144,7 @@ KResult Ext2FS::initialize()
}
m_root_inode = static_ptr_cast<Ext2FSInode>(TRY(get_inode({ fsid(), EXT2_ROOT_INO })));
return KSuccess;
return {};
}
Ext2FSInode& Ext2FS::root_inode()
@ -204,7 +204,7 @@ Ext2FS::BlockListShape Ext2FS::compute_block_list_shape(unsigned blocks) const
return shape;
}
KResult Ext2FSInode::write_indirect_block(BlockBasedFileSystem::BlockIndex block, Span<BlockBasedFileSystem::BlockIndex> blocks_indices)
ErrorOr<void> Ext2FSInode::write_indirect_block(BlockBasedFileSystem::BlockIndex block, Span<BlockBasedFileSystem::BlockIndex> blocks_indices)
{
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
VERIFY(blocks_indices.size() <= entries_per_block);
@ -224,7 +224,7 @@ KResult Ext2FSInode::write_indirect_block(BlockBasedFileSystem::BlockIndex block
return fs().write_block(block, buffer, stream.size());
}
KResult Ext2FSInode::grow_doubly_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFileSystem::BlockIndex> blocks_indices, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
ErrorOr<void> Ext2FSInode::grow_doubly_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFileSystem::BlockIndex> blocks_indices, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
{
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
const auto entries_per_doubly_indirect_block = entries_per_block * entries_per_block;
@ -267,7 +267,7 @@ KResult Ext2FSInode::grow_doubly_indirect_block(BlockBasedFileSystem::BlockIndex
return fs().write_block(block, buffer, stream.size());
}
KResult Ext2FSInode::shrink_doubly_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, size_t new_blocks_length, unsigned& meta_blocks)
ErrorOr<void> Ext2FSInode::shrink_doubly_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, size_t new_blocks_length, unsigned& meta_blocks)
{
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
const auto entries_per_doubly_indirect_block = entries_per_block * entries_per_block;
@ -299,10 +299,10 @@ KResult Ext2FSInode::shrink_doubly_indirect_block(BlockBasedFileSystem::BlockInd
meta_blocks--;
}
return KSuccess;
return {};
}
KResult Ext2FSInode::grow_triply_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFileSystem::BlockIndex> blocks_indices, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
ErrorOr<void> Ext2FSInode::grow_triply_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFileSystem::BlockIndex> blocks_indices, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
{
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
const auto entries_per_doubly_indirect_block = entries_per_block * entries_per_block;
@ -348,7 +348,7 @@ KResult Ext2FSInode::grow_triply_indirect_block(BlockBasedFileSystem::BlockIndex
return fs().write_block(block, buffer, stream.size());
}
KResult Ext2FSInode::shrink_triply_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, size_t new_blocks_length, unsigned& meta_blocks)
ErrorOr<void> Ext2FSInode::shrink_triply_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, size_t new_blocks_length, unsigned& meta_blocks)
{
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
const auto entries_per_doubly_indirect_block = entries_per_block * entries_per_block;
@ -383,10 +383,10 @@ KResult Ext2FSInode::shrink_triply_indirect_block(BlockBasedFileSystem::BlockInd
meta_blocks--;
}
return KSuccess;
return {};
}
KResult Ext2FSInode::flush_block_list()
ErrorOr<void> Ext2FSInode::flush_block_list()
{
MutexLocker locker(m_inode_lock);
@ -394,7 +394,7 @@ KResult Ext2FSInode::flush_block_list()
m_raw_inode.i_blocks = 0;
memset(m_raw_inode.i_block, 0, sizeof(m_raw_inode.i_block));
set_metadata_dirty(true);
return KSuccess;
return {};
}
// NOTE: There is a mismatch between i_blocks and blocks.size() since i_blocks includes meta blocks and blocks.size() does not.
@ -512,7 +512,7 @@ KResult Ext2FSInode::flush_block_list()
VERIFY(new_meta_blocks.size() == 0);
VERIFY(old_shape.meta_blocks == new_shape.meta_blocks);
if (!remaining_blocks)
return KSuccess;
return {};
dbgln("we don't know how to write qind ext2fs blocks, they don't exist anyway!");
VERIFY_NOT_REACHED();
@ -633,7 +633,7 @@ Vector<Ext2FS::BlockIndex> Ext2FSInode::compute_block_list_impl_internal(const e
return list;
}
KResult Ext2FS::free_inode(Ext2FSInode& inode)
ErrorOr<void> Ext2FS::free_inode(Ext2FSInode& inode)
{
MutexLocker locker(m_lock);
VERIFY(inode.m_raw_inode.i_links_count == 0);
@ -662,7 +662,7 @@ KResult Ext2FS::free_inode(Ext2FSInode& inode)
// Mark the inode as free.
TRY(set_inode_allocation_state(inode.index(), false));
return KSuccess;
return {};
}
void Ext2FS::flush_block_group_descriptor_table()
@ -773,7 +773,7 @@ InodeMetadata Ext2FSInode::metadata() const
return metadata;
}
KResult Ext2FSInode::flush_metadata()
ErrorOr<void> Ext2FSInode::flush_metadata()
{
MutexLocker locker(m_inode_lock);
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]::flush_metadata(): Flushing inode", identifier());
@ -786,10 +786,10 @@ KResult Ext2FSInode::flush_metadata()
}
}
set_metadata_dirty(false);
return KSuccess;
return {};
}
KResultOr<NonnullRefPtr<Inode>> Ext2FS::get_inode(InodeIdentifier inode) const
ErrorOr<NonnullRefPtr<Inode>> Ext2FS::get_inode(InodeIdentifier inode) const
{
MutexLocker locker(m_lock);
VERIFY(inode.fsid() == fsid());
@ -799,7 +799,7 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::get_inode(InodeIdentifier inode) const
if (it != m_inode_cache.end()) {
if (!it->value)
return ENOENT;
return *it->value;
return NonnullRefPtr<Inode> { *it->value };
}
}
@ -824,7 +824,7 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::get_inode(InodeIdentifier inode) const
return new_inode;
}
KResultOr<size_t> Ext2FSInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const
ErrorOr<size_t> Ext2FSInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const
{
MutexLocker inode_locker(m_inode_lock);
VERIFY(offset >= 0);
@ -878,7 +878,7 @@ KResultOr<size_t> Ext2FSInode::read_bytes(off_t offset, size_t count, UserOrKern
} else {
if (auto result = fs().read_block(block_index, &buffer_offset, num_bytes_to_copy, offset_into_block, allow_cache); result.is_error()) {
dmesgln("Ext2FSInode[{}]::read_bytes(): Failed to read block {} (index {})", identifier(), block_index.value(), bi);
return result.error();
return result.release_error();
}
}
remaining_count -= num_bytes_to_copy;
@ -888,11 +888,11 @@ KResultOr<size_t> Ext2FSInode::read_bytes(off_t offset, size_t count, UserOrKern
return nread;
}
KResult Ext2FSInode::resize(u64 new_size)
ErrorOr<void> Ext2FSInode::resize(u64 new_size)
{
auto old_size = size();
if (old_size == new_size)
return KSuccess;
return {};
if (!((u32)fs().get_features_readonly() & (u32)Ext2FS::FeaturesReadOnly::FileSize64bits) && (new_size >= static_cast<u32>(-1)))
return ENOSPC;
@ -959,10 +959,10 @@ KResult Ext2FSInode::resize(u64 new_size)
}
}
return KSuccess;
return {};
}
KResultOr<size_t> Ext2FSInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& data, OpenFileDescription* description)
ErrorOr<size_t> Ext2FSInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& data, OpenFileDescription* description)
{
VERIFY(offset >= 0);
@ -1018,7 +1018,7 @@ KResultOr<size_t> Ext2FSInode::write_bytes(off_t offset, size_t count, const Use
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]::write_bytes(): Writing block {} (offset_into_block: {})", identifier(), m_block_list[bi.value()], offset_into_block);
if (auto result = fs().write_block(m_block_list[bi.value()], data.offset(nwritten), num_bytes_to_copy, offset_into_block, allow_cache); result.is_error()) {
dbgln("Ext2FSInode[{}]::write_bytes(): Failed to write block {} (index {})", identifier(), m_block_list[bi.value()], bi);
return result;
return result.release_error();
}
remaining_count -= num_bytes_to_copy;
nwritten += num_bytes_to_copy;
@ -1059,7 +1059,7 @@ Ext2FS::FeaturesReadOnly Ext2FS::get_features_readonly() const
return Ext2FS::FeaturesReadOnly::None;
}
KResult Ext2FSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> Ext2FSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
VERIFY(is_directory());
@ -1081,16 +1081,16 @@ KResult Ext2FSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEn
if (entry->inode != 0) {
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]::traverse_as_directory(): inode {}, name_len: {}, rec_len: {}, file_type: {}, name: {}", identifier(), entry->inode, entry->name_len, entry->rec_len, entry->file_type, StringView(entry->name, entry->name_len));
if (!callback({ { entry->name, entry->name_len }, { fsid(), entry->inode }, entry->file_type }))
return KSuccess;
return {};
}
entry = (ext2_dir_entry_2*)((char*)entry + entry->rec_len);
}
}
return KSuccess;
return {};
}
KResult Ext2FSInode::write_directory(Vector<Ext2FSDirectoryEntry>& entries)
ErrorOr<void> Ext2FSInode::write_directory(Vector<Ext2FSDirectoryEntry>& entries)
{
MutexLocker locker(m_inode_lock);
auto block_size = fs().block_size();
@ -1147,17 +1147,17 @@ KResult Ext2FSInode::write_directory(Vector<Ext2FSDirectoryEntry>& entries)
set_metadata_dirty(true);
if (nwritten != directory_data.size())
return EIO;
return KSuccess;
return {};
}
KResultOr<NonnullRefPtr<Inode>> Ext2FSInode::create_child(StringView name, mode_t mode, dev_t dev, UserID uid, GroupID gid)
ErrorOr<NonnullRefPtr<Inode>> Ext2FSInode::create_child(StringView name, mode_t mode, dev_t dev, UserID uid, GroupID gid)
{
if (::is_directory(mode))
return fs().create_directory(*this, name, mode, uid, gid);
return fs().create_inode(*this, name, mode, dev, uid, gid);
}
KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode)
ErrorOr<void> Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode)
{
MutexLocker locker(m_inode_lock);
VERIFY(is_directory());
@ -1192,10 +1192,10 @@ KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode
m_lookup_cache.set(name, child.index());
did_add_child(child.identifier(), name);
return KSuccess;
return {};
}
KResult Ext2FSInode::remove_child(const StringView& name)
ErrorOr<void> Ext2FSInode::remove_child(const StringView& name)
{
MutexLocker locker(m_inode_lock);
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]::remove_child(): Removing '{}'", identifier(), name);
@ -1225,7 +1225,7 @@ KResult Ext2FSInode::remove_child(const StringView& name)
TRY(child_inode->decrement_link_count());
did_remove_child(child_id, name);
return KSuccess;
return {};
}
u64 Ext2FS::inodes_per_block() const
@ -1247,7 +1247,7 @@ u64 Ext2FS::blocks_per_group() const
return EXT2_BLOCKS_PER_GROUP(&super_block());
}
KResult Ext2FS::write_ext2_inode(InodeIndex inode, ext2_inode const& e2inode)
ErrorOr<void> Ext2FS::write_ext2_inode(InodeIndex inode, ext2_inode const& e2inode)
{
BlockIndex block_index;
unsigned offset;
@ -1257,7 +1257,7 @@ KResult Ext2FS::write_ext2_inode(InodeIndex inode, ext2_inode const& e2inode)
return write_block(block_index, buffer, inode_size(), offset);
}
auto Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count) -> KResultOr<Vector<BlockIndex>>
auto Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count) -> ErrorOr<Vector<BlockIndex>>
{
dbgln_if(EXT2_DEBUG, "Ext2FS: allocate_blocks(preferred group: {}, count {})", preferred_group_index, count);
if (count == 0)
@ -1304,10 +1304,7 @@ auto Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count) ->
dbgln_if(EXT2_DEBUG, "Ext2FS: allocating free region of size: {} [{}]", free_region_size, group_index);
for (size_t i = 0; i < free_region_size; ++i) {
BlockIndex block_index = (first_unset_bit_index.value() + i) + first_block_in_group.value();
if (auto result = set_block_allocation_state(block_index, true); result.is_error()) {
dbgln("Ext2FS: Failed to allocate block {} in allocate_blocks()", block_index);
return result;
}
TRY(set_block_allocation_state(block_index, true));
blocks.unchecked_append(block_index);
dbgln_if(EXT2_DEBUG, " allocated > {}", block_index);
}
@ -1317,7 +1314,7 @@ auto Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count) ->
return blocks;
}
KResultOr<InodeIndex> Ext2FS::allocate_inode(GroupIndex preferred_group)
ErrorOr<InodeIndex> Ext2FS::allocate_inode(GroupIndex preferred_group)
{
dbgln_if(EXT2_DEBUG, "Ext2FS: allocate_inode(preferred_group: {})", preferred_group);
MutexLocker locker(m_lock);
@ -1391,7 +1388,7 @@ auto Ext2FS::group_index_from_inode(InodeIndex inode) const -> GroupIndex
return (inode.value() - 1) / inodes_per_group() + 1;
}
KResultOr<bool> Ext2FS::get_inode_allocation_state(InodeIndex index) const
ErrorOr<bool> Ext2FS::get_inode_allocation_state(InodeIndex index) const
{
MutexLocker locker(m_lock);
if (index == 0)
@ -1405,7 +1402,7 @@ KResultOr<bool> Ext2FS::get_inode_allocation_state(InodeIndex index) const
return cached_bitmap->bitmap(inodes_per_group()).get(bit_index);
}
KResult Ext2FS::update_bitmap_block(BlockIndex bitmap_block, size_t bit_index, bool new_state, u32& super_block_counter, u16& group_descriptor_counter)
ErrorOr<void> Ext2FS::update_bitmap_block(BlockIndex bitmap_block, size_t bit_index, bool new_state, u32& super_block_counter, u16& group_descriptor_counter)
{
auto* cached_bitmap = TRY(get_bitmap_block(bitmap_block));
bool current_state = cached_bitmap->bitmap(blocks_per_group()).get(bit_index);
@ -1426,10 +1423,10 @@ KResult Ext2FS::update_bitmap_block(BlockIndex bitmap_block, size_t bit_index, b
m_super_block_dirty = true;
m_block_group_descriptors_dirty = true;
return KSuccess;
return {};
}
KResult Ext2FS::set_inode_allocation_state(InodeIndex inode_index, bool new_state)
ErrorOr<void> Ext2FS::set_inode_allocation_state(InodeIndex inode_index, bool new_state)
{
MutexLocker locker(m_lock);
auto group_index = group_index_from_inode(inode_index);
@ -1446,26 +1443,23 @@ Ext2FS::BlockIndex Ext2FS::first_block_index() const
return block_size() == 1024 ? 1 : 0;
}
KResultOr<Ext2FS::CachedBitmap*> Ext2FS::get_bitmap_block(BlockIndex bitmap_block_index)
ErrorOr<Ext2FS::CachedBitmap*> Ext2FS::get_bitmap_block(BlockIndex bitmap_block_index)
{
for (auto& cached_bitmap : m_cached_bitmaps) {
if (cached_bitmap->bitmap_block_index == bitmap_block_index)
return cached_bitmap;
return cached_bitmap.ptr();
}
auto block = TRY(KBuffer::try_create_with_size(block_size(), Memory::Region::Access::ReadWrite, "Ext2FS: Cached bitmap block"));
auto buffer = UserOrKernelBuffer::for_kernel_buffer(block->data());
if (auto result = read_block(bitmap_block_index, &buffer, block_size()); result.is_error()) {
dbgln("Ext2FS: Failed to load bitmap block {}", bitmap_block_index);
return result;
}
TRY(read_block(bitmap_block_index, &buffer, block_size()));
auto new_bitmap = TRY(adopt_nonnull_own_or_enomem(new (nothrow) CachedBitmap(bitmap_block_index, move(block))));
if (!m_cached_bitmaps.try_append(move(new_bitmap)))
return ENOMEM;
return m_cached_bitmaps.last();
return m_cached_bitmaps.last().ptr();
}
KResult Ext2FS::set_block_allocation_state(BlockIndex block_index, bool new_state)
ErrorOr<void> Ext2FS::set_block_allocation_state(BlockIndex block_index, bool new_state)
{
VERIFY(block_index != 0);
MutexLocker locker(m_lock);
@ -1479,7 +1473,7 @@ KResult Ext2FS::set_block_allocation_state(BlockIndex block_index, bool new_stat
return update_bitmap_block(bgd.bg_block_bitmap, bit_index, new_state, m_super_block.s_free_blocks_count, bgd.bg_free_blocks_count);
}
KResult Ext2FS::create_directory(Ext2FSInode& parent_inode, StringView name, mode_t mode, UserID uid, GroupID gid)
ErrorOr<NonnullRefPtr<Inode>> Ext2FS::create_directory(Ext2FSInode& parent_inode, StringView name, mode_t mode, UserID uid, GroupID gid)
{
MutexLocker locker(m_lock);
VERIFY(is_directory(mode));
@ -1499,10 +1493,10 @@ KResult Ext2FS::create_directory(Ext2FSInode& parent_inode, StringView name, mod
++bgd.bg_used_dirs_count;
m_block_group_descriptors_dirty = true;
return KSuccess;
return inode;
}
KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode, StringView name, mode_t mode, dev_t dev, UserID uid, GroupID gid)
ErrorOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode, StringView name, mode_t mode, dev_t dev, UserID uid, GroupID gid)
{
if (name.length() > EXT2_NAME_LEN)
return ENAMETOOLONG;
@ -1542,11 +1536,11 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode,
return new_inode;
}
KResult Ext2FSInode::populate_lookup_cache() const
ErrorOr<void> Ext2FSInode::populate_lookup_cache() const
{
MutexLocker locker(m_inode_lock);
if (!m_lookup_cache.is_empty())
return KSuccess;
return {};
HashMap<String, InodeIndex> children;
TRY(traverse_as_directory([&children](auto& entry) {
@ -1556,10 +1550,10 @@ KResult Ext2FSInode::populate_lookup_cache() const
VERIFY(m_lookup_cache.is_empty());
m_lookup_cache = move(children);
return KSuccess;
return {};
}
KResultOr<NonnullRefPtr<Inode>> Ext2FSInode::lookup(StringView name)
ErrorOr<NonnullRefPtr<Inode>> Ext2FSInode::lookup(StringView name)
{
VERIFY(is_directory());
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): Looking up '{}'", identifier(), name);
@ -1584,37 +1578,37 @@ void Ext2FSInode::one_ref_left()
// FIXME: I would like to not live forever, but uncached Ext2FS is fucking painful right now.
}
KResult Ext2FSInode::set_atime(time_t t)
ErrorOr<void> Ext2FSInode::set_atime(time_t t)
{
MutexLocker locker(m_inode_lock);
if (fs().is_readonly())
return EROFS;
m_raw_inode.i_atime = t;
set_metadata_dirty(true);
return KSuccess;
return {};
}
KResult Ext2FSInode::set_ctime(time_t t)
ErrorOr<void> Ext2FSInode::set_ctime(time_t t)
{
MutexLocker locker(m_inode_lock);
if (fs().is_readonly())
return EROFS;
m_raw_inode.i_ctime = t;
set_metadata_dirty(true);
return KSuccess;
return {};
}
KResult Ext2FSInode::set_mtime(time_t t)
ErrorOr<void> Ext2FSInode::set_mtime(time_t t)
{
MutexLocker locker(m_inode_lock);
if (fs().is_readonly())
return EROFS;
m_raw_inode.i_mtime = t;
set_metadata_dirty(true);
return KSuccess;
return {};
}
KResult Ext2FSInode::increment_link_count()
ErrorOr<void> Ext2FSInode::increment_link_count()
{
MutexLocker locker(m_inode_lock);
if (fs().is_readonly())
@ -1624,10 +1618,10 @@ KResult Ext2FSInode::increment_link_count()
return EMLINK;
++m_raw_inode.i_links_count;
set_metadata_dirty(true);
return KSuccess;
return {};
}
KResult Ext2FSInode::decrement_link_count()
ErrorOr<void> Ext2FSInode::decrement_link_count()
{
MutexLocker locker(m_inode_lock);
if (fs().is_readonly())
@ -1642,7 +1636,7 @@ KResult Ext2FSInode::decrement_link_count()
if (ref_count() == 1 && m_raw_inode.i_links_count == 0)
fs().uncache_inode(index());
return KSuccess;
return {};
}
void Ext2FS::uncache_inode(InodeIndex index)
@ -1651,38 +1645,38 @@ void Ext2FS::uncache_inode(InodeIndex index)
m_inode_cache.remove(index);
}
KResult Ext2FSInode::chmod(mode_t mode)
ErrorOr<void> Ext2FSInode::chmod(mode_t mode)
{
MutexLocker locker(m_inode_lock);
if (m_raw_inode.i_mode == mode)
return KSuccess;
return {};
m_raw_inode.i_mode = mode;
set_metadata_dirty(true);
return KSuccess;
return {};
}
KResult Ext2FSInode::chown(UserID uid, GroupID gid)
ErrorOr<void> Ext2FSInode::chown(UserID uid, GroupID gid)
{
MutexLocker locker(m_inode_lock);
if (m_raw_inode.i_uid == uid && m_raw_inode.i_gid == gid)
return KSuccess;
return {};
m_raw_inode.i_uid = uid.value();
m_raw_inode.i_gid = gid.value();
set_metadata_dirty(true);
return KSuccess;
return {};
}
KResult Ext2FSInode::truncate(u64 size)
ErrorOr<void> Ext2FSInode::truncate(u64 size)
{
MutexLocker locker(m_inode_lock);
if (static_cast<u64>(m_raw_inode.i_size) == size)
return KSuccess;
return {};
TRY(resize(size));
set_metadata_dirty(true);
return KSuccess;
return {};
}
KResultOr<int> Ext2FSInode::get_block_address(int index)
ErrorOr<int> Ext2FSInode::get_block_address(int index)
{
MutexLocker locker(m_inode_lock);
@ -1719,7 +1713,7 @@ unsigned Ext2FS::free_inode_count() const
return super_block().s_free_inodes_count;
}
KResult Ext2FS::prepare_to_unmount()
ErrorOr<void> Ext2FS::prepare_to_unmount()
{
MutexLocker locker(m_lock);
@ -1730,6 +1724,6 @@ KResult Ext2FS::prepare_to_unmount()
m_inode_cache.clear();
m_root_inode = nullptr;
return KSuccess;
return {};
}
}

View file

@ -38,34 +38,34 @@ public:
private:
// ^Inode
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual InodeMetadata metadata() const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual KResult flush_metadata() override;
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) override;
virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual KResult add_child(Inode& child, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override;
virtual KResult set_atime(time_t) override;
virtual KResult set_ctime(time_t) override;
virtual KResult set_mtime(time_t) override;
virtual KResult increment_link_count() override;
virtual KResult decrement_link_count() override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(UserID, GroupID) override;
virtual KResult truncate(u64) override;
virtual KResultOr<int> get_block_address(int) override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) override;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual ErrorOr<void> add_child(Inode& child, const StringView& name, mode_t) override;
virtual ErrorOr<void> remove_child(const StringView& name) override;
virtual ErrorOr<void> set_atime(time_t) override;
virtual ErrorOr<void> set_ctime(time_t) override;
virtual ErrorOr<void> set_mtime(time_t) override;
virtual ErrorOr<void> increment_link_count() override;
virtual ErrorOr<void> decrement_link_count() override;
virtual ErrorOr<void> chmod(mode_t) override;
virtual ErrorOr<void> chown(UserID, GroupID) override;
virtual ErrorOr<void> truncate(u64) override;
virtual ErrorOr<int> get_block_address(int) override;
KResult write_directory(Vector<Ext2FSDirectoryEntry>&);
KResult populate_lookup_cache() const;
KResult resize(u64);
KResult write_indirect_block(BlockBasedFileSystem::BlockIndex, Span<BlockBasedFileSystem::BlockIndex>);
KResult grow_doubly_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, Span<BlockBasedFileSystem::BlockIndex>, Vector<BlockBasedFileSystem::BlockIndex>&, unsigned&);
KResult shrink_doubly_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, size_t, unsigned&);
KResult grow_triply_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, Span<BlockBasedFileSystem::BlockIndex>, Vector<BlockBasedFileSystem::BlockIndex>&, unsigned&);
KResult shrink_triply_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, size_t, unsigned&);
KResult flush_block_list();
ErrorOr<void> write_directory(Vector<Ext2FSDirectoryEntry>&);
ErrorOr<void> populate_lookup_cache() const;
ErrorOr<void> resize(u64);
ErrorOr<void> write_indirect_block(BlockBasedFileSystem::BlockIndex, Span<BlockBasedFileSystem::BlockIndex>);
ErrorOr<void> grow_doubly_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, Span<BlockBasedFileSystem::BlockIndex>, Vector<BlockBasedFileSystem::BlockIndex>&, unsigned&);
ErrorOr<void> shrink_doubly_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, size_t, unsigned&);
ErrorOr<void> grow_triply_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, Span<BlockBasedFileSystem::BlockIndex>, Vector<BlockBasedFileSystem::BlockIndex>&, unsigned&);
ErrorOr<void> shrink_triply_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, size_t, unsigned&);
ErrorOr<void> flush_block_list();
Vector<BlockBasedFileSystem::BlockIndex> compute_block_list() const;
Vector<BlockBasedFileSystem::BlockIndex> compute_block_list_with_meta_blocks() const;
Vector<BlockBasedFileSystem::BlockIndex> compute_block_list_impl(bool include_block_list_blocks) const;
@ -89,17 +89,17 @@ public:
FileSize64bits = 1 << 1,
};
static KResultOr<NonnullRefPtr<Ext2FS>> try_create(OpenFileDescription&);
static ErrorOr<NonnullRefPtr<Ext2FS>> try_create(OpenFileDescription&);
virtual ~Ext2FS() override;
virtual KResult initialize() override;
virtual ErrorOr<void> initialize() override;
virtual unsigned total_block_count() const override;
virtual unsigned free_block_count() const override;
virtual unsigned total_inode_count() const override;
virtual unsigned free_inode_count() const override;
virtual KResult prepare_to_unmount() override;
virtual ErrorOr<void> prepare_to_unmount() override;
virtual bool supports_watchers() const override { return true; }
@ -122,30 +122,30 @@ private:
u64 blocks_per_group() const;
u64 inode_size() const;
KResult write_ext2_inode(InodeIndex, ext2_inode const&);
ErrorOr<void> write_ext2_inode(InodeIndex, ext2_inode const&);
bool find_block_containing_inode(InodeIndex, BlockIndex& block_index, unsigned& offset) const;
bool flush_super_block();
virtual StringView class_name() const override { return "Ext2FS"sv; }
virtual Ext2FSInode& root_inode() override;
KResultOr<NonnullRefPtr<Inode>> get_inode(InodeIdentifier) const;
KResultOr<NonnullRefPtr<Inode>> create_inode(Ext2FSInode& parent_inode, StringView name, mode_t, dev_t, UserID, GroupID);
KResult create_directory(Ext2FSInode& parent_inode, StringView name, mode_t, UserID, GroupID);
ErrorOr<NonnullRefPtr<Inode>> get_inode(InodeIdentifier) const;
ErrorOr<NonnullRefPtr<Inode>> create_inode(Ext2FSInode& parent_inode, StringView name, mode_t, dev_t, UserID, GroupID);
ErrorOr<NonnullRefPtr<Inode>> create_directory(Ext2FSInode& parent_inode, StringView name, mode_t, UserID, GroupID);
virtual void flush_writes() override;
BlockIndex first_block_index() const;
KResultOr<InodeIndex> allocate_inode(GroupIndex preferred_group = 0);
KResultOr<Vector<BlockIndex>> allocate_blocks(GroupIndex preferred_group_index, size_t count);
ErrorOr<InodeIndex> allocate_inode(GroupIndex preferred_group = 0);
ErrorOr<Vector<BlockIndex>> allocate_blocks(GroupIndex preferred_group_index, size_t count);
GroupIndex group_index_from_inode(InodeIndex) const;
GroupIndex group_index_from_block_index(BlockIndex) const;
KResultOr<bool> get_inode_allocation_state(InodeIndex) const;
KResult set_inode_allocation_state(InodeIndex, bool);
KResult set_block_allocation_state(BlockIndex, bool);
ErrorOr<bool> get_inode_allocation_state(InodeIndex) const;
ErrorOr<void> set_inode_allocation_state(InodeIndex, bool);
ErrorOr<void> set_block_allocation_state(BlockIndex, bool);
void uncache_inode(InodeIndex);
KResult free_inode(Ext2FSInode&);
ErrorOr<void> free_inode(Ext2FSInode&);
struct BlockListShape {
unsigned direct_blocks { 0 };
@ -179,8 +179,8 @@ private:
BitmapView bitmap(u32 blocks_per_group) { return BitmapView { buffer->data(), blocks_per_group }; }
};
KResultOr<CachedBitmap*> get_bitmap_block(BlockIndex);
KResult update_bitmap_block(BlockIndex bitmap_block, size_t bit_index, bool new_state, u32& super_block_counter, u16& group_descriptor_counter);
ErrorOr<CachedBitmap*> get_bitmap_block(BlockIndex);
ErrorOr<void> update_bitmap_block(BlockIndex bitmap_block, size_t bit_index, bool new_state, u32& super_block_counter, u16& group_descriptor_counter);
Vector<OwnPtr<CachedBitmap>> m_cached_bitmaps;
RefPtr<Ext2FSInode> m_root_inode;

View file

@ -16,13 +16,13 @@ namespace Kernel {
static Atomic<int> s_next_fifo_id = 1;
KResultOr<NonnullRefPtr<FIFO>> FIFO::try_create(UserID uid)
ErrorOr<NonnullRefPtr<FIFO>> FIFO::try_create(UserID uid)
{
auto buffer = TRY(DoubleBuffer::try_create());
return adopt_nonnull_ref_or_enomem(new (nothrow) FIFO(uid, move(buffer)));
}
KResultOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direction direction)
ErrorOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direction direction)
{
auto description = TRY(OpenFileDescription::try_create(*this));
attach(direction);
@ -30,7 +30,7 @@ KResultOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Directi
return description;
}
KResultOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction_blocking(FIFO::Direction direction)
ErrorOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction_blocking(FIFO::Direction direction)
{
MutexLocker locker(m_open_lock);
@ -109,7 +109,7 @@ bool FIFO::can_write(const OpenFileDescription&, size_t) const
return m_buffer->space_for_writing() || !m_readers;
}
KResultOr<size_t> FIFO::read(OpenFileDescription& fd, u64, UserOrKernelBuffer& buffer, size_t size)
ErrorOr<size_t> FIFO::read(OpenFileDescription& fd, u64, UserOrKernelBuffer& buffer, size_t size)
{
if (m_buffer->is_empty()) {
if (!m_writers)
@ -120,7 +120,7 @@ KResultOr<size_t> FIFO::read(OpenFileDescription& fd, u64, UserOrKernelBuffer& b
return m_buffer->read(buffer, size);
}
KResultOr<size_t> FIFO::write(OpenFileDescription& fd, u64, const UserOrKernelBuffer& buffer, size_t size)
ErrorOr<size_t> FIFO::write(OpenFileDescription& fd, u64, const UserOrKernelBuffer& buffer, size_t size)
{
if (!m_readers) {
Thread::current()->send_signal(SIGPIPE, &Process::current());
@ -132,16 +132,16 @@ KResultOr<size_t> FIFO::write(OpenFileDescription& fd, u64, const UserOrKernelBu
return m_buffer->write(buffer, size);
}
KResultOr<NonnullOwnPtr<KString>> FIFO::pseudo_path(const OpenFileDescription&) const
ErrorOr<NonnullOwnPtr<KString>> FIFO::pseudo_path(const OpenFileDescription&) const
{
return KString::try_create(String::formatted("fifo:{}", m_fifo_id));
}
KResult FIFO::stat(::stat& st) const
ErrorOr<void> FIFO::stat(::stat& st) const
{
memset(&st, 0, sizeof(st));
st.st_mode = S_IFIFO;
return KSuccess;
return {};
}
}

View file

@ -24,13 +24,13 @@ public:
Writer
};
static KResultOr<NonnullRefPtr<FIFO>> try_create(UserID);
static ErrorOr<NonnullRefPtr<FIFO>> try_create(UserID);
virtual ~FIFO() override;
UserID uid() const { return m_uid; }
KResultOr<NonnullRefPtr<OpenFileDescription>> open_direction(Direction);
KResultOr<NonnullRefPtr<OpenFileDescription>> open_direction_blocking(Direction);
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_direction(Direction);
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_direction_blocking(Direction);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
@ -40,12 +40,12 @@ public:
private:
// ^File
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual KResult stat(::stat&) const override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<void> stat(::stat&) const override;
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual bool can_write(const OpenFileDescription&, size_t) const override;
virtual KResultOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
virtual StringView class_name() const override { return "FIFO"sv; }
virtual bool is_fifo() const override { return true; }

View file

@ -29,7 +29,7 @@ bool File::unref() const
return true;
}
KResultOr<NonnullRefPtr<OpenFileDescription>> File::open(int options)
ErrorOr<NonnullRefPtr<OpenFileDescription>> File::open(int options)
{
auto description = OpenFileDescription::try_create(*this);
if (!description.is_error()) {
@ -39,25 +39,25 @@ KResultOr<NonnullRefPtr<OpenFileDescription>> File::open(int options)
return description;
}
KResult File::close()
ErrorOr<void> File::close()
{
return KSuccess;
return {};
}
KResult File::ioctl(OpenFileDescription&, unsigned, Userspace<void*>)
ErrorOr<void> File::ioctl(OpenFileDescription&, unsigned, Userspace<void*>)
{
return ENOTTY;
}
KResultOr<Memory::Region*> File::mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64, int, bool)
ErrorOr<Memory::Region*> File::mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64, int, bool)
{
return ENODEV;
}
KResult File::attach(OpenFileDescription&)
ErrorOr<void> File::attach(OpenFileDescription&)
{
m_attach_count++;
return KSuccess;
return {};
}
void File::detach(OpenFileDescription&)

View file

@ -6,12 +6,12 @@
#pragma once
#include <AK/Error.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <AK/Weakable.h>
#include <Kernel/API/KResult.h>
#include <Kernel/Forward.h>
#include <Kernel/UnixTypes.h>
#include <Kernel/UserOrKernelBuffer.h>
@ -78,28 +78,28 @@ public:
virtual void before_removing() { }
virtual ~File();
virtual KResultOr<NonnullRefPtr<OpenFileDescription>> open(int options);
virtual KResult close();
virtual ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options);
virtual ErrorOr<void> close();
virtual bool can_read(const OpenFileDescription&, size_t) const = 0;
virtual bool can_write(const OpenFileDescription&, size_t) const = 0;
virtual KResult attach(OpenFileDescription&);
virtual ErrorOr<void> attach(OpenFileDescription&);
virtual void detach(OpenFileDescription&);
virtual void did_seek(OpenFileDescription&, off_t) { }
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) = 0;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) = 0;
virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg);
virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared);
virtual KResult stat(::stat&) const { return EBADF; }
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) = 0;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) = 0;
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg);
virtual ErrorOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared);
virtual ErrorOr<void> stat(::stat&) const { return EBADF; }
// Although this might be better described "name" or "description", these terms already have other meanings.
virtual KResultOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const = 0;
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const = 0;
virtual KResult truncate(u64) { return EINVAL; }
virtual KResult sync() { return EINVAL; }
virtual KResult chown(OpenFileDescription&, UserID, GroupID) { return EBADF; }
virtual KResult chmod(OpenFileDescription&, mode_t) { return EBADF; }
virtual ErrorOr<void> truncate(u64) { return EINVAL; }
virtual ErrorOr<void> sync() { return EINVAL; }
virtual ErrorOr<void> chown(OpenFileDescription&, UserID, GroupID) { return EBADF; }
virtual ErrorOr<void> chmod(OpenFileDescription&, mode_t) { return EBADF; }
virtual StringView class_name() const = 0;

View file

@ -6,10 +6,10 @@
#pragma once
#include <AK/Error.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/StringView.h>
#include <Kernel/API/KResult.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
#include <Kernel/Forward.h>
#include <Kernel/Locking/Mutex.h>
@ -31,7 +31,7 @@ public:
static void sync();
static void lock_all();
virtual KResult initialize() = 0;
virtual ErrorOr<void> initialize() = 0;
virtual StringView class_name() const = 0;
virtual Inode& root_inode() = 0;
virtual bool supports_watchers() const { return false; }
@ -43,7 +43,7 @@ public:
virtual unsigned total_inode_count() const { return 0; }
virtual unsigned free_inode_count() const { return 0; }
virtual KResult prepare_to_unmount() { return KSuccess; }
virtual ErrorOr<void> prepare_to_unmount() { return {}; }
struct DirectoryEntryView {
DirectoryEntryView(const StringView& name, InodeIdentifier, u8 file_type);

View file

@ -46,7 +46,7 @@ public:
ISO::DirectoryRecordHeader const* operator*() { return m_current_header; }
// Recurses into subdirectories. May fail.
KResultOr<bool> next()
ErrorOr<bool> next()
{
if (done())
return false;
@ -148,10 +148,10 @@ public:
}
private:
KResult read_directory_contents()
ErrorOr<void> read_directory_contents()
{
m_current_directory.entry = TRY(m_fs.directory_entry_for_record({}, m_current_header));
return KSuccess;
return {};
}
void get_header()
@ -171,7 +171,7 @@ private:
Vector<DirectoryState> m_directory_stack;
};
KResultOr<NonnullRefPtr<ISO9660FS>> ISO9660FS::try_create(OpenFileDescription& description)
ErrorOr<NonnullRefPtr<ISO9660FS>> ISO9660FS::try_create(OpenFileDescription& description)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) ISO9660FS(description));
}
@ -187,12 +187,12 @@ ISO9660FS::~ISO9660FS()
{
}
KResult ISO9660FS::initialize()
ErrorOr<void> ISO9660FS::initialize()
{
TRY(BlockBasedFileSystem::initialize());
TRY(parse_volume_set());
TRY(create_root_inode());
return KSuccess;
return {};
}
Inode& ISO9660FS::root_inode()
@ -211,7 +211,7 @@ unsigned ISO9660FS::total_inode_count() const
if (!m_cached_inode_count) {
auto result = calculate_inode_count();
if (result.is_error()) {
// FIXME: This should be able to return a KResult.
// FIXME: This should be able to return a ErrorOr<void>.
return 0;
}
}
@ -228,7 +228,7 @@ u8 ISO9660FS::internal_file_type_to_directory_entry_type(const DirectoryEntryVie
return DT_REG;
}
KResult ISO9660FS::parse_volume_set()
ErrorOr<void> ISO9660FS::parse_volume_set()
{
VERIFY(!m_primary_volume);
@ -278,10 +278,10 @@ all_headers_read:
}
m_logical_block_size = LittleEndian { m_primary_volume->logical_block_size.little };
return KSuccess;
return {};
}
KResult ISO9660FS::create_root_inode()
ErrorOr<void> ISO9660FS::create_root_inode()
{
if (!m_primary_volume) {
dbgln_if(ISO9660_DEBUG, "Primary volume doesn't exist, can't create root inode");
@ -289,10 +289,10 @@ KResult ISO9660FS::create_root_inode()
}
m_root_inode = TRY(ISO9660Inode::try_create_from_directory_record(*this, m_primary_volume->root_directory_record_header, {}));
return KSuccess;
return {};
}
KResult ISO9660FS::calculate_inode_count() const
ErrorOr<void> ISO9660FS::calculate_inode_count() const
{
if (!m_primary_volume) {
dbgln_if(ISO9660_DEBUG, "Primary volume doesn't exist, can't calculate inode count");
@ -323,13 +323,13 @@ KResult ISO9660FS::calculate_inode_count() const
}));
m_cached_inode_count = inode_count;
return KSuccess;
return {};
}
KResult ISO9660FS::visit_directory_record(ISO::DirectoryRecordHeader const& record, Function<KResultOr<RecursionDecision>(ISO::DirectoryRecordHeader const*)> const& visitor) const
ErrorOr<void> ISO9660FS::visit_directory_record(ISO::DirectoryRecordHeader const& record, Function<ErrorOr<RecursionDecision>(ISO::DirectoryRecordHeader const*)> const& visitor) const
{
if (!has_flag(record.file_flags, ISO::FileFlags::Directory)) {
return KSuccess;
return {};
}
ISO9660DirectoryIterator iterator { const_cast<ISO9660FS&>(*this), record };
@ -342,7 +342,7 @@ KResult ISO9660FS::visit_directory_record(ISO::DirectoryRecordHeader const& reco
if (!has_moved) {
// If next() hasn't moved then we have read through all the
// directories, and can exit.
return KSuccess;
return {};
}
continue;
@ -352,20 +352,20 @@ KResult ISO9660FS::visit_directory_record(ISO::DirectoryRecordHeader const& reco
if (iterator.skip())
break;
if (!iterator.go_up())
return KSuccess;
return {};
}
continue;
}
case RecursionDecision::Break:
return KSuccess;
return {};
}
}
return KSuccess;
return {};
}
KResultOr<NonnullRefPtr<ISO9660FS::DirectoryEntry>> ISO9660FS::directory_entry_for_record(Badge<ISO9660DirectoryIterator>, ISO::DirectoryRecordHeader const* record)
ErrorOr<NonnullRefPtr<ISO9660FS::DirectoryEntry>> ISO9660FS::directory_entry_for_record(Badge<ISO9660DirectoryIterator>, ISO::DirectoryRecordHeader const* record)
{
u32 extent_location = LittleEndian { record->extent_location.little };
u32 data_length = LittleEndian { record->data_length.little };
@ -407,7 +407,7 @@ u32 ISO9660FS::calculate_directory_entry_cache_key(ISO::DirectoryRecordHeader co
return LittleEndian { record.extent_location.little };
}
KResultOr<size_t> ISO9660Inode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, OpenFileDescription*) const
ErrorOr<size_t> ISO9660Inode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, OpenFileDescription*) const
{
MutexLocker inode_locker(m_inode_lock);
@ -450,7 +450,7 @@ InodeMetadata ISO9660Inode::metadata() const
return m_metadata;
}
KResult ISO9660Inode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> visitor) const
ErrorOr<void> ISO9660Inode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> visitor) const
{
Array<u8, max_file_identifier_length> file_identifier_buffer;
@ -469,7 +469,7 @@ KResult ISO9660Inode::traverse_as_directory(Function<bool(FileSystem::DirectoryE
});
}
KResultOr<NonnullRefPtr<Inode>> ISO9660Inode::lookup(StringView name)
ErrorOr<NonnullRefPtr<Inode>> ISO9660Inode::lookup(StringView name)
{
RefPtr<Inode> inode;
Array<u8, max_file_identifier_length> file_identifier_buffer;
@ -481,8 +481,8 @@ KResultOr<NonnullRefPtr<Inode>> ISO9660Inode::lookup(StringView name)
auto maybe_inode = ISO9660Inode::try_create_from_directory_record(fs(), *record, filename);
if (maybe_inode.is_error()) {
// FIXME: The Inode API does not handle allocation failures very
// well... we can't return a KResultOr from here. It
// would be nice if we could return a KResult(Or) from
// well... we can't return a ErrorOr from here. It
// would be nice if we could return a ErrorOr<void>(Or) from
// any place where allocation may happen.
dbgln("Could not allocate inode for lookup!");
} else {
@ -499,57 +499,57 @@ KResultOr<NonnullRefPtr<Inode>> ISO9660Inode::lookup(StringView name)
return inode.release_nonnull();
}
KResult ISO9660Inode::flush_metadata()
ErrorOr<void> ISO9660Inode::flush_metadata()
{
return KSuccess;
return {};
}
KResultOr<size_t> ISO9660Inode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*)
ErrorOr<size_t> ISO9660Inode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*)
{
return EROFS;
}
KResultOr<NonnullRefPtr<Inode>> ISO9660Inode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
ErrorOr<NonnullRefPtr<Inode>> ISO9660Inode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
{
return EROFS;
}
KResult ISO9660Inode::add_child(Inode&, const StringView&, mode_t)
ErrorOr<void> ISO9660Inode::add_child(Inode&, const StringView&, mode_t)
{
return EROFS;
}
KResult ISO9660Inode::remove_child(const StringView&)
ErrorOr<void> ISO9660Inode::remove_child(const StringView&)
{
return EROFS;
}
KResult ISO9660Inode::chmod(mode_t)
ErrorOr<void> ISO9660Inode::chmod(mode_t)
{
return EROFS;
}
KResult ISO9660Inode::chown(UserID, GroupID)
ErrorOr<void> ISO9660Inode::chown(UserID, GroupID)
{
return EROFS;
}
KResult ISO9660Inode::truncate(u64)
ErrorOr<void> ISO9660Inode::truncate(u64)
{
return EROFS;
}
KResult ISO9660Inode::set_atime(time_t)
ErrorOr<void> ISO9660Inode::set_atime(time_t)
{
return EROFS;
}
KResult ISO9660Inode::set_ctime(time_t)
ErrorOr<void> ISO9660Inode::set_ctime(time_t)
{
return EROFS;
}
KResult ISO9660Inode::set_mtime(time_t)
ErrorOr<void> ISO9660Inode::set_mtime(time_t)
{
return EROFS;
}
@ -570,7 +570,7 @@ ISO9660Inode::~ISO9660Inode()
{
}
KResultOr<NonnullRefPtr<ISO9660Inode>> ISO9660Inode::try_create_from_directory_record(ISO9660FS& fs, ISO::DirectoryRecordHeader const& record, StringView const& name)
ErrorOr<NonnullRefPtr<ISO9660Inode>> ISO9660Inode::try_create_from_directory_record(ISO9660FS& fs, ISO::DirectoryRecordHeader const& record, StringView const& name)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) ISO9660Inode(fs, record, name));
}

View file

@ -7,12 +7,12 @@
#pragma once
#include <AK/EnumBits.h>
#include <AK/Error.h>
#include <AK/HashMap.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RecursionDecision.h>
#include <AK/StringView.h>
#include <AK/Types.h>
#include <Kernel/API/KResult.h>
#include <Kernel/FileSystem/BlockBasedFileSystem.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/KBuffer.h>
@ -291,7 +291,7 @@ public:
// We need it as an OwnPtr to default-construct this struct.
OwnPtr<KBuffer> blocks;
static KResultOr<NonnullRefPtr<DirectoryEntry>> try_create(u32 extent, u32 length, OwnPtr<KBuffer> blocks)
static ErrorOr<NonnullRefPtr<DirectoryEntry>> try_create(u32 extent, u32 length, OwnPtr<KBuffer> blocks)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) DirectoryEntry(extent, length, move(blocks)));
}
@ -305,10 +305,10 @@ public:
}
};
static KResultOr<NonnullRefPtr<ISO9660FS>> try_create(OpenFileDescription&);
static ErrorOr<NonnullRefPtr<ISO9660FS>> try_create(OpenFileDescription&);
virtual ~ISO9660FS() override;
virtual KResult initialize() override;
virtual ErrorOr<void> initialize() override;
virtual StringView class_name() const override { return "ISO9660FS"sv; }
virtual Inode& root_inode() override;
@ -317,18 +317,18 @@ public:
virtual u8 internal_file_type_to_directory_entry_type(DirectoryEntryView const& entry) const override;
KResultOr<NonnullRefPtr<DirectoryEntry>> directory_entry_for_record(Badge<ISO9660DirectoryIterator>, ISO::DirectoryRecordHeader const* record);
ErrorOr<NonnullRefPtr<DirectoryEntry>> directory_entry_for_record(Badge<ISO9660DirectoryIterator>, ISO::DirectoryRecordHeader const* record);
private:
ISO9660FS(OpenFileDescription&);
KResult parse_volume_set();
KResult create_root_inode();
KResult calculate_inode_count() const;
ErrorOr<void> parse_volume_set();
ErrorOr<void> create_root_inode();
ErrorOr<void> calculate_inode_count() const;
u32 calculate_directory_entry_cache_key(ISO::DirectoryRecordHeader const&);
KResult visit_directory_record(ISO::DirectoryRecordHeader const& record, Function<KResultOr<RecursionDecision>(ISO::DirectoryRecordHeader const*)> const& visitor) const;
ErrorOr<void> visit_directory_record(ISO::DirectoryRecordHeader const& record, Function<ErrorOr<RecursionDecision>(ISO::DirectoryRecordHeader const*)> const& visitor) const;
OwnPtr<ISO::PrimaryVolumeDescriptor> m_primary_volume;
RefPtr<ISO9660Inode> m_root_inode;
@ -347,21 +347,21 @@ public:
ISO9660FS const& fs() const { return static_cast<ISO9660FS const&>(Inode::fs()); }
// ^Inode
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual InodeMetadata metadata() const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual KResult flush_metadata() override;
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual KResult add_child(Inode&, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(UserID, GroupID) override;
virtual KResult truncate(u64) override;
virtual KResult set_atime(time_t) override;
virtual KResult set_ctime(time_t) override;
virtual KResult set_mtime(time_t) override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual ErrorOr<void> add_child(Inode&, const StringView& name, mode_t) override;
virtual ErrorOr<void> remove_child(const StringView& name) override;
virtual ErrorOr<void> chmod(mode_t) override;
virtual ErrorOr<void> chown(UserID, GroupID) override;
virtual ErrorOr<void> truncate(u64) override;
virtual ErrorOr<void> set_atime(time_t) override;
virtual ErrorOr<void> set_ctime(time_t) override;
virtual ErrorOr<void> set_mtime(time_t) override;
virtual void one_ref_left() override;
private:
@ -371,7 +371,7 @@ private:
static constexpr size_t max_file_identifier_length = 256 - sizeof(ISO::DirectoryRecordHeader);
ISO9660Inode(ISO9660FS&, ISO::DirectoryRecordHeader const& record, StringView const& name);
static KResultOr<NonnullRefPtr<ISO9660Inode>> try_create_from_directory_record(ISO9660FS&, ISO::DirectoryRecordHeader const& record, StringView const& name);
static ErrorOr<NonnullRefPtr<ISO9660Inode>> try_create_from_directory_record(ISO9660FS&, ISO::DirectoryRecordHeader const& record, StringView const& name);
static InodeIndex get_inode_index(ISO::DirectoryRecordHeader const& record, StringView const& name);
static StringView get_normalized_filename(ISO::DirectoryRecordHeader const& record, Bytes buffer);

View file

@ -52,7 +52,7 @@ void Inode::sync()
fs().flush_writes();
}
KResultOr<NonnullOwnPtr<KBuffer>> Inode::read_entire(OpenFileDescription* description) const
ErrorOr<NonnullOwnPtr<KBuffer>> Inode::read_entire(OpenFileDescription* description) const
{
auto builder = TRY(KBufferBuilder::try_create());
@ -76,7 +76,7 @@ KResultOr<NonnullOwnPtr<KBuffer>> Inode::read_entire(OpenFileDescription* descri
return entire_file.release_nonnull();
}
KResultOr<NonnullRefPtr<Custody>> Inode::resolve_as_link(Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level) const
ErrorOr<NonnullRefPtr<Custody>> Inode::resolve_as_link(Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level) const
{
// The default implementation simply treats the stored
// contents as a path and resolves that. That is, it
@ -106,27 +106,27 @@ void Inode::will_be_destroyed()
(void)flush_metadata();
}
KResult Inode::set_atime(time_t)
ErrorOr<void> Inode::set_atime(time_t)
{
return ENOTIMPL;
}
KResult Inode::set_ctime(time_t)
ErrorOr<void> Inode::set_ctime(time_t)
{
return ENOTIMPL;
}
KResult Inode::set_mtime(time_t)
ErrorOr<void> Inode::set_mtime(time_t)
{
return ENOTIMPL;
}
KResult Inode::increment_link_count()
ErrorOr<void> Inode::increment_link_count()
{
return ENOTIMPL;
}
KResult Inode::decrement_link_count()
ErrorOr<void> Inode::decrement_link_count()
{
return ENOTIMPL;
}
@ -169,7 +169,7 @@ void Inode::unregister_watcher(Badge<InodeWatcher>, InodeWatcher& watcher)
m_watchers.remove(&watcher);
}
KResultOr<NonnullRefPtr<FIFO>> Inode::fifo()
ErrorOr<NonnullRefPtr<FIFO>> Inode::fifo()
{
MutexLocker locker(m_inode_lock);
VERIFY(metadata().is_fifo());
@ -178,7 +178,7 @@ KResultOr<NonnullRefPtr<FIFO>> Inode::fifo()
if (!m_fifo)
m_fifo = TRY(FIFO::try_create(metadata().uid));
return *m_fifo;
return NonnullRefPtr { *m_fifo };
}
void Inode::set_metadata_dirty(bool metadata_dirty)
@ -242,7 +242,7 @@ void Inode::did_delete_self()
}
}
KResult Inode::prepare_to_write_data()
ErrorOr<void> Inode::prepare_to_write_data()
{
// FIXME: It's a poor design that filesystems are expected to call this before writing out data.
// We should funnel everything through an interface at the VirtualFileSystem layer so this can happen from a single place.
@ -254,7 +254,7 @@ KResult Inode::prepare_to_write_data()
dbgln("Inode::prepare_to_write_data(): Stripping SUID/SGID bits from {}", identifier());
return chmod(metadata.mode & ~(04000 | 02000));
}
return KSuccess;
return {};
}
RefPtr<Memory::SharedInodeVMObject> Inode::shared_vmobject() const
@ -269,7 +269,7 @@ static inline bool range_overlap(T start1, T len1, T start2, T len2)
return ((start1 < start2 + len2) || len2 == 0) && ((start2 < start1 + len1) || len1 == 0);
}
static inline KResult normalize_flock(OpenFileDescription const& description, flock& lock)
static inline ErrorOr<void> normalize_flock(OpenFileDescription const& description, flock& lock)
{
off_t start;
switch (lock.l_whence) {
@ -286,10 +286,10 @@ static inline KResult normalize_flock(OpenFileDescription const& description, fl
return EINVAL;
}
lock = { lock.l_type, SEEK_SET, start, lock.l_len, 0 };
return KSuccess;
return {};
}
KResult Inode::can_apply_flock(OpenFileDescription const& description, flock const& new_lock) const
ErrorOr<void> Inode::can_apply_flock(OpenFileDescription const& description, flock const& new_lock) const
{
VERIFY(new_lock.l_whence == SEEK_SET);
@ -298,7 +298,7 @@ KResult Inode::can_apply_flock(OpenFileDescription const& description, flock con
if (new_lock.l_type == F_UNLCK) {
for (auto& lock : m_flocks) {
if (&description == lock.owner && lock.start == new_lock.l_start && lock.len == new_lock.l_len)
return KSuccess;
return {};
}
return EINVAL;
}
@ -313,10 +313,10 @@ KResult Inode::can_apply_flock(OpenFileDescription const& description, flock con
if (new_lock.l_type == F_WRLCK)
return EAGAIN;
}
return KSuccess;
return {};
}
KResult Inode::apply_flock(Process const& process, OpenFileDescription const& description, Userspace<flock const*> input_lock)
ErrorOr<void> Inode::apply_flock(Process const& process, OpenFileDescription const& description, Userspace<flock const*> input_lock)
{
flock new_lock = {};
TRY(copy_from_user(&new_lock, input_lock));
@ -330,17 +330,17 @@ KResult Inode::apply_flock(Process const& process, OpenFileDescription const& de
for (size_t i = 0; i < m_flocks.size(); ++i) {
if (&description == m_flocks[i].owner && m_flocks[i].start == new_lock.l_start && m_flocks[i].len == new_lock.l_len) {
m_flocks.remove(i);
return KSuccess;
return {};
}
}
return EINVAL;
}
m_flocks.append(Flock { new_lock.l_start, new_lock.l_len, &description, process.pid().value(), new_lock.l_type });
return KSuccess;
return {};
}
KResult Inode::get_flock(OpenFileDescription const& description, Userspace<flock*> reference_lock) const
ErrorOr<void> Inode::get_flock(OpenFileDescription const& description, Userspace<flock*> reference_lock) const
{
flock lookup = {};
TRY(copy_from_user(&lookup, reference_lock));

View file

@ -7,12 +7,12 @@
#pragma once
#include <AK/Error.h>
#include <AK/Function.h>
#include <AK/HashTable.h>
#include <AK/IntrusiveList.h>
#include <AK/String.h>
#include <AK/WeakPtr.h>
#include <Kernel/API/KResult.h>
#include <Kernel/FileSystem/FIFO.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
@ -47,24 +47,24 @@ public:
InodeIdentifier identifier() const { return { fsid(), index() }; }
virtual InodeMetadata metadata() const = 0;
KResultOr<NonnullOwnPtr<KBuffer>> read_entire(OpenFileDescription* = nullptr) const;
ErrorOr<NonnullOwnPtr<KBuffer>> read_entire(OpenFileDescription* = nullptr) const;
virtual KResult attach(OpenFileDescription&) { return KSuccess; }
virtual ErrorOr<void> attach(OpenFileDescription&) { return {}; }
virtual void detach(OpenFileDescription&) { }
virtual void did_seek(OpenFileDescription&, off_t) { }
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const = 0;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const = 0;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) = 0;
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) = 0;
virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) = 0;
virtual KResult add_child(Inode&, const StringView& name, mode_t) = 0;
virtual KResult remove_child(const StringView& name) = 0;
virtual KResult chmod(mode_t) = 0;
virtual KResult chown(UserID, GroupID) = 0;
virtual KResult truncate(u64) { return KSuccess; }
virtual KResultOr<NonnullRefPtr<Custody>> resolve_as_link(Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level) const;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const = 0;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const = 0;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) = 0;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) = 0;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) = 0;
virtual ErrorOr<void> add_child(Inode&, const StringView& name, mode_t) = 0;
virtual ErrorOr<void> remove_child(const StringView& name) = 0;
virtual ErrorOr<void> chmod(mode_t) = 0;
virtual ErrorOr<void> chown(UserID, GroupID) = 0;
virtual ErrorOr<void> truncate(u64) { return {}; }
virtual ErrorOr<NonnullRefPtr<Custody>> resolve_as_link(Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level) const;
virtual KResultOr<int> get_block_address(int) { return ENOTSUP; }
virtual ErrorOr<int> get_block_address(int) { return ENOTSUP; }
LocalSocket* socket() { return m_socket.ptr(); }
const LocalSocket* socket() const { return m_socket.ptr(); }
@ -75,13 +75,13 @@ public:
bool is_metadata_dirty() const { return m_metadata_dirty; }
virtual KResult set_atime(time_t);
virtual KResult set_ctime(time_t);
virtual KResult set_mtime(time_t);
virtual KResult increment_link_count();
virtual KResult decrement_link_count();
virtual ErrorOr<void> set_atime(time_t);
virtual ErrorOr<void> set_ctime(time_t);
virtual ErrorOr<void> set_mtime(time_t);
virtual ErrorOr<void> increment_link_count();
virtual ErrorOr<void> decrement_link_count();
virtual KResult flush_metadata() = 0;
virtual ErrorOr<void> flush_metadata() = 0;
void will_be_destroyed();
@ -96,17 +96,17 @@ public:
void register_watcher(Badge<InodeWatcher>, InodeWatcher&);
void unregister_watcher(Badge<InodeWatcher>, InodeWatcher&);
KResultOr<NonnullRefPtr<FIFO>> fifo();
ErrorOr<NonnullRefPtr<FIFO>> fifo();
KResult can_apply_flock(OpenFileDescription const&, flock const&) const;
KResult apply_flock(Process const&, OpenFileDescription const&, Userspace<flock const*>);
KResult get_flock(OpenFileDescription const&, Userspace<flock*>) const;
ErrorOr<void> can_apply_flock(OpenFileDescription const&, flock const&) const;
ErrorOr<void> apply_flock(Process const&, OpenFileDescription const&, Userspace<flock const*>);
ErrorOr<void> get_flock(OpenFileDescription const&, Userspace<flock*>) const;
void remove_flocks_for_description(OpenFileDescription const&);
protected:
Inode(FileSystem&, InodeIndex);
void set_metadata_dirty(bool);
KResult prepare_to_write_data();
ErrorOr<void> prepare_to_write_data();
void did_add_child(InodeIdentifier const& child_id, String const& name);
void did_remove_child(InodeIdentifier const& child_id, String const& name);

View file

@ -26,7 +26,7 @@ InodeFile::~InodeFile()
{
}
KResultOr<size_t> InodeFile::read(OpenFileDescription& description, u64 offset, UserOrKernelBuffer& buffer, size_t count)
ErrorOr<size_t> InodeFile::read(OpenFileDescription& description, u64 offset, UserOrKernelBuffer& buffer, size_t count)
{
if (Checked<off_t>::addition_would_overflow(offset, count))
return EOVERFLOW;
@ -39,7 +39,7 @@ KResultOr<size_t> InodeFile::read(OpenFileDescription& description, u64 offset,
return nread;
}
KResultOr<size_t> InodeFile::write(OpenFileDescription& description, u64 offset, const UserOrKernelBuffer& data, size_t count)
ErrorOr<size_t> InodeFile::write(OpenFileDescription& description, u64 offset, const UserOrKernelBuffer& data, size_t count)
{
if (Checked<off_t>::addition_would_overflow(offset, count))
return EOVERFLOW;
@ -50,12 +50,12 @@ KResultOr<size_t> InodeFile::write(OpenFileDescription& description, u64 offset,
Thread::current()->did_file_write(nwritten);
evaluate_block_conditions();
if (mtime_result.is_error())
return mtime_result;
return mtime_result.release_error();
}
return nwritten;
}
KResult InodeFile::ioctl(OpenFileDescription& description, unsigned request, Userspace<void*> arg)
ErrorOr<void> InodeFile::ioctl(OpenFileDescription& description, unsigned request, Userspace<void*> arg)
{
switch (request) {
case FIBMAP: {
@ -81,7 +81,7 @@ KResult InodeFile::ioctl(OpenFileDescription& description, unsigned request, Use
}
}
KResultOr<Memory::Region*> InodeFile::mmap(Process& process, OpenFileDescription& description, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
ErrorOr<Memory::Region*> InodeFile::mmap(Process& process, OpenFileDescription& description, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
{
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.
RefPtr<Memory::InodeVMObject> vmobject;
@ -93,33 +93,33 @@ KResultOr<Memory::Region*> InodeFile::mmap(Process& process, OpenFileDescription
return process.address_space().allocate_region_with_vmobject(range, vmobject.release_nonnull(), offset, path->view(), prot, shared);
}
KResultOr<NonnullOwnPtr<KString>> InodeFile::pseudo_path(const OpenFileDescription&) const
ErrorOr<NonnullOwnPtr<KString>> InodeFile::pseudo_path(const OpenFileDescription&) const
{
// If it has an inode, then it has a path, and therefore the caller should have been able to get a custody at some point.
VERIFY_NOT_REACHED();
}
KResult InodeFile::truncate(u64 size)
ErrorOr<void> InodeFile::truncate(u64 size)
{
TRY(m_inode->truncate(size));
TRY(m_inode->set_mtime(kgettimeofday().to_truncated_seconds()));
return KSuccess;
return {};
}
KResult InodeFile::sync()
ErrorOr<void> InodeFile::sync()
{
m_inode->sync();
return KSuccess;
return {};
}
KResult InodeFile::chown(OpenFileDescription& description, UserID uid, GroupID gid)
ErrorOr<void> InodeFile::chown(OpenFileDescription& description, UserID uid, GroupID gid)
{
VERIFY(description.inode() == m_inode);
VERIFY(description.custody());
return VirtualFileSystem::the().chown(*description.custody(), uid, gid);
}
KResult InodeFile::chmod(OpenFileDescription& description, mode_t mode)
ErrorOr<void> InodeFile::chmod(OpenFileDescription& description, mode_t mode)
{
VERIFY(description.inode() == m_inode);
VERIFY(description.custody());

View file

@ -14,7 +14,7 @@ class Inode;
class InodeFile final : public File {
public:
static KResultOr<NonnullRefPtr<InodeFile>> create(NonnullRefPtr<Inode>&& inode)
static ErrorOr<NonnullRefPtr<InodeFile>> create(NonnullRefPtr<Inode>&& inode)
{
auto file = adopt_ref_if_nonnull(new (nothrow) InodeFile(move(inode)));
if (!file)
@ -30,18 +30,18 @@ public:
virtual bool can_read(const OpenFileDescription&, size_t) const override { return true; }
virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; }
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
virtual KResult stat(::stat& buffer) const override { return inode().metadata().stat(buffer); }
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
virtual ErrorOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
virtual ErrorOr<void> stat(::stat& buffer) const override { return inode().metadata().stat(buffer); }
virtual KResultOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
virtual KResult truncate(u64) override;
virtual KResult sync() override;
virtual KResult chown(OpenFileDescription&, UserID, GroupID) override;
virtual KResult chmod(OpenFileDescription&, mode_t) override;
virtual ErrorOr<void> truncate(u64) override;
virtual ErrorOr<void> sync() override;
virtual ErrorOr<void> chown(OpenFileDescription&, UserID, GroupID) override;
virtual ErrorOr<void> chmod(OpenFileDescription&, mode_t) override;
virtual StringView class_name() const override { return "InodeFile"sv; }

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/Error.h>
#include <AK/Span.h>
#include <Kernel/API/KResult.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
#include <Kernel/Forward.h>
#include <Kernel/UnixTypes.h>
@ -86,7 +86,7 @@ struct InodeMetadata {
bool is_setuid() const { return Kernel::is_setuid(mode); }
bool is_setgid() const { return Kernel::is_setgid(mode); }
KResult stat(stat& buffer) const
ErrorOr<void> stat(stat& buffer) const
{
if (!is_valid())
return EIO;
@ -106,7 +106,7 @@ struct InodeMetadata {
buffer.st_mtim.tv_nsec = 0;
buffer.st_ctim.tv_sec = ctime;
buffer.st_ctim.tv_nsec = 0;
return KSuccess;
return {};
}
InodeIdentifier inode;

View file

@ -12,7 +12,7 @@
namespace Kernel {
KResultOr<NonnullRefPtr<InodeWatcher>> InodeWatcher::try_create()
ErrorOr<NonnullRefPtr<InodeWatcher>> InodeWatcher::try_create()
{
return adopt_nonnull_ref_or_enomem(new (nothrow) InodeWatcher);
}
@ -28,7 +28,7 @@ bool InodeWatcher::can_read(const OpenFileDescription&, size_t) const
return !m_queue.is_empty();
}
KResultOr<size_t> InodeWatcher::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t buffer_size)
ErrorOr<size_t> InodeWatcher::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t buffer_size)
{
MutexLocker locker(m_lock);
if (m_queue.is_empty())
@ -67,7 +67,7 @@ KResultOr<size_t> InodeWatcher::read(OpenFileDescription&, u64, UserOrKernelBuff
return result;
}
KResult InodeWatcher::close()
ErrorOr<void> InodeWatcher::close()
{
MutexLocker locker(m_lock);
@ -78,10 +78,10 @@ KResult InodeWatcher::close()
m_wd_to_watches.clear();
m_inode_to_watches.clear();
return KSuccess;
return {};
}
KResultOr<NonnullOwnPtr<KString>> InodeWatcher::pseudo_path(const OpenFileDescription&) const
ErrorOr<NonnullOwnPtr<KString>> InodeWatcher::pseudo_path(const OpenFileDescription&) const
{
return KString::try_create(String::formatted("InodeWatcher:({})", m_wd_to_watches.size()));
}
@ -102,7 +102,7 @@ void InodeWatcher::notify_inode_event(Badge<Inode>, InodeIdentifier inode_id, In
evaluate_block_conditions();
}
KResultOr<int> InodeWatcher::register_inode(Inode& inode, unsigned event_mask)
ErrorOr<int> InodeWatcher::register_inode(Inode& inode, unsigned event_mask)
{
MutexLocker locker(m_lock);
@ -118,11 +118,8 @@ KResultOr<int> InodeWatcher::register_inode(Inode& inode, unsigned event_mask)
m_wd_counter = 1;
} while (m_wd_to_watches.find(wd) != m_wd_to_watches.end());
auto description_or_error = WatchDescription::create(wd, inode, event_mask);
if (description_or_error.is_error())
return description_or_error.error();
auto description = TRY(WatchDescription::create(wd, inode, event_mask));
auto description = description_or_error.release_value();
m_inode_to_watches.set(inode.identifier(), description.ptr());
m_wd_to_watches.set(wd, move(description));
@ -130,7 +127,7 @@ KResultOr<int> InodeWatcher::register_inode(Inode& inode, unsigned event_mask)
return wd;
}
KResult InodeWatcher::unregister_by_wd(int wd)
ErrorOr<void> InodeWatcher::unregister_by_wd(int wd)
{
MutexLocker locker(m_lock);
@ -144,7 +141,7 @@ KResult InodeWatcher::unregister_by_wd(int wd)
m_inode_to_watches.remove(inode.identifier());
m_wd_to_watches.remove(it);
return KSuccess;
return {};
}
void InodeWatcher::unregister_by_inode(Badge<Inode>, InodeIdentifier identifier)

View file

@ -24,7 +24,7 @@ struct WatchDescription {
Inode& inode;
unsigned event_mask;
static KResultOr<NonnullOwnPtr<WatchDescription>> create(int wd, Inode& inode, unsigned event_mask)
static ErrorOr<NonnullOwnPtr<WatchDescription>> create(int wd, Inode& inode, unsigned event_mask)
{
return adopt_nonnull_own_or_enomem(new (nothrow) WatchDescription(wd, inode, event_mask));
}
@ -40,24 +40,24 @@ private:
class InodeWatcher final : public File {
public:
static KResultOr<NonnullRefPtr<InodeWatcher>> try_create();
static ErrorOr<NonnullRefPtr<InodeWatcher>> try_create();
virtual ~InodeWatcher() override;
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
// Can't write to an inode watcher.
virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; }
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EIO; }
virtual KResult close() override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EIO; }
virtual ErrorOr<void> close() override;
virtual KResultOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
virtual StringView class_name() const override { return "InodeWatcher"sv; };
virtual bool is_inode_watcher() const override { return true; }
void notify_inode_event(Badge<Inode>, InodeIdentifier, InodeWatcherEvent::Type, String const& name = {});
KResultOr<int> register_inode(Inode&, unsigned event_mask);
KResult unregister_by_wd(int);
ErrorOr<int> register_inode(Inode&, unsigned event_mask);
ErrorOr<void> unregister_by_wd(int);
void unregister_by_inode(Badge<Inode>, InodeIdentifier);
private:

View file

@ -24,7 +24,7 @@
namespace Kernel {
KResultOr<NonnullRefPtr<OpenFileDescription>> OpenFileDescription::try_create(Custody& custody)
ErrorOr<NonnullRefPtr<OpenFileDescription>> OpenFileDescription::try_create(Custody& custody)
{
auto inode_file = TRY(InodeFile::create(custody.inode()));
auto description = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) OpenFileDescription(move(inode_file))));
@ -34,7 +34,7 @@ KResultOr<NonnullRefPtr<OpenFileDescription>> OpenFileDescription::try_create(Cu
return description;
}
KResultOr<NonnullRefPtr<OpenFileDescription>> OpenFileDescription::try_create(File& file)
ErrorOr<NonnullRefPtr<OpenFileDescription>> OpenFileDescription::try_create(File& file)
{
auto description = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) OpenFileDescription(file)));
TRY(description->attach());
@ -64,7 +64,7 @@ OpenFileDescription::~OpenFileDescription()
m_inode->remove_flocks_for_description(*this);
}
KResult OpenFileDescription::attach()
ErrorOr<void> OpenFileDescription::attach()
{
if (m_inode)
TRY(m_inode->attach(*this));
@ -97,7 +97,7 @@ Thread::FileBlocker::BlockFlags OpenFileDescription::should_unblock(Thread::File
return unblock_flags;
}
KResult OpenFileDescription::stat(::stat& buffer)
ErrorOr<void> OpenFileDescription::stat(::stat& buffer)
{
MutexLocker locker(m_lock);
// FIXME: This is due to the Device class not overriding File::stat().
@ -106,7 +106,7 @@ KResult OpenFileDescription::stat(::stat& buffer)
return m_file->stat(buffer);
}
KResultOr<off_t> OpenFileDescription::seek(off_t offset, int whence)
ErrorOr<off_t> OpenFileDescription::seek(off_t offset, int whence)
{
MutexLocker locker(m_lock);
if (!m_file->is_seekable())
@ -147,21 +147,21 @@ KResultOr<off_t> OpenFileDescription::seek(off_t offset, int whence)
return m_current_offset;
}
KResultOr<size_t> OpenFileDescription::read(UserOrKernelBuffer& buffer, u64 offset, size_t count)
ErrorOr<size_t> OpenFileDescription::read(UserOrKernelBuffer& buffer, u64 offset, size_t count)
{
if (Checked<u64>::addition_would_overflow(offset, count))
return EOVERFLOW;
return m_file->read(*this, offset, buffer, count);
}
KResultOr<size_t> OpenFileDescription::write(u64 offset, UserOrKernelBuffer const& data, size_t data_size)
ErrorOr<size_t> OpenFileDescription::write(u64 offset, UserOrKernelBuffer const& data, size_t data_size)
{
if (Checked<u64>::addition_would_overflow(offset, data_size))
return EOVERFLOW;
return m_file->write(*this, offset, data, data_size);
}
KResultOr<size_t> OpenFileDescription::read(UserOrKernelBuffer& buffer, size_t count)
ErrorOr<size_t> OpenFileDescription::read(UserOrKernelBuffer& buffer, size_t count)
{
MutexLocker locker(m_lock);
if (Checked<off_t>::addition_would_overflow(m_current_offset, count))
@ -173,7 +173,7 @@ KResultOr<size_t> OpenFileDescription::read(UserOrKernelBuffer& buffer, size_t c
return nread;
}
KResultOr<size_t> OpenFileDescription::write(const UserOrKernelBuffer& data, size_t size)
ErrorOr<size_t> OpenFileDescription::write(const UserOrKernelBuffer& data, size_t size)
{
MutexLocker locker(m_lock);
if (Checked<off_t>::addition_would_overflow(m_current_offset, size))
@ -195,7 +195,7 @@ bool OpenFileDescription::can_read() const
return m_file->can_read(*this, offset());
}
KResultOr<NonnullOwnPtr<KBuffer>> OpenFileDescription::read_entire_file()
ErrorOr<NonnullOwnPtr<KBuffer>> OpenFileDescription::read_entire_file()
{
// HACK ALERT: (This entire function)
VERIFY(m_file->is_inode());
@ -203,7 +203,7 @@ KResultOr<NonnullOwnPtr<KBuffer>> OpenFileDescription::read_entire_file()
return m_inode->read_entire(this);
}
KResultOr<size_t> OpenFileDescription::get_dir_entries(UserOrKernelBuffer& output_buffer, size_t size)
ErrorOr<size_t> OpenFileDescription::get_dir_entries(UserOrKernelBuffer& output_buffer, size_t size)
{
MutexLocker locker(m_lock, Mutex::Mode::Shared);
if (!is_directory())
@ -214,7 +214,7 @@ KResultOr<size_t> OpenFileDescription::get_dir_entries(UserOrKernelBuffer& outpu
return EIO;
size_t remaining = size;
KResult error = KSuccess;
ErrorOr<void> error;
u8 stack_buffer[PAGE_SIZE];
Bytes temp_buffer(stack_buffer, sizeof(stack_buffer));
OutputMemoryStream stream { temp_buffer };
@ -238,7 +238,7 @@ KResultOr<size_t> OpenFileDescription::get_dir_entries(UserOrKernelBuffer& outpu
return true;
};
KResult result = VirtualFileSystem::the().traverse_directory_inode(*m_inode, [&flush_stream_to_output_buffer, &stream, this](auto& entry) {
ErrorOr<void> result = VirtualFileSystem::the().traverse_directory_inode(*m_inode, [&flush_stream_to_output_buffer, &stream, this](auto& entry) {
size_t serialized_size = sizeof(ino_t) + sizeof(u8) + sizeof(size_t) + sizeof(char) * entry.name.length();
if (serialized_size > stream.remaining()) {
if (!flush_stream_to_output_buffer()) {
@ -257,12 +257,12 @@ KResultOr<size_t> OpenFileDescription::get_dir_entries(UserOrKernelBuffer& outpu
// We should only return EFAULT when the userspace buffer is too small,
// so that userspace can reliably use it as a signal to increase its
// buffer size.
VERIFY(result != EFAULT);
return result;
VERIFY(result.error().code() != EFAULT);
return result.release_error();
}
if (error.is_error())
return error;
return error.release_error();
return size - remaining;
}
@ -342,21 +342,21 @@ MasterPTY* OpenFileDescription::master_pty()
return static_cast<MasterPTY*>(m_file.ptr());
}
KResult OpenFileDescription::close()
ErrorOr<void> OpenFileDescription::close()
{
if (m_file->attach_count() > 0)
return KSuccess;
return {};
return m_file->close();
}
KResultOr<NonnullOwnPtr<KString>> OpenFileDescription::original_absolute_path() const
ErrorOr<NonnullOwnPtr<KString>> OpenFileDescription::original_absolute_path() const
{
if (!m_custody)
return ENOENT;
return m_custody->try_serialize_absolute_path();
}
KResultOr<NonnullOwnPtr<KString>> OpenFileDescription::pseudo_path() const
ErrorOr<NonnullOwnPtr<KString>> OpenFileDescription::pseudo_path() const
{
if (m_custody)
return m_custody->try_serialize_absolute_path();
@ -370,19 +370,19 @@ InodeMetadata OpenFileDescription::metadata() const
return {};
}
KResultOr<Memory::Region*> OpenFileDescription::mmap(Process& process, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
ErrorOr<Memory::Region*> OpenFileDescription::mmap(Process& process, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
{
MutexLocker locker(m_lock);
return m_file->mmap(process, *this, range, offset, prot, shared);
}
KResult OpenFileDescription::truncate(u64 length)
ErrorOr<void> OpenFileDescription::truncate(u64 length)
{
MutexLocker locker(m_lock);
return m_file->truncate(length);
}
KResult OpenFileDescription::sync()
ErrorOr<void> OpenFileDescription::sync()
{
MutexLocker locker(m_lock);
return m_file->sync();
@ -428,13 +428,13 @@ void OpenFileDescription::set_file_flags(u32 flags)
m_file_flags = flags;
}
KResult OpenFileDescription::chmod(mode_t mode)
ErrorOr<void> OpenFileDescription::chmod(mode_t mode)
{
MutexLocker locker(m_lock);
return m_file->chmod(*this, mode);
}
KResult OpenFileDescription::chown(UserID uid, GroupID gid)
ErrorOr<void> OpenFileDescription::chown(UserID uid, GroupID gid)
{
MutexLocker locker(m_lock);
return m_file->chown(*this, uid, gid);
@ -445,7 +445,7 @@ FileBlockerSet& OpenFileDescription::blocker_set()
return m_file->blocker_set();
}
KResult OpenFileDescription::apply_flock(Process const& process, Userspace<flock const*> lock)
ErrorOr<void> OpenFileDescription::apply_flock(Process const& process, Userspace<flock const*> lock)
{
if (!m_inode)
return EBADF;
@ -453,7 +453,7 @@ KResult OpenFileDescription::apply_flock(Process const& process, Userspace<flock
return m_inode->apply_flock(process, *this, lock);
}
KResult OpenFileDescription::get_flock(Userspace<flock*> lock) const
ErrorOr<void> OpenFileDescription::get_flock(Userspace<flock*> lock) const
{
if (!m_inode)
return EBADF;

View file

@ -26,8 +26,8 @@ public:
class OpenFileDescription : public RefCounted<OpenFileDescription> {
MAKE_SLAB_ALLOCATED(OpenFileDescription)
public:
static KResultOr<NonnullRefPtr<OpenFileDescription>> try_create(Custody&);
static KResultOr<NonnullRefPtr<OpenFileDescription>> try_create(File&);
static ErrorOr<NonnullRefPtr<OpenFileDescription>> try_create(Custody&);
static ErrorOr<NonnullRefPtr<OpenFileDescription>> try_create(File&);
~OpenFileDescription();
Thread::FileBlocker::BlockFlags should_unblock(Thread::FileBlocker::BlockFlags) const;
@ -44,28 +44,28 @@ public:
set_writable(options & O_WRONLY);
}
KResult close();
ErrorOr<void> close();
KResultOr<off_t> seek(off_t, int whence);
KResultOr<size_t> read(UserOrKernelBuffer&, size_t);
KResultOr<size_t> write(const UserOrKernelBuffer& data, size_t);
KResult stat(::stat&);
ErrorOr<off_t> seek(off_t, int whence);
ErrorOr<size_t> read(UserOrKernelBuffer&, size_t);
ErrorOr<size_t> write(const UserOrKernelBuffer& data, size_t);
ErrorOr<void> stat(::stat&);
// NOTE: These ignore the current offset of this file description.
KResultOr<size_t> read(UserOrKernelBuffer&, u64 offset, size_t);
KResultOr<size_t> write(u64 offset, UserOrKernelBuffer const&, size_t);
ErrorOr<size_t> read(UserOrKernelBuffer&, u64 offset, size_t);
ErrorOr<size_t> write(u64 offset, UserOrKernelBuffer const&, size_t);
KResult chmod(mode_t);
ErrorOr<void> chmod(mode_t);
bool can_read() const;
bool can_write() const;
KResultOr<size_t> get_dir_entries(UserOrKernelBuffer& buffer, size_t);
ErrorOr<size_t> get_dir_entries(UserOrKernelBuffer& buffer, size_t);
KResultOr<NonnullOwnPtr<KBuffer>> read_entire_file();
ErrorOr<NonnullOwnPtr<KBuffer>> read_entire_file();
KResultOr<NonnullOwnPtr<KString>> original_absolute_path() const;
KResultOr<NonnullOwnPtr<KString>> pseudo_path() const;
ErrorOr<NonnullOwnPtr<KString>> original_absolute_path() const;
ErrorOr<NonnullOwnPtr<KString>> pseudo_path() const;
bool is_direct() const { return m_direct; }
@ -97,7 +97,7 @@ public:
Custody* custody() { return m_custody.ptr(); }
const Custody* custody() const { return m_custody.ptr(); }
KResultOr<Memory::Region*> mmap(Process&, Memory::VirtualRange const&, u64 offset, int prot, bool shared);
ErrorOr<Memory::Region*> mmap(Process&, Memory::VirtualRange const&, u64 offset, int prot, bool shared);
bool is_blocking() const { return m_is_blocking; }
void set_blocking(bool b) { m_is_blocking = b; }
@ -121,23 +121,23 @@ public:
void set_original_inode(Badge<VirtualFileSystem>, NonnullRefPtr<Inode>&& inode) { m_inode = move(inode); }
void set_original_custody(Badge<VirtualFileSystem>, Custody& custody);
KResult truncate(u64);
KResult sync();
ErrorOr<void> truncate(u64);
ErrorOr<void> sync();
off_t offset() const { return m_current_offset; }
KResult chown(UserID, GroupID);
ErrorOr<void> chown(UserID, GroupID);
FileBlockerSet& blocker_set();
KResult apply_flock(Process const&, Userspace<flock const*>);
KResult get_flock(Userspace<flock*>) const;
ErrorOr<void> apply_flock(Process const&, Userspace<flock const*>);
ErrorOr<void> get_flock(Userspace<flock*>) const;
private:
friend class VirtualFileSystem;
explicit OpenFileDescription(File&);
KResult attach();
ErrorOr<void> attach();
void evaluate_block_conditions()
{

View file

@ -9,7 +9,7 @@
namespace Kernel {
KResultOr<NonnullRefPtr<Plan9FS>> Plan9FS::try_create(OpenFileDescription& file_description)
ErrorOr<NonnullRefPtr<Plan9FS>> Plan9FS::try_create(OpenFileDescription& file_description)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) Plan9FS(file_description));
}
@ -196,7 +196,7 @@ private:
bool m_have_been_built { false };
};
KResult Plan9FS::initialize()
ErrorOr<void> Plan9FS::initialize()
{
ensure_thread();
@ -225,7 +225,7 @@ KResult Plan9FS::initialize()
TRY(post_message_and_wait_for_a_reply(attach_message));
m_root_inode = TRY(Plan9FSInode::try_create(*this, root_fid));
return KSuccess;
return {};
}
Plan9FS::ProtocolVersion Plan9FS::parse_protocol_version(const StringView& s) const
@ -489,7 +489,7 @@ bool Plan9FS::is_complete(const ReceiveCompletion& completion)
return true;
}
KResult Plan9FS::post_message(Message& message, RefPtr<ReceiveCompletion> completion)
ErrorOr<void> Plan9FS::post_message(Message& message, RefPtr<ReceiveCompletion> completion)
{
auto& buffer = message.build();
const u8* data = buffer.data();
@ -521,10 +521,10 @@ KResult Plan9FS::post_message(Message& message, RefPtr<ReceiveCompletion> comple
size -= nwritten;
}
return KSuccess;
return {};
}
KResult Plan9FS::do_read(u8* data, size_t size)
ErrorOr<void> Plan9FS::do_read(u8* data, size_t size)
{
auto& description = file_description();
while (size > 0) {
@ -540,10 +540,10 @@ KResult Plan9FS::do_read(u8* data, size_t size)
data += nread;
size -= nread;
}
return KSuccess;
return {};
}
KResult Plan9FS::read_and_dispatch_one_message()
ErrorOr<void> Plan9FS::read_and_dispatch_one_message()
{
struct [[gnu::packed]] Header {
u32 size;
@ -564,7 +564,7 @@ KResult Plan9FS::read_and_dispatch_one_message()
if (optional_completion.has_value()) {
auto completion = optional_completion.value();
SpinlockLocker lock(completion->lock);
completion->result = KSuccess;
completion->result = {};
completion->message = adopt_own_if_nonnull(new (nothrow) Message { move(buffer) });
completion->completed = true;
@ -574,15 +574,15 @@ KResult Plan9FS::read_and_dispatch_one_message()
dbgln("Received a 9p message of type {} with an unexpected tag {}, dropping", header.type, header.tag);
}
return KSuccess;
return {};
}
KResult Plan9FS::post_message_and_explicitly_ignore_reply(Message& message)
ErrorOr<void> Plan9FS::post_message_and_explicitly_ignore_reply(Message& message)
{
return post_message(message, {});
}
KResult Plan9FS::post_message_and_wait_for_a_reply(Message& message)
ErrorOr<void> Plan9FS::post_message_and_wait_for_a_reply(Message& message)
{
auto request_type = message.type();
auto tag = message.tag();
@ -602,7 +602,7 @@ KResult Plan9FS::post_message_and_wait_for_a_reply(Message& message)
// Contains a numerical Linux errno; hopefully our errno numbers match.
u32 error_code;
message >> error_code;
return KResult((ErrnoCode)error_code);
return Error::from_errno((ErrnoCode)error_code);
} else if (reply_type == Message::Type::Rerror) {
// Contains an error message. We could attempt to parse it, but for now
// we simply return EIO instead. In 9P200.u, it can also contain a
@ -617,7 +617,7 @@ KResult Plan9FS::post_message_and_wait_for_a_reply(Message& message)
dbgln("Plan9FS: Received unexpected message type {} in response to {}", (u8)reply_type, (u8)request_type);
return EIO;
} else {
return KSuccess;
return {};
}
}
@ -668,7 +668,7 @@ Plan9FSInode::Plan9FSInode(Plan9FS& fs, u32 fid)
{
}
KResultOr<NonnullRefPtr<Plan9FSInode>> Plan9FSInode::try_create(Plan9FS& fs, u32 fid)
ErrorOr<NonnullRefPtr<Plan9FSInode>> Plan9FSInode::try_create(Plan9FS& fs, u32 fid)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) Plan9FSInode(fs, fid));
}
@ -681,7 +681,7 @@ Plan9FSInode::~Plan9FSInode()
[[maybe_unused]] auto rc = fs().post_message_and_explicitly_ignore_reply(clunk_request);
}
KResult Plan9FSInode::ensure_open_for_mode(int mode)
ErrorOr<void> Plan9FSInode::ensure_open_for_mode(int mode)
{
bool use_lopen = fs().m_remote_protocol_version >= Plan9FS::ProtocolVersion::v9P2000L;
u32 l_mode = 0;
@ -692,7 +692,7 @@ KResult Plan9FSInode::ensure_open_for_mode(int mode)
// If it's already open in this mode, we're done.
if ((m_open_mode & mode) == mode)
return KSuccess;
return {};
m_open_mode |= mode;
@ -718,7 +718,7 @@ KResult Plan9FSInode::ensure_open_for_mode(int mode)
}
}
KResultOr<size_t> Plan9FSInode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, OpenFileDescription*) const
ErrorOr<size_t> Plan9FSInode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, OpenFileDescription*) const
{
TRY(const_cast<Plan9FSInode&>(*this).ensure_open_for_mode(O_RDONLY));
@ -731,7 +731,7 @@ KResultOr<size_t> Plan9FSInode::read_bytes(off_t offset, size_t size, UserOrKern
bool readlink_succeded = false;
if (fs().m_remote_protocol_version >= Plan9FS::ProtocolVersion::v9P2000L && offset == 0) {
message << fid();
if (auto result = fs().post_message_and_wait_for_a_reply(message); result.is_success()) {
if (auto result = fs().post_message_and_wait_for_a_reply(message); !result.is_error()) {
readlink_succeded = true;
message >> data;
}
@ -750,7 +750,7 @@ KResultOr<size_t> Plan9FSInode::read_bytes(off_t offset, size_t size, UserOrKern
return nread;
}
KResultOr<size_t> Plan9FSInode::write_bytes(off_t offset, size_t size, const UserOrKernelBuffer& data, OpenFileDescription*)
ErrorOr<size_t> Plan9FSInode::write_bytes(off_t offset, size_t size, const UserOrKernelBuffer& data, OpenFileDescription*)
{
TRY(ensure_open_for_mode(O_WRONLY));
size = fs().adjust_buffer_size(size);
@ -822,13 +822,13 @@ InodeMetadata Plan9FSInode::metadata() const
return metadata;
}
KResult Plan9FSInode::flush_metadata()
ErrorOr<void> Plan9FSInode::flush_metadata()
{
// Do nothing.
return KSuccess;
return {};
}
KResult Plan9FSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> Plan9FSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
// TODO: Should we synthesize "." and ".." here?
@ -853,7 +853,7 @@ KResult Plan9FSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryE
u64 offset = 0;
u32 count = fs().adjust_buffer_size(8 * MiB);
KResult result = KSuccess;
ErrorOr<void> result;
while (true) {
Plan9FS::Message message { fs(), Plan9FS::Message::Type::Treaddir };
@ -888,7 +888,7 @@ KResult Plan9FSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryE
}
}
KResultOr<NonnullRefPtr<Inode>> Plan9FSInode::lookup(StringView name)
ErrorOr<NonnullRefPtr<Inode>> Plan9FSInode::lookup(StringView name)
{
u32 newfid = fs().allocate_fid();
Plan9FS::Message message { fs(), Plan9FS::Message::Type::Twalk };
@ -897,37 +897,37 @@ KResultOr<NonnullRefPtr<Inode>> Plan9FSInode::lookup(StringView name)
return TRY(Plan9FSInode::try_create(fs(), newfid));
}
KResultOr<NonnullRefPtr<Inode>> Plan9FSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
ErrorOr<NonnullRefPtr<Inode>> Plan9FSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
{
// TODO
return ENOTIMPL;
}
KResult Plan9FSInode::add_child(Inode&, const StringView&, mode_t)
ErrorOr<void> Plan9FSInode::add_child(Inode&, const StringView&, mode_t)
{
// TODO
return ENOTIMPL;
}
KResult Plan9FSInode::remove_child(const StringView&)
ErrorOr<void> Plan9FSInode::remove_child(const StringView&)
{
// TODO
return ENOTIMPL;
}
KResult Plan9FSInode::chmod(mode_t)
ErrorOr<void> Plan9FSInode::chmod(mode_t)
{
// TODO
return ENOTIMPL;
}
KResult Plan9FSInode::chown(UserID, GroupID)
ErrorOr<void> Plan9FSInode::chown(UserID, GroupID)
{
// TODO
return ENOTIMPL;
}
KResult Plan9FSInode::truncate(u64 new_size)
ErrorOr<void> Plan9FSInode::truncate(u64 new_size)
{
if (fs().m_remote_protocol_version >= Plan9FS::ProtocolVersion::v9P2000L) {
Plan9FS::Message message { fs(), Plan9FS::Message::Type::Tsetattr };
@ -943,7 +943,7 @@ KResult Plan9FSInode::truncate(u64 new_size)
return fs().post_message_and_wait_for_a_reply(message);
} else {
// TODO: wstat version
return KSuccess;
return {};
}
}

View file

@ -20,9 +20,9 @@ class Plan9FS final : public FileBackedFileSystem {
public:
virtual ~Plan9FS() override;
static KResultOr<NonnullRefPtr<Plan9FS>> try_create(OpenFileDescription&);
static ErrorOr<NonnullRefPtr<Plan9FS>> try_create(OpenFileDescription&);
virtual KResult initialize() override;
virtual ErrorOr<void> initialize() override;
virtual bool supports_watchers() const override { return false; }
@ -74,7 +74,7 @@ private:
bool completed { false };
const u16 tag;
OwnPtr<Message> message;
KResult result { KSuccess };
ErrorOr<void> result;
ReceiveCompletion(u16 tag);
~ReceiveCompletion();
@ -116,11 +116,11 @@ private:
virtual StringView class_name() const override { return "Plan9FS"sv; }
bool is_complete(const ReceiveCompletion&);
KResult post_message(Message&, RefPtr<ReceiveCompletion>);
KResult do_read(u8* buffer, size_t);
KResult read_and_dispatch_one_message();
KResult post_message_and_wait_for_a_reply(Message&);
KResult post_message_and_explicitly_ignore_reply(Message&);
ErrorOr<void> post_message(Message&, RefPtr<ReceiveCompletion>);
ErrorOr<void> do_read(u8* buffer, size_t);
ErrorOr<void> read_and_dispatch_one_message();
ErrorOr<void> post_message_and_wait_for_a_reply(Message&);
ErrorOr<void> post_message_and_explicitly_ignore_reply(Message&);
ProtocolVersion parse_protocol_version(const StringView&) const;
size_t adjust_buffer_size(size_t size) const;
@ -155,21 +155,21 @@ public:
// ^Inode
virtual InodeMetadata metadata() const override;
virtual KResult flush_metadata() override;
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual KResult add_child(Inode&, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(UserID, GroupID) override;
virtual KResult truncate(u64) override;
virtual ErrorOr<void> flush_metadata() override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual ErrorOr<void> add_child(Inode&, const StringView& name, mode_t) override;
virtual ErrorOr<void> remove_child(const StringView& name) override;
virtual ErrorOr<void> chmod(mode_t) override;
virtual ErrorOr<void> chown(UserID, GroupID) override;
virtual ErrorOr<void> truncate(u64) override;
private:
Plan9FSInode(Plan9FS&, u32 fid);
static KResultOr<NonnullRefPtr<Plan9FSInode>> try_create(Plan9FS&, u32 fid);
static ErrorOr<NonnullRefPtr<Plan9FSInode>> try_create(Plan9FS&, u32 fid);
enum class GetAttrMask : u64 {
Mode = 0x1,
@ -206,7 +206,7 @@ private:
// Mode in which the file is already open, using SerenityOS constants.
int m_open_mode { 0 };
KResult ensure_open_for_mode(int mode);
ErrorOr<void> ensure_open_for_mode(int mode);
Plan9FS& fs() { return reinterpret_cast<Plan9FS&>(Inode::fs()); }
Plan9FS& fs() const

View file

@ -37,7 +37,7 @@ UNMAP_AFTER_INIT ProcFSComponentRegistry::ProcFSComponentRegistry()
{
}
KResultOr<NonnullRefPtr<ProcFS>> ProcFS::try_create()
ErrorOr<NonnullRefPtr<ProcFS>> ProcFS::try_create()
{
return adopt_nonnull_ref_or_enomem(new (nothrow) ProcFS());
}
@ -50,10 +50,10 @@ ProcFS::~ProcFS()
{
}
KResult ProcFS::initialize()
ErrorOr<void> ProcFS::initialize()
{
m_root_inode = static_ptr_cast<ProcFSDirectoryInode>(TRY(ProcFSComponentRegistry::the().root_directory().to_inode(*this)));
return KSuccess;
return {};
}
Inode& ProcFS::root_inode()
@ -70,37 +70,37 @@ ProcFSInode::~ProcFSInode()
{
}
KResult ProcFSInode::flush_metadata()
ErrorOr<void> ProcFSInode::flush_metadata()
{
return KSuccess;
return {};
}
KResult ProcFSInode::add_child(Inode&, const StringView&, mode_t)
ErrorOr<void> ProcFSInode::add_child(Inode&, const StringView&, mode_t)
{
return EROFS;
}
KResultOr<NonnullRefPtr<Inode>> ProcFSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
ErrorOr<NonnullRefPtr<Inode>> ProcFSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
{
return EROFS;
}
KResult ProcFSInode::remove_child(const StringView&)
ErrorOr<void> ProcFSInode::remove_child(const StringView&)
{
return EROFS;
}
KResult ProcFSInode::chmod(mode_t)
ErrorOr<void> ProcFSInode::chmod(mode_t)
{
return EPERM;
}
KResult ProcFSInode::chown(UserID, GroupID)
ErrorOr<void> ProcFSInode::chown(UserID, GroupID)
{
return EPERM;
}
KResultOr<NonnullRefPtr<ProcFSGlobalInode>> ProcFSGlobalInode::try_create(const ProcFS& fs, const ProcFSExposedComponent& component)
ErrorOr<NonnullRefPtr<ProcFSGlobalInode>> ProcFSGlobalInode::try_create(const ProcFS& fs, const ProcFSExposedComponent& component)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) ProcFSGlobalInode(fs, component));
}
@ -122,12 +122,12 @@ void ProcFSGlobalInode::did_seek(OpenFileDescription& description, off_t new_off
}
}
KResult ProcFSGlobalInode::attach(OpenFileDescription& description)
ErrorOr<void> ProcFSGlobalInode::attach(OpenFileDescription& description)
{
return m_associated_component->refresh_data(description);
}
KResultOr<size_t> ProcFSGlobalInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* fd) const
ErrorOr<size_t> ProcFSGlobalInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* fd) const
{
return m_associated_component->read_bytes(offset, count, buffer, fd);
}
@ -137,22 +137,22 @@ StringView ProcFSGlobalInode::name() const
return m_associated_component->name();
}
KResult ProcFSGlobalInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
ErrorOr<void> ProcFSGlobalInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
{
VERIFY_NOT_REACHED();
}
KResultOr<NonnullRefPtr<Inode>> ProcFSGlobalInode::lookup(StringView)
ErrorOr<NonnullRefPtr<Inode>> ProcFSGlobalInode::lookup(StringView)
{
VERIFY_NOT_REACHED();
}
KResult ProcFSGlobalInode::truncate(u64 size)
ErrorOr<void> ProcFSGlobalInode::truncate(u64 size)
{
return m_associated_component->truncate(size);
}
KResult ProcFSGlobalInode::set_mtime(time_t time)
ErrorOr<void> ProcFSGlobalInode::set_mtime(time_t time)
{
return m_associated_component->set_mtime(time);
}
@ -170,12 +170,12 @@ InodeMetadata ProcFSGlobalInode::metadata() const
return metadata;
}
KResultOr<size_t> ProcFSGlobalInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& buffer, OpenFileDescription* fd)
ErrorOr<size_t> ProcFSGlobalInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& buffer, OpenFileDescription* fd)
{
return m_associated_component->write_bytes(offset, count, buffer, fd);
}
KResultOr<NonnullRefPtr<ProcFSDirectoryInode>> ProcFSDirectoryInode::try_create(const ProcFS& procfs, const ProcFSExposedComponent& component)
ErrorOr<NonnullRefPtr<ProcFSDirectoryInode>> ProcFSDirectoryInode::try_create(const ProcFS& procfs, const ProcFSExposedComponent& component)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) ProcFSDirectoryInode(procfs, component));
}
@ -200,20 +200,20 @@ InodeMetadata ProcFSDirectoryInode::metadata() const
metadata.mtime = m_associated_component->modified_time();
return metadata;
}
KResult ProcFSDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> ProcFSDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(procfs().m_lock);
return m_associated_component->traverse_as_directory(procfs().fsid(), move(callback));
}
KResultOr<NonnullRefPtr<Inode>> ProcFSDirectoryInode::lookup(StringView name)
ErrorOr<NonnullRefPtr<Inode>> ProcFSDirectoryInode::lookup(StringView name)
{
MutexLocker locker(procfs().m_lock);
auto component = TRY(m_associated_component->lookup(name));
return component->to_inode(procfs());
}
KResultOr<NonnullRefPtr<ProcFSLinkInode>> ProcFSLinkInode::try_create(const ProcFS& procfs, const ProcFSExposedComponent& component)
ErrorOr<NonnullRefPtr<ProcFSLinkInode>> ProcFSLinkInode::try_create(const ProcFS& procfs, const ProcFSExposedComponent& component)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) ProcFSLinkInode(procfs, component));
}
@ -242,12 +242,12 @@ ProcFSProcessAssociatedInode::ProcFSProcessAssociatedInode(const ProcFS& fs, Pro
{
}
KResultOr<size_t> ProcFSProcessAssociatedInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*)
ErrorOr<size_t> ProcFSProcessAssociatedInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*)
{
return ENOTSUP;
}
KResultOr<NonnullRefPtr<ProcFSProcessDirectoryInode>> ProcFSProcessDirectoryInode::try_create(const ProcFS& procfs, ProcessID pid)
ErrorOr<NonnullRefPtr<ProcFSProcessDirectoryInode>> ProcFSProcessDirectoryInode::try_create(const ProcFS& procfs, ProcessID pid)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) ProcFSProcessDirectoryInode(procfs, pid));
}
@ -257,9 +257,9 @@ ProcFSProcessDirectoryInode::ProcFSProcessDirectoryInode(const ProcFS& procfs, P
{
}
KResult ProcFSProcessDirectoryInode::attach(OpenFileDescription&)
ErrorOr<void> ProcFSProcessDirectoryInode::attach(OpenFileDescription&)
{
return KSuccess;
return {};
}
InodeMetadata ProcFSProcessDirectoryInode::metadata() const
@ -280,12 +280,12 @@ InodeMetadata ProcFSProcessDirectoryInode::metadata() const
return metadata;
}
KResultOr<size_t> ProcFSProcessDirectoryInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const
ErrorOr<size_t> ProcFSProcessDirectoryInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const
{
VERIFY_NOT_REACHED();
}
KResult ProcFSProcessDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> ProcFSProcessDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(procfs().m_lock);
auto process = Process::from_pid(associated_pid());
@ -294,7 +294,7 @@ KResult ProcFSProcessDirectoryInode::traverse_as_directory(Function<bool(FileSys
return process->procfs_traits()->traverse_as_directory(procfs().fsid(), move(callback));
}
KResultOr<NonnullRefPtr<Inode>> ProcFSProcessDirectoryInode::lookup(StringView name)
ErrorOr<NonnullRefPtr<Inode>> ProcFSProcessDirectoryInode::lookup(StringView name)
{
MutexLocker locker(procfs().m_lock);
auto process = Process::from_pid(associated_pid());
@ -321,7 +321,7 @@ KResultOr<NonnullRefPtr<Inode>> ProcFSProcessDirectoryInode::lookup(StringView n
return ENOENT;
}
KResultOr<NonnullRefPtr<ProcFSProcessSubDirectoryInode>> ProcFSProcessSubDirectoryInode::try_create(const ProcFS& procfs, SegmentedProcFSIndex::ProcessSubDirectory sub_directory_type, ProcessID pid)
ErrorOr<NonnullRefPtr<ProcFSProcessSubDirectoryInode>> ProcFSProcessSubDirectoryInode::try_create(const ProcFS& procfs, SegmentedProcFSIndex::ProcessSubDirectory sub_directory_type, ProcessID pid)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) ProcFSProcessSubDirectoryInode(procfs, sub_directory_type, pid));
}
@ -332,14 +332,14 @@ ProcFSProcessSubDirectoryInode::ProcFSProcessSubDirectoryInode(const ProcFS& pro
{
}
KResultOr<size_t> ProcFSProcessSubDirectoryInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const
ErrorOr<size_t> ProcFSProcessSubDirectoryInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const
{
VERIFY_NOT_REACHED();
}
KResult ProcFSProcessSubDirectoryInode::attach(OpenFileDescription&)
ErrorOr<void> ProcFSProcessSubDirectoryInode::attach(OpenFileDescription&)
{
return KSuccess;
return {};
}
void ProcFSProcessSubDirectoryInode::did_seek(OpenFileDescription&, off_t)
@ -365,7 +365,7 @@ InodeMetadata ProcFSProcessSubDirectoryInode::metadata() const
return metadata;
}
KResult ProcFSProcessSubDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> ProcFSProcessSubDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(procfs().m_lock);
auto process = Process::from_pid(associated_pid());
@ -382,7 +382,7 @@ KResult ProcFSProcessSubDirectoryInode::traverse_as_directory(Function<bool(File
VERIFY_NOT_REACHED();
}
KResultOr<NonnullRefPtr<Inode>> ProcFSProcessSubDirectoryInode::lookup(StringView name)
ErrorOr<NonnullRefPtr<Inode>> ProcFSProcessSubDirectoryInode::lookup(StringView name)
{
MutexLocker locker(procfs().m_lock);
auto process = Process::from_pid(associated_pid());
@ -398,15 +398,15 @@ KResultOr<NonnullRefPtr<Inode>> ProcFSProcessSubDirectoryInode::lookup(StringVie
}
}
KResultOr<NonnullRefPtr<ProcFSProcessPropertyInode>> ProcFSProcessPropertyInode::try_create_for_file_description_link(const ProcFS& procfs, unsigned file_description_index, ProcessID pid)
ErrorOr<NonnullRefPtr<ProcFSProcessPropertyInode>> ProcFSProcessPropertyInode::try_create_for_file_description_link(const ProcFS& procfs, unsigned file_description_index, ProcessID pid)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) ProcFSProcessPropertyInode(procfs, file_description_index, pid));
}
KResultOr<NonnullRefPtr<ProcFSProcessPropertyInode>> ProcFSProcessPropertyInode::try_create_for_thread_stack(const ProcFS& procfs, ThreadID stack_thread_index, ProcessID pid)
ErrorOr<NonnullRefPtr<ProcFSProcessPropertyInode>> ProcFSProcessPropertyInode::try_create_for_thread_stack(const ProcFS& procfs, ThreadID stack_thread_index, ProcessID pid)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) ProcFSProcessPropertyInode(procfs, stack_thread_index, pid));
}
KResultOr<NonnullRefPtr<ProcFSProcessPropertyInode>> ProcFSProcessPropertyInode::try_create_for_pid_property(const ProcFS& procfs, SegmentedProcFSIndex::MainProcessProperty main_property_type, ProcessID pid)
ErrorOr<NonnullRefPtr<ProcFSProcessPropertyInode>> ProcFSProcessPropertyInode::try_create_for_pid_property(const ProcFS& procfs, SegmentedProcFSIndex::MainProcessProperty main_property_type, ProcessID pid)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) ProcFSProcessPropertyInode(procfs, main_property_type, pid));
}
@ -432,7 +432,7 @@ ProcFSProcessPropertyInode::ProcFSProcessPropertyInode(const ProcFS& procfs, Thr
m_possible_data.property_index = thread_stack_index.value();
}
KResult ProcFSProcessPropertyInode::attach(OpenFileDescription& description)
ErrorOr<void> ProcFSProcessPropertyInode::attach(OpenFileDescription& description)
{
return refresh_data(description);
}
@ -474,11 +474,11 @@ InodeMetadata ProcFSProcessPropertyInode::metadata() const
metadata.mtime = traits->modified_time();
return metadata;
}
KResult ProcFSProcessPropertyInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
ErrorOr<void> ProcFSProcessPropertyInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
{
VERIFY_NOT_REACHED();
}
KResultOr<size_t> ProcFSProcessPropertyInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const
ErrorOr<size_t> ProcFSProcessPropertyInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const
{
dbgln_if(PROCFS_DEBUG, "ProcFS ProcessInformation: read_bytes offset: {} count: {}", offset, count);
@ -489,18 +489,18 @@ KResultOr<size_t> ProcFSProcessPropertyInode::read_bytes(off_t offset, size_t co
auto builder = TRY(KBufferBuilder::try_create());
auto process = Process::from_pid(associated_pid());
if (!process)
return KResult(ESRCH);
return Error::from_errno(ESRCH);
TRY(try_to_acquire_data(*process, builder));
auto data_buffer = builder.build();
if (!data_buffer)
return KResult(EFAULT);
return Error::from_errno(EFAULT);
ssize_t nread = min(static_cast<off_t>(data_buffer->size() - offset), static_cast<off_t>(count));
TRY(buffer.write(data_buffer->data() + offset, nread));
return nread;
}
if (!description->data()) {
dbgln("ProcFS Process Information: Do not have cached data!");
return KResult(EIO);
return Error::from_errno(EIO);
}
MutexLocker locker(m_refresh_lock);
@ -516,29 +516,29 @@ KResultOr<size_t> ProcFSProcessPropertyInode::read_bytes(off_t offset, size_t co
return nread;
}
KResultOr<NonnullRefPtr<Inode>> ProcFSProcessPropertyInode::lookup(StringView)
ErrorOr<NonnullRefPtr<Inode>> ProcFSProcessPropertyInode::lookup(StringView)
{
return EINVAL;
}
static KResult build_from_cached_data(KBufferBuilder& builder, ProcFSInodeData& cached_data)
static ErrorOr<void> build_from_cached_data(KBufferBuilder& builder, ProcFSInodeData& cached_data)
{
cached_data.buffer = builder.build();
if (!cached_data.buffer)
return ENOMEM;
return KSuccess;
return {};
}
KResult ProcFSProcessPropertyInode::try_to_acquire_data(Process& process, KBufferBuilder& builder) const
ErrorOr<void> ProcFSProcessPropertyInode::try_to_acquire_data(Process& process, KBufferBuilder& builder) const
{
// FIXME: Verify process is already ref-counted
if (m_parent_sub_directory_type == SegmentedProcFSIndex::ProcessSubDirectory::OpenFileDescriptions) {
TRY(process.procfs_get_file_description_link(m_possible_data.property_index, builder));
return KSuccess;
return {};
}
if (m_parent_sub_directory_type == SegmentedProcFSIndex::ProcessSubDirectory::Stacks) {
TRY(process.procfs_get_thread_stack(m_possible_data.property_index, builder));
return KSuccess;
return {};
}
VERIFY(m_parent_sub_directory_type == SegmentedProcFSIndex::ProcessSubDirectory::Reserved);
@ -562,14 +562,14 @@ KResult ProcFSProcessPropertyInode::try_to_acquire_data(Process& process, KBuffe
}
}
KResult ProcFSProcessPropertyInode::refresh_data(OpenFileDescription& description)
ErrorOr<void> ProcFSProcessPropertyInode::refresh_data(OpenFileDescription& description)
{
// For process-specific inodes, hold the process's ptrace lock across refresh
// and refuse to load data if the process is not dumpable.
// Without this, files opened before a process went non-dumpable could still be used for dumping.
auto process = Process::from_pid(associated_pid());
if (!process)
return KResult(ESRCH);
return Error::from_errno(ESRCH);
process->ptrace_lock().lock();
if (!process->is_dumpable()) {
process->ptrace_lock().unlock();

View file

@ -28,9 +28,9 @@ class ProcFS final : public FileSystem {
public:
virtual ~ProcFS() override;
static KResultOr<NonnullRefPtr<ProcFS>> try_create();
static ErrorOr<NonnullRefPtr<ProcFS>> try_create();
virtual KResult initialize() override;
virtual ErrorOr<void> initialize() override;
virtual StringView class_name() const override { return "ProcFS"sv; }
virtual Inode& root_inode() override;
@ -54,21 +54,21 @@ protected:
ProcFS const& procfs() const { return static_cast<ProcFS const&>(Inode::fs()); }
// ^Inode
virtual KResult attach(OpenFileDescription& description) = 0;
virtual ErrorOr<void> attach(OpenFileDescription& description) = 0;
virtual void did_seek(OpenFileDescription&, off_t) = 0;
virtual KResult flush_metadata() override final;
virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override final;
virtual KResult add_child(Inode&, const StringView& name, mode_t) override final;
virtual KResult remove_child(const StringView& name) override final;
virtual KResult chmod(mode_t) override final;
virtual KResult chown(UserID, GroupID) override final;
virtual ErrorOr<void> flush_metadata() override final;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override final;
virtual ErrorOr<void> add_child(Inode&, const StringView& name, mode_t) override final;
virtual ErrorOr<void> remove_child(const StringView& name) override final;
virtual ErrorOr<void> chmod(mode_t) override final;
virtual ErrorOr<void> chown(UserID, GroupID) override final;
};
class ProcFSGlobalInode : public ProcFSInode {
friend class ProcFS;
public:
static KResultOr<NonnullRefPtr<ProcFSGlobalInode>> try_create(const ProcFS&, const ProcFSExposedComponent&);
static ErrorOr<NonnullRefPtr<ProcFSGlobalInode>> try_create(const ProcFS&, const ProcFSExposedComponent&);
virtual ~ProcFSGlobalInode() override {};
StringView name() const;
@ -76,15 +76,15 @@ protected:
ProcFSGlobalInode(const ProcFS&, const ProcFSExposedComponent&);
// ^Inode
virtual KResult attach(OpenFileDescription& description) override final;
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override final;
virtual ErrorOr<void> attach(OpenFileDescription& description) override final;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override final;
virtual void did_seek(OpenFileDescription&, off_t) override final;
virtual InodeMetadata metadata() const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView) override;
virtual KResult truncate(u64) override final;
virtual KResult set_mtime(time_t) override final;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView) override;
virtual ErrorOr<void> truncate(u64) override final;
virtual ErrorOr<void> set_mtime(time_t) override final;
NonnullRefPtr<ProcFSExposedComponent> m_associated_component;
};
@ -93,7 +93,7 @@ class ProcFSLinkInode : public ProcFSGlobalInode {
friend class ProcFS;
public:
static KResultOr<NonnullRefPtr<ProcFSLinkInode>> try_create(const ProcFS&, const ProcFSExposedComponent&);
static ErrorOr<NonnullRefPtr<ProcFSLinkInode>> try_create(const ProcFS&, const ProcFSExposedComponent&);
protected:
ProcFSLinkInode(const ProcFS&, const ProcFSExposedComponent&);
@ -104,15 +104,15 @@ class ProcFSDirectoryInode final : public ProcFSGlobalInode {
friend class ProcFS;
public:
static KResultOr<NonnullRefPtr<ProcFSDirectoryInode>> try_create(const ProcFS&, const ProcFSExposedComponent&);
static ErrorOr<NonnullRefPtr<ProcFSDirectoryInode>> try_create(const ProcFS&, const ProcFSExposedComponent&);
virtual ~ProcFSDirectoryInode() override;
protected:
ProcFSDirectoryInode(const ProcFS&, const ProcFSExposedComponent&);
// ^Inode
virtual InodeMetadata metadata() const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
};
class ProcFSProcessAssociatedInode : public ProcFSInode {
@ -123,7 +123,7 @@ protected:
ProcessID associated_pid() const { return m_pid; }
// ^Inode
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override final;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override final;
private:
const ProcessID m_pid;
@ -133,34 +133,34 @@ class ProcFSProcessDirectoryInode final : public ProcFSProcessAssociatedInode {
friend class ProcFS;
public:
static KResultOr<NonnullRefPtr<ProcFSProcessDirectoryInode>> try_create(const ProcFS&, ProcessID);
static ErrorOr<NonnullRefPtr<ProcFSProcessDirectoryInode>> try_create(const ProcFS&, ProcessID);
private:
ProcFSProcessDirectoryInode(const ProcFS&, ProcessID);
// ^Inode
virtual KResult attach(OpenFileDescription& description) override;
virtual ErrorOr<void> attach(OpenFileDescription& description) override;
virtual void did_seek(OpenFileDescription&, off_t) override { }
virtual InodeMetadata metadata() const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
};
class ProcFSProcessSubDirectoryInode final : public ProcFSProcessAssociatedInode {
friend class ProcFS;
public:
static KResultOr<NonnullRefPtr<ProcFSProcessSubDirectoryInode>> try_create(const ProcFS&, SegmentedProcFSIndex::ProcessSubDirectory, ProcessID);
static ErrorOr<NonnullRefPtr<ProcFSProcessSubDirectoryInode>> try_create(const ProcFS&, SegmentedProcFSIndex::ProcessSubDirectory, ProcessID);
private:
ProcFSProcessSubDirectoryInode(const ProcFS&, SegmentedProcFSIndex::ProcessSubDirectory, ProcessID);
// ^Inode
virtual KResult attach(OpenFileDescription& description) override;
virtual ErrorOr<void> attach(OpenFileDescription& description) override;
virtual void did_seek(OpenFileDescription&, off_t) override;
virtual InodeMetadata metadata() const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
const SegmentedProcFSIndex::ProcessSubDirectory m_sub_directory_type;
};
@ -169,24 +169,24 @@ class ProcFSProcessPropertyInode final : public ProcFSProcessAssociatedInode {
friend class ProcFS;
public:
static KResultOr<NonnullRefPtr<ProcFSProcessPropertyInode>> try_create_for_file_description_link(const ProcFS&, unsigned, ProcessID);
static KResultOr<NonnullRefPtr<ProcFSProcessPropertyInode>> try_create_for_thread_stack(const ProcFS&, ThreadID, ProcessID);
static KResultOr<NonnullRefPtr<ProcFSProcessPropertyInode>> try_create_for_pid_property(const ProcFS&, SegmentedProcFSIndex::MainProcessProperty, ProcessID);
static ErrorOr<NonnullRefPtr<ProcFSProcessPropertyInode>> try_create_for_file_description_link(const ProcFS&, unsigned, ProcessID);
static ErrorOr<NonnullRefPtr<ProcFSProcessPropertyInode>> try_create_for_thread_stack(const ProcFS&, ThreadID, ProcessID);
static ErrorOr<NonnullRefPtr<ProcFSProcessPropertyInode>> try_create_for_pid_property(const ProcFS&, SegmentedProcFSIndex::MainProcessProperty, ProcessID);
private:
ProcFSProcessPropertyInode(const ProcFS&, SegmentedProcFSIndex::MainProcessProperty, ProcessID);
ProcFSProcessPropertyInode(const ProcFS&, ThreadID, ProcessID);
ProcFSProcessPropertyInode(const ProcFS&, unsigned, ProcessID);
// ^Inode
virtual KResult attach(OpenFileDescription& description) override;
virtual ErrorOr<void> attach(OpenFileDescription& description) override;
virtual void did_seek(OpenFileDescription&, off_t) override;
virtual InodeMetadata metadata() const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override final;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override final;
KResult refresh_data(OpenFileDescription& description);
KResult try_to_acquire_data(Process& process, KBufferBuilder& builder) const;
ErrorOr<void> refresh_data(OpenFileDescription& description);
ErrorOr<void> try_to_acquire_data(Process& process, KBufferBuilder& builder) const;
const SegmentedProcFSIndex::ProcessSubDirectory m_parent_sub_directory_type;
union {

View file

@ -46,7 +46,7 @@ NonnullRefPtr<SysFSRootDirectory> SysFSRootDirectory::create()
return adopt_ref(*new (nothrow) SysFSRootDirectory);
}
KResult SysFSRootDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> SysFSRootDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(SysFSComponentRegistry::the().get_lock());
callback({ ".", { fsid, component_index() }, 0 });
@ -56,7 +56,7 @@ KResult SysFSRootDirectory::traverse_as_directory(unsigned fsid, Function<bool(F
InodeIdentifier identifier = { fsid, component.component_index() };
callback({ component.name(), identifier, 0 });
}
return KSuccess;
return {};
}
SysFSRootDirectory::SysFSRootDirectory()
@ -69,7 +69,7 @@ SysFSRootDirectory::SysFSRootDirectory()
m_buses_directory = buses_directory;
}
KResultOr<NonnullRefPtr<SysFS>> SysFS::try_create()
ErrorOr<NonnullRefPtr<SysFS>> SysFS::try_create()
{
return adopt_nonnull_ref_or_enomem(new (nothrow) SysFS);
}
@ -82,10 +82,10 @@ SysFS::~SysFS()
{
}
KResult SysFS::initialize()
ErrorOr<void> SysFS::initialize()
{
m_root_inode = TRY(SysFSComponentRegistry::the().root_directory().to_inode(*this));
return KSuccess;
return {};
}
Inode& SysFS::root_inode()
@ -93,7 +93,7 @@ Inode& SysFS::root_inode()
return *m_root_inode;
}
KResultOr<NonnullRefPtr<SysFSInode>> SysFSInode::try_create(SysFS const& fs, SysFSComponent const& component)
ErrorOr<NonnullRefPtr<SysFSInode>> SysFSInode::try_create(SysFS const& fs, SysFSComponent const& component)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) SysFSInode(fs, component));
}
@ -115,22 +115,22 @@ void SysFSInode::did_seek(OpenFileDescription& description, off_t new_offset)
}
}
KResult SysFSInode::attach(OpenFileDescription& description)
ErrorOr<void> SysFSInode::attach(OpenFileDescription& description)
{
return m_associated_component->refresh_data(description);
}
KResultOr<size_t> SysFSInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* fd) const
ErrorOr<size_t> SysFSInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* fd) const
{
return m_associated_component->read_bytes(offset, count, buffer, fd);
}
KResult SysFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
ErrorOr<void> SysFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
{
VERIFY_NOT_REACHED();
}
KResultOr<NonnullRefPtr<Inode>> SysFSInode::lookup(StringView)
ErrorOr<NonnullRefPtr<Inode>> SysFSInode::lookup(StringView)
{
VERIFY_NOT_REACHED();
}
@ -148,52 +148,52 @@ InodeMetadata SysFSInode::metadata() const
return metadata;
}
KResult SysFSInode::flush_metadata()
ErrorOr<void> SysFSInode::flush_metadata()
{
return KSuccess;
return {};
}
KResultOr<size_t> SysFSInode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& buffer, OpenFileDescription* fd)
ErrorOr<size_t> SysFSInode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& buffer, OpenFileDescription* fd)
{
return m_associated_component->write_bytes(offset, count, buffer, fd);
}
KResultOr<NonnullRefPtr<Inode>> SysFSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
ErrorOr<NonnullRefPtr<Inode>> SysFSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID)
{
return EROFS;
}
KResult SysFSInode::add_child(Inode&, StringView const&, mode_t)
ErrorOr<void> SysFSInode::add_child(Inode&, StringView const&, mode_t)
{
return EROFS;
}
KResult SysFSInode::remove_child(StringView const&)
ErrorOr<void> SysFSInode::remove_child(StringView const&)
{
return EROFS;
}
KResult SysFSInode::chmod(mode_t)
ErrorOr<void> SysFSInode::chmod(mode_t)
{
return EPERM;
}
KResult SysFSInode::chown(UserID, GroupID)
ErrorOr<void> SysFSInode::chown(UserID, GroupID)
{
return EPERM;
}
KResult SysFSInode::set_mtime(time_t time)
ErrorOr<void> SysFSInode::set_mtime(time_t time)
{
return m_associated_component->set_mtime(time);
}
KResult SysFSInode::truncate(u64 size)
ErrorOr<void> SysFSInode::truncate(u64 size)
{
return m_associated_component->truncate(size);
}
KResultOr<NonnullRefPtr<SysFSDirectoryInode>> SysFSDirectoryInode::try_create(SysFS const& sysfs, SysFSComponent const& component)
ErrorOr<NonnullRefPtr<SysFSDirectoryInode>> SysFSDirectoryInode::try_create(SysFS const& sysfs, SysFSComponent const& component)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) SysFSDirectoryInode(sysfs, component));
}
@ -219,13 +219,13 @@ InodeMetadata SysFSDirectoryInode::metadata() const
metadata.mtime = mepoch;
return metadata;
}
KResult SysFSDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> SysFSDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(fs().m_lock);
return m_associated_component->traverse_as_directory(fs().fsid(), move(callback));
}
KResultOr<NonnullRefPtr<Inode>> SysFSDirectoryInode::lookup(StringView name)
ErrorOr<NonnullRefPtr<Inode>> SysFSDirectoryInode::lookup(StringView name)
{
MutexLocker locker(fs().m_lock);
auto component = m_associated_component->lookup(name);

View file

@ -19,7 +19,7 @@ class SysFSRootDirectory final : public SysFSDirectory {
public:
static NonnullRefPtr<SysFSRootDirectory> create();
virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
private:
SysFSRootDirectory();
@ -53,7 +53,7 @@ private:
class SysFSBlockDevicesDirectory final : public SysFSDirectory {
public:
static NonnullRefPtr<SysFSBlockDevicesDirectory> must_create(SysFSDevicesDirectory const&);
virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
private:
@ -63,7 +63,7 @@ private:
class SysFSCharacterDevicesDirectory final : public SysFSDirectory {
public:
static NonnullRefPtr<SysFSCharacterDevicesDirectory> must_create(SysFSDevicesDirectory const&);
virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
private:
@ -111,9 +111,9 @@ class SysFS final : public FileSystem {
public:
virtual ~SysFS() override;
static KResultOr<NonnullRefPtr<SysFS>> try_create();
static ErrorOr<NonnullRefPtr<SysFS>> try_create();
virtual KResult initialize() override;
virtual ErrorOr<void> initialize() override;
virtual StringView class_name() const override { return "SysFS"sv; }
virtual Inode& root_inode() override;
@ -129,26 +129,26 @@ class SysFSInode : public Inode {
friend class SysFSDirectoryInode;
public:
static KResultOr<NonnullRefPtr<SysFSInode>> try_create(SysFS const&, SysFSComponent const&);
static ErrorOr<NonnullRefPtr<SysFSInode>> try_create(SysFS const&, SysFSComponent const&);
StringView name() const { return m_associated_component->name(); }
protected:
SysFSInode(SysFS const&, SysFSComponent const&);
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual KResult flush_metadata() override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual InodeMetadata metadata() const override;
virtual KResultOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) override;
virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual KResult add_child(Inode&, StringView const& name, mode_t) override;
virtual KResult remove_child(StringView const& name) override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(UserID, GroupID) override;
virtual KResult truncate(u64) override;
virtual KResult set_mtime(time_t);
virtual ErrorOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) override;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual ErrorOr<void> add_child(Inode&, StringView const& name, mode_t) override;
virtual ErrorOr<void> remove_child(StringView const& name) override;
virtual ErrorOr<void> chmod(mode_t) override;
virtual ErrorOr<void> chown(UserID, GroupID) override;
virtual ErrorOr<void> truncate(u64) override;
virtual ErrorOr<void> set_mtime(time_t);
virtual KResult attach(OpenFileDescription& description) override final;
virtual ErrorOr<void> attach(OpenFileDescription& description) override final;
virtual void did_seek(OpenFileDescription&, off_t) override final;
NonnullRefPtr<SysFSComponent> m_associated_component;
@ -158,7 +158,7 @@ class SysFSDirectoryInode : public SysFSInode {
friend class SysFS;
public:
static KResultOr<NonnullRefPtr<SysFSDirectoryInode>> try_create(SysFS const&, SysFSComponent const&);
static ErrorOr<NonnullRefPtr<SysFSDirectoryInode>> try_create(SysFS const&, SysFSComponent const&);
virtual ~SysFSDirectoryInode() override;
SysFS& fs() { return static_cast<SysFS&>(Inode::fs()); }
@ -168,8 +168,8 @@ protected:
SysFSDirectoryInode(SysFS const&, SysFSComponent const&);
// ^Inode
virtual InodeMetadata metadata() const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
};
}

View file

@ -31,7 +31,7 @@ mode_t SysFSComponent::permissions() const
return S_IRUSR | S_IRGRP | S_IROTH;
}
KResult SysFSDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> SysFSDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(SysFSComponentRegistry::the().get_lock());
VERIFY(m_parent_directory);
@ -42,7 +42,7 @@ KResult SysFSDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileS
InodeIdentifier identifier = { fsid, component.component_index() };
callback({ component.name(), identifier, 0 });
}
return KSuccess;
return {};
}
RefPtr<SysFSComponent> SysFSDirectory::lookup(StringView name)
@ -66,12 +66,12 @@ SysFSDirectory::SysFSDirectory(StringView name, SysFSDirectory const& parent_dir
{
}
KResultOr<NonnullRefPtr<SysFSInode>> SysFSDirectory::to_inode(SysFS const& sysfs_instance) const
ErrorOr<NonnullRefPtr<SysFSInode>> SysFSDirectory::to_inode(SysFS const& sysfs_instance) const
{
return TRY(SysFSDirectoryInode::try_create(sysfs_instance, *this));
}
KResultOr<NonnullRefPtr<SysFSInode>> SysFSComponent::to_inode(SysFS const& sysfs_instance) const
ErrorOr<NonnullRefPtr<SysFSInode>> SysFSComponent::to_inode(SysFS const& sysfs_instance) const
{
return SysFSInode::try_create(sysfs_instance, *this);
}

View file

@ -6,12 +6,12 @@
#pragma once
#include <AK/Error.h>
#include <AK/Function.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/StringView.h>
#include <AK/Types.h>
#include <Kernel/API/KResult.h>
#include <Kernel/FileSystem/File.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/OpenFileDescription.h>
@ -26,16 +26,16 @@ struct SysFSInodeData : public OpenFileDescriptionData {
class SysFSComponent : public RefCounted<SysFSComponent> {
public:
virtual StringView name() const { return m_name->view(); }
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { return KResult(ENOTIMPL); }
virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); }
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { return Error::from_errno(ENOTIMPL); }
virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); }
virtual RefPtr<SysFSComponent> lookup(StringView) { VERIFY_NOT_REACHED(); };
virtual mode_t permissions() const;
virtual KResult truncate(u64) { return EPERM; }
virtual KResult set_mtime(time_t) { return ENOTIMPL; }
virtual KResultOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) { return EROFS; }
virtual KResult refresh_data(OpenFileDescription&) const { return KSuccess; }
virtual ErrorOr<void> truncate(u64) { return EPERM; }
virtual ErrorOr<void> set_mtime(time_t) { return ENOTIMPL; }
virtual ErrorOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) { return EROFS; }
virtual ErrorOr<void> refresh_data(OpenFileDescription&) const { return {}; }
virtual KResultOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const&) const;
virtual ErrorOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const&) const;
InodeIndex component_index() const { return m_component_index; };
@ -51,10 +51,10 @@ private:
class SysFSDirectory : public SysFSComponent {
public:
virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
virtual KResultOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const& sysfs_instance) const override final;
virtual ErrorOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const& sysfs_instance) const override final;
protected:
explicit SysFSDirectory(StringView name);

View file

@ -10,7 +10,7 @@
namespace Kernel {
KResultOr<NonnullRefPtr<TmpFS>> TmpFS::try_create()
ErrorOr<NonnullRefPtr<TmpFS>> TmpFS::try_create()
{
return adopt_nonnull_ref_or_enomem(new (nothrow) TmpFS);
}
@ -23,10 +23,10 @@ TmpFS::~TmpFS()
{
}
KResult TmpFS::initialize()
ErrorOr<void> TmpFS::initialize()
{
m_root_inode = TRY(TmpFSInode::try_create_root(*this));
return KSuccess;
return {};
}
Inode& TmpFS::root_inode()
@ -59,7 +59,7 @@ unsigned TmpFS::next_inode_index()
return m_next_inode_index++;
}
KResultOr<NonnullRefPtr<Inode>> TmpFS::get_inode(InodeIdentifier identifier) const
ErrorOr<NonnullRefPtr<Inode>> TmpFS::get_inode(InodeIdentifier identifier) const
{
MutexLocker locker(m_lock, Mutex::Mode::Shared);
VERIFY(identifier.fsid() == fsid());
@ -82,14 +82,14 @@ TmpFSInode::~TmpFSInode()
{
}
KResultOr<NonnullRefPtr<TmpFSInode>> TmpFSInode::try_create(TmpFS& fs, InodeMetadata const& metadata, InodeIdentifier parent)
ErrorOr<NonnullRefPtr<TmpFSInode>> TmpFSInode::try_create(TmpFS& fs, InodeMetadata const& metadata, InodeIdentifier parent)
{
auto inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) TmpFSInode(fs, metadata, parent)));
fs.register_inode(inode);
return inode;
}
KResultOr<NonnullRefPtr<TmpFSInode>> TmpFSInode::try_create_root(TmpFS& fs)
ErrorOr<NonnullRefPtr<TmpFSInode>> TmpFSInode::try_create_root(TmpFS& fs)
{
InodeMetadata metadata;
auto now = kgettimeofday().to_truncated_seconds();
@ -107,7 +107,7 @@ InodeMetadata TmpFSInode::metadata() const
return m_metadata;
}
KResult TmpFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
ErrorOr<void> TmpFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(m_inode_lock, Mutex::Mode::Shared);
@ -120,10 +120,10 @@ KResult TmpFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEnt
for (auto& child : m_children) {
callback({ child.name->view(), child.inode->identifier(), 0 });
}
return KSuccess;
return {};
}
KResultOr<size_t> TmpFSInode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, OpenFileDescription*) const
ErrorOr<size_t> TmpFSInode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, OpenFileDescription*) const
{
MutexLocker locker(m_inode_lock, Mutex::Mode::Shared);
VERIFY(!is_directory());
@ -142,7 +142,7 @@ KResultOr<size_t> TmpFSInode::read_bytes(off_t offset, size_t size, UserOrKernel
return size;
}
KResultOr<size_t> TmpFSInode::write_bytes(off_t offset, size_t size, const UserOrKernelBuffer& buffer, OpenFileDescription*)
ErrorOr<size_t> TmpFSInode::write_bytes(off_t offset, size_t size, const UserOrKernelBuffer& buffer, OpenFileDescription*)
{
MutexLocker locker(m_inode_lock);
VERIFY(!is_directory());
@ -185,7 +185,7 @@ KResultOr<size_t> TmpFSInode::write_bytes(off_t offset, size_t size, const UserO
return size;
}
KResultOr<NonnullRefPtr<Inode>> TmpFSInode::lookup(StringView name)
ErrorOr<NonnullRefPtr<Inode>> TmpFSInode::lookup(StringView name)
{
MutexLocker locker(m_inode_lock, Mutex::Mode::Shared);
VERIFY(is_directory());
@ -216,7 +216,7 @@ void TmpFSInode::notify_watchers()
set_metadata_dirty(false);
}
KResult TmpFSInode::flush_metadata()
ErrorOr<void> TmpFSInode::flush_metadata()
{
// We don't really have any metadata that could become dirty.
// The only reason we even call set_metadata_dirty() is
@ -224,29 +224,29 @@ KResult TmpFSInode::flush_metadata()
// switched to a different mechanism, we can stop ever marking
// our metadata as dirty at all.
set_metadata_dirty(false);
return KSuccess;
return {};
}
KResult TmpFSInode::chmod(mode_t mode)
ErrorOr<void> TmpFSInode::chmod(mode_t mode)
{
MutexLocker locker(m_inode_lock);
m_metadata.mode = mode;
notify_watchers();
return KSuccess;
return {};
}
KResult TmpFSInode::chown(UserID uid, GroupID gid)
ErrorOr<void> TmpFSInode::chown(UserID uid, GroupID gid)
{
MutexLocker locker(m_inode_lock);
m_metadata.uid = uid;
m_metadata.gid = gid;
notify_watchers();
return KSuccess;
return {};
}
KResultOr<NonnullRefPtr<Inode>> TmpFSInode::create_child(StringView name, mode_t mode, dev_t dev, UserID uid, GroupID gid)
ErrorOr<NonnullRefPtr<Inode>> TmpFSInode::create_child(StringView name, mode_t mode, dev_t dev, UserID uid, GroupID gid)
{
MutexLocker locker(m_inode_lock);
@ -269,7 +269,7 @@ KResultOr<NonnullRefPtr<Inode>> TmpFSInode::create_child(StringView name, mode_t
return child;
}
KResult TmpFSInode::add_child(Inode& child, StringView const& name, mode_t)
ErrorOr<void> TmpFSInode::add_child(Inode& child, StringView const& name, mode_t)
{
VERIFY(is_directory());
VERIFY(child.fsid() == fsid());
@ -286,16 +286,16 @@ KResult TmpFSInode::add_child(Inode& child, StringView const& name, mode_t)
MutexLocker locker(m_inode_lock);
m_children.append(*child_entry);
did_add_child(child.identifier(), name);
return KSuccess;
return {};
}
KResult TmpFSInode::remove_child(StringView const& name)
ErrorOr<void> TmpFSInode::remove_child(StringView const& name)
{
MutexLocker locker(m_inode_lock);
VERIFY(is_directory());
if (name == "." || name == "..")
return KSuccess;
return {};
auto* child = find_child_by_name(name);
if (!child)
@ -307,10 +307,10 @@ KResult TmpFSInode::remove_child(StringView const& name)
did_remove_child(child_id, name);
// Balanced by `new` in add_child()
delete child;
return KSuccess;
return {};
}
KResult TmpFSInode::truncate(u64 size)
ErrorOr<void> TmpFSInode::truncate(u64 size)
{
MutexLocker locker(m_inode_lock);
VERIFY(!is_directory());
@ -333,34 +333,34 @@ KResult TmpFSInode::truncate(u64 size)
m_metadata.size = size;
notify_watchers();
return KSuccess;
return {};
}
KResult TmpFSInode::set_atime(time_t time)
ErrorOr<void> TmpFSInode::set_atime(time_t time)
{
MutexLocker locker(m_inode_lock);
m_metadata.atime = time;
notify_watchers();
return KSuccess;
return {};
}
KResult TmpFSInode::set_ctime(time_t time)
ErrorOr<void> TmpFSInode::set_ctime(time_t time)
{
MutexLocker locker(m_inode_lock);
m_metadata.ctime = time;
notify_watchers();
return KSuccess;
return {};
}
KResult TmpFSInode::set_mtime(time_t t)
ErrorOr<void> TmpFSInode::set_mtime(time_t t)
{
MutexLocker locker(m_inode_lock);
m_metadata.mtime = t;
notify_watchers();
return KSuccess;
return {};
}
void TmpFSInode::one_ref_left()

View file

@ -19,8 +19,8 @@ class TmpFS final : public FileSystem {
public:
virtual ~TmpFS() override;
static KResultOr<NonnullRefPtr<TmpFS>> try_create();
virtual KResult initialize() override;
static ErrorOr<NonnullRefPtr<TmpFS>> try_create();
virtual ErrorOr<void> initialize() override;
virtual StringView class_name() const override { return "TmpFS"sv; }
@ -34,7 +34,7 @@ private:
RefPtr<TmpFSInode> m_root_inode;
HashMap<InodeIndex, NonnullRefPtr<TmpFSInode>> m_inodes;
KResultOr<NonnullRefPtr<Inode>> get_inode(InodeIdentifier identifier) const;
ErrorOr<NonnullRefPtr<Inode>> get_inode(InodeIdentifier identifier) const;
void register_inode(TmpFSInode&);
void unregister_inode(InodeIdentifier);
@ -52,27 +52,27 @@ public:
const TmpFS& fs() const { return static_cast<const TmpFS&>(Inode::fs()); }
// ^Inode
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual InodeMetadata metadata() const override;
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual KResult flush_metadata() override;
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual KResult add_child(Inode&, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(UserID, GroupID) override;
virtual KResult truncate(u64) override;
virtual KResult set_atime(time_t) override;
virtual KResult set_ctime(time_t) override;
virtual KResult set_mtime(time_t) override;
virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual ErrorOr<void> add_child(Inode&, const StringView& name, mode_t) override;
virtual ErrorOr<void> remove_child(const StringView& name) override;
virtual ErrorOr<void> chmod(mode_t) override;
virtual ErrorOr<void> chown(UserID, GroupID) override;
virtual ErrorOr<void> truncate(u64) override;
virtual ErrorOr<void> set_atime(time_t) override;
virtual ErrorOr<void> set_ctime(time_t) override;
virtual ErrorOr<void> set_mtime(time_t) override;
virtual void one_ref_left() override;
private:
TmpFSInode(TmpFS& fs, const InodeMetadata& metadata, InodeIdentifier parent);
static KResultOr<NonnullRefPtr<TmpFSInode>> try_create(TmpFS&, InodeMetadata const& metadata, InodeIdentifier parent);
static KResultOr<NonnullRefPtr<TmpFSInode>> try_create_root(TmpFS&);
static ErrorOr<NonnullRefPtr<TmpFSInode>> try_create(TmpFS&, InodeMetadata const& metadata, InodeIdentifier parent);
static ErrorOr<NonnullRefPtr<TmpFSInode>> try_create_root(TmpFS&);
void notify_watchers();
struct Child {

View file

@ -51,9 +51,9 @@ InodeIdentifier VirtualFileSystem::root_inode_id() const
return m_root_inode->identifier();
}
KResult VirtualFileSystem::mount(FileSystem& fs, Custody& mount_point, int flags)
ErrorOr<void> VirtualFileSystem::mount(FileSystem& fs, Custody& mount_point, int flags)
{
return m_mounts.with_exclusive([&](auto& mounts) -> KResult {
return m_mounts.with_exclusive([&](auto& mounts) -> ErrorOr<void> {
auto& inode = mount_point.inode();
dbgln("VirtualFileSystem: Mounting {} at inode {} with flags {}",
fs.class_name(),
@ -62,22 +62,22 @@ KResult VirtualFileSystem::mount(FileSystem& fs, Custody& mount_point, int flags
// FIXME: check that this is not already a mount point
Mount mount { fs, &mount_point, flags };
mounts.append(move(mount));
return KSuccess;
return {};
});
}
KResult VirtualFileSystem::bind_mount(Custody& source, Custody& mount_point, int flags)
ErrorOr<void> VirtualFileSystem::bind_mount(Custody& source, Custody& mount_point, int flags)
{
return m_mounts.with_exclusive([&](auto& mounts) -> KResult {
return m_mounts.with_exclusive([&](auto& mounts) -> ErrorOr<void> {
dbgln("VirtualFileSystem: Bind-mounting inode {} at inode {}", source.inode().identifier(), mount_point.inode().identifier());
// FIXME: check that this is not already a mount point
Mount mount { source.inode(), mount_point, flags };
mounts.append(move(mount));
return KSuccess;
return {};
});
}
KResult VirtualFileSystem::remount(Custody& mount_point, int new_flags)
ErrorOr<void> VirtualFileSystem::remount(Custody& mount_point, int new_flags)
{
dbgln("VirtualFileSystem: Remounting inode {}", mount_point.inode().identifier());
@ -86,14 +86,14 @@ KResult VirtualFileSystem::remount(Custody& mount_point, int new_flags)
return ENODEV;
mount->set_flags(new_flags);
return KSuccess;
return {};
}
KResult VirtualFileSystem::unmount(Inode& guest_inode)
ErrorOr<void> VirtualFileSystem::unmount(Inode& guest_inode)
{
dbgln("VirtualFileSystem: unmount called with inode {}", guest_inode.identifier());
return m_mounts.with_exclusive([&](auto& mounts) -> KResult {
return m_mounts.with_exclusive([&](auto& mounts) -> ErrorOr<void> {
for (size_t i = 0; i < mounts.size(); ++i) {
auto& mount = mounts[i];
if (&mount.guest() != &guest_inode)
@ -101,14 +101,14 @@ KResult VirtualFileSystem::unmount(Inode& guest_inode)
TRY(mount.guest_fs().prepare_to_unmount());
dbgln("VirtualFileSystem: Unmounting file system {}...", mount.guest_fs().fsid());
mounts.unstable_take(i);
return KSuccess;
return {};
}
dbgln("VirtualFileSystem: Nothing mounted on inode {}", guest_inode.identifier());
return ENODEV;
});
}
KResult VirtualFileSystem::mount_root(FileSystem& fs)
ErrorOr<void> VirtualFileSystem::mount_root(FileSystem& fs)
{
if (m_root_inode) {
dmesgln("VirtualFileSystem: mount_root can't mount another root");
@ -132,7 +132,7 @@ KResult VirtualFileSystem::mount_root(FileSystem& fs)
});
m_root_custody = TRY(Custody::try_create(nullptr, "", *m_root_inode, root_mount_flags));
return KSuccess;
return {};
}
auto VirtualFileSystem::find_mount_for_host(InodeIdentifier id) -> Mount*
@ -162,7 +162,7 @@ bool VirtualFileSystem::is_vfs_root(InodeIdentifier inode) const
return inode == root_inode_id();
}
KResult VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function<bool(FileSystem::DirectoryEntryView const&)> callback)
ErrorOr<void> VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function<bool(FileSystem::DirectoryEntryView const&)> callback)
{
return dir_inode.traverse_as_directory([&](auto& entry) {
InodeIdentifier resolved_inode;
@ -184,7 +184,7 @@ KResult VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function<b
});
}
KResult VirtualFileSystem::utime(StringView path, Custody& base, time_t atime, time_t mtime)
ErrorOr<void> VirtualFileSystem::utime(StringView path, Custody& base, time_t atime, time_t mtime)
{
auto custody = TRY(resolve_path(path, base));
auto& inode = custody->inode();
@ -196,16 +196,16 @@ KResult VirtualFileSystem::utime(StringView path, Custody& base, time_t atime, t
TRY(inode.set_atime(atime));
TRY(inode.set_mtime(mtime));
return KSuccess;
return {};
}
KResultOr<InodeMetadata> VirtualFileSystem::lookup_metadata(StringView path, Custody& base, int options)
ErrorOr<InodeMetadata> VirtualFileSystem::lookup_metadata(StringView path, Custody& base, int options)
{
auto custody = TRY(resolve_path(path, base, nullptr, options));
return custody->inode().metadata();
}
KResultOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> owner)
ErrorOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> owner)
{
if ((options & O_CREAT) && (options & O_DIRECTORY))
return EINVAL;
@ -215,9 +215,9 @@ KResultOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::open(StringView
if (custody_or_error.is_error()) {
// NOTE: ENOENT with a non-null parent custody signals us that the immediate parent
// of the file exists, but the file itself does not.
if ((options & O_CREAT) && custody_or_error.error() == ENOENT && parent_custody)
if ((options & O_CREAT) && custody_or_error.error().code() == ENOENT && parent_custody)
return create(path, options, mode, *parent_custody, move(owner));
return custody_or_error.error();
return custody_or_error.release_error();
}
if ((options & O_CREAT) && (options & O_EXCL))
@ -297,7 +297,7 @@ KResultOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::open(StringView
return description;
}
KResult VirtualFileSystem::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
ErrorOr<void> VirtualFileSystem::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
{
if (!is_regular_file(mode) && !is_block_device(mode) && !is_character_device(mode) && !is_fifo(mode) && !is_socket(mode))
return EINVAL;
@ -308,8 +308,8 @@ KResult VirtualFileSystem::mknod(StringView path, mode_t mode, dev_t dev, Custod
return EEXIST;
if (!parent_custody)
return ENOENT;
if (existing_file_or_error.error() != ENOENT)
return existing_file_or_error.error();
if (existing_file_or_error.error().code() != ENOENT)
return existing_file_or_error.release_error();
auto& parent_inode = parent_custody->inode();
auto& current_process = Process::current();
if (!parent_inode.metadata().may_write(current_process))
@ -319,10 +319,11 @@ KResult VirtualFileSystem::mknod(StringView path, mode_t mode, dev_t dev, Custod
auto basename = KLexicalPath::basename(path);
dbgln_if(VFS_DEBUG, "VirtualFileSystem::mknod: '{}' mode={} dev={} in {}", basename, mode, dev, parent_inode.identifier());
return parent_inode.create_child(basename, mode, dev, current_process.euid(), current_process.egid()).result();
TRY(parent_inode.create_child(basename, mode, dev, current_process.euid(), current_process.egid()));
return {};
}
KResultOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner)
ErrorOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner)
{
auto basename = KLexicalPath::basename(path);
auto parent_path = TRY(parent_custody.try_serialize_absolute_path());
@ -354,7 +355,7 @@ KResultOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::create(StringVi
return description;
}
KResult VirtualFileSystem::mkdir(StringView path, mode_t mode, Custody& base)
ErrorOr<void> VirtualFileSystem::mkdir(StringView path, mode_t mode, Custody& base)
{
// Unlike in basically every other case, where it's only the last
// path component (the one being created) that is allowed not to
@ -371,9 +372,9 @@ KResult VirtualFileSystem::mkdir(StringView path, mode_t mode, Custody& base)
if (!result.is_error())
return EEXIST;
else if (!parent_custody)
return result.error();
return result.release_error();
// NOTE: If resolve_path fails with a non-null parent custody, the error should be ENOENT.
VERIFY(result.error() == ENOENT);
VERIFY(result.error().code() == ENOENT);
auto& parent_inode = parent_custody->inode();
auto& current_process = Process::current();
@ -384,10 +385,11 @@ KResult VirtualFileSystem::mkdir(StringView path, mode_t mode, Custody& base)
auto basename = KLexicalPath::basename(path);
dbgln_if(VFS_DEBUG, "VirtualFileSystem::mkdir: '{}' in {}", basename, parent_inode.identifier());
return parent_inode.create_child(basename, S_IFDIR | mode, 0, current_process.euid(), current_process.egid()).result();
TRY(parent_inode.create_child(basename, S_IFDIR | mode, 0, current_process.euid(), current_process.egid()));
return {};
}
KResult VirtualFileSystem::access(StringView path, int mode, Custody& base)
ErrorOr<void> VirtualFileSystem::access(StringView path, int mode, Custody& base)
{
auto custody = TRY(resolve_path(path, base));
@ -408,10 +410,10 @@ KResult VirtualFileSystem::access(StringView path, int mode, Custody& base)
if (!metadata.may_execute(current_process))
return EACCES;
}
return KSuccess;
return {};
}
KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::open_directory(StringView path, Custody& base)
ErrorOr<NonnullRefPtr<Custody>> VirtualFileSystem::open_directory(StringView path, Custody& base)
{
auto custody = TRY(resolve_path(path, base));
auto& inode = custody->inode();
@ -422,7 +424,7 @@ KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::open_directory(StringView p
return custody;
}
KResult VirtualFileSystem::chmod(Custody& custody, mode_t mode)
ErrorOr<void> VirtualFileSystem::chmod(Custody& custody, mode_t mode)
{
auto& inode = custody.inode();
@ -437,13 +439,13 @@ KResult VirtualFileSystem::chmod(Custody& custody, mode_t mode)
return inode.chmod(mode);
}
KResult VirtualFileSystem::chmod(StringView path, mode_t mode, Custody& base)
ErrorOr<void> VirtualFileSystem::chmod(StringView path, mode_t mode, Custody& base)
{
auto custody = TRY(resolve_path(path, base));
return chmod(custody, mode);
}
KResult VirtualFileSystem::rename(StringView old_path, StringView new_path, Custody& base)
ErrorOr<void> VirtualFileSystem::rename(StringView old_path, StringView new_path, Custody& base)
{
RefPtr<Custody> old_parent_custody;
auto old_custody = TRY(resolve_path(old_path, base, &old_parent_custody, O_NOFOLLOW_NOERROR));
@ -452,8 +454,8 @@ KResult VirtualFileSystem::rename(StringView old_path, StringView new_path, Cust
RefPtr<Custody> new_parent_custody;
auto new_custody_or_error = resolve_path(new_path, base, &new_parent_custody);
if (new_custody_or_error.is_error()) {
if (new_custody_or_error.error() != ENOENT || !new_parent_custody)
return new_custody_or_error.error();
if (new_custody_or_error.error().code() != ENOENT || !new_parent_custody)
return new_custody_or_error.release_error();
}
if (!old_parent_custody || !new_parent_custody) {
@ -509,14 +511,14 @@ KResult VirtualFileSystem::rename(StringView old_path, StringView new_path, Cust
return EINVAL;
if (old_basename == new_basename && old_parent_inode.index() == new_parent_inode.index())
return KSuccess;
return {};
if (!new_custody_or_error.is_error()) {
auto& new_custody = *new_custody_or_error.value();
auto& new_inode = new_custody.inode();
// FIXME: Is this really correct? Check what other systems do.
if (&new_inode == &old_inode)
return KSuccess;
return {};
if (new_parent_inode.metadata().is_sticky()) {
if (!current_process.is_superuser() && new_inode.metadata().uid != current_process.euid())
return EACCES;
@ -528,10 +530,10 @@ KResult VirtualFileSystem::rename(StringView old_path, StringView new_path, Cust
TRY(new_parent_inode.add_child(old_inode, new_basename, old_inode.mode()));
TRY(old_parent_inode.remove_child(old_basename));
return KSuccess;
return {};
}
KResult VirtualFileSystem::chown(Custody& custody, UserID a_uid, GroupID a_gid)
ErrorOr<void> VirtualFileSystem::chown(Custody& custody, UserID a_uid, GroupID a_gid)
{
auto& inode = custody.inode();
auto metadata = inode.metadata();
@ -567,7 +569,7 @@ KResult VirtualFileSystem::chown(Custody& custody, UserID a_uid, GroupID a_gid)
return inode.chown(new_uid, new_gid);
}
KResult VirtualFileSystem::chown(StringView path, UserID a_uid, GroupID a_gid, Custody& base)
ErrorOr<void> VirtualFileSystem::chown(StringView path, UserID a_uid, GroupID a_gid, Custody& base)
{
auto custody = TRY(resolve_path(path, base));
return chown(custody, a_uid, a_gid);
@ -590,7 +592,7 @@ static bool hard_link_allowed(const Inode& inode)
return false;
}
KResult VirtualFileSystem::link(StringView old_path, StringView new_path, Custody& base)
ErrorOr<void> VirtualFileSystem::link(StringView old_path, StringView new_path, Custody& base)
{
auto old_custody = TRY(resolve_path(old_path, base));
auto& old_inode = old_custody->inode();
@ -623,7 +625,7 @@ KResult VirtualFileSystem::link(StringView old_path, StringView new_path, Custod
return parent_inode.add_child(old_inode, KLexicalPath::basename(new_path), old_inode.mode());
}
KResult VirtualFileSystem::unlink(StringView path, Custody& base)
ErrorOr<void> VirtualFileSystem::unlink(StringView path, Custody& base)
{
RefPtr<Custody> parent_custody;
auto custody = TRY(resolve_path(path, base, &parent_custody, O_NOFOLLOW_NOERROR | O_UNLINK_INTERNAL));
@ -653,7 +655,7 @@ KResult VirtualFileSystem::unlink(StringView path, Custody& base)
return parent_inode.remove_child(KLexicalPath::basename(path));
}
KResult VirtualFileSystem::symlink(StringView target, StringView linkpath, Custody& base)
ErrorOr<void> VirtualFileSystem::symlink(StringView target, StringView linkpath, Custody& base)
{
RefPtr<Custody> parent_custody;
auto existing_custody_or_error = resolve_path(linkpath, base, &parent_custody);
@ -661,8 +663,8 @@ KResult VirtualFileSystem::symlink(StringView target, StringView linkpath, Custo
return EEXIST;
if (!parent_custody)
return ENOENT;
if (existing_custody_or_error.is_error() && existing_custody_or_error.error() != ENOENT)
return existing_custody_or_error.error();
if (existing_custody_or_error.is_error() && existing_custody_or_error.error().code() != ENOENT)
return existing_custody_or_error.release_error();
auto& parent_inode = parent_custody->inode();
auto& current_process = Process::current();
if (!parent_inode.metadata().may_write(current_process))
@ -677,10 +679,10 @@ KResult VirtualFileSystem::symlink(StringView target, StringView linkpath, Custo
auto target_buffer = UserOrKernelBuffer::for_kernel_buffer(const_cast<u8*>((const u8*)target.characters_without_null_termination()));
TRY(inode->write_bytes(0, target.length(), target_buffer, nullptr));
return KSuccess;
return {};
}
KResult VirtualFileSystem::rmdir(StringView path, Custody& base)
ErrorOr<void> VirtualFileSystem::rmdir(StringView path, Custody& base)
{
RefPtr<Custody> parent_custody;
auto custody = TRY(resolve_path(path, base, &parent_custody));
@ -755,20 +757,20 @@ UnveilNode const& VirtualFileSystem::find_matching_unveiled_path(StringView path
return unveil_root.traverse_until_last_accessible_node(path_parts.begin(), path_parts.end());
}
KResult VirtualFileSystem::validate_path_against_process_veil(Custody const& custody, int options)
ErrorOr<void> VirtualFileSystem::validate_path_against_process_veil(Custody const& custody, int options)
{
if (Process::current().veil_state() == VeilState::None)
return KSuccess;
return {};
auto absolute_path = TRY(custody.try_serialize_absolute_path());
return validate_path_against_process_veil(absolute_path->view(), options);
}
KResult VirtualFileSystem::validate_path_against_process_veil(StringView path, int options)
ErrorOr<void> VirtualFileSystem::validate_path_against_process_veil(StringView path, int options)
{
if (Process::current().veil_state() == VeilState::None)
return KSuccess;
return {};
if (options == O_EXEC && path == "/usr/lib/Loader.so")
return KSuccess;
return {};
VERIFY(path.starts_with('/'));
VERIFY(!path.contains("/../"sv) && !path.ends_with("/.."sv));
@ -794,7 +796,7 @@ KResult VirtualFileSystem::validate_path_against_process_veil(StringView path, i
dump_backtrace();
return EACCES;
}
return KSuccess;
return {};
}
if (options & O_RDONLY) {
if (options & O_DIRECTORY) {
@ -825,10 +827,10 @@ KResult VirtualFileSystem::validate_path_against_process_veil(StringView path, i
return EACCES;
}
}
return KSuccess;
return {};
}
KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path(StringView path, Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level)
ErrorOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path(StringView path, Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level)
{
auto custody = TRY(resolve_path_without_veil(path, base, out_parent, options, symlink_recursion_level));
TRY(validate_path_against_process_veil(*custody, options));
@ -850,7 +852,7 @@ static bool safe_to_follow_symlink(const Inode& inode, const InodeMetadata& pare
return false;
}
KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path_without_veil(StringView path, Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level)
ErrorOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path_without_veil(StringView path, Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level)
{
if (symlink_recursion_level >= symlink_recursion_limit)
return ELOOP;
@ -898,7 +900,7 @@ KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path_without_veil(S
// does not exist yet.
*out_parent = have_more_parts ? nullptr : &parent;
}
return child_or_error.error();
return child_or_error.release_error();
}
auto child_inode = child_or_error.release_value();

View file

@ -7,13 +7,13 @@
#pragma once
#include <AK/Badge.h>
#include <AK/Error.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtrVector.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <Kernel/API/KResult.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
#include <Kernel/FileSystem/InodeMetadata.h>
@ -42,29 +42,29 @@ public:
VirtualFileSystem();
~VirtualFileSystem();
KResult mount_root(FileSystem&);
KResult mount(FileSystem&, Custody& mount_point, int flags);
KResult bind_mount(Custody& source, Custody& mount_point, int flags);
KResult remount(Custody& mount_point, int new_flags);
KResult unmount(Inode& guest_inode);
ErrorOr<void> mount_root(FileSystem&);
ErrorOr<void> mount(FileSystem&, Custody& mount_point, int flags);
ErrorOr<void> bind_mount(Custody& source, Custody& mount_point, int flags);
ErrorOr<void> remount(Custody& mount_point, int new_flags);
ErrorOr<void> unmount(Inode& guest_inode);
KResultOr<NonnullRefPtr<OpenFileDescription>> open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});
KResultOr<NonnullRefPtr<OpenFileDescription>> create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> = {});
KResult mkdir(StringView path, mode_t mode, Custody& base);
KResult link(StringView old_path, StringView new_path, Custody& base);
KResult unlink(StringView path, Custody& base);
KResult symlink(StringView target, StringView linkpath, Custody& base);
KResult rmdir(StringView path, Custody& base);
KResult chmod(StringView path, mode_t, Custody& base);
KResult chmod(Custody&, mode_t);
KResult chown(StringView path, UserID, GroupID, Custody& base);
KResult chown(Custody&, UserID, GroupID);
KResult access(StringView path, int mode, Custody& base);
KResultOr<InodeMetadata> lookup_metadata(StringView path, Custody& base, int options = 0);
KResult utime(StringView path, Custody& base, time_t atime, time_t mtime);
KResult rename(StringView oldpath, StringView newpath, Custody& base);
KResult mknod(StringView path, mode_t, dev_t, Custody& base);
KResultOr<NonnullRefPtr<Custody>> open_directory(StringView path, Custody& base);
ErrorOr<NonnullRefPtr<OpenFileDescription>> open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});
ErrorOr<NonnullRefPtr<OpenFileDescription>> create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> = {});
ErrorOr<void> mkdir(StringView path, mode_t mode, Custody& base);
ErrorOr<void> link(StringView old_path, StringView new_path, Custody& base);
ErrorOr<void> unlink(StringView path, Custody& base);
ErrorOr<void> symlink(StringView target, StringView linkpath, Custody& base);
ErrorOr<void> rmdir(StringView path, Custody& base);
ErrorOr<void> chmod(StringView path, mode_t, Custody& base);
ErrorOr<void> chmod(Custody&, mode_t);
ErrorOr<void> chown(StringView path, UserID, GroupID, Custody& base);
ErrorOr<void> chown(Custody&, UserID, GroupID);
ErrorOr<void> access(StringView path, int mode, Custody& base);
ErrorOr<InodeMetadata> lookup_metadata(StringView path, Custody& base, int options = 0);
ErrorOr<void> utime(StringView path, Custody& base, time_t atime, time_t mtime);
ErrorOr<void> rename(StringView oldpath, StringView newpath, Custody& base);
ErrorOr<void> mknod(StringView path, mode_t, dev_t, Custody& base);
ErrorOr<NonnullRefPtr<Custody>> open_directory(StringView path, Custody& base);
void for_each_mount(Function<IterationDecision(const Mount&)>) const;
@ -73,19 +73,19 @@ public:
static void sync();
Custody& root_custody();
KResultOr<NonnullRefPtr<Custody>> resolve_path(StringView path, Custody& base, RefPtr<Custody>* out_parent = nullptr, int options = 0, int symlink_recursion_level = 0);
KResultOr<NonnullRefPtr<Custody>> resolve_path_without_veil(StringView path, Custody& base, RefPtr<Custody>* out_parent = nullptr, int options = 0, int symlink_recursion_level = 0);
ErrorOr<NonnullRefPtr<Custody>> resolve_path(StringView path, Custody& base, RefPtr<Custody>* out_parent = nullptr, int options = 0, int symlink_recursion_level = 0);
ErrorOr<NonnullRefPtr<Custody>> resolve_path_without_veil(StringView path, Custody& base, RefPtr<Custody>* out_parent = nullptr, int options = 0, int symlink_recursion_level = 0);
private:
friend class OpenFileDescription;
UnveilNode const& find_matching_unveiled_path(StringView path);
KResult validate_path_against_process_veil(Custody const& path, int options);
KResult validate_path_against_process_veil(StringView path, int options);
ErrorOr<void> validate_path_against_process_veil(Custody const& path, int options);
ErrorOr<void> validate_path_against_process_veil(StringView path, int options);
bool is_vfs_root(InodeIdentifier) const;
KResult traverse_directory_inode(Inode&, Function<bool(FileSystem::DirectoryEntryView const&)>);
ErrorOr<void> traverse_directory_inode(Inode&, Function<bool(FileSystem::DirectoryEntryView const&)>);
Mount* find_mount_for_host(InodeIdentifier);
Mount* find_mount_for_guest(InodeIdentifier);

View file

@ -39,19 +39,19 @@ UNMAP_AFTER_INIT NonnullRefPtr<ACPISysFSComponent> ACPISysFSComponent::create(St
return adopt_ref(*new (nothrow) ACPISysFSComponent(name, paddr, table_size));
}
KResultOr<size_t> ACPISysFSComponent::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const
ErrorOr<size_t> ACPISysFSComponent::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const
{
auto blob = TRY(try_to_generate_buffer());
if ((size_t)offset >= blob->size())
return KSuccess;
return 0;
ssize_t nread = min(static_cast<off_t>(blob->size() - offset), static_cast<off_t>(count));
TRY(buffer.write(blob->data() + offset, nread));
return nread;
}
KResultOr<NonnullOwnPtr<KBuffer>> ACPISysFSComponent::try_to_generate_buffer() const
ErrorOr<NonnullOwnPtr<KBuffer>> ACPISysFSComponent::try_to_generate_buffer() const
{
auto acpi_blob = Memory::map_typed<u8>((m_paddr), m_length);
return KBuffer::try_create_with_bytes(Span<u8> { acpi_blob.ptr(), m_length });
@ -64,7 +64,7 @@ UNMAP_AFTER_INIT ACPISysFSComponent::ACPISysFSComponent(String name, PhysicalAdd
{
}
UNMAP_AFTER_INIT KResultOr<NonnullRefPtr<ACPISysFSDirectory>> ACPISysFSDirectory::try_create(FirmwareSysFSDirectory& firmware_directory)
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<ACPISysFSDirectory>> ACPISysFSDirectory::try_create(FirmwareSysFSDirectory& firmware_directory)
{
auto acpi_directory = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ACPISysFSDirectory(firmware_directory)));
return acpi_directory;

View file

@ -22,7 +22,7 @@ namespace Kernel::ACPI {
class ACPISysFSDirectory : public SysFSDirectory {
public:
static KResultOr<NonnullRefPtr<ACPISysFSDirectory>> try_create(FirmwareSysFSDirectory& firmware_directory);
static ErrorOr<NonnullRefPtr<ACPISysFSDirectory>> try_create(FirmwareSysFSDirectory& firmware_directory);
private:
explicit ACPISysFSDirectory(FirmwareSysFSDirectory& firmware_directory);
@ -32,10 +32,10 @@ class ACPISysFSComponent : public SysFSComponent {
public:
static NonnullRefPtr<ACPISysFSComponent> create(String name, PhysicalAddress, size_t table_size);
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override;
protected:
KResultOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const;
ErrorOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const;
ACPISysFSComponent(String name, PhysicalAddress, size_t table_size);
PhysicalAddress m_paddr;

Some files were not shown because too many files have changed in this diff Show more