OSDN Git Service

Merge pull request #1409 from gportay/partition-uuid
[alterlinux/alterlinux-calamares.git] / src / modules / partition / core / PartitionLayout.h
1 /* === This file is part of Calamares - <https://github.com/calamares> ===
2  *
3  *   Copyright 2018-2019, Collabora Ltd <arnaud.ferraris@collabora.com>
4  *   Copyright 2019, Adriaan de Groot <groot@kde.org>
5  *
6  *   Calamares is free software: you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, either version 3 of the License, or
9  *   (at your option) any later version.
10  *
11  *   Calamares is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef PARTITIONLAYOUT_H
21 #define PARTITIONLAYOUT_H
22
23 #include "partition/PartitionSize.h"
24
25 #include "core/PartUtils.h"
26
27 // KPMcore
28 #include <kpmcore/core/partitiontable.h>
29 #include <kpmcore/fs/filesystem.h>
30
31 // Qt
32 #include <QList>
33 #include <QObject>
34 #include <QVariantMap>
35
36 class Partition;
37
38 class PartitionLayout
39 {
40 public:
41     struct PartitionEntry
42     {
43         QString partLabel;
44         QString partUUID;
45         QString partType;
46         QString partMountPoint;
47         FileSystem::Type partFileSystem = FileSystem::Unknown;
48         QVariantMap partFeatures;
49         CalamaresUtils::Partition::PartitionSize partSize;
50         CalamaresUtils::Partition::PartitionSize partMinSize;
51         CalamaresUtils::Partition::PartitionSize partMaxSize;
52
53         /// @brief All-zeroes PartitionEntry
54         PartitionEntry() {}
55         /// @brief Parse @p size, @p min and @p max to their respective member variables
56         PartitionEntry( const QString& size, const QString& min, const QString& max );
57
58         bool isValid() const
59         {
60             if ( !partSize.isValid()
61                  || ( partMinSize.isValid() && partMaxSize.isValid() && partMinSize > partMaxSize ) )
62             {
63                 return false;
64             }
65             return true;
66         }
67     };
68
69     PartitionLayout();
70     PartitionLayout( PartitionEntry entry );
71     PartitionLayout( const PartitionLayout& layout );
72     ~PartitionLayout();
73
74     bool addEntry( PartitionEntry entry );
75     bool addEntry( const QString& mountPoint,
76                    const QString& size,
77                    const QString& min = QString(),
78                    const QString& max = QString() );
79     bool addEntry( const QString& label,
80                    const QString& uuid,
81                    const QString& type,
82                    const QString& mountPoint,
83                    const QString& fs,
84                    const QVariantMap& features,
85                    const QString& size,
86                    const QString& min = QString(),
87                    const QString& max = QString() );
88
89     /**
90      * @brief Apply the current partition layout to the selected drive space.
91      * @return  A list of Partition objects.
92      */
93     QList< Partition* > execute( Device* dev,
94                                  qint64 firstSector,
95                                  qint64 lastSector,
96                                  QString luksPassphrase,
97                                  PartitionNode* parent,
98                                  const PartitionRole& role );
99
100 private:
101     FileSystem::Type m_defaultFsType;
102     QList< PartitionEntry > m_partLayout;
103 };
104
105 #endif /* PARTITIONLAYOUT_H */