PartitionTable.cpp 806 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibPartition/PartitionTable.h>
  7. #ifndef KERNEL
  8. # include <LibCore/DeprecatedFile.h>
  9. # include <sys/ioctl.h>
  10. #endif
  11. namespace Partition {
  12. #ifdef KERNEL
  13. PartitionTable::PartitionTable(Kernel::StorageDevice& device)
  14. : m_device(device)
  15. , m_block_size(device.block_size())
  16. {
  17. }
  18. #else
  19. PartitionTable::PartitionTable(NonnullRefPtr<Core::DeprecatedFile> device_file)
  20. : m_device_file(device_file)
  21. {
  22. VERIFY(ioctl(m_device_file->leak_fd(), STORAGE_DEVICE_GET_BLOCK_SIZE, &m_block_size) >= 0);
  23. }
  24. #endif
  25. Optional<DiskPartitionMetadata> PartitionTable::partition(unsigned index) const
  26. {
  27. if (index > partitions_count())
  28. return {};
  29. return m_partitions[index];
  30. }
  31. }