libstorage-ng
Partition.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2020] 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 
69  std::string get_partition_type_name(PartitionType partition_type);
70 
71 
85  enum IdNum : unsigned int {
86 
88  ID_DOS12 = 0x01,
89 
91  ID_DOS16 = 0x06,
92 
94  ID_NTFS = 0x07,
95 
97  ID_DOS32 = 0x0c,
98 
100  ID_EXTENDED = 0x0f,
101 
103  ID_DIAG = 0x12,
104 
106  ID_PREP = 0x41,
107 
109  ID_SWAP = 0x82,
110 
112  ID_LINUX = 0x83,
113 
115  ID_IRST = 0x84,
116 
118  ID_LVM = 0x8e,
119 
121  ID_RAID = 0xfd,
122 
124  ID_ESP = 0xef,
125 
127  ID_UNKNOWN = 0x100,
128 
131  ID_BIOS_BOOT = 0x101,
132 
135 
137  ID_MICROSOFT_RESERVED = 0x103
138 
139  };
140 
141 
149  std::string get_partition_id_name(IdNum partition_id);
150 
151 
155  class Partition : public BlkDevice
156  {
157  public:
158 
166  static Partition* create(Devicegraph* devicegraph, const std::string& name,
167  const Region& region, PartitionType type);
168 
169  static Partition* load(Devicegraph* devicegraph, const xmlNode* node);
170 
174  unsigned int get_number() const;
175 
182 
191 
192  unsigned int get_id() const;
193 
197  void set_id(unsigned int id);
198 
202  bool is_boot() const;
203 
220  void set_boot(bool boot);
221 
225  bool is_legacy_boot() const;
226 
232  void set_legacy_boot(bool legacy_boot);
233 
237  const std::string& get_label() const;
238 
242  const std::string& get_uuid() const;
243 
250 
257 
265 
271  static Partition* find_by_name(Devicegraph* devicegraph, const std::string& name);
272 
276  static const Partition* find_by_name(const Devicegraph* devicegraph, const std::string& name);
277 
283  static bool compare_by_number(const Partition* lhs, const Partition* rhs);
284 
285  public:
286 
287  class Impl;
288 
289  Impl& get_impl();
290  const Impl& get_impl() const;
291 
292  virtual Partition* clone() const override;
293 
294  protected:
295 
296  Partition(Impl* impl);
297 
298  };
299 
300 
306  bool is_partition(const Device* device);
307 
315 
319  const Partition* to_partition(const Device* device);
320 
321 }
322 
323 #endif
storage::Partition::compare_by_number
static bool compare_by_number(const Partition *lhs, const Partition *rhs)
Compare (less than) two Partitions by number.
storage::Partition
A partition of a Partitionable, e.g.
Definition: Partition.h:156
storage::get_partition_id_name
std::string get_partition_id_name(IdNum partition_id)
Convert the IdNum partition_id to a string.
storage::ID_WINDOWS_BASIC_DATA
@ ID_WINDOWS_BASIC_DATA
Windows basic data partition, only for GPT.
Definition: Partition.h:134
storage::Partitionable
Definition: Partitionable.h:40
storage::ID_ESP
@ ID_ESP
EFI System Partition, for MS-DOS and GPT.
Definition: Partition.h:124
storage::Region
A start/length pair with a block size.
Definition: Region.h:74
storage::Partition::get_label
const std::string & get_label() const
Get the partition label.
storage::ID_DOS32
@ ID_DOS32
Only for MS-DOS.
Definition: Partition.h:97
storage::ID_MICROSOFT_RESERVED
@ ID_MICROSOFT_RESERVED
Microsoft reserved partition, only for GPT.
Definition: Partition.h:137
storage::ID_RAID
@ ID_RAID
RAID partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:121
storage::Partition::set_type
void set_type(PartitionType type)
Set the partiton type.
storage::is_partition
bool is_partition(const Device *device)
Checks whether device points to a Partition.
storage::PartitionType::PRIMARY
@ PRIMARY
Primary partition.
storage::ID_NTFS
@ ID_NTFS
Only for MS-DOS.
Definition: Partition.h:94
storage
The storage namespace.
Definition: Actiongraph.h:39
storage::Partition::set_id
void set_id(unsigned int id)
storage::Partition::find_by_name
static const Partition * find_by_name(const Devicegraph *devicegraph, const std::string &name)
Find a Partition by its name.
storage::PartitionType
PartitionType
Enum with partition types.
Definition: Partition.h:41
storage::ID_UNKNOWN
@ ID_UNKNOWN
Only set during probing.
Definition: Partition.h:127
storage::PartitionTable
Definition: PartitionTable.h:88
storage::ID_EXTENDED
@ ID_EXTENDED
Only for MS-DOS.
Definition: Partition.h:100
storage::Partition::get_uuid
const std::string & get_uuid() const
Get the partition UUID.
storage::get_partition_type_name
std::string get_partition_type_name(PartitionType partition_type)
Convert the PartitionType partition_type to a string.
storage::Partition::set_boot
void set_boot(bool boot)
Set the boot flag of the partition.
storage::Partition::get_unused_surrounding_region
Region get_unused_surrounding_region() const
Returns the unused region surrounding the partition (including the partition itself).
storage::Partition::get_type
PartitionType get_type() const
Get the partition type.
storage::BlkDevice
An abstract Block Device.
Definition: BlkDevice.h:47
storage::ID_LVM
@ ID_LVM
LVM partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:118
storage::Devicegraph
The main container of the libstorage-ng.
Definition: Devicegraph.h:170
storage::ID_DOS16
@ ID_DOS16
Only for MS-DOS.
Definition: Partition.h:91
storage::ID_BIOS_BOOT
@ ID_BIOS_BOOT
BIOS boot partition (https://en.wikipedia.org/wiki/BIOS_boot_partition), only for GPT.
Definition: Partition.h:131
storage::ID_DIAG
@ ID_DIAG
For MS-DOS and GPT.
Definition: Partition.h:103
storage::Partition::get_partitionable
const Partitionable * get_partitionable() const
Return the partitionable the partition belongs to.
storage::Device
An abstract base class for storage devices.
Definition: Device.h:82
storage::ID_LINUX
@ ID_LINUX
For MS-DOS, GPT, DASD and implicit.
Definition: Partition.h:112
storage::Partition::get_partition_table
const PartitionTable * get_partition_table() const
Return the partition table the partition belongs to.
storage::ID_DOS12
@ ID_DOS12
Only for MS-DOS.
Definition: Partition.h:88
storage::Partition::set_legacy_boot
void set_legacy_boot(bool legacy_boot)
Set the legacy boot flag of the partition.
storage::Partition::create
static Partition * create(Devicegraph *devicegraph, const std::string &name, const Region &region, PartitionType type)
Create a device of type Partition.
storage::ID_IRST
@ ID_IRST
Intel Rapid Start Technology, for MS-DOS and GPT.
Definition: Partition.h:115
storage::Partition::get_number
unsigned int get_number() const
Get the partition number.
storage::Partition::find_by_name
static Partition * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a Partition by its name.
storage::to_partition
Partition * to_partition(Device *device)
Converts pointer to Device to pointer to Partition.
storage::Partition::is_boot
bool is_boot() const
Query the boot flag of the partition.
storage::Partition::is_legacy_boot
bool is_legacy_boot() const
Query the legacy boot flag of the partition.
storage::ID_PREP
@ ID_PREP
PPC PReP Boot partition, for MS-DOS and GPT.
Definition: Partition.h:106
storage::ID_SWAP
@ ID_SWAP
Swap partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:109
storage::IdNum
IdNum
Enum with values used as partition ids.
Definition: Partition.h:85