libstorage-ng
 All Classes Namespaces Functions Typedefs Enumerations 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 
44  enum IdNum : unsigned int {
45  ID_DOS12 = 0x01, ID_DOS16 = 0x06, ID_DOS32 = 0x0c, ID_NTFS = 0x07,
46  ID_EXTENDED = 0x0f, ID_PPC_PREP = 0x41, ID_LINUX = 0x83, ID_SWAP = 0x82,
47  ID_LVM = 0x8e, ID_EFI = 0xef, ID_RAID = 0xfd, ID_APPLE_OTHER = 0x101,
48  ID_APPLE_HFS = 0x102, ID_GPT_BOOT = 0x103, ID_GPT_SERVICE = 0x104,
49  ID_GPT_MSFTRES = 0x105, ID_APPLE_UFS = 0x106, ID_GPT_BIOS = 0x107,
50  ID_GPT_PREP = 0x108
51  };
52 
53 
55  class Partition : public BlkDevice
56  {
57  public:
58 
62  static Partition* create(Devicegraph* devicegraph, const std::string& name,
63  const Region& region, PartitionType type);
64  static Partition* load(Devicegraph* devicegraph, const xmlNode* node);
65 
66  unsigned int get_number() const;
67 
68  PartitionType get_type() const;
69  void set_type(PartitionType type);
70 
71  unsigned int get_id() const;
72  void set_id(unsigned int id);
73 
74  bool get_boot() const;
75  void set_boot(bool boot);
76 
77  const PartitionTable* get_partition_table() const;
78  const Partitionable* get_partitionable() const;
79 
80  static Partition* find_by_name(Devicegraph* devicegraph, const std::string& name);
81  static const Partition* find_by_name(const Devicegraph* devicegraph, const std::string& name);
82 
83  public:
84 
85  class Impl;
86 
87  Impl& get_impl();
88  const Impl& get_impl() const;
89 
90  virtual Partition* clone() const override;
91 
92  protected:
93 
94  Partition(Impl* impl);
95 
96  };
97 
98 
99  bool is_partition(const Device* device);
100 
101  Partition* to_partition(Device* device);
102  const Partition* to_partition(const Device* device);
103 
104 }
105 
106 #endif
PartitionType
Partition type (primary, extended, logical)
Definition: Partition.h:39
A start/length pair with a block size.
Definition: Region.h:71
The master container of the libstorage.
Definition: Devicegraph.h:133
An abstract Block Device.
Definition: BlkDevice.h:40
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:55
Definition: PartitionTable.h:71
static Partition * create(Devicegraph *devicegraph, const std::string &name, const Region &region, PartitionType type)
region is sector-based.