libstorage-ng
PartitionTable.h
1 /*
2  * Copyright (c) [2015-2021] SUSE LLC
3  *
4  * All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as published
8  * by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, contact Novell, Inc.
17  *
18  * To contact Novell about this file by physical or electronic mail, you may
19  * find current contact information at www.novell.com.
20  */
21 
22 
23 #ifndef STORAGE_PARTITION_TABLE_H
24 #define STORAGE_PARTITION_TABLE_H
25 
26 
27 #include <vector>
28 
29 #include "storage/Utils/Swig.h"
30 #include "storage/Utils/Region.h"
31 #include "storage/Utils/Alignment.h"
32 #include "storage/Devices/Device.h"
33 #include "storage/Devices/Partition.h"
34 
35 
36 namespace storage
37 {
38  class Partitionable;
39 
40 
42  enum class PtType {
43  UNKNOWN, LOOP, MSDOS, GPT, DASD, MAC, IMPLICIT, AIX, SUN, ATARI, BSD, AMIGA, DVH
44  };
45 
46 
52  std::string get_pt_type_name(PtType pt_type);
53 
54 
59  {
60  public:
61 
62  PartitionSlot();
63 
64  Region region;
65 
66  unsigned int number;
67  unsigned nr() const ST_DEPRECATED { return number; }
68 
69  std::string name;
70 
71  bool primary_slot;
72  bool primary_possible;
73  bool extended_slot;
74  bool extended_possible;
75  bool logical_slot;
76  bool logical_possible;
77 
78  bool is_possible(PartitionType partition_type) const;
79 
80  friend std::ostream& operator<<(std::ostream& s, const PartitionSlot& partition_slot);
81 
82  };
83 
84 
85  // abstract class
86 
87  class PartitionTable : public Device
88  {
89  public:
90 
96  PtType get_type() const;
97 
103  Partition* create_partition(const std::string& name, const Region& region, PartitionType type);
104 
109  void delete_partition(Partition* partition);
110 
111  void delete_partition(const std::string& name) ST_DEPRECATED;
112 
121  unsigned int max_primary() const;
122 
128  bool extended_possible() const;
129 
138  unsigned int max_logical() const;
139 
140  unsigned int num_primary() const;
141  bool has_extended() const;
142  unsigned int num_logical() const;
143 
148  std::vector<Partition*> get_partitions();
149 
153  std::vector<const Partition*> get_partitions() const;
154 
158  Partition* get_partition(const std::string& name);
159 
166  const Partition* get_extended() const;
167 
174 
178  const Partitionable* get_partitionable() const;
179 
180  Alignment get_alignment(AlignType align_type = AlignType::OPTIMAL) const;
181 
185  std::vector<PartitionSlot> get_unused_partition_slots(AlignPolicy align_policy = AlignPolicy::ALIGN_START_KEEP_END,
186  AlignType align_type = AlignType::OPTIMAL) const;
187 
193  Region align(const Region& region, AlignPolicy align_policy = AlignPolicy::ALIGN_START_AND_END,
194  AlignType align_type = AlignType::OPTIMAL) const;
195 
201 
207 
218  bool is_partition_id_supported(unsigned int id) const;
219 
220  public:
221 
222  class Impl;
223 
224  Impl& get_impl();
225  const Impl& get_impl() const;
226 
227  protected:
228 
229  PartitionTable(Impl* impl);
230 
231  };
232 
233 
239  bool is_partition_table(const Device* device);
240 
248 
252  const PartitionTable* to_partition_table(const Device* device);
253 
254 }
255 
256 #endif
Region align(const Region &region, AlignPolicy align_policy=AlignPolicy::ALIGN_START_AND_END, AlignType align_type=AlignType::OPTIMAL) const
region is sector-based.
bool extended_possible() const
Returns whether a extended partition is supported.
std::vector< PartitionSlot > get_unused_partition_slots(AlignPolicy align_policy=AlignPolicy::ALIGN_START_KEEP_END, AlignType align_type=AlignType::OPTIMAL) const
const Partition * get_extended() const
Returns the extended partition of the partition table.
PartitionType
Enum with partition types.
Definition: Partition.h:42
PartitionTable * to_partition_table(Device *device)
Converts pointer to Device to pointer to PartitionTable.
unsigned int max_primary() const
Highest number for a primary or extended partition.
A start/length pair with a block size.
Definition: Region.h:84
bool is_partition_legacy_boot_flag_supported() const
Returns whether the legacy boot flag is supported on partitions on the partition table.
AlignPolicy
Definition: Alignment.h:50
Partition * get_partition(const std::string &name)
std::vector< Partition * > get_partitions()
Get the partitions of the partition table.
PtType
Partition Table Type.
Definition: PartitionTable.h:42
Partitionable * get_partitionable()
Return the partitionable of the partition table.
A class to calculate partition alignment based on hardware topology.
Definition: Alignment.h:91
bool is_partition_table(const Device *device)
Checks whether device points to a PartitionTable.
An abstract base class for storage devices.
Definition: Device.h:81
Definition: Partitionable.h:39
unsigned int max_logical() const
Highest number for a logical partition.
bool is_partition_id_supported(unsigned int id) const
Returns whether the partition id is supported on the partition table.
Partition * create_partition(const std::string &name, const Region &region, PartitionType type)
region is sector-based.
std::string get_pt_type_name(PtType pt_type)
Convert the PtType pt_type to a string.
bool is_partition_boot_flag_supported() const
Returns whether the boot flag is supported on partitions on the partition table.
AlignType
Definition: Alignment.h:36
Align to topology information.
A partition of a Partitionable, e.g.
Definition: Partition.h:248
PtType get_type() const
Get the partition type.
The storage namespace.
Definition: Actiongraph.h:39
Definition: PartitionTable.h:87
Number and name are only valid if one of the possible flags is true.
Definition: PartitionTable.h:58
void delete_partition(Partition *partition)
Delete a partition in the partition table.