mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-25 19:02:07 -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 {
|
namespace Partition {
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
ErrorOr<NonnullOwnPtr<EBRPartitionTable>> EBRPartitionTable::try_to_initialize(Kernel::StorageDevice const& device)
|
ErrorOr<NonnullOwnPtr<EBRPartitionTable>> EBRPartitionTable::try_to_initialize(Kernel::StorageDevice const& device)
|
||||||
{
|
{
|
||||||
auto table = TRY(adopt_nonnull_own_or_enomem(new (nothrow) EBRPartitionTable(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())
|
if (table->is_protective_mbr())
|
||||||
return Error::from_errno(ENOTSUP);
|
return Error::from_errno(ENOTSUP);
|
||||||
if (!table->is_valid())
|
if (!table->is_valid())
|
||||||
|
@ -18,7 +24,11 @@ ErrorOr<NonnullOwnPtr<EBRPartitionTable>> EBRPartitionTable::try_to_initialize(K
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
void EBRPartitionTable::search_extended_partition(Kernel::StorageDevice const& device, MBRPartitionTable& checked_ebr, u64 current_block_offset, size_t limit)
|
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)
|
if (limit == 0)
|
||||||
return;
|
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));
|
search_extended_partition(device, *next_ebr, current_block_offset, (limit - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
EBRPartitionTable::EBRPartitionTable(Kernel::StorageDevice const& device)
|
EBRPartitionTable::EBRPartitionTable(Kernel::StorageDevice const& device)
|
||||||
|
#else
|
||||||
|
EBRPartitionTable::EBRPartitionTable(NonnullRefPtr<Core::File> device)
|
||||||
|
#endif
|
||||||
: MBRPartitionTable(device)
|
: MBRPartitionTable(device)
|
||||||
{
|
{
|
||||||
if (!is_header_valid())
|
if (!is_header_valid())
|
||||||
|
|
|
@ -15,12 +15,25 @@ class EBRPartitionTable : public MBRPartitionTable {
|
||||||
public:
|
public:
|
||||||
~EBRPartitionTable();
|
~EBRPartitionTable();
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
static ErrorOr<NonnullOwnPtr<EBRPartitionTable>> try_to_initialize(Kernel::StorageDevice const&);
|
static ErrorOr<NonnullOwnPtr<EBRPartitionTable>> try_to_initialize(Kernel::StorageDevice const&);
|
||||||
explicit EBRPartitionTable(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:
|
private:
|
||||||
|
#ifdef KERNEL
|
||||||
void search_extended_partition(Kernel::StorageDevice const&, MBRPartitionTable&, u64, size_t limit);
|
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 };
|
bool m_valid { false };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue