libstorage-ng
Partition.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2018] SUSE LLC
4  *
5  * All Rights Reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of version 2 of the GNU General Public License as published
9  * by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, contact Novell, Inc.
18  *
19  * To contact Novell about this file by physical or electronic mail, you may
20  * find current contact information at www.novell.com.
21  */
22 
23 
24 #ifndef STORAGE_PARTITION_H
25 #define STORAGE_PARTITION_H
26 
27 
28 #include "storage/Devices/BlkDevice.h"
29 
30 
31 namespace storage
32 {
33 
34  class PartitionTable;
35  class Partitionable;
36 
37 
41  enum class PartitionType {
42 
49  PRIMARY,
50 
54  EXTENDED,
55 
59  LOGICAL
60 
61  };
62 
63 
67  std::string get_partition_type_name(PartitionType partition_type);
68 
69 
83  enum IdNum : unsigned int {
84 
86  ID_DOS12 = 0x01,
87 
89  ID_DOS16 = 0x06,
90 
92  ID_NTFS = 0x07,
93 
95  ID_DOS32 = 0x0c,
96 
98  ID_EXTENDED = 0x0f,
99 
101  ID_DIAG = 0x12,
102 
104  ID_PREP = 0x41,
105 
107  ID_SWAP = 0x82,
108 
110  ID_LINUX = 0x83,
111 
113  ID_IRST = 0x84,
114 
116  ID_LVM = 0x8e,
117 
119  ID_RAID = 0xfd,
120 
122  ID_ESP = 0xef,
123 
125  ID_UNKNOWN = 0x100,
126 
129  ID_BIOS_BOOT = 0x101,
130 
133 
136 
137  };
138 
139 
145  std::string get_partition_id_name(IdNum partition_id);
146 
147 
149  class Partition : public BlkDevice
150  {
151  public:
152 
156  static Partition* create(Devicegraph* devicegraph, const std::string& name,
157  const Region& region, PartitionType type);
158  static Partition* load(Devicegraph* devicegraph, const xmlNode* node);
159 
160  unsigned int get_number() const;
161 
162  PartitionType get_type() const;
163 
167  void set_type(PartitionType type);
168 
169  unsigned int get_id() const;
170 
174  void set_id(unsigned int id);
175 
179  bool is_boot() const;
180 
197  void set_boot(bool boot);
198 
202  bool is_legacy_boot() const;
203 
209  void set_legacy_boot(bool legacy_boot);
210 
211  const PartitionTable* get_partition_table() const;
212  const Partitionable* get_partitionable() const;
213 
221 
227  static Partition* find_by_name(Devicegraph* devicegraph, const std::string& name);
228 
232  static const Partition* find_by_name(const Devicegraph* devicegraph, const std::string& name);
233 
237  static bool compare_by_number(const Partition* lhs, const Partition* rhs);
238 
239  public:
240 
241  class Impl;
242 
243  Impl& get_impl();
244  const Impl& get_impl() const;
245 
246  virtual Partition* clone() const override;
247 
248  protected:
249 
250  Partition(Impl* impl);
251 
252  };
253 
254 
260  bool is_partition(const Device* device);
261 
268  Partition* to_partition(Device* device);
269 
273  const Partition* to_partition(const Device* device);
274 
275 }
276 
277 #endif
Only for MS-DOS.
Definition: Partition.h:92
Partition * to_partition(Device *device)
Converts pointer to Device to pointer to Partition.
BIOS boot partition (https://en.wikipedia.org/wiki/BIOS_boot_partition), only for GPT...
Definition: Partition.h:129
Only set during probing.
Definition: Partition.h:125
For MS-DOS, GPT, DASD and implicit.
Definition: Partition.h:110
void set_type(PartitionType type)
std::string get_partition_id_name(IdNum partition_id)
Convert IdNum to string.
For MS-DOS and GPT.
Definition: Partition.h:101
void set_legacy_boot(bool legacy_boot)
Set the legacy boot flag of the partition.
static bool compare_by_number(const Partition *lhs, const Partition *rhs)
Compare (less than) two Partitions by number.
Only for MS-DOS.
Definition: Partition.h:89
PartitionType
Enum with partition types.
Definition: Partition.h:41
Only for MS-DOS.
Definition: Partition.h:86
LVM partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:116
std::string get_partition_type_name(PartitionType partition_type)
Convert PartitionType to string.
A start/length pair with a block size.
Definition: Region.h:73
Region get_unused_surrounding_region() const
Returns the unused region surrounding the partition (including the partition itself).
PPC PReP Boot partition, for MS-DOS and GPT.
Definition: Partition.h:104
Windows basic data partition, only for GPT.
Definition: Partition.h:132
bool is_partition(const Device *device)
Checks whether device points to a Partition.
Intel Rapid Start Technology, for MS-DOS and GPT.
Definition: Partition.h:113
EFI System Partition, for MS-DOS and GPT.
Definition: Partition.h:122
The master container of the libstorage.
Definition: Devicegraph.h:153
Swap partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:107
Only for MS-DOS.
Definition: Partition.h:95
An abstract Block Device.
Definition: BlkDevice.h:46
void set_boot(bool boot)
Set the boot flag of the partition.
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:75
Microsoft reserved partition, only for GPT.
Definition: Partition.h:135
Only for MS-DOS.
Definition: Partition.h:98
Definition: Partitionable.h:39
bool is_legacy_boot() const
Query the legacy boot flag of the partition.
A partition of a Partitionable, e.g. Disk or Md.
Definition: Partition.h:149
RAID partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:119
The storage namespace.
Definition: Actiongraph.h:37
static Partition * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a Partition by its name.
Definition: PartitionTable.h:81
bool is_boot() const
Query the boot flag of the partition.
IdNum
Enum with values used as partition ids.
Definition: Partition.h:83
static Partition * create(Devicegraph *devicegraph, const std::string &name, const Region &region, PartitionType type)
region is sector-based.
void set_id(unsigned int id)