diff --git a/src/modules/partition/core/BootLoaderModel.cpp b/src/modules/partition/core/BootLoaderModel.cpp index 7f5a0427a..10b88be76 100644 --- a/src/modules/partition/core/BootLoaderModel.cpp +++ b/src/modules/partition/core/BootLoaderModel.cpp @@ -20,8 +20,8 @@ #include "core/BootLoaderModel.h" -#include "core/PartitionInfo.h" #include "core/KPMHelpers.h" +#include "core/PartitionInfo.h" #include "utils/Logger.h" @@ -44,9 +44,7 @@ BootLoaderModel::BootLoaderModel( QObject* parent ) { } -BootLoaderModel::~BootLoaderModel() -{ -} +BootLoaderModel::~BootLoaderModel() {} void BootLoaderModel::init( const QList< Device* >& devices ) @@ -67,11 +65,8 @@ BootLoaderModel::createMbrItems() { for ( auto device : m_devices ) { - QString text = tr( "Master Boot Record of %1" ) - .arg( device->name() ); - appendRow( - createBootLoaderItem( text, device->deviceNode(), false ) - ); + QString text = tr( "Master Boot Record of %1" ).arg( device->name() ); + appendRow( createBootLoaderItem( text, device->deviceNode(), false ) ); } } @@ -90,23 +85,29 @@ BootLoaderModel::update() void BootLoaderModel::updateInternal() { - QMutexLocker lock(&m_lock); + QMutexLocker lock( &m_lock ); clear(); createMbrItems(); // An empty model is possible if you don't havee permissions: don't crash though. if ( rowCount() < 1 ) + { return; + } QString partitionText; Partition* partition = KPMHelpers::findPartitionByMountPoint( m_devices, "/boot" ); if ( partition ) + { partitionText = tr( "Boot Partition" ); + } else { partition = KPMHelpers::findPartitionByMountPoint( m_devices, "/" ); if ( partition ) + { partitionText = tr( "System Partition" ); + } } Q_ASSERT( rowCount() > 0 ); @@ -117,7 +118,9 @@ BootLoaderModel::updateInternal() if ( !partition ) { if ( lastIsPartition ) + { takeRow( rowCount() - 1 ); + } } else { @@ -129,15 +132,11 @@ BootLoaderModel::updateInternal() } else { - appendRow( - createBootLoaderItem( partitionText, PartitionInfo::mountPoint( partition ), true ) - ); + appendRow( createBootLoaderItem( partitionText, PartitionInfo::mountPoint( partition ), true ) ); } // Create "don't install bootloader" item - appendRow( - createBootLoaderItem( tr( "Do not install a boot loader" ), QString(), false ) - ); + appendRow( createBootLoaderItem( tr( "Do not install a boot loader" ), QString(), false ) ); } } @@ -145,13 +144,15 @@ BootLoaderModel::updateInternal() QVariant BootLoaderModel::data( const QModelIndex& index, int role ) const { - QMutexLocker lock(&m_lock); + QMutexLocker lock( &m_lock ); if ( role == Qt::DisplayRole ) { QString displayRole = QStandardItemModel::data( index, Qt::DisplayRole ).toString(); QString pathRole = QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString(); if ( pathRole.isEmpty() ) + { return displayRole; + } return tr( "%1 (%2)" ).arg( displayRole, pathRole ); } @@ -163,14 +164,18 @@ namespace Calamares int findBootloader( const QAbstractItemModel* model, const QString& path ) { - for ( int i = 0; i < model->rowCount(); ++i) + for ( int i = 0; i < model->rowCount(); ++i ) { const auto index = model->index( i, 0, QModelIndex() ); if ( !index.isValid() ) + { continue; + } QVariant var = model->data( index, BootLoaderModel::BootLoaderPathRole ); if ( var.isValid() && var.toString() == path ) + { return i; + } } return -1; @@ -191,7 +196,7 @@ restoreSelectedBootLoader( QComboBox& combo, const QString& path ) { combo.setCurrentIndex( 0 ); } - else if ( (r = findBootloader( model, path )) >= 0 ) + else if ( ( r = findBootloader( model, path ) ) >= 0 ) { combo.setCurrentIndex( r ); } @@ -201,4 +206,4 @@ restoreSelectedBootLoader( QComboBox& combo, const QString& path ) } } -} // namespace +} // namespace Calamares diff --git a/src/modules/partition/core/BootLoaderModel.h b/src/modules/partition/core/BootLoaderModel.h index a2befad00..8daa8ca04 100644 --- a/src/modules/partition/core/BootLoaderModel.h +++ b/src/modules/partition/core/BootLoaderModel.h @@ -66,18 +66,18 @@ private: namespace Calamares { - /** @brief Returns the row number of boot-loader @p path (e.g. /dev/sda) - * - * Assuming the @p model is a BootLoaderModel, will return a row number - * in the model. Returns -1 otherwise. - */ - int findBootloader( const QAbstractItemModel* model, const QString& path ); +/** @brief Returns the row number of boot-loader @p path (e.g. /dev/sda) + * + * Assuming the @p model is a BootLoaderModel, will return a row number + * in the model. Returns -1 otherwise. + */ +int findBootloader( const QAbstractItemModel* model, const QString& path ); - /** @brief Tries to set @p path as selected item in @p combo - * - * Matches a boot-loader install path (e.g. /dev/sda) with a model - * row and sets that as the current row. - */ - void restoreSelectedBootLoader( QComboBox& combo, const QString& path ); -} // namespace +/** @brief Tries to set @p path as selected item in @p combo + * + * Matches a boot-loader install path (e.g. /dev/sda) with a model + * row and sets that as the current row. + */ +void restoreSelectedBootLoader( QComboBox& combo, const QString& path ); +} // namespace Calamares #endif /* BOOTLOADERMODEL_H */ diff --git a/src/modules/partition/core/ColorUtils.cpp b/src/modules/partition/core/ColorUtils.cpp index 63f51cddf..d04c4110d 100644 --- a/src/modules/partition/core/ColorUtils.cpp +++ b/src/modules/partition/core/ColorUtils.cpp @@ -33,27 +33,25 @@ #include #include -using CalamaresUtils::Partition::PartitionIterator; using CalamaresUtils::Partition::isPartitionFreeSpace; using CalamaresUtils::Partition::isPartitionNew; +using CalamaresUtils::Partition::PartitionIterator; static const int NUM_PARTITION_COLORS = 5; static const int NUM_NEW_PARTITION_COLORS = 4; //Let's try to use the Breeze palette -static const QColor PARTITION_COLORS[ NUM_PARTITION_COLORS ] = -{ - "#2980b9", //Dark Plasma Blue - "#27ae60", //Dark Icon Green - "#c9ce3b", //Dirty Yellow - "#3daee9", //Plasma Blue - "#9b59b6", //Purple +static const QColor PARTITION_COLORS[ NUM_PARTITION_COLORS ] = { + "#2980b9", //Dark Plasma Blue + "#27ae60", //Dark Icon Green + "#c9ce3b", //Dirty Yellow + "#3daee9", //Plasma Blue + "#9b59b6", //Purple }; -static const QColor NEW_PARTITION_COLORS[ NUM_NEW_PARTITION_COLORS ] = -{ - "#c0392b", //Dark Icon Red - "#f39c1f", //Dark Icon Yellow - "#f1b7bc", //Light Salmon - "#fed999", //Light Orange +static const QColor NEW_PARTITION_COLORS[ NUM_NEW_PARTITION_COLORS ] = { + "#c0392b", //Dark Icon Red + "#f39c1f", //Dark Icon Yellow + "#f1b7bc", //Light Salmon + "#fed999", //Light Orange }; static QColor FREE_SPACE_COLOR = "#777777"; static QColor EXTENDED_COLOR = "#aaaaaa"; @@ -65,12 +63,14 @@ static QMap< QString, QColor > s_partitionColorsCache; namespace ColorUtils { -QColor freeSpaceColor() +QColor +freeSpaceColor() { return FREE_SPACE_COLOR; } -QColor unknownDisklabelColor() +QColor +unknownDisklabelColor() { return UNKNOWN_DISKLABEL_COLOR; } @@ -78,9 +78,10 @@ QColor unknownDisklabelColor() PartitionNode* _findRootForPartition( PartitionNode* partition ) { - if ( partition->isRoot() || - !partition->parent() ) + if ( partition->isRoot() || !partition->parent() ) + { return partition; + } return _findRootForPartition( partition->parent() ); } @@ -95,23 +96,30 @@ colorForPartition( Partition* partition ) } if ( isPartitionFreeSpace( partition ) ) + { return FREE_SPACE_COLOR; + } if ( partition->roles().has( PartitionRole::Extended ) ) + { return EXTENDED_COLOR; + } - if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone && - !partition->fileSystem().uuid().isEmpty() ) + if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone + && !partition->fileSystem().uuid().isEmpty() ) { if ( partition->fileSystem().type() == FileSystem::Luks ) { FS::luks& luksFs = dynamic_cast< FS::luks& >( partition->fileSystem() ); - if ( !luksFs.outerUuid().isEmpty() && - s_partitionColorsCache.contains( luksFs.outerUuid() ) ) + 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 @@ -122,27 +130,30 @@ colorForPartition( Partition* partition ) Q_ASSERT( table ); int colorIdx = 0; int newColorIdx = 0; - for ( PartitionIterator it = PartitionIterator::begin( table ); - it != PartitionIterator::end( table ); - ++it ) + for ( PartitionIterator it = PartitionIterator::begin( table ); it != PartitionIterator::end( table ); ++it ) { Partition* child = *it; if ( child == partition ) + { break; - if ( !isPartitionFreeSpace( child ) && - !child->hasChildren() ) + } + if ( !isPartitionFreeSpace( child ) && !child->hasChildren() ) { if ( isPartitionNew( child ) ) + { ++newColorIdx; + } ++colorIdx; } } if ( isPartitionNew( partition ) ) + { return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ]; + } - if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone && - !partition->fileSystem().uuid().isEmpty() ) + if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone + && !partition->fileSystem().uuid().isEmpty() ) { if ( partition->fileSystem().type() == FileSystem::Luks ) { @@ -168,17 +179,17 @@ colorForPartitionInFreeSpace( Partition* partition ) PartitionTable* table = dynamic_cast< PartitionTable* >( parent ); Q_ASSERT( table ); int newColorIdx = 0; - for ( PartitionIterator it = PartitionIterator::begin( table ); - it != PartitionIterator::end( table ); - ++it ) + for ( PartitionIterator it = PartitionIterator::begin( table ); it != PartitionIterator::end( table ); ++it ) { Partition* child = *it; if ( child == partition ) + { break; - if ( !isPartitionFreeSpace( child ) && - !child->hasChildren() && - isPartitionNew( child ) ) + } + if ( !isPartitionFreeSpace( child ) && !child->hasChildren() && isPartitionNew( child ) ) + { ++newColorIdx; + } } return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ]; } @@ -190,4 +201,4 @@ invalidateCache() s_partitionColorsCache.clear(); } -} // namespace +} // namespace ColorUtils diff --git a/src/modules/partition/core/ColorUtils.h b/src/modules/partition/core/ColorUtils.h index 33efc4b7e..3c65b75b2 100644 --- a/src/modules/partition/core/ColorUtils.h +++ b/src/modules/partition/core/ColorUtils.h @@ -53,6 +53,6 @@ QColor colorForPartitionInFreeSpace( Partition* freeSpacePartition ); */ void invalidateCache(); -} +} // namespace ColorUtils #endif /* COLORUTILS_H */ diff --git a/src/modules/partition/core/DeviceList.cpp b/src/modules/partition/core/DeviceList.cpp index f11293533..944940d9a 100644 --- a/src/modules/partition/core/DeviceList.cpp +++ b/src/modules/partition/core/DeviceList.cpp @@ -50,7 +50,9 @@ hasRootPartition( Device* device ) { for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it ) if ( ( *it )->mountPoint() == "/" ) + { return true; + } return false; } @@ -69,17 +71,22 @@ isIso9660( const Device* device ) { const QString path = device->deviceNode(); if ( path.isEmpty() ) + { return false; + } if ( blkIdCheckIso9660( path ) ) + { return true; + } - if ( device->partitionTable() && - !device->partitionTable()->children().isEmpty() ) + if ( device->partitionTable() && !device->partitionTable()->children().isEmpty() ) { for ( const Partition* partition : device->partitionTable()->children() ) { if ( blkIdCheckIso9660( partition->partitionPath() ) ) + { return true; + } } } return false; @@ -87,7 +94,7 @@ isIso9660( const Device* device ) static inline QDebug& -operator <<( QDebug& s, QList< Device* >::iterator& it ) +operator<<( QDebug& s, QList< Device* >::iterator& it ) { s << ( ( *it ) ? ( *it )->deviceNode() : QString( "" ) ); return s; @@ -96,7 +103,7 @@ operator <<( QDebug& s, QList< Device* >::iterator& it ) using DeviceList = QList< Device* >; static inline DeviceList::iterator -erase(DeviceList& l, DeviceList::iterator& it) +erase( DeviceList& l, DeviceList::iterator& it ) { Device* p = *it; auto r = l.erase( it ); @@ -104,13 +111,14 @@ erase(DeviceList& l, DeviceList::iterator& it) return r; } -QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) +QList< Device* > +getDevices( DeviceType which, qint64 minimumSize ) { - bool writableOnly = (which == DeviceType::WritableOnly); + bool writableOnly = ( which == DeviceType::WritableOnly ); CoreBackend* backend = CoreBackendManager::self()->backend(); #if defined( WITH_KPMCORE4API ) - DeviceList devices = backend->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag(0) ); + DeviceList devices = backend->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag( 0 ) ); #else DeviceList devices = backend->scanDevices( /* excludeReadOnly */ true ); #endif @@ -128,14 +136,12 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) if ( !( *it ) ) { cDebug() << Logger::SubEntry << "Skipping nullptr device"; - it = erase( devices, it); + it = erase( devices, it ); } - else if ( ( *it )->deviceNode().startsWith( "/dev/zram" ) - ) + else if ( ( *it )->deviceNode().startsWith( "/dev/zram" ) ) { cDebug() << Logger::SubEntry << "Removing zram" << it; it = erase( devices, it ); - } else if ( writableOnly && hasRootPartition( *it ) ) { @@ -147,13 +153,15 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) cDebug() << Logger::SubEntry << "Removing device with iso9660 filesystem (probably a CD) on it" << it; it = erase( devices, it ); } - else if ( (minimumSize >= 0) && !( (*it)->capacity() > minimumSize ) ) + else if ( ( minimumSize >= 0 ) && !( ( *it )->capacity() > minimumSize ) ) { cDebug() << Logger::SubEntry << "Removing too-small" << it; it = erase( devices, it ); } else + { ++it; + } #endif return devices; diff --git a/src/modules/partition/core/DeviceList.h b/src/modules/partition/core/DeviceList.h index 3754f58e6..6823d6951 100644 --- a/src/modules/partition/core/DeviceList.h +++ b/src/modules/partition/core/DeviceList.h @@ -28,7 +28,11 @@ class Device; namespace PartUtils { -enum class DeviceType { All, WritableOnly }; +enum class DeviceType +{ + All, + WritableOnly +}; /** * @brief Gets a list of storage devices. @@ -43,6 +47,6 @@ enum class DeviceType { All, WritableOnly }; */ QList< Device* > getDevices( DeviceType which = DeviceType::All, qint64 minimumSize = -1 ); -} +} // namespace PartUtils -#endif // DEVICELIST_H +#endif // DEVICELIST_H diff --git a/src/modules/partition/core/DeviceModel.cpp b/src/modules/partition/core/DeviceModel.cpp index c76c39090..f881d265b 100644 --- a/src/modules/partition/core/DeviceModel.cpp +++ b/src/modules/partition/core/DeviceModel.cpp @@ -30,8 +30,8 @@ // KF5 #include -#include #include +#include // STL #include @@ -39,8 +39,7 @@ static void sortDevices( DeviceModel::DeviceList& l ) { - std::sort( l.begin(), l.end(), []( const Device* dev1, const Device* dev2 ) - { + std::sort( l.begin(), l.end(), []( const Device* dev1, const Device* dev2 ) { return dev1->deviceNode() < dev2->deviceNode(); } ); } @@ -50,9 +49,7 @@ DeviceModel::DeviceModel( QObject* parent ) { } -DeviceModel::~DeviceModel() -{ -} +DeviceModel::~DeviceModel() {} void DeviceModel::init( const DeviceList& devices ) @@ -74,7 +71,9 @@ DeviceModel::data( const QModelIndex& index, int role ) const { int row = index.row(); if ( row < 0 || row >= m_devices.count() ) + { return QVariant(); + } Device* device = m_devices.at( row ); @@ -83,16 +82,18 @@ DeviceModel::data( const QModelIndex& index, int role ) const case Qt::DisplayRole: case Qt::ToolTipRole: if ( device->name().isEmpty() ) + { return device->deviceNode(); + } else { if ( device->logicalSize() >= 0 && device->totalLogical() >= 0 ) { //: device[name] - size[number] (device-node[name]) return tr( "%1 - %2 (%3)" ) - .arg( device->name() ) - .arg( KFormat().formatByteSize( device->capacity() ) ) - .arg( device->deviceNode() ); + .arg( device->name() ) + .arg( KFormat().formatByteSize( device->capacity() ) ) + .arg( device->deviceNode() ); } else { @@ -100,16 +101,14 @@ DeviceModel::data( const QModelIndex& index, int role ) const // always has 1B capacity), so don't show it for a while. // //: device[name] - (device-node[name]) - return tr( "%1 - (%2)" ) - .arg( device->name() ) - .arg( device->deviceNode() ); + return tr( "%1 - (%2)" ).arg( device->name() ).arg( device->deviceNode() ); } - } + } case Qt::DecorationRole: - return CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionDisk, - CalamaresUtils::Original, - QSize( CalamaresUtils::defaultIconSize().width() * 3, - CalamaresUtils::defaultIconSize().height() * 3 ) ); + return CalamaresUtils::defaultPixmap( + CalamaresUtils::PartitionDisk, + CalamaresUtils::Original, + QSize( CalamaresUtils::defaultIconSize().width() * 3, CalamaresUtils::defaultIconSize().height() * 3 ) ); default: return QVariant(); } @@ -121,7 +120,9 @@ DeviceModel::deviceForIndex( const QModelIndex& index ) const { int row = index.row(); if ( row < 0 || row >= m_devices.count() ) + { return nullptr; + } return m_devices.at( row ); } @@ -134,7 +135,9 @@ DeviceModel::swapDevice( Device* oldDevice, Device* newDevice ) int indexOfOldDevice = m_devices.indexOf( oldDevice ); if ( indexOfOldDevice < 0 ) + { return; + } m_devices[ indexOfOldDevice ] = newDevice; @@ -142,7 +145,7 @@ DeviceModel::swapDevice( Device* oldDevice, Device* newDevice ) } void -DeviceModel::addDevice( Device *device ) +DeviceModel::addDevice( Device* device ) { beginResetModel(); m_devices << device; @@ -151,7 +154,7 @@ DeviceModel::addDevice( Device *device ) } void -DeviceModel::removeDevice( Device *device ) +DeviceModel::removeDevice( Device* device ) { beginResetModel(); m_devices.removeAll( device ); diff --git a/src/modules/partition/core/DeviceModel.h b/src/modules/partition/core/DeviceModel.h index f3e158bbf..29d1598ad 100644 --- a/src/modules/partition/core/DeviceModel.h +++ b/src/modules/partition/core/DeviceModel.h @@ -20,8 +20,8 @@ #define DEVICEMODEL_H #include -#include #include +#include class Device; class PartitionModel; diff --git a/src/modules/partition/core/KPMHelpers.cpp b/src/modules/partition/core/KPMHelpers.cpp index c3d4c07cc..730d1d9af 100644 --- a/src/modules/partition/core/KPMHelpers.cpp +++ b/src/modules/partition/core/KPMHelpers.cpp @@ -26,10 +26,10 @@ #include "utils/Logger.h" // KPMcore +#include #include #include #include -#include #include using CalamaresUtils::Partition::PartitionIterator; @@ -43,7 +43,9 @@ findPartitionByMountPoint( const QList< Device* >& devices, const QString& mount for ( auto device : devices ) for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it ) if ( PartitionInfo::mountPoint( *it ) == mountPoint ) + { return *it; + } return nullptr; } @@ -57,21 +59,19 @@ createNewPartition( PartitionNode* parent, qint64 lastSector, PartitionTable::Flags flags ) { - FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector - ,device.logicalSize() - ); - return new Partition( - parent, - device, - role, - fs, fs->firstSector(), fs->lastSector(), - QString() /* path */, - KPM_PARTITION_FLAG(None) /* availableFlags */, - QString() /* mountPoint */, - false /* mounted */, - flags /* activeFlags */, - KPM_PARTITION_STATE(New) - ); + FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector, device.logicalSize() ); + return new Partition( parent, + device, + role, + fs, + fs->firstSector(), + fs->lastSector(), + QString() /* path */, + KPM_PARTITION_FLAG( None ) /* availableFlags */, + QString() /* mountPoint */, + false /* mounted */, + flags /* activeFlags */, + KPM_PARTITION_STATE( New ) ); } @@ -87,14 +87,12 @@ createNewEncryptedPartition( PartitionNode* parent, { PartitionRole::Roles newRoles = role.roles(); if ( !role.has( PartitionRole::Luks ) ) + { newRoles |= PartitionRole::Luks; + } FS::luks* fs = dynamic_cast< FS::luks* >( - FileSystemFactory::create( FileSystem::Luks, - firstSector, - lastSector - ,device.logicalSize() - ) ); + FileSystemFactory::create( FileSystem::Luks, firstSector, lastSector, device.logicalSize() ) ); if ( !fs ) { cError() << "cannot create LUKS filesystem. Giving up."; @@ -106,13 +104,15 @@ createNewEncryptedPartition( PartitionNode* parent, Partition* p = new Partition( parent, device, PartitionRole( newRoles ), - fs, fs->firstSector(), fs->lastSector(), + fs, + fs->firstSector(), + fs->lastSector(), QString() /* path */, - KPM_PARTITION_FLAG(None) /* availableFlags */, + KPM_PARTITION_FLAG( None ) /* availableFlags */, QString() /* mountPoint */, false /* mounted */, flags /* activeFlags */, - KPM_PARTITION_STATE(New) ); + KPM_PARTITION_STATE( New ) ); return p; } @@ -121,11 +121,7 @@ Partition* clonePartition( Device* device, Partition* partition ) { FileSystem* fs = FileSystemFactory::create( - partition->fileSystem().type(), - partition->firstSector(), - partition->lastSector() - ,device->logicalSize() - ); + partition->fileSystem().type(), partition->firstSector(), partition->lastSector(), device->logicalSize() ); return new Partition( partition->parent(), *device, partition->roles(), @@ -136,4 +132,4 @@ clonePartition( Device* device, Partition* partition ) partition->activeFlags() ); } -} // namespace +} // namespace KPMHelpers diff --git a/src/modules/partition/core/KPMHelpers.h b/src/modules/partition/core/KPMHelpers.h index 5e18aaf3a..326993362 100644 --- a/src/modules/partition/core/KPMHelpers.h +++ b/src/modules/partition/core/KPMHelpers.h @@ -35,12 +35,12 @@ class PartitionNode; class PartitionRole; #if defined( WITH_KPMCORE4API ) -#define KPM_PARTITION_FLAG(x) PartitionTable::Flag::x -#define KPM_PARTITION_STATE(x) Partition::State::x +#define KPM_PARTITION_FLAG( x ) PartitionTable::Flag::x +#define KPM_PARTITION_STATE( x ) Partition::State::x #define KPM_PARTITION_FLAG_ESP PartitionTable::Flag::Boot #else -#define KPM_PARTITION_FLAG(x) PartitionTable::Flag##x -#define KPM_PARTITION_STATE(x) Partition::State##x +#define KPM_PARTITION_FLAG( x ) PartitionTable::Flag##x +#define KPM_PARTITION_STATE( x ) Partition::State##x #define KPM_PARTITION_FLAG_ESP PartitionTable::FlagEsp #endif @@ -79,6 +79,6 @@ Partition* createNewEncryptedPartition( PartitionNode* parent, Partition* clonePartition( Device* device, Partition* partition ); -} +} // namespace KPMHelpers #endif /* KPMHELPERS_H */ diff --git a/src/modules/partition/core/OsproberEntry.h b/src/modules/partition/core/OsproberEntry.h index e8c7895f0..1e1fd0eca 100644 --- a/src/modules/partition/core/OsproberEntry.h +++ b/src/modules/partition/core/OsproberEntry.h @@ -32,7 +32,7 @@ struct FstabEntry int pass; /// Does this entry make sense and is it complete? - bool isValid() const; // implemented in Partutils.cpp + bool isValid() const; // implemented in Partutils.cpp /** @brief Create an entry from a live of /etc/fstab * @@ -41,7 +41,7 @@ struct FstabEntry * If the string isn't valid (e.g. comment-line, or broken * fstab entry) then the entry that is returned is invalid. */ - static FstabEntry fromEtcFstab( const QString& ); // implemented in Partutils.cpp + static FstabEntry fromEtcFstab( const QString& ); // implemented in Partutils.cpp }; typedef QList< FstabEntry > FstabEntryList; @@ -59,4 +59,4 @@ struct OsproberEntry typedef QList< OsproberEntry > OsproberEntryList; -#endif // OSPROBERENTRY_H +#endif // OSPROBERENTRY_H diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index b1eee4cef..4cc59d518 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -52,17 +52,25 @@ QString convenienceName( const Partition* const candidate ) { if ( !candidate->mountPoint().isEmpty() ) + { return candidate->mountPoint(); + } if ( !candidate->partitionPath().isEmpty() ) + { return candidate->partitionPath(); + } if ( !candidate->devicePath().isEmpty() ) + { return candidate->devicePath(); + } if ( !candidate->deviceNode().isEmpty() ) + { return candidate->devicePath(); + } QString p; QTextStream s( &p ); - s << (void *)candidate; + s << (void*)candidate; return p; } @@ -111,9 +119,9 @@ canBeReplaced( Partition* candidate ) Logger::CDebug deb; deb << Logger::SubEntry << "NO, insufficient storage"; deb << Logger::Continuation << "Required storage B:" << requiredStorageB - << QString( "(%1GiB)" ).arg( requiredStorageGiB ); + << QString( "(%1GiB)" ).arg( requiredStorageGiB ); deb << Logger::Continuation << "Available storage B:" << availableStorageB - << QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) ); + << QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) ); return false; } } @@ -129,11 +137,10 @@ canBeResized( Partition* candidate ) } cDebug() << "Checking if" << convenienceName( candidate ) << "can be resized."; - if ( !candidate->fileSystem().supportGrow() || - !candidate->fileSystem().supportShrink() ) + if ( !candidate->fileSystem().supportGrow() || !candidate->fileSystem().supportShrink() ) { cDebug() << Logger::SubEntry << "NO, filesystem" << candidate->fileSystem().name() - << "does not support resize."; + << "does not support resize."; return false; } @@ -160,8 +167,8 @@ canBeResized( Partition* candidate ) if ( table->numPrimaries() >= table->maxPrimaries() ) { - cDebug() << Logger::SubEntry << "NO, partition table already has" - << table->maxPrimaries() << "primary partitions."; + cDebug() << Logger::SubEntry << "NO, partition table already has" << table->maxPrimaries() + << "primary partitions."; return false; } } @@ -189,11 +196,11 @@ canBeResized( Partition* candidate ) Logger::CDebug deb; deb << Logger::SubEntry << "NO, insufficient storage"; deb << Logger::Continuation << "Required storage B:" << advisedStorageB - << QString( "(%1GiB)" ).arg( advisedStorageGiB ); + << QString( "(%1GiB)" ).arg( advisedStorageGiB ); deb << Logger::Continuation << "Available storage B:" << availableStorageB - << QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) ) - << "for" << convenienceName( candidate ) << "length:" << candidate->length() - << "sectorsUsed:" << candidate->sectorsUsed() << "fsType:" << candidate->fileSystem().name(); + << QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) ) << "for" + << convenienceName( candidate ) << "length:" << candidate->length() + << "sectorsUsed:" << candidate->sectorsUsed() << "fsType:" << candidate->fileSystem().name(); return false; } } @@ -227,27 +234,28 @@ canBeResized( PartitionCoreModule* core, const QString& partitionPath ) static FstabEntryList lookForFstabEntries( const QString& partitionPath ) { - QStringList mountOptions{ "ro" }; + QStringList mountOptions { "ro" }; - auto r = CalamaresUtils::System::runCommand( - CalamaresUtils::System::RunLocation::RunInHost, - { "blkid", "-s", "TYPE", "-o", "value", partitionPath } - ); + auto r = CalamaresUtils::System::runCommand( CalamaresUtils::System::RunLocation::RunInHost, + { "blkid", "-s", "TYPE", "-o", "value", partitionPath } ); if ( r.getExitCode() ) + { cWarning() << "blkid on" << partitionPath << "failed."; + } else { QString fstype = r.getOutput().trimmed(); if ( ( fstype == "ext3" ) || ( fstype == "ext4" ) ) + { mountOptions.append( "noload" ); + } } - cDebug() << "Checking device" << partitionPath - << "for fstab (fs=" << r.getOutput() << ')'; + cDebug() << "Checking device" << partitionPath << "for fstab (fs=" << r.getOutput() << ')'; FstabEntryList fstabEntries; - CalamaresUtils::Partition::TemporaryMount mount( partitionPath, QString(), mountOptions.join(',') ); + CalamaresUtils::Partition::TemporaryMount mount( partitionPath, QString(), mountOptions.join( ',' ) ); if ( mount.isValid() ) { QFile fstabFile( mount.path() + "/etc/fstab" ); @@ -256,32 +264,39 @@ lookForFstabEntries( const QString& partitionPath ) if ( fstabFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) { - const QStringList fstabLines = QString::fromLocal8Bit( fstabFile.readAll() ) - .split( '\n' ); + const QStringList fstabLines = QString::fromLocal8Bit( fstabFile.readAll() ).split( '\n' ); for ( const QString& rawLine : fstabLines ) + { fstabEntries.append( FstabEntry::fromEtcFstab( rawLine ) ); + } fstabFile.close(); cDebug() << Logger::SubEntry << "got" << fstabEntries.count() << "lines."; - std::remove_if( fstabEntries.begin(), fstabEntries.end(), [](const FstabEntry& x) { return !x.isValid(); } ); + std::remove_if( + fstabEntries.begin(), fstabEntries.end(), []( const FstabEntry& x ) { return !x.isValid(); } ); cDebug() << Logger::SubEntry << "got" << fstabEntries.count() << "fstab entries."; } else + { cWarning() << "Could not read fstab from mounted fs"; + } } else + { cWarning() << "Could not mount existing fs"; + } return fstabEntries; } static QString -findPartitionPathForMountPoint( const FstabEntryList& fstab, - const QString& mountPoint ) +findPartitionPathForMountPoint( const FstabEntryList& fstab, const QString& mountPoint ) { if ( fstab.isEmpty() ) + { return QString(); + } for ( const FstabEntry& entry : fstab ) { @@ -290,7 +305,7 @@ findPartitionPathForMountPoint( const FstabEntryList& fstab, QProcess readlink; QString partPath; - if ( entry.partitionNode.startsWith( "/dev" ) ) // plain dev node + if ( entry.partitionNode.startsWith( "/dev" ) ) // plain dev node { partPath = entry.partitionNode; } @@ -325,17 +340,22 @@ findPartitionPathForMountPoint( const FstabEntryList& fstab, // At this point we either have /dev/sda1, or /dev/disk/by-something/... - if ( partPath.startsWith( "/dev/disk/by-" ) ) // we got a fancy node + if ( partPath.startsWith( "/dev/disk/by-" ) ) // we got a fancy node { - readlink.start( "readlink", { "-en", partPath }); + readlink.start( "readlink", { "-en", partPath } ); if ( !readlink.waitForStarted( 1000 ) ) + { return QString(); + } if ( !readlink.waitForFinished( 1000 ) ) + { return QString(); + } if ( readlink.exitCode() != 0 || readlink.exitStatus() != QProcess::NormalExit ) + { return QString(); - partPath = QString::fromLocal8Bit( - readlink.readAllStandardOutput() ).trimmed(); + } + partPath = QString::fromLocal8Bit( readlink.readAllStandardOutput() ).trimmed(); } return partPath; @@ -364,9 +384,7 @@ runOsprober( PartitionCoreModule* core ) } else { - osproberOutput.append( - QString::fromLocal8Bit( - osprober.readAllStandardOutput() ).trimmed() ); + osproberOutput.append( QString::fromLocal8Bit( osprober.readAllStandardOutput() ).trimmed() ); } QStringList osproberCleanLines; @@ -379,32 +397,37 @@ runOsprober( PartitionCoreModule* core ) QStringList lineColumns = line.split( ':' ); QString prettyName; if ( !lineColumns.value( 1 ).simplified().isEmpty() ) + { prettyName = lineColumns.value( 1 ).simplified(); + } else if ( !lineColumns.value( 2 ).simplified().isEmpty() ) + { prettyName = lineColumns.value( 2 ).simplified(); + } QString path = lineColumns.value( 0 ).simplified(); - if ( !path.startsWith( "/dev/" ) ) //basic sanity check + if ( !path.startsWith( "/dev/" ) ) //basic sanity check + { continue; + } FstabEntryList fstabEntries = lookForFstabEntries( path ); QString homePath = findPartitionPathForMountPoint( fstabEntries, "/home" ); - osproberEntries.append( { prettyName, - path, - QString(), - canBeResized( core, path ), - lineColumns, - fstabEntries, - homePath } ); + osproberEntries.append( + { prettyName, path, QString(), canBeResized( core, path ), lineColumns, fstabEntries, homePath } ); osproberCleanLines.append( line ); } } if ( osproberCleanLines.count() > 0 ) + { cDebug() << "os-prober lines after cleanup:" << Logger::DebugList( osproberCleanLines ); + } else + { cDebug() << "os-prober gave no output."; + } Calamares::JobQueue::instance()->globalStorage()->insert( "osproberLines", osproberCleanLines ); @@ -427,24 +450,28 @@ isEfiBootable( const Partition* candidate ) /* If bit 17 is set, old-style Esp flag, it's OK */ if ( flags.testFlag( KPM_PARTITION_FLAG_ESP ) ) + { return true; + } /* Otherwise, if it's a GPT table, Boot (bit 0) is the same as Esp */ const PartitionNode* root = candidate; while ( root && !root->isRoot() ) { root = root->parent(); - cDebug() << Logger::SubEntry << "moved towards root" << (void *)root; + cDebug() << Logger::SubEntry << "moved towards root" << (void*)root; } // Strange case: no root found, no partition table node? if ( !root ) + { return false; + } - const PartitionTable* table = dynamic_cast( root ); - cDebug() << Logger::SubEntry << "partition table" << (void *)table << "type" << ( table ? table->type() : PartitionTable::TableType::unknownTableType ); - return table && ( table->type() == PartitionTable::TableType::gpt ) && - flags.testFlag( KPM_PARTITION_FLAG(Boot) ); + const PartitionTable* table = dynamic_cast< const PartitionTable* >( root ); + cDebug() << Logger::SubEntry << "partition table" << (void*)table << "type" + << ( table ? table->type() : PartitionTable::TableType::unknownTableType ); + return table && ( table->type() == PartitionTable::TableType::gpt ) && flags.testFlag( KPM_PARTITION_FLAG( Boot ) ); } QString @@ -452,14 +479,18 @@ findFS( QString fsName, FileSystem::Type* fsType ) { QStringList fsLanguage { QLatin1String( "C" ) }; // Required language list to turn off localization if ( fsName.isEmpty() ) + { fsName = QStringLiteral( "ext4" ); + } FileSystem::Type tmpType = FileSystem::typeForName( fsName, fsLanguage ); if ( tmpType != FileSystem::Unknown ) { cDebug() << "Found filesystem" << fsName; if ( fsType ) + { *fsType = tmpType; + } return fsName; } @@ -472,7 +503,9 @@ findFS( QString fsName, FileSystem::Type* fsType ) QString fsRealName = FileSystem::nameForType( t, fsLanguage ); cDebug() << "Filesystem name" << fsName << "translated to" << fsRealName; if ( fsType ) + { *fsType = t; + } return fsRealName; } } @@ -480,8 +513,10 @@ findFS( QString fsName, FileSystem::Type* fsType ) cDebug() << "Filesystem" << fsName << "not found, using ext4"; fsName = QStringLiteral( "ext4" ); // fsType can be used to check whether fsName was a valid filesystem. - if (fsType) + if ( fsType ) + { *fsType = FileSystem::Unknown; + } #ifdef DEBUG_FILESYSTEMS // This bit is for distro's debugging their settings, and shows // all the strings that KPMCore is matching against for FS type. @@ -491,13 +526,15 @@ findFS( QString fsName, FileSystem::Type* fsType ) const auto fstypes = FileSystem::types(); d << "Available types (" << fstypes.count() << ')'; for ( FileSystem::Type t : fstypes ) - d << TR( static_cast( t ), FileSystem::nameForType( t, fsLanguage ) ); + { + d << TR( static_cast< int >( t ), FileSystem::nameForType( t, fsLanguage ) ); + } } #endif return fsName; } -} // nmamespace PartUtils +} // namespace PartUtils /* Implementation of methods for FstabEntry, from OsproberEntry.h */ @@ -512,17 +549,18 @@ FstabEntry::fromEtcFstab( const QString& rawLine ) { QString line = rawLine.simplified(); if ( line.startsWith( '#' ) ) - return FstabEntry{ QString(), QString(), QString(), QString(), 0, 0 }; + return FstabEntry { QString(), QString(), QString(), QString(), 0, 0 }; QStringList splitLine = line.split( ' ' ); if ( splitLine.length() != 6 ) - return FstabEntry{ QString(), QString(), QString(), QString(), 0, 0 }; + return FstabEntry { QString(), QString(), QString(), QString(), 0, 0 }; - return FstabEntry{ splitLine.at( 0 ), // path, or UUID, or LABEL, etc. - splitLine.at( 1 ), // mount point - splitLine.at( 2 ), // fs type - splitLine.at( 3 ), // options - splitLine.at( 4 ).toInt(), //dump - splitLine.at( 5 ).toInt() //pass - }; - } + return FstabEntry { + splitLine.at( 0 ), // path, or UUID, or LABEL, etc. + splitLine.at( 1 ), // mount point + splitLine.at( 2 ), // fs type + splitLine.at( 3 ), // options + splitLine.at( 4 ).toInt(), //dump + splitLine.at( 5 ).toInt() //pass + }; +} diff --git a/src/modules/partition/core/PartUtils.h b/src/modules/partition/core/PartUtils.h index 1b4ee0b71..0db49d043 100644 --- a/src/modules/partition/core/PartUtils.h +++ b/src/modules/partition/core/PartUtils.h @@ -22,8 +22,8 @@ #define PARTUTILS_H #include "OsproberEntry.h" -#include "utils/Units.h" #include "utils/NamedSuffix.h" +#include "utils/Units.h" // KPMcore #include @@ -99,6 +99,6 @@ bool isEfiBootable( const Partition* candidate ); */ QString findFS( QString fsName, FileSystem::Type* fsType ); -} +} // namespace PartUtils -#endif // PARTUTILS_H +#endif // PARTUTILS_H diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index f0d5acdd9..5e785c9d1 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -21,13 +21,13 @@ #include "PartitionActions.h" #include "core/KPMHelpers.h" -#include "core/PartitionInfo.h" -#include "core/PartitionCoreModule.h" #include "core/PartUtils.h" +#include "core/PartitionCoreModule.h" +#include "core/PartitionInfo.h" #include "utils/CalamaresUtilsSystem.h" -#include "utils/Units.h" #include "utils/NamedEnum.h" +#include "utils/Units.h" #include "GlobalStorage.h" #include "JobQueue.h" @@ -47,7 +47,9 @@ qint64 swapSuggestion( const qint64 availableSpaceB, Choices::SwapChoice swap ) { if ( ( swap != Choices::SmallSwap ) && ( swap != Choices::FullSwap ) ) + { return 0; + } // See partition.conf for explanation qint64 suggestedSwapSizeB = 0; @@ -59,15 +61,23 @@ swapSuggestion( const qint64 availableSpaceB, Choices::SwapChoice swap ) // Ramp up quickly to 8GiB, then follow memory size if ( availableRamB <= 4_GiB ) + { suggestedSwapSizeB = availableRamB * 2; + } else if ( availableRamB <= 8_GiB ) + { suggestedSwapSizeB = 8_GiB; + } else + { suggestedSwapSizeB = availableRamB; + } // .. top out at 8GiB if we don't care about suspend if ( !ensureSuspendToDisk ) + { suggestedSwapSizeB = qMin( 8_GiB, suggestedSwapSizeB ); + } // Allow for a fudge factor @@ -75,7 +85,9 @@ swapSuggestion( const qint64 availableSpaceB, Choices::SwapChoice swap ) // don't use more than 10% of available space if ( !ensureSuspendToDisk ) + { suggestedSwapSizeB = qMin( suggestedSwapSizeB, qint64( 0.10 * availableSpaceB ) ); + } cDebug() << "Suggested swap size:" << suggestedSwapSizeB / 1024. / 1024. / 1024. << "GiB"; @@ -88,7 +100,9 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); QString defaultFsType = o.defaultFsType; if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown ) + { defaultFsType = "ext4"; + } bool isEfi = PartUtils::isEfiSystem(); @@ -103,8 +117,8 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO { if ( gs->contains( "efiSystemPartitionSize" ) ) { - CalamaresUtils::Partition::PartitionSize part_size = CalamaresUtils::Partition::PartitionSize( - gs->value( "efiSystemPartitionSize" ).toString() ); + CalamaresUtils::Partition::PartitionSize part_size + = CalamaresUtils::Partition::PartitionSize( gs->value( "efiSystemPartitionSize" ).toString() ); uefisys_part_sizeB = part_size.toBytes( dev->capacity() ); } else @@ -128,15 +142,13 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO // firstFreeSector..firstFreeSector+efiSectorCount-1. qint64 lastSector = firstFreeSector + efiSectorCount - 1; core->createPartitionTable( dev, PartitionTable::gpt ); - Partition* efiPartition = KPMHelpers::createNewPartition( - dev->partitionTable(), - *dev, - PartitionRole( PartitionRole::Primary ), - FileSystem::Fat32, - firstFreeSector, - lastSector, - KPM_PARTITION_FLAG(None) - ); + Partition* efiPartition = KPMHelpers::createNewPartition( dev->partitionTable(), + *dev, + PartitionRole( PartitionRole::Primary ), + FileSystem::Fat32, + firstFreeSector, + lastSector, + KPM_PARTITION_FLAG( None ) ); PartitionInfo::setFormat( efiPartition, true ); PartitionInfo::setMountPoint( efiPartition, o.efiPartitionMountPoint ); core->createPartition( dev, efiPartition, KPM_PARTITION_FLAG_ESP ); @@ -164,7 +176,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO shouldCreateSwap = availableSpaceB > requiredSpaceB; } - qint64 lastSectorForRoot = dev->totalLogical() - 1; //last sector of the device + qint64 lastSectorForRoot = dev->totalLogical() - 1; //last sector of the device if ( shouldCreateSwap ) { lastSectorForRoot -= suggestedSwapSizeB / dev->logicalSize() + 1; @@ -177,28 +189,24 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO Partition* swapPartition = nullptr; if ( o.luksPassphrase.isEmpty() ) { - swapPartition = KPMHelpers::createNewPartition( - dev->partitionTable(), - *dev, - PartitionRole( PartitionRole::Primary ), - FileSystem::LinuxSwap, - lastSectorForRoot + 1, - dev->totalLogical() - 1, - KPM_PARTITION_FLAG(None) - ); + swapPartition = KPMHelpers::createNewPartition( dev->partitionTable(), + *dev, + PartitionRole( PartitionRole::Primary ), + FileSystem::LinuxSwap, + lastSectorForRoot + 1, + dev->totalLogical() - 1, + KPM_PARTITION_FLAG( None ) ); } else { - swapPartition = KPMHelpers::createNewEncryptedPartition( - dev->partitionTable(), - *dev, - PartitionRole( PartitionRole::Primary ), - FileSystem::LinuxSwap, - lastSectorForRoot + 1, - dev->totalLogical() - 1, - o.luksPassphrase, - KPM_PARTITION_FLAG(None) - ); + swapPartition = KPMHelpers::createNewEncryptedPartition( dev->partitionTable(), + *dev, + PartitionRole( PartitionRole::Primary ), + FileSystem::LinuxSwap, + lastSectorForRoot + 1, + dev->totalLogical() - 1, + o.luksPassphrase, + KPM_PARTITION_FLAG( None ) ); } PartitionInfo::setFormat( swapPartition, true ); core->createPartition( dev, swapPartition ); @@ -209,10 +217,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO void -doReplacePartition( PartitionCoreModule* core, - Device* dev, - Partition* partition, - Choices::ReplacePartitionOptions o ) +doReplacePartition( PartitionCoreModule* core, Device* dev, Partition* partition, Choices::ReplacePartitionOptions o ) { qint64 firstSector, lastSector; @@ -220,11 +225,15 @@ doReplacePartition( PartitionCoreModule* core, QString defaultFsType = o.defaultFsType; if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown ) + { defaultFsType = "ext4"; + } PartitionRole newRoles( partition->roles() ); if ( partition->roles().has( PartitionRole::Extended ) ) + { newRoles = PartitionRole( PartitionRole::Primary ); + } if ( partition->roles().has( PartitionRole::Unallocated ) ) { @@ -234,7 +243,9 @@ doReplacePartition( PartitionCoreModule* core, { Partition* parent = dynamic_cast< Partition* >( partition->parent() ); if ( parent && parent->roles().has( PartitionRole::Extended ) ) + { newRoles = PartitionRole( PartitionRole::Logical ); + } } } @@ -242,7 +253,9 @@ doReplacePartition( PartitionCoreModule* core, firstSector = partition->firstSector(); lastSector = partition->lastSector(); if ( !partition->roles().has( PartitionRole::Unallocated ) ) + { core->deletePartition( dev, partition ); + } core->layoutApply( dev, firstSector, lastSector, o.luksPassphrase ); @@ -251,16 +264,14 @@ doReplacePartition( PartitionCoreModule* core, namespace Choices { -static const NamedEnumTable& +static const NamedEnumTable< SwapChoice >& nameTable() { - static const NamedEnumTable names{ - { QStringLiteral( "none" ), SwapChoice::NoSwap }, - { QStringLiteral( "small" ), SwapChoice::SmallSwap }, - { QStringLiteral( "suspend" ), SwapChoice::FullSwap }, - { QStringLiteral( "reuse" ), SwapChoice::ReuseSwap }, - { QStringLiteral( "file" ), SwapChoice::SwapFile } - }; + static const NamedEnumTable< SwapChoice > names { { QStringLiteral( "none" ), SwapChoice::NoSwap }, + { QStringLiteral( "small" ), SwapChoice::SmallSwap }, + { QStringLiteral( "suspend" ), SwapChoice::FullSwap }, + { QStringLiteral( "reuse" ), SwapChoice::ReuseSwap }, + { QStringLiteral( "file" ), SwapChoice::SwapFile } }; return names; } diff --git a/src/modules/partition/core/PartitionActions.h b/src/modules/partition/core/PartitionActions.h index cc9716123..ed7045822 100644 --- a/src/modules/partition/core/PartitionActions.h +++ b/src/modules/partition/core/PartitionActions.h @@ -33,45 +33,49 @@ namespace PartitionActions */ namespace Choices { - /** @brief Ccchoice of swap (size and type) */ - enum SwapChoice +/** @brief Ccchoice of swap (size and type) */ +enum SwapChoice +{ + NoSwap, // don't create any swap, don't use any + ReuseSwap, // don't create, but do use existing + SmallSwap, // up to 8GiB of swap + FullSwap, // ensureSuspendToDisk -- at least RAM size + SwapFile // use a file (if supported) +}; + +SwapChoice nameToChoice( QString name, bool& ok ); +QString choiceToName( SwapChoice ); + +struct ReplacePartitionOptions +{ + QString defaultFsType; // e.g. "ext4" or "btrfs" + QString luksPassphrase; // optional + + ReplacePartitionOptions( const QString& fs, const QString& luks ) + : defaultFsType( fs ) + , luksPassphrase( luks ) { - NoSwap, // don't create any swap, don't use any - ReuseSwap, // don't create, but do use existing - SmallSwap, // up to 8GiB of swap - FullSwap, // ensureSuspendToDisk -- at least RAM size - SwapFile // use a file (if supported) - }; + } +}; - SwapChoice nameToChoice( QString name, bool& ok ); - QString choiceToName( SwapChoice ); +struct AutoPartitionOptions : ReplacePartitionOptions +{ + QString efiPartitionMountPoint; // optional, e.g. "/boot" + quint64 requiredSpaceB; // estimated required space for root partition + SwapChoice swap; - struct ReplacePartitionOptions + AutoPartitionOptions( const QString& fs, + const QString& luks, + const QString& efi, + qint64 requiredBytes, + SwapChoice s ) + : ReplacePartitionOptions( fs, luks ) + , efiPartitionMountPoint( efi ) + , requiredSpaceB( requiredBytes > 0 ? static_cast< quint64 >( requiredBytes ) : 0 ) + , swap( s ) { - QString defaultFsType; // e.g. "ext4" or "btrfs" - QString luksPassphrase; // optional - - ReplacePartitionOptions( const QString& fs, const QString& luks ) - : defaultFsType( fs ) - , luksPassphrase( luks ) - { - } - }; - - struct AutoPartitionOptions : ReplacePartitionOptions - { - QString efiPartitionMountPoint; // optional, e.g. "/boot" - quint64 requiredSpaceB; // estimated required space for root partition - SwapChoice swap; - - AutoPartitionOptions( const QString& fs, const QString& luks, const QString& efi, qint64 requiredBytes, SwapChoice s ) - : ReplacePartitionOptions( fs, luks ) - , efiPartitionMountPoint( efi ) - , requiredSpaceB( requiredBytes > 0 ? static_cast( requiredBytes ) : 0 ) - , swap( s ) - { - } - }; + } +}; } // namespace Choices @@ -81,9 +85,7 @@ namespace Choices * @param dev the device to wipe. * @param options settings for autopartitioning. */ -void doAutopartition( PartitionCoreModule* core, - Device* dev, - Choices::AutoPartitionOptions options ); +void doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionOptions options ); /** * @brief doReplacePartition sets up replace-partitioning with the given partition. @@ -100,4 +102,4 @@ void doReplacePartition( PartitionCoreModule* core, Choices::ReplacePartitionOptions options ); } // namespace PartitionActions -#endif // PARTITIONACTIONS_H +#endif // PARTITIONACTIONS_H diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index cd5d009f0..5d4d8f3cd 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -26,10 +26,10 @@ #include "core/ColorUtils.h" #include "core/DeviceList.h" #include "core/DeviceModel.h" -#include "core/PartitionInfo.h" -#include "core/PartitionModel.h" #include "core/KPMHelpers.h" #include "core/PartUtils.h" +#include "core/PartitionInfo.h" +#include "core/PartitionModel.h" #include "jobs/ClearMountsJob.h" #include "jobs/ClearTempMountsJob.h" #include "jobs/CreatePartitionJob.h" @@ -53,28 +53,28 @@ #include "utils/Variant.h" // KPMcore +#include +#include #include #include #include #include -#include -#include #include #include #include // Qt -#include #include -#include #include +#include +#include #include -using CalamaresUtils::Partition::PartitionIterator; using CalamaresUtils::Partition::isPartitionFreeSpace; using CalamaresUtils::Partition::isPartitionNew; +using CalamaresUtils::Partition::PartitionIterator; -PartitionCoreModule::RefreshHelper::RefreshHelper(PartitionCoreModule* module) +PartitionCoreModule::RefreshHelper::RefreshHelper( PartitionCoreModule* module ) : m_module( module ) { } @@ -102,7 +102,7 @@ private: // called in *reverse* order of declaration in this class. PartitionCoreModule::RefreshHelper m_coreHelper; PartitionModel::ResetHelper m_modelHelper; -} ; +}; //- DeviceInfo --------------------------------------------- @@ -111,19 +111,20 @@ PartitionCoreModule::DeviceInfo::DeviceInfo( Device* _device ) , partitionModel( new PartitionModel ) , immutableDevice( new Device( *_device ) ) , isAvailable( true ) -{} - -PartitionCoreModule::DeviceInfo::~DeviceInfo() { } +PartitionCoreModule::DeviceInfo::~DeviceInfo() {} + void PartitionCoreModule::DeviceInfo::forgetChanges() { jobs.clear(); for ( auto it = PartitionIterator::begin( device.data() ); it != PartitionIterator::end( device.data() ); ++it ) + { PartitionInfo::reset( *it ); + } partitionModel->revert(); } @@ -132,11 +133,15 @@ bool PartitionCoreModule::DeviceInfo::isDirty() const { if ( !jobs.isEmpty() ) + { return true; + } for ( auto it = PartitionIterator::begin( device.data() ); it != PartitionIterator::end( device.data() ); ++it ) if ( PartitionInfo::isDirty( *it ) ) + { return true; + } return false; } @@ -148,7 +153,9 @@ PartitionCoreModule::PartitionCoreModule( QObject* parent ) , m_bootLoaderModel( new BootLoaderModel( this ) ) { if ( !m_kpmcore ) + { qFatal( "Failed to initialize KPMcore backend" ); + } } @@ -197,33 +204,39 @@ PartitionCoreModule::doInit() for ( auto deviceInfo : m_deviceInfos ) { for ( auto it = PartitionIterator::begin( deviceInfo->device.data() ); - it != PartitionIterator::end( deviceInfo->device.data() ); ++it ) + it != PartitionIterator::end( deviceInfo->device.data() ); + ++it ) { Partition* partition = *it; - for ( auto jt = m_osproberLines.begin(); - jt != m_osproberLines.end(); ++jt ) + for ( auto jt = m_osproberLines.begin(); jt != m_osproberLines.end(); ++jt ) { - if ( jt->path == partition->partitionPath() && - partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone && - !partition->fileSystem().uuid().isEmpty() ) + if ( jt->path == partition->partitionPath() + && partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone + && !partition->fileSystem().uuid().isEmpty() ) + { jt->uuid = partition->fileSystem().uuid(); + } } } } for ( auto deviceInfo : m_deviceInfos ) + { deviceInfo->partitionModel->init( deviceInfo->device.data(), m_osproberLines ); + } DeviceList bootLoaderDevices; - for ( DeviceList::Iterator it = devices.begin(); it != devices.end(); ++it) - if ( (*it)->type() != Device::Type::Disk_Device ) + for ( DeviceList::Iterator it = devices.begin(); it != devices.end(); ++it ) + if ( ( *it )->type() != Device::Type::Disk_Device ) { cDebug() << "Ignoring device that is not Disk_Device to bootLoaderDevices list."; continue; } else - bootLoaderDevices.append(*it); + { + bootLoaderDevices.append( *it ); + } m_bootLoaderModel->init( bootLoaderDevices ); @@ -232,7 +245,9 @@ PartitionCoreModule::doInit() //FIXME: this should be removed in favor of // proper KPM support for EFI if ( PartUtils::isEfiSystem() ) + { scanForEfiSystemPartitions(); + } } PartitionCoreModule::~PartitionCoreModule() @@ -267,7 +282,9 @@ PartitionCoreModule::immutableDeviceCopy( const Device* device ) Q_ASSERT( device ); DeviceInfo* info = infoForDevice( device ); if ( !info ) + { return nullptr; + } return info->immutableDevice.data(); } @@ -291,9 +308,7 @@ PartitionCoreModule::createPartitionTable( Device* device, PartitionTable::Table } void -PartitionCoreModule::createPartition( Device* device, - Partition* partition, - PartitionTable::Flags flags ) +PartitionCoreModule::createPartition( Device* device, Partition* partition, PartitionTable::Flags flags ) { auto deviceInfo = infoForDevice( device ); Q_ASSERT( deviceInfo ); @@ -304,7 +319,7 @@ PartitionCoreModule::createPartition( Device* device, deviceInfo->jobs << Calamares::job_ptr( job ); - if ( flags != KPM_PARTITION_FLAG(None) ) + if ( flags != KPM_PARTITION_FLAG( None ) ) { SetPartFlagsJob* fJob = new SetPartFlagsJob( device, partition, flags ); deviceInfo->jobs << Calamares::job_ptr( fJob ); @@ -313,21 +328,23 @@ PartitionCoreModule::createPartition( Device* device, } void -PartitionCoreModule::createVolumeGroup( QString &vgName, - QVector< const Partition* > pvList, - qint32 peSize ) +PartitionCoreModule::createVolumeGroup( QString& vgName, QVector< const Partition* > pvList, qint32 peSize ) { // Appending '_' character in case of repeated VG name while ( hasVGwithThisName( vgName ) ) - vgName.append('_'); + { + vgName.append( '_' ); + } CreateVolumeGroupJob* job = new CreateVolumeGroupJob( vgName, pvList, peSize ); job->updatePreview(); - LvmDevice* device = new LvmDevice(vgName); + LvmDevice* device = new LvmDevice( vgName ); for ( const Partition* p : pvList ) + { device->physicalVolumes() << p; + } DeviceInfo* deviceInfo = new DeviceInfo( device ); @@ -342,7 +359,7 @@ PartitionCoreModule::createVolumeGroup( QString &vgName, } void -PartitionCoreModule::resizeVolumeGroup( LvmDevice *device, QVector< const Partition* >& pvList ) +PartitionCoreModule::resizeVolumeGroup( LvmDevice* device, QVector< const Partition* >& pvList ) { DeviceInfo* deviceInfo = infoForDevice( device ); Q_ASSERT( deviceInfo ); @@ -355,7 +372,7 @@ PartitionCoreModule::resizeVolumeGroup( LvmDevice *device, QVector< const Partit } void -PartitionCoreModule::deactivateVolumeGroup( LvmDevice *device ) +PartitionCoreModule::deactivateVolumeGroup( LvmDevice* device ) { DeviceInfo* deviceInfo = infoForDevice( device ); Q_ASSERT( deviceInfo ); @@ -371,7 +388,7 @@ PartitionCoreModule::deactivateVolumeGroup( LvmDevice *device ) } void -PartitionCoreModule::removeVolumeGroup( LvmDevice *device ) +PartitionCoreModule::removeVolumeGroup( LvmDevice* device ) { DeviceInfo* deviceInfo = infoForDevice( device ); Q_ASSERT( deviceInfo ); @@ -399,28 +416,35 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition ) QList< Partition* > lst; for ( auto childPartition : partition->children() ) if ( !isPartitionFreeSpace( childPartition ) ) + { lst << childPartition; + } for ( auto childPartition : lst ) + { deletePartition( device, childPartition ); + } } Calamares::JobList& jobs = deviceInfo->jobs; - if ( partition->state() == KPM_PARTITION_STATE(New) ) + if ( partition->state() == KPM_PARTITION_STATE( New ) ) { // First remove matching SetPartFlagsJobs for ( auto it = jobs.begin(); it != jobs.end(); ) { SetPartFlagsJob* job = qobject_cast< SetPartFlagsJob* >( it->data() ); if ( job && job->partition() == partition ) + { it = jobs.erase( it ); + } else + { ++it; + } } // Find matching CreatePartitionJob - auto it = std::find_if( jobs.begin(), jobs.end(), [ partition ]( Calamares::job_ptr job ) - { + auto it = std::find_if( jobs.begin(), jobs.end(), [partition]( Calamares::job_ptr job ) { CreatePartitionJob* createJob = qobject_cast< CreatePartitionJob* >( job.data() ); return createJob && createJob->partition() == partition; } ); @@ -430,7 +454,7 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition ) return; } // Remove it - if ( ! partition->parent()->remove( partition ) ) + if ( !partition->parent()->remove( partition ) ) { cDebug() << "Failed to remove partition from preview"; return; @@ -449,9 +473,13 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition ) { PartitionJob* job = qobject_cast< PartitionJob* >( it->data() ); if ( job && job->partition() == partition ) + { it = jobs.erase( it ); + } else + { ++it; + } } DeletePartitionJob* job = new DeletePartitionJob( device, partition ); job->updatePreview(); @@ -471,10 +499,7 @@ PartitionCoreModule::formatPartition( Device* device, Partition* partition ) } void -PartitionCoreModule::resizePartition( Device* device, - Partition* partition, - qint64 first, - qint64 last ) +PartitionCoreModule::resizePartition( Device* device, Partition* partition, qint64 first, qint64 last ) { auto deviceInfo = infoForDevice( device ); Q_ASSERT( deviceInfo ); @@ -486,9 +511,7 @@ PartitionCoreModule::resizePartition( Device* device, } void -PartitionCoreModule::setPartitionFlags( Device* device, - Partition* partition, - PartitionTable::Flags flags ) +PartitionCoreModule::setPartitionFlags( Device* device, Partition* partition, PartitionTable::Flags flags ) { auto deviceInfo = infoForDevice( device ); Q_ASSERT( deviceInfo ); @@ -521,7 +544,9 @@ PartitionCoreModule::jobs() const for ( auto info : m_deviceInfos ) { if ( info->isDirty() ) + { lst << Calamares::job_ptr( new ClearMountsJob( info->device.data() ) ); + } } for ( auto info : m_deviceInfos ) @@ -555,18 +580,18 @@ PartitionCoreModule::lvmPVs() const bool PartitionCoreModule::hasVGwithThisName( const QString& name ) const { - auto condition = [ name ]( DeviceInfo* d ) { - return dynamic_cast(d->device.data()) && d->device.data()->name() == name; + auto condition = [name]( DeviceInfo* d ) { + return dynamic_cast< LvmDevice* >( d->device.data() ) && d->device.data()->name() == name; }; return std::find_if( m_deviceInfos.begin(), m_deviceInfos.end(), condition ) != m_deviceInfos.end(); } bool -PartitionCoreModule::isInVG( const Partition *partition ) const +PartitionCoreModule::isInVG( const Partition* partition ) const { - auto condition = [ partition ]( DeviceInfo* d ) { - LvmDevice* vg = dynamic_cast( d->device.data()); + auto condition = [partition]( DeviceInfo* d ) { + LvmDevice* vg = dynamic_cast< LvmDevice* >( d->device.data() ); return vg && vg->physicalVolumes().contains( partition ); }; @@ -581,7 +606,9 @@ PartitionCoreModule::dumpQueue() const { cDebug() << "## Device:" << info->device->name(); for ( auto job : info->jobs ) + { cDebug() << "-" << job->prettyName(); + } } } @@ -615,16 +642,21 @@ PartitionCoreModule::refreshAfterModelChange() //FIXME: this should be removed in favor of // proper KPM support for EFI if ( PartUtils::isEfiSystem() ) + { scanForEfiSystemPartitions(); + } } -void PartitionCoreModule::updateHasRootMountPoint() +void +PartitionCoreModule::updateHasRootMountPoint() { bool oldValue = m_hasRootMountPoint; m_hasRootMountPoint = findPartitionByMountPoint( "/" ); if ( oldValue != m_hasRootMountPoint ) + { hasRootMountPointChanged( m_hasRootMountPoint ); + } } void @@ -639,7 +671,9 @@ PartitionCoreModule::updateIsDirty() break; } if ( oldValue != m_isDirty ) + { isDirtyChanged( m_isDirty ); + } } void @@ -650,16 +684,17 @@ PartitionCoreModule::scanForEfiSystemPartitions() QList< Device* > devices; for ( int row = 0; row < deviceModel()->rowCount(); ++row ) { - Device* device = deviceModel()->deviceForIndex( - deviceModel()->index( row ) ); + Device* device = deviceModel()->deviceForIndex( deviceModel()->index( row ) ); devices.append( device ); } - QList< Partition* > efiSystemPartitions = - CalamaresUtils::Partition::findPartitions( devices, PartUtils::isEfiBootable ); + QList< Partition* > efiSystemPartitions + = CalamaresUtils::Partition::findPartitions( devices, PartUtils::isEfiBootable ); if ( efiSystemPartitions.isEmpty() ) + { cWarning() << "system is EFI but no EFI system partitions found."; + } m_efiSystemPartitions = efiSystemPartitions; } @@ -674,11 +709,13 @@ PartitionCoreModule::scanForLVMPVs() for ( DeviceInfo* deviceInfo : m_deviceInfos ) { - if ( deviceInfo->device.data()->type() == Device::Type::Disk_Device) + if ( deviceInfo->device.data()->type() == Device::Type::Disk_Device ) + { physicalDevices << deviceInfo->device.data(); + } else if ( deviceInfo->device.data()->type() == Device::Type::LVM_Device ) { - LvmDevice* device = dynamic_cast(deviceInfo->device.data()); + LvmDevice* device = dynamic_cast< LvmDevice* >( deviceInfo->device.data() ); // Restoring physical volume list device->physicalVolumes().clear(); @@ -711,29 +748,35 @@ PartitionCoreModule::scanForLVMPVs() for ( auto job : d->jobs ) { // Including new LVM PVs - CreatePartitionJob* partJob = dynamic_cast( job.data() ); + CreatePartitionJob* partJob = dynamic_cast< CreatePartitionJob* >( job.data() ); if ( partJob ) { Partition* p = partJob->partition(); if ( p->fileSystem().type() == FileSystem::Type::Lvm2_PV ) + { m_lvmPVs << p; + } else if ( p->fileSystem().type() == FileSystem::Type::Luks ) { // Encrypted LVM PVs - FileSystem* innerFS = static_cast(&p->fileSystem())->innerFS(); + FileSystem* innerFS = static_cast< const FS::luks* >( &p->fileSystem() )->innerFS(); if ( innerFS && innerFS->type() == FileSystem::Type::Lvm2_PV ) + { m_lvmPVs << p; + } } #if defined( WITH_KPMCORE4API ) else if ( p->fileSystem().type() == FileSystem::Type::Luks2 ) { // Encrypted LVM PVs - FileSystem* innerFS = static_cast(&p->fileSystem())->innerFS(); + FileSystem* innerFS = static_cast< const FS::luks* >( &p->fileSystem() )->innerFS(); if ( innerFS && innerFS->type() == FileSystem::Type::Lvm2_PV ) + { m_lvmPVs << p; + } } #endif } @@ -744,13 +787,16 @@ PartitionCoreModule::scanForLVMPVs() PartitionCoreModule::DeviceInfo* PartitionCoreModule::infoForDevice( const Device* device ) const { - for ( auto it = m_deviceInfos.constBegin(); - it != m_deviceInfos.constEnd(); ++it ) + for ( auto it = m_deviceInfos.constBegin(); it != m_deviceInfos.constEnd(); ++it ) { if ( ( *it )->device.data() == device ) + { return *it; + } if ( ( *it )->immutableDevice.data() == device ) + { return *it; + } } return nullptr; } @@ -763,7 +809,9 @@ PartitionCoreModule::findPartitionByMountPoint( const QString& mountPoint ) cons Device* device = deviceInfo->device.data(); for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it ) if ( PartitionInfo::mountPoint( *it ) == mountPoint ) + { return *it; + } } return nullptr; } @@ -780,7 +828,7 @@ PartitionCoreModule::initLayout() { m_partLayout = new PartitionLayout(); - m_partLayout->addEntry( QString("/"), QString("100%") ); + m_partLayout->addEntry( QString( "/" ), QString( "100%" ) ); } void @@ -796,42 +844,52 @@ PartitionCoreModule::initLayout( const QVariantList& config ) { QVariantMap pentry = r.toMap(); - if ( !pentry.contains( "name" ) || !pentry.contains( "mountPoint" ) || - !pentry.contains( "filesystem" ) || !pentry.contains( "size" ) ) + if ( !pentry.contains( "name" ) || !pentry.contains( "mountPoint" ) || !pentry.contains( "filesystem" ) + || !pentry.contains( "size" ) ) { - cError() << "Partition layout entry #" << config.indexOf(r) - << "lacks mandatory attributes, switching to default layout."; - delete( m_partLayout ); + cError() << "Partition layout entry #" << config.indexOf( r ) + << "lacks mandatory attributes, switching to default layout."; + delete ( m_partLayout ); initLayout(); break; } - if ( pentry.contains("size") && CalamaresUtils::getString( pentry, "size" ).isEmpty() ) + if ( pentry.contains( "size" ) && CalamaresUtils::getString( pentry, "size" ).isEmpty() ) + { sizeString.setNum( CalamaresUtils::getInteger( pentry, "size", 0 ) ); + } else + { sizeString = CalamaresUtils::getString( pentry, "size" ); + } - if ( pentry.contains("minSize") && CalamaresUtils::getString( pentry, "minSize" ).isEmpty() ) + if ( pentry.contains( "minSize" ) && CalamaresUtils::getString( pentry, "minSize" ).isEmpty() ) + { minSizeString.setNum( CalamaresUtils::getInteger( pentry, "minSize", 0 ) ); + } else + { minSizeString = CalamaresUtils::getString( pentry, "minSize" ); + } - if ( pentry.contains("maxSize") && CalamaresUtils::getString( pentry, "maxSize" ).isEmpty() ) + if ( pentry.contains( "maxSize" ) && CalamaresUtils::getString( pentry, "maxSize" ).isEmpty() ) + { maxSizeString.setNum( CalamaresUtils::getInteger( pentry, "maxSize", 0 ) ); + } else + { maxSizeString = CalamaresUtils::getString( pentry, "maxSize" ); + } if ( !m_partLayout->addEntry( CalamaresUtils::getString( pentry, "name" ), CalamaresUtils::getString( pentry, "mountPoint" ), CalamaresUtils::getString( pentry, "filesystem" ), sizeString, minSizeString, - maxSizeString - ) ) + maxSizeString ) ) { - cError() << "Partition layout entry #" << config.indexOf(r) - << "is invalid, switching to default layout."; - delete( m_partLayout ); + cError() << "Partition layout entry #" << config.indexOf( r ) << "is invalid, switching to default layout."; + delete ( m_partLayout ); initLayout(); break; } @@ -839,7 +897,7 @@ PartitionCoreModule::initLayout( const QVariantList& config ) } void -PartitionCoreModule::layoutApply( Device *dev, +PartitionCoreModule::layoutApply( Device* dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase, @@ -847,17 +905,14 @@ PartitionCoreModule::layoutApply( Device *dev, const PartitionRole& role ) { bool isEfi = PartUtils::isEfiSystem(); - QList< Partition* > partList = m_partLayout->execute( dev, firstSector, lastSector, - luksPassphrase, parent, role - ); + QList< Partition* > partList = m_partLayout->execute( dev, firstSector, lastSector, luksPassphrase, parent, role ); - foreach ( Partition *part, partList ) + foreach ( Partition* part, partList ) { if ( part->mountPoint() == "/" ) { - createPartition( dev, part, - part->activeFlags() | ( isEfi ? KPM_PARTITION_FLAG(None) : KPM_PARTITION_FLAG(Boot) ) - ); + createPartition( + dev, part, part->activeFlags() | ( isEfi ? KPM_PARTITION_FLAG( None ) : KPM_PARTITION_FLAG( Boot ) ) ); } else { @@ -867,14 +922,10 @@ PartitionCoreModule::layoutApply( Device *dev, } void -PartitionCoreModule::layoutApply( Device *dev, - qint64 firstSector, - qint64 lastSector, - QString luksPassphrase ) +PartitionCoreModule::layoutApply( Device* dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase ) { - layoutApply( dev, firstSector, lastSector, luksPassphrase, dev->partitionTable(), - PartitionRole( PartitionRole::Primary ) - ); + layoutApply( + dev, firstSector, lastSector, luksPassphrase, dev->partitionTable(), PartitionRole( PartitionRole::Primary ) ); } void @@ -895,13 +946,13 @@ PartitionCoreModule::revertAllDevices() 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 - if ( dynamic_cast( ( *it )->device.data() ) ) + if ( dynamic_cast< LvmDevice* >( ( *it )->device.data() ) ) { ( *it )->isAvailable = true; if ( !( *it )->jobs.empty() ) { - CreateVolumeGroupJob* vgJob = dynamic_cast( ( *it )->jobs[0].data() ); + CreateVolumeGroupJob* vgJob = dynamic_cast< CreateVolumeGroupJob* >( ( *it )->jobs[ 0 ].data() ); if ( vgJob ) { @@ -933,7 +984,9 @@ PartitionCoreModule::revertDevice( Device* dev, bool individualRevert ) DeviceInfo* devInfo = infoForDevice( dev ); if ( !devInfo ) + { return; + } devInfo->forgetChanges(); CoreBackend* backend = CoreBackendManager::self()->backend(); Device* newDev = backend->scanDevice( devInfo->device->deviceNode() ); @@ -946,13 +999,17 @@ PartitionCoreModule::revertDevice( Device* dev, bool individualRevert ) for ( DeviceInfo* const info : m_deviceInfos ) { if ( info && !info->device.isNull() && info->device->type() == Device::Type::Disk_Device ) + { devices.append( info->device.data() ); + } } m_bootLoaderModel->init( devices ); if ( individualRevert ) + { refreshAfterModelChange(); + } emit deviceReverted( newDev ); } @@ -961,9 +1018,7 @@ void PartitionCoreModule::asyncRevertDevice( Device* dev, std::function< void() > callback ) { QFutureWatcher< void >* watcher = new QFutureWatcher< void >(); - connect( watcher, &QFutureWatcher< void >::finished, - this, [ watcher, callback ] - { + connect( watcher, &QFutureWatcher< void >::finished, this, [watcher, callback] { callback(); watcher->deleteLater(); } ); @@ -977,7 +1032,9 @@ void PartitionCoreModule::clearJobs() { foreach ( DeviceInfo* deviceInfo, m_deviceInfos ) + { deviceInfo->forgetChanges(); + } updateIsDirty(); } @@ -989,11 +1046,13 @@ PartitionCoreModule::isDirty() } bool -PartitionCoreModule::isVGdeactivated( LvmDevice *device ) +PartitionCoreModule::isVGdeactivated( LvmDevice* device ) { for ( DeviceInfo* deviceInfo : m_deviceInfos ) if ( device == deviceInfo->device.data() && !deviceInfo->isAvailable ) + { return true; + } return false; } @@ -1005,7 +1064,9 @@ PartitionCoreModule::createSummaryInfo() const for ( auto deviceInfo : m_deviceInfos ) { if ( !deviceInfo->isDirty() ) + { continue; + } SummaryInfo summaryInfo; summaryInfo.deviceName = deviceInfo->device->name(); summaryInfo.deviceNode = deviceInfo->device->deviceNode(); diff --git a/src/modules/partition/core/PartitionCoreModule.h b/src/modules/partition/core/PartitionCoreModule.h index aaae67bab..eba3411db 100644 --- a/src/modules/partition/core/PartitionCoreModule.h +++ b/src/modules/partition/core/PartitionCoreModule.h @@ -139,10 +139,10 @@ public: * If @p flags is not FlagNone, then the given flags are * applied to the newly-created partition. */ - void createPartition( Device* device, Partition* partition, - PartitionTable::Flags flags = KPM_PARTITION_FLAG(None) ); + void + createPartition( Device* device, Partition* partition, PartitionTable::Flags flags = KPM_PARTITION_FLAG( None ) ); - void createVolumeGroup( QString &vgName, QVector< const Partition* > pvList, qint32 peSize ); + void createVolumeGroup( QString& vgName, QVector< const Partition* > pvList, qint32 peSize ); void resizeVolumeGroup( LvmDevice* device, QVector< const Partition* >& pvList ); @@ -166,8 +166,13 @@ public: void initLayout(); void initLayout( const QVariantList& config ); - void layoutApply( Device *dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase ); - void layoutApply( Device *dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase, PartitionNode* parent, const PartitionRole& role ); + void layoutApply( Device* dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase ); + void layoutApply( Device* dev, + qint64 firstSector, + qint64 lastSector, + QString luksPassphrase, + PartitionNode* parent, + const PartitionRole& role ); /** * @brief jobs creates and returns a list of jobs which can then apply the changes @@ -196,19 +201,19 @@ public: */ Partition* findPartitionByMountPoint( const QString& mountPoint ) const; - void revert(); // full revert, thread safe, calls doInit - void revertAllDevices(); // convenience function, calls revertDevice + void revert(); // full revert, thread safe, calls doInit + void revertAllDevices(); // convenience function, calls revertDevice /** @brief rescans a single Device and updates DeviceInfo * * When @p individualRevert is true, calls refreshAfterModelChange(), * used to reduce number of refreshes when calling revertAllDevices(). */ - void revertDevice( Device* dev, bool individualRevert=true ); - void asyncRevertDevice( Device* dev, std::function< void() > callback ); //like revertDevice, but asynchronous + void revertDevice( Device* dev, bool individualRevert = true ); + void asyncRevertDevice( Device* dev, std::function< void() > callback ); //like revertDevice, but asynchronous - void clearJobs(); // only clear jobs, the Device* states are preserved + void clearJobs(); // only clear jobs, the Device* states are preserved - bool isDirty(); // true if there are pending changes, otherwise false + bool isDirty(); // true if there are pending changes, otherwise false bool isVGdeactivated( LvmDevice* device ); @@ -225,9 +230,9 @@ public: */ QList< SummaryInfo > createSummaryInfo() const; - void dumpQueue() const; // debug output + void dumpQueue() const; // debug output - const OsproberEntryList osproberEntries() const; // os-prober data structure, cached + const OsproberEntryList osproberEntries() const; // os-prober data structure, cached Q_SIGNALS: void hasRootMountPointChanged( bool value ); diff --git a/src/modules/partition/core/PartitionInfo.cpp b/src/modules/partition/core/PartitionInfo.cpp index 3a2e5bbd3..fe38bf2d6 100644 --- a/src/modules/partition/core/PartitionInfo.cpp +++ b/src/modules/partition/core/PartitionInfo.cpp @@ -57,15 +57,19 @@ setFormat( Partition* partition, bool value ) partition->setProperty( FORMAT_PROPERTY, value ); } -PartitionTable::Flags flags(const Partition* partition) +PartitionTable::Flags +flags( const Partition* partition ) { auto v = partition->property( FLAGS_PROPERTY ); - if (v.type() == QVariant::Int ) - return static_cast( v.toInt() ); + if ( v.type() == QVariant::Int ) + { + return static_cast< PartitionTable::Flags >( v.toInt() ); + } return partition->activeFlags(); } -void setFlags(Partition* partition, PartitionTable::Flags f) +void +setFlags( Partition* partition, PartitionTable::Flags f ) { partition->setProperty( FLAGS_PROPERTY, PartitionTable::Flags::Int( f ) ); } @@ -82,11 +86,11 @@ bool isDirty( Partition* partition ) { if ( LvmDevice::s_DirtyPVs.contains( partition ) ) + { return true; + } - return !mountPoint( partition ).isEmpty() - || format( partition ) - || flags( partition ) != partition->activeFlags(); + return !mountPoint( partition ).isEmpty() || format( partition ) || flags( partition ) != partition->activeFlags(); } -} // namespace +} // namespace PartitionInfo diff --git a/src/modules/partition/core/PartitionInfo.h b/src/modules/partition/core/PartitionInfo.h index a9c391059..9f9cd2d1e 100644 --- a/src/modules/partition/core/PartitionInfo.h +++ b/src/modules/partition/core/PartitionInfo.h @@ -60,6 +60,6 @@ void reset( Partition* partition ); */ bool isDirty( Partition* partition ); -}; +}; // namespace PartitionInfo #endif /* PARTITIONINFO_H */ diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index 35b90722a..23332f3f5 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -26,9 +26,9 @@ #include "core/PartitionLayout.h" #include "core/KPMHelpers.h" +#include "core/PartUtils.h" #include "core/PartitionActions.h" #include "core/PartitionInfo.h" -#include "core/PartUtils.h" #include #include @@ -42,9 +42,11 @@ getDefaultFileSystemType() if ( gs->contains( "defaultFileSystemType" ) ) { - PartUtils::findFS( gs->value( "defaultFileSystemType" ).toString(), &defaultFS); + PartUtils::findFS( gs->value( "defaultFileSystemType" ).toString(), &defaultFS ); if ( defaultFS == FileSystem::Unknown ) + { defaultFS = FileSystem::Ext4; + } } return defaultFS; @@ -67,9 +69,7 @@ PartitionLayout::PartitionLayout( const PartitionLayout& layout ) { } -PartitionLayout::~PartitionLayout() -{ -} +PartitionLayout::~PartitionLayout() {} bool PartitionLayout::addEntry( PartitionLayout::PartitionEntry entry ) @@ -117,7 +117,12 @@ PartitionLayout::addEntry( const QString& mountPoint, const QString& size, const } bool -PartitionLayout::addEntry( const QString& label, const QString& mountPoint, const QString& fs, const QString& size, const QString& min, const QString& max ) +PartitionLayout::addEntry( const QString& label, + const QString& mountPoint, + const QString& fs, + const QString& size, + const QString& min, + const QString& max ) { PartitionLayout::PartitionEntry entry( size, min, max ); @@ -136,7 +141,9 @@ PartitionLayout::addEntry( const QString& label, const QString& mountPoint, cons entry.partMountPoint = mountPoint; PartUtils::findFS( fs, &entry.partFileSystem ); if ( entry.partFileSystem == FileSystem::Unknown ) + { entry.partFileSystem = m_defaultFsType; + } m_partLayout.append( entry ); @@ -144,8 +151,10 @@ PartitionLayout::addEntry( const QString& label, const QString& mountPoint, cons } QList< Partition* > -PartitionLayout::execute( Device *dev, qint64 firstSector, - qint64 lastSector, QString luksPassphrase, +PartitionLayout::execute( Device* dev, + qint64 firstSector, + qint64 lastSector, + QString luksPassphrase, PartitionNode* parent, const PartitionRole& role ) { @@ -157,9 +166,9 @@ PartitionLayout::execute( Device *dev, qint64 firstSector, // TODO: Refine partition sizes to make sure there is room for every partition // Use a default (200-500M ?) minimum size for partition without minSize - foreach( const PartitionLayout::PartitionEntry& part, m_partLayout ) + foreach ( const PartitionLayout::PartitionEntry& part, m_partLayout ) { - Partition *currentPartition = nullptr; + Partition* currentPartition = nullptr; qint64 size = -1; // Calculate partition size @@ -169,67 +178,67 @@ PartitionLayout::execute( Device *dev, qint64 firstSector, } else { - cWarning() << "Partition" << part.partMountPoint << "size (" - << size << "sectors) is invalid, skipping..."; + cWarning() << "Partition" << part.partMountPoint << "size (" << size << "sectors) is invalid, skipping..."; continue; } if ( part.partMinSize.isValid() ) + { minSize = part.partMinSize.toSectors( totalSize, dev->logicalSize() ); + } else + { minSize = 0; + } if ( part.partMaxSize.isValid() ) + { maxSize = part.partMaxSize.toSectors( totalSize, dev->logicalSize() ); + } else + { maxSize = availableSize; + } // Make sure we never go under minSize once converted to sectors if ( maxSize < minSize ) { - cWarning() << "Partition" << part.partMountPoint << "max size (" << maxSize - << "sectors) is < min size (" << minSize << "sectors), using min size"; + cWarning() << "Partition" << part.partMountPoint << "max size (" << maxSize << "sectors) is < min size (" + << minSize << "sectors), using min size"; maxSize = minSize; } // Adjust partition size based on user-defined boundaries and available space if ( size < minSize ) + { size = minSize; + } if ( size > maxSize ) + { size = maxSize; + } if ( size > availableSize ) + { size = availableSize; + } end = firstSector + size - 1; if ( luksPassphrase.isEmpty() ) { currentPartition = KPMHelpers::createNewPartition( - parent, - *dev, - role, - part.partFileSystem, - firstSector, - end, - KPM_PARTITION_FLAG(None) - ); + parent, *dev, role, part.partFileSystem, firstSector, end, KPM_PARTITION_FLAG( None ) ); } else { currentPartition = KPMHelpers::createNewEncryptedPartition( - parent, - *dev, - role, - part.partFileSystem, - firstSector, - end, - luksPassphrase, - KPM_PARTITION_FLAG(None) - ); + parent, *dev, role, part.partFileSystem, firstSector, end, luksPassphrase, KPM_PARTITION_FLAG( None ) ); } PartitionInfo::setFormat( currentPartition, true ); PartitionInfo::setMountPoint( currentPartition, part.partMountPoint ); if ( !part.partLabel.isEmpty() ) + { currentPartition->fileSystem().setLabel( part.partLabel ); + } // Some buggy (legacy) BIOSes test if the bootflag of at least one partition is set. // Otherwise they ignore the device in boot-order, so add it here. partList.append( currentPartition ); diff --git a/src/modules/partition/core/PartitionLayout.h b/src/modules/partition/core/PartitionLayout.h index a9b8d410b..50bb1ba43 100644 --- a/src/modules/partition/core/PartitionLayout.h +++ b/src/modules/partition/core/PartitionLayout.h @@ -37,7 +37,6 @@ class Partition; class PartitionLayout { public: - struct PartitionEntry { QString partLabel; @@ -54,9 +53,11 @@ public: bool isValid() const { - if ( !partSize.isValid() || - ( partMinSize.isValid() && partMaxSize.isValid() && partMinSize > partMaxSize ) ) + if ( !partSize.isValid() + || ( partMinSize.isValid() && partMaxSize.isValid() && partMinSize > partMaxSize ) ) + { return false; + } return true; } }; @@ -67,14 +68,27 @@ public: ~PartitionLayout(); bool addEntry( PartitionEntry entry ); - bool addEntry( const QString& mountPoint, const QString& size, const QString& min = QString(), const QString& max = QString() ); - bool addEntry( const QString& label, const QString& mountPoint, const QString& fs, const QString& size, const QString& min = QString(), const QString& max = QString() ); + bool addEntry( const QString& mountPoint, + const QString& size, + const QString& min = QString(), + const QString& max = QString() ); + bool addEntry( const QString& label, + const QString& mountPoint, + const QString& fs, + const QString& size, + const QString& min = QString(), + const QString& max = QString() ); /** * @brief Apply the current partition layout to the selected drive space. * @return A list of Partition objects. */ - QList< Partition* > execute( Device *dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase, PartitionNode* parent, const PartitionRole& role ); + QList< Partition* > execute( Device* dev, + qint64 firstSector, + qint64 lastSector, + QString luksPassphrase, + PartitionNode* parent, + const PartitionRole& role ); private: FileSystem::Type m_defaultFsType; diff --git a/src/modules/partition/core/PartitionModel.cpp b/src/modules/partition/core/PartitionModel.cpp index db3be50a6..d6f996c4f 100644 --- a/src/modules/partition/core/PartitionModel.cpp +++ b/src/modules/partition/core/PartitionModel.cpp @@ -20,8 +20,8 @@ #include "core/PartitionModel.h" #include "core/ColorUtils.h" -#include "core/PartitionInfo.h" #include "core/KPMHelpers.h" +#include "core/PartitionInfo.h" #include "partition/FileSystem.h" #include "partition/PartitionQuery.h" @@ -67,9 +67,9 @@ PartitionModel::PartitionModel( QObject* parent ) } void -PartitionModel::init( Device* device , const OsproberEntryList& osproberEntries ) +PartitionModel::init( Device* device, const OsproberEntryList& osproberEntries ) { - QMutexLocker lock(&m_lock); + QMutexLocker lock( &m_lock ); beginResetModel(); m_device = device; m_osproberEntries = osproberEntries; @@ -87,7 +87,9 @@ PartitionModel::rowCount( const QModelIndex& parent ) const { Partition* parentPartition = partitionForIndex( parent ); if ( parentPartition ) + { return parentPartition->children().count(); + } PartitionTable* table = m_device->partitionTable(); return table ? table->children().count() : 0; } @@ -95,16 +97,21 @@ PartitionModel::rowCount( const QModelIndex& parent ) const QModelIndex PartitionModel::index( int row, int column, const QModelIndex& parent ) const { - PartitionNode* parentPartition = parent.isValid() - ? static_cast< PartitionNode* >( partitionForIndex( parent ) ) - : static_cast< PartitionNode* >( m_device->partitionTable() ); + PartitionNode* parentPartition = parent.isValid() ? static_cast< PartitionNode* >( partitionForIndex( parent ) ) + : static_cast< PartitionNode* >( m_device->partitionTable() ); if ( !parentPartition ) + { return QModelIndex(); + } auto lst = parentPartition->children(); if ( row < 0 || row >= lst.count() ) + { return QModelIndex(); + } if ( column < 0 || column >= ColumnCount ) + { return QModelIndex(); + } Partition* partition = parentPartition->children().at( row ); return createIndex( row, column, partition ); } @@ -113,19 +120,27 @@ QModelIndex PartitionModel::parent( const QModelIndex& child ) const { if ( !child.isValid() ) + { return QModelIndex(); + } Partition* partition = partitionForIndex( child ); if ( !partition ) + { return QModelIndex(); + } PartitionNode* parentNode = partition->parent(); if ( parentNode == m_device->partitionTable() ) + { return QModelIndex(); + } int row = 0; for ( auto p : m_device->partitionTable()->children() ) { if ( parentNode == p ) + { return createIndex( row, 0, parentNode ); + } ++row; } cWarning() << "No parent found!"; @@ -137,7 +152,9 @@ PartitionModel::data( const QModelIndex& index, int role ) const { Partition* partition = partitionForIndex( index ); if ( !partition ) + { return QVariant(); + } switch ( role ) { @@ -147,18 +164,22 @@ PartitionModel::data( const QModelIndex& index, int role ) const if ( col == NameColumn ) { if ( isPartitionFreeSpace( partition ) ) + { return tr( "Free Space" ); + } else { - return isPartitionNew( partition ) - ? tr( "New partition" ) - : partition->partitionPath(); + return isPartitionNew( partition ) ? tr( "New partition" ) : partition->partitionPath(); } } if ( col == FileSystemColumn ) + { return CalamaresUtils::Partition::prettyNameForFileSystemType( partition->fileSystem().type() ); + } if ( col == MountPointColumn ) + { return PartitionInfo::mountPoint( partition ); + } if ( col == SizeColumn ) { qint64 size = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSize(); @@ -169,9 +190,13 @@ PartitionModel::data( const QModelIndex& index, int role ) const } case Qt::DecorationRole: if ( index.column() == NameColumn ) + { return ColorUtils::colorForPartition( partition ); + } else + { return QVariant(); + } case Qt::ToolTipRole: { int col = index.column(); @@ -179,18 +204,19 @@ PartitionModel::data( const QModelIndex& index, int role ) const if ( col == NameColumn ) { if ( isPartitionFreeSpace( partition ) ) + { name = tr( "Free Space" ); + } else { - name = isPartitionNew( partition ) - ? tr( "New partition" ) - : partition->partitionPath(); + name = isPartitionNew( partition ) ? tr( "New partition" ) : partition->partitionPath(); } } - QString prettyFileSystem = CalamaresUtils::Partition::prettyNameForFileSystemType( partition->fileSystem().type() ); + QString prettyFileSystem + = CalamaresUtils::Partition::prettyNameForFileSystemType( partition->fileSystem().type() ); qint64 size = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSize(); QString prettySize = KFormat().formatByteSize( size ); - return QVariant(name + " " + prettyFileSystem + " " + prettySize); + return QVariant( name + " " + prettyFileSystem + " " + prettySize ); } case SizeRole: return ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSize(); @@ -201,9 +227,11 @@ PartitionModel::data( const QModelIndex& index, int role ) const return isPartitionNew( partition ); case FileSystemLabelRole: - if ( partition->fileSystem().supportGetLabel() != FileSystem::cmdSupportNone && - !partition->fileSystem().label().isEmpty() ) + if ( partition->fileSystem().supportGetLabel() != FileSystem::cmdSupportNone + && !partition->fileSystem().label().isEmpty() ) + { return partition->fileSystem().label(); + } return QVariant(); case FileSystemTypeRole: @@ -218,40 +246,45 @@ PartitionModel::data( const QModelIndex& index, int role ) const // Osprober roles: case OsproberNameRole: foreach ( const OsproberEntry& osproberEntry, m_osproberEntries ) - if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone && - !partition->fileSystem().uuid().isEmpty() && - osproberEntry.uuid == partition->fileSystem().uuid() ) + if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone + && !partition->fileSystem().uuid().isEmpty() && osproberEntry.uuid == partition->fileSystem().uuid() ) + { return osproberEntry.prettyName; + } return QVariant(); case OsproberPathRole: foreach ( const OsproberEntry& osproberEntry, m_osproberEntries ) - if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone && - !partition->fileSystem().uuid().isEmpty() && - osproberEntry.uuid == partition->fileSystem().uuid() ) + if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone + && !partition->fileSystem().uuid().isEmpty() && osproberEntry.uuid == partition->fileSystem().uuid() ) + { return osproberEntry.path; + } return QVariant(); case OsproberCanBeResizedRole: foreach ( const OsproberEntry& osproberEntry, m_osproberEntries ) - if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone && - !partition->fileSystem().uuid().isEmpty() && - osproberEntry.uuid == partition->fileSystem().uuid() ) + if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone + && !partition->fileSystem().uuid().isEmpty() && osproberEntry.uuid == partition->fileSystem().uuid() ) + { return osproberEntry.canBeResized; + } return QVariant(); case OsproberRawLineRole: foreach ( const OsproberEntry& osproberEntry, m_osproberEntries ) - if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone && - !partition->fileSystem().uuid().isEmpty() && - osproberEntry.uuid == partition->fileSystem().uuid() ) + if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone + && !partition->fileSystem().uuid().isEmpty() && osproberEntry.uuid == partition->fileSystem().uuid() ) + { return osproberEntry.line; + } return QVariant(); case OsproberHomePartitionPathRole: foreach ( const OsproberEntry& osproberEntry, m_osproberEntries ) - if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone && - !partition->fileSystem().uuid().isEmpty() && - osproberEntry.uuid == partition->fileSystem().uuid() ) + if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone + && !partition->fileSystem().uuid().isEmpty() && osproberEntry.uuid == partition->fileSystem().uuid() ) + { return osproberEntry.homePath; + } return QVariant(); - // end Osprober roles. + // end Osprober roles. default: return QVariant(); @@ -262,7 +295,9 @@ QVariant PartitionModel::headerData( int section, Qt::Orientation, int role ) const { if ( role != Qt::DisplayRole ) + { return QVariant(); + } switch ( section ) { @@ -283,9 +318,11 @@ PartitionModel::headerData( int section, Qt::Orientation, int role ) const Partition* PartitionModel::partitionForIndex( const QModelIndex& index ) const { - QMutexLocker lock(&m_lock); + QMutexLocker lock( &m_lock ); if ( !index.isValid() ) + { return nullptr; + } return reinterpret_cast< Partition* >( index.internalPointer() ); } diff --git a/src/modules/partition/core/PartitionModel.h b/src/modules/partition/core/PartitionModel.h index f5289254b..7066aa5a5 100644 --- a/src/modules/partition/core/PartitionModel.h +++ b/src/modules/partition/core/PartitionModel.h @@ -61,6 +61,7 @@ public: ResetHelper( const ResetHelper& ) = delete; ResetHelper& operator=( const ResetHelper& ) = delete; + private: PartitionModel* m_model; }; @@ -75,7 +76,7 @@ public: FileSystemLabelRole, FileSystemTypeRole, PartitionPathRole, - PartitionPtrRole, // passed as void*, use sparingly + PartitionPtrRole, // passed as void*, use sparingly OsproberNameRole, OsproberPathRole, OsproberCanBeResizedRole, @@ -89,7 +90,7 @@ public: FileSystemColumn, MountPointColumn, SizeColumn, - ColumnCount // Must remain last + ColumnCount // Must remain last }; PartitionModel( QObject* parent = nullptr ); @@ -108,10 +109,7 @@ public: Partition* partitionForIndex( const QModelIndex& index ) const; - Device* device() const - { - return m_device; - } + Device* device() const { return m_device; } void update();