libstorage-ng
Loading...
Searching...
No Matches
Partition.h
1/*
2 * Copyright (c) [2014-2015] Novell, Inc.
3 * Copyright (c) [2016-2022] 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
31namespace storage
32{
33
34 class PartitionTable;
35 class Partitionable;
36 class SystemInfo;
37
38
42 enum class PartitionType {
43
50 PRIMARY,
51
56
61
62 };
63
64
70 std::string get_partition_type_name(PartitionType partition_type);
71
72
86 enum IdNum : unsigned int {
87
89 ID_DOS12 = 0x01,
90
92 ID_DOS16 = 0x06,
93
95 ID_NTFS = 0x07,
96
98 ID_DOS32 = 0x0c,
99
102
104 ID_DIAG = 0x12,
105
107 ID_PREP = 0x41,
108
110 ID_SWAP = 0x82,
111
113 ID_LINUX = 0x83,
114
116 ID_IRST = 0x84,
117
119 ID_LVM = 0x8e,
120
122 ID_RAID = 0xfd,
123
125 ID_ESP = 0xef,
126
128 ID_UNKNOWN = 0x100,
129
133
136
139
142
145
148
151
154
157
160
163
166
169
172
175
178
181
184
187
190
193
196
199
202
205
208
211
212 };
213
214
222 std::string get_partition_id_name(IdNum partition_id);
223
224
229 {
230 ROOT, USR
231 };
232
233
242 IdNum get_linux_partition_id(LinuxPartitionIdCategory linux_partition_id_category, SystemInfo& system_info);
243
244
248 class Partition : public BlkDevice
249 {
250 public:
251
259 static Partition* create(Devicegraph* devicegraph, const std::string& name,
260 const Region& region, PartitionType type);
261
262 static Partition* load(Devicegraph* devicegraph, const xmlNode* node);
263
267 unsigned int get_number() const;
268
275
284
290 unsigned int get_id() const;
291
299 void set_id(unsigned int id);
300
304 bool is_boot() const;
305
324 void set_boot(bool boot);
325
329 bool is_legacy_boot() const;
330
338 void set_legacy_boot(bool legacy_boot);
339
346 const std::string& get_label() const;
347
353 void set_label(const std::string& label);
354
358 const std::string& get_uuid() const;
359
366
371
378
383
391
397 static Partition* find_by_name(Devicegraph* devicegraph, const std::string& name);
398
402 static const Partition* find_by_name(const Devicegraph* devicegraph, const std::string& name);
403
409 static bool compare_by_number(const Partition* lhs, const Partition* rhs);
410
411 public:
412
413 class Impl;
414
415 Impl& get_impl();
416 const Impl& get_impl() const;
417
418 virtual Partition* clone() const override;
419
420 protected:
421
422 Partition(Impl* impl);
423
424 };
425
426
432 bool is_partition(const Device* device);
433
441
445 const Partition* to_partition(const Device* device);
446
447}
448
449#endif
An abstract Block Device.
Definition: BlkDevice.h:49
An abstract base class for storage devices.
Definition: Device.h:82
The main container of the libstorage-ng.
Definition: Devicegraph.h:170
Definition: PartitionTable.h:88
A partition of a Partitionable, e.g.
Definition: Partition.h:249
const std::string & get_uuid() const
Get the partition UUID.
static Partition * create(Devicegraph *devicegraph, const std::string &name, const Region &region, PartitionType type)
Create a device of type Partition.
void set_legacy_boot(bool legacy_boot)
Set the legacy boot flag of the partition.
void set_id(unsigned int id)
Set the partition id.
unsigned int get_number() const
Get the partition number.
void set_boot(bool boot)
Set the boot flag of the partition.
PartitionType get_type() const
Get the partition type.
void set_type(PartitionType type)
Set the partiton type.
bool is_legacy_boot() const
Query the legacy boot flag of the partition.
const std::string & get_label() const
Get the partition label.
static Partition * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a Partition by its name.
unsigned int get_id() const
Get the partition id.
const PartitionTable * get_partition_table() const
Return the partition table the partition belongs to.
PartitionTable * get_partition_table()
Return the partition table the partition belongs to.
static const Partition * find_by_name(const Devicegraph *devicegraph, const std::string &name)
Find a Partition by its name.
const Partitionable * get_partitionable() const
Return the partitionable the partition belongs to.
Region get_unused_surrounding_region() const
Returns the unused region surrounding the partition (including the partition itself).
Partitionable * get_partitionable()
Return the partitionable the partition belongs to.
bool is_boot() const
Query the boot flag of the partition.
void set_label(const std::string &label)
Set the partition label.
static bool compare_by_number(const Partition *lhs, const Partition *rhs)
Compare (less than) two Partitions by number.
Definition: Partitionable.h:40
A start/length pair with a block size.
Definition: Region.h:85
The SystemInfo class keeps various system information.
Definition: SystemInfo.h:42
The storage namespace.
Definition: Actiongraph.h:39
PartitionType
Enum with partition types.
Definition: Partition.h:42
@ EXTENDED
Extended partition.
@ LOGICAL
Logical partition.
@ PRIMARY
Primary partition.
LinuxPartitionIdCategory
Enum with categories for Linux partitions.
Definition: Partition.h:229
IdNum
Enum with values used as partition ids.
Definition: Partition.h:86
@ ID_LINUX_ROOT_PPC64LE
Linux Root Partition (ppc64le), only for GPT.
Definition: Partition.h:159
@ ID_SWAP
Swap partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:110
@ ID_LINUX_USR_ARM
Linux USR Partition (arm), only for GPT.
Definition: Partition.h:180
@ ID_LINUX
For MS-DOS, GPT, DASD and implicit.
Definition: Partition.h:113
@ ID_UNKNOWN
Only set during probing.
Definition: Partition.h:128
@ ID_LINUX_USR_PPC32
Linux USR Partition (ppc), only for GPT.
Definition: Partition.h:186
@ ID_BIOS_BOOT
BIOS boot partition (https://en.wikipedia.org/wiki/BIOS_boot_partition), only for GPT.
Definition: Partition.h:132
@ ID_LINUX_USR_S390X
Linux USR Partition (s390x), only for GPT.
Definition: Partition.h:204
@ ID_PREP
PPC PReP Boot partition, for MS-DOS and GPT.
Definition: Partition.h:107
@ ID_LINUX_USR_PPC64LE
Linux USR Partition (ppc64le), only for GPT.
Definition: Partition.h:192
@ ID_LINUX_ROOT_X86_64
Linux Root Partition (x86_64), only for GPT.
Definition: Partition.h:177
@ ID_LINUX_ROOT_AARCH64
Linux Root Partition (aarch64), only for GPT.
Definition: Partition.h:150
@ ID_LINUX_ROOT_S390X
Linux Root Partition (s390x), only for GPT.
Definition: Partition.h:171
@ ID_LINUX_ROOT_PPC32
Linux Root Partition (ppc), only for GPT.
Definition: Partition.h:153
@ ID_LINUX_HOME
Linux Home, only for GPT.
Definition: Partition.h:141
@ ID_RAID
RAID partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:122
@ ID_LINUX_SERVER_DATA
Linux Server Data, only for GPT.
Definition: Partition.h:144
@ ID_LINUX_ROOT_PPC64BE
Linux Root Partition (ppc64be), only for GPT.
Definition: Partition.h:156
@ ID_LINUX_ROOT_ARM
Linux Root Partition (arm), only for GPT.
Definition: Partition.h:147
@ ID_LINUX_USR_X86
Linux USR Partition (x86), only for GPT.
Definition: Partition.h:207
@ ID_WINDOWS_BASIC_DATA
Windows basic data partition, only for GPT.
Definition: Partition.h:135
@ ID_DOS32
Only for MS-DOS.
Definition: Partition.h:98
@ ID_ESP
EFI System Partition, for MS-DOS and GPT.
Definition: Partition.h:125
@ ID_DIAG
For MS-DOS and GPT.
Definition: Partition.h:104
@ ID_DOS16
Only for MS-DOS.
Definition: Partition.h:92
@ ID_LINUX_USR_X86_64
Linux USR Partition (x86_64), only for GPT.
Definition: Partition.h:210
@ ID_EXTENDED
Only for MS-DOS.
Definition: Partition.h:101
@ ID_LINUX_USR_S390
Linux USR Partition (s390), only for GPT.
Definition: Partition.h:201
@ ID_NTFS
Only for MS-DOS.
Definition: Partition.h:95
@ ID_MICROSOFT_RESERVED
Microsoft reserved partition, only for GPT.
Definition: Partition.h:138
@ ID_LINUX_USR_AARCH64
Linux USR Partition (aarch64), only for GPT.
Definition: Partition.h:183
@ ID_LINUX_ROOT_S390
Linux Root Partition (s390), only for GPT.
Definition: Partition.h:168
@ ID_LINUX_USR_RISCV32
Linux USR Partition (riscv32), only for GPT.
Definition: Partition.h:195
@ ID_LINUX_ROOT_X86
Linux Root Partition (x86), only for GPT.
Definition: Partition.h:174
@ ID_LINUX_USR_PPC64BE
Linux USR Partition (ppc64be), only for GPT.
Definition: Partition.h:189
@ ID_LINUX_ROOT_RISCV32
Linux Root Partition (riscv32, only for GPT.
Definition: Partition.h:162
@ ID_LINUX_ROOT_RISCV64
Linux Root Partition (riscv64), only for GPT.
Definition: Partition.h:165
@ ID_LVM
LVM partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:119
@ ID_DOS12
Only for MS-DOS.
Definition: Partition.h:89
@ ID_LINUX_USR_RISCV64
Linux USR Partition (riscv64), only for GPT.
Definition: Partition.h:198
@ ID_IRST
Intel Rapid Start Technology, for MS-DOS and GPT.
Definition: Partition.h:116
bool is_partition(const Device *device)
Checks whether device points to a Partition.
std::string get_partition_id_name(IdNum partition_id)
Convert the IdNum partition_id to a string.
std::string get_partition_type_name(PartitionType partition_type)
Convert the PartitionType partition_type to a string.
Partition * to_partition(Device *device)
Converts pointer to Device to pointer to Partition.
IdNum get_linux_partition_id(LinuxPartitionIdCategory linux_partition_id_category, SystemInfo &system_info)
Get the partition id for the Linux partition of the given category (root, usr, ......