summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibPartition
diff options
context:
space:
mode:
authorSamuel Bowman <sam@sambowman.tech>2022-03-01 18:09:46 -0500
committerLinus Groh <mail@linusgroh.de>2022-07-21 20:13:44 +0100
commit940dde99473ec756cc78dc3ef9cea6fb1d651b6c (patch)
treede07d5a92f2c6299329103378f939b0eefad5f26 /Userland/Libraries/LibPartition
parentbe1c5c6b9f2d69074e076efdee4816dd22a2ad70 (diff)
downloadserenity-940dde99473ec756cc78dc3ef9cea6fb1d651b6c.zip
Kernel+LibPartition: Move PartitionTable into LibPartition
Diffstat (limited to 'Userland/Libraries/LibPartition')
-rw-r--r--Userland/Libraries/LibPartition/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibPartition/PartitionTable.cpp23
-rw-r--r--Userland/Libraries/LibPartition/PartitionTable.h30
3 files changed, 54 insertions, 0 deletions
diff --git a/Userland/Libraries/LibPartition/CMakeLists.txt b/Userland/Libraries/LibPartition/CMakeLists.txt
index 83751ec44b..9d3a0ef59e 100644
--- a/Userland/Libraries/LibPartition/CMakeLists.txt
+++ b/Userland/Libraries/LibPartition/CMakeLists.txt
@@ -1,5 +1,6 @@
set(SOURCES
DiskPartitionMetadata.cpp
+ PartitionTable.cpp
)
serenity_lib(LibPartition partition)
diff --git a/Userland/Libraries/LibPartition/PartitionTable.cpp b/Userland/Libraries/LibPartition/PartitionTable.cpp
new file mode 100644
index 0000000000..dc5685667d
--- /dev/null
+++ b/Userland/Libraries/LibPartition/PartitionTable.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibPartition/PartitionTable.h>
+
+namespace Partition {
+
+PartitionTable::PartitionTable(Kernel::StorageDevice const& device)
+ : m_device(device)
+{
+}
+
+Optional<DiskPartitionMetadata> PartitionTable::partition(unsigned index)
+{
+ if (index > partitions_count())
+ return {};
+ return m_partitions[index];
+}
+
+}
diff --git a/Userland/Libraries/LibPartition/PartitionTable.h b/Userland/Libraries/LibPartition/PartitionTable.h
new file mode 100644
index 0000000000..2ca4db59a0
--- /dev/null
+++ b/Userland/Libraries/LibPartition/PartitionTable.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2020-2022, Liav A. <liavalb@hotmail.co.il>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <Kernel/Storage/StorageDevice.h>
+#include <LibPartition/DiskPartitionMetadata.h>
+
+namespace Partition {
+
+class PartitionTable {
+public:
+ Optional<DiskPartitionMetadata> partition(unsigned index);
+ size_t partitions_count() const { return m_partitions.size(); }
+ virtual ~PartitionTable() = default;
+ virtual bool is_valid() const = 0;
+
+ Vector<DiskPartitionMetadata> partitions() const { return m_partitions; }
+
+protected:
+ explicit PartitionTable(Kernel::StorageDevice const&);
+
+ NonnullRefPtr<Kernel::StorageDevice> m_device;
+ Vector<DiskPartitionMetadata> m_partitions;
+};
+
+}