From 586cb63ef5209bd532f1695bf89bc64816d6fe7f Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Fri, 22 Feb 2019 12:58:55 +0100 Subject: [PATCH 1/3] [partition] use configured default filesystem type instead of ext4 When using the default partition layout (only a `/` partition), the filesystem used was ext4, ignoring the `defaultFileSystemType` configuration option. This commit fixes this bug, so that any supported filesystem can now be used for the default partitioning scheme. Fixes #1093 Signed-off-by: Arnaud Ferraris --- .../partition/core/PartitionLayout.cpp | 22 ++++++++++++++++++- src/modules/partition/core/PartitionLayout.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index c2489620f..a17e764e8 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -18,6 +18,9 @@ * along with Calamares. If not, see . */ +#include "GlobalStorage.h" +#include "JobQueue.h" + #include "core/PartitionLayout.h" #include "core/KPMHelpers.h" @@ -28,17 +31,32 @@ #include #include +static int +getDefaultFileSystemType() +{ + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + int defaultFs = FileSystem::typeForName( gs->value( "defaultFileSystemType" ).toString() ); + + if ( defaultFs == FileSystem::Unknown ) + defaultFs = FileSystem::Ext4; + + return defaultFs; +} + PartitionLayout::PartitionLayout() { + defaultFsType = getDefaultFileSystemType(); } PartitionLayout::PartitionLayout( PartitionLayout::PartitionEntry entry ) { + defaultFsType = getDefaultFileSystemType(); partLayout.append( entry ); } PartitionLayout::PartitionLayout( const PartitionLayout& layout ) : partLayout( layout.partLayout ) + , defaultFsType( layout.defaultFsType ) { } @@ -115,7 +133,7 @@ PartitionLayout::addEntry( const QString& mountPoint, const QString& size, const PartitionLayout::PartitionEntry entry( size, min ); entry.partMountPoint = mountPoint; - entry.partFileSystem = FileSystem::Ext4; + entry.partFileSystem = defaultFsType; partLayout.append( entry ); } @@ -128,6 +146,8 @@ PartitionLayout::addEntry( const QString& label, const QString& mountPoint, cons entry.partLabel = label; entry.partMountPoint = mountPoint; entry.partFileSystem = FileSystem::typeForName( fs ); + if ( entry.partFileSystem == FileSystem::Unknown ) + entry.partFileSystem = defaultFsType; partLayout.append( entry ); } diff --git a/src/modules/partition/core/PartitionLayout.h b/src/modules/partition/core/PartitionLayout.h index 5e216122c..63ea8d9ec 100644 --- a/src/modules/partition/core/PartitionLayout.h +++ b/src/modules/partition/core/PartitionLayout.h @@ -76,6 +76,7 @@ public: QList< Partition* > execute( Device *dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase, PartitionNode* parent, const PartitionRole& role ); private: + int defaultFsType; QList< PartitionEntry > partLayout; }; From 5084c44b54784a03b6c9751ea1c109cff0cd161f Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Fri, 22 Feb 2019 13:08:59 +0100 Subject: [PATCH 2/3] [partition] fix naming of PartitionLayout class member variables Signed-off-by: Arnaud Ferraris --- .../partition/core/PartitionLayout.cpp | 22 +++++++++---------- src/modules/partition/core/PartitionLayout.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index a17e764e8..f6521cea7 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -45,18 +45,18 @@ getDefaultFileSystemType() PartitionLayout::PartitionLayout() { - defaultFsType = getDefaultFileSystemType(); + m_defaultFsType = getDefaultFileSystemType(); } PartitionLayout::PartitionLayout( PartitionLayout::PartitionEntry entry ) { - defaultFsType = getDefaultFileSystemType(); - partLayout.append( entry ); + m_defaultFsType = getDefaultFileSystemType(); + m_partLayout.append( entry ); } PartitionLayout::PartitionLayout( const PartitionLayout& layout ) - : partLayout( layout.partLayout ) - , defaultFsType( layout.defaultFsType ) + : m_partLayout( layout.m_partLayout ) + , m_defaultFsType( layout.m_defaultFsType ) { } @@ -67,7 +67,7 @@ PartitionLayout::~PartitionLayout() void PartitionLayout::addEntry( PartitionLayout::PartitionEntry entry ) { - partLayout.append( entry ); + m_partLayout.append( entry ); } static double @@ -133,9 +133,9 @@ PartitionLayout::addEntry( const QString& mountPoint, const QString& size, const PartitionLayout::PartitionEntry entry( size, min ); entry.partMountPoint = mountPoint; - entry.partFileSystem = defaultFsType; + entry.partFileSystem = m_defaultFsType; - partLayout.append( entry ); + m_partLayout.append( entry ); } void @@ -147,9 +147,9 @@ PartitionLayout::addEntry( const QString& label, const QString& mountPoint, cons entry.partMountPoint = mountPoint; entry.partFileSystem = FileSystem::typeForName( fs ); if ( entry.partFileSystem == FileSystem::Unknown ) - entry.partFileSystem = defaultFsType; + entry.partFileSystem = m_defaultFsType; - partLayout.append( entry ); + m_partLayout.append( entry ); } static qint64 @@ -195,7 +195,7 @@ 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, partLayout ) + foreach( const PartitionLayout::PartitionEntry& part, m_partLayout ) { Partition *currentPartition = nullptr; diff --git a/src/modules/partition/core/PartitionLayout.h b/src/modules/partition/core/PartitionLayout.h index 63ea8d9ec..f2a4cbff5 100644 --- a/src/modules/partition/core/PartitionLayout.h +++ b/src/modules/partition/core/PartitionLayout.h @@ -76,8 +76,8 @@ public: QList< Partition* > execute( Device *dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase, PartitionNode* parent, const PartitionRole& role ); private: - int defaultFsType; - QList< PartitionEntry > partLayout; + int m_defaultFsType; + QList< PartitionEntry > m_partLayout; }; #endif /* PARTITIONLAYOUT_H */ From 74ead4c7bad673d6099d198f80a5524988264cde Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Fri, 22 Feb 2019 18:42:16 +0100 Subject: [PATCH 3/3] [partition] improve filesystem search operation Due to changes to the FileSsytem::typeForName() function, more processing is needed to deal with locales and different cases. This is done by refactoring the findFS() function, initially located in the PartitionViewStep class, and making it available to the whole module. Additionnally, more checks have been implemented regarding the use of global storage in the PartitionLayout class, and the filesystem types now use the correct FileSystem::Type, as requested. Signed-off-by: Arnaud Ferraris --- src/modules/partition/core/PartUtils.cpp | 50 ++++++++++++++ src/modules/partition/core/PartUtils.h | 13 ++++ .../partition/core/PartitionLayout.cpp | 21 +++--- src/modules/partition/core/PartitionLayout.h | 5 +- .../partition/gui/PartitionViewStep.cpp | 65 +++++-------------- 5 files changed, 94 insertions(+), 60 deletions(-) diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index d61064041..d09bcd149 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -408,6 +408,56 @@ isEfiBootable( const Partition* candidate ) flags.testFlag( PartitionTable::FlagBoot ); } +QString +findFS( QString fsName, FileSystem::Type* fsType ) +{ + QStringList fsLanguage { QLatin1Literal( "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; + } + + // Second pass: try case-insensitive + const auto fstypes = FileSystem::types(); + for ( FileSystem::Type t : fstypes ) + { + if ( 0 == QString::compare( fsName, FileSystem::nameForType( t, fsLanguage ), Qt::CaseInsensitive ) ) + { + QString fsRealName = FileSystem::nameForType( t, fsLanguage ); + cDebug() << "Filesystem name" << fsName << "translated to" << fsRealName; + if ( fsType ) + *fsType = t; + return fsRealName; + } + } + + cDebug() << "Filesystem" << fsName << "not found, using ext4"; + fsName = QStringLiteral( "ext4" ); + // fsType can be used to check whether fsName was a valid filesystem. + 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. + { + Logger::CDebug d; + using TR = Logger::DebugRow< int, QString >; + const auto fstypes = FileSystem::types(); + d << "Available types (" << fstypes.count() << ')'; + for ( FileSystem::Type t : fstypes ) + d << TR( static_cast( t ), FileSystem::nameForType( t, fsLanguage ) ); + } +#endif + return fsName; +} + } // nmamespace PartUtils /* Implementation of methods for FstabEntry, from OsproberEntry.h */ diff --git a/src/modules/partition/core/PartUtils.h b/src/modules/partition/core/PartUtils.h index b94e20567..c7da86c06 100644 --- a/src/modules/partition/core/PartUtils.h +++ b/src/modules/partition/core/PartUtils.h @@ -22,6 +22,10 @@ #include "OsproberEntry.h" +// KPMcore +#include + +// Qt #include class PartitionCoreModule; @@ -73,6 +77,15 @@ bool isEfiSystem(); * the partition table layout, this may mean different flags. */ bool isEfiBootable( const Partition* candidate ); + +/** @brief translate @p fsName into a recognized name and type + * + * Makes several attempts to translate the string into a + * name that KPMCore will recognize. + * The corresponding filesystem type is stored in @p fsType, and + * its value is FileSystem::Unknown if @p fsName is not recognized. + */ +QString findFS( QString fsName, FileSystem::Type* fsType ); } #endif // PARTUTILS_H diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index f6521cea7..39341fddd 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -26,21 +26,26 @@ #include "core/KPMHelpers.h" #include "core/PartitionActions.h" #include "core/PartitionInfo.h" +#include "core/PartUtils.h" #include #include #include -static int +static FileSystem::Type getDefaultFileSystemType() { Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - int defaultFs = FileSystem::typeForName( gs->value( "defaultFileSystemType" ).toString() ); + FileSystem::Type defaultFS = FileSystem::Ext4; - if ( defaultFs == FileSystem::Unknown ) - defaultFs = FileSystem::Ext4; + if ( gs->contains( "defaultFileSystemType" ) ) + { + PartUtils::findFS( gs->value( "defaultFileSystemType" ).toString(), &defaultFS); + if ( defaultFS == FileSystem::Unknown ) + defaultFS = FileSystem::Ext4; + } - return defaultFs; + return defaultFS; } PartitionLayout::PartitionLayout() @@ -145,7 +150,7 @@ PartitionLayout::addEntry( const QString& label, const QString& mountPoint, cons entry.partLabel = label; entry.partMountPoint = mountPoint; - entry.partFileSystem = FileSystem::typeForName( fs ); + PartUtils::findFS( fs, &entry.partFileSystem ); if ( entry.partFileSystem == FileSystem::Unknown ) entry.partFileSystem = m_defaultFsType; @@ -214,7 +219,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector, parent, *dev, role, - static_cast(part.partFileSystem), + part.partFileSystem, firstSector, end, PartitionTable::FlagNone @@ -226,7 +231,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector, parent, *dev, role, - static_cast(part.partFileSystem), + part.partFileSystem, firstSector, end, luksPassphrase, diff --git a/src/modules/partition/core/PartitionLayout.h b/src/modules/partition/core/PartitionLayout.h index f2a4cbff5..999e10425 100644 --- a/src/modules/partition/core/PartitionLayout.h +++ b/src/modules/partition/core/PartitionLayout.h @@ -24,6 +24,7 @@ // KPMcore #include +#include // Qt #include @@ -48,7 +49,7 @@ public: { QString partLabel; QString partMountPoint; - int partFileSystem = 0; + FileSystem::Type partFileSystem = FileSystem::Unknown; double partSize = 0.0L; SizeUnit partSizeUnit = Percent; double partMinSize = 0.0L; @@ -76,7 +77,7 @@ public: QList< Partition* > execute( Device *dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase, PartitionNode* parent, const PartitionRole& role ); private: - int m_defaultFsType; + FileSystem::Type m_defaultFsType; QList< PartitionEntry > m_partLayout; }; diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index a152db14b..3c71302e0 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -493,55 +493,6 @@ nameToChoice( QString name, bool& ok ) return names.find( name, ok ); } -/** @brief translate @p defaultFS into a recognized name - * - * Makes several attempts to translate the string into a - * name that KPMCore will recognize. - */ -static QString -findFS( QString defaultFS ) -{ - QStringList fsLanguage { QLatin1Literal( "C" ) }; // Required language list to turn off localization - if ( defaultFS.isEmpty() ) - { - cWarning() << "Partition-module setting *defaultFileSystemType* is missing, using ext4"; - defaultFS = QStringLiteral( "ext4" ); - } - if ( FileSystem::typeForName( defaultFS, fsLanguage ) != FileSystem::Unknown ) - { - cDebug() << "Partition-module setting *defaultFileSystemType*" << defaultFS; - return defaultFS; - } - - // Second pass: try case-insensitive - const auto fstypes = FileSystem::types(); - for ( FileSystem::Type t : fstypes ) - { - if ( 0 == QString::compare( defaultFS, FileSystem::nameForType( t, fsLanguage ), Qt::CaseInsensitive ) ) - { - defaultFS = FileSystem::nameForType( t, fsLanguage ); - cWarning() << "Partition-module setting *defaultFileSystemType* changed" << defaultFS; - return defaultFS; - } - } - - cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << defaultFS << ") using ext4."; - defaultFS = QStringLiteral( "ext4" ); -#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. - { - Logger::CDebug d; - using TR = Logger::DebugRow< int, QString >; - const auto fstypes = FileSystem::types(); - d << "Available types (" << fstypes.count() << ')'; - for ( FileSystem::Type t : fstypes ) - d << TR( static_cast( t ), FileSystem::nameForType( t, fsLanguage ) ); - } -#endif - return defaultFS; -} - void PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { @@ -630,7 +581,21 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) gs->insert( "alwaysShowPartitionLabels", CalamaresUtils::getBool( configurationMap, "alwaysShowPartitionLabels", true ) ); gs->insert( "enableLuksAutomatedPartitioning", CalamaresUtils::getBool( configurationMap, "enableLuksAutomatedPartitioning", true ) ); gs->insert( "allowManualPartitioning", CalamaresUtils::getBool( configurationMap, "allowManualPartitioning", true ) ); - gs->insert( "defaultFileSystemType", findFS( CalamaresUtils::getString( configurationMap, "defaultFileSystemType" ) ) ); + + // The defaultFileSystemType setting needs a bit more processing, + // as we want to cover various cases (such as different cases) + QString fsName = CalamaresUtils::getString( configurationMap, "defaultFileSystemType" ); + FileSystem::Type fsType; + if ( fsName.isEmpty() ) + cWarning() << "Partition-module setting *defaultFileSystemType* is missing, will use ext4"; + QString fsRealName = PartUtils::findFS( fsName, &fsType ); + if ( fsRealName == fsName ) + cDebug() << "Partition-module setting *defaultFileSystemType*" << fsRealName; + else if ( fsType != FileSystem::Unknown ) + cWarning() << "Partition-module setting *defaultFileSystemType* changed" << fsRealName; + else + cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << fsRealName << ") using ext4."; + gs->insert( "defaultFileSystemType", fsRealName ); // Now that we have the config, we load the PartitionCoreModule in the background