2014-07-10 19:55:16 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
2015-04-09 15:16:09 +02:00
|
|
|
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
2017-09-19 11:11:46 +02:00
|
|
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
2014-07-10 19:55:16 +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/>.
|
|
|
|
*/
|
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "jobs/CreatePartitionTableJob.h"
|
2014-07-10 19:55:16 +02:00
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "utils/Logger.h"
|
2014-07-10 19:55:16 +02:00
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
// KPMcore
|
|
|
|
#include <kpmcore/backend/corebackend.h>
|
|
|
|
#include <kpmcore/backend/corebackendmanager.h>
|
|
|
|
#include <kpmcore/backend/corebackenddevice.h>
|
|
|
|
#include <kpmcore/backend/corebackendpartitiontable.h>
|
|
|
|
#include <kpmcore/core/device.h>
|
|
|
|
#include <kpmcore/core/partition.h>
|
|
|
|
#include <kpmcore/core/partitiontable.h>
|
|
|
|
#include <kpmcore/fs/filesystem.h>
|
|
|
|
#include <kpmcore/util/report.h>
|
2014-07-10 19:55:16 +02:00
|
|
|
|
|
|
|
// Qt
|
|
|
|
#include <QScopedPointer>
|
2015-02-05 13:23:41 +01:00
|
|
|
#include <QProcess>
|
2014-07-10 19:55:16 +02:00
|
|
|
|
2014-07-15 14:40:08 +02:00
|
|
|
CreatePartitionTableJob::CreatePartitionTableJob( Device* device, PartitionTable::TableType type )
|
2014-07-10 19:55:16 +02:00
|
|
|
: m_device( device )
|
2014-07-15 14:40:08 +02:00
|
|
|
, m_type( type )
|
2014-07-10 19:55:16 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
CreatePartitionTableJob::prettyName() const
|
|
|
|
{
|
2015-04-10 13:03:31 +02:00
|
|
|
return tr( "Create new %1 partition table on %2." )
|
|
|
|
.arg( PartitionTable::tableTypeToName( m_type ) )
|
|
|
|
.arg( m_device->deviceNode() );
|
2015-04-09 15:16:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CreatePartitionTableJob::prettyDescription() const
|
|
|
|
{
|
2015-04-10 13:03:31 +02:00
|
|
|
return tr( "Create new <strong>%1</strong> partition table on <strong>%2</strong> (%3)." )
|
|
|
|
.arg( PartitionTable::tableTypeToName( m_type ).toUpper() )
|
|
|
|
.arg( m_device->deviceNode() )
|
|
|
|
.arg( m_device->name() );
|
2014-07-10 19:55:16 +02:00
|
|
|
}
|
|
|
|
|
2015-06-13 02:26:38 +02:00
|
|
|
|
|
|
|
QString
|
|
|
|
CreatePartitionTableJob::prettyStatusMessage() const
|
|
|
|
{
|
|
|
|
return tr( "Creating new %1 partition table on %2." )
|
|
|
|
.arg( PartitionTable::tableTypeToName( m_type ).toUpper() )
|
|
|
|
.arg( m_device->deviceNode() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-10 19:55:16 +02:00
|
|
|
Calamares::JobResult
|
|
|
|
CreatePartitionTableJob::exec()
|
|
|
|
{
|
2017-09-14 12:34:07 +02:00
|
|
|
Report report( nullptr );
|
2014-07-10 19:55:16 +02:00
|
|
|
QString message = tr( "The installer failed to create a partition table on %1." ).arg( m_device->name() );
|
|
|
|
|
|
|
|
CoreBackend* backend = CoreBackendManager::self()->backend();
|
|
|
|
QScopedPointer< CoreBackendDevice > backendDevice( backend->openDevice( m_device->deviceNode() ) );
|
|
|
|
if ( !backendDevice.data() )
|
|
|
|
{
|
|
|
|
return Calamares::JobResult::error(
|
2014-07-15 11:11:17 +02:00
|
|
|
message,
|
|
|
|
tr( "Could not open device %1." ).arg( m_device->deviceNode() )
|
|
|
|
);
|
2014-07-10 19:55:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QScopedPointer< PartitionTable > table( createTable() );
|
2014-11-27 14:21:29 +01:00
|
|
|
cDebug() << "Creating new partition table of type" << table->typeName()
|
|
|
|
<< ", uncommitted yet:\n" << table;
|
|
|
|
|
2015-02-05 13:23:41 +01:00
|
|
|
QProcess lsblk;
|
|
|
|
lsblk.setProgram( "lsblk" );
|
|
|
|
lsblk.setProcessChannelMode( QProcess::MergedChannels );
|
|
|
|
lsblk.start();
|
|
|
|
lsblk.waitForFinished();
|
|
|
|
cDebug() << "lsblk:\n" << lsblk.readAllStandardOutput();
|
|
|
|
|
|
|
|
QProcess mount;
|
|
|
|
mount.setProgram( "mount" );
|
|
|
|
mount.setProcessChannelMode( QProcess::MergedChannels );
|
|
|
|
mount.start();
|
|
|
|
mount.waitForFinished();
|
|
|
|
cDebug() << "mount:\n" << mount.readAllStandardOutput();
|
|
|
|
|
2014-07-10 19:55:16 +02:00
|
|
|
bool ok = backendDevice->createPartitionTable( report, *table );
|
|
|
|
if ( !ok )
|
|
|
|
{
|
|
|
|
return Calamares::JobResult::error(
|
2014-11-23 11:46:16 +01:00
|
|
|
message,
|
|
|
|
QString( "Text: %1\nCommand: %2\nOutput: %3\nStatus: %4" )
|
|
|
|
.arg( report.toText() )
|
|
|
|
.arg( report.command() )
|
|
|
|
.arg( report.output() )
|
|
|
|
.arg( report.status() )
|
2014-07-15 11:11:17 +02:00
|
|
|
);
|
2014-07-10 19:55:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Calamares::JobResult::ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CreatePartitionTableJob::updatePreview()
|
|
|
|
{
|
|
|
|
// Device takes ownership of its table, but does not destroy the current
|
|
|
|
// one when setPartitionTable() is called, so do it ourself
|
|
|
|
delete m_device->partitionTable();
|
|
|
|
m_device->setPartitionTable( createTable() );
|
|
|
|
m_device->partitionTable()->updateUnallocated( *m_device );
|
|
|
|
}
|
|
|
|
|
|
|
|
PartitionTable*
|
|
|
|
CreatePartitionTableJob::createTable()
|
|
|
|
{
|
2014-11-27 14:21:29 +01:00
|
|
|
cDebug() << "CreatePartitionTableJob::createTable trying to make table for device"
|
|
|
|
<< m_device->deviceNode();
|
2014-07-15 14:40:08 +02:00
|
|
|
return new PartitionTable( m_type,
|
|
|
|
PartitionTable::defaultFirstUsable( *m_device, m_type ),
|
|
|
|
PartitionTable::defaultLastUsable( *m_device, m_type )
|
2014-07-15 11:11:17 +02:00
|
|
|
);
|
2014-07-10 19:55:16 +02:00
|
|
|
}
|