libstorage-ng
 All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
Partition.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) 2016 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 
54  enum IdNum : unsigned int {
55 
57  ID_DOS12 = 0x01,
58 
60  ID_DOS16 = 0x06,
61 
63  ID_DOS32 = 0x0c,
64 
66  ID_NTFS = 0x07,
67 
69  ID_EXTENDED = 0x0f,
70 
72  ID_PREP = 0x41,
73 
75  ID_LINUX = 0x83,
76 
79  ID_SWAP = 0x82,
80 
82  ID_LVM = 0x8e,
83 
85  ID_RAID = 0xfd,
86 
88  ID_ESP = 0xef,
89 
91  ID_UNKNOWN = 0x100,
92 
95  ID_BIOS_BOOT = 0x101,
96 
99 
102 
103  };
104 
105 
107  class Partition : public BlkDevice
108  {
109  public:
110 
114  static Partition* create(Devicegraph* devicegraph, const std::string& name,
115  const Region& region, PartitionType type);
116  static Partition* load(Devicegraph* devicegraph, const xmlNode* node);
117 
118  unsigned int get_number() const;
119 
120  PartitionType get_type() const;
121  void set_type(PartitionType type);
122 
123  unsigned int get_id() const;
124  void set_id(unsigned int id);
125 
129  bool is_boot() const;
130 
145  void set_boot(bool boot);
146 
150  bool is_legacy_boot() const;
151 
155  void set_legacy_boot(bool legacy_boot);
156 
157  const PartitionTable* get_partition_table() const;
158  const Partitionable* get_partitionable() const;
159 
160  static Partition* find_by_name(Devicegraph* devicegraph, const std::string& name);
161  static const Partition* find_by_name(const Devicegraph* devicegraph, const std::string& name);
162 
163  public:
164 
165  class Impl;
166 
167  Impl& get_impl();
168  const Impl& get_impl() const;
169 
170  virtual Partition* clone() const override;
171 
172  protected:
173 
174  Partition(Impl* impl);
175 
176  };
177 
178 
179  bool is_partition(const Device* device);
180 
181  Partition* to_partition(Device* device);
182  const Partition* to_partition(const Device* device);
183 
184 }
185 
186 #endif
bool is_legacy_boot() const
Query the legacy boot flag of the partition.
Only for MSDOS.
Definition: Partition.h:66
BIOS boot partition (https://en.wikipedia.org/wiki/BIOS_boot_partition), only for GPT...
Definition: Partition.h:95
Only set during probing.
Definition: Partition.h:91
For MSDOS and GPT.
Definition: Partition.h:75
bool is_boot() const
Query the boot flag of the partition.
void set_legacy_boot(bool legacy_boot)
Set the legacy boot flag of the partition.
Only for MSDOS.
Definition: Partition.h:60
PartitionType
Partition type (primary, extended, logical)
Definition: Partition.h:39
Only for MSDOS.
Definition: Partition.h:57
LVM partition, for MSDOS and GPT.
Definition: Partition.h:82
A start/length pair with a block size.
Definition: Region.h:71
PPC PReP Boot partition, for MSDOS and GPT.
Definition: Partition.h:72
Windows basic data partition, only for GPT.
Definition: Partition.h:98
EFI System Partition, for MSDOS and GPT.
Definition: Partition.h:88
The master container of the libstorage.
Definition: Devicegraph.h:133
Swap partition, for MSDOS and GPT, but GPT only when the partition is created.
Definition: Partition.h:79
Only for MSDOS.
Definition: Partition.h:63
An abstract Block Device.
Definition: BlkDevice.h:40
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:73
Microsoft reserved partition, only for GPT.
Definition: Partition.h:101
Only for MSDOS.
Definition: Partition.h:69
Definition: Partitionable.h:40
A partition of a Partitionable, e.g. Disk or Md.
Definition: Partition.h:107
RAID partition, for MSDOS and GPT.
Definition: Partition.h:85
The storage namespace.
Definition: Actiongraph.h:36
Definition: PartitionTable.h:71
IdNum
Enum with values used as partition ids.
Definition: Partition.h:54
static Partition * create(Devicegraph *devicegraph, const std::string &name, const Region &region, PartitionType type)
region is sector-based.