libstorage-ng
Partition.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2017] 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 
39  enum class PartitionType {
40  PRIMARY, EXTENDED, LOGICAL
41  };
42 
43  std::string get_partition_type_name(PartitionType partition_type);
44 
45 
59  enum IdNum : unsigned int {
60 
62  ID_DOS12 = 0x01,
63 
65  ID_DOS16 = 0x06,
66 
68  ID_DOS32 = 0x0c,
69 
71  ID_NTFS = 0x07,
72 
74  ID_EXTENDED = 0x0f,
75 
77  ID_DIAG = 0x12,
78 
80  ID_PREP = 0x41,
81 
83  ID_LINUX = 0x83,
84 
86  ID_SWAP = 0x82,
87 
89  ID_LVM = 0x8e,
90 
92  ID_RAID = 0xfd,
93 
95  ID_ESP = 0xef,
96 
98  ID_UNKNOWN = 0x100,
99 
102  ID_BIOS_BOOT = 0x101,
103 
106 
109 
110  };
111 
112 
114  class Partition : public BlkDevice
115  {
116  public:
117 
121  static Partition* create(Devicegraph* devicegraph, const std::string& name,
122  const Region& region, PartitionType type);
123  static Partition* load(Devicegraph* devicegraph, const xmlNode* node);
124 
125  unsigned int get_number() const;
126 
127  PartitionType get_type() const;
128 
132  void set_type(PartitionType type);
133 
134  unsigned int get_id() const;
135 
139  void set_id(unsigned int id);
140 
144  bool is_boot() const;
145 
162  void set_boot(bool boot);
163 
167  bool is_legacy_boot() const;
168 
174  void set_legacy_boot(bool legacy_boot);
175 
176  const PartitionTable* get_partition_table() const;
177  const Partitionable* get_partitionable() const;
178 
186 
192  static Partition* find_by_name(Devicegraph* devicegraph, const std::string& name);
193 
197  static const Partition* find_by_name(const Devicegraph* devicegraph, const std::string& name);
198 
202  static bool compare_by_number(const Partition* lhs, const Partition* rhs);
203 
204  public:
205 
206  class Impl;
207 
208  Impl& get_impl();
209  const Impl& get_impl() const;
210 
211  virtual Partition* clone() const override;
212 
213  protected:
214 
215  Partition(Impl* impl);
216 
217  };
218 
219 
220  bool is_partition(const Device* device);
221 
228  Partition* to_partition(Device* device);
229 
233  const Partition* to_partition(const Device* device);
234 
235 }
236 
237 #endif
Only for MS-DOS.
Definition: Partition.h:71
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:102
Only set during probing.
Definition: Partition.h:98
For MS-DOS, GPT, DASD and implicit.
Definition: Partition.h:83
void set_type(PartitionType type)
For MS-DOS and GPT.
Definition: Partition.h:77
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:65
PartitionType
Partition type (primary, extended, logical)
Definition: Partition.h:39
Only for MS-DOS.
Definition: Partition.h:62
LVM partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:89
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:80
Windows basic data partition, only for GPT.
Definition: Partition.h:105
EFI System Partition, for MS-DOS and GPT.
Definition: Partition.h:95
The master container of the libstorage.
Definition: Devicegraph.h:153
Swap partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:86
Only for MS-DOS.
Definition: Partition.h:68
An abstract Block Device.
Definition: BlkDevice.h:41
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:108
Only for MS-DOS.
Definition: Partition.h:74
Definition: Partitionable.h:40
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:114
RAID partition, for MS-DOS, GPT and DASD.
Definition: Partition.h:92
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:59
static Partition * create(Devicegraph *devicegraph, const std::string &name, const Region &region, PartitionType type)
region is sector-based.
void set_id(unsigned int id)