2016-07-23 20:04:23 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
|
|
|
*
|
|
|
|
* SPDX-FileCopyrightText: 2016, Lisa Vitolo <shainer@chakraos.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ChangeFilesystemLabelJob.h"
|
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
|
|
|
#include <kpmcore/backend/corebackend.h>
|
|
|
|
#include <kpmcore/backend/corebackendmanager.h>
|
|
|
|
#include <kpmcore/core/device.h>
|
2021-03-27 15:43:32 +01:00
|
|
|
#include <kpmcore/core/partition.h>
|
2016-07-23 20:04:23 +02:00
|
|
|
#include <kpmcore/util/report.h>
|
|
|
|
|
2021-03-28 17:56:54 +02:00
|
|
|
#ifndef WITH_KPMCORE42API
|
|
|
|
#include <kpmcore/backend/corebackenddevice.h>
|
|
|
|
#include <kpmcore/backend/corebackendpartition.h>
|
|
|
|
#include <kpmcore/backend/corebackendpartitiontable.h>
|
|
|
|
#endif
|
|
|
|
|
2021-03-27 15:43:32 +01:00
|
|
|
ChangeFilesystemLabelJob::ChangeFilesystemLabelJob( Device* device, Partition* partition, const QString& newLabel )
|
2016-07-23 20:04:23 +02:00
|
|
|
: PartitionJob( partition )
|
|
|
|
, m_device( device )
|
|
|
|
, m_label( newLabel )
|
2021-03-27 15:43:32 +01:00
|
|
|
{
|
|
|
|
}
|
2016-07-23 20:04:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
ChangeFilesystemLabelJob::prettyName() const
|
|
|
|
{
|
|
|
|
return tr( "Set filesystem label on %1." ).arg( partition()->partitionPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
ChangeFilesystemLabelJob::prettyDescription() const
|
|
|
|
{
|
|
|
|
return tr( "Set filesystem label <strong>%1</strong> to partition "
|
|
|
|
"<strong>%2</strong>." )
|
2021-03-27 15:43:32 +01:00
|
|
|
.arg( m_label )
|
|
|
|
.arg( partition()->partitionPath() );
|
2016-07-23 20:04:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
ChangeFilesystemLabelJob::prettyStatusMessage() const
|
|
|
|
{
|
|
|
|
return prettyDescription();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Calamares::JobResult
|
|
|
|
ChangeFilesystemLabelJob::exec()
|
|
|
|
{
|
2021-03-27 15:43:32 +01:00
|
|
|
if ( m_label == partition()->fileSystem().label() )
|
|
|
|
{
|
2016-07-23 20:04:23 +02:00
|
|
|
return Calamares::JobResult::ok();
|
|
|
|
}
|
|
|
|
|
2016-08-13 13:14:48 +02:00
|
|
|
Report report( nullptr );
|
2016-07-23 20:04:23 +02:00
|
|
|
CoreBackend* backend = CoreBackendManager::self()->backend();
|
|
|
|
|
|
|
|
QScopedPointer< CoreBackendDevice > backendDevice( backend->openDevice( m_device->deviceNode() ) );
|
|
|
|
if ( !backendDevice.data() )
|
|
|
|
{
|
2021-03-27 15:43:32 +01:00
|
|
|
return Calamares::JobResult::error( tr( "Could not open device '%1'." ).arg( m_device->deviceNode() ),
|
|
|
|
report.toText() );
|
2016-07-23 20:04:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QScopedPointer< CoreBackendPartitionTable > backendPartitionTable( backendDevice->openPartitionTable() );
|
|
|
|
if ( !backendPartitionTable.data() )
|
|
|
|
{
|
|
|
|
return Calamares::JobResult::error(
|
2021-03-27 15:43:32 +01:00
|
|
|
tr( "Could not open partition table on device '%1'." ).arg( m_device->deviceNode() ), report.toText() );
|
2016-07-23 20:04:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QScopedPointer< CoreBackendPartition > backendPartition(
|
2021-03-27 15:43:32 +01:00
|
|
|
( partition()->roles().has( PartitionRole::Extended ) )
|
2016-07-23 20:04:23 +02:00
|
|
|
? backendPartitionTable->getExtendedPartition()
|
2021-03-27 15:43:32 +01:00
|
|
|
: backendPartitionTable->getPartitionBySector( partition()->firstSector() ) );
|
|
|
|
if ( !backendPartition.data() )
|
|
|
|
{
|
|
|
|
return Calamares::JobResult::error( tr( "Could not find partition '%1'." ).arg( partition()->partitionPath() ),
|
|
|
|
report.toText() );
|
2016-07-23 20:04:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FileSystem& fs = m_partition->fileSystem();
|
|
|
|
fs.setLabel( m_label );
|
|
|
|
|
2016-08-13 13:14:48 +02:00
|
|
|
if ( !backendPartitionTable->setPartitionSystemType( report, *m_partition ) )
|
|
|
|
{
|
|
|
|
return Calamares::JobResult::error(
|
2021-03-27 15:43:32 +01:00
|
|
|
tr( "The installer failed to update partition table on disk '%1'." ).arg( m_device->name() ),
|
|
|
|
report.toText() );
|
2016-08-13 13:14:48 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:04:23 +02:00
|
|
|
backendPartitionTable->commit();
|
|
|
|
return Calamares::JobResult::ok();
|
|
|
|
}
|