2022-03-01 18:09:46 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020-2022, Liav A. <liavalb@hotmail.co.il>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibPartition/DiskPartitionMetadata.h>
|
|
|
|
|
2022-03-20 19:59:05 -04:00
|
|
|
#ifdef KERNEL
|
|
|
|
# include <Kernel/Storage/StorageDevice.h>
|
|
|
|
#else
|
|
|
|
# include <LibCore/File.h>
|
|
|
|
#endif
|
|
|
|
|
2022-03-01 18:09:46 -05:00
|
|
|
namespace Partition {
|
|
|
|
|
|
|
|
class PartitionTable {
|
|
|
|
public:
|
2022-03-20 19:59:05 -04:00
|
|
|
Optional<DiskPartitionMetadata> partition(unsigned index) const;
|
2022-03-01 18:09:46 -05:00
|
|
|
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; }
|
2022-03-20 19:59:05 -04:00
|
|
|
size_t block_size() const { return m_block_size; }
|
2022-03-01 18:09:46 -05:00
|
|
|
|
|
|
|
protected:
|
2022-03-20 19:59:05 -04:00
|
|
|
#ifdef KERNEL
|
2022-03-01 18:09:46 -05:00
|
|
|
explicit PartitionTable(Kernel::StorageDevice const&);
|
|
|
|
NonnullRefPtr<Kernel::StorageDevice> m_device;
|
2022-03-20 19:59:05 -04:00
|
|
|
#else
|
|
|
|
explicit PartitionTable(NonnullRefPtr<Core::File>);
|
|
|
|
NonnullRefPtr<Core::File> m_device_file;
|
|
|
|
#endif
|
|
|
|
|
2022-03-01 18:09:46 -05:00
|
|
|
Vector<DiskPartitionMetadata> m_partitions;
|
2022-03-20 19:59:05 -04:00
|
|
|
size_t m_block_size;
|
2022-03-01 18:09:46 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|