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 
141  class Partition : public BlkDevice
142  {
143  public:
144 
148  static Partition* create(Devicegraph* devicegraph, const std::string& name,
149  const Region& region, PartitionType type);
150  static Partition* load(Devicegraph* devicegraph, const xmlNode* node);
151 
152  unsigned int get_number() const;
153 
154  PartitionType get_type() const;
155 
159  void set_type(PartitionType type);
160 
161  unsigned int get_id() const;
162 
166  void set_id(unsigned int id);
167 
171  bool is_boot() const;
172 
189  void set_boot(bool boot);
190 
194  bool is_legacy_boot() const;
195 
201  void set_legacy_boot(bool legacy_boot);
202 
203  const PartitionTable* get_partition_table() const;
204  const Partitionable* get_partitionable() const;
205 
213 
219  static Partition* find_by_name(Devicegraph* devicegraph, const std::string& name);
220 
224  static const Partition* find_by_name(const Devicegraph* devicegraph, const std::string& name);
225 
229  static bool compare_by_number(const Partition* lhs, const Partition* rhs);
230 
231  public:
232 
233  class Impl;
234 
235  Impl& get_impl();
236  const Impl& get_impl() const;
237 
238  virtual Partition* clone() const override;
239 
240  protected:
241 
242  Partition(Impl* impl);
243 
244  };
245 
246 
247  bool is_partition(const Device* device);
248 
255  Partition* to_partition(Device* device);
256 
260  const Partition* to_partition(const Device* device);
261 
262 }
263 
264 #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)
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
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:44
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:141
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)