2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-06-30 13:37:46 +02:00
|
|
|
*
|
|
|
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
2016-03-04 19:12:17 +01:00
|
|
|
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
2014-06-30 13:37:46 +02:00
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PARTITIONCOREMODULE_H
|
|
|
|
#define PARTITIONCOREMODULE_H
|
|
|
|
|
2019-01-07 17:25:39 +01:00
|
|
|
#include "core/PartitionLayout.h"
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "core/PartitionModel.h"
|
|
|
|
#include "Typedefs.h"
|
2014-06-30 13:37:46 +02:00
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
// KPMcore
|
2018-06-07 22:22:22 +02:00
|
|
|
#include <kpmcore/core/lvmdevice.h>
|
2015-07-02 13:49:21 +02:00
|
|
|
#include <kpmcore/core/partitiontable.h>
|
2014-06-30 16:17:28 +02:00
|
|
|
|
2014-07-02 15:49:35 +02:00
|
|
|
// Qt
|
|
|
|
#include <QList>
|
2015-12-23 19:14:33 +01:00
|
|
|
#include <QMutex>
|
2014-07-02 15:49:35 +02:00
|
|
|
#include <QObject>
|
|
|
|
|
2015-12-23 19:14:33 +01:00
|
|
|
#include <functional>
|
|
|
|
|
2014-07-23 18:14:27 +02:00
|
|
|
class BootLoaderModel;
|
2014-06-30 18:08:13 +02:00
|
|
|
class CreatePartitionJob;
|
2014-06-30 13:37:46 +02:00
|
|
|
class Device;
|
2014-06-30 13:48:40 +02:00
|
|
|
class DeviceModel;
|
2014-06-30 16:17:28 +02:00
|
|
|
class FileSystem;
|
|
|
|
class Partition;
|
2014-06-30 13:37:46 +02:00
|
|
|
|
2014-07-22 10:42:50 +02:00
|
|
|
class QStandardItemModel;
|
|
|
|
|
2014-06-30 13:37:46 +02:00
|
|
|
/**
|
2014-08-08 11:46:43 +02:00
|
|
|
* The core of the module.
|
|
|
|
*
|
|
|
|
* It has two responsibilities:
|
|
|
|
* - Listing the devices and partitions, creating Qt models for them.
|
|
|
|
* - Creating jobs for any changes requested by the user interface.
|
2014-06-30 13:37:46 +02:00
|
|
|
*/
|
|
|
|
class PartitionCoreModule : public QObject
|
|
|
|
{
|
2014-07-07 16:26:56 +02:00
|
|
|
Q_OBJECT
|
2014-06-30 13:37:46 +02:00
|
|
|
public:
|
2018-09-03 16:57:20 +02:00
|
|
|
/**
|
|
|
|
* This helper class calls refresh() on the module
|
|
|
|
* on destruction (nothing else). It is used as
|
|
|
|
* part of the model-consistency objects, along with
|
|
|
|
* PartitionModel::ResetHelper.
|
|
|
|
*/
|
|
|
|
class RefreshHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RefreshHelper( PartitionCoreModule* module );
|
|
|
|
~RefreshHelper();
|
|
|
|
|
|
|
|
RefreshHelper( const RefreshHelper& ) = delete;
|
|
|
|
RefreshHelper& operator=( const RefreshHelper& ) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
PartitionCoreModule* m_module;
|
|
|
|
};
|
|
|
|
|
2017-03-03 12:31:39 +01:00
|
|
|
/**
|
|
|
|
* @brief The SummaryInfo struct is a wrapper for PartitionModel instances for
|
|
|
|
* a given Device.
|
|
|
|
* Each Device gets a mutable "after" model and an immutable "before" model.
|
|
|
|
*/
|
2014-07-30 14:15:29 +02:00
|
|
|
struct SummaryInfo
|
|
|
|
{
|
|
|
|
QString deviceName;
|
2015-04-09 17:47:23 +02:00
|
|
|
QString deviceNode;
|
2014-07-30 14:15:29 +02:00
|
|
|
PartitionModel* partitionModelBefore;
|
|
|
|
PartitionModel* partitionModelAfter;
|
|
|
|
};
|
|
|
|
|
2014-06-30 13:37:46 +02:00
|
|
|
PartitionCoreModule( QObject* parent = nullptr );
|
2014-06-30 14:12:23 +02:00
|
|
|
~PartitionCoreModule();
|
2014-06-30 13:37:46 +02:00
|
|
|
|
2017-03-03 12:31:39 +01:00
|
|
|
/**
|
|
|
|
* @brief init performs a devices scan and initializes all KPMcore data
|
|
|
|
* structures.
|
|
|
|
* This function is thread safe.
|
|
|
|
*/
|
2016-07-19 13:00:54 +02:00
|
|
|
void init();
|
|
|
|
|
2017-03-03 12:31:39 +01:00
|
|
|
/**
|
|
|
|
* @brief deviceModel returns a model which exposes a list of available
|
|
|
|
* storage devices.
|
|
|
|
* @return the device model.
|
|
|
|
*/
|
2014-06-30 13:48:40 +02:00
|
|
|
DeviceModel* deviceModel() const;
|
|
|
|
|
2017-03-03 12:31:39 +01:00
|
|
|
/**
|
|
|
|
* @brief partitionModelForDevice returns the PartitionModel for the given device.
|
|
|
|
* @param device the device for which to get a model.
|
|
|
|
* @return a PartitionModel which represents the partitions of a device.
|
|
|
|
*/
|
2016-09-09 11:25:04 +02:00
|
|
|
PartitionModel* partitionModelForDevice( const Device* device ) const;
|
2014-06-30 14:12:23 +02:00
|
|
|
|
2015-04-28 17:40:49 +02:00
|
|
|
//HACK: all devices change over time, and together make up the state of the CoreModule.
|
|
|
|
// However this makes it hard to show the *original* state of a device.
|
2017-03-03 12:31:39 +01:00
|
|
|
// For each DeviceInfo we keep a second Device object that contains the
|
|
|
|
// current state of a disk regardless of subsequent changes.
|
2015-04-28 17:40:49 +02:00
|
|
|
// -- Teo 4/2015
|
2015-12-23 15:41:31 +01:00
|
|
|
//FIXME: make this horrible method private. -- Teo 12/2015
|
2016-09-09 11:25:04 +02:00
|
|
|
Device* immutableDeviceCopy( const Device* device );
|
2015-04-28 17:40:49 +02:00
|
|
|
|
2017-03-03 12:31:39 +01:00
|
|
|
/**
|
|
|
|
* @brief bootLoaderModel returns a model which represents the available boot
|
|
|
|
* loader locations.
|
|
|
|
* The single BootLoaderModel instance belongs to the PCM.
|
|
|
|
* @return the BootLoaderModel.
|
|
|
|
*/
|
2014-07-22 10:42:50 +02:00
|
|
|
QAbstractItemModel* bootLoaderModel() const;
|
|
|
|
|
2014-07-15 14:40:08 +02:00
|
|
|
void createPartitionTable( Device* device, PartitionTable::TableType type );
|
2014-07-10 19:55:16 +02:00
|
|
|
|
2018-11-12 14:16:33 +01:00
|
|
|
/**
|
|
|
|
* @brief Add a job to do the actual partition-creation.
|
|
|
|
*
|
|
|
|
* If @p flags is not FlagNone, then the given flags are
|
|
|
|
* applied to the newly-created partition.
|
|
|
|
*/
|
2016-03-08 16:25:43 +01:00
|
|
|
void createPartition( Device* device, Partition* partition,
|
|
|
|
PartitionTable::Flags flags = PartitionTable::FlagNone );
|
2014-06-30 16:17:28 +02:00
|
|
|
|
2018-06-04 21:31:58 +02:00
|
|
|
void createVolumeGroup( QString &vgName, QVector< const Partition* > pvList, qint32 peSize );
|
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
void resizeVolumeGroup( LvmDevice* device, QVector< const Partition* >& pvList );
|
|
|
|
|
|
|
|
void deactivateVolumeGroup( LvmDevice* device );
|
|
|
|
|
|
|
|
void removeVolumeGroup( LvmDevice* device );
|
|
|
|
|
2014-07-02 15:49:35 +02:00
|
|
|
void deletePartition( Device* device, Partition* partition );
|
|
|
|
|
2014-07-17 14:59:59 +02:00
|
|
|
void formatPartition( Device* device, Partition* partition );
|
|
|
|
|
2014-08-05 14:57:00 +02:00
|
|
|
void resizePartition( Device* device, Partition* partition, qint64 first, qint64 last );
|
|
|
|
|
2016-03-04 19:12:17 +01:00
|
|
|
void setPartitionFlags( Device* device, Partition* partition, PartitionTable::Flags flags );
|
|
|
|
|
2014-07-23 18:15:46 +02:00
|
|
|
void setBootLoaderInstallPath( const QString& path );
|
|
|
|
|
2019-01-07 17:25:39 +01:00
|
|
|
void initLayout();
|
|
|
|
void initLayout( const QVariantList& config );
|
|
|
|
|
2019-01-07 17:26:37 +01:00
|
|
|
void layoutApply( Device *dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase );
|
2017-03-03 12:31:39 +01:00
|
|
|
/**
|
|
|
|
* @brief jobs creates and returns a list of jobs which can then apply the changes
|
|
|
|
* requested by the user.
|
|
|
|
* @return a list of jobs.
|
|
|
|
*/
|
2014-07-11 15:58:12 +02:00
|
|
|
QList< Calamares::job_ptr > jobs() const;
|
2014-07-02 16:06:54 +02:00
|
|
|
|
2015-05-28 18:32:59 +02:00
|
|
|
bool hasRootMountPoint() const;
|
2014-07-07 16:26:56 +02:00
|
|
|
|
2015-05-28 19:08:53 +02:00
|
|
|
QList< Partition* > efiSystemPartitions() const;
|
2017-03-03 12:31:39 +01:00
|
|
|
|
2018-06-07 22:22:22 +02:00
|
|
|
QVector< const Partition* > lvmPVs() const;
|
|
|
|
|
|
|
|
bool hasVGwithThisName( const QString& name ) const;
|
|
|
|
|
|
|
|
bool isInVG( const Partition* partition ) const;
|
2018-06-04 21:31:58 +02:00
|
|
|
|
2017-03-03 12:31:39 +01:00
|
|
|
/**
|
|
|
|
* @brief findPartitionByMountPoint returns a Partition* for a given mount point.
|
|
|
|
* @param mountPoint the mount point to find a partition for.
|
|
|
|
* @return a pointer to a Partition object.
|
|
|
|
* Note that this function looks for partitions in live devices (the "proposed"
|
|
|
|
* state), not the immutable copies. Comparisons with Partition* objects that
|
|
|
|
* refer to immutable Device*s will fail.
|
|
|
|
*/
|
2016-03-09 12:52:43 +01:00
|
|
|
Partition* findPartitionByMountPoint( const QString& mountPoint ) const;
|
2015-05-28 19:08:53 +02:00
|
|
|
|
2017-03-03 12:31:39 +01:00
|
|
|
void revert(); // full revert, thread safe, calls doInit
|
|
|
|
void revertAllDevices(); // convenience function, calls revertDevice
|
|
|
|
void revertDevice( Device* dev ); // rescans a single Device and updates DeviceInfo
|
|
|
|
void asyncRevertDevice( Device* dev, std::function< void() > callback ); //like revertDevice, but asynchronous
|
2014-07-24 19:28:53 +02:00
|
|
|
|
2017-03-03 12:31:39 +01:00
|
|
|
void clearJobs(); // only clear jobs, the Device* states are preserved
|
2014-09-16 18:11:19 +02:00
|
|
|
|
2017-03-03 12:31:39 +01:00
|
|
|
bool isDirty(); // true if there are pending changes, otherwise false
|
2014-09-04 19:35:44 +02:00
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
bool isVGdeactivated( LvmDevice* device );
|
|
|
|
|
2014-07-29 10:57:10 +02:00
|
|
|
/**
|
|
|
|
* To be called when a partition has been altered, but only for changes
|
|
|
|
* which do not affect its size, because changes which affect the partition size
|
|
|
|
* affect the size of other partitions as well.
|
|
|
|
*/
|
|
|
|
void refreshPartition( Device* device, Partition* partition );
|
|
|
|
|
2014-07-30 14:15:29 +02:00
|
|
|
/**
|
|
|
|
* Returns a list of SummaryInfo for devices which have pending changes.
|
|
|
|
* Caller is responsible for deleting the partition models
|
|
|
|
*/
|
|
|
|
QList< SummaryInfo > createSummaryInfo() const;
|
|
|
|
|
2017-03-03 12:31:39 +01:00
|
|
|
void dumpQueue() const; // debug output
|
2014-09-16 18:11:19 +02:00
|
|
|
|
2017-03-03 12:31:39 +01:00
|
|
|
const OsproberEntryList osproberEntries() const; // os-prober data structure, cached
|
2015-12-15 14:00:34 +01:00
|
|
|
|
2014-07-07 16:26:56 +02:00
|
|
|
Q_SIGNALS:
|
|
|
|
void hasRootMountPointChanged( bool value );
|
2014-07-24 19:28:53 +02:00
|
|
|
void isDirtyChanged( bool value );
|
2015-10-30 17:28:31 +01:00
|
|
|
void reverted();
|
2016-01-05 18:44:05 +01:00
|
|
|
void deviceReverted( Device* device );
|
2014-07-07 16:26:56 +02:00
|
|
|
|
2014-06-30 13:37:46 +02:00
|
|
|
private:
|
2018-09-03 16:57:20 +02:00
|
|
|
void refreshAfterModelChange();
|
2014-07-29 10:57:10 +02:00
|
|
|
|
2014-07-11 16:55:21 +02:00
|
|
|
/**
|
2014-07-16 16:20:58 +02:00
|
|
|
* Owns the Device, PartitionModel and the jobs
|
2014-07-11 16:55:21 +02:00
|
|
|
*/
|
2014-07-16 16:20:58 +02:00
|
|
|
struct DeviceInfo
|
2014-07-11 15:58:12 +02:00
|
|
|
{
|
|
|
|
DeviceInfo( Device* );
|
2014-07-11 16:55:21 +02:00
|
|
|
~DeviceInfo();
|
2014-07-11 15:58:12 +02:00
|
|
|
QScopedPointer< Device > device;
|
|
|
|
QScopedPointer< PartitionModel > partitionModel;
|
2016-09-09 11:25:04 +02:00
|
|
|
const QScopedPointer< Device > immutableDevice;
|
2014-07-11 15:58:12 +02:00
|
|
|
QList< Calamares::job_ptr > jobs;
|
2014-07-11 16:55:21 +02:00
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
// To check if LVM VGs are deactivated
|
|
|
|
bool isAvailable;
|
|
|
|
|
2014-07-11 17:08:56 +02:00
|
|
|
void forgetChanges();
|
2014-07-24 19:28:53 +02:00
|
|
|
bool isDirty() const;
|
2014-07-11 15:58:12 +02:00
|
|
|
};
|
|
|
|
QList< DeviceInfo* > m_deviceInfos;
|
2015-05-28 19:08:53 +02:00
|
|
|
QList< Partition* > m_efiSystemPartitions;
|
2018-06-07 22:22:22 +02:00
|
|
|
QVector< const Partition* > m_lvmPVs;
|
2014-07-11 15:58:12 +02:00
|
|
|
|
2014-06-30 13:48:40 +02:00
|
|
|
DeviceModel* m_deviceModel;
|
2014-07-23 18:14:27 +02:00
|
|
|
BootLoaderModel* m_bootLoaderModel;
|
2014-07-07 16:26:56 +02:00
|
|
|
bool m_hasRootMountPoint = false;
|
2014-07-24 19:28:53 +02:00
|
|
|
bool m_isDirty = false;
|
2014-07-23 18:15:46 +02:00
|
|
|
QString m_bootLoaderInstallPath;
|
2019-01-07 17:25:39 +01:00
|
|
|
PartitionLayout* m_partLayout;
|
2014-06-30 13:37:46 +02:00
|
|
|
|
2016-07-19 13:00:54 +02:00
|
|
|
void doInit();
|
2014-07-10 19:01:55 +02:00
|
|
|
void updateHasRootMountPoint();
|
2014-07-24 19:28:53 +02:00
|
|
|
void updateIsDirty();
|
2015-05-28 19:08:53 +02:00
|
|
|
void scanForEfiSystemPartitions();
|
2018-06-04 21:31:58 +02:00
|
|
|
void scanForLVMPVs();
|
2014-07-10 18:55:19 +02:00
|
|
|
|
2016-09-09 11:25:04 +02:00
|
|
|
DeviceInfo* infoForDevice( const Device* ) const;
|
2014-07-22 10:42:50 +02:00
|
|
|
|
2015-12-15 14:00:34 +01:00
|
|
|
OsproberEntryList m_osproberLines;
|
2015-12-23 19:14:33 +01:00
|
|
|
|
|
|
|
QMutex m_revertMutex;
|
2014-06-30 13:37:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* PARTITIONCOREMODULE_H */
|