PartitionableDevice.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2023, Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Noncopyable.h>
  8. #ifdef KERNEL
  9. # include <Kernel/Devices/Storage/StorageDevice.h>
  10. #else
  11. # include <AK/MaybeOwned.h>
  12. # include <LibCore/File.h>
  13. #endif
  14. namespace Partition {
  15. class PartitionableDevice {
  16. AK_MAKE_NONCOPYABLE(PartitionableDevice);
  17. public:
  18. #ifdef KERNEL
  19. PartitionableDevice(Kernel::StorageDevice&);
  20. // Userland doesn't get an implicit constructor.
  21. #endif
  22. PartitionableDevice(PartitionableDevice&&) = default;
  23. // Unused, and "move out of reference" isn't well-defined anyway:
  24. PartitionableDevice& operator=(PartitionableDevice&&) = delete;
  25. #ifdef KERNEL
  26. static ErrorOr<PartitionableDevice> create(Kernel::StorageDevice& device);
  27. #else
  28. static ErrorOr<PartitionableDevice> create(MaybeOwned<Core::File> device_file);
  29. #endif
  30. ~PartitionableDevice() = default;
  31. PartitionableDevice clone_unowned();
  32. ErrorOr<PartitionableDevice> clone_owned();
  33. size_t block_size() const;
  34. ErrorOr<void> read_block(size_t block_index, Bytes block_buffer);
  35. private:
  36. #ifdef KERNEL
  37. Kernel::StorageDevice& m_device;
  38. #else
  39. explicit PartitionableDevice(MaybeOwned<Core::File>, size_t block_size);
  40. MaybeOwned<Core::File> m_device_file;
  41. size_t m_block_size;
  42. #endif
  43. };
  44. }