[partition] update to kpmcore v3.3

This commit is contained in:
Philip 2017-12-16 08:46:22 -05:00
parent 5ebd629307
commit ce1e8fa499
19 changed files with 167 additions and 313 deletions

View File

@ -12,6 +12,6 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH})
include(KDEInstallDirs) include(KDEInstallDirs)
include(GenerateExportHeader) include(GenerateExportHeader)
find_package( KF5 REQUIRED CoreAddons ) find_package( KF5 REQUIRED CoreAddons )
find_package( KF5 REQUIRED Config I18n IconThemes KIO Service ) find_package( KF5 REQUIRED Config I18n Service WidgetsAddons )
find_package( KPMcore 3.0.3 REQUIRED ) find_package( KPMcore 3.2 REQUIRED )

View File

@ -1,39 +1,11 @@
find_package(ECM 5.10.0 REQUIRED NO_MODULE) find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH})
include(KDEInstallDirs) include(KDEInstallDirs)
include(GenerateExportHeader) include(GenerateExportHeader)
find_package( KF5 REQUIRED CoreAddons ) find_package( Qt5 REQUIRED DBus )
find_package( KF5 REQUIRED Config CoreAddons I18n WidgetsAddons )
# These are needed because KPMcore links publicly against ConfigCore, I18n, IconThemes, KIOCore and Service
find_package( KF5 REQUIRED Config I18n IconThemes KIO Service )
find_package( KPMcore 3.1.50 QUIET )
if ( KPMcore_FOUND )
add_definitions(-DWITH_KPMCORE22)
endif()
find_package( KPMcore 3.0.3 QUIET )
# 3.0.3 and newer has fixes for NVMe support; allow 3.0.2, but warn
# about it .. needs to use a different feature name because it otherwise
# gets reported as KPMcore (the package).
if ( KPMcore_FOUND )
message( STATUS "KPMCore supports NVMe operations" )
add_feature_info( KPMcoreNVMe KPMcore_FOUND "KPMcore with NVMe support" )
else()
find_package( KPMcore 3.0.2 REQUIRED )
message( WARNING "KPMCore 3.0.2 is known to have bugs with NVMe devices" )
add_feature_info( KPMcoreNVMe KPMcore_FOUND "Older KPMcore with no NVMe support" )
endif()
find_library( atasmart_LIB atasmart )
find_library( blkid_LIB blkid )
if( NOT atasmart_LIB )
message( WARNING "atasmart library not found." )
endif()
if( NOT blkid_LIB )
message( WARNING "blkid library not found." )
endif()
find_package( KPMcore 3.3 REQUIRED )
include_directories( ${KPMCORE_INCLUDE_DIR} ) include_directories( ${KPMCORE_INCLUDE_DIR} )
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ) include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )

View File

@ -24,6 +24,7 @@
// KPMcore // KPMcore
#include <kpmcore/core/partition.h> #include <kpmcore/core/partition.h>
#include <kpmcore/fs/luks.h>
// Qt // Qt
#include <QColor> #include <QColor>
@ -86,9 +87,19 @@ colorForPartition( Partition* partition )
return EXTENDED_COLOR; return EXTENDED_COLOR;
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone && if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
!partition->fileSystem().uuid().isEmpty() && !partition->fileSystem().uuid().isEmpty() )
s_partitionColorsCache.contains( partition->fileSystem().uuid() ) ) {
return s_partitionColorsCache[ partition->fileSystem().uuid() ]; if ( partition->fileSystem().type() == FileSystem::Luks )
{
FS::luks& luksFs = dynamic_cast< FS::luks& >( partition->fileSystem() );
if ( !luksFs.outerUuid().isEmpty() &&
s_partitionColorsCache.contains( luksFs.outerUuid() ) )
return s_partitionColorsCache[ luksFs.outerUuid() ];
}
if ( s_partitionColorsCache.contains( partition->fileSystem().uuid() ) )
return s_partitionColorsCache[ partition->fileSystem().uuid() ];
}
// No partition-specific color needed, pick one from our list, but skip // No partition-specific color needed, pick one from our list, but skip
// free space: we don't want a partition to change colors if space before // free space: we don't want a partition to change colors if space before
@ -119,8 +130,20 @@ colorForPartition( Partition* partition )
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone && if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
!partition->fileSystem().uuid().isEmpty() ) !partition->fileSystem().uuid().isEmpty() )
s_partitionColorsCache.insert( partition->fileSystem().uuid(), {
PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ] ); if ( partition->fileSystem().type() == FileSystem::Luks )
{
FS::luks& luksFs = dynamic_cast< FS::luks& >( partition->fileSystem() );
if ( !luksFs.outerUuid().isEmpty() )
{
s_partitionColorsCache.insert( luksFs.outerUuid(),
PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ] );
}
}
else
s_partitionColorsCache.insert( partition->fileSystem().uuid(),
PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ] );
}
return PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ]; return PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ];
} }

View File

@ -116,9 +116,7 @@ createNewPartition( PartitionNode* parent,
PartitionTable::Flags flags ) PartitionTable::Flags flags )
{ {
FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector
#ifdef WITH_KPMCORE22
,device.logicalSize() ,device.logicalSize()
#endif
); );
return new Partition( return new Partition(
parent, parent,
@ -153,9 +151,7 @@ createNewEncryptedPartition( PartitionNode* parent,
FileSystemFactory::create( FileSystem::Luks, FileSystemFactory::create( FileSystem::Luks,
firstSector, firstSector,
lastSector lastSector
#ifdef WITH_KPMCORE22
,device.logicalSize() ,device.logicalSize()
#endif
) ); ) );
if ( !fs ) if ( !fs )
{ {
@ -186,9 +182,7 @@ clonePartition( Device* device, Partition* partition )
partition->fileSystem().type(), partition->fileSystem().type(),
partition->firstSector(), partition->firstSector(),
partition->lastSector() partition->lastSector()
#ifdef WITH_KPMCORE22
,device->logicalSize() ,device->logicalSize()
#endif
); );
return new Partition( partition->parent(), return new Partition( partition->parent(),
*device, *device,

View File

@ -43,6 +43,8 @@
#include <QDir> #include <QDir>
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QPushButton> #include <QPushButton>
#include <QRegularExpression>
#include <QRegularExpressionValidator>
#include <QSet> #include <QSet>
static QSet< FileSystem::Type > s_unmountableFS( static QSet< FileSystem::Type > s_unmountableFS(
@ -66,6 +68,19 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par
m_ui->encryptWidget->setText( tr( "En&crypt" ) ); m_ui->encryptWidget->setText( tr( "En&crypt" ) );
m_ui->encryptWidget->hide(); m_ui->encryptWidget->hide();
if (m_device->type() == Device::Disk_Device) {
m_ui->lvNameLabel->hide();
m_ui->lvNameLineEdit->hide();
}
if (m_device->type() == Device::LVM_Device) {
/* LVM logical volume name can consist of: letters numbers _ . - +
* It cannot start with underscore _ and must not be equal to . or .. or any entry in /dev/
* QLineEdit accepts QValidator::Intermediate, so we just disable . at the beginning */
QRegularExpression re(QStringLiteral(R"(^(?!_|\.)[\w\-.+]+)"));
QRegularExpressionValidator *validator = new QRegularExpressionValidator(re, this);
m_ui->lvNameLineEdit->setValidator(validator);
}
QStringList mountPoints = { "/", "/boot", "/home", "/opt", "/usr", "/var" }; QStringList mountPoints = { "/", "/boot", "/home", "/opt", "/usr", "/var" };
if ( PartUtils::isEfiSystem() ) if ( PartUtils::isEfiSystem() )
mountPoints << Calamares::JobQueue::instance()->globalStorage()->value( "efiSystemPartition" ).toString(); mountPoints << Calamares::JobQueue::instance()->globalStorage()->value( "efiSystemPartition" ).toString();
@ -227,6 +242,10 @@ CreatePartitionDialog::createPartition()
); );
} }
if (m_device->type() == Device::LVM_Device) {
partition->setPartitionPath(m_device->deviceNode() + QStringLiteral("/") + m_ui->lvNameLineEdit->text().trimmed());
}
PartitionInfo::setMountPoint( partition, m_ui->mountPointComboBox->currentText() ); PartitionInfo::setMountPoint( partition, m_ui->mountPointComboBox->currentText() );
PartitionInfo::setFormat( partition, true ); PartitionInfo::setFormat( partition, true );

View File

@ -146,6 +146,16 @@
</spacer> </spacer>
</item> </item>
<item row="6" column="0"> <item row="6" column="0">
<widget class="QLabel" name="lvNameLabel">
<property name="text">
<string>LVM LV name</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="lvNameLineEdit"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mountPointLabel"> <widget class="QLabel" name="mountPointLabel">
<property name="text"> <property name="text">
<string>&amp;Mount Point:</string> <string>&amp;Mount Point:</string>
@ -155,7 +165,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="7" column="1">
<widget class="QComboBox" name="mountPointComboBox"> <widget class="QComboBox" name="mountPointComboBox">
<property name="editable"> <property name="editable">
<bool>true</bool> <bool>true</bool>
@ -165,21 +175,21 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="8" column="1">
<widget class="QLabel" name="labelMountPoint"> <widget class="QLabel" name="labelMountPoint">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="0"> <item row="9" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Flags:</string> <string>Flags:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="1"> <item row="9" column="1">
<widget class="QListWidget" name="m_listFlags"> <widget class="QListWidget" name="m_listFlags">
<property name="alternatingRowColors"> <property name="alternatingRowColors">
<bool>true</bool> <bool>true</bool>
@ -192,7 +202,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="0"> <item row="10" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>

View File

@ -119,7 +119,7 @@ PartitionPage::~PartitionPage()
void void
PartitionPage::updateButtons() PartitionPage::updateButtons()
{ {
bool create = false, edit = false, del = false; bool create = false, createTable = false, edit = false, del = false;
QModelIndex index = m_ui->partitionTreeView->currentIndex(); QModelIndex index = m_ui->partitionTreeView->currentIndex();
if ( index.isValid() ) if ( index.isValid() )
@ -141,11 +141,18 @@ PartitionPage::updateButtons()
edit = !isFree && !isExtended; edit = !isFree && !isExtended;
del = !isFree; del = !isFree;
} }
if ( m_ui->deviceComboBox->currentIndex() >= 0 )
{
QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
if ( m_core->deviceModel()->deviceForIndex( deviceIndex )->type() != Device::LVM_Device )
createTable = true;
}
m_ui->createButton->setEnabled( create ); m_ui->createButton->setEnabled( create );
m_ui->editButton->setEnabled( edit ); m_ui->editButton->setEnabled( edit );
m_ui->deleteButton->setEnabled( del ); m_ui->deleteButton->setEnabled( del );
m_ui->newPartitionTableButton->setEnabled( createTable );
m_ui->newPartitionTableButton->setEnabled( m_ui->deviceComboBox->currentIndex() >= 0 );
} }
void void

View File

@ -24,15 +24,12 @@
#include "utils/Units.h" #include "utils/Units.h"
// KPMcore // KPMcore
#include <kpmcore/backend/corebackend.h>
#include <kpmcore/backend/corebackendmanager.h>
#include <kpmcore/backend/corebackenddevice.h>
#include <kpmcore/backend/corebackendpartition.h>
#include <kpmcore/backend/corebackendpartitiontable.h>
#include <kpmcore/core/device.h> #include <kpmcore/core/device.h>
#include <kpmcore/core/lvmdevice.h>
#include <kpmcore/core/partition.h> #include <kpmcore/core/partition.h>
#include <kpmcore/core/partitiontable.h> #include <kpmcore/core/partitiontable.h>
#include <kpmcore/fs/filesystem.h> #include <kpmcore/fs/filesystem.h>
#include <kpmcore/ops/newoperation.h>
#include <kpmcore/util/report.h> #include <kpmcore/util/report.h>
// Qt // Qt
@ -78,68 +75,15 @@ CreatePartitionJob::prettyStatusMessage() const
Calamares::JobResult Calamares::JobResult
CreatePartitionJob::exec() CreatePartitionJob::exec()
{ {
int step = 0;
const qreal stepCount = 4;
Report report( nullptr ); Report report( nullptr );
NewOperation op(*m_device, m_partition);
op.setStatus(Operation::StatusRunning);
QString message = tr( "The installer failed to create partition on disk '%1'." ).arg( m_device->name() ); QString message = tr( "The installer failed to create partition on disk '%1'." ).arg( m_device->name() );
if (op.execute(report))
progress( step++ / stepCount );
CoreBackend* backend = CoreBackendManager::self()->backend();
QScopedPointer<CoreBackendDevice> backendDevice( backend->openDevice( m_device->deviceNode() ) );
if ( !backendDevice.data() )
{
return Calamares::JobResult::error(
message,
tr( "Could not open device '%1'." ).arg( m_device->deviceNode() )
);
}
progress( step++ / stepCount );
QScopedPointer<CoreBackendPartitionTable> backendPartitionTable( backendDevice->openPartitionTable() );
if ( !backendPartitionTable.data() )
{
return Calamares::JobResult::error(
message,
tr( "Could not open partition table." )
);
}
progress( step++ / stepCount );
QString partitionPath = backendPartitionTable->createPartition( report, *m_partition );
if ( partitionPath.isEmpty() )
{
return Calamares::JobResult::error(
message,
report.toText()
);
}
m_partition->setPartitionPath( partitionPath );
backendPartitionTable->commit();
progress( step++ / stepCount );
FileSystem& fs = m_partition->fileSystem();
if ( fs.type() == FileSystem::Unformatted || fs.type() == FileSystem::Extended )
return Calamares::JobResult::ok(); return Calamares::JobResult::ok();
if ( !fs.create( report, partitionPath ) ) return Calamares::JobResult::error(message, report.toText());
{
return Calamares::JobResult::error(
tr( "The installer failed to create file system on partition %1." ).arg( partitionPath ),
report.toText()
);
}
if ( !backendPartitionTable->setPartitionSystemType( report, *m_partition ) )
{
return Calamares::JobResult::error(
tr( "The installer failed to update partition table on disk '%1'." ).arg( m_device->name() ),
report.toText()
);
}
backendPartitionTable->commit();
return Calamares::JobResult::ok();
} }
void void

View File

@ -26,7 +26,6 @@
#include <kpmcore/backend/corebackend.h> #include <kpmcore/backend/corebackend.h>
#include <kpmcore/backend/corebackendmanager.h> #include <kpmcore/backend/corebackendmanager.h>
#include <kpmcore/backend/corebackenddevice.h> #include <kpmcore/backend/corebackenddevice.h>
#include <kpmcore/backend/corebackendpartition.h>
#include <kpmcore/backend/corebackendpartitiontable.h> #include <kpmcore/backend/corebackendpartitiontable.h>
#include <kpmcore/core/device.h> #include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h> #include <kpmcore/core/partition.h>

View File

@ -29,6 +29,7 @@
#include <kpmcore/core/partition.h> #include <kpmcore/core/partition.h>
#include <kpmcore/core/partitiontable.h> #include <kpmcore/core/partitiontable.h>
#include <kpmcore/fs/filesystem.h> #include <kpmcore/fs/filesystem.h>
#include <kpmcore/ops/deleteoperation.h>
#include <kpmcore/util/report.h> #include <kpmcore/util/report.h>
DeletePartitionJob::DeletePartitionJob( Device* device, Partition* partition ) DeletePartitionJob::DeletePartitionJob( Device* device, Partition* partition )
@ -65,48 +66,14 @@ Calamares::JobResult
DeletePartitionJob::exec() DeletePartitionJob::exec()
{ {
Report report( nullptr ); Report report( nullptr );
DeleteOperation op(*m_device, m_partition);
op.setStatus(Operation::StatusRunning);
QString message = tr( "The installer failed to delete partition %1." ).arg( m_partition->devicePath() ); QString message = tr( "The installer failed to delete partition %1." ).arg( m_partition->devicePath() );
if (op.execute(report))
return Calamares::JobResult::ok();
if ( m_device->deviceNode() != m_partition->devicePath() ) return Calamares::JobResult::error(message, report.toText());
{
return Calamares::JobResult::error(
message,
tr( "Partition (%1) and device (%2) do not match." )
.arg( m_partition->devicePath() )
.arg( m_device->deviceNode() )
);
}
CoreBackend* backend = CoreBackendManager::self()->backend();
QScopedPointer<CoreBackendDevice> backendDevice( backend->openDevice( m_device->deviceNode() ) );
if ( !backendDevice.data() )
{
return Calamares::JobResult::error(
message,
tr( "Could not open device %1." ).arg( m_device->deviceNode() )
);
}
QScopedPointer<CoreBackendPartitionTable> backendPartitionTable( backendDevice->openPartitionTable() );
if ( !backendPartitionTable.data() )
{
return Calamares::JobResult::error(
message,
tr( "Could not open partition table." )
);
}
bool ok = backendPartitionTable->deletePartition( report, *m_partition );
if ( !ok )
{
return Calamares::JobResult::error(
message,
report.toText()
);
}
backendPartitionTable->commit();
return Calamares::JobResult::ok();
} }
void void

View File

@ -77,50 +77,6 @@ getLuksUuid( const QString& path )
return uuid; return uuid;
} }
// TODO: this will be available from KPMCore soon
static const char* filesystem_labels[] = {
"unknown",
"extended",
"ext2",
"ext3",
"ext4",
"linuxswap",
"fat16",
"fat32",
"ntfs",
"reiser",
"reiser4",
"xfs",
"jfs",
"hfs",
"hfsplus",
"ufs",
"unformatted",
"btrfs",
"hpfs",
"luks",
"ocfs2",
"zfs",
"exfat",
"nilfs2",
"lvm2 pv",
"f2fs",
"udf",
"iso9660",
};
Q_STATIC_ASSERT_X((sizeof(filesystem_labels) / sizeof(char *)) >= FileSystem::__lastType, "Mismatch in filesystem labels");
static QString
untranslatedTypeName(FileSystem::Type t)
{
Q_ASSERT( t >= 0 );
Q_ASSERT( t <= FileSystem::__lastType );
return QLatin1String(filesystem_labels[t]);
}
static QVariant static QVariant
mapForPartition( Partition* partition, const QString& uuid ) mapForPartition( Partition* partition, const QString& uuid )
@ -129,7 +85,7 @@ mapForPartition( Partition* partition, const QString& uuid )
map[ "device" ] = partition->partitionPath(); map[ "device" ] = partition->partitionPath();
map[ "mountPoint" ] = PartitionInfo::mountPoint( partition ); map[ "mountPoint" ] = PartitionInfo::mountPoint( partition );
map[ "fsName" ] = partition->fileSystem().name(); map[ "fsName" ] = partition->fileSystem().name();
map[ "fs" ] = untranslatedTypeName( partition->fileSystem().type() ); map[ "fs" ] = partition->fileSystem().name( { QStringLiteral("C") } ); // Untranslated
if ( partition->fileSystem().type() == FileSystem::Luks && if ( partition->fileSystem().type() == FileSystem::Luks &&
dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() )
map[ "fs" ] = dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS()->name(); map[ "fs" ] = dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS()->name();

View File

@ -25,7 +25,6 @@
#include <kpmcore/backend/corebackend.h> #include <kpmcore/backend/corebackend.h>
#include <kpmcore/backend/corebackendmanager.h> #include <kpmcore/backend/corebackendmanager.h>
#include <kpmcore/backend/corebackenddevice.h> #include <kpmcore/backend/corebackenddevice.h>
#include <kpmcore/backend/corebackendpartition.h>
#include <kpmcore/backend/corebackendpartitiontable.h> #include <kpmcore/backend/corebackendpartitiontable.h>
#include <kpmcore/core/device.h> #include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h> #include <kpmcore/core/partition.h>

View File

@ -21,3 +21,12 @@
PartitionJob::PartitionJob( Partition* partition ) PartitionJob::PartitionJob( Partition* partition )
: m_partition( partition ) : m_partition( partition )
{} {}
void PartitionJob::progress(int percent)
{
if ( percent < 0 )
percent = 0;
if ( percent > 100 )
percent = 100;
emit progress( qreal( percent / 100.0 ) );
}

View File

@ -37,6 +37,14 @@ public:
return m_partition; return m_partition;
} }
public slots:
/** @brief Translate from KPMCore to Calamares progress.
*
* KPMCore presents progress as an integer percent from 0 .. 100,
* while Calamares uses a qreal from 0 .. 1.00 .
*/
void progress( int percent );
protected: protected:
Partition* m_partition; Partition* m_partition;
}; };

View File

@ -20,11 +20,15 @@
#include "jobs/ResizePartitionJob.h" #include "jobs/ResizePartitionJob.h"
#include "utils/Units.h"
// KPMcore // KPMcore
#include <core/device.h> #include <core/device.h>
#include <ops/resizeoperation.h> #include <ops/resizeoperation.h>
#include <util/report.h> #include <util/report.h>
using CalamaresUtils::BytesToMiB;
//- ResizePartitionJob --------------------------------------------------------- //- ResizePartitionJob ---------------------------------------------------------
ResizePartitionJob::ResizePartitionJob( Device* device, Partition* partition, qint64 firstSector, qint64 lastSector ) ResizePartitionJob::ResizePartitionJob( Device* device, Partition* partition, qint64 firstSector, qint64 lastSector )
: PartitionJob( partition ) : PartitionJob( partition )
@ -51,8 +55,8 @@ ResizePartitionJob::prettyDescription() const
return tr( "Resize <strong>%2MB</strong> partition <strong>%1</strong> to " return tr( "Resize <strong>%2MB</strong> partition <strong>%1</strong> to "
"<strong>%3MB</strong>." ) "<strong>%3MB</strong>." )
.arg( partition()->partitionPath() ) .arg( partition()->partitionPath() )
.arg( ( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 ) .arg( ( BytesToMiB( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() ) )
.arg( ( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 ); .arg( ( BytesToMiB( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() ) );
} }
@ -62,8 +66,8 @@ ResizePartitionJob::prettyStatusMessage() const
return tr( "Resizing %2MB partition %1 to " return tr( "Resizing %2MB partition %1 to "
"%3MB." ) "%3MB." )
.arg( partition()->partitionPath() ) .arg( partition()->partitionPath() )
.arg( ( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 ) .arg( ( BytesToMiB( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() ) )
.arg( ( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 ); .arg( ( BytesToMiB( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() ) );
} }
@ -76,7 +80,7 @@ ResizePartitionJob::exec()
m_partition->setLastSector( m_oldLastSector ); m_partition->setLastSector( m_oldLastSector );
ResizeOperation op(*m_device, *m_partition, m_newFirstSector, m_newLastSector); ResizeOperation op(*m_device, *m_partition, m_newFirstSector, m_newLastSector);
op.setStatus(Operation::StatusRunning); op.setStatus(Operation::StatusRunning);
connect(&op, &Operation::progress, [&](int percent) { emit progress(percent / 100.0); } ); connect(&op, &Operation::progress, this, &ResizePartitionJob::progress );
QString errorMessage = tr( "The installer failed to resize partition %1 on disk '%2'." ) QString errorMessage = tr( "The installer failed to resize partition %1 on disk '%2'." )
.arg( m_partition->partitionPath() ) .arg( m_partition->partitionPath() )

View File

@ -22,19 +22,20 @@
#include "SetPartitionFlagsJob.h" #include "SetPartitionFlagsJob.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Units.h"
#include <kpmcore/core/partition.h> // KPMcore
#include <kpmcore/backend/corebackend.h> #include <core/device.h>
#include <kpmcore/backend/corebackenddevice.h> #include <core/partition.h>
#include <kpmcore/backend/corebackendmanager.h> #include <fs/filesystem.h>
#include <kpmcore/backend/corebackendpartition.h> #include <ops/setpartflagsoperation.h>
#include <kpmcore/backend/corebackendpartitiontable.h> #include <util/report.h>
#include <kpmcore/core/device.h>
#include <kpmcore/util/report.h> using CalamaresUtils::BytesToMiB;
SetPartFlagsJob::SetPartFlagsJob( Device* device, SetPartFlagsJob::SetPartFlagsJob( Device* device,
Partition* partition, Partition* partition,
PartitionTable::Flags flags ) PartitionTable::Flags flags )
: PartitionJob( partition ) : PartitionJob( partition )
, m_device( device ) , m_device( device )
, m_flags( flags ) , m_flags( flags )
@ -49,8 +50,8 @@ SetPartFlagsJob::prettyName() const
if ( !partition()->fileSystem().name().isEmpty() ) if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Set flags on %1MB %2 partition." ) return tr( "Set flags on %1MB %2 partition." )
.arg( partition()->capacity() /1024 /1024) .arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() ); .arg( partition()->fileSystem().name() );
return tr( "Set flags on new partition." ); return tr( "Set flags on new partition." );
} }
@ -64,12 +65,12 @@ SetPartFlagsJob::prettyDescription() const
{ {
if ( !partition()->partitionPath().isEmpty() ) if ( !partition()->partitionPath().isEmpty() )
return tr( "Clear flags on partition <strong>%1</strong>." ) return tr( "Clear flags on partition <strong>%1</strong>." )
.arg( partition()->partitionPath() ); .arg( partition()->partitionPath() );
if ( !partition()->fileSystem().name().isEmpty() ) if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Clear flags on %1MB <strong>%2</strong> partition." ) return tr( "Clear flags on %1MB <strong>%2</strong> partition." )
.arg( partition()->capacity() /1024 /1024) .arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() ); .arg( partition()->fileSystem().name() );
return tr( "Clear flags on new partition." ); return tr( "Clear flags on new partition." );
} }
@ -77,18 +78,18 @@ SetPartFlagsJob::prettyDescription() const
if ( !partition()->partitionPath().isEmpty() ) if ( !partition()->partitionPath().isEmpty() )
return tr( "Flag partition <strong>%1</strong> as " return tr( "Flag partition <strong>%1</strong> as "
"<strong>%2</strong>." ) "<strong>%2</strong>." )
.arg( partition()->partitionPath() ) .arg( partition()->partitionPath() )
.arg( flagsList.join( ", " ) ); .arg( flagsList.join( ", " ) );
if ( !partition()->fileSystem().name().isEmpty() ) if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Flag %1MB <strong>%2</strong> partition as " return tr( "Flag %1MB <strong>%2</strong> partition as "
"<strong>%3</strong>." ) "<strong>%3</strong>." )
.arg( partition()->capacity() /1024 /1024) .arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() ) .arg( partition()->fileSystem().name() )
.arg( flagsList.join( ", " ) ); .arg( flagsList.join( ", " ) );
return tr( "Flag new partition as <strong>%1</strong>." ) return tr( "Flag new partition as <strong>%1</strong>." )
.arg( flagsList.join( ", " ) ); .arg( flagsList.join( ", " ) );
} }
@ -100,12 +101,12 @@ SetPartFlagsJob::prettyStatusMessage() const
{ {
if ( !partition()->partitionPath().isEmpty() ) if ( !partition()->partitionPath().isEmpty() )
return tr( "Clearing flags on partition <strong>%1</strong>." ) return tr( "Clearing flags on partition <strong>%1</strong>." )
.arg( partition()->partitionPath() ); .arg( partition()->partitionPath() );
if ( !partition()->fileSystem().name().isEmpty() ) if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Clearing flags on %1MB <strong>%2</strong> partition." ) return tr( "Clearing flags on %1MB <strong>%2</strong> partition." )
.arg( partition()->capacity() /1024 /1024) .arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() ); .arg( partition()->fileSystem().name() );
return tr( "Clearing flags on new partition." ); return tr( "Clearing flags on new partition." );
} }
@ -113,94 +114,33 @@ SetPartFlagsJob::prettyStatusMessage() const
if ( !partition()->partitionPath().isEmpty() ) if ( !partition()->partitionPath().isEmpty() )
return tr( "Setting flags <strong>%2</strong> on partition " return tr( "Setting flags <strong>%2</strong> on partition "
"<strong>%1</strong>." ) "<strong>%1</strong>." )
.arg( partition()->partitionPath() ) .arg( partition()->partitionPath() )
.arg( flagsList.join( ", " ) ); .arg( flagsList.join( ", " ) );
if ( !partition()->fileSystem().name().isEmpty() ) if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Setting flags <strong>%3</strong> on " return tr( "Setting flags <strong>%3</strong> on "
"%1MB <strong>%2</strong> partition." ) "%1MB <strong>%2</strong> partition." )
.arg( partition()->capacity() /1024 /1024) .arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() ) .arg( partition()->fileSystem().name() )
.arg( flagsList.join( ", " ) ); .arg( flagsList.join( ", " ) );
return tr( "Setting flags <strong>%1</strong> on new partition." ) return tr( "Setting flags <strong>%1</strong> on new partition." )
.arg( flagsList.join( ", " ) ); .arg( flagsList.join( ", " ) );
} }
Calamares::JobResult Calamares::JobResult
SetPartFlagsJob::exec() SetPartFlagsJob::exec()
{ {
PartitionTable::Flags oldFlags = partition()->availableFlags(); Report report ( nullptr );
if ( oldFlags == m_flags ) SetPartFlagsOperation op( *m_device, *partition(), m_flags );
return Calamares::JobResult::ok(); op.setStatus( Operation::StatusRunning );
connect( &op, &Operation::progress, this, &SetPartFlagsJob::progress );
CoreBackend* backend = CoreBackendManager::self()->backend();
QString errorMessage = tr( "The installer failed to set flags on partition %1." ) QString errorMessage = tr( "The installer failed to set flags on partition %1." )
.arg( m_partition->partitionPath() ); .arg( m_partition->partitionPath() );
if ( op.execute( report ) )
return Calamares::JobResult::ok();
QScopedPointer< CoreBackendDevice > backendDevice( backend->openDevice( m_device->deviceNode() ) ); return Calamares::JobResult::error( errorMessage, report.toText() );
if ( !backendDevice.data() )
{
return Calamares::JobResult::error(
errorMessage,
tr( "Could not open device '%1'." ).arg( m_device->deviceNode() )
);
}
QScopedPointer< CoreBackendPartitionTable > backendPartitionTable( backendDevice->openPartitionTable() );
if ( !backendPartitionTable.data() )
{
return Calamares::JobResult::error(
errorMessage,
tr( "Could not open partition table on device '%1'." ).arg( m_device->deviceNode() )
);
}
QScopedPointer< CoreBackendPartition > backendPartition(
( partition()->roles().has( PartitionRole::Extended ) )
? backendPartitionTable->getExtendedPartition()
: backendPartitionTable->getPartitionBySector( partition()->firstSector() )
);
if ( !backendPartition.data() ) {
return Calamares::JobResult::error(
errorMessage,
tr( "Could not find partition '%1'." ).arg( partition()->partitionPath() )
);
}
quint32 count = 0;
foreach( const PartitionTable::Flag& f, PartitionTable::flagList() )
{
emit progress(++count);
const bool state = ( m_flags & f ) ? true : false;
Report report( nullptr );
if ( !backendPartition->setFlag( report, f, state ) )
{
cDebug() << QStringLiteral( "WARNING: Could not set flag %2 on "
"partition '%1'." )
.arg( partition()->partitionPath() )
.arg( PartitionTable::flagName( f ) );
}
}
// HACK: Partition (in KPMcore) declares SetPartFlagsJob as friend, but this actually
// refers to an unrelated class SetPartFlagsJob which is in KPMcore but is not
// exported.
// Obviously here we are relying on having a class in Calamares with the same
// name as a private one in KPMcore, which is awful, but it's the least evil
// way to call Partition::setFlags (KPMcore's SetPartFlagsJob needs its friend
// status for the very same reason).
m_partition->setFlags( m_flags );
backendPartitionTable->commit();
return Calamares::JobResult::ok();
} }
#include "SetPartitionFlagsJob.moc"

View File

@ -26,9 +26,16 @@ drawNestedPartitions: false
# Show/hide partition labels on manual partitioning page. # Show/hide partition labels on manual partitioning page.
alwaysShowPartitionLabels: true alwaysShowPartitionLabels: true
# Default filesystem type, pre-selected in the "Create Partition" dialog. # Default filesystem type, used when a "new" partition is made.
# The filesystem type selected here is also used for automated install #
# modes (Erase, Replace and Alongside). # When replacing a partition, the existing filesystem inside the
# partition is retained. In other cases, e.g. Erase and Alongside,
# as well as when using manual partitioning and creating a new
# partition, this filesystem type is pre-selected. Note that
# editing a partition in manual-creation mode will not automatically
# change the filesystem type to this default value -- it is not
# creating a new partition.
#
# Suggested values: ext2, ext3, ext4, reiser, xfs, jfs, btrfs # Suggested values: ext2, ext3, ext4, reiser, xfs, jfs, btrfs
# If nothing is specified, Calamares defaults to "ext4". # If nothing is specified, Calamares defaults to "ext4".
defaultFileSystemType: "ext4" defaultFileSystemType: "ext4"

View File

@ -1,5 +1,4 @@
find_package( Qt5 COMPONENTS Gui Test REQUIRED ) find_package( Qt5 COMPONENTS Gui Test REQUIRED )
find_package( KF5 COMPONENTS Service REQUIRED )
include( ECMAddTests ) include( ECMAddTests )
@ -31,7 +30,6 @@ ecm_add_test( ${partitionjobtests_SRCS}
kpmcore kpmcore
Qt5::Core Qt5::Core
Qt5::Test Qt5::Test
KF5::Service
) )
set_target_properties( partitionjobtests PROPERTIES AUTOMOC TRUE ) set_target_properties( partitionjobtests PROPERTIES AUTOMOC TRUE )

View File

@ -219,9 +219,7 @@ PartitionJobTests::newCreatePartitionJob( Partition* freeSpacePartition, Partiti
else else
lastSector = freeSpacePartition->lastSector(); lastSector = freeSpacePartition->lastSector();
FileSystem* fs = FileSystemFactory::create( type, firstSector, lastSector FileSystem* fs = FileSystemFactory::create( type, firstSector, lastSector
#ifdef WITH_KPMCORE22
,m_device->logicalSize() ,m_device->logicalSize()
#endif
); );
Partition* partition = new Partition( Partition* partition = new Partition(