2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2020-12-26 16:53:30 +02:00
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2022-03-01 18:09:46 -05:00
|
|
|
#include <LibPartition/PartitionTable.h>
|
2019-10-07 03:12:37 +03:00
|
|
|
|
2022-03-20 19:59:05 -04:00
|
|
|
#ifndef KERNEL
|
2023-02-08 21:08:01 +01:00
|
|
|
# include <LibCore/DeprecatedFile.h>
|
2022-03-20 19:59:05 -04:00
|
|
|
# include <sys/ioctl.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-03-01 18:09:46 -05:00
|
|
|
namespace Partition {
|
|
|
|
|
|
2022-03-20 19:59:05 -04:00
|
|
|
#ifdef KERNEL
|
2023-02-19 23:36:30 +01:00
|
|
|
PartitionTable::PartitionTable(Kernel::StorageDevice& device)
|
2020-12-26 16:53:30 +02:00
|
|
|
: m_device(device)
|
2022-03-20 19:59:05 -04:00
|
|
|
, m_block_size(device.block_size())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
#else
|
2023-02-08 21:08:01 +01:00
|
|
|
PartitionTable::PartitionTable(NonnullRefPtr<Core::DeprecatedFile> device_file)
|
2022-03-20 19:59:05 -04:00
|
|
|
: m_device_file(device_file)
|
2020-02-01 18:17:50 +02:00
|
|
|
{
|
2022-03-20 19:59:05 -04:00
|
|
|
VERIFY(ioctl(m_device_file->leak_fd(), STORAGE_DEVICE_GET_BLOCK_SIZE, &m_block_size) >= 0);
|
2020-12-26 16:53:30 +02:00
|
|
|
}
|
2022-03-20 19:59:05 -04:00
|
|
|
#endif
|
2019-10-07 03:12:37 +03:00
|
|
|
|
2022-03-20 19:59:05 -04:00
|
|
|
Optional<DiskPartitionMetadata> PartitionTable::partition(unsigned index) const
|
2020-02-01 18:17:50 +02:00
|
|
|
{
|
2020-12-26 16:53:30 +02:00
|
|
|
if (index > partitions_count())
|
|
|
|
|
return {};
|
|
|
|
|
return m_partitions[index];
|
|
|
|
|
}
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
|
}
|