libstorage-ng
PartitionTable.h
1 /*
2  * Copyright (c) [2015-2016] SUSE LLC
3  *
4  * All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as published
8  * by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, contact Novell, Inc.
17  *
18  * To contact Novell about this file by physical or electronic mail, you may
19  * find current contact information at www.novell.com.
20  */
21 
22 
23 #ifndef STORAGE_PARTITION_TABLE_H
24 #define STORAGE_PARTITION_TABLE_H
25 
26 
27 #include <vector>
28 
29 #include "storage/Utils/Swig.h"
30 #include "storage/Utils/Region.h"
31 #include "storage/Utils/Topology.h"
32 #include "storage/Devices/Device.h"
33 #include "storage/Devices/Partition.h"
34 
35 
36 namespace storage
37 {
38  class Partitionable;
39 
40 
42  enum class PtType {
43  PT_UNKNOWN, PT_LOOP, MSDOS, GPT, DASD, MAC
44  };
45 
46  std::string get_pt_type_name(PtType pt_type);
47 
48 
50  {
51  public:
52 
53  PartitionSlot();
54 
55  Region region;
56  unsigned nr;
57  std::string name;
58  bool primary_slot;
59  bool primary_possible;
60  bool extended_slot;
61  bool extended_possible;
62  bool logical_slot;
63  bool logical_possible;
64 
65  bool is_possible(PartitionType partition_type) const;
66  };
67 
68 
69  // abstract class
70 
71  class PartitionTable : public Device
72  {
73  public:
74 
75  PtType get_type() const;
76 
80  Partition* create_partition(const std::string& name, const Region& region, PartitionType type);
81 
86  void delete_partition(Partition* partition);
87 
88  void delete_partition(const std::string& name) DEPRECATED;
89 
90  unsigned int max_primary() const;
91  bool extended_possible() const;
92  unsigned int max_logical() const;
93 
94  unsigned int num_primary() const;
95  bool has_extended() const;
96  unsigned int num_logical() const;
97 
101  std::vector<Partition*> get_partitions();
102 
106  std::vector<const Partition*> get_partitions() const;
107 
108  Partition* get_partition(const std::string& name);
109 
110  const Partitionable* get_partitionable() const;
111 
112  std::vector<PartitionSlot> get_unused_partition_slots(AlignPolicy align_policy = AlignPolicy::KEEP_END) const;
113 
117  Region align(const Region& region, AlignPolicy align_policy = AlignPolicy::ALIGN_END) const;
118 
119  public:
120 
121  class Impl;
122 
123  Impl& get_impl();
124  const Impl& get_impl() const;
125 
126  protected:
127 
128  PartitionTable(Impl* impl);
129 
130  };
131 
132 
133  bool is_partition_table(const Device* device);
134 
135  PartitionTable* to_partition_table(Device* device);
136  const PartitionTable* to_partition_table(const Device* device);
137 
138 }
139 
140 #endif
PartitionType
Partition type (primary, extended, logical)
Definition: Partition.h:39
A start/length pair with a block size.
Definition: Region.h:71
PtType
Partition Table Type.
Definition: PartitionTable.h:42
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:73
Definition: Partitionable.h:40
A partition of a Partitionable, e.g. Disk or Md.
Definition: Partition.h:107
The storage namespace.
Definition: Actiongraph.h:36
Definition: PartitionTable.h:71
Definition: PartitionTable.h:49