/* * Copyright (c) 2023, Ben Wiederhake * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #ifdef KERNEL # include #else # include # include #endif namespace Partition { class PartitionableDevice { AK_MAKE_NONCOPYABLE(PartitionableDevice); public: #ifdef KERNEL PartitionableDevice(Kernel::StorageDevice&); // Userland doesn't get an implicit constructor. #endif PartitionableDevice(PartitionableDevice&&) = default; // Unused, and "move out of reference" isn't well-defined anyway: PartitionableDevice& operator=(PartitionableDevice&&) = delete; #ifdef KERNEL static ErrorOr create(Kernel::StorageDevice& device); #else static ErrorOr create(MaybeOwned device_file); #endif ~PartitionableDevice() = default; PartitionableDevice clone_unowned(); ErrorOr clone_owned(); size_t block_size() const; ErrorOr read_block(size_t block_index, Bytes block_buffer); private: #ifdef KERNEL Kernel::StorageDevice& m_device; #else explicit PartitionableDevice(MaybeOwned, size_t block_size); MaybeOwned m_device_file; size_t m_block_size; #endif }; }