2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2014-06-30 13:37:46 +02:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014 Aurélien Gâteau <agateau@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2014-2015 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2017-2019 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2018 Caio Carvalho <caiojcarvalho@gmail.com>
|
|
|
|
* SPDX-FileCopyrightText: 2019 Collabora Ltd <arnaud.ferraris@collabora.com>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2014-06-30 13:37:46 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2014-06-30 13:37:46 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-07-03 17:03:33 +02:00
|
|
|
#include "core/PartitionCoreModule.h"
|
|
|
|
|
|
|
|
#include "core/BootLoaderModel.h"
|
2016-07-27 16:49:53 +02:00
|
|
|
#include "core/ColorUtils.h"
|
2017-07-11 14:54:56 +02:00
|
|
|
#include "core/DeviceList.h"
|
2015-07-03 17:03:33 +02:00
|
|
|
#include "core/DeviceModel.h"
|
2015-09-18 15:41:07 +02:00
|
|
|
#include "core/KPMHelpers.h"
|
2015-12-15 14:00:34 +01:00
|
|
|
#include "core/PartUtils.h"
|
2020-02-14 11:15:57 +01:00
|
|
|
#include "core/PartitionInfo.h"
|
|
|
|
#include "core/PartitionModel.h"
|
2021-02-03 01:31:37 +01:00
|
|
|
#include "jobs/AutoMountManagementJob.h"
|
2016-07-23 20:04:23 +02:00
|
|
|
#include "jobs/ChangeFilesystemLabelJob.h"
|
2015-07-03 17:03:33 +02:00
|
|
|
#include "jobs/ClearMountsJob.h"
|
|
|
|
#include "jobs/ClearTempMountsJob.h"
|
|
|
|
#include "jobs/CreatePartitionJob.h"
|
|
|
|
#include "jobs/CreatePartitionTableJob.h"
|
2018-06-04 21:31:58 +02:00
|
|
|
#include "jobs/CreateVolumeGroupJob.h"
|
2018-06-26 05:38:52 +02:00
|
|
|
#include "jobs/DeactivateVolumeGroupJob.h"
|
2015-07-03 17:03:33 +02:00
|
|
|
#include "jobs/DeletePartitionJob.h"
|
|
|
|
#include "jobs/FillGlobalStorageJob.h"
|
|
|
|
#include "jobs/FormatPartitionJob.h"
|
2018-06-26 05:38:52 +02:00
|
|
|
#include "jobs/RemoveVolumeGroupJob.h"
|
2015-07-03 17:03:33 +02:00
|
|
|
#include "jobs/ResizePartitionJob.h"
|
2018-06-26 05:38:52 +02:00
|
|
|
#include "jobs/ResizeVolumeGroupJob.h"
|
2016-03-04 19:12:17 +01:00
|
|
|
#include "jobs/SetPartitionFlagsJob.h"
|
2019-04-29 11:51:27 +02:00
|
|
|
|
2019-03-17 18:32:18 +01:00
|
|
|
#ifdef DEBUG_PARTITION_LAME
|
|
|
|
#include "JobExample.h"
|
|
|
|
#endif
|
2019-06-13 12:27:39 +02:00
|
|
|
#include "partition/PartitionIterator.h"
|
2019-06-13 14:41:33 +02:00
|
|
|
#include "partition/PartitionQuery.h"
|
2015-07-03 17:03:33 +02:00
|
|
|
#include "utils/Logger.h"
|
2020-08-04 16:20:04 +02:00
|
|
|
#include "utils/Traits.h"
|
2019-06-13 12:27:39 +02:00
|
|
|
#include "utils/Variant.h"
|
2014-06-30 13:48:40 +02:00
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
// KPMcore
|
2020-02-14 11:15:57 +01:00
|
|
|
#include <kpmcore/backend/corebackend.h>
|
|
|
|
#include <kpmcore/backend/corebackendmanager.h>
|
2015-07-02 13:49:21 +02:00
|
|
|
#include <kpmcore/core/device.h>
|
2018-06-04 21:31:58 +02:00
|
|
|
#include <kpmcore/core/lvmdevice.h>
|
2015-07-02 13:49:21 +02:00
|
|
|
#include <kpmcore/core/partition.h>
|
2019-04-10 07:12:31 +02:00
|
|
|
#include <kpmcore/core/volumemanagerdevice.h>
|
2015-07-02 13:49:21 +02:00
|
|
|
#include <kpmcore/fs/filesystemfactory.h>
|
2018-06-08 23:52:53 +02:00
|
|
|
#include <kpmcore/fs/luks.h>
|
2018-06-04 21:31:58 +02:00
|
|
|
#include <kpmcore/fs/lvm2_pv.h>
|
2014-06-30 13:37:46 +02:00
|
|
|
|
2014-07-22 10:42:50 +02:00
|
|
|
// Qt
|
2015-05-28 19:08:53 +02:00
|
|
|
#include <QDir>
|
2015-12-24 12:09:47 +01:00
|
|
|
#include <QFutureWatcher>
|
2020-02-14 11:15:57 +01:00
|
|
|
#include <QProcess>
|
|
|
|
#include <QStandardItemModel>
|
2015-12-24 12:09:47 +01:00
|
|
|
#include <QtConcurrent/QtConcurrent>
|
2014-07-22 10:42:50 +02:00
|
|
|
|
2019-06-13 14:41:33 +02:00
|
|
|
using CalamaresUtils::Partition::isPartitionFreeSpace;
|
|
|
|
using CalamaresUtils::Partition::isPartitionNew;
|
2020-02-14 11:15:57 +01:00
|
|
|
using CalamaresUtils::Partition::PartitionIterator;
|
2018-09-03 16:57:20 +02:00
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::RefreshHelper::RefreshHelper( PartitionCoreModule* module )
|
2018-09-03 16:57:20 +02:00
|
|
|
: m_module( module )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PartitionCoreModule::RefreshHelper::~RefreshHelper()
|
|
|
|
{
|
|
|
|
m_module->refreshAfterModelChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
class OperationHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OperationHelper( PartitionModel* model, PartitionCoreModule* core )
|
2018-09-03 21:21:30 +02:00
|
|
|
: m_coreHelper( core )
|
|
|
|
, m_modelHelper( model )
|
2018-09-03 16:57:20 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OperationHelper( const OperationHelper& ) = delete;
|
|
|
|
OperationHelper& operator=( const OperationHelper& ) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Keep these in order: first the model needs to finish,
|
2018-09-03 21:21:30 +02:00
|
|
|
// then refresh is called. Remember that destructors are
|
|
|
|
// called in *reverse* order of declaration in this class.
|
2018-09-03 16:57:20 +02:00
|
|
|
PartitionCoreModule::RefreshHelper m_coreHelper;
|
2018-09-03 21:21:30 +02:00
|
|
|
PartitionModel::ResetHelper m_modelHelper;
|
2020-02-14 11:15:57 +01:00
|
|
|
};
|
2018-09-03 16:57:20 +02:00
|
|
|
|
|
|
|
|
2014-07-11 15:58:12 +02:00
|
|
|
//- DeviceInfo ---------------------------------------------
|
2020-08-04 16:20:04 +02:00
|
|
|
// Some jobs have an updatePreview some don't
|
2020-09-21 16:36:43 +02:00
|
|
|
DECLARE_HAS_METHOD( updatePreview )
|
2020-08-04 16:20:04 +02:00
|
|
|
|
2020-09-21 16:36:43 +02:00
|
|
|
template < typename Job >
|
|
|
|
void
|
|
|
|
updatePreview( Job* job, const std::true_type& )
|
2020-08-04 16:20:04 +02:00
|
|
|
{
|
|
|
|
job->updatePreview();
|
|
|
|
}
|
|
|
|
|
2020-09-21 16:36:43 +02:00
|
|
|
template < typename Job >
|
|
|
|
void
|
2020-10-24 02:24:37 +02:00
|
|
|
updatePreview( Job*, const std::false_type& )
|
2020-08-04 16:20:04 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-21 16:36:43 +02:00
|
|
|
template < typename Job >
|
|
|
|
void
|
|
|
|
updatePreview( Job* job )
|
2020-08-04 16:20:04 +02:00
|
|
|
{
|
2020-09-21 16:36:43 +02:00
|
|
|
updatePreview( job, has_updatePreview< Job > {} );
|
2020-08-04 16:20:04 +02:00
|
|
|
}
|
|
|
|
|
2020-08-03 13:20:04 +02:00
|
|
|
/**
|
2020-08-04 16:20:04 +02:00
|
|
|
* Owns the Device, PartitionModel and the jobs
|
|
|
|
*/
|
2020-08-03 13:20:04 +02:00
|
|
|
struct PartitionCoreModule::DeviceInfo
|
|
|
|
{
|
|
|
|
DeviceInfo( Device* );
|
|
|
|
~DeviceInfo();
|
|
|
|
QScopedPointer< Device > device;
|
|
|
|
QScopedPointer< PartitionModel > partitionModel;
|
|
|
|
const QScopedPointer< Device > immutableDevice;
|
|
|
|
|
|
|
|
// To check if LVM VGs are deactivated
|
|
|
|
bool isAvailable;
|
|
|
|
|
|
|
|
void forgetChanges();
|
|
|
|
bool isDirty() const;
|
|
|
|
|
|
|
|
const Calamares::JobList& jobs() const { return m_jobs; }
|
|
|
|
|
2020-09-21 16:36:43 +02:00
|
|
|
/** @brief Take the jobs of the given type that apply to @p partition
|
|
|
|
*
|
|
|
|
* Returns a job pointer to the job that has just been removed.
|
|
|
|
*/
|
|
|
|
template < typename Job >
|
|
|
|
Calamares::job_ptr takeJob( Partition* partition )
|
|
|
|
{
|
|
|
|
for ( auto it = m_jobs.begin(); it != m_jobs.end(); )
|
|
|
|
{
|
|
|
|
Job* job = qobject_cast< Job* >( it->data() );
|
|
|
|
if ( job && job->partition() == partition )
|
|
|
|
{
|
|
|
|
Calamares::job_ptr p = *it;
|
|
|
|
it = m_jobs.erase( it );
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Calamares::job_ptr( nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Add a job of given type to the job list
|
|
|
|
*/
|
|
|
|
template < typename Job, typename... Args >
|
|
|
|
Calamares::Job* makeJob( Args... a )
|
2020-08-03 13:20:04 +02:00
|
|
|
{
|
|
|
|
auto* job = new Job( device.get(), a... );
|
2020-08-04 16:20:04 +02:00
|
|
|
updatePreview( job );
|
2020-08-03 13:20:04 +02:00
|
|
|
m_jobs << Calamares::job_ptr( job );
|
|
|
|
return job;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Calamares::JobList m_jobs;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-11 15:58:12 +02:00
|
|
|
PartitionCoreModule::DeviceInfo::DeviceInfo( Device* _device )
|
|
|
|
: device( _device )
|
|
|
|
, partitionModel( new PartitionModel )
|
2016-09-09 11:25:04 +02:00
|
|
|
, immutableDevice( new Device( *_device ) )
|
2018-06-26 05:38:52 +02:00
|
|
|
, isAvailable( true )
|
2014-07-11 16:55:21 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::DeviceInfo::~DeviceInfo() {}
|
|
|
|
|
2015-12-23 15:41:31 +01:00
|
|
|
|
2014-07-11 17:08:56 +02:00
|
|
|
void
|
|
|
|
PartitionCoreModule::DeviceInfo::forgetChanges()
|
|
|
|
{
|
2020-08-03 13:13:56 +02:00
|
|
|
m_jobs.clear();
|
2014-07-17 09:49:24 +02:00
|
|
|
for ( auto it = PartitionIterator::begin( device.data() ); it != PartitionIterator::end( device.data() ); ++it )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2014-07-16 16:20:58 +02:00
|
|
|
PartitionInfo::reset( *it );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2015-12-18 15:02:55 +01:00
|
|
|
partitionModel->revert();
|
2014-07-11 17:08:56 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 19:28:53 +02:00
|
|
|
|
|
|
|
bool
|
|
|
|
PartitionCoreModule::DeviceInfo::isDirty() const
|
|
|
|
{
|
2020-08-03 13:13:56 +02:00
|
|
|
if ( !m_jobs.isEmpty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2014-07-24 19:28:53 +02:00
|
|
|
return true;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-07-24 19:28:53 +02:00
|
|
|
|
|
|
|
for ( auto it = PartitionIterator::begin( device.data() ); it != PartitionIterator::end( device.data() ); ++it )
|
2020-08-03 13:13:56 +02:00
|
|
|
{
|
2014-07-24 19:28:53 +02:00
|
|
|
if ( PartitionInfo::isDirty( *it ) )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2014-07-24 19:28:53 +02:00
|
|
|
return true;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2020-08-03 13:13:56 +02:00
|
|
|
}
|
2014-07-24 19:28:53 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-11 15:58:12 +02:00
|
|
|
//- PartitionCoreModule ------------------------------------
|
2014-06-30 13:37:46 +02:00
|
|
|
PartitionCoreModule::PartitionCoreModule( QObject* parent )
|
|
|
|
: QObject( parent )
|
2014-06-30 13:48:40 +02:00
|
|
|
, m_deviceModel( new DeviceModel( this ) )
|
2014-07-23 18:14:27 +02:00
|
|
|
, m_bootLoaderModel( new BootLoaderModel( this ) )
|
2014-06-30 13:37:46 +02:00
|
|
|
{
|
2019-06-13 22:33:41 +02:00
|
|
|
if ( !m_kpmcore )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2015-07-03 17:03:33 +02:00
|
|
|
qFatal( "Failed to initialize KPMcore backend" );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-07-24 19:28:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-19 13:00:54 +02:00
|
|
|
|
2014-07-24 19:28:53 +02:00
|
|
|
void
|
|
|
|
PartitionCoreModule::init()
|
2016-07-19 13:00:54 +02:00
|
|
|
{
|
|
|
|
QMutexLocker locker( &m_revertMutex );
|
|
|
|
doInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PartitionCoreModule::doInit()
|
2014-07-24 19:28:53 +02:00
|
|
|
{
|
2016-07-20 13:01:33 +02:00
|
|
|
FileSystemFactory::init();
|
|
|
|
|
2017-07-04 11:32:05 +02:00
|
|
|
using DeviceList = QList< Device* >;
|
2017-07-12 11:41:29 +02:00
|
|
|
DeviceList devices = PartUtils::getDevices( PartUtils::DeviceType::WritableOnly );
|
2014-07-30 23:21:06 +02:00
|
|
|
|
2017-07-04 11:32:05 +02:00
|
|
|
cDebug() << "LIST OF DETECTED DEVICES:";
|
2021-06-04 13:32:22 +02:00
|
|
|
cDebug() << Logger::SubEntry << "node\tcapacity\tname\tprettyName";
|
2014-07-11 15:58:12 +02:00
|
|
|
for ( auto device : devices )
|
2014-06-30 14:12:23 +02:00
|
|
|
{
|
2021-06-04 13:32:22 +02:00
|
|
|
cDebug() << Logger::SubEntry << Logger::Pointer(device);
|
|
|
|
if ( device )
|
|
|
|
{
|
|
|
|
// Gives ownership of the Device* to the DeviceInfo object
|
|
|
|
auto deviceInfo = new DeviceInfo( device );
|
|
|
|
m_deviceInfos << deviceInfo;
|
|
|
|
cDebug() << Logger::SubEntry << device->deviceNode() << device->capacity() << device->name()
|
|
|
|
<< device->prettyName();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cDebug() << Logger::SubEntry << "(skipped null device)";
|
|
|
|
}
|
2014-06-30 14:12:23 +02:00
|
|
|
}
|
2019-04-15 14:59:12 +02:00
|
|
|
cDebug() << Logger::SubEntry << devices.count() << "devices detected.";
|
2014-07-11 15:58:12 +02:00
|
|
|
m_deviceModel->init( devices );
|
2014-06-30 13:48:40 +02:00
|
|
|
|
2015-12-15 18:12:23 +01:00
|
|
|
// The following PartUtils::runOsprober call in turn calls PartUtils::canBeResized,
|
|
|
|
// which relies on a working DeviceModel.
|
2020-10-05 11:39:04 +02:00
|
|
|
m_osproberLines = PartUtils::runOsprober( this->deviceModel() );
|
2015-12-15 18:12:23 +01:00
|
|
|
|
2016-07-28 17:41:44 +02:00
|
|
|
// We perform a best effort of filling out filesystem UUIDs in m_osproberLines
|
|
|
|
// because we will need them later on in PartitionModel if partition paths
|
|
|
|
// change.
|
|
|
|
// It is a known fact that /dev/sda1-style device paths aren't persistent
|
|
|
|
// across reboots (and this doesn't affect us), but partition numbers can also
|
|
|
|
// change at runtime against our will just for shits and giggles.
|
|
|
|
// But why would that ever happen? What system could possibly be so poorly
|
|
|
|
// designed that it requires a partition path rearrangement at runtime?
|
|
|
|
// Logical partitions on an MSDOS disklabel of course.
|
|
|
|
// See DeletePartitionJob::updatePreview.
|
|
|
|
for ( auto deviceInfo : m_deviceInfos )
|
|
|
|
{
|
|
|
|
for ( auto it = PartitionIterator::begin( deviceInfo->device.data() );
|
2020-02-14 11:15:57 +01:00
|
|
|
it != PartitionIterator::end( deviceInfo->device.data() );
|
|
|
|
++it )
|
2016-07-28 17:41:44 +02:00
|
|
|
{
|
|
|
|
Partition* partition = *it;
|
2020-02-14 11:15:57 +01:00
|
|
|
for ( auto jt = m_osproberLines.begin(); jt != m_osproberLines.end(); ++jt )
|
2016-07-28 17:41:44 +02:00
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
if ( jt->path == partition->partitionPath()
|
|
|
|
&& partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone
|
|
|
|
&& !partition->fileSystem().uuid().isEmpty() )
|
|
|
|
{
|
2016-07-28 17:41:44 +02:00
|
|
|
jt->uuid = partition->fileSystem().uuid();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2016-07-28 17:41:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 18:12:23 +01:00
|
|
|
for ( auto deviceInfo : m_deviceInfos )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2015-12-15 18:12:23 +01:00
|
|
|
deviceInfo->partitionModel->init( deviceInfo->device.data(), m_osproberLines );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2015-12-15 18:12:23 +01:00
|
|
|
|
2018-05-10 23:37:37 +02:00
|
|
|
DeviceList bootLoaderDevices;
|
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
for ( DeviceList::Iterator it = devices.begin(); it != devices.end(); ++it )
|
|
|
|
if ( ( *it )->type() != Device::Type::Disk_Device )
|
2018-05-10 23:37:37 +02:00
|
|
|
{
|
|
|
|
cDebug() << "Ignoring device that is not Disk_Device to bootLoaderDevices list.";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
|
|
|
bootLoaderDevices.append( *it );
|
|
|
|
}
|
2018-05-10 23:37:37 +02:00
|
|
|
|
|
|
|
m_bootLoaderModel->init( bootLoaderDevices );
|
2015-05-28 19:08:53 +02:00
|
|
|
|
2018-06-04 21:31:58 +02:00
|
|
|
scanForLVMPVs();
|
|
|
|
|
2017-07-11 11:26:10 +02:00
|
|
|
//FIXME: this should be removed in favor of
|
|
|
|
// proper KPM support for EFI
|
2017-08-28 11:36:21 +02:00
|
|
|
if ( PartUtils::isEfiSystem() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2017-07-11 11:26:10 +02:00
|
|
|
scanForEfiSystemPartitions();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-06-30 13:37:46 +02:00
|
|
|
}
|
|
|
|
|
2014-06-30 14:12:23 +02:00
|
|
|
PartitionCoreModule::~PartitionCoreModule()
|
2014-06-30 13:37:46 +02:00
|
|
|
{
|
2014-07-11 15:58:12 +02:00
|
|
|
qDeleteAll( m_deviceInfos );
|
2014-06-30 13:37:46 +02:00
|
|
|
}
|
2014-06-30 13:48:40 +02:00
|
|
|
|
|
|
|
DeviceModel*
|
|
|
|
PartitionCoreModule::deviceModel() const
|
|
|
|
{
|
|
|
|
return m_deviceModel;
|
|
|
|
}
|
2014-06-30 14:12:23 +02:00
|
|
|
|
2021-05-25 13:23:28 +02:00
|
|
|
BootLoaderModel*
|
2014-07-22 10:42:50 +02:00
|
|
|
PartitionCoreModule::bootLoaderModel() const
|
|
|
|
{
|
|
|
|
return m_bootLoaderModel;
|
|
|
|
}
|
|
|
|
|
2014-06-30 14:12:23 +02:00
|
|
|
PartitionModel*
|
2016-09-09 11:25:04 +02:00
|
|
|
PartitionCoreModule::partitionModelForDevice( const Device* device ) const
|
2014-06-30 14:12:23 +02:00
|
|
|
{
|
2014-07-11 15:58:12 +02:00
|
|
|
DeviceInfo* info = infoForDevice( device );
|
|
|
|
Q_ASSERT( info );
|
|
|
|
return info->partitionModel.data();
|
2014-06-30 14:12:23 +02:00
|
|
|
}
|
2014-06-30 16:17:28 +02:00
|
|
|
|
2015-04-28 17:40:49 +02:00
|
|
|
|
|
|
|
Device*
|
2016-09-09 11:25:04 +02:00
|
|
|
PartitionCoreModule::immutableDeviceCopy( const Device* device )
|
2015-04-28 17:40:49 +02:00
|
|
|
{
|
2016-09-09 11:25:04 +02:00
|
|
|
Q_ASSERT( device );
|
|
|
|
DeviceInfo* info = infoForDevice( device );
|
|
|
|
if ( !info )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2016-09-09 11:25:04 +02:00
|
|
|
return nullptr;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2015-04-28 17:40:49 +02:00
|
|
|
|
2016-09-09 11:25:04 +02:00
|
|
|
return info->immutableDevice.data();
|
2015-04-28 17:40:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-10 19:55:16 +02:00
|
|
|
void
|
2014-07-15 14:40:08 +02:00
|
|
|
PartitionCoreModule::createPartitionTable( Device* device, PartitionTable::TableType type )
|
2014-07-10 19:55:16 +02:00
|
|
|
{
|
2020-08-03 13:41:34 +02:00
|
|
|
auto* deviceInfo = infoForDevice( device );
|
|
|
|
if ( deviceInfo )
|
2015-06-21 01:27:02 +02:00
|
|
|
{
|
|
|
|
// Creating a partition table wipes all the disk, so there is no need to
|
|
|
|
// keep previous changes
|
2020-08-03 13:41:34 +02:00
|
|
|
deviceInfo->forgetChanges();
|
2015-06-21 01:27:02 +02:00
|
|
|
|
2018-09-03 16:57:20 +02:00
|
|
|
OperationHelper helper( partitionModelForDevice( device ), this );
|
2020-08-04 16:53:29 +02:00
|
|
|
deviceInfo->makeJob< CreatePartitionTableJob >( type );
|
2021-03-31 18:15:02 +02:00
|
|
|
|
2015-06-21 01:27:02 +02:00
|
|
|
}
|
2014-07-10 19:55:16 +02:00
|
|
|
}
|
|
|
|
|
2014-06-30 16:17:28 +02:00
|
|
|
void
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::createPartition( Device* device, Partition* partition, PartitionTable::Flags flags )
|
2014-06-30 16:17:28 +02:00
|
|
|
{
|
2020-08-03 13:41:34 +02:00
|
|
|
auto* deviceInfo = infoForDevice( device );
|
2014-07-11 15:58:12 +02:00
|
|
|
Q_ASSERT( deviceInfo );
|
2014-07-04 17:58:32 +02:00
|
|
|
|
2018-09-03 16:57:20 +02:00
|
|
|
OperationHelper helper( partitionModelForDevice( device ), this );
|
2020-08-04 16:53:29 +02:00
|
|
|
deviceInfo->makeJob< CreatePartitionJob >( partition );
|
2014-07-02 15:49:35 +02:00
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
if ( flags != KPM_PARTITION_FLAG( None ) )
|
2016-03-08 16:25:43 +01:00
|
|
|
{
|
2020-08-04 16:53:29 +02:00
|
|
|
deviceInfo->makeJob< SetPartFlagsJob >( partition, flags );
|
2018-05-16 13:13:35 +02:00
|
|
|
PartitionInfo::setFlags( partition, flags );
|
2016-03-08 16:25:43 +01:00
|
|
|
}
|
2014-06-30 16:17:28 +02:00
|
|
|
}
|
|
|
|
|
2018-06-04 21:31:58 +02:00
|
|
|
void
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::createVolumeGroup( QString& vgName, QVector< const Partition* > pvList, qint32 peSize )
|
2018-06-04 21:31:58 +02:00
|
|
|
{
|
2018-06-07 22:22:22 +02:00
|
|
|
// Appending '_' character in case of repeated VG name
|
|
|
|
while ( hasVGwithThisName( vgName ) )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
|
|
|
vgName.append( '_' );
|
|
|
|
}
|
2018-06-07 22:22:22 +02:00
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
LvmDevice* device = new LvmDevice( vgName );
|
2018-06-04 21:31:58 +02:00
|
|
|
for ( const Partition* p : pvList )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-06-04 21:31:58 +02:00
|
|
|
device->physicalVolumes() << p;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-06-04 21:31:58 +02:00
|
|
|
|
|
|
|
DeviceInfo* deviceInfo = new DeviceInfo( device );
|
2018-06-07 22:22:22 +02:00
|
|
|
deviceInfo->partitionModel->init( device, osproberEntries() );
|
|
|
|
m_deviceModel->addDevice( device );
|
2018-06-04 21:31:58 +02:00
|
|
|
m_deviceInfos << deviceInfo;
|
|
|
|
|
2020-08-04 16:53:29 +02:00
|
|
|
deviceInfo->makeJob< CreateVolumeGroupJob >( vgName, pvList, peSize );
|
2018-09-03 16:57:20 +02:00
|
|
|
refreshAfterModelChange();
|
2018-06-04 21:31:58 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
void
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::resizeVolumeGroup( LvmDevice* device, QVector< const Partition* >& pvList )
|
2018-06-26 05:38:52 +02:00
|
|
|
{
|
2020-08-03 13:41:34 +02:00
|
|
|
auto* deviceInfo = infoForDevice( device );
|
2018-06-26 05:38:52 +02:00
|
|
|
Q_ASSERT( deviceInfo );
|
2020-08-04 16:53:29 +02:00
|
|
|
deviceInfo->makeJob< ResizeVolumeGroupJob >( device, pvList );
|
2018-09-03 16:57:20 +02:00
|
|
|
refreshAfterModelChange();
|
2018-06-26 05:38:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::deactivateVolumeGroup( LvmDevice* device )
|
2018-06-26 05:38:52 +02:00
|
|
|
{
|
2020-08-03 13:41:34 +02:00
|
|
|
auto* deviceInfo = infoForDevice( device );
|
2018-06-26 05:38:52 +02:00
|
|
|
Q_ASSERT( deviceInfo );
|
|
|
|
|
|
|
|
deviceInfo->isAvailable = false;
|
|
|
|
|
2020-08-04 16:53:29 +02:00
|
|
|
// TODO: this leaks
|
2018-06-26 05:38:52 +02:00
|
|
|
DeactivateVolumeGroupJob* job = new DeactivateVolumeGroupJob( device );
|
|
|
|
|
|
|
|
// DeactivateVolumeGroupJob needs to be immediately called
|
|
|
|
job->exec();
|
|
|
|
|
2018-09-03 16:57:20 +02:00
|
|
|
refreshAfterModelChange();
|
2018-06-26 05:38:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::removeVolumeGroup( LvmDevice* device )
|
2018-06-26 05:38:52 +02:00
|
|
|
{
|
2020-08-03 13:41:34 +02:00
|
|
|
auto* deviceInfo = infoForDevice( device );
|
2018-06-26 05:38:52 +02:00
|
|
|
Q_ASSERT( deviceInfo );
|
2020-08-04 16:53:29 +02:00
|
|
|
deviceInfo->makeJob< RemoveVolumeGroupJob >( device );
|
2018-09-03 16:57:20 +02:00
|
|
|
refreshAfterModelChange();
|
2018-06-26 05:38:52 +02:00
|
|
|
}
|
|
|
|
|
2014-07-02 15:49:35 +02:00
|
|
|
void
|
|
|
|
PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
|
|
|
{
|
2020-08-03 13:41:34 +02:00
|
|
|
auto* deviceInfo = infoForDevice( device );
|
2014-07-11 15:58:12 +02:00
|
|
|
Q_ASSERT( deviceInfo );
|
2014-07-04 17:59:03 +02:00
|
|
|
|
2018-09-03 16:57:20 +02:00
|
|
|
OperationHelper helper( partitionModelForDevice( device ), this );
|
2014-07-29 10:57:10 +02:00
|
|
|
|
2014-07-17 15:01:45 +02:00
|
|
|
if ( partition->roles().has( PartitionRole::Extended ) )
|
|
|
|
{
|
|
|
|
// Delete all logical partitions first
|
|
|
|
// I am not sure if we can iterate on Partition::children() while
|
|
|
|
// deleting them, so let's play it safe and keep our own list.
|
|
|
|
QList< Partition* > lst;
|
|
|
|
for ( auto childPartition : partition->children() )
|
2019-06-13 14:41:33 +02:00
|
|
|
if ( !isPartitionFreeSpace( childPartition ) )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2014-07-17 15:01:45 +02:00
|
|
|
lst << childPartition;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-07-17 15:01:45 +02:00
|
|
|
|
2017-09-21 10:04:01 +02:00
|
|
|
for ( auto childPartition : lst )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2017-09-21 10:04:01 +02:00
|
|
|
deletePartition( device, childPartition );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-07-17 15:01:45 +02:00
|
|
|
}
|
2014-07-11 15:58:12 +02:00
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
if ( partition->state() == KPM_PARTITION_STATE( New ) )
|
2014-07-02 15:49:35 +02:00
|
|
|
{
|
2020-09-21 16:36:43 +02:00
|
|
|
// Take all the SetPartFlagsJob from the list and delete them
|
|
|
|
do
|
2016-03-08 16:25:43 +01:00
|
|
|
{
|
2020-09-21 16:36:43 +02:00
|
|
|
auto job_ptr = deviceInfo->takeJob< SetPartFlagsJob >( partition );
|
|
|
|
if ( job_ptr.data() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2020-09-21 16:36:43 +02:00
|
|
|
continue;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2020-09-21 16:36:43 +02:00
|
|
|
} while ( false );
|
|
|
|
|
2016-03-08 16:25:43 +01:00
|
|
|
|
2014-07-02 15:49:35 +02:00
|
|
|
// Find matching CreatePartitionJob
|
2020-09-21 16:36:43 +02:00
|
|
|
auto job_ptr = deviceInfo->takeJob< CreatePartitionJob >( partition );
|
|
|
|
if ( !job_ptr.data() )
|
2014-07-02 15:49:35 +02:00
|
|
|
{
|
|
|
|
cDebug() << "Failed to find a CreatePartitionJob matching the partition to remove";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Remove it
|
2020-02-14 11:15:57 +01:00
|
|
|
if ( !partition->parent()->remove( partition ) )
|
2014-07-02 15:49:35 +02:00
|
|
|
{
|
|
|
|
cDebug() << "Failed to remove partition from preview";
|
|
|
|
return;
|
|
|
|
}
|
2016-03-08 16:25:43 +01:00
|
|
|
|
2014-07-02 15:49:35 +02:00
|
|
|
device->partitionTable()->updateUnallocated( *device );
|
|
|
|
// The partition is no longer referenced by either a job or the device
|
|
|
|
// partition list, so we have to delete it
|
|
|
|
delete partition;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-18 14:29:27 +02:00
|
|
|
// Remove any PartitionJob on this partition
|
2020-09-21 16:36:43 +02:00
|
|
|
do
|
2014-07-18 14:29:27 +02:00
|
|
|
{
|
2020-09-21 16:36:43 +02:00
|
|
|
auto job_ptr = deviceInfo->takeJob< PartitionJob >( partition );
|
|
|
|
if ( job_ptr.data() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2020-09-21 16:36:43 +02:00
|
|
|
continue;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2020-09-21 16:36:43 +02:00
|
|
|
} while ( false );
|
2020-08-04 16:53:29 +02:00
|
|
|
|
|
|
|
deviceInfo->makeJob< DeletePartitionJob >( partition );
|
2014-07-02 15:49:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-17 14:59:59 +02:00
|
|
|
void
|
|
|
|
PartitionCoreModule::formatPartition( Device* device, Partition* partition )
|
|
|
|
{
|
2020-08-03 13:41:34 +02:00
|
|
|
auto* deviceInfo = infoForDevice( device );
|
2014-07-18 15:06:56 +02:00
|
|
|
Q_ASSERT( deviceInfo );
|
2018-09-03 16:57:20 +02:00
|
|
|
OperationHelper helper( partitionModelForDevice( device ), this );
|
2020-08-04 16:53:29 +02:00
|
|
|
deviceInfo->makeJob< FormatPartitionJob >( partition );
|
2014-07-17 14:59:59 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:04:23 +02:00
|
|
|
void
|
2021-03-27 15:43:32 +01:00
|
|
|
PartitionCoreModule::setFilesystemLabel( Device* device, Partition* partition, const QString& newLabel )
|
|
|
|
{
|
2016-07-23 20:04:23 +02:00
|
|
|
auto deviceInfo = infoForDevice( device );
|
|
|
|
Q_ASSERT( deviceInfo );
|
|
|
|
|
|
|
|
OperationHelper helper( partitionModelForDevice( device ), this );
|
|
|
|
deviceInfo->makeJob< ChangeFilesystemLabelJob >( partition, newLabel );
|
|
|
|
}
|
|
|
|
|
2014-08-05 14:57:00 +02:00
|
|
|
void
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::resizePartition( Device* device, Partition* partition, qint64 first, qint64 last )
|
2014-08-05 14:57:00 +02:00
|
|
|
{
|
2020-08-03 13:41:34 +02:00
|
|
|
auto* deviceInfo = infoForDevice( device );
|
2014-08-05 14:57:00 +02:00
|
|
|
Q_ASSERT( deviceInfo );
|
2018-09-03 16:57:20 +02:00
|
|
|
OperationHelper helper( partitionModelForDevice( device ), this );
|
2020-08-04 16:53:29 +02:00
|
|
|
deviceInfo->makeJob< ResizePartitionJob >( partition, first, last );
|
2014-08-05 14:57:00 +02:00
|
|
|
}
|
|
|
|
|
2016-03-04 19:12:17 +01:00
|
|
|
void
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::setPartitionFlags( Device* device, Partition* partition, PartitionTable::Flags flags )
|
2016-03-04 19:12:17 +01:00
|
|
|
{
|
2020-08-03 13:41:34 +02:00
|
|
|
auto* deviceInfo = infoForDevice( device );
|
2016-03-04 19:12:17 +01:00
|
|
|
Q_ASSERT( deviceInfo );
|
2018-09-03 16:57:20 +02:00
|
|
|
OperationHelper( partitionModelForDevice( device ), this );
|
2020-08-04 16:53:29 +02:00
|
|
|
deviceInfo->makeJob< SetPartFlagsJob >( partition, flags );
|
2018-05-16 13:13:35 +02:00
|
|
|
PartitionInfo::setFlags( partition, flags );
|
2016-03-04 19:12:17 +01:00
|
|
|
}
|
|
|
|
|
2019-05-28 16:39:00 +02:00
|
|
|
Calamares::JobList
|
2020-10-02 12:08:42 +02:00
|
|
|
PartitionCoreModule::jobs( const Config* config ) const
|
2014-07-11 15:58:12 +02:00
|
|
|
{
|
2019-05-28 16:39:00 +02:00
|
|
|
Calamares::JobList lst;
|
2014-07-22 17:32:26 +02:00
|
|
|
QList< Device* > devices;
|
2014-11-28 15:51:59 +01:00
|
|
|
|
2019-03-17 18:32:18 +01:00
|
|
|
#ifdef DEBUG_PARTITION_UNSAFE
|
|
|
|
#ifdef DEBUG_PARTITION_LAME
|
|
|
|
cDebug() << "Unsafe partitioning is enabled.";
|
2019-04-15 14:59:12 +02:00
|
|
|
cDebug() << Logger::SubEntry << "it has been lamed, and will fail.";
|
2019-03-17 18:32:18 +01:00
|
|
|
lst << Calamares::job_ptr( new Calamares::FailJob( QStringLiteral( "Partition" ) ) );
|
|
|
|
#else
|
|
|
|
cWarning() << "Unsafe partitioning is enabled.";
|
2019-04-15 14:59:12 +02:00
|
|
|
cWarning() << Logger::SubEntry << "the unsafe actions will be executed.";
|
2019-03-17 18:32:18 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2021-02-03 01:31:37 +01:00
|
|
|
// The automountControl job goes in the list twice: the first
|
|
|
|
// time it runs, it disables automount and remembers the old setting
|
|
|
|
// for automount; the second time it restores that old setting.
|
|
|
|
Calamares::job_ptr automountControl( new AutoMountManagementJob( true /* disable automount */ ) );
|
|
|
|
lst << automountControl;
|
2015-02-27 19:07:17 +01:00
|
|
|
lst << Calamares::job_ptr( new ClearTempMountsJob() );
|
|
|
|
|
2014-11-28 15:51:59 +01:00
|
|
|
for ( auto info : m_deviceInfos )
|
|
|
|
{
|
2015-02-18 17:41:01 +01:00
|
|
|
if ( info->isDirty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2015-02-18 17:41:01 +01:00
|
|
|
lst << Calamares::job_ptr( new ClearMountsJob( info->device.data() ) );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-11-28 15:51:59 +01:00
|
|
|
}
|
|
|
|
|
2014-07-11 15:58:12 +02:00
|
|
|
for ( auto info : m_deviceInfos )
|
2014-07-22 17:32:26 +02:00
|
|
|
{
|
2020-08-04 16:53:29 +02:00
|
|
|
lst << info->jobs();
|
2014-07-22 17:32:26 +02:00
|
|
|
devices << info->device.data();
|
|
|
|
}
|
2020-10-02 12:08:42 +02:00
|
|
|
lst << Calamares::job_ptr( new FillGlobalStorageJob( config, devices, m_bootLoaderInstallPath ) );
|
2021-02-03 01:31:37 +01:00
|
|
|
lst << automountControl;
|
2014-11-28 15:51:59 +01:00
|
|
|
|
2014-07-11 15:58:12 +02:00
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:32:59 +02:00
|
|
|
bool
|
|
|
|
PartitionCoreModule::hasRootMountPoint() const
|
|
|
|
{
|
|
|
|
return m_hasRootMountPoint;
|
|
|
|
}
|
|
|
|
|
2015-05-28 19:08:53 +02:00
|
|
|
QList< Partition* >
|
|
|
|
PartitionCoreModule::efiSystemPartitions() const
|
|
|
|
{
|
|
|
|
return m_efiSystemPartitions;
|
|
|
|
}
|
|
|
|
|
2018-06-07 22:22:22 +02:00
|
|
|
QVector< const Partition* >
|
2018-06-04 21:31:58 +02:00
|
|
|
PartitionCoreModule::lvmPVs() const
|
|
|
|
{
|
|
|
|
return m_lvmPVs;
|
|
|
|
}
|
|
|
|
|
2018-06-07 22:22:22 +02:00
|
|
|
bool
|
|
|
|
PartitionCoreModule::hasVGwithThisName( const QString& name ) const
|
|
|
|
{
|
2020-10-12 14:27:01 +02:00
|
|
|
auto condition = [name]( DeviceInfo* d ) {
|
2020-02-14 11:15:57 +01:00
|
|
|
return dynamic_cast< LvmDevice* >( d->device.data() ) && d->device.data()->name() == name;
|
2019-04-10 07:14:34 +02:00
|
|
|
};
|
2018-06-07 22:22:22 +02:00
|
|
|
|
2019-04-10 07:14:34 +02:00
|
|
|
return std::find_if( m_deviceInfos.begin(), m_deviceInfos.end(), condition ) != m_deviceInfos.end();
|
2018-06-07 22:22:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::isInVG( const Partition* partition ) const
|
2018-06-07 22:22:22 +02:00
|
|
|
{
|
2020-10-12 14:27:01 +02:00
|
|
|
auto condition = [partition]( DeviceInfo* d ) {
|
2020-02-14 11:15:57 +01:00
|
|
|
LvmDevice* vg = dynamic_cast< LvmDevice* >( d->device.data() );
|
2019-04-10 07:14:34 +02:00
|
|
|
return vg && vg->physicalVolumes().contains( partition );
|
|
|
|
};
|
2018-06-07 22:22:22 +02:00
|
|
|
|
2019-04-10 07:14:34 +02:00
|
|
|
return std::find_if( m_deviceInfos.begin(), m_deviceInfos.end(), condition ) != m_deviceInfos.end();
|
2018-06-07 22:22:22 +02:00
|
|
|
}
|
|
|
|
|
2014-07-02 15:49:35 +02:00
|
|
|
void
|
|
|
|
PartitionCoreModule::dumpQueue() const
|
|
|
|
{
|
2014-07-16 11:15:22 +02:00
|
|
|
cDebug() << "# Queue:";
|
2014-07-11 15:58:12 +02:00
|
|
|
for ( auto info : m_deviceInfos )
|
2014-07-02 15:49:35 +02:00
|
|
|
{
|
2021-03-29 14:17:40 +02:00
|
|
|
cDebug() << Logger::SubEntry << "## Device:" << info->device->name();
|
2020-08-04 16:53:29 +02:00
|
|
|
for ( const auto& job : info->jobs() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2021-03-29 14:17:40 +02:00
|
|
|
cDebug() << Logger::SubEntry << "-" << job->prettyName();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-07-02 15:49:35 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-10 18:55:19 +02:00
|
|
|
|
2015-12-15 14:00:34 +01:00
|
|
|
|
2016-09-01 14:21:05 +02:00
|
|
|
const OsproberEntryList
|
2015-12-15 14:00:34 +01:00
|
|
|
PartitionCoreModule::osproberEntries() const
|
|
|
|
{
|
|
|
|
return m_osproberLines;
|
|
|
|
}
|
|
|
|
|
2014-07-10 18:55:19 +02:00
|
|
|
void
|
2017-09-21 10:04:01 +02:00
|
|
|
PartitionCoreModule::refreshPartition( Device* device, Partition* )
|
2014-07-10 18:55:19 +02:00
|
|
|
{
|
2014-07-29 10:57:10 +02:00
|
|
|
// Keep it simple for now: reset the model. This can be improved to cause
|
|
|
|
// the model to emit dataChanged() for the affected row instead, avoiding
|
|
|
|
// the loss of the current selection.
|
2014-07-11 15:58:12 +02:00
|
|
|
auto model = partitionModelForDevice( device );
|
2014-07-10 18:55:19 +02:00
|
|
|
Q_ASSERT( model );
|
2018-09-03 16:57:20 +02:00
|
|
|
OperationHelper helper( model, this );
|
2014-07-29 10:57:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-09-03 16:57:20 +02:00
|
|
|
PartitionCoreModule::refreshAfterModelChange()
|
2014-07-29 10:57:10 +02:00
|
|
|
{
|
2014-07-17 14:26:40 +02:00
|
|
|
updateHasRootMountPoint();
|
2014-07-24 19:28:53 +02:00
|
|
|
updateIsDirty();
|
2014-07-23 18:14:27 +02:00
|
|
|
m_bootLoaderModel->update();
|
2017-07-11 11:26:10 +02:00
|
|
|
|
2018-06-07 22:22:22 +02:00
|
|
|
scanForLVMPVs();
|
|
|
|
|
2017-07-11 11:26:10 +02:00
|
|
|
//FIXME: this should be removed in favor of
|
|
|
|
// proper KPM support for EFI
|
2017-08-28 11:36:21 +02:00
|
|
|
if ( PartUtils::isEfiSystem() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2017-07-11 11:26:10 +02:00
|
|
|
scanForEfiSystemPartitions();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-07-10 18:55:19 +02:00
|
|
|
}
|
2014-07-10 19:01:55 +02:00
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
void
|
|
|
|
PartitionCoreModule::updateHasRootMountPoint()
|
2014-07-10 19:01:55 +02:00
|
|
|
{
|
|
|
|
bool oldValue = m_hasRootMountPoint;
|
2014-07-22 10:50:08 +02:00
|
|
|
m_hasRootMountPoint = findPartitionByMountPoint( "/" );
|
2014-07-10 19:01:55 +02:00
|
|
|
|
|
|
|
if ( oldValue != m_hasRootMountPoint )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2014-07-10 19:01:55 +02:00
|
|
|
hasRootMountPointChanged( m_hasRootMountPoint );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-07-10 19:01:55 +02:00
|
|
|
}
|
2014-07-11 15:58:12 +02:00
|
|
|
|
2014-07-24 19:28:53 +02:00
|
|
|
void
|
|
|
|
PartitionCoreModule::updateIsDirty()
|
|
|
|
{
|
|
|
|
bool oldValue = m_isDirty;
|
|
|
|
m_isDirty = false;
|
|
|
|
for ( auto info : m_deviceInfos )
|
|
|
|
if ( info->isDirty() )
|
|
|
|
{
|
|
|
|
m_isDirty = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( oldValue != m_isDirty )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2014-07-24 19:28:53 +02:00
|
|
|
isDirtyChanged( m_isDirty );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-07-24 19:28:53 +02:00
|
|
|
}
|
|
|
|
|
2015-05-28 19:08:53 +02:00
|
|
|
void
|
|
|
|
PartitionCoreModule::scanForEfiSystemPartitions()
|
|
|
|
{
|
2020-11-04 12:32:51 +01:00
|
|
|
const bool wasEmpty = m_efiSystemPartitions.isEmpty();
|
|
|
|
|
2015-05-28 19:08:53 +02:00
|
|
|
m_efiSystemPartitions.clear();
|
|
|
|
|
|
|
|
QList< Device* > devices;
|
|
|
|
for ( int row = 0; row < deviceModel()->rowCount(); ++row )
|
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
Device* device = deviceModel()->deviceForIndex( deviceModel()->index( row ) );
|
2015-05-28 19:08:53 +02:00
|
|
|
devices.append( device );
|
|
|
|
}
|
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
QList< Partition* > efiSystemPartitions
|
|
|
|
= CalamaresUtils::Partition::findPartitions( devices, PartUtils::isEfiBootable );
|
2015-05-28 19:08:53 +02:00
|
|
|
|
|
|
|
if ( efiSystemPartitions.isEmpty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "system is EFI but no EFI system partitions found.";
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2020-11-04 12:32:51 +01:00
|
|
|
else if ( wasEmpty )
|
|
|
|
{
|
|
|
|
// But it isn't empty anymore, so whatever problem has been solved
|
|
|
|
cDebug() << "system is EFI and new EFI system partition has been found.";
|
|
|
|
}
|
2015-05-28 19:08:53 +02:00
|
|
|
|
|
|
|
m_efiSystemPartitions = efiSystemPartitions;
|
|
|
|
}
|
|
|
|
|
2018-06-04 21:31:58 +02:00
|
|
|
void
|
|
|
|
PartitionCoreModule::scanForLVMPVs()
|
|
|
|
{
|
|
|
|
m_lvmPVs.clear();
|
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
QList< Device* > physicalDevices;
|
|
|
|
QList< LvmDevice* > vgDevices;
|
2018-06-04 21:31:58 +02:00
|
|
|
|
|
|
|
for ( DeviceInfo* deviceInfo : m_deviceInfos )
|
2018-06-26 05:38:52 +02:00
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
if ( deviceInfo->device.data()->type() == Device::Type::Disk_Device )
|
|
|
|
{
|
2018-06-26 05:38:52 +02:00
|
|
|
physicalDevices << deviceInfo->device.data();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-06-26 05:38:52 +02:00
|
|
|
else if ( deviceInfo->device.data()->type() == Device::Type::LVM_Device )
|
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
LvmDevice* device = dynamic_cast< LvmDevice* >( deviceInfo->device.data() );
|
2018-06-26 05:38:52 +02:00
|
|
|
|
|
|
|
// Restoring physical volume list
|
|
|
|
device->physicalVolumes().clear();
|
|
|
|
|
|
|
|
vgDevices << device;
|
|
|
|
}
|
|
|
|
}
|
2018-06-04 21:31:58 +02:00
|
|
|
|
2019-04-12 12:54:13 +02:00
|
|
|
#if defined( WITH_KPMCORE4API )
|
2019-04-10 07:12:31 +02:00
|
|
|
VolumeManagerDevice::scanDevices( physicalDevices );
|
2019-04-12 12:54:13 +02:00
|
|
|
for ( auto p : LVM::pvList::list() )
|
2018-08-12 15:26:43 +02:00
|
|
|
#else
|
2019-04-10 07:12:31 +02:00
|
|
|
LvmDevice::scanSystemLVM( physicalDevices );
|
2018-06-04 21:31:58 +02:00
|
|
|
for ( auto p : LVM::pvList )
|
2018-08-12 15:26:43 +02:00
|
|
|
#endif
|
2018-06-26 05:38:52 +02:00
|
|
|
{
|
2018-06-04 21:31:58 +02:00
|
|
|
m_lvmPVs << p.partition().data();
|
2018-06-08 23:52:53 +02:00
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
for ( LvmDevice* device : vgDevices )
|
|
|
|
if ( p.vgName() == device->name() )
|
|
|
|
{
|
|
|
|
// Adding scanned VG to PV list
|
|
|
|
device->physicalVolumes() << p.partition();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-08 23:52:53 +02:00
|
|
|
for ( DeviceInfo* d : m_deviceInfos )
|
|
|
|
{
|
2020-08-04 16:53:29 +02:00
|
|
|
for ( const auto& job : d->jobs() )
|
2018-06-08 23:52:53 +02:00
|
|
|
{
|
|
|
|
// Including new LVM PVs
|
2020-02-14 11:15:57 +01:00
|
|
|
CreatePartitionJob* partJob = dynamic_cast< CreatePartitionJob* >( job.data() );
|
2018-06-08 23:52:53 +02:00
|
|
|
if ( partJob )
|
|
|
|
{
|
|
|
|
Partition* p = partJob->partition();
|
|
|
|
|
|
|
|
if ( p->fileSystem().type() == FileSystem::Type::Lvm2_PV )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-06-08 23:52:53 +02:00
|
|
|
m_lvmPVs << p;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-06-14 20:37:00 +02:00
|
|
|
else if ( p->fileSystem().type() == FileSystem::Type::Luks )
|
2018-06-08 23:52:53 +02:00
|
|
|
{
|
|
|
|
// Encrypted LVM PVs
|
2020-02-14 11:15:57 +01:00
|
|
|
FileSystem* innerFS = static_cast< const FS::luks* >( &p->fileSystem() )->innerFS();
|
2018-06-08 23:52:53 +02:00
|
|
|
|
|
|
|
if ( innerFS && innerFS->type() == FileSystem::Type::Lvm2_PV )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-06-08 23:52:53 +02:00
|
|
|
m_lvmPVs << p;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-06-08 23:52:53 +02:00
|
|
|
}
|
2019-06-13 14:10:49 +02:00
|
|
|
#if defined( WITH_KPMCORE4API )
|
2018-06-14 20:37:00 +02:00
|
|
|
else if ( p->fileSystem().type() == FileSystem::Type::Luks2 )
|
|
|
|
{
|
|
|
|
// Encrypted LVM PVs
|
2020-02-14 11:15:57 +01:00
|
|
|
FileSystem* innerFS = static_cast< const FS::luks* >( &p->fileSystem() )->innerFS();
|
2018-06-14 20:37:00 +02:00
|
|
|
|
|
|
|
if ( innerFS && innerFS->type() == FileSystem::Type::Lvm2_PV )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-06-14 20:37:00 +02:00
|
|
|
m_lvmPVs << p;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-06-14 20:37:00 +02:00
|
|
|
}
|
|
|
|
#endif
|
2018-06-08 23:52:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-04 21:31:58 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 15:58:12 +02:00
|
|
|
PartitionCoreModule::DeviceInfo*
|
2016-09-09 11:25:04 +02:00
|
|
|
PartitionCoreModule::infoForDevice( const Device* device ) const
|
2014-07-11 15:58:12 +02:00
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
for ( auto it = m_deviceInfos.constBegin(); it != m_deviceInfos.constEnd(); ++it )
|
2014-07-11 15:58:12 +02:00
|
|
|
{
|
2016-09-09 11:25:04 +02:00
|
|
|
if ( ( *it )->device.data() == device )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2016-09-09 11:25:04 +02:00
|
|
|
return *it;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2016-09-09 11:25:04 +02:00
|
|
|
if ( ( *it )->immutableDevice.data() == device )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2016-09-09 11:25:04 +02:00
|
|
|
return *it;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-07-11 15:58:12 +02:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-07-22 10:42:50 +02:00
|
|
|
|
|
|
|
Partition*
|
|
|
|
PartitionCoreModule::findPartitionByMountPoint( const QString& mountPoint ) const
|
|
|
|
{
|
|
|
|
for ( auto deviceInfo : m_deviceInfos )
|
|
|
|
{
|
|
|
|
Device* device = deviceInfo->device.data();
|
|
|
|
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
|
|
|
if ( PartitionInfo::mountPoint( *it ) == mountPoint )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2014-07-22 10:42:50 +02:00
|
|
|
return *it;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-07-22 10:42:50 +02:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-07-23 18:15:46 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
PartitionCoreModule::setBootLoaderInstallPath( const QString& path )
|
|
|
|
{
|
2016-12-02 18:36:02 +01:00
|
|
|
cDebug() << "PCM::setBootLoaderInstallPath" << path;
|
2014-07-23 18:15:46 +02:00
|
|
|
m_bootLoaderInstallPath = path;
|
|
|
|
}
|
2014-07-24 19:28:53 +02:00
|
|
|
|
2019-01-07 17:25:39 +01:00
|
|
|
void
|
2020-11-02 21:35:43 +01:00
|
|
|
PartitionCoreModule::initLayout( FileSystem::Type defaultFsType, const QVariantList& config )
|
2019-01-07 17:25:39 +01:00
|
|
|
{
|
2020-11-02 21:35:43 +01:00
|
|
|
m_partLayout.init( defaultFsType, config );
|
2019-01-07 17:25:39 +01:00
|
|
|
}
|
|
|
|
|
2019-01-07 17:26:37 +01:00
|
|
|
void
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::layoutApply( Device* dev,
|
2019-01-07 17:26:37 +01:00
|
|
|
qint64 firstSector,
|
|
|
|
qint64 lastSector,
|
2019-01-07 17:27:12 +01:00
|
|
|
QString luksPassphrase,
|
|
|
|
PartitionNode* parent,
|
|
|
|
const PartitionRole& role )
|
2019-01-07 17:26:37 +01:00
|
|
|
{
|
|
|
|
bool isEfi = PartUtils::isEfiSystem();
|
2020-11-02 21:35:43 +01:00
|
|
|
QList< Partition* > partList
|
|
|
|
= m_partLayout.createPartitions( dev, firstSector, lastSector, luksPassphrase, parent, role );
|
2019-01-07 17:26:37 +01:00
|
|
|
|
2020-04-07 21:26:54 +02:00
|
|
|
// Partition::mountPoint() tells us where it is mounted **now**, while
|
|
|
|
// PartitionInfo::mountPoint() says where it will be mounted in the target system.
|
|
|
|
// .. the latter is more interesting.
|
|
|
|
//
|
|
|
|
// If we have a separate /boot, mark that one as bootable, otherwise mark
|
|
|
|
// the root / as bootable.
|
|
|
|
//
|
|
|
|
// TODO: perhaps the partition that holds the bootloader?
|
|
|
|
const QString boot = QStringLiteral( "/boot" );
|
|
|
|
const QString root = QStringLiteral( "/" );
|
2020-04-07 21:38:15 +02:00
|
|
|
const auto is_boot
|
2020-10-12 14:27:01 +02:00
|
|
|
= [&]( Partition* p ) -> bool { return PartitionInfo::mountPoint( p ) == boot || p->mountPoint() == boot; };
|
2020-04-07 21:38:15 +02:00
|
|
|
const auto is_root
|
2020-10-12 14:27:01 +02:00
|
|
|
= [&]( Partition* p ) -> bool { return PartitionInfo::mountPoint( p ) == root || p->mountPoint() == root; };
|
2020-04-07 21:38:15 +02:00
|
|
|
|
|
|
|
const bool separate_boot_partition
|
|
|
|
= std::find_if( partList.constBegin(), partList.constEnd(), is_boot ) != partList.constEnd();
|
|
|
|
for ( Partition* part : partList )
|
2019-01-07 17:26:37 +01:00
|
|
|
{
|
2016-07-21 14:33:35 +02:00
|
|
|
if ( is_boot( part ) )
|
|
|
|
{
|
|
|
|
part->setLabel( "boot" );
|
|
|
|
}
|
|
|
|
if ( is_root( part ) )
|
|
|
|
{
|
|
|
|
part->setLabel( "root" );
|
|
|
|
}
|
2020-04-07 21:38:15 +02:00
|
|
|
if ( ( separate_boot_partition && is_boot( part ) ) || ( !separate_boot_partition && is_root( part ) ) )
|
2019-01-07 17:26:37 +01:00
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
createPartition(
|
|
|
|
dev, part, part->activeFlags() | ( isEfi ? KPM_PARTITION_FLAG( None ) : KPM_PARTITION_FLAG( Boot ) ) );
|
2019-01-07 17:26:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
createPartition( dev, part );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 17:27:12 +01:00
|
|
|
void
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::layoutApply( Device* dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase )
|
2019-01-07 17:27:12 +01:00
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
layoutApply(
|
|
|
|
dev, firstSector, lastSector, luksPassphrase, dev->partitionTable(), PartitionRole( PartitionRole::Primary ) );
|
2019-01-07 17:27:12 +01:00
|
|
|
}
|
|
|
|
|
2014-07-24 19:28:53 +02:00
|
|
|
void
|
|
|
|
PartitionCoreModule::revert()
|
|
|
|
{
|
2015-12-30 16:37:04 +01:00
|
|
|
QMutexLocker locker( &m_revertMutex );
|
2014-07-24 19:28:53 +02:00
|
|
|
qDeleteAll( m_deviceInfos );
|
|
|
|
m_deviceInfos.clear();
|
2016-07-19 13:00:54 +02:00
|
|
|
doInit();
|
2014-07-24 19:28:53 +02:00
|
|
|
updateIsDirty();
|
2015-10-30 17:28:31 +01:00
|
|
|
emit reverted();
|
2014-07-24 19:28:53 +02:00
|
|
|
}
|
2014-07-30 14:15:29 +02:00
|
|
|
|
2014-09-04 19:35:44 +02:00
|
|
|
|
2015-12-30 16:37:04 +01:00
|
|
|
void
|
|
|
|
PartitionCoreModule::revertAllDevices()
|
|
|
|
{
|
2018-06-09 01:20:05 +02:00
|
|
|
for ( auto it = m_deviceInfos.begin(); it != m_deviceInfos.end(); )
|
|
|
|
{
|
|
|
|
// In new VGs device info, there will be always a CreateVolumeGroupJob as the first job in jobs list
|
2020-02-14 11:15:57 +01:00
|
|
|
if ( dynamic_cast< LvmDevice* >( ( *it )->device.data() ) )
|
2018-06-09 01:20:05 +02:00
|
|
|
{
|
2018-06-26 05:38:52 +02:00
|
|
|
( *it )->isAvailable = true;
|
2018-06-09 01:20:05 +02:00
|
|
|
|
2020-08-04 16:53:29 +02:00
|
|
|
if ( !( *it )->jobs().empty() )
|
2018-06-09 01:20:05 +02:00
|
|
|
{
|
2020-08-04 16:53:29 +02:00
|
|
|
CreateVolumeGroupJob* vgJob = dynamic_cast< CreateVolumeGroupJob* >( ( *it )->jobs().first().data() );
|
2018-06-26 05:38:52 +02:00
|
|
|
|
|
|
|
if ( vgJob )
|
|
|
|
{
|
|
|
|
vgJob->undoPreview();
|
2018-06-09 01:20:05 +02:00
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
( *it )->forgetChanges();
|
2018-06-09 01:20:05 +02:00
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
m_deviceModel->removeDevice( ( *it )->device.data() );
|
2018-06-09 01:20:05 +02:00
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
it = m_deviceInfos.erase( it );
|
2018-06-09 01:20:05 +02:00
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
continue;
|
|
|
|
}
|
2018-06-09 01:20:05 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-11 23:38:57 +02:00
|
|
|
|
2019-02-12 01:03:09 +01:00
|
|
|
revertDevice( ( *it )->device.data(), false );
|
2018-06-11 23:38:57 +02:00
|
|
|
++it;
|
2018-06-09 01:20:05 +02:00
|
|
|
}
|
|
|
|
|
2018-09-03 16:57:20 +02:00
|
|
|
refreshAfterModelChange();
|
2015-12-30 16:37:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-17 18:00:00 +01:00
|
|
|
void
|
2019-02-12 01:03:09 +01:00
|
|
|
PartitionCoreModule::revertDevice( Device* dev, bool individualRevert )
|
2015-12-17 18:00:00 +01:00
|
|
|
{
|
2015-12-23 19:14:33 +01:00
|
|
|
QMutexLocker locker( &m_revertMutex );
|
2015-12-17 18:00:00 +01:00
|
|
|
DeviceInfo* devInfo = infoForDevice( dev );
|
2018-06-09 01:20:05 +02:00
|
|
|
|
2015-12-17 18:00:00 +01:00
|
|
|
if ( !devInfo )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2015-12-17 18:00:00 +01:00
|
|
|
return;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2015-12-17 18:00:00 +01:00
|
|
|
devInfo->forgetChanges();
|
|
|
|
CoreBackend* backend = CoreBackendManager::self()->backend();
|
2017-07-11 11:26:10 +02:00
|
|
|
Device* newDev = backend->scanDevice( devInfo->device->deviceNode() );
|
2015-12-17 18:00:00 +01:00
|
|
|
devInfo->device.reset( newDev );
|
2015-12-17 18:37:53 +01:00
|
|
|
devInfo->partitionModel->init( newDev, m_osproberLines );
|
|
|
|
|
2015-12-17 18:00:00 +01:00
|
|
|
m_deviceModel->swapDevice( dev, newDev );
|
|
|
|
|
|
|
|
QList< Device* > devices;
|
2019-05-03 14:47:34 +02:00
|
|
|
for ( DeviceInfo* const info : m_deviceInfos )
|
2018-06-26 05:38:52 +02:00
|
|
|
{
|
2019-05-31 11:37:14 +02:00
|
|
|
if ( info && !info->device.isNull() && info->device->type() == Device::Type::Disk_Device )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-06-26 05:38:52 +02:00
|
|
|
devices.append( info->device.data() );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-06-26 05:38:52 +02:00
|
|
|
}
|
2015-12-17 18:00:00 +01:00
|
|
|
|
|
|
|
m_bootLoaderModel->init( devices );
|
|
|
|
|
2019-02-12 01:03:09 +01:00
|
|
|
if ( individualRevert )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2019-02-12 01:03:09 +01:00
|
|
|
refreshAfterModelChange();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2016-01-05 18:44:05 +01:00
|
|
|
emit deviceReverted( newDev );
|
2015-12-17 18:00:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-23 19:14:33 +01:00
|
|
|
void
|
|
|
|
PartitionCoreModule::asyncRevertDevice( Device* dev, std::function< void() > callback )
|
|
|
|
{
|
2015-12-24 12:09:47 +01:00
|
|
|
QFutureWatcher< void >* watcher = new QFutureWatcher< void >();
|
2020-10-12 14:27:01 +02:00
|
|
|
connect( watcher, &QFutureWatcher< void >::finished, this, [watcher, callback] {
|
2015-12-24 12:09:47 +01:00
|
|
|
callback();
|
|
|
|
watcher->deleteLater();
|
2015-12-23 19:21:08 +01:00
|
|
|
} );
|
2015-12-24 12:09:47 +01:00
|
|
|
|
2019-02-12 01:03:09 +01:00
|
|
|
QFuture< void > future = QtConcurrent::run( this, &PartitionCoreModule::revertDevice, dev, true );
|
2015-12-24 12:09:47 +01:00
|
|
|
watcher->setFuture( future );
|
2015-12-23 19:14:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-16 18:11:19 +02:00
|
|
|
void
|
|
|
|
PartitionCoreModule::clearJobs()
|
|
|
|
{
|
|
|
|
foreach ( DeviceInfo* deviceInfo, m_deviceInfos )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2014-09-16 18:11:19 +02:00
|
|
|
deviceInfo->forgetChanges();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-09-16 18:11:19 +02:00
|
|
|
updateIsDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-04 19:35:44 +02:00
|
|
|
bool
|
|
|
|
PartitionCoreModule::isDirty()
|
|
|
|
{
|
|
|
|
return m_isDirty;
|
|
|
|
}
|
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
bool
|
2020-02-14 11:15:57 +01:00
|
|
|
PartitionCoreModule::isVGdeactivated( LvmDevice* device )
|
2018-06-26 05:38:52 +02:00
|
|
|
{
|
|
|
|
for ( DeviceInfo* deviceInfo : m_deviceInfos )
|
|
|
|
if ( device == deviceInfo->device.data() && !deviceInfo->isAvailable )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-06-26 05:38:52 +02:00
|
|
|
return true;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-06-26 05:38:52 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-30 14:15:29 +02:00
|
|
|
QList< PartitionCoreModule::SummaryInfo >
|
|
|
|
PartitionCoreModule::createSummaryInfo() const
|
|
|
|
{
|
|
|
|
QList< SummaryInfo > lst;
|
|
|
|
for ( auto deviceInfo : m_deviceInfos )
|
|
|
|
{
|
|
|
|
if ( !deviceInfo->isDirty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2014-07-30 14:15:29 +02:00
|
|
|
continue;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2014-07-30 14:15:29 +02:00
|
|
|
SummaryInfo summaryInfo;
|
|
|
|
summaryInfo.deviceName = deviceInfo->device->name();
|
2015-04-09 17:47:23 +02:00
|
|
|
summaryInfo.deviceNode = deviceInfo->device->deviceNode();
|
2014-07-30 14:15:29 +02:00
|
|
|
|
2016-09-11 10:56:06 +02:00
|
|
|
Device* deviceBefore = deviceInfo->immutableDevice.data();
|
2014-07-30 14:15:29 +02:00
|
|
|
summaryInfo.partitionModelBefore = new PartitionModel;
|
2015-12-15 14:00:34 +01:00
|
|
|
summaryInfo.partitionModelBefore->init( deviceBefore, m_osproberLines );
|
2014-07-30 14:15:29 +02:00
|
|
|
// Make deviceBefore a child of partitionModelBefore so that it is not
|
|
|
|
// leaked (as long as partitionModelBefore is deleted)
|
|
|
|
deviceBefore->setParent( summaryInfo.partitionModelBefore );
|
|
|
|
|
|
|
|
summaryInfo.partitionModelAfter = new PartitionModel;
|
2015-12-15 14:00:34 +01:00
|
|
|
summaryInfo.partitionModelAfter->init( deviceInfo->device.data(), m_osproberLines );
|
2014-07-30 14:15:29 +02:00
|
|
|
|
|
|
|
lst << summaryInfo;
|
|
|
|
}
|
|
|
|
return lst;
|
|
|
|
}
|