mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 03:28:25 +03:00
6a1c85aa61
Previously, PartitionTable was constructed using a Kernel::StorageDevice making it only usable in the kernel. This commit adds a new constructor that takes a Core::File instead, making it usable in userland as well. This also adds the m_block_size field which stores the block size of the underlying device obtained by calling StorageDevice::block_size() in the kernel or by using the STORAGE_DEVICE_GET_BLOCK_SIZE ioctl in userland. This avoids the need for an #ifdef every time block size is needed.
43 lines
1014 B
C++
43 lines
1014 B
C++
/*
|
|
* Copyright (c) 2020-2022, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibPartition/DiskPartitionMetadata.h>
|
|
|
|
#ifdef KERNEL
|
|
# include <Kernel/Storage/StorageDevice.h>
|
|
#else
|
|
# include <LibCore/File.h>
|
|
#endif
|
|
|
|
namespace Partition {
|
|
|
|
class PartitionTable {
|
|
public:
|
|
Optional<DiskPartitionMetadata> partition(unsigned index) const;
|
|
size_t partitions_count() const { return m_partitions.size(); }
|
|
virtual ~PartitionTable() = default;
|
|
virtual bool is_valid() const = 0;
|
|
|
|
Vector<DiskPartitionMetadata> partitions() const { return m_partitions; }
|
|
size_t block_size() const { return m_block_size; }
|
|
|
|
protected:
|
|
#ifdef KERNEL
|
|
explicit PartitionTable(Kernel::StorageDevice const&);
|
|
NonnullRefPtr<Kernel::StorageDevice> m_device;
|
|
#else
|
|
explicit PartitionTable(NonnullRefPtr<Core::File>);
|
|
NonnullRefPtr<Core::File> m_device_file;
|
|
#endif
|
|
|
|
Vector<DiskPartitionMetadata> m_partitions;
|
|
size_t m_block_size;
|
|
};
|
|
|
|
}
|