PartitionTable.cpp 762 B

123456789101112131415161718192021222324252627282930313233343536
  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 <sys/ioctl.h>
  9. #endif
  10. namespace Partition {
  11. #ifdef KERNEL
  12. PartitionTable::PartitionTable(Kernel::StorageDevice const& device)
  13. : m_device(device)
  14. , m_block_size(device.block_size())
  15. {
  16. }
  17. #else
  18. PartitionTable::PartitionTable(NonnullRefPtr<Core::File> device_file)
  19. : m_device_file(device_file)
  20. {
  21. VERIFY(ioctl(m_device_file->leak_fd(), STORAGE_DEVICE_GET_BLOCK_SIZE, &m_block_size) >= 0);
  22. }
  23. #endif
  24. Optional<DiskPartitionMetadata> PartitionTable::partition(unsigned index) const
  25. {
  26. if (index > partitions_count())
  27. return {};
  28. return m_partitions[index];
  29. }
  30. }