mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05:00
LibPartition: Make EBRPartitionTable kernel/userland agnostic
This commit is contained in:
parent
7e45c3b687
commit
11b4d51fc9
2 changed files with 28 additions and 1 deletions
|
@ -8,9 +8,15 @@
|
|||
|
||||
namespace Partition {
|
||||
|
||||
#ifdef KERNEL
|
||||
ErrorOr<NonnullOwnPtr<EBRPartitionTable>> EBRPartitionTable::try_to_initialize(Kernel::StorageDevice const& device)
|
||||
{
|
||||
auto table = TRY(adopt_nonnull_own_or_enomem(new (nothrow) EBRPartitionTable(device)));
|
||||
#else
|
||||
ErrorOr<NonnullOwnPtr<EBRPartitionTable>> EBRPartitionTable::try_to_initialize(NonnullRefPtr<Core::File> device_file)
|
||||
{
|
||||
auto table = TRY(adopt_nonnull_own_or_enomem(new (nothrow) EBRPartitionTable(move(device_file))));
|
||||
#endif
|
||||
if (table->is_protective_mbr())
|
||||
return Error::from_errno(ENOTSUP);
|
||||
if (!table->is_valid())
|
||||
|
@ -18,7 +24,11 @@ ErrorOr<NonnullOwnPtr<EBRPartitionTable>> EBRPartitionTable::try_to_initialize(K
|
|||
return table;
|
||||
}
|
||||
|
||||
#ifdef KERNEL
|
||||
void EBRPartitionTable::search_extended_partition(Kernel::StorageDevice const& device, MBRPartitionTable& checked_ebr, u64 current_block_offset, size_t limit)
|
||||
#else
|
||||
void EBRPartitionTable::search_extended_partition(NonnullRefPtr<Core::File> device, MBRPartitionTable& checked_ebr, u64 current_block_offset, size_t limit)
|
||||
#endif
|
||||
{
|
||||
if (limit == 0)
|
||||
return;
|
||||
|
@ -38,7 +48,11 @@ void EBRPartitionTable::search_extended_partition(Kernel::StorageDevice const& d
|
|||
search_extended_partition(device, *next_ebr, current_block_offset, (limit - 1));
|
||||
}
|
||||
|
||||
#ifdef KERNEL
|
||||
EBRPartitionTable::EBRPartitionTable(Kernel::StorageDevice const& device)
|
||||
#else
|
||||
EBRPartitionTable::EBRPartitionTable(NonnullRefPtr<Core::File> device)
|
||||
#endif
|
||||
: MBRPartitionTable(device)
|
||||
{
|
||||
if (!is_header_valid())
|
||||
|
|
|
@ -15,12 +15,25 @@ class EBRPartitionTable : public MBRPartitionTable {
|
|||
public:
|
||||
~EBRPartitionTable();
|
||||
|
||||
#ifdef KERNEL
|
||||
static ErrorOr<NonnullOwnPtr<EBRPartitionTable>> try_to_initialize(Kernel::StorageDevice const&);
|
||||
explicit EBRPartitionTable(Kernel::StorageDevice const&);
|
||||
virtual bool is_valid() const override { return m_valid; };
|
||||
#else
|
||||
static ErrorOr<NonnullOwnPtr<EBRPartitionTable>> try_to_initialize(NonnullRefPtr<Core::File>);
|
||||
explicit EBRPartitionTable(NonnullRefPtr<Core::File>);
|
||||
#endif
|
||||
|
||||
virtual bool is_valid() const override
|
||||
{
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
private:
|
||||
#ifdef KERNEL
|
||||
void search_extended_partition(Kernel::StorageDevice const&, MBRPartitionTable&, u64, size_t limit);
|
||||
#else
|
||||
void search_extended_partition(NonnullRefPtr<Core::File>, MBRPartitionTable&, u64, size_t limit);
|
||||
#endif
|
||||
|
||||
bool m_valid { false };
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue