Merge branch 'kpmcore-manager'
This commit is contained in:
commit
6d0f5e4111
@ -34,7 +34,7 @@ function( calamares_add_test )
|
|||||||
# parse arguments (name needs to be saved before passing ARGN into the macro)
|
# parse arguments (name needs to be saved before passing ARGN into the macro)
|
||||||
set( NAME ${ARGV0} )
|
set( NAME ${ARGV0} )
|
||||||
set( options GUI )
|
set( options GUI )
|
||||||
set( multiValueArgs SOURCES LIBRARIES )
|
set( multiValueArgs SOURCES LIBRARIES DEFINITIONS )
|
||||||
cmake_parse_arguments( TEST "${options}" "" "${multiValueArgs}" ${ARGN} )
|
cmake_parse_arguments( TEST "${options}" "" "${multiValueArgs}" ${ARGN} )
|
||||||
set( TEST_NAME ${NAME} )
|
set( TEST_NAME ${NAME} )
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ function( calamares_add_test )
|
|||||||
Qt5::Test
|
Qt5::Test
|
||||||
)
|
)
|
||||||
calamares_automoc( ${TEST_NAME} )
|
calamares_automoc( ${TEST_NAME} )
|
||||||
target_compile_definitions( ${TEST_NAME} PRIVATE -DBUILD_AS_TEST )
|
target_compile_definitions( ${TEST_NAME} PRIVATE -DBUILD_AS_TEST ${TEST_DEFINITIONS} )
|
||||||
if( TEST_GUI )
|
if( TEST_GUI )
|
||||||
target_link_libraries( ${TEST_NAME} calamaresui Qt5::Gui )
|
target_link_libraries( ${TEST_NAME} calamaresui Qt5::Gui )
|
||||||
endif()
|
endif()
|
||||||
|
@ -44,7 +44,9 @@ set( libSources
|
|||||||
network/Manager.cpp
|
network/Manager.cpp
|
||||||
|
|
||||||
# Partition service
|
# Partition service
|
||||||
|
partition/Mount.cpp
|
||||||
partition/PartitionSize.cpp
|
partition/PartitionSize.cpp
|
||||||
|
partition/Sync.cpp
|
||||||
|
|
||||||
# Utility service
|
# Utility service
|
||||||
utils/CalamaresUtilsSystem.cpp
|
utils/CalamaresUtilsSystem.cpp
|
||||||
@ -110,6 +112,38 @@ if( Qt5Xml_FOUND )
|
|||||||
list( APPEND OPTIONAL_PUBLIC_LIBRARIES Qt5::Network Qt5::Xml )
|
list( APPEND OPTIONAL_PUBLIC_LIBRARIES Qt5::Network Qt5::Xml )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
### OPTIONAL KPMcore support
|
||||||
|
#
|
||||||
|
#
|
||||||
|
find_package( KPMcore 3.3 )
|
||||||
|
set_package_properties(
|
||||||
|
KPMcore PROPERTIES
|
||||||
|
URL "https://invent.kde.org/kde/kpmcore"
|
||||||
|
DESCRIPTION "KDE Partitioning library"
|
||||||
|
TYPE RECOMMENDED
|
||||||
|
PURPOSE "For partitioning service"
|
||||||
|
)
|
||||||
|
|
||||||
|
if ( KPMcore_FOUND )
|
||||||
|
find_package( Qt5 REQUIRED DBus ) # Needed for KPMCore
|
||||||
|
find_package( KF5 REQUIRED I18n WidgetsAddons ) # Needed for KPMCore
|
||||||
|
|
||||||
|
if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.0" )
|
||||||
|
add_definitions( -DWITH_KPMCORE4API ) # kpmcore 4 with new API
|
||||||
|
elseif( KPMcore_VERSION VERSION_GREATER "3.3.70" )
|
||||||
|
message( FATAL_ERROR "KPMCore beta versions ${KPMcore_VERSION} not supported" )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include_directories( ${KPMCORE_INCLUDE_DIR} )
|
||||||
|
list( APPEND libSources
|
||||||
|
partition/FileSystem.cpp
|
||||||
|
partition/KPMManager.cpp
|
||||||
|
partition/PartitionIterator.cpp
|
||||||
|
partition/PartitionQuery.cpp
|
||||||
|
)
|
||||||
|
list( APPEND OPTIONAL_PRIVATE_LIBRARIES kpmcore )
|
||||||
|
endif()
|
||||||
|
|
||||||
### LIBRARY
|
### LIBRARY
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
@ -36,12 +36,13 @@ public:
|
|||||||
: QThread( queue )
|
: QThread( queue )
|
||||||
, m_queue( queue )
|
, m_queue( queue )
|
||||||
, m_jobIndex( 0 )
|
, m_jobIndex( 0 )
|
||||||
|
, m_jobCount( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~JobThread() override;
|
virtual ~JobThread() override;
|
||||||
|
|
||||||
void setJobs( const JobList& jobs )
|
void setJobs( JobList&& jobs )
|
||||||
{
|
{
|
||||||
m_jobs = jobs;
|
m_jobs = jobs;
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
emitProgress();
|
emitProgress();
|
||||||
cDebug() << "Starting" << ( anyFailed ? "EMERGENCY JOB" : "job" ) << job->prettyName();
|
cDebug() << "Starting" << ( anyFailed ? "EMERGENCY JOB" : "job" ) << job->prettyName() << " (there are" << m_jobs.count() << " left)";
|
||||||
connect( job.data(), &Job::progress, this, &JobThread::emitProgress );
|
connect( job.data(), &Job::progress, this, &JobThread::emitProgress );
|
||||||
JobResult result = job->exec();
|
JobResult result = job->exec();
|
||||||
if ( !anyFailed && !result )
|
if ( !anyFailed && !result )
|
||||||
@ -103,6 +104,7 @@ private:
|
|||||||
QList< qreal > m_jobWeights;
|
QList< qreal > m_jobWeights;
|
||||||
JobQueue* m_queue;
|
JobQueue* m_queue;
|
||||||
int m_jobIndex;
|
int m_jobIndex;
|
||||||
|
int m_jobCount;
|
||||||
|
|
||||||
void emitProgress( qreal jobPercent = 0 )
|
void emitProgress( qreal jobPercent = 0 )
|
||||||
{
|
{
|
||||||
@ -193,7 +195,7 @@ void
|
|||||||
JobQueue::start()
|
JobQueue::start()
|
||||||
{
|
{
|
||||||
Q_ASSERT( !m_thread->isRunning() );
|
Q_ASSERT( !m_thread->isRunning() );
|
||||||
m_thread->setJobs( m_jobs );
|
m_thread->setJobs( std::move( m_jobs ) );
|
||||||
m_jobs.clear();
|
m_jobs.clear();
|
||||||
m_thread->start();
|
m_thread->start();
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
#include "PythonHelper.h"
|
#include "PythonHelper.h"
|
||||||
|
#include "partition/Mount.h"
|
||||||
#include "utils/CalamaresUtilsSystem.h"
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/String.h"
|
#include "utils/String.h"
|
||||||
@ -63,7 +64,7 @@ mount( const std::string& device_path,
|
|||||||
const std::string& filesystem_name,
|
const std::string& filesystem_name,
|
||||||
const std::string& options )
|
const std::string& options )
|
||||||
{
|
{
|
||||||
return CalamaresUtils::System::instance()->mount( QString::fromStdString( device_path ),
|
return CalamaresUtils::Partition::mount( QString::fromStdString( device_path ),
|
||||||
QString::fromStdString( mount_point ),
|
QString::fromStdString( mount_point ),
|
||||||
QString::fromStdString( filesystem_name ),
|
QString::fromStdString( filesystem_name ),
|
||||||
QString::fromStdString( options ) );
|
QString::fromStdString( options ) );
|
||||||
|
74
src/libcalamares/partition/FileSystem.cpp
Normal file
74
src/libcalamares/partition/FileSystem.cpp
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
|
* Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2018-2019 Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FileSystem.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
|
||||||
|
QString
|
||||||
|
prettyNameForFileSystemType( FileSystem::Type t )
|
||||||
|
{
|
||||||
|
switch ( t )
|
||||||
|
{
|
||||||
|
case FileSystem::Unknown:
|
||||||
|
return QObject::tr( "unknown" );
|
||||||
|
case FileSystem::Extended:
|
||||||
|
return QObject::tr( "extended" );
|
||||||
|
case FileSystem::Unformatted:
|
||||||
|
return QObject::tr( "unformatted" );
|
||||||
|
case FileSystem::LinuxSwap:
|
||||||
|
return QObject::tr( "swap" );
|
||||||
|
case FileSystem::Fat16:
|
||||||
|
case FileSystem::Fat32:
|
||||||
|
case FileSystem::Ntfs:
|
||||||
|
case FileSystem::Xfs:
|
||||||
|
case FileSystem::Jfs:
|
||||||
|
case FileSystem::Hfs:
|
||||||
|
case FileSystem::Ufs:
|
||||||
|
case FileSystem::Hpfs:
|
||||||
|
case FileSystem::Luks:
|
||||||
|
case FileSystem::Ocfs2:
|
||||||
|
case FileSystem::Zfs:
|
||||||
|
case FileSystem::Nilfs2:
|
||||||
|
return FileSystem::nameForType( t ).toUpper();
|
||||||
|
case FileSystem::ReiserFS:
|
||||||
|
return "ReiserFS";
|
||||||
|
case FileSystem::Reiser4:
|
||||||
|
return "Reiser4";
|
||||||
|
case FileSystem::HfsPlus:
|
||||||
|
return "HFS+";
|
||||||
|
case FileSystem::Btrfs:
|
||||||
|
return "Btrfs";
|
||||||
|
case FileSystem::Exfat:
|
||||||
|
return "exFAT";
|
||||||
|
case FileSystem::Lvm2_PV:
|
||||||
|
return "LVM PV";
|
||||||
|
default:
|
||||||
|
return FileSystem::nameForType( t );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
65
src/libcalamares/partition/FileSystem.h
Normal file
65
src/libcalamares/partition/FileSystem.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
|
* Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: this functionality is only available when Calamares is compiled
|
||||||
|
* with KPMcore support.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PARTITION_FILESYSTEM_H
|
||||||
|
#define PARTITION_FILESYSTEM_H
|
||||||
|
|
||||||
|
#include <kpmcore/fs/filesystem.h>
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
QString prettyNameForFileSystemType( FileSystem::Type t );
|
||||||
|
|
||||||
|
static inline QString
|
||||||
|
untranslatedFS( FileSystem& fs )
|
||||||
|
{
|
||||||
|
return fs.name( { QStringLiteral( "C" ) } );
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QString
|
||||||
|
untranslatedFS( FileSystem* fs )
|
||||||
|
{
|
||||||
|
return fs ? untranslatedFS( *fs ) : QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QString
|
||||||
|
userVisibleFS( FileSystem& fs )
|
||||||
|
{
|
||||||
|
return fs.name();
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QString
|
||||||
|
userVisibleFS( FileSystem* fs )
|
||||||
|
{
|
||||||
|
return fs ? userVisibleFS( *fs ) : QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
|
#endif // PARTITION_PARTITIONQUERY_H
|
128
src/libcalamares/partition/KPMManager.cpp
Normal file
128
src/libcalamares/partition/KPMManager.cpp
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "KPMManager.h"
|
||||||
|
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <kpmcore/backend/corebackend.h>
|
||||||
|
#include <kpmcore/backend/corebackendmanager.h>
|
||||||
|
#if defined( WITH_KPMCORE4API )
|
||||||
|
#include <kpmcore/util/externalcommand.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
class InternalManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InternalManager();
|
||||||
|
~InternalManager();
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool s_kpm_loaded = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We have one living InternalManager object at a time.
|
||||||
|
* It is managed by shared_ptr<>s help by KPMManager
|
||||||
|
* objects, but since we can create KPMManager objects
|
||||||
|
* independent of each other, all of which share ownership
|
||||||
|
* of the same InternalManager, hang on to one extra reference
|
||||||
|
* to the InternalManager so we can hand it out in getInternal().
|
||||||
|
*/
|
||||||
|
static std::weak_ptr< InternalManager > s_backend;
|
||||||
|
|
||||||
|
InternalManager::InternalManager()
|
||||||
|
{
|
||||||
|
cDebug() << "KPMCore backend starting ..";
|
||||||
|
|
||||||
|
Q_ASSERT( s_backend.expired() );
|
||||||
|
|
||||||
|
if ( !s_kpm_loaded )
|
||||||
|
{
|
||||||
|
QByteArray backendName = qgetenv( "KPMCORE_BACKEND" );
|
||||||
|
if ( !CoreBackendManager::self()->load( backendName.isEmpty() ? CoreBackendManager::defaultBackendName()
|
||||||
|
: backendName ) )
|
||||||
|
{
|
||||||
|
cWarning() << "Failed to load backend plugin" << backendName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto* backend_p = CoreBackendManager::self()->backend();
|
||||||
|
cDebug() << Logger::SubEntry << "Backend @" << (void*)backend_p << backend_p->id() << backend_p->version();
|
||||||
|
s_kpm_loaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
InternalManager::~InternalManager()
|
||||||
|
{
|
||||||
|
cDebug() << "Cleaning up KPMCore backend ..";
|
||||||
|
|
||||||
|
#if defined( WITH_KPMCORE4API )
|
||||||
|
auto backend_p = CoreBackendManager::self()->backend();
|
||||||
|
if ( backend_p )
|
||||||
|
{
|
||||||
|
ExternalCommand::stopHelper();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr< InternalManager >
|
||||||
|
getInternal()
|
||||||
|
{
|
||||||
|
if ( s_backend.expired() )
|
||||||
|
{
|
||||||
|
auto p = std::make_shared< InternalManager >();
|
||||||
|
s_backend = p;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
return s_backend.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
KPMManager::KPMManager()
|
||||||
|
: m_d( getInternal() )
|
||||||
|
{
|
||||||
|
cDebug() << "KPMManager" << s_backend.use_count() << "created.";
|
||||||
|
}
|
||||||
|
|
||||||
|
KPMManager::~KPMManager()
|
||||||
|
{
|
||||||
|
cDebug() << "KPMManager" << s_backend.use_count() << "being destroyed.";
|
||||||
|
}
|
||||||
|
|
||||||
|
KPMManager::operator bool() const
|
||||||
|
{
|
||||||
|
return s_kpm_loaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoreBackend*
|
||||||
|
KPMManager::backend() const
|
||||||
|
{
|
||||||
|
return s_kpm_loaded ? CoreBackendManager::self()->backend() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
69
src/libcalamares/partition/KPMManager.h
Normal file
69
src/libcalamares/partition/KPMManager.h
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: this functionality is only available when Calamares is compiled
|
||||||
|
* with KPMcore support.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PARTITION_KPMMANAGER_H
|
||||||
|
#define PARTITION_KPMMANAGER_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class CoreBackend;
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
/// @brief Handle to KPMCore
|
||||||
|
class InternalManager;
|
||||||
|
|
||||||
|
/** @brief KPMCore loader and cleanup
|
||||||
|
*
|
||||||
|
* A Calamares plugin that uses KPMCore should hold an object of
|
||||||
|
* this class; its only responsibility is to load KPMCore
|
||||||
|
* and to cleanly unload it on destruction (with KPMCore 4,
|
||||||
|
* also to shutdown the privileged helper application).
|
||||||
|
*
|
||||||
|
* It loads the default plugin ("parted" with KPMCore 3, "sfdisk"
|
||||||
|
* with KPMCore 4), but this can be overridden by setting the
|
||||||
|
* environment variable KPMCORE_BACKEND. Setting it to
|
||||||
|
* "dummy" will load the dummy plugin instead.
|
||||||
|
*/
|
||||||
|
class KPMManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KPMManager();
|
||||||
|
~KPMManager();
|
||||||
|
|
||||||
|
/// @brief Is KPMCore loaded correctly?
|
||||||
|
operator bool() const;
|
||||||
|
|
||||||
|
/// @brief Gets the KPMCore backend (e.g. CoreBackendManager::self()->backend() )
|
||||||
|
CoreBackend* backend() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr< InternalManager > m_d;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
|
#endif // PARTITION_KPMMANAGER_H
|
132
src/libcalamares/partition/Mount.cpp
Normal file
132
src/libcalamares/partition/Mount.cpp
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2017-2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Mount.h"
|
||||||
|
|
||||||
|
#include "partition/Sync.h"
|
||||||
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QTemporaryDir>
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
|
||||||
|
int
|
||||||
|
mount( const QString& devicePath, const QString& mountPoint, const QString& filesystemName, const QString& options )
|
||||||
|
{
|
||||||
|
if ( devicePath.isEmpty() || mountPoint.isEmpty() )
|
||||||
|
{
|
||||||
|
if ( devicePath.isEmpty() )
|
||||||
|
{
|
||||||
|
cWarning() << "Can't mount an empty device.";
|
||||||
|
}
|
||||||
|
if ( mountPoint.isEmpty() )
|
||||||
|
{
|
||||||
|
cWarning() << "Can't mount on an empty mountpoint.";
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast< int >( ProcessResult::Code::NoWorkingDirectory );
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir mountPointDir( mountPoint );
|
||||||
|
if ( !mountPointDir.exists() )
|
||||||
|
{
|
||||||
|
bool ok = mountPointDir.mkpath( mountPoint );
|
||||||
|
if ( !ok )
|
||||||
|
{
|
||||||
|
cWarning() << "Could not create mountpoint" << mountPoint;
|
||||||
|
return static_cast< int >( ProcessResult::Code::NoWorkingDirectory );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList args = { "mount" };
|
||||||
|
|
||||||
|
if ( !filesystemName.isEmpty() )
|
||||||
|
{
|
||||||
|
args << "-t" << filesystemName;
|
||||||
|
}
|
||||||
|
if ( !options.isEmpty() )
|
||||||
|
{
|
||||||
|
if ( options.startsWith( '-' ) )
|
||||||
|
{
|
||||||
|
args << options;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
args << "-o" << options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
args << devicePath << mountPoint;
|
||||||
|
|
||||||
|
auto r = CalamaresUtils::System::runCommand( args, std::chrono::seconds( 10 ) );
|
||||||
|
sync();
|
||||||
|
return r.getExitCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
unmount( const QString& path, const QStringList& options )
|
||||||
|
{
|
||||||
|
auto r
|
||||||
|
= CalamaresUtils::System::runCommand( QStringList { "umount" } << options << path, std::chrono::seconds( 10 ) );
|
||||||
|
sync();
|
||||||
|
return r.getExitCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TemporaryMount::Private
|
||||||
|
{
|
||||||
|
QString m_devicePath;
|
||||||
|
QTemporaryDir m_mountDir;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
TemporaryMount::TemporaryMount( const QString& devicePath, const QString& filesystemName, const QString& options )
|
||||||
|
: m_d( new Private )
|
||||||
|
{
|
||||||
|
m_d->m_devicePath = devicePath;
|
||||||
|
m_d->m_mountDir.setAutoRemove( false );
|
||||||
|
int r = mount( devicePath, m_d->m_mountDir.path(), filesystemName, options );
|
||||||
|
if ( !r )
|
||||||
|
{
|
||||||
|
delete m_d;
|
||||||
|
m_d = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TemporaryMount::~TemporaryMount()
|
||||||
|
{
|
||||||
|
if ( m_d )
|
||||||
|
{
|
||||||
|
unmount( m_d->m_devicePath, { "-R" } );
|
||||||
|
delete m_d;
|
||||||
|
m_d = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
TemporaryMount::path() const
|
||||||
|
{
|
||||||
|
return m_d ? m_d->m_mountDir.path() : QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
80
src/libcalamares/partition/Mount.h
Normal file
80
src/libcalamares/partition/Mount.h
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2017-2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PARTITION_MOUNT_H
|
||||||
|
#define PARTITION_MOUNT_H
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the mount utility with the specified parameters.
|
||||||
|
* @param devicePath the path of the partition to mount.
|
||||||
|
* @param mountPoint the full path of the target mount point.
|
||||||
|
* @param filesystemName the name of the filesystem (optional).
|
||||||
|
* @param options any additional options as passed to mount -o (optional).
|
||||||
|
* If @p options starts with a dash (-) then it is passed unchanged
|
||||||
|
* and no -o option is added; this is used in handling --bind mounts.
|
||||||
|
* @returns the program's exit code, or:
|
||||||
|
* Crashed = QProcess crash
|
||||||
|
* FailedToStart = QProcess cannot start
|
||||||
|
* NoWorkingDirectory = bad arguments
|
||||||
|
*/
|
||||||
|
DLLEXPORT int mount( const QString& devicePath,
|
||||||
|
const QString& mountPoint,
|
||||||
|
const QString& filesystemName = QString(),
|
||||||
|
const QString& options = QString() );
|
||||||
|
|
||||||
|
/** @brief Unmount the given @p path (device or mount point).
|
||||||
|
*
|
||||||
|
* Runs umount(8) in the host system.
|
||||||
|
*
|
||||||
|
* @returns the program's exit code, or special codes like mount().
|
||||||
|
*/
|
||||||
|
DLLEXPORT int unmount( const QString& path, const QStringList& options = QStringList() );
|
||||||
|
|
||||||
|
class DLLEXPORT TemporaryMount
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TemporaryMount( const QString& devicePath,
|
||||||
|
const QString& filesystemName = QString(),
|
||||||
|
const QString& options = QString() );
|
||||||
|
TemporaryMount( const TemporaryMount& ) = delete;
|
||||||
|
TemporaryMount& operator=( const TemporaryMount& ) = delete;
|
||||||
|
~TemporaryMount();
|
||||||
|
|
||||||
|
bool isValid() const { return m_d; }
|
||||||
|
QString path() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Private;
|
||||||
|
Private* m_d = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
|
#endif
|
@ -2,7 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
||||||
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
* Copyright 2017, 2019 Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -25,12 +25,19 @@
|
|||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
#include <kpmcore/core/partitiontable.h>
|
#include <kpmcore/core/partitiontable.h>
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
|
||||||
|
using Partition = ::Partition;
|
||||||
|
|
||||||
PartitionIterator::PartitionIterator( PartitionTable* table )
|
PartitionIterator::PartitionIterator( PartitionTable* table )
|
||||||
: m_table( table )
|
: m_table( table )
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Partition*
|
Partition* PartitionIterator::operator*() const
|
||||||
PartitionIterator::operator*() const
|
|
||||||
{
|
{
|
||||||
return m_current;
|
return m_current;
|
||||||
}
|
}
|
||||||
@ -39,7 +46,9 @@ void
|
|||||||
PartitionIterator::operator++()
|
PartitionIterator::operator++()
|
||||||
{
|
{
|
||||||
if ( !m_current )
|
if ( !m_current )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if ( m_current->hasChildren() )
|
if ( m_current->hasChildren() )
|
||||||
{
|
{
|
||||||
// Go to the first child
|
// Go to the first child
|
||||||
@ -78,18 +87,21 @@ PartitionIterator::operator==( const PartitionIterator& other ) const
|
|||||||
bool
|
bool
|
||||||
PartitionIterator::operator!=( const PartitionIterator& other ) const
|
PartitionIterator::operator!=( const PartitionIterator& other ) const
|
||||||
{
|
{
|
||||||
return ! ( *this == other );
|
return !( *this == other );
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionIterator
|
PartitionIterator
|
||||||
PartitionIterator::begin( Device* device )
|
PartitionIterator::begin( Device* device )
|
||||||
{
|
{
|
||||||
if ( !device )
|
if ( !device )
|
||||||
|
{
|
||||||
return PartitionIterator( nullptr );
|
return PartitionIterator( nullptr );
|
||||||
Q_ASSERT(device);
|
}
|
||||||
PartitionTable* table = device->partitionTable();
|
PartitionTable* table = device->partitionTable();
|
||||||
if ( !table )
|
if ( !table )
|
||||||
|
{
|
||||||
return PartitionIterator( nullptr );
|
return PartitionIterator( nullptr );
|
||||||
|
}
|
||||||
return PartitionIterator::begin( table );
|
return PartitionIterator::begin( table );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +113,9 @@ PartitionIterator::begin( PartitionTable* table )
|
|||||||
// Does not usually happen, but it did happen on a tiny (10MiB) disk with an MBR
|
// Does not usually happen, but it did happen on a tiny (10MiB) disk with an MBR
|
||||||
// partition table.
|
// partition table.
|
||||||
if ( children.isEmpty() )
|
if ( children.isEmpty() )
|
||||||
|
{
|
||||||
return it;
|
return it;
|
||||||
|
}
|
||||||
it.m_current = children.first();
|
it.m_current = children.first();
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
@ -110,10 +124,14 @@ PartitionIterator
|
|||||||
PartitionIterator::end( Device* device )
|
PartitionIterator::end( Device* device )
|
||||||
{
|
{
|
||||||
if ( !device )
|
if ( !device )
|
||||||
|
{
|
||||||
return PartitionIterator( nullptr );
|
return PartitionIterator( nullptr );
|
||||||
|
}
|
||||||
PartitionTable* table = device->partitionTable();
|
PartitionTable* table = device->partitionTable();
|
||||||
if ( !table )
|
if ( !table )
|
||||||
|
{
|
||||||
return PartitionIterator( nullptr );
|
return PartitionIterator( nullptr );
|
||||||
|
}
|
||||||
|
|
||||||
return PartitionIterator::end( table );
|
return PartitionIterator::end( table );
|
||||||
}
|
}
|
||||||
@ -123,3 +141,6 @@ PartitionIterator::end( PartitionTable* table )
|
|||||||
{
|
{
|
||||||
return PartitionIterator( table );
|
return PartitionIterator( table );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
@ -2,6 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -17,37 +18,57 @@
|
|||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PARTITIONITERATOR_H
|
/*
|
||||||
#define PARTITIONITERATOR_H
|
* NOTE: this functionality is only available when Calamares is compiled
|
||||||
|
* with KPMcore support.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PARTITION_PARTITIONITERATOR_H
|
||||||
|
#define PARTITION_PARTITIONITERATOR_H
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class Partition;
|
class Partition;
|
||||||
class PartitionTable;
|
class PartitionTable;
|
||||||
|
|
||||||
/**
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @brief Iterator over KPMCore partitions
|
||||||
|
*
|
||||||
* A forward-only iterator to go through the partitions of a device,
|
* A forward-only iterator to go through the partitions of a device,
|
||||||
* independently of whether they are primary, logical or extended.
|
* independently of whether they are primary, logical or extended.
|
||||||
|
*
|
||||||
|
* An iterator can be created from a device (then it refers to the
|
||||||
|
* partition table of that device) or a partition table. The
|
||||||
|
* partition table must remain valid throughout iteration.
|
||||||
|
*
|
||||||
|
* A nullptr is valid, for an empty iterator.
|
||||||
*/
|
*/
|
||||||
class PartitionIterator
|
class PartitionIterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Partition* operator*() const;
|
::Partition* operator*() const;
|
||||||
|
|
||||||
void operator++();
|
void operator++();
|
||||||
|
|
||||||
bool operator==( const PartitionIterator& other ) const;
|
bool operator==( const PartitionIterator& other ) const;
|
||||||
bool operator!=( const PartitionIterator& other ) const;
|
bool operator!=( const PartitionIterator& other ) const;
|
||||||
|
|
||||||
static PartitionIterator begin( Device* device );
|
static PartitionIterator begin( ::Device* device );
|
||||||
static PartitionIterator begin( PartitionTable* table );
|
static PartitionIterator begin( ::PartitionTable* table );
|
||||||
static PartitionIterator end( Device* device );
|
static PartitionIterator end( ::Device* device );
|
||||||
static PartitionIterator end( PartitionTable* table );
|
static PartitionIterator end( ::PartitionTable* table );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PartitionIterator( PartitionTable* table );
|
PartitionIterator( ::PartitionTable* table );
|
||||||
|
|
||||||
PartitionTable* m_table;
|
::PartitionTable* m_table;
|
||||||
Partition* m_current = nullptr;
|
::Partition* m_current = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PARTITIONITERATOR_H */
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
|
#endif // PARTITION_PARTITIONITERATOR_H
|
102
src/libcalamares/partition/PartitionQuery.cpp
Normal file
102
src/libcalamares/partition/PartitionQuery.cpp
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
|
* Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2018-2019 Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PartitionQuery.h"
|
||||||
|
|
||||||
|
#include "PartitionIterator.h"
|
||||||
|
|
||||||
|
#include <kpmcore/core/device.h>
|
||||||
|
#include <kpmcore/core/partition.h>
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
|
||||||
|
// Types from KPMCore
|
||||||
|
using ::Device;
|
||||||
|
using ::Partition;
|
||||||
|
|
||||||
|
bool
|
||||||
|
isPartitionFreeSpace( Partition* partition )
|
||||||
|
{
|
||||||
|
return partition->roles().has( PartitionRole::Unallocated );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
isPartitionNew( Partition* partition )
|
||||||
|
{
|
||||||
|
#if defined( WITH_KPMCORE4API )
|
||||||
|
constexpr auto NewState = Partition::State::New;
|
||||||
|
#else
|
||||||
|
constexpr auto NewState = Partition::StateNew;
|
||||||
|
#endif
|
||||||
|
return partition->state() == NewState;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Partition*
|
||||||
|
findPartitionByCurrentMountPoint( const QList< Device* >& devices, const QString& mountPoint )
|
||||||
|
{
|
||||||
|
for ( auto device : devices )
|
||||||
|
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
||||||
|
if ( ( *it )->mountPoint() == mountPoint )
|
||||||
|
{
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Partition*
|
||||||
|
findPartitionByPath( const QList< Device* >& devices, const QString& path )
|
||||||
|
{
|
||||||
|
if ( path.simplified().isEmpty() )
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( auto device : devices )
|
||||||
|
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
||||||
|
if ( ( *it )->partitionPath() == path.simplified() )
|
||||||
|
{
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList< Partition* >
|
||||||
|
findPartitions( const QList< Device* >& devices, std::function< bool( Partition* ) > criterionFunction )
|
||||||
|
{
|
||||||
|
QList< Partition* > results;
|
||||||
|
for ( auto device : devices )
|
||||||
|
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
||||||
|
if ( criterionFunction( *it ) )
|
||||||
|
{
|
||||||
|
results.append( *it );
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
78
src/libcalamares/partition/PartitionQuery.h
Normal file
78
src/libcalamares/partition/PartitionQuery.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
|
* Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: this functionality is only available when Calamares is compiled
|
||||||
|
* with KPMcore support.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PARTITION_PARTITIONQUERY_H
|
||||||
|
#define PARTITION_PARTITIONQUERY_H
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
class Device;
|
||||||
|
class Partition;
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
|
||||||
|
using ::Device;
|
||||||
|
using ::Partition;
|
||||||
|
|
||||||
|
/** @brief Is this a free-space area? */
|
||||||
|
bool isPartitionFreeSpace( Partition* );
|
||||||
|
|
||||||
|
/** @brief Is this partition newly-to-be-created?
|
||||||
|
*
|
||||||
|
* Returns true if the partition is planned to be created by the installer as
|
||||||
|
* opposed to already existing on the disk.
|
||||||
|
*/
|
||||||
|
bool isPartitionNew( Partition* );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterates on all devices and return the first partition which is (already)
|
||||||
|
* mounted on @p mountPoint.
|
||||||
|
*/
|
||||||
|
Partition* findPartitionByCurrentMountPoint( const QList< Device* >& devices, const QString& mountPoint );
|
||||||
|
|
||||||
|
// TODO: add this distinction
|
||||||
|
// Partition* findPartitionByIntendedMountPoint( const QList< Device* >& devices, const QString& mountPoint );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterates on all devices and partitions and returns a pointer to the Partition object
|
||||||
|
* for the given path, or nullptr if a Partition for the given path cannot be found.
|
||||||
|
*/
|
||||||
|
Partition* findPartitionByPath( const QList< Device* >& devices, const QString& path );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterates on all devices and partitions and returns a list of pointers to the Partition
|
||||||
|
* objects that satisfy the conditions defined in the criterion function.
|
||||||
|
*/
|
||||||
|
QList< Partition* > findPartitions( const QList< Device* >& devices,
|
||||||
|
std::function< bool( Partition* ) > criterionFunction );
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
|
#endif // PARTITION_PARTITIONQUERY_H
|
36
src/libcalamares/partition/Sync.cpp
Normal file
36
src/libcalamares/partition/Sync.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Sync.h"
|
||||||
|
|
||||||
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
CalamaresUtils::Partition::sync()
|
||||||
|
{
|
||||||
|
auto r = CalamaresUtils::System::runCommand( { "/sbin/udevadm", "settle" }, std::chrono::seconds( 10 ) );
|
||||||
|
|
||||||
|
if ( r.getExitCode() != 0 )
|
||||||
|
{
|
||||||
|
cWarning() << "Could not settle disks.";
|
||||||
|
r.explainProcess( "udevadm", std::chrono::seconds( 10 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
CalamaresUtils::System::runCommand( { "/bin/sync" }, std::chrono::seconds( 10 ) );
|
||||||
|
}
|
46
src/libcalamares/partition/Sync.h
Normal file
46
src/libcalamares/partition/Sync.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PARTITION_SYNC_H
|
||||||
|
#define PARTITION_SYNC_H
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @brief Run "udevadm settle" or other disk-sync mechanism.
|
||||||
|
*
|
||||||
|
* Call this after mounting, unmount, toggling swap, or other functions
|
||||||
|
* that might cause the disk to be "busy" for other disk-modifying
|
||||||
|
* actions (in particular, KPMcore actions with the sfdisk backend
|
||||||
|
* are sensitive, and systemd tends to keep disks busy after a change
|
||||||
|
* for a while).
|
||||||
|
*/
|
||||||
|
void sync();
|
||||||
|
|
||||||
|
/** @brief RAII class for calling sync() */
|
||||||
|
struct Syncer
|
||||||
|
{
|
||||||
|
~Syncer() { sync(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
|
#endif
|
@ -117,53 +117,6 @@ System::instance()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
System::mount( const QString& devicePath,
|
|
||||||
const QString& mountPoint,
|
|
||||||
const QString& filesystemName,
|
|
||||||
const QString& options )
|
|
||||||
{
|
|
||||||
if ( devicePath.isEmpty() || mountPoint.isEmpty() )
|
|
||||||
{
|
|
||||||
if ( devicePath.isEmpty() )
|
|
||||||
{
|
|
||||||
cWarning() << "Can't mount an empty device.";
|
|
||||||
}
|
|
||||||
if ( mountPoint.isEmpty() )
|
|
||||||
{
|
|
||||||
cWarning() << "Can't mount on an empty mountpoint.";
|
|
||||||
}
|
|
||||||
|
|
||||||
return static_cast< int >( ProcessResult::Code::NoWorkingDirectory );
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir mountPointDir( mountPoint );
|
|
||||||
if ( !mountPointDir.exists() )
|
|
||||||
{
|
|
||||||
bool ok = mountPointDir.mkpath( mountPoint );
|
|
||||||
if ( !ok )
|
|
||||||
{
|
|
||||||
cWarning() << "Could not create mountpoint" << mountPoint;
|
|
||||||
return static_cast< int >( ProcessResult::Code::NoWorkingDirectory );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString program( "mount" );
|
|
||||||
QStringList args = { devicePath, mountPoint };
|
|
||||||
|
|
||||||
if ( !filesystemName.isEmpty() )
|
|
||||||
{
|
|
||||||
args << "-t" << filesystemName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !options.isEmpty() )
|
|
||||||
{
|
|
||||||
args << "-o" << options;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QProcess::execute( program, args );
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessResult
|
ProcessResult
|
||||||
System::runCommand( System::RunLocation location,
|
System::runCommand( System::RunLocation location,
|
||||||
const QStringList& args,
|
const QStringList& args,
|
||||||
|
@ -138,23 +138,6 @@ public:
|
|||||||
|
|
||||||
static System* instance();
|
static System* instance();
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs the mount utility with the specified parameters.
|
|
||||||
* @param devicePath the path of the partition to mount.
|
|
||||||
* @param mountPoint the full path of the target mount point.
|
|
||||||
* @param filesystemName the name of the filesystem (optional).
|
|
||||||
* @param options any additional options as passed to mount -o (optional).
|
|
||||||
* @returns the program's exit code, or:
|
|
||||||
* Crashed = QProcess crash
|
|
||||||
* FailedToStart = QProcess cannot start
|
|
||||||
* NoWorkingDirectory = bad arguments
|
|
||||||
*/
|
|
||||||
DLLEXPORT int mount( const QString& devicePath,
|
|
||||||
const QString& mountPoint,
|
|
||||||
const QString& filesystemName = QString(),
|
|
||||||
const QString& options = QString() );
|
|
||||||
|
|
||||||
|
|
||||||
/** (Typed) Boolean describing where a particular command should be run,
|
/** (Typed) Boolean describing where a particular command should be run,
|
||||||
* whether in the host (live) system or in the (chroot) target system.
|
* whether in the host (live) system or in the (chroot) target system.
|
||||||
*/
|
*/
|
||||||
@ -187,6 +170,16 @@ public:
|
|||||||
const QString& stdInput = QString(),
|
const QString& stdInput = QString(),
|
||||||
std::chrono::seconds timeoutSec = std::chrono::seconds( 0 ) );
|
std::chrono::seconds timeoutSec = std::chrono::seconds( 0 ) );
|
||||||
|
|
||||||
|
/** @brief Convenience wrapper for runCommand()
|
||||||
|
*
|
||||||
|
* Runs the given command-line @p args in the host in the current direcory
|
||||||
|
* with no input, and the given @p timeoutSec for completion.
|
||||||
|
*/
|
||||||
|
static inline ProcessResult runCommand( const QStringList& args, std::chrono::seconds timeoutSec )
|
||||||
|
{
|
||||||
|
return runCommand( RunLocation::RunInHost, args, QString(), QString(), timeoutSec );
|
||||||
|
}
|
||||||
|
|
||||||
/** @brief Convenience wrapper for runCommand().
|
/** @brief Convenience wrapper for runCommand().
|
||||||
* Runs the command in the location specified through the boolean
|
* Runs the command in the location specified through the boolean
|
||||||
* doChroot(), which is what you usually want for running commands
|
* doChroot(), which is what you usually want for running commands
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,6 +19,7 @@
|
|||||||
|
|
||||||
#include "PythonQtUtilsWrapper.h"
|
#include "PythonQtUtilsWrapper.h"
|
||||||
|
|
||||||
|
#include "partition/Mount.h"
|
||||||
#include "utils/CalamaresUtilsSystem.h"
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/String.h"
|
#include "utils/String.h"
|
||||||
@ -46,7 +48,7 @@ Utils::mount( const QString& device_path,
|
|||||||
const QString& filesystem_name,
|
const QString& filesystem_name,
|
||||||
const QString& options ) const
|
const QString& options ) const
|
||||||
{
|
{
|
||||||
return CalamaresUtils::System::instance()->mount( device_path, mount_point, filesystem_name, options );
|
return CalamaresUtils::Partition::mount( device_path, mount_point, filesystem_name, options );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,11 +8,10 @@ set( _partition_defs "" )
|
|||||||
if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND )
|
if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND )
|
||||||
include_directories( ${KPMCORE_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/modules/partition )
|
include_directories( ${KPMCORE_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/modules/partition )
|
||||||
|
|
||||||
if ( KPMcore_VERSION VERSION_GREATER "3.3.0")
|
if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.0" )
|
||||||
list( APPEND _partition_defs WITH_KPMCORE331API) # kpmcore > 3.3.0 with deprecations
|
list( APPEND _partition_defs WITH_KPMCORE4API ) # kpmcore 4 with new API
|
||||||
endif()
|
elseif( KPMcore_VERSION VERSION_GREATER "3.3.70" )
|
||||||
if ( KPMcore_VERSION VERSION_GREATER "3.90")
|
message( FATAL_ERROR "KPMCore beta versions ${KPMcore_VERSION} are not supported" )
|
||||||
list( APPEND _partition_defs WITH_KPMCORE4API) # kpmcore 4 with new API
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# The PartitionIterator is a small class, and it's easiest -- but also a
|
# The PartitionIterator is a small class, and it's easiest -- but also a
|
||||||
@ -22,7 +21,6 @@ if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND
|
|||||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||||
SOURCES
|
SOURCES
|
||||||
ResizeFSJob.cpp
|
ResizeFSJob.cpp
|
||||||
${PROJECT_SOURCE_DIR}/src/modules/partition/core/PartitionIterator.cpp
|
|
||||||
LINK_PRIVATE_LIBRARIES
|
LINK_PRIVATE_LIBRARIES
|
||||||
kpmcore
|
kpmcore
|
||||||
calamares
|
calamares
|
||||||
@ -37,10 +35,8 @@ if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND
|
|||||||
LIBRARIES
|
LIBRARIES
|
||||||
calamares_job_fsresizer # From above
|
calamares_job_fsresizer # From above
|
||||||
yamlcpp
|
yamlcpp
|
||||||
|
DEFINITIONS ${_partition_defs}
|
||||||
)
|
)
|
||||||
if( TARGET fsresizertest )
|
|
||||||
target_compile_definitions( fsresizertest PRIVATE ${_partition_defs} )
|
|
||||||
endif()
|
|
||||||
else()
|
else()
|
||||||
if ( NOT KPMcore_FOUND )
|
if ( NOT KPMcore_FOUND )
|
||||||
calamares_skip_module( "fsresizer (missing suitable KPMcore)" )
|
calamares_skip_module( "fsresizer (missing suitable KPMcore)" )
|
||||||
|
@ -18,6 +18,14 @@
|
|||||||
|
|
||||||
#include "ResizeFSJob.h"
|
#include "ResizeFSJob.h"
|
||||||
|
|
||||||
|
#include "CalamaresVersion.h"
|
||||||
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
#include "partition/PartitionIterator.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/Units.h"
|
||||||
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@ -29,17 +37,7 @@
|
|||||||
#include <kpmcore/ops/resizeoperation.h>
|
#include <kpmcore/ops/resizeoperation.h>
|
||||||
#include <kpmcore/util/report.h>
|
#include <kpmcore/util/report.h>
|
||||||
|
|
||||||
#include "CalamaresVersion.h"
|
using CalamaresUtils::Partition::PartitionIterator;
|
||||||
#include "JobQueue.h"
|
|
||||||
#include "GlobalStorage.h"
|
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
|
||||||
#include "utils/Units.h"
|
|
||||||
#include "utils/Variant.h"
|
|
||||||
|
|
||||||
// From partition module
|
|
||||||
#include "core/PartitionIterator.h"
|
|
||||||
|
|
||||||
|
|
||||||
ResizeFSJob::ResizeFSJob( QObject* parent )
|
ResizeFSJob::ResizeFSJob( QObject* parent )
|
||||||
: Calamares::CppJob( parent )
|
: Calamares::CppJob( parent )
|
||||||
@ -60,13 +58,13 @@ ResizeFSJob::prettyName() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResizeFSJob::PartitionMatch
|
ResizeFSJob::PartitionMatch
|
||||||
ResizeFSJob::findPartition( CoreBackend* backend )
|
ResizeFSJob::findPartition()
|
||||||
{
|
{
|
||||||
using DeviceList = QList< Device* >;
|
using DeviceList = QList< Device* >;
|
||||||
#ifdef WITH_KPMCORE331API
|
#if defined( WITH_KPMCORE4API )
|
||||||
DeviceList devices = backend->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag(0) );
|
DeviceList devices = m_kpmcore.backend()->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag(0) );
|
||||||
#else
|
#else
|
||||||
DeviceList devices = backend->scanDevices( /* excludeReadOnly */ true );
|
DeviceList devices = m_kpmcore.backend()->scanDevices( /* excludeReadOnly */ true );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cDebug() << "ResizeFSJob found" << devices.count() << "devices.";
|
cDebug() << "ResizeFSJob found" << devices.count() << "devices.";
|
||||||
@ -172,35 +170,17 @@ ResizeFSJob::exec()
|
|||||||
tr( "Invalid configuration" ),
|
tr( "Invalid configuration" ),
|
||||||
tr( "The file-system resize job has an invalid configuration and will not run." ) );
|
tr( "The file-system resize job has an invalid configuration and will not run." ) );
|
||||||
|
|
||||||
// Get KPMCore
|
if ( !m_kpmcore)
|
||||||
auto backend_p = CoreBackendManager::self()->backend();
|
|
||||||
if ( backend_p )
|
|
||||||
cDebug() << "KPMCore backend @" << ( void* )backend_p << backend_p->id() << backend_p->version();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cDebug() << "No KPMCore backend loaded yet";
|
|
||||||
QByteArray backendName = qgetenv( "KPMCORE_BACKEND" );
|
|
||||||
if ( !CoreBackendManager::self()->load( backendName.isEmpty() ? CoreBackendManager::defaultBackendName() : backendName ) )
|
|
||||||
{
|
|
||||||
cWarning() << "Could not load KPMCore backend.";
|
|
||||||
return Calamares::JobResult::error(
|
|
||||||
tr( "KPMCore not Available" ),
|
|
||||||
tr( "Calamares cannot start KPMCore for the file-system resize job." ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
backend_p = CoreBackendManager::self()->backend();
|
|
||||||
}
|
|
||||||
if ( !backend_p )
|
|
||||||
{
|
{
|
||||||
cWarning() << "Could not load KPMCore backend (2).";
|
cWarning() << "Could not load KPMCore backend (2).";
|
||||||
return Calamares::JobResult::error(
|
return Calamares::JobResult::error(
|
||||||
tr( "KPMCore not Available" ),
|
tr( "KPMCore not Available" ),
|
||||||
tr( "Calamares cannot start KPMCore for the file-system resize job." ) );
|
tr( "Calamares cannot start KPMCore for the file-system resize job." ) );
|
||||||
}
|
}
|
||||||
backend_p->initFSSupport(); // Might not be enough, see below
|
m_kpmcore.backend()->initFSSupport(); // Might not be enough, see below
|
||||||
|
|
||||||
// Now get the partition and FS we want to work on
|
// Now get the partition and FS we want to work on
|
||||||
PartitionMatch m = findPartition( backend_p );
|
PartitionMatch m = findPartition();
|
||||||
if ( !m.first || !m.second )
|
if ( !m.first || !m.second )
|
||||||
return Calamares::JobResult::error(
|
return Calamares::JobResult::error(
|
||||||
tr( "Resize Failed" ),
|
tr( "Resize Failed" ),
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <CppJob.h>
|
#include <CppJob.h>
|
||||||
|
|
||||||
|
#include "partition/KPMManager.h"
|
||||||
#include "partition/PartitionSize.h"
|
#include "partition/PartitionSize.h"
|
||||||
#include "utils/PluginFactory.h"
|
#include "utils/PluginFactory.h"
|
||||||
|
|
||||||
@ -72,6 +73,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CalamaresUtils::Partition::KPMManager m_kpmcore;
|
||||||
PartitionSize m_size;
|
PartitionSize m_size;
|
||||||
PartitionSize m_atleast;
|
PartitionSize m_atleast;
|
||||||
QString m_fsname; // Either this, or devicename, is set, not both
|
QString m_fsname; // Either this, or devicename, is set, not both
|
||||||
@ -79,8 +81,8 @@ private:
|
|||||||
bool m_required;
|
bool m_required;
|
||||||
|
|
||||||
using PartitionMatch = QPair<Device*, Partition*>;
|
using PartitionMatch = QPair<Device*, Partition*>;
|
||||||
/** @brief Find the configured FS using KPMCore @p backend */
|
/** @brief Find the configured FS */
|
||||||
PartitionMatch findPartition( CoreBackend* backend );
|
PartitionMatch findPartition();
|
||||||
|
|
||||||
/** @brief Return a new end-sector for the given dev-part pair. */
|
/** @brief Return a new end-sector for the given dev-part pair. */
|
||||||
qint64 findGrownEnd( PartitionMatch );
|
qint64 findGrownEnd( PartitionMatch );
|
||||||
|
@ -45,6 +45,9 @@ void
|
|||||||
InitramfsTests::initTestCase()
|
InitramfsTests::initTestCase()
|
||||||
{
|
{
|
||||||
Logger::setupLogLevel( Logger::LOGDEBUG );
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
||||||
|
|
||||||
|
auto* j = new Calamares::JobQueue();
|
||||||
|
(void) new CalamaresUtils::System( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char contents[] = "UMASK=0077\n";
|
static const char contents[] = "UMASK=0077\n";
|
||||||
@ -55,40 +58,21 @@ void InitramfsTests::cleanup()
|
|||||||
QFile::remove( confFile );
|
QFile::remove( confFile );
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitramfsTests::testCreateHostFile()
|
|
||||||
{
|
|
||||||
|
|
||||||
CalamaresUtils::System s( false ); // don't chroot
|
|
||||||
auto r = s.createTargetFile( confFile, QByteArray( contents ) );
|
|
||||||
QVERIFY( !r.failed() );
|
|
||||||
QVERIFY( r );
|
|
||||||
QString path = r.path();
|
|
||||||
QVERIFY( !path.isEmpty() );
|
|
||||||
QCOMPARE( path, confFile ); // don't chroot, so path create relative to /
|
|
||||||
QVERIFY( QFile::exists( confFile ) );
|
|
||||||
|
|
||||||
QFileInfo fi( confFile );
|
|
||||||
QVERIFY( fi.exists() );
|
|
||||||
QCOMPARE( fi.size(), sizeof( contents )-1 ); // don't count trailing NUL
|
|
||||||
|
|
||||||
QFile::remove( confFile );
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitramfsTests::testCreateTargetFile()
|
void InitramfsTests::testCreateTargetFile()
|
||||||
{
|
{
|
||||||
static const char short_confFile[] = "/calamares-safe-umask";
|
static const char short_confFile[] = "/calamares-safe-umask";
|
||||||
|
|
||||||
CalamaresUtils::System s( true );
|
auto* s = CalamaresUtils::System::instance();
|
||||||
auto r = s.createTargetFile( short_confFile, QByteArray( contents ) );
|
auto r = s->createTargetFile( short_confFile, QByteArray( contents ) );
|
||||||
QVERIFY( r.failed() );
|
QVERIFY( r.failed() );
|
||||||
QVERIFY( !r );
|
QVERIFY( !r );
|
||||||
QString path = r.path();
|
QString path = r.path();
|
||||||
QVERIFY( path.isEmpty() ); // because no rootmountpoint is set
|
QVERIFY( path.isEmpty() ); // because no rootmountpoint is set
|
||||||
|
|
||||||
Calamares::JobQueue j;
|
Calamares::JobQueue::instance()->globalStorage()->insert( "rootMountPoint", "/tmp" );
|
||||||
j.globalStorage()->insert( "rootMountPoint", "/tmp" );
|
|
||||||
|
|
||||||
path = s.createTargetFile( short_confFile, QByteArray( contents ) );
|
path = s->createTargetFile( short_confFile, QByteArray( contents ) ).path();
|
||||||
|
QCOMPARE( path, QString( confFile ) );
|
||||||
QVERIFY( path.endsWith( short_confFile ) ); // chroot, so path create relative to
|
QVERIFY( path.endsWith( short_confFile ) ); // chroot, so path create relative to
|
||||||
QVERIFY( path.startsWith( "/tmp/" ) );
|
QVERIFY( path.startsWith( "/tmp/" ) );
|
||||||
QVERIFY( QFile::exists( path ) );
|
QVERIFY( QFile::exists( path ) );
|
||||||
|
@ -32,7 +32,7 @@ private Q_SLOTS:
|
|||||||
void initTestCase();
|
void initTestCase();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
void testCreateHostFile();
|
// TODO: this doesn't actually test any of the functionality of this job
|
||||||
void testCreateTargetFile();
|
void testCreateTargetFile();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE)
|
|||||||
find_package( KPMcore 3.3 )
|
find_package( KPMcore 3.3 )
|
||||||
set_package_properties(
|
set_package_properties(
|
||||||
KPMcore PROPERTIES
|
KPMcore PROPERTIES
|
||||||
PURPOSE "For partitioning module"
|
PURPOSE "For partition module"
|
||||||
)
|
)
|
||||||
find_package( KF5Config CONFIG )
|
find_package( KF5Config CONFIG )
|
||||||
find_package( KF5I18n CONFIG )
|
find_package( KF5I18n CONFIG )
|
||||||
@ -51,7 +51,6 @@ if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND
|
|||||||
core/PartitionActions.cpp
|
core/PartitionActions.cpp
|
||||||
core/PartitionCoreModule.cpp
|
core/PartitionCoreModule.cpp
|
||||||
core/PartitionInfo.cpp
|
core/PartitionInfo.cpp
|
||||||
core/PartitionIterator.cpp
|
|
||||||
core/PartitionLayout.cpp
|
core/PartitionLayout.cpp
|
||||||
core/PartitionModel.cpp
|
core/PartitionModel.cpp
|
||||||
core/PartUtils.cpp
|
core/PartUtils.cpp
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
|
|
||||||
#include "core/BootLoaderModel.h"
|
#include "core/BootLoaderModel.h"
|
||||||
|
|
||||||
#include "core/PartitionInfo.h"
|
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
|
#include "core/PartitionInfo.h"
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
@ -44,9 +44,7 @@ BootLoaderModel::BootLoaderModel( QObject* parent )
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BootLoaderModel::~BootLoaderModel()
|
BootLoaderModel::~BootLoaderModel() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BootLoaderModel::init( const QList< Device* >& devices )
|
BootLoaderModel::init( const QList< Device* >& devices )
|
||||||
@ -67,11 +65,8 @@ BootLoaderModel::createMbrItems()
|
|||||||
{
|
{
|
||||||
for ( auto device : m_devices )
|
for ( auto device : m_devices )
|
||||||
{
|
{
|
||||||
QString text = tr( "Master Boot Record of %1" )
|
QString text = tr( "Master Boot Record of %1" ).arg( device->name() );
|
||||||
.arg( device->name() );
|
appendRow( createBootLoaderItem( text, device->deviceNode(), false ) );
|
||||||
appendRow(
|
|
||||||
createBootLoaderItem( text, device->deviceNode(), false )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,24 +85,30 @@ BootLoaderModel::update()
|
|||||||
void
|
void
|
||||||
BootLoaderModel::updateInternal()
|
BootLoaderModel::updateInternal()
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_lock);
|
QMutexLocker lock( &m_lock );
|
||||||
clear();
|
clear();
|
||||||
createMbrItems();
|
createMbrItems();
|
||||||
|
|
||||||
// An empty model is possible if you don't havee permissions: don't crash though.
|
// An empty model is possible if you don't havee permissions: don't crash though.
|
||||||
if ( rowCount() < 1 )
|
if ( rowCount() < 1 )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QString partitionText;
|
QString partitionText;
|
||||||
Partition* partition = KPMHelpers::findPartitionByMountPoint( m_devices, "/boot" );
|
Partition* partition = KPMHelpers::findPartitionByMountPoint( m_devices, "/boot" );
|
||||||
if ( partition )
|
if ( partition )
|
||||||
|
{
|
||||||
partitionText = tr( "Boot Partition" );
|
partitionText = tr( "Boot Partition" );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
partition = KPMHelpers::findPartitionByMountPoint( m_devices, "/" );
|
partition = KPMHelpers::findPartitionByMountPoint( m_devices, "/" );
|
||||||
if ( partition )
|
if ( partition )
|
||||||
|
{
|
||||||
partitionText = tr( "System Partition" );
|
partitionText = tr( "System Partition" );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Q_ASSERT( rowCount() > 0 );
|
Q_ASSERT( rowCount() > 0 );
|
||||||
QStandardItem* last = item( rowCount() - 1 );
|
QStandardItem* last = item( rowCount() - 1 );
|
||||||
@ -117,8 +118,10 @@ BootLoaderModel::updateInternal()
|
|||||||
if ( !partition )
|
if ( !partition )
|
||||||
{
|
{
|
||||||
if ( lastIsPartition )
|
if ( lastIsPartition )
|
||||||
|
{
|
||||||
takeRow( rowCount() - 1 );
|
takeRow( rowCount() - 1 );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString mountPoint = PartitionInfo::mountPoint( partition );
|
QString mountPoint = PartitionInfo::mountPoint( partition );
|
||||||
@ -129,15 +132,11 @@ BootLoaderModel::updateInternal()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
appendRow(
|
appendRow( createBootLoaderItem( partitionText, PartitionInfo::mountPoint( partition ), true ) );
|
||||||
createBootLoaderItem( partitionText, PartitionInfo::mountPoint( partition ), true )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create "don't install bootloader" item
|
// Create "don't install bootloader" item
|
||||||
appendRow(
|
appendRow( createBootLoaderItem( tr( "Do not install a boot loader" ), QString(), false ) );
|
||||||
createBootLoaderItem( tr( "Do not install a boot loader" ), QString(), false )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,13 +144,15 @@ BootLoaderModel::updateInternal()
|
|||||||
QVariant
|
QVariant
|
||||||
BootLoaderModel::data( const QModelIndex& index, int role ) const
|
BootLoaderModel::data( const QModelIndex& index, int role ) const
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_lock);
|
QMutexLocker lock( &m_lock );
|
||||||
if ( role == Qt::DisplayRole )
|
if ( role == Qt::DisplayRole )
|
||||||
{
|
{
|
||||||
QString displayRole = QStandardItemModel::data( index, Qt::DisplayRole ).toString();
|
QString displayRole = QStandardItemModel::data( index, Qt::DisplayRole ).toString();
|
||||||
QString pathRole = QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString();
|
QString pathRole = QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString();
|
||||||
if ( pathRole.isEmpty() )
|
if ( pathRole.isEmpty() )
|
||||||
|
{
|
||||||
return displayRole;
|
return displayRole;
|
||||||
|
}
|
||||||
|
|
||||||
return tr( "%1 (%2)" ).arg( displayRole, pathRole );
|
return tr( "%1 (%2)" ).arg( displayRole, pathRole );
|
||||||
}
|
}
|
||||||
@ -163,15 +164,19 @@ namespace Calamares
|
|||||||
int
|
int
|
||||||
findBootloader( const QAbstractItemModel* model, const QString& path )
|
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() );
|
const auto index = model->index( i, 0, QModelIndex() );
|
||||||
if ( !index.isValid() )
|
if ( !index.isValid() )
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
QVariant var = model->data( index, BootLoaderModel::BootLoaderPathRole );
|
QVariant var = model->data( index, BootLoaderModel::BootLoaderPathRole );
|
||||||
if ( var.isValid() && var.toString() == path )
|
if ( var.isValid() && var.toString() == path )
|
||||||
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -191,7 +196,7 @@ restoreSelectedBootLoader( QComboBox& combo, const QString& path )
|
|||||||
{
|
{
|
||||||
combo.setCurrentIndex( 0 );
|
combo.setCurrentIndex( 0 );
|
||||||
}
|
}
|
||||||
else if ( (r = findBootloader( model, path )) >= 0 )
|
else if ( ( r = findBootloader( model, path ) ) >= 0 )
|
||||||
{
|
{
|
||||||
combo.setCurrentIndex( r );
|
combo.setCurrentIndex( r );
|
||||||
}
|
}
|
||||||
@ -201,4 +206,4 @@ restoreSelectedBootLoader( QComboBox& combo, const QString& path )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace Calamares
|
||||||
|
@ -66,18 +66,18 @@ private:
|
|||||||
|
|
||||||
namespace Calamares
|
namespace Calamares
|
||||||
{
|
{
|
||||||
/** @brief Returns the row number of boot-loader @p path (e.g. /dev/sda)
|
/** @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
|
* Assuming the @p model is a BootLoaderModel, will return a row number
|
||||||
* in the model. Returns -1 otherwise.
|
* in the model. Returns -1 otherwise.
|
||||||
*/
|
*/
|
||||||
int findBootloader( const QAbstractItemModel* model, const QString& path );
|
int findBootloader( const QAbstractItemModel* model, const QString& path );
|
||||||
|
|
||||||
/** @brief Tries to set @p path as selected item in @p combo
|
/** @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
|
* Matches a boot-loader install path (e.g. /dev/sda) with a model
|
||||||
* row and sets that as the current row.
|
* row and sets that as the current row.
|
||||||
*/
|
*/
|
||||||
void restoreSelectedBootLoader( QComboBox& combo, const QString& path );
|
void restoreSelectedBootLoader( QComboBox& combo, const QString& path );
|
||||||
} // namespace
|
} // namespace Calamares
|
||||||
#endif /* BOOTLOADERMODEL_H */
|
#endif /* BOOTLOADERMODEL_H */
|
||||||
|
@ -20,8 +20,9 @@
|
|||||||
#include "core/ColorUtils.h"
|
#include "core/ColorUtils.h"
|
||||||
|
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
#include "core/PartitionIterator.h"
|
|
||||||
|
|
||||||
|
#include "partition/PartitionIterator.h"
|
||||||
|
#include "partition/PartitionQuery.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
@ -32,19 +33,21 @@
|
|||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
|
using CalamaresUtils::Partition::isPartitionFreeSpace;
|
||||||
|
using CalamaresUtils::Partition::isPartitionNew;
|
||||||
|
using CalamaresUtils::Partition::PartitionIterator;
|
||||||
|
|
||||||
static const int NUM_PARTITION_COLORS = 5;
|
static const int NUM_PARTITION_COLORS = 5;
|
||||||
static const int NUM_NEW_PARTITION_COLORS = 4;
|
static const int NUM_NEW_PARTITION_COLORS = 4;
|
||||||
//Let's try to use the Breeze palette
|
//Let's try to use the Breeze palette
|
||||||
static const QColor PARTITION_COLORS[ NUM_PARTITION_COLORS ] =
|
static const QColor PARTITION_COLORS[ NUM_PARTITION_COLORS ] = {
|
||||||
{
|
|
||||||
"#2980b9", //Dark Plasma Blue
|
"#2980b9", //Dark Plasma Blue
|
||||||
"#27ae60", //Dark Icon Green
|
"#27ae60", //Dark Icon Green
|
||||||
"#c9ce3b", //Dirty Yellow
|
"#c9ce3b", //Dirty Yellow
|
||||||
"#3daee9", //Plasma Blue
|
"#3daee9", //Plasma Blue
|
||||||
"#9b59b6", //Purple
|
"#9b59b6", //Purple
|
||||||
};
|
};
|
||||||
static const QColor NEW_PARTITION_COLORS[ NUM_NEW_PARTITION_COLORS ] =
|
static const QColor NEW_PARTITION_COLORS[ NUM_NEW_PARTITION_COLORS ] = {
|
||||||
{
|
|
||||||
"#c0392b", //Dark Icon Red
|
"#c0392b", //Dark Icon Red
|
||||||
"#f39c1f", //Dark Icon Yellow
|
"#f39c1f", //Dark Icon Yellow
|
||||||
"#f1b7bc", //Light Salmon
|
"#f1b7bc", //Light Salmon
|
||||||
@ -60,12 +63,14 @@ static QMap< QString, QColor > s_partitionColorsCache;
|
|||||||
namespace ColorUtils
|
namespace ColorUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
QColor freeSpaceColor()
|
QColor
|
||||||
|
freeSpaceColor()
|
||||||
{
|
{
|
||||||
return FREE_SPACE_COLOR;
|
return FREE_SPACE_COLOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor unknownDisklabelColor()
|
QColor
|
||||||
|
unknownDisklabelColor()
|
||||||
{
|
{
|
||||||
return UNKNOWN_DISKLABEL_COLOR;
|
return UNKNOWN_DISKLABEL_COLOR;
|
||||||
}
|
}
|
||||||
@ -73,9 +78,10 @@ QColor unknownDisklabelColor()
|
|||||||
PartitionNode*
|
PartitionNode*
|
||||||
_findRootForPartition( PartitionNode* partition )
|
_findRootForPartition( PartitionNode* partition )
|
||||||
{
|
{
|
||||||
if ( partition->isRoot() ||
|
if ( partition->isRoot() || !partition->parent() )
|
||||||
!partition->parent() )
|
{
|
||||||
return partition;
|
return partition;
|
||||||
|
}
|
||||||
|
|
||||||
return _findRootForPartition( partition->parent() );
|
return _findRootForPartition( partition->parent() );
|
||||||
}
|
}
|
||||||
@ -89,25 +95,32 @@ colorForPartition( Partition* partition )
|
|||||||
return FREE_SPACE_COLOR;
|
return FREE_SPACE_COLOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( KPMHelpers::isPartitionFreeSpace( partition ) )
|
if ( isPartitionFreeSpace( partition ) )
|
||||||
|
{
|
||||||
return FREE_SPACE_COLOR;
|
return FREE_SPACE_COLOR;
|
||||||
|
}
|
||||||
if ( partition->roles().has( PartitionRole::Extended ) )
|
if ( partition->roles().has( PartitionRole::Extended ) )
|
||||||
|
{
|
||||||
return EXTENDED_COLOR;
|
return EXTENDED_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
|
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone
|
||||||
!partition->fileSystem().uuid().isEmpty() )
|
&& !partition->fileSystem().uuid().isEmpty() )
|
||||||
{
|
{
|
||||||
if ( partition->fileSystem().type() == FileSystem::Luks )
|
if ( partition->fileSystem().type() == FileSystem::Luks )
|
||||||
{
|
{
|
||||||
FS::luks& luksFs = dynamic_cast< FS::luks& >( partition->fileSystem() );
|
FS::luks& luksFs = dynamic_cast< FS::luks& >( partition->fileSystem() );
|
||||||
if ( !luksFs.outerUuid().isEmpty() &&
|
if ( !luksFs.outerUuid().isEmpty() && s_partitionColorsCache.contains( luksFs.outerUuid() ) )
|
||||||
s_partitionColorsCache.contains( luksFs.outerUuid() ) )
|
{
|
||||||
return s_partitionColorsCache[ luksFs.outerUuid() ];
|
return s_partitionColorsCache[ luksFs.outerUuid() ];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( s_partitionColorsCache.contains( partition->fileSystem().uuid() ) )
|
if ( s_partitionColorsCache.contains( partition->fileSystem().uuid() ) )
|
||||||
|
{
|
||||||
return s_partitionColorsCache[ partition->fileSystem().uuid() ];
|
return s_partitionColorsCache[ partition->fileSystem().uuid() ];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// No partition-specific color needed, pick one from our list, but skip
|
// No partition-specific color needed, pick one from our list, but skip
|
||||||
// free space: we don't want a partition to change colors if space before
|
// free space: we don't want a partition to change colors if space before
|
||||||
@ -117,27 +130,30 @@ colorForPartition( Partition* partition )
|
|||||||
Q_ASSERT( table );
|
Q_ASSERT( table );
|
||||||
int colorIdx = 0;
|
int colorIdx = 0;
|
||||||
int newColorIdx = 0;
|
int newColorIdx = 0;
|
||||||
for ( PartitionIterator it = PartitionIterator::begin( table );
|
for ( PartitionIterator it = PartitionIterator::begin( table ); it != PartitionIterator::end( table ); ++it )
|
||||||
it != PartitionIterator::end( table );
|
|
||||||
++it )
|
|
||||||
{
|
{
|
||||||
Partition* child = *it;
|
Partition* child = *it;
|
||||||
if ( child == partition )
|
if ( child == partition )
|
||||||
break;
|
|
||||||
if ( !KPMHelpers::isPartitionFreeSpace( child ) &&
|
|
||||||
!child->hasChildren() )
|
|
||||||
{
|
{
|
||||||
if ( KPMHelpers::isPartitionNew( child ) )
|
break;
|
||||||
|
}
|
||||||
|
if ( !isPartitionFreeSpace( child ) && !child->hasChildren() )
|
||||||
|
{
|
||||||
|
if ( isPartitionNew( child ) )
|
||||||
|
{
|
||||||
++newColorIdx;
|
++newColorIdx;
|
||||||
|
}
|
||||||
++colorIdx;
|
++colorIdx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( KPMHelpers::isPartitionNew( partition ) )
|
if ( isPartitionNew( partition ) )
|
||||||
|
{
|
||||||
return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];
|
return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];
|
||||||
|
}
|
||||||
|
|
||||||
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
|
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone
|
||||||
!partition->fileSystem().uuid().isEmpty() )
|
&& !partition->fileSystem().uuid().isEmpty() )
|
||||||
{
|
{
|
||||||
if ( partition->fileSystem().type() == FileSystem::Luks )
|
if ( partition->fileSystem().type() == FileSystem::Luks )
|
||||||
{
|
{
|
||||||
@ -163,18 +179,18 @@ colorForPartitionInFreeSpace( Partition* partition )
|
|||||||
PartitionTable* table = dynamic_cast< PartitionTable* >( parent );
|
PartitionTable* table = dynamic_cast< PartitionTable* >( parent );
|
||||||
Q_ASSERT( table );
|
Q_ASSERT( table );
|
||||||
int newColorIdx = 0;
|
int newColorIdx = 0;
|
||||||
for ( PartitionIterator it = PartitionIterator::begin( table );
|
for ( PartitionIterator it = PartitionIterator::begin( table ); it != PartitionIterator::end( table ); ++it )
|
||||||
it != PartitionIterator::end( table );
|
|
||||||
++it )
|
|
||||||
{
|
{
|
||||||
Partition* child = *it;
|
Partition* child = *it;
|
||||||
if ( child == partition )
|
if ( child == partition )
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
if ( !KPMHelpers::isPartitionFreeSpace( child ) &&
|
}
|
||||||
!child->hasChildren() &&
|
if ( !isPartitionFreeSpace( child ) && !child->hasChildren() && isPartitionNew( child ) )
|
||||||
KPMHelpers::isPartitionNew( child ) )
|
{
|
||||||
++newColorIdx;
|
++newColorIdx;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];
|
return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,4 +201,4 @@ invalidateCache()
|
|||||||
s_partitionColorsCache.clear();
|
s_partitionColorsCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace ColorUtils
|
||||||
|
@ -53,6 +53,6 @@ QColor colorForPartitionInFreeSpace( Partition* freeSpacePartition );
|
|||||||
*/
|
*/
|
||||||
void invalidateCache();
|
void invalidateCache();
|
||||||
|
|
||||||
}
|
} // namespace ColorUtils
|
||||||
|
|
||||||
#endif /* COLORUTILS_H */
|
#endif /* COLORUTILS_H */
|
||||||
|
@ -20,23 +20,24 @@
|
|||||||
#include "DeviceList.h"
|
#include "DeviceList.h"
|
||||||
|
|
||||||
#include "PartitionCoreModule.h"
|
#include "PartitionCoreModule.h"
|
||||||
|
|
||||||
#include "core/DeviceModel.h"
|
#include "core/DeviceModel.h"
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
#include "core/PartitionIterator.h"
|
|
||||||
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
#include "partition/PartitionIterator.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <kpmcore/backend/corebackend.h>
|
#include <kpmcore/backend/corebackend.h>
|
||||||
#include <kpmcore/backend/corebackendmanager.h>
|
#include <kpmcore/backend/corebackendmanager.h>
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
|
|
||||||
#include <utils/Logger.h>
|
|
||||||
#include <JobQueue.h>
|
|
||||||
#include <GlobalStorage.h>
|
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
|
|
||||||
|
using CalamaresUtils::Partition::PartitionIterator;
|
||||||
|
|
||||||
namespace PartUtils
|
namespace PartUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -49,7 +50,9 @@ hasRootPartition( Device* device )
|
|||||||
{
|
{
|
||||||
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
||||||
if ( ( *it )->mountPoint() == "/" )
|
if ( ( *it )->mountPoint() == "/" )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,25 +71,30 @@ isIso9660( const Device* device )
|
|||||||
{
|
{
|
||||||
const QString path = device->deviceNode();
|
const QString path = device->deviceNode();
|
||||||
if ( path.isEmpty() )
|
if ( path.isEmpty() )
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if ( blkIdCheckIso9660( path ) )
|
if ( blkIdCheckIso9660( path ) )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ( device->partitionTable() &&
|
if ( device->partitionTable() && !device->partitionTable()->children().isEmpty() )
|
||||||
!device->partitionTable()->children().isEmpty() )
|
|
||||||
{
|
{
|
||||||
for ( const Partition* partition : device->partitionTable()->children() )
|
for ( const Partition* partition : device->partitionTable()->children() )
|
||||||
{
|
{
|
||||||
if ( blkIdCheckIso9660( partition->partitionPath() ) )
|
if ( blkIdCheckIso9660( partition->partitionPath() ) )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline QDebug&
|
static inline QDebug&
|
||||||
operator <<( QDebug& s, QList< Device* >::iterator& it )
|
operator<<( QDebug& s, QList< Device* >::iterator& it )
|
||||||
{
|
{
|
||||||
s << ( ( *it ) ? ( *it )->deviceNode() : QString( "<null device>" ) );
|
s << ( ( *it ) ? ( *it )->deviceNode() : QString( "<null device>" ) );
|
||||||
return s;
|
return s;
|
||||||
@ -95,7 +103,7 @@ operator <<( QDebug& s, QList< Device* >::iterator& it )
|
|||||||
using DeviceList = QList< Device* >;
|
using DeviceList = QList< Device* >;
|
||||||
|
|
||||||
static inline DeviceList::iterator
|
static inline DeviceList::iterator
|
||||||
erase(DeviceList& l, DeviceList::iterator& it)
|
erase( DeviceList& l, DeviceList::iterator& it )
|
||||||
{
|
{
|
||||||
Device* p = *it;
|
Device* p = *it;
|
||||||
auto r = l.erase( it );
|
auto r = l.erase( it );
|
||||||
@ -103,13 +111,14 @@ erase(DeviceList& l, DeviceList::iterator& it)
|
|||||||
return r;
|
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();
|
CoreBackend* backend = CoreBackendManager::self()->backend();
|
||||||
#ifdef WITH_KPMCORE331API
|
#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
|
#else
|
||||||
DeviceList devices = backend->scanDevices( /* excludeReadOnly */ true );
|
DeviceList devices = backend->scanDevices( /* excludeReadOnly */ true );
|
||||||
#endif
|
#endif
|
||||||
@ -127,14 +136,12 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize )
|
|||||||
if ( !( *it ) )
|
if ( !( *it ) )
|
||||||
{
|
{
|
||||||
cDebug() << Logger::SubEntry << "Skipping nullptr device";
|
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;
|
cDebug() << Logger::SubEntry << "Removing zram" << it;
|
||||||
it = erase( devices, it );
|
it = erase( devices, it );
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( writableOnly && hasRootPartition( *it ) )
|
else if ( writableOnly && hasRootPartition( *it ) )
|
||||||
{
|
{
|
||||||
@ -146,13 +153,15 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize )
|
|||||||
cDebug() << Logger::SubEntry << "Removing device with iso9660 filesystem (probably a CD) on it" << it;
|
cDebug() << Logger::SubEntry << "Removing device with iso9660 filesystem (probably a CD) on it" << it;
|
||||||
it = erase( devices, 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;
|
cDebug() << Logger::SubEntry << "Removing too-small" << it;
|
||||||
it = erase( devices, it );
|
it = erase( devices, it );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
++it;
|
++it;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return devices;
|
return devices;
|
||||||
|
@ -28,7 +28,11 @@ class Device;
|
|||||||
namespace PartUtils
|
namespace PartUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class DeviceType { All, WritableOnly };
|
enum class DeviceType
|
||||||
|
{
|
||||||
|
All,
|
||||||
|
WritableOnly
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets a list of storage devices.
|
* @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 );
|
QList< Device* > getDevices( DeviceType which = DeviceType::All, qint64 minimumSize = -1 );
|
||||||
|
|
||||||
}
|
} // namespace PartUtils
|
||||||
|
|
||||||
#endif // DEVICELIST_H
|
#endif // DEVICELIST_H
|
||||||
|
@ -30,8 +30,8 @@
|
|||||||
// KF5
|
// KF5
|
||||||
#include <KFormat>
|
#include <KFormat>
|
||||||
|
|
||||||
#include <QStandardItemModel>
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QStandardItemModel>
|
||||||
|
|
||||||
// STL
|
// STL
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -39,8 +39,7 @@
|
|||||||
static void
|
static void
|
||||||
sortDevices( DeviceModel::DeviceList& l )
|
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();
|
return dev1->deviceNode() < dev2->deviceNode();
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
@ -50,9 +49,7 @@ DeviceModel::DeviceModel( QObject* parent )
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceModel::~DeviceModel()
|
DeviceModel::~DeviceModel() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DeviceModel::init( const DeviceList& devices )
|
DeviceModel::init( const DeviceList& devices )
|
||||||
@ -74,7 +71,9 @@ DeviceModel::data( const QModelIndex& index, int role ) const
|
|||||||
{
|
{
|
||||||
int row = index.row();
|
int row = index.row();
|
||||||
if ( row < 0 || row >= m_devices.count() )
|
if ( row < 0 || row >= m_devices.count() )
|
||||||
|
{
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
Device* device = m_devices.at( row );
|
Device* device = m_devices.at( row );
|
||||||
|
|
||||||
@ -83,7 +82,9 @@ DeviceModel::data( const QModelIndex& index, int role ) const
|
|||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
if ( device->name().isEmpty() )
|
if ( device->name().isEmpty() )
|
||||||
|
{
|
||||||
return device->deviceNode();
|
return device->deviceNode();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( device->logicalSize() >= 0 && device->totalLogical() >= 0 )
|
if ( device->logicalSize() >= 0 && device->totalLogical() >= 0 )
|
||||||
@ -100,16 +101,14 @@ DeviceModel::data( const QModelIndex& index, int role ) const
|
|||||||
// always has 1B capacity), so don't show it for a while.
|
// always has 1B capacity), so don't show it for a while.
|
||||||
//
|
//
|
||||||
//: device[name] - (device-node[name])
|
//: device[name] - (device-node[name])
|
||||||
return tr( "%1 - (%2)" )
|
return tr( "%1 - (%2)" ).arg( device->name() ).arg( device->deviceNode() );
|
||||||
.arg( device->name() )
|
|
||||||
.arg( device->deviceNode() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionDisk,
|
return CalamaresUtils::defaultPixmap(
|
||||||
|
CalamaresUtils::PartitionDisk,
|
||||||
CalamaresUtils::Original,
|
CalamaresUtils::Original,
|
||||||
QSize( CalamaresUtils::defaultIconSize().width() * 3,
|
QSize( CalamaresUtils::defaultIconSize().width() * 3, CalamaresUtils::defaultIconSize().height() * 3 ) );
|
||||||
CalamaresUtils::defaultIconSize().height() * 3 ) );
|
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
@ -121,7 +120,9 @@ DeviceModel::deviceForIndex( const QModelIndex& index ) const
|
|||||||
{
|
{
|
||||||
int row = index.row();
|
int row = index.row();
|
||||||
if ( row < 0 || row >= m_devices.count() )
|
if ( row < 0 || row >= m_devices.count() )
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
return m_devices.at( row );
|
return m_devices.at( row );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +135,9 @@ DeviceModel::swapDevice( Device* oldDevice, Device* newDevice )
|
|||||||
|
|
||||||
int indexOfOldDevice = m_devices.indexOf( oldDevice );
|
int indexOfOldDevice = m_devices.indexOf( oldDevice );
|
||||||
if ( indexOfOldDevice < 0 )
|
if ( indexOfOldDevice < 0 )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_devices[ indexOfOldDevice ] = newDevice;
|
m_devices[ indexOfOldDevice ] = newDevice;
|
||||||
|
|
||||||
@ -142,7 +145,7 @@ DeviceModel::swapDevice( Device* oldDevice, Device* newDevice )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DeviceModel::addDevice( Device *device )
|
DeviceModel::addDevice( Device* device )
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_devices << device;
|
m_devices << device;
|
||||||
@ -151,7 +154,7 @@ DeviceModel::addDevice( Device *device )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DeviceModel::removeDevice( Device *device )
|
DeviceModel::removeDevice( Device* device )
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_devices.removeAll( device );
|
m_devices.removeAll( device );
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
#define DEVICEMODEL_H
|
#define DEVICEMODEL_H
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QScopedPointer>
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QScopedPointer>
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class PartitionModel;
|
class PartitionModel;
|
||||||
|
@ -21,94 +21,35 @@
|
|||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
|
|
||||||
#include "core/PartitionInfo.h"
|
#include "core/PartitionInfo.h"
|
||||||
#include "core/PartitionIterator.h"
|
|
||||||
|
#include "partition/PartitionIterator.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
|
#include <kpmcore/backend/corebackendmanager.h>
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
#include <kpmcore/fs/filesystemfactory.h>
|
#include <kpmcore/fs/filesystemfactory.h>
|
||||||
#include <kpmcore/backend/corebackendmanager.h>
|
|
||||||
#include <kpmcore/fs/luks.h>
|
#include <kpmcore/fs/luks.h>
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
using CalamaresUtils::Partition::PartitionIterator;
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
|
|
||||||
namespace KPMHelpers
|
namespace KPMHelpers
|
||||||
{
|
{
|
||||||
|
|
||||||
static bool s_KPMcoreInited = false;
|
|
||||||
|
|
||||||
bool
|
|
||||||
initKPMcore()
|
|
||||||
{
|
|
||||||
if ( s_KPMcoreInited )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
QByteArray backendName = qgetenv( "KPMCORE_BACKEND" );
|
|
||||||
if ( !CoreBackendManager::self()->load( backendName.isEmpty() ? CoreBackendManager::defaultBackendName() : backendName ) )
|
|
||||||
{
|
|
||||||
cWarning() << "Failed to load backend plugin" << backendName;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
s_KPMcoreInited = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
isPartitionFreeSpace( Partition* partition )
|
|
||||||
{
|
|
||||||
return partition->roles().has( PartitionRole::Unallocated );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
isPartitionNew( Partition* partition )
|
|
||||||
{
|
|
||||||
return partition->state() == KPM_PARTITION_STATE(New);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Partition*
|
Partition*
|
||||||
findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint )
|
findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint )
|
||||||
{
|
{
|
||||||
for ( auto device : devices )
|
for ( auto device : devices )
|
||||||
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
||||||
if ( PartitionInfo::mountPoint( *it ) == mountPoint )
|
if ( PartitionInfo::mountPoint( *it ) == mountPoint )
|
||||||
|
{
|
||||||
return *it;
|
return *it;
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Partition*
|
|
||||||
findPartitionByPath( const QList< Device* >& devices, const QString& path )
|
|
||||||
{
|
|
||||||
if ( path.simplified().isEmpty() )
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
for ( auto device : devices )
|
|
||||||
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
|
||||||
if ( ( *it )->partitionPath() == path.simplified() )
|
|
||||||
return *it;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QList< Partition* >
|
|
||||||
findPartitions( const QList< Device* >& devices,
|
|
||||||
std::function< bool ( Partition* ) > criterionFunction )
|
|
||||||
{
|
|
||||||
QList< Partition* > results;
|
|
||||||
for ( auto device : devices )
|
|
||||||
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
|
||||||
if ( criterionFunction( *it ) )
|
|
||||||
results.append( *it );
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Partition*
|
Partition*
|
||||||
createNewPartition( PartitionNode* parent,
|
createNewPartition( PartitionNode* parent,
|
||||||
const Device& device,
|
const Device& device,
|
||||||
@ -118,21 +59,19 @@ createNewPartition( PartitionNode* parent,
|
|||||||
qint64 lastSector,
|
qint64 lastSector,
|
||||||
PartitionTable::Flags flags )
|
PartitionTable::Flags flags )
|
||||||
{
|
{
|
||||||
FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector
|
FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector, device.logicalSize() );
|
||||||
,device.logicalSize()
|
return new Partition( parent,
|
||||||
);
|
|
||||||
return new Partition(
|
|
||||||
parent,
|
|
||||||
device,
|
device,
|
||||||
role,
|
role,
|
||||||
fs, fs->firstSector(), fs->lastSector(),
|
fs,
|
||||||
|
fs->firstSector(),
|
||||||
|
fs->lastSector(),
|
||||||
QString() /* path */,
|
QString() /* path */,
|
||||||
KPM_PARTITION_FLAG(None) /* availableFlags */,
|
KPM_PARTITION_FLAG( None ) /* availableFlags */,
|
||||||
QString() /* mountPoint */,
|
QString() /* mountPoint */,
|
||||||
false /* mounted */,
|
false /* mounted */,
|
||||||
flags /* activeFlags */,
|
flags /* activeFlags */,
|
||||||
KPM_PARTITION_STATE(New)
|
KPM_PARTITION_STATE( New ) );
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -148,14 +87,12 @@ createNewEncryptedPartition( PartitionNode* parent,
|
|||||||
{
|
{
|
||||||
PartitionRole::Roles newRoles = role.roles();
|
PartitionRole::Roles newRoles = role.roles();
|
||||||
if ( !role.has( PartitionRole::Luks ) )
|
if ( !role.has( PartitionRole::Luks ) )
|
||||||
|
{
|
||||||
newRoles |= PartitionRole::Luks;
|
newRoles |= PartitionRole::Luks;
|
||||||
|
}
|
||||||
|
|
||||||
FS::luks* fs = dynamic_cast< FS::luks* >(
|
FS::luks* fs = dynamic_cast< FS::luks* >(
|
||||||
FileSystemFactory::create( FileSystem::Luks,
|
FileSystemFactory::create( FileSystem::Luks, firstSector, lastSector, device.logicalSize() ) );
|
||||||
firstSector,
|
|
||||||
lastSector
|
|
||||||
,device.logicalSize()
|
|
||||||
) );
|
|
||||||
if ( !fs )
|
if ( !fs )
|
||||||
{
|
{
|
||||||
cError() << "cannot create LUKS filesystem. Giving up.";
|
cError() << "cannot create LUKS filesystem. Giving up.";
|
||||||
@ -167,13 +104,15 @@ createNewEncryptedPartition( PartitionNode* parent,
|
|||||||
Partition* p = new Partition( parent,
|
Partition* p = new Partition( parent,
|
||||||
device,
|
device,
|
||||||
PartitionRole( newRoles ),
|
PartitionRole( newRoles ),
|
||||||
fs, fs->firstSector(), fs->lastSector(),
|
fs,
|
||||||
|
fs->firstSector(),
|
||||||
|
fs->lastSector(),
|
||||||
QString() /* path */,
|
QString() /* path */,
|
||||||
KPM_PARTITION_FLAG(None) /* availableFlags */,
|
KPM_PARTITION_FLAG( None ) /* availableFlags */,
|
||||||
QString() /* mountPoint */,
|
QString() /* mountPoint */,
|
||||||
false /* mounted */,
|
false /* mounted */,
|
||||||
flags /* activeFlags */,
|
flags /* activeFlags */,
|
||||||
KPM_PARTITION_STATE(New) );
|
KPM_PARTITION_STATE( New ) );
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,11 +121,7 @@ Partition*
|
|||||||
clonePartition( Device* device, Partition* partition )
|
clonePartition( Device* device, Partition* partition )
|
||||||
{
|
{
|
||||||
FileSystem* fs = FileSystemFactory::create(
|
FileSystem* fs = FileSystemFactory::create(
|
||||||
partition->fileSystem().type(),
|
partition->fileSystem().type(), partition->firstSector(), partition->lastSector(), device->logicalSize() );
|
||||||
partition->firstSector(),
|
|
||||||
partition->lastSector()
|
|
||||||
,device->logicalSize()
|
|
||||||
);
|
|
||||||
return new Partition( partition->parent(),
|
return new Partition( partition->parent(),
|
||||||
*device,
|
*device,
|
||||||
partition->roles(),
|
partition->roles(),
|
||||||
@ -197,48 +132,4 @@ clonePartition( Device* device, Partition* partition )
|
|||||||
partition->activeFlags() );
|
partition->activeFlags() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace KPMHelpers
|
||||||
QString
|
|
||||||
prettyNameForFileSystemType( FileSystem::Type t )
|
|
||||||
{
|
|
||||||
switch ( t )
|
|
||||||
{
|
|
||||||
case FileSystem::Unknown:
|
|
||||||
return QObject::tr( "unknown" );
|
|
||||||
case FileSystem::Extended:
|
|
||||||
return QObject::tr( "extended" );
|
|
||||||
case FileSystem::Unformatted:
|
|
||||||
return QObject::tr( "unformatted" );
|
|
||||||
case FileSystem::LinuxSwap:
|
|
||||||
return QObject::tr( "swap" );
|
|
||||||
case FileSystem::Fat16:
|
|
||||||
case FileSystem::Fat32:
|
|
||||||
case FileSystem::Ntfs:
|
|
||||||
case FileSystem::Xfs:
|
|
||||||
case FileSystem::Jfs:
|
|
||||||
case FileSystem::Hfs:
|
|
||||||
case FileSystem::Ufs:
|
|
||||||
case FileSystem::Hpfs:
|
|
||||||
case FileSystem::Luks:
|
|
||||||
case FileSystem::Ocfs2:
|
|
||||||
case FileSystem::Zfs:
|
|
||||||
case FileSystem::Nilfs2:
|
|
||||||
return FileSystem::nameForType( t ).toUpper();
|
|
||||||
case FileSystem::ReiserFS:
|
|
||||||
return "ReiserFS";
|
|
||||||
case FileSystem::Reiser4:
|
|
||||||
return "Reiser4";
|
|
||||||
case FileSystem::HfsPlus:
|
|
||||||
return "HFS+";
|
|
||||||
case FileSystem::Btrfs:
|
|
||||||
return "Btrfs";
|
|
||||||
case FileSystem::Exfat:
|
|
||||||
return "exFAT";
|
|
||||||
case FileSystem::Lvm2_PV:
|
|
||||||
return "LVM PV";
|
|
||||||
default:
|
|
||||||
return FileSystem::nameForType( t );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
@ -34,13 +34,13 @@ class Partition;
|
|||||||
class PartitionNode;
|
class PartitionNode;
|
||||||
class PartitionRole;
|
class PartitionRole;
|
||||||
|
|
||||||
#ifdef WITH_KPMCORE331API
|
#if defined( WITH_KPMCORE4API )
|
||||||
#define KPM_PARTITION_FLAG(x) PartitionTable::Flag::x
|
#define KPM_PARTITION_FLAG( x ) PartitionTable::Flag::x
|
||||||
#define KPM_PARTITION_STATE(x) Partition::State::x
|
#define KPM_PARTITION_STATE( x ) Partition::State::x
|
||||||
#define KPM_PARTITION_FLAG_ESP PartitionTable::Flag::Boot
|
#define KPM_PARTITION_FLAG_ESP PartitionTable::Flag::Boot
|
||||||
#else
|
#else
|
||||||
#define KPM_PARTITION_FLAG(x) PartitionTable::Flag##x
|
#define KPM_PARTITION_FLAG( x ) PartitionTable::Flag##x
|
||||||
#define KPM_PARTITION_STATE(x) Partition::State##x
|
#define KPM_PARTITION_STATE( x ) Partition::State##x
|
||||||
#define KPM_PARTITION_FLAG_ESP PartitionTable::FlagEsp
|
#define KPM_PARTITION_FLAG_ESP PartitionTable::FlagEsp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -50,46 +50,12 @@ class PartitionRole;
|
|||||||
namespace KPMHelpers
|
namespace KPMHelpers
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Thin wrapper on top of CoreBackendManager. Hides things like initializing the
|
|
||||||
* Config instance or instantiating the backend.
|
|
||||||
*
|
|
||||||
* Initialize PartitionManager Config object and load a PartitionManager
|
|
||||||
* backend. It loads the "libparted" plugin by default, but this can be
|
|
||||||
* overloaded by settings the environment variable KPMCORE_BACKEND. Setting it to
|
|
||||||
* "dummy" will load the dummy plugin instead.
|
|
||||||
*
|
|
||||||
* @return true if initialization was successful.
|
|
||||||
*/
|
|
||||||
bool initKPMcore();
|
|
||||||
|
|
||||||
bool isPartitionFreeSpace( Partition* );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the partition is planned to be created by the installer as
|
|
||||||
* opposed to already existing on the disk.
|
|
||||||
*/
|
|
||||||
bool isPartitionNew( Partition* );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterates on all devices and return the first partition which is associated
|
* Iterates on all devices and return the first partition which is associated
|
||||||
* with mountPoint. This uses PartitionInfo::mountPoint(), not Partition::mountPoint()
|
* with mountPoint. This uses PartitionInfo::mountPoint(), not Partition::mountPoint()
|
||||||
*/
|
*/
|
||||||
Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint );
|
Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint );
|
||||||
|
|
||||||
/**
|
|
||||||
* Iterates on all devices and partitions and returns a pointer to the Partition object
|
|
||||||
* for the given path, or nullptr if a Partition for the given path cannot be found.
|
|
||||||
*/
|
|
||||||
Partition* findPartitionByPath( const QList< Device* >& devices, const QString& path );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Iterates on all devices and partitions and returns a list of pointers to the Partition
|
|
||||||
* objects that satisfy the conditions defined in the criterion function.
|
|
||||||
*/
|
|
||||||
QList< Partition* > findPartitions( const QList< Device* >& devices,
|
|
||||||
std::function< bool ( Partition* ) > criterionFunction );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to create a new Partition object (does not create anything
|
* Helper function to create a new Partition object (does not create anything
|
||||||
* on the disk) associated with a FileSystem.
|
* on the disk) associated with a FileSystem.
|
||||||
@ -113,32 +79,6 @@ Partition* createNewEncryptedPartition( PartitionNode* parent,
|
|||||||
|
|
||||||
Partition* clonePartition( Device* device, Partition* partition );
|
Partition* clonePartition( Device* device, Partition* partition );
|
||||||
|
|
||||||
QString prettyNameForFileSystemType( FileSystem::Type t );
|
} // namespace KPMHelpers
|
||||||
|
|
||||||
static inline QString
|
|
||||||
untranslatedFS( FileSystem& fs )
|
|
||||||
{
|
|
||||||
return fs.name( { QStringLiteral( "C" ) } );
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline QString
|
|
||||||
untranslatedFS( FileSystem* fs )
|
|
||||||
{
|
|
||||||
return fs ? untranslatedFS( *fs ) : QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline QString
|
|
||||||
userVisibleFS( FileSystem& fs )
|
|
||||||
{
|
|
||||||
return fs.name();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline QString
|
|
||||||
userVisibleFS( FileSystem* fs )
|
|
||||||
{
|
|
||||||
return fs ? userVisibleFS( *fs ) : QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* KPMHELPERS_H */
|
#endif /* KPMHELPERS_H */
|
||||||
|
@ -25,21 +25,26 @@
|
|||||||
#include "core/DeviceModel.h"
|
#include "core/DeviceModel.h"
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
#include "core/PartitionInfo.h"
|
#include "core/PartitionInfo.h"
|
||||||
#include "core/PartitionIterator.h"
|
|
||||||
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
#include "partition/Mount.h"
|
||||||
|
#include "partition/PartitionIterator.h"
|
||||||
|
#include "partition/PartitionQuery.h"
|
||||||
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <kpmcore/backend/corebackend.h>
|
#include <kpmcore/backend/corebackend.h>
|
||||||
#include <kpmcore/backend/corebackendmanager.h>
|
#include <kpmcore/backend/corebackendmanager.h>
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
|
|
||||||
#include <utils/CalamaresUtilsSystem.h>
|
|
||||||
#include <utils/Logger.h>
|
|
||||||
#include <JobQueue.h>
|
|
||||||
#include <GlobalStorage.h>
|
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
|
|
||||||
|
using CalamaresUtils::Partition::isPartitionFreeSpace;
|
||||||
|
using CalamaresUtils::Partition::isPartitionNew;
|
||||||
|
|
||||||
namespace PartUtils
|
namespace PartUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -47,17 +52,25 @@ QString
|
|||||||
convenienceName( const Partition* const candidate )
|
convenienceName( const Partition* const candidate )
|
||||||
{
|
{
|
||||||
if ( !candidate->mountPoint().isEmpty() )
|
if ( !candidate->mountPoint().isEmpty() )
|
||||||
|
{
|
||||||
return candidate->mountPoint();
|
return candidate->mountPoint();
|
||||||
|
}
|
||||||
if ( !candidate->partitionPath().isEmpty() )
|
if ( !candidate->partitionPath().isEmpty() )
|
||||||
|
{
|
||||||
return candidate->partitionPath();
|
return candidate->partitionPath();
|
||||||
|
}
|
||||||
if ( !candidate->devicePath().isEmpty() )
|
if ( !candidate->devicePath().isEmpty() )
|
||||||
|
{
|
||||||
return candidate->devicePath();
|
return candidate->devicePath();
|
||||||
|
}
|
||||||
if ( !candidate->deviceNode().isEmpty() )
|
if ( !candidate->deviceNode().isEmpty() )
|
||||||
|
{
|
||||||
return candidate->devicePath();
|
return candidate->devicePath();
|
||||||
|
}
|
||||||
|
|
||||||
QString p;
|
QString p;
|
||||||
QTextStream s( &p );
|
QTextStream s( &p );
|
||||||
s << (void *)candidate;
|
s << (void*)candidate;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -124,15 +137,14 @@ canBeResized( Partition* candidate )
|
|||||||
}
|
}
|
||||||
|
|
||||||
cDebug() << "Checking if" << convenienceName( candidate ) << "can be resized.";
|
cDebug() << "Checking if" << convenienceName( candidate ) << "can be resized.";
|
||||||
if ( !candidate->fileSystem().supportGrow() ||
|
if ( !candidate->fileSystem().supportGrow() || !candidate->fileSystem().supportShrink() )
|
||||||
!candidate->fileSystem().supportShrink() )
|
|
||||||
{
|
{
|
||||||
cDebug() << Logger::SubEntry << "NO, filesystem" << candidate->fileSystem().name()
|
cDebug() << Logger::SubEntry << "NO, filesystem" << candidate->fileSystem().name()
|
||||||
<< "does not support resize.";
|
<< "does not support resize.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( KPMHelpers::isPartitionFreeSpace( candidate ) )
|
if ( isPartitionFreeSpace( candidate ) )
|
||||||
{
|
{
|
||||||
cDebug() << Logger::SubEntry << "NO, partition is free space";
|
cDebug() << Logger::SubEntry << "NO, partition is free space";
|
||||||
return false;
|
return false;
|
||||||
@ -155,8 +167,8 @@ canBeResized( Partition* candidate )
|
|||||||
|
|
||||||
if ( table->numPrimaries() >= table->maxPrimaries() )
|
if ( table->numPrimaries() >= table->maxPrimaries() )
|
||||||
{
|
{
|
||||||
cDebug() << Logger::SubEntry << "NO, partition table already has"
|
cDebug() << Logger::SubEntry << "NO, partition table already has" << table->maxPrimaries()
|
||||||
<< table->maxPrimaries() << "primary partitions.";
|
<< "primary partitions.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,8 +198,8 @@ canBeResized( Partition* candidate )
|
|||||||
deb << Logger::Continuation << "Required storage B:" << advisedStorageB
|
deb << Logger::Continuation << "Required storage B:" << advisedStorageB
|
||||||
<< QString( "(%1GiB)" ).arg( advisedStorageGiB );
|
<< QString( "(%1GiB)" ).arg( advisedStorageGiB );
|
||||||
deb << Logger::Continuation << "Available storage B:" << availableStorageB
|
deb << Logger::Continuation << "Available storage B:" << availableStorageB
|
||||||
<< QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) )
|
<< QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) ) << "for"
|
||||||
<< "for" << convenienceName( candidate ) << "length:" << candidate->length()
|
<< convenienceName( candidate ) << "length:" << candidate->length()
|
||||||
<< "sectorsUsed:" << candidate->sectorsUsed() << "fsType:" << candidate->fileSystem().name();
|
<< "sectorsUsed:" << candidate->sectorsUsed() << "fsType:" << candidate->fileSystem().name();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -205,7 +217,7 @@ canBeResized( PartitionCoreModule* core, const QString& partitionPath )
|
|||||||
for ( int i = 0; i < dm->rowCount(); ++i )
|
for ( int i = 0; i < dm->rowCount(); ++i )
|
||||||
{
|
{
|
||||||
Device* dev = dm->deviceForIndex( dm->index( i ) );
|
Device* dev = dm->deviceForIndex( dm->index( i ) );
|
||||||
Partition* candidate = KPMHelpers::findPartitionByPath( { dev }, partitionWithOs );
|
Partition* candidate = CalamaresUtils::Partition::findPartitionByPath( { dev }, partitionWithOs );
|
||||||
if ( candidate )
|
if ( candidate )
|
||||||
{
|
{
|
||||||
return canBeResized( candidate );
|
return canBeResized( candidate );
|
||||||
@ -222,66 +234,69 @@ canBeResized( PartitionCoreModule* core, const QString& partitionPath )
|
|||||||
static FstabEntryList
|
static FstabEntryList
|
||||||
lookForFstabEntries( const QString& partitionPath )
|
lookForFstabEntries( const QString& partitionPath )
|
||||||
{
|
{
|
||||||
QStringList mountOptions{ "ro" };
|
QStringList mountOptions { "ro" };
|
||||||
|
|
||||||
auto r = CalamaresUtils::System::runCommand(
|
auto r = CalamaresUtils::System::runCommand( CalamaresUtils::System::RunLocation::RunInHost,
|
||||||
CalamaresUtils::System::RunLocation::RunInHost,
|
{ "blkid", "-s", "TYPE", "-o", "value", partitionPath } );
|
||||||
{ "blkid", "-s", "TYPE", "-o", "value", partitionPath }
|
|
||||||
);
|
|
||||||
if ( r.getExitCode() )
|
if ( r.getExitCode() )
|
||||||
|
{
|
||||||
cWarning() << "blkid on" << partitionPath << "failed.";
|
cWarning() << "blkid on" << partitionPath << "failed.";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString fstype = r.getOutput().trimmed();
|
QString fstype = r.getOutput().trimmed();
|
||||||
if ( ( fstype == "ext3" ) || ( fstype == "ext4" ) )
|
if ( ( fstype == "ext3" ) || ( fstype == "ext4" ) )
|
||||||
|
{
|
||||||
mountOptions.append( "noload" );
|
mountOptions.append( "noload" );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cDebug() << "Checking device" << partitionPath
|
cDebug() << "Checking device" << partitionPath << "for fstab (fs=" << r.getOutput() << ')';
|
||||||
<< "for fstab (fs=" << r.getOutput() << ')';
|
|
||||||
|
|
||||||
FstabEntryList fstabEntries;
|
FstabEntryList fstabEntries;
|
||||||
QTemporaryDir mountsDir;
|
|
||||||
mountsDir.setAutoRemove( false );
|
|
||||||
|
|
||||||
int exit = QProcess::execute( "mount", { "-o", mountOptions.join(','), partitionPath, mountsDir.path() } );
|
CalamaresUtils::Partition::TemporaryMount mount( partitionPath, QString(), mountOptions.join( ',' ) );
|
||||||
if ( !exit ) // if all is well
|
if ( mount.isValid() )
|
||||||
{
|
{
|
||||||
QFile fstabFile( mountsDir.path() + "/etc/fstab" );
|
QFile fstabFile( mount.path() + "/etc/fstab" );
|
||||||
|
|
||||||
cDebug() << Logger::SubEntry << "reading" << fstabFile.fileName();
|
cDebug() << Logger::SubEntry << "reading" << fstabFile.fileName();
|
||||||
|
|
||||||
if ( fstabFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
if ( fstabFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||||
{
|
{
|
||||||
const QStringList fstabLines = QString::fromLocal8Bit( fstabFile.readAll() )
|
const QStringList fstabLines = QString::fromLocal8Bit( fstabFile.readAll() ).split( '\n' );
|
||||||
.split( '\n' );
|
|
||||||
|
|
||||||
for ( const QString& rawLine : fstabLines )
|
for ( const QString& rawLine : fstabLines )
|
||||||
|
{
|
||||||
fstabEntries.append( FstabEntry::fromEtcFstab( rawLine ) );
|
fstabEntries.append( FstabEntry::fromEtcFstab( rawLine ) );
|
||||||
|
}
|
||||||
fstabFile.close();
|
fstabFile.close();
|
||||||
cDebug() << Logger::SubEntry << "got" << fstabEntries.count() << "lines.";
|
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.";
|
cDebug() << Logger::SubEntry << "got" << fstabEntries.count() << "fstab entries.";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
cWarning() << "Could not read fstab from mounted fs";
|
cWarning() << "Could not read fstab from mounted fs";
|
||||||
|
}
|
||||||
if ( QProcess::execute( "umount", { "-R", mountsDir.path() } ) )
|
|
||||||
cWarning() << "Could not unmount" << mountsDir.path();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
cWarning() << "Could not mount existing fs";
|
cWarning() << "Could not mount existing fs";
|
||||||
|
}
|
||||||
|
|
||||||
return fstabEntries;
|
return fstabEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static QString
|
static QString
|
||||||
findPartitionPathForMountPoint( const FstabEntryList& fstab,
|
findPartitionPathForMountPoint( const FstabEntryList& fstab, const QString& mountPoint )
|
||||||
const QString& mountPoint )
|
|
||||||
{
|
{
|
||||||
if ( fstab.isEmpty() )
|
if ( fstab.isEmpty() )
|
||||||
|
{
|
||||||
return QString();
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
for ( const FstabEntry& entry : fstab )
|
for ( const FstabEntry& entry : fstab )
|
||||||
{
|
{
|
||||||
@ -327,15 +342,20 @@ findPartitionPathForMountPoint( const FstabEntryList& fstab,
|
|||||||
|
|
||||||
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 ) )
|
if ( !readlink.waitForStarted( 1000 ) )
|
||||||
|
{
|
||||||
return QString();
|
return QString();
|
||||||
|
}
|
||||||
if ( !readlink.waitForFinished( 1000 ) )
|
if ( !readlink.waitForFinished( 1000 ) )
|
||||||
|
{
|
||||||
return QString();
|
return QString();
|
||||||
|
}
|
||||||
if ( readlink.exitCode() != 0 || readlink.exitStatus() != QProcess::NormalExit )
|
if ( readlink.exitCode() != 0 || readlink.exitStatus() != QProcess::NormalExit )
|
||||||
|
{
|
||||||
return QString();
|
return QString();
|
||||||
partPath = QString::fromLocal8Bit(
|
}
|
||||||
readlink.readAllStandardOutput() ).trimmed();
|
partPath = QString::fromLocal8Bit( readlink.readAllStandardOutput() ).trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
return partPath;
|
return partPath;
|
||||||
@ -364,9 +384,7 @@ runOsprober( PartitionCoreModule* core )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
osproberOutput.append(
|
osproberOutput.append( QString::fromLocal8Bit( osprober.readAllStandardOutput() ).trimmed() );
|
||||||
QString::fromLocal8Bit(
|
|
||||||
osprober.readAllStandardOutput() ).trimmed() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList osproberCleanLines;
|
QStringList osproberCleanLines;
|
||||||
@ -379,32 +397,37 @@ runOsprober( PartitionCoreModule* core )
|
|||||||
QStringList lineColumns = line.split( ':' );
|
QStringList lineColumns = line.split( ':' );
|
||||||
QString prettyName;
|
QString prettyName;
|
||||||
if ( !lineColumns.value( 1 ).simplified().isEmpty() )
|
if ( !lineColumns.value( 1 ).simplified().isEmpty() )
|
||||||
|
{
|
||||||
prettyName = lineColumns.value( 1 ).simplified();
|
prettyName = lineColumns.value( 1 ).simplified();
|
||||||
|
}
|
||||||
else if ( !lineColumns.value( 2 ).simplified().isEmpty() )
|
else if ( !lineColumns.value( 2 ).simplified().isEmpty() )
|
||||||
|
{
|
||||||
prettyName = lineColumns.value( 2 ).simplified();
|
prettyName = lineColumns.value( 2 ).simplified();
|
||||||
|
}
|
||||||
|
|
||||||
QString path = lineColumns.value( 0 ).simplified();
|
QString path = lineColumns.value( 0 ).simplified();
|
||||||
if ( !path.startsWith( "/dev/" ) ) //basic sanity check
|
if ( !path.startsWith( "/dev/" ) ) //basic sanity check
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
FstabEntryList fstabEntries = lookForFstabEntries( path );
|
FstabEntryList fstabEntries = lookForFstabEntries( path );
|
||||||
QString homePath = findPartitionPathForMountPoint( fstabEntries, "/home" );
|
QString homePath = findPartitionPathForMountPoint( fstabEntries, "/home" );
|
||||||
|
|
||||||
osproberEntries.append( { prettyName,
|
osproberEntries.append(
|
||||||
path,
|
{ prettyName, path, QString(), canBeResized( core, path ), lineColumns, fstabEntries, homePath } );
|
||||||
QString(),
|
|
||||||
canBeResized( core, path ),
|
|
||||||
lineColumns,
|
|
||||||
fstabEntries,
|
|
||||||
homePath } );
|
|
||||||
osproberCleanLines.append( line );
|
osproberCleanLines.append( line );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( osproberCleanLines.count() > 0 )
|
if ( osproberCleanLines.count() > 0 )
|
||||||
|
{
|
||||||
cDebug() << "os-prober lines after cleanup:" << Logger::DebugList( osproberCleanLines );
|
cDebug() << "os-prober lines after cleanup:" << Logger::DebugList( osproberCleanLines );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
cDebug() << "os-prober gave no output.";
|
cDebug() << "os-prober gave no output.";
|
||||||
|
}
|
||||||
|
|
||||||
Calamares::JobQueue::instance()->globalStorage()->insert( "osproberLines", osproberCleanLines );
|
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 bit 17 is set, old-style Esp flag, it's OK */
|
||||||
if ( flags.testFlag( KPM_PARTITION_FLAG_ESP ) )
|
if ( flags.testFlag( KPM_PARTITION_FLAG_ESP ) )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Otherwise, if it's a GPT table, Boot (bit 0) is the same as Esp */
|
/* Otherwise, if it's a GPT table, Boot (bit 0) is the same as Esp */
|
||||||
const PartitionNode* root = candidate;
|
const PartitionNode* root = candidate;
|
||||||
while ( root && !root->isRoot() )
|
while ( root && !root->isRoot() )
|
||||||
{
|
{
|
||||||
root = root->parent();
|
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?
|
// Strange case: no root found, no partition table node?
|
||||||
if ( !root )
|
if ( !root )
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const PartitionTable* table = dynamic_cast<const PartitionTable*>( root );
|
const PartitionTable* table = dynamic_cast< const PartitionTable* >( root );
|
||||||
cDebug() << Logger::SubEntry << "partition table" << (void *)table << "type" << ( table ? table->type() : PartitionTable::TableType::unknownTableType );
|
cDebug() << Logger::SubEntry << "partition table" << (void*)table << "type"
|
||||||
return table && ( table->type() == PartitionTable::TableType::gpt ) &&
|
<< ( table ? table->type() : PartitionTable::TableType::unknownTableType );
|
||||||
flags.testFlag( KPM_PARTITION_FLAG(Boot) );
|
return table && ( table->type() == PartitionTable::TableType::gpt ) && flags.testFlag( KPM_PARTITION_FLAG( Boot ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
@ -452,14 +479,18 @@ findFS( QString fsName, FileSystem::Type* fsType )
|
|||||||
{
|
{
|
||||||
QStringList fsLanguage { QLatin1String( "C" ) }; // Required language list to turn off localization
|
QStringList fsLanguage { QLatin1String( "C" ) }; // Required language list to turn off localization
|
||||||
if ( fsName.isEmpty() )
|
if ( fsName.isEmpty() )
|
||||||
|
{
|
||||||
fsName = QStringLiteral( "ext4" );
|
fsName = QStringLiteral( "ext4" );
|
||||||
|
}
|
||||||
|
|
||||||
FileSystem::Type tmpType = FileSystem::typeForName( fsName, fsLanguage );
|
FileSystem::Type tmpType = FileSystem::typeForName( fsName, fsLanguage );
|
||||||
if ( tmpType != FileSystem::Unknown )
|
if ( tmpType != FileSystem::Unknown )
|
||||||
{
|
{
|
||||||
cDebug() << "Found filesystem" << fsName;
|
cDebug() << "Found filesystem" << fsName;
|
||||||
if ( fsType )
|
if ( fsType )
|
||||||
|
{
|
||||||
*fsType = tmpType;
|
*fsType = tmpType;
|
||||||
|
}
|
||||||
return fsName;
|
return fsName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,7 +503,9 @@ findFS( QString fsName, FileSystem::Type* fsType )
|
|||||||
QString fsRealName = FileSystem::nameForType( t, fsLanguage );
|
QString fsRealName = FileSystem::nameForType( t, fsLanguage );
|
||||||
cDebug() << "Filesystem name" << fsName << "translated to" << fsRealName;
|
cDebug() << "Filesystem name" << fsName << "translated to" << fsRealName;
|
||||||
if ( fsType )
|
if ( fsType )
|
||||||
|
{
|
||||||
*fsType = t;
|
*fsType = t;
|
||||||
|
}
|
||||||
return fsRealName;
|
return fsRealName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -480,8 +513,10 @@ findFS( QString fsName, FileSystem::Type* fsType )
|
|||||||
cDebug() << "Filesystem" << fsName << "not found, using ext4";
|
cDebug() << "Filesystem" << fsName << "not found, using ext4";
|
||||||
fsName = QStringLiteral( "ext4" );
|
fsName = QStringLiteral( "ext4" );
|
||||||
// fsType can be used to check whether fsName was a valid filesystem.
|
// fsType can be used to check whether fsName was a valid filesystem.
|
||||||
if (fsType)
|
if ( fsType )
|
||||||
|
{
|
||||||
*fsType = FileSystem::Unknown;
|
*fsType = FileSystem::Unknown;
|
||||||
|
}
|
||||||
#ifdef DEBUG_FILESYSTEMS
|
#ifdef DEBUG_FILESYSTEMS
|
||||||
// This bit is for distro's debugging their settings, and shows
|
// This bit is for distro's debugging their settings, and shows
|
||||||
// all the strings that KPMCore is matching against for FS type.
|
// 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();
|
const auto fstypes = FileSystem::types();
|
||||||
d << "Available types (" << fstypes.count() << ')';
|
d << "Available types (" << fstypes.count() << ')';
|
||||||
for ( FileSystem::Type t : fstypes )
|
for ( FileSystem::Type t : fstypes )
|
||||||
d << TR( static_cast<int>( t ), FileSystem::nameForType( t, fsLanguage ) );
|
{
|
||||||
|
d << TR( static_cast< int >( t ), FileSystem::nameForType( t, fsLanguage ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return fsName;
|
return fsName;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // nmamespace PartUtils
|
} // namespace PartUtils
|
||||||
|
|
||||||
/* Implementation of methods for FstabEntry, from OsproberEntry.h */
|
/* Implementation of methods for FstabEntry, from OsproberEntry.h */
|
||||||
|
|
||||||
@ -512,17 +549,18 @@ FstabEntry::fromEtcFstab( const QString& rawLine )
|
|||||||
{
|
{
|
||||||
QString line = rawLine.simplified();
|
QString line = rawLine.simplified();
|
||||||
if ( line.startsWith( '#' ) )
|
if ( line.startsWith( '#' ) )
|
||||||
return FstabEntry{ QString(), QString(), QString(), QString(), 0, 0 };
|
return FstabEntry { QString(), QString(), QString(), QString(), 0, 0 };
|
||||||
|
|
||||||
QStringList splitLine = line.split( ' ' );
|
QStringList splitLine = line.split( ' ' );
|
||||||
if ( splitLine.length() != 6 )
|
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.
|
return FstabEntry {
|
||||||
|
splitLine.at( 0 ), // path, or UUID, or LABEL, etc.
|
||||||
splitLine.at( 1 ), // mount point
|
splitLine.at( 1 ), // mount point
|
||||||
splitLine.at( 2 ), // fs type
|
splitLine.at( 2 ), // fs type
|
||||||
splitLine.at( 3 ), // options
|
splitLine.at( 3 ), // options
|
||||||
splitLine.at( 4 ).toInt(), //dump
|
splitLine.at( 4 ).toInt(), //dump
|
||||||
splitLine.at( 5 ).toInt() //pass
|
splitLine.at( 5 ).toInt() //pass
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
#define PARTUTILS_H
|
#define PARTUTILS_H
|
||||||
|
|
||||||
#include "OsproberEntry.h"
|
#include "OsproberEntry.h"
|
||||||
#include "utils/Units.h"
|
|
||||||
#include "utils/NamedSuffix.h"
|
#include "utils/NamedSuffix.h"
|
||||||
|
#include "utils/Units.h"
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
#include <kpmcore/fs/filesystem.h>
|
#include <kpmcore/fs/filesystem.h>
|
||||||
@ -99,6 +99,6 @@ bool isEfiBootable( const Partition* candidate );
|
|||||||
*/
|
*/
|
||||||
QString findFS( QString fsName, FileSystem::Type* fsType );
|
QString findFS( QString fsName, FileSystem::Type* fsType );
|
||||||
|
|
||||||
}
|
} // namespace PartUtils
|
||||||
|
|
||||||
#endif // PARTUTILS_H
|
#endif // PARTUTILS_H
|
||||||
|
@ -21,13 +21,13 @@
|
|||||||
#include "PartitionActions.h"
|
#include "PartitionActions.h"
|
||||||
|
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
#include "core/PartitionInfo.h"
|
|
||||||
#include "core/PartitionCoreModule.h"
|
|
||||||
#include "core/PartUtils.h"
|
#include "core/PartUtils.h"
|
||||||
|
#include "core/PartitionCoreModule.h"
|
||||||
|
#include "core/PartitionInfo.h"
|
||||||
|
|
||||||
#include "utils/CalamaresUtilsSystem.h"
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
#include "utils/Units.h"
|
|
||||||
#include "utils/NamedEnum.h"
|
#include "utils/NamedEnum.h"
|
||||||
|
#include "utils/Units.h"
|
||||||
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
@ -47,7 +47,9 @@ qint64
|
|||||||
swapSuggestion( const qint64 availableSpaceB, Choices::SwapChoice swap )
|
swapSuggestion( const qint64 availableSpaceB, Choices::SwapChoice swap )
|
||||||
{
|
{
|
||||||
if ( ( swap != Choices::SmallSwap ) && ( swap != Choices::FullSwap ) )
|
if ( ( swap != Choices::SmallSwap ) && ( swap != Choices::FullSwap ) )
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// See partition.conf for explanation
|
// See partition.conf for explanation
|
||||||
qint64 suggestedSwapSizeB = 0;
|
qint64 suggestedSwapSizeB = 0;
|
||||||
@ -59,15 +61,23 @@ swapSuggestion( const qint64 availableSpaceB, Choices::SwapChoice swap )
|
|||||||
|
|
||||||
// Ramp up quickly to 8GiB, then follow memory size
|
// Ramp up quickly to 8GiB, then follow memory size
|
||||||
if ( availableRamB <= 4_GiB )
|
if ( availableRamB <= 4_GiB )
|
||||||
|
{
|
||||||
suggestedSwapSizeB = availableRamB * 2;
|
suggestedSwapSizeB = availableRamB * 2;
|
||||||
|
}
|
||||||
else if ( availableRamB <= 8_GiB )
|
else if ( availableRamB <= 8_GiB )
|
||||||
|
{
|
||||||
suggestedSwapSizeB = 8_GiB;
|
suggestedSwapSizeB = 8_GiB;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
suggestedSwapSizeB = availableRamB;
|
suggestedSwapSizeB = availableRamB;
|
||||||
|
}
|
||||||
|
|
||||||
// .. top out at 8GiB if we don't care about suspend
|
// .. top out at 8GiB if we don't care about suspend
|
||||||
if ( !ensureSuspendToDisk )
|
if ( !ensureSuspendToDisk )
|
||||||
|
{
|
||||||
suggestedSwapSizeB = qMin( 8_GiB, suggestedSwapSizeB );
|
suggestedSwapSizeB = qMin( 8_GiB, suggestedSwapSizeB );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Allow for a fudge factor
|
// 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
|
// don't use more than 10% of available space
|
||||||
if ( !ensureSuspendToDisk )
|
if ( !ensureSuspendToDisk )
|
||||||
|
{
|
||||||
suggestedSwapSizeB = qMin( suggestedSwapSizeB, qint64( 0.10 * availableSpaceB ) );
|
suggestedSwapSizeB = qMin( suggestedSwapSizeB, qint64( 0.10 * availableSpaceB ) );
|
||||||
|
}
|
||||||
|
|
||||||
cDebug() << "Suggested swap size:" << suggestedSwapSizeB / 1024. / 1024. / 1024. << "GiB";
|
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();
|
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||||
QString defaultFsType = o.defaultFsType;
|
QString defaultFsType = o.defaultFsType;
|
||||||
if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown )
|
if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown )
|
||||||
|
{
|
||||||
defaultFsType = "ext4";
|
defaultFsType = "ext4";
|
||||||
|
}
|
||||||
|
|
||||||
bool isEfi = PartUtils::isEfiSystem();
|
bool isEfi = PartUtils::isEfiSystem();
|
||||||
|
|
||||||
@ -103,8 +117,8 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO
|
|||||||
{
|
{
|
||||||
if ( gs->contains( "efiSystemPartitionSize" ) )
|
if ( gs->contains( "efiSystemPartitionSize" ) )
|
||||||
{
|
{
|
||||||
CalamaresUtils::Partition::PartitionSize part_size = CalamaresUtils::Partition::PartitionSize(
|
CalamaresUtils::Partition::PartitionSize part_size
|
||||||
gs->value( "efiSystemPartitionSize" ).toString() );
|
= CalamaresUtils::Partition::PartitionSize( gs->value( "efiSystemPartitionSize" ).toString() );
|
||||||
uefisys_part_sizeB = part_size.toBytes( dev->capacity() );
|
uefisys_part_sizeB = part_size.toBytes( dev->capacity() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -128,15 +142,13 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO
|
|||||||
// firstFreeSector..firstFreeSector+efiSectorCount-1.
|
// firstFreeSector..firstFreeSector+efiSectorCount-1.
|
||||||
qint64 lastSector = firstFreeSector + efiSectorCount - 1;
|
qint64 lastSector = firstFreeSector + efiSectorCount - 1;
|
||||||
core->createPartitionTable( dev, PartitionTable::gpt );
|
core->createPartitionTable( dev, PartitionTable::gpt );
|
||||||
Partition* efiPartition = KPMHelpers::createNewPartition(
|
Partition* efiPartition = KPMHelpers::createNewPartition( dev->partitionTable(),
|
||||||
dev->partitionTable(),
|
|
||||||
*dev,
|
*dev,
|
||||||
PartitionRole( PartitionRole::Primary ),
|
PartitionRole( PartitionRole::Primary ),
|
||||||
FileSystem::Fat32,
|
FileSystem::Fat32,
|
||||||
firstFreeSector,
|
firstFreeSector,
|
||||||
lastSector,
|
lastSector,
|
||||||
KPM_PARTITION_FLAG(None)
|
KPM_PARTITION_FLAG( None ) );
|
||||||
);
|
|
||||||
PartitionInfo::setFormat( efiPartition, true );
|
PartitionInfo::setFormat( efiPartition, true );
|
||||||
PartitionInfo::setMountPoint( efiPartition, o.efiPartitionMountPoint );
|
PartitionInfo::setMountPoint( efiPartition, o.efiPartitionMountPoint );
|
||||||
core->createPartition( dev, efiPartition, KPM_PARTITION_FLAG_ESP );
|
core->createPartition( dev, efiPartition, KPM_PARTITION_FLAG_ESP );
|
||||||
@ -177,28 +189,24 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO
|
|||||||
Partition* swapPartition = nullptr;
|
Partition* swapPartition = nullptr;
|
||||||
if ( o.luksPassphrase.isEmpty() )
|
if ( o.luksPassphrase.isEmpty() )
|
||||||
{
|
{
|
||||||
swapPartition = KPMHelpers::createNewPartition(
|
swapPartition = KPMHelpers::createNewPartition( dev->partitionTable(),
|
||||||
dev->partitionTable(),
|
|
||||||
*dev,
|
*dev,
|
||||||
PartitionRole( PartitionRole::Primary ),
|
PartitionRole( PartitionRole::Primary ),
|
||||||
FileSystem::LinuxSwap,
|
FileSystem::LinuxSwap,
|
||||||
lastSectorForRoot + 1,
|
lastSectorForRoot + 1,
|
||||||
dev->totalLogical() - 1,
|
dev->totalLogical() - 1,
|
||||||
KPM_PARTITION_FLAG(None)
|
KPM_PARTITION_FLAG( None ) );
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
swapPartition = KPMHelpers::createNewEncryptedPartition(
|
swapPartition = KPMHelpers::createNewEncryptedPartition( dev->partitionTable(),
|
||||||
dev->partitionTable(),
|
|
||||||
*dev,
|
*dev,
|
||||||
PartitionRole( PartitionRole::Primary ),
|
PartitionRole( PartitionRole::Primary ),
|
||||||
FileSystem::LinuxSwap,
|
FileSystem::LinuxSwap,
|
||||||
lastSectorForRoot + 1,
|
lastSectorForRoot + 1,
|
||||||
dev->totalLogical() - 1,
|
dev->totalLogical() - 1,
|
||||||
o.luksPassphrase,
|
o.luksPassphrase,
|
||||||
KPM_PARTITION_FLAG(None)
|
KPM_PARTITION_FLAG( None ) );
|
||||||
);
|
|
||||||
}
|
}
|
||||||
PartitionInfo::setFormat( swapPartition, true );
|
PartitionInfo::setFormat( swapPartition, true );
|
||||||
core->createPartition( dev, swapPartition );
|
core->createPartition( dev, swapPartition );
|
||||||
@ -209,10 +217,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
doReplacePartition( PartitionCoreModule* core,
|
doReplacePartition( PartitionCoreModule* core, Device* dev, Partition* partition, Choices::ReplacePartitionOptions o )
|
||||||
Device* dev,
|
|
||||||
Partition* partition,
|
|
||||||
Choices::ReplacePartitionOptions o )
|
|
||||||
{
|
{
|
||||||
qint64 firstSector, lastSector;
|
qint64 firstSector, lastSector;
|
||||||
|
|
||||||
@ -220,11 +225,15 @@ doReplacePartition( PartitionCoreModule* core,
|
|||||||
|
|
||||||
QString defaultFsType = o.defaultFsType;
|
QString defaultFsType = o.defaultFsType;
|
||||||
if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown )
|
if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown )
|
||||||
|
{
|
||||||
defaultFsType = "ext4";
|
defaultFsType = "ext4";
|
||||||
|
}
|
||||||
|
|
||||||
PartitionRole newRoles( partition->roles() );
|
PartitionRole newRoles( partition->roles() );
|
||||||
if ( partition->roles().has( PartitionRole::Extended ) )
|
if ( partition->roles().has( PartitionRole::Extended ) )
|
||||||
|
{
|
||||||
newRoles = PartitionRole( PartitionRole::Primary );
|
newRoles = PartitionRole( PartitionRole::Primary );
|
||||||
|
}
|
||||||
|
|
||||||
if ( partition->roles().has( PartitionRole::Unallocated ) )
|
if ( partition->roles().has( PartitionRole::Unallocated ) )
|
||||||
{
|
{
|
||||||
@ -234,15 +243,19 @@ doReplacePartition( PartitionCoreModule* core,
|
|||||||
{
|
{
|
||||||
Partition* parent = dynamic_cast< Partition* >( partition->parent() );
|
Partition* parent = dynamic_cast< Partition* >( partition->parent() );
|
||||||
if ( parent && parent->roles().has( PartitionRole::Extended ) )
|
if ( parent && parent->roles().has( PartitionRole::Extended ) )
|
||||||
|
{
|
||||||
newRoles = PartitionRole( PartitionRole::Logical );
|
newRoles = PartitionRole( PartitionRole::Logical );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Save the first and last sector values as the partition will be deleted
|
// Save the first and last sector values as the partition will be deleted
|
||||||
firstSector = partition->firstSector();
|
firstSector = partition->firstSector();
|
||||||
lastSector = partition->lastSector();
|
lastSector = partition->lastSector();
|
||||||
if ( !partition->roles().has( PartitionRole::Unallocated ) )
|
if ( !partition->roles().has( PartitionRole::Unallocated ) )
|
||||||
|
{
|
||||||
core->deletePartition( dev, partition );
|
core->deletePartition( dev, partition );
|
||||||
|
}
|
||||||
|
|
||||||
core->layoutApply( dev, firstSector, lastSector, o.luksPassphrase );
|
core->layoutApply( dev, firstSector, lastSector, o.luksPassphrase );
|
||||||
|
|
||||||
@ -251,16 +264,14 @@ doReplacePartition( PartitionCoreModule* core,
|
|||||||
|
|
||||||
namespace Choices
|
namespace Choices
|
||||||
{
|
{
|
||||||
static const NamedEnumTable<SwapChoice>&
|
static const NamedEnumTable< SwapChoice >&
|
||||||
nameTable()
|
nameTable()
|
||||||
{
|
{
|
||||||
static const NamedEnumTable<SwapChoice> names{
|
static const NamedEnumTable< SwapChoice > names { { QStringLiteral( "none" ), SwapChoice::NoSwap },
|
||||||
{ QStringLiteral( "none" ), SwapChoice::NoSwap },
|
|
||||||
{ QStringLiteral( "small" ), SwapChoice::SmallSwap },
|
{ QStringLiteral( "small" ), SwapChoice::SmallSwap },
|
||||||
{ QStringLiteral( "suspend" ), SwapChoice::FullSwap },
|
{ QStringLiteral( "suspend" ), SwapChoice::FullSwap },
|
||||||
{ QStringLiteral( "reuse" ), SwapChoice::ReuseSwap },
|
{ QStringLiteral( "reuse" ), SwapChoice::ReuseSwap },
|
||||||
{ QStringLiteral( "file" ), SwapChoice::SwapFile }
|
{ QStringLiteral( "file" ), SwapChoice::SwapFile } };
|
||||||
};
|
|
||||||
|
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
@ -33,21 +33,21 @@ namespace PartitionActions
|
|||||||
*/
|
*/
|
||||||
namespace Choices
|
namespace Choices
|
||||||
{
|
{
|
||||||
/** @brief Ccchoice of swap (size and type) */
|
/** @brief Ccchoice of swap (size and type) */
|
||||||
enum SwapChoice
|
enum SwapChoice
|
||||||
{
|
{
|
||||||
NoSwap, // don't create any swap, don't use any
|
NoSwap, // don't create any swap, don't use any
|
||||||
ReuseSwap, // don't create, but do use existing
|
ReuseSwap, // don't create, but do use existing
|
||||||
SmallSwap, // up to 8GiB of swap
|
SmallSwap, // up to 8GiB of swap
|
||||||
FullSwap, // ensureSuspendToDisk -- at least RAM size
|
FullSwap, // ensureSuspendToDisk -- at least RAM size
|
||||||
SwapFile // use a file (if supported)
|
SwapFile // use a file (if supported)
|
||||||
};
|
};
|
||||||
|
|
||||||
SwapChoice nameToChoice( QString name, bool& ok );
|
SwapChoice nameToChoice( QString name, bool& ok );
|
||||||
QString choiceToName( SwapChoice );
|
QString choiceToName( SwapChoice );
|
||||||
|
|
||||||
struct ReplacePartitionOptions
|
struct ReplacePartitionOptions
|
||||||
{
|
{
|
||||||
QString defaultFsType; // e.g. "ext4" or "btrfs"
|
QString defaultFsType; // e.g. "ext4" or "btrfs"
|
||||||
QString luksPassphrase; // optional
|
QString luksPassphrase; // optional
|
||||||
|
|
||||||
@ -56,22 +56,26 @@ namespace Choices
|
|||||||
, luksPassphrase( luks )
|
, luksPassphrase( luks )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AutoPartitionOptions : ReplacePartitionOptions
|
struct AutoPartitionOptions : ReplacePartitionOptions
|
||||||
{
|
{
|
||||||
QString efiPartitionMountPoint; // optional, e.g. "/boot"
|
QString efiPartitionMountPoint; // optional, e.g. "/boot"
|
||||||
quint64 requiredSpaceB; // estimated required space for root partition
|
quint64 requiredSpaceB; // estimated required space for root partition
|
||||||
SwapChoice swap;
|
SwapChoice swap;
|
||||||
|
|
||||||
AutoPartitionOptions( const QString& fs, const QString& luks, const QString& efi, qint64 requiredBytes, SwapChoice s )
|
AutoPartitionOptions( const QString& fs,
|
||||||
|
const QString& luks,
|
||||||
|
const QString& efi,
|
||||||
|
qint64 requiredBytes,
|
||||||
|
SwapChoice s )
|
||||||
: ReplacePartitionOptions( fs, luks )
|
: ReplacePartitionOptions( fs, luks )
|
||||||
, efiPartitionMountPoint( efi )
|
, efiPartitionMountPoint( efi )
|
||||||
, requiredSpaceB( requiredBytes > 0 ? static_cast<quint64>( requiredBytes ) : 0 )
|
, requiredSpaceB( requiredBytes > 0 ? static_cast< quint64 >( requiredBytes ) : 0 )
|
||||||
, swap( s )
|
, swap( s )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Choices
|
} // namespace Choices
|
||||||
|
|
||||||
@ -81,9 +85,7 @@ namespace Choices
|
|||||||
* @param dev the device to wipe.
|
* @param dev the device to wipe.
|
||||||
* @param options settings for autopartitioning.
|
* @param options settings for autopartitioning.
|
||||||
*/
|
*/
|
||||||
void doAutopartition( PartitionCoreModule* core,
|
void doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionOptions options );
|
||||||
Device* dev,
|
|
||||||
Choices::AutoPartitionOptions options );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief doReplacePartition sets up replace-partitioning with the given partition.
|
* @brief doReplacePartition sets up replace-partitioning with the given partition.
|
||||||
|
@ -26,11 +26,10 @@
|
|||||||
#include "core/ColorUtils.h"
|
#include "core/ColorUtils.h"
|
||||||
#include "core/DeviceList.h"
|
#include "core/DeviceList.h"
|
||||||
#include "core/DeviceModel.h"
|
#include "core/DeviceModel.h"
|
||||||
#include "core/PartitionInfo.h"
|
|
||||||
#include "core/PartitionIterator.h"
|
|
||||||
#include "core/PartitionModel.h"
|
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
#include "core/PartUtils.h"
|
#include "core/PartUtils.h"
|
||||||
|
#include "core/PartitionInfo.h"
|
||||||
|
#include "core/PartitionModel.h"
|
||||||
#include "jobs/ClearMountsJob.h"
|
#include "jobs/ClearMountsJob.h"
|
||||||
#include "jobs/ClearTempMountsJob.h"
|
#include "jobs/ClearTempMountsJob.h"
|
||||||
#include "jobs/CreatePartitionJob.h"
|
#include "jobs/CreatePartitionJob.h"
|
||||||
@ -45,33 +44,37 @@
|
|||||||
#include "jobs/ResizeVolumeGroupJob.h"
|
#include "jobs/ResizeVolumeGroupJob.h"
|
||||||
#include "jobs/SetPartitionFlagsJob.h"
|
#include "jobs/SetPartitionFlagsJob.h"
|
||||||
|
|
||||||
#include "utils/Variant.h"
|
|
||||||
|
|
||||||
#ifdef DEBUG_PARTITION_LAME
|
#ifdef DEBUG_PARTITION_LAME
|
||||||
#include "JobExample.h"
|
#include "JobExample.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "partition/PartitionIterator.h"
|
||||||
|
#include "partition/PartitionQuery.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
|
#include <kpmcore/backend/corebackend.h>
|
||||||
|
#include <kpmcore/backend/corebackendmanager.h>
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <kpmcore/core/lvmdevice.h>
|
#include <kpmcore/core/lvmdevice.h>
|
||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
#include <kpmcore/core/volumemanagerdevice.h>
|
#include <kpmcore/core/volumemanagerdevice.h>
|
||||||
#include <kpmcore/backend/corebackend.h>
|
|
||||||
#include <kpmcore/backend/corebackendmanager.h>
|
|
||||||
#include <kpmcore/fs/filesystemfactory.h>
|
#include <kpmcore/fs/filesystemfactory.h>
|
||||||
#include <kpmcore/fs/luks.h>
|
#include <kpmcore/fs/luks.h>
|
||||||
#include <kpmcore/fs/lvm2_pv.h>
|
#include <kpmcore/fs/lvm2_pv.h>
|
||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QStandardItemModel>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QProcess>
|
|
||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QStandardItemModel>
|
||||||
#include <QtConcurrent/QtConcurrent>
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
|
||||||
|
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 )
|
: m_module( module )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -99,7 +102,7 @@ private:
|
|||||||
// called in *reverse* order of declaration in this class.
|
// called in *reverse* order of declaration in this class.
|
||||||
PartitionCoreModule::RefreshHelper m_coreHelper;
|
PartitionCoreModule::RefreshHelper m_coreHelper;
|
||||||
PartitionModel::ResetHelper m_modelHelper;
|
PartitionModel::ResetHelper m_modelHelper;
|
||||||
} ;
|
};
|
||||||
|
|
||||||
|
|
||||||
//- DeviceInfo ---------------------------------------------
|
//- DeviceInfo ---------------------------------------------
|
||||||
@ -108,19 +111,20 @@ PartitionCoreModule::DeviceInfo::DeviceInfo( Device* _device )
|
|||||||
, partitionModel( new PartitionModel )
|
, partitionModel( new PartitionModel )
|
||||||
, immutableDevice( new Device( *_device ) )
|
, immutableDevice( new Device( *_device ) )
|
||||||
, isAvailable( true )
|
, isAvailable( true )
|
||||||
{}
|
|
||||||
|
|
||||||
PartitionCoreModule::DeviceInfo::~DeviceInfo()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PartitionCoreModule::DeviceInfo::~DeviceInfo() {}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionCoreModule::DeviceInfo::forgetChanges()
|
PartitionCoreModule::DeviceInfo::forgetChanges()
|
||||||
{
|
{
|
||||||
jobs.clear();
|
jobs.clear();
|
||||||
for ( auto it = PartitionIterator::begin( device.data() ); it != PartitionIterator::end( device.data() ); ++it )
|
for ( auto it = PartitionIterator::begin( device.data() ); it != PartitionIterator::end( device.data() ); ++it )
|
||||||
|
{
|
||||||
PartitionInfo::reset( *it );
|
PartitionInfo::reset( *it );
|
||||||
|
}
|
||||||
partitionModel->revert();
|
partitionModel->revert();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,11 +133,15 @@ bool
|
|||||||
PartitionCoreModule::DeviceInfo::isDirty() const
|
PartitionCoreModule::DeviceInfo::isDirty() const
|
||||||
{
|
{
|
||||||
if ( !jobs.isEmpty() )
|
if ( !jobs.isEmpty() )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for ( auto it = PartitionIterator::begin( device.data() ); it != PartitionIterator::end( device.data() ); ++it )
|
for ( auto it = PartitionIterator::begin( device.data() ); it != PartitionIterator::end( device.data() ); ++it )
|
||||||
if ( PartitionInfo::isDirty( *it ) )
|
if ( PartitionInfo::isDirty( *it ) )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -144,8 +152,10 @@ PartitionCoreModule::PartitionCoreModule( QObject* parent )
|
|||||||
, m_deviceModel( new DeviceModel( this ) )
|
, m_deviceModel( new DeviceModel( this ) )
|
||||||
, m_bootLoaderModel( new BootLoaderModel( this ) )
|
, m_bootLoaderModel( new BootLoaderModel( this ) )
|
||||||
{
|
{
|
||||||
if ( !KPMHelpers::initKPMcore() )
|
if ( !m_kpmcore )
|
||||||
|
{
|
||||||
qFatal( "Failed to initialize KPMcore backend" );
|
qFatal( "Failed to initialize KPMcore backend" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -194,33 +204,39 @@ PartitionCoreModule::doInit()
|
|||||||
for ( auto deviceInfo : m_deviceInfos )
|
for ( auto deviceInfo : m_deviceInfos )
|
||||||
{
|
{
|
||||||
for ( auto it = PartitionIterator::begin( deviceInfo->device.data() );
|
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;
|
Partition* partition = *it;
|
||||||
for ( auto jt = m_osproberLines.begin();
|
for ( auto jt = m_osproberLines.begin(); jt != m_osproberLines.end(); ++jt )
|
||||||
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();
|
jt->uuid = partition->fileSystem().uuid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for ( auto deviceInfo : m_deviceInfos )
|
for ( auto deviceInfo : m_deviceInfos )
|
||||||
|
{
|
||||||
deviceInfo->partitionModel->init( deviceInfo->device.data(), m_osproberLines );
|
deviceInfo->partitionModel->init( deviceInfo->device.data(), m_osproberLines );
|
||||||
|
}
|
||||||
|
|
||||||
DeviceList bootLoaderDevices;
|
DeviceList bootLoaderDevices;
|
||||||
|
|
||||||
for ( DeviceList::Iterator it = devices.begin(); it != devices.end(); ++it)
|
for ( DeviceList::Iterator it = devices.begin(); it != devices.end(); ++it )
|
||||||
if ( (*it)->type() != Device::Type::Disk_Device )
|
if ( ( *it )->type() != Device::Type::Disk_Device )
|
||||||
{
|
{
|
||||||
cDebug() << "Ignoring device that is not Disk_Device to bootLoaderDevices list.";
|
cDebug() << "Ignoring device that is not Disk_Device to bootLoaderDevices list.";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
bootLoaderDevices.append(*it);
|
{
|
||||||
|
bootLoaderDevices.append( *it );
|
||||||
|
}
|
||||||
|
|
||||||
m_bootLoaderModel->init( bootLoaderDevices );
|
m_bootLoaderModel->init( bootLoaderDevices );
|
||||||
|
|
||||||
@ -229,7 +245,9 @@ PartitionCoreModule::doInit()
|
|||||||
//FIXME: this should be removed in favor of
|
//FIXME: this should be removed in favor of
|
||||||
// proper KPM support for EFI
|
// proper KPM support for EFI
|
||||||
if ( PartUtils::isEfiSystem() )
|
if ( PartUtils::isEfiSystem() )
|
||||||
|
{
|
||||||
scanForEfiSystemPartitions();
|
scanForEfiSystemPartitions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionCoreModule::~PartitionCoreModule()
|
PartitionCoreModule::~PartitionCoreModule()
|
||||||
@ -264,7 +282,9 @@ PartitionCoreModule::immutableDeviceCopy( const Device* device )
|
|||||||
Q_ASSERT( device );
|
Q_ASSERT( device );
|
||||||
DeviceInfo* info = infoForDevice( device );
|
DeviceInfo* info = infoForDevice( device );
|
||||||
if ( !info )
|
if ( !info )
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
return info->immutableDevice.data();
|
return info->immutableDevice.data();
|
||||||
}
|
}
|
||||||
@ -288,9 +308,7 @@ PartitionCoreModule::createPartitionTable( Device* device, PartitionTable::Table
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionCoreModule::createPartition( Device* device,
|
PartitionCoreModule::createPartition( Device* device, Partition* partition, PartitionTable::Flags flags )
|
||||||
Partition* partition,
|
|
||||||
PartitionTable::Flags flags )
|
|
||||||
{
|
{
|
||||||
auto deviceInfo = infoForDevice( device );
|
auto deviceInfo = infoForDevice( device );
|
||||||
Q_ASSERT( deviceInfo );
|
Q_ASSERT( deviceInfo );
|
||||||
@ -301,7 +319,7 @@ PartitionCoreModule::createPartition( Device* device,
|
|||||||
|
|
||||||
deviceInfo->jobs << Calamares::job_ptr( job );
|
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 );
|
SetPartFlagsJob* fJob = new SetPartFlagsJob( device, partition, flags );
|
||||||
deviceInfo->jobs << Calamares::job_ptr( fJob );
|
deviceInfo->jobs << Calamares::job_ptr( fJob );
|
||||||
@ -310,21 +328,23 @@ PartitionCoreModule::createPartition( Device* device,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionCoreModule::createVolumeGroup( QString &vgName,
|
PartitionCoreModule::createVolumeGroup( QString& vgName, QVector< const Partition* > pvList, qint32 peSize )
|
||||||
QVector< const Partition* > pvList,
|
|
||||||
qint32 peSize )
|
|
||||||
{
|
{
|
||||||
// Appending '_' character in case of repeated VG name
|
// Appending '_' character in case of repeated VG name
|
||||||
while ( hasVGwithThisName( vgName ) )
|
while ( hasVGwithThisName( vgName ) )
|
||||||
vgName.append('_');
|
{
|
||||||
|
vgName.append( '_' );
|
||||||
|
}
|
||||||
|
|
||||||
CreateVolumeGroupJob* job = new CreateVolumeGroupJob( vgName, pvList, peSize );
|
CreateVolumeGroupJob* job = new CreateVolumeGroupJob( vgName, pvList, peSize );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
|
|
||||||
LvmDevice* device = new LvmDevice(vgName);
|
LvmDevice* device = new LvmDevice( vgName );
|
||||||
|
|
||||||
for ( const Partition* p : pvList )
|
for ( const Partition* p : pvList )
|
||||||
|
{
|
||||||
device->physicalVolumes() << p;
|
device->physicalVolumes() << p;
|
||||||
|
}
|
||||||
|
|
||||||
DeviceInfo* deviceInfo = new DeviceInfo( device );
|
DeviceInfo* deviceInfo = new DeviceInfo( device );
|
||||||
|
|
||||||
@ -339,7 +359,7 @@ PartitionCoreModule::createVolumeGroup( QString &vgName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionCoreModule::resizeVolumeGroup( LvmDevice *device, QVector< const Partition* >& pvList )
|
PartitionCoreModule::resizeVolumeGroup( LvmDevice* device, QVector< const Partition* >& pvList )
|
||||||
{
|
{
|
||||||
DeviceInfo* deviceInfo = infoForDevice( device );
|
DeviceInfo* deviceInfo = infoForDevice( device );
|
||||||
Q_ASSERT( deviceInfo );
|
Q_ASSERT( deviceInfo );
|
||||||
@ -352,7 +372,7 @@ PartitionCoreModule::resizeVolumeGroup( LvmDevice *device, QVector< const Partit
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionCoreModule::deactivateVolumeGroup( LvmDevice *device )
|
PartitionCoreModule::deactivateVolumeGroup( LvmDevice* device )
|
||||||
{
|
{
|
||||||
DeviceInfo* deviceInfo = infoForDevice( device );
|
DeviceInfo* deviceInfo = infoForDevice( device );
|
||||||
Q_ASSERT( deviceInfo );
|
Q_ASSERT( deviceInfo );
|
||||||
@ -368,7 +388,7 @@ PartitionCoreModule::deactivateVolumeGroup( LvmDevice *device )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionCoreModule::removeVolumeGroup( LvmDevice *device )
|
PartitionCoreModule::removeVolumeGroup( LvmDevice* device )
|
||||||
{
|
{
|
||||||
DeviceInfo* deviceInfo = infoForDevice( device );
|
DeviceInfo* deviceInfo = infoForDevice( device );
|
||||||
Q_ASSERT( deviceInfo );
|
Q_ASSERT( deviceInfo );
|
||||||
@ -395,29 +415,36 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
|||||||
// deleting them, so let's play it safe and keep our own list.
|
// deleting them, so let's play it safe and keep our own list.
|
||||||
QList< Partition* > lst;
|
QList< Partition* > lst;
|
||||||
for ( auto childPartition : partition->children() )
|
for ( auto childPartition : partition->children() )
|
||||||
if ( !KPMHelpers::isPartitionFreeSpace( childPartition ) )
|
if ( !isPartitionFreeSpace( childPartition ) )
|
||||||
|
{
|
||||||
lst << childPartition;
|
lst << childPartition;
|
||||||
|
}
|
||||||
|
|
||||||
for ( auto childPartition : lst )
|
for ( auto childPartition : lst )
|
||||||
|
{
|
||||||
deletePartition( device, childPartition );
|
deletePartition( device, childPartition );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Calamares::JobList& jobs = deviceInfo->jobs;
|
Calamares::JobList& jobs = deviceInfo->jobs;
|
||||||
if ( partition->state() == KPM_PARTITION_STATE(New) )
|
if ( partition->state() == KPM_PARTITION_STATE( New ) )
|
||||||
{
|
{
|
||||||
// First remove matching SetPartFlagsJobs
|
// First remove matching SetPartFlagsJobs
|
||||||
for ( auto it = jobs.begin(); it != jobs.end(); )
|
for ( auto it = jobs.begin(); it != jobs.end(); )
|
||||||
{
|
{
|
||||||
SetPartFlagsJob* job = qobject_cast< SetPartFlagsJob* >( it->data() );
|
SetPartFlagsJob* job = qobject_cast< SetPartFlagsJob* >( it->data() );
|
||||||
if ( job && job->partition() == partition )
|
if ( job && job->partition() == partition )
|
||||||
|
{
|
||||||
it = jobs.erase( it );
|
it = jobs.erase( it );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Find matching CreatePartitionJob
|
// 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() );
|
CreatePartitionJob* createJob = qobject_cast< CreatePartitionJob* >( job.data() );
|
||||||
return createJob && createJob->partition() == partition;
|
return createJob && createJob->partition() == partition;
|
||||||
} );
|
} );
|
||||||
@ -427,7 +454,7 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Remove it
|
// Remove it
|
||||||
if ( ! partition->parent()->remove( partition ) )
|
if ( !partition->parent()->remove( partition ) )
|
||||||
{
|
{
|
||||||
cDebug() << "Failed to remove partition from preview";
|
cDebug() << "Failed to remove partition from preview";
|
||||||
return;
|
return;
|
||||||
@ -446,10 +473,14 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
|||||||
{
|
{
|
||||||
PartitionJob* job = qobject_cast< PartitionJob* >( it->data() );
|
PartitionJob* job = qobject_cast< PartitionJob* >( it->data() );
|
||||||
if ( job && job->partition() == partition )
|
if ( job && job->partition() == partition )
|
||||||
|
{
|
||||||
it = jobs.erase( it );
|
it = jobs.erase( it );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
DeletePartitionJob* job = new DeletePartitionJob( device, partition );
|
DeletePartitionJob* job = new DeletePartitionJob( device, partition );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
jobs << Calamares::job_ptr( job );
|
jobs << Calamares::job_ptr( job );
|
||||||
@ -468,10 +499,7 @@ PartitionCoreModule::formatPartition( Device* device, Partition* partition )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionCoreModule::resizePartition( Device* device,
|
PartitionCoreModule::resizePartition( Device* device, Partition* partition, qint64 first, qint64 last )
|
||||||
Partition* partition,
|
|
||||||
qint64 first,
|
|
||||||
qint64 last )
|
|
||||||
{
|
{
|
||||||
auto deviceInfo = infoForDevice( device );
|
auto deviceInfo = infoForDevice( device );
|
||||||
Q_ASSERT( deviceInfo );
|
Q_ASSERT( deviceInfo );
|
||||||
@ -483,9 +511,7 @@ PartitionCoreModule::resizePartition( Device* device,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionCoreModule::setPartitionFlags( Device* device,
|
PartitionCoreModule::setPartitionFlags( Device* device, Partition* partition, PartitionTable::Flags flags )
|
||||||
Partition* partition,
|
|
||||||
PartitionTable::Flags flags )
|
|
||||||
{
|
{
|
||||||
auto deviceInfo = infoForDevice( device );
|
auto deviceInfo = infoForDevice( device );
|
||||||
Q_ASSERT( deviceInfo );
|
Q_ASSERT( deviceInfo );
|
||||||
@ -518,8 +544,10 @@ PartitionCoreModule::jobs() const
|
|||||||
for ( auto info : m_deviceInfos )
|
for ( auto info : m_deviceInfos )
|
||||||
{
|
{
|
||||||
if ( info->isDirty() )
|
if ( info->isDirty() )
|
||||||
|
{
|
||||||
lst << Calamares::job_ptr( new ClearMountsJob( info->device.data() ) );
|
lst << Calamares::job_ptr( new ClearMountsJob( info->device.data() ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for ( auto info : m_deviceInfos )
|
for ( auto info : m_deviceInfos )
|
||||||
{
|
{
|
||||||
@ -552,18 +580,18 @@ PartitionCoreModule::lvmPVs() const
|
|||||||
bool
|
bool
|
||||||
PartitionCoreModule::hasVGwithThisName( const QString& name ) const
|
PartitionCoreModule::hasVGwithThisName( const QString& name ) const
|
||||||
{
|
{
|
||||||
auto condition = [ name ]( DeviceInfo* d ) {
|
auto condition = [name]( DeviceInfo* d ) {
|
||||||
return dynamic_cast<LvmDevice*>(d->device.data()) && d->device.data()->name() == name;
|
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();
|
return std::find_if( m_deviceInfos.begin(), m_deviceInfos.end(), condition ) != m_deviceInfos.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PartitionCoreModule::isInVG( const Partition *partition ) const
|
PartitionCoreModule::isInVG( const Partition* partition ) const
|
||||||
{
|
{
|
||||||
auto condition = [ partition ]( DeviceInfo* d ) {
|
auto condition = [partition]( DeviceInfo* d ) {
|
||||||
LvmDevice* vg = dynamic_cast<LvmDevice*>( d->device.data());
|
LvmDevice* vg = dynamic_cast< LvmDevice* >( d->device.data() );
|
||||||
return vg && vg->physicalVolumes().contains( partition );
|
return vg && vg->physicalVolumes().contains( partition );
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -578,8 +606,10 @@ PartitionCoreModule::dumpQueue() const
|
|||||||
{
|
{
|
||||||
cDebug() << "## Device:" << info->device->name();
|
cDebug() << "## Device:" << info->device->name();
|
||||||
for ( auto job : info->jobs )
|
for ( auto job : info->jobs )
|
||||||
|
{
|
||||||
cDebug() << "-" << job->prettyName();
|
cDebug() << "-" << job->prettyName();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -612,16 +642,21 @@ PartitionCoreModule::refreshAfterModelChange()
|
|||||||
//FIXME: this should be removed in favor of
|
//FIXME: this should be removed in favor of
|
||||||
// proper KPM support for EFI
|
// proper KPM support for EFI
|
||||||
if ( PartUtils::isEfiSystem() )
|
if ( PartUtils::isEfiSystem() )
|
||||||
|
{
|
||||||
scanForEfiSystemPartitions();
|
scanForEfiSystemPartitions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartitionCoreModule::updateHasRootMountPoint()
|
void
|
||||||
|
PartitionCoreModule::updateHasRootMountPoint()
|
||||||
{
|
{
|
||||||
bool oldValue = m_hasRootMountPoint;
|
bool oldValue = m_hasRootMountPoint;
|
||||||
m_hasRootMountPoint = findPartitionByMountPoint( "/" );
|
m_hasRootMountPoint = findPartitionByMountPoint( "/" );
|
||||||
|
|
||||||
if ( oldValue != m_hasRootMountPoint )
|
if ( oldValue != m_hasRootMountPoint )
|
||||||
|
{
|
||||||
hasRootMountPointChanged( m_hasRootMountPoint );
|
hasRootMountPointChanged( m_hasRootMountPoint );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -636,7 +671,9 @@ PartitionCoreModule::updateIsDirty()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( oldValue != m_isDirty )
|
if ( oldValue != m_isDirty )
|
||||||
|
{
|
||||||
isDirtyChanged( m_isDirty );
|
isDirtyChanged( m_isDirty );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -647,16 +684,17 @@ PartitionCoreModule::scanForEfiSystemPartitions()
|
|||||||
QList< Device* > devices;
|
QList< Device* > devices;
|
||||||
for ( int row = 0; row < deviceModel()->rowCount(); ++row )
|
for ( int row = 0; row < deviceModel()->rowCount(); ++row )
|
||||||
{
|
{
|
||||||
Device* device = deviceModel()->deviceForIndex(
|
Device* device = deviceModel()->deviceForIndex( deviceModel()->index( row ) );
|
||||||
deviceModel()->index( row ) );
|
|
||||||
devices.append( device );
|
devices.append( device );
|
||||||
}
|
}
|
||||||
|
|
||||||
QList< Partition* > efiSystemPartitions =
|
QList< Partition* > efiSystemPartitions
|
||||||
KPMHelpers::findPartitions( devices, PartUtils::isEfiBootable );
|
= CalamaresUtils::Partition::findPartitions( devices, PartUtils::isEfiBootable );
|
||||||
|
|
||||||
if ( efiSystemPartitions.isEmpty() )
|
if ( efiSystemPartitions.isEmpty() )
|
||||||
|
{
|
||||||
cWarning() << "system is EFI but no EFI system partitions found.";
|
cWarning() << "system is EFI but no EFI system partitions found.";
|
||||||
|
}
|
||||||
|
|
||||||
m_efiSystemPartitions = efiSystemPartitions;
|
m_efiSystemPartitions = efiSystemPartitions;
|
||||||
}
|
}
|
||||||
@ -671,11 +709,13 @@ PartitionCoreModule::scanForLVMPVs()
|
|||||||
|
|
||||||
for ( DeviceInfo* deviceInfo : m_deviceInfos )
|
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();
|
physicalDevices << deviceInfo->device.data();
|
||||||
|
}
|
||||||
else if ( deviceInfo->device.data()->type() == Device::Type::LVM_Device )
|
else if ( deviceInfo->device.data()->type() == Device::Type::LVM_Device )
|
||||||
{
|
{
|
||||||
LvmDevice* device = dynamic_cast<LvmDevice*>(deviceInfo->device.data());
|
LvmDevice* device = dynamic_cast< LvmDevice* >( deviceInfo->device.data() );
|
||||||
|
|
||||||
// Restoring physical volume list
|
// Restoring physical volume list
|
||||||
device->physicalVolumes().clear();
|
device->physicalVolumes().clear();
|
||||||
@ -687,14 +727,9 @@ PartitionCoreModule::scanForLVMPVs()
|
|||||||
#if defined( WITH_KPMCORE4API )
|
#if defined( WITH_KPMCORE4API )
|
||||||
VolumeManagerDevice::scanDevices( physicalDevices );
|
VolumeManagerDevice::scanDevices( physicalDevices );
|
||||||
for ( auto p : LVM::pvList::list() )
|
for ( auto p : LVM::pvList::list() )
|
||||||
#else
|
|
||||||
#if defined( WITH_KPMCORE331API )
|
|
||||||
LvmDevice::scanSystemLVM( physicalDevices );
|
|
||||||
for ( auto p : LVM::pvList::list() )
|
|
||||||
#else
|
#else
|
||||||
LvmDevice::scanSystemLVM( physicalDevices );
|
LvmDevice::scanSystemLVM( physicalDevices );
|
||||||
for ( auto p : LVM::pvList )
|
for ( auto p : LVM::pvList )
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
m_lvmPVs << p.partition().data();
|
m_lvmPVs << p.partition().data();
|
||||||
@ -713,30 +748,36 @@ PartitionCoreModule::scanForLVMPVs()
|
|||||||
for ( auto job : d->jobs )
|
for ( auto job : d->jobs )
|
||||||
{
|
{
|
||||||
// Including new LVM PVs
|
// Including new LVM PVs
|
||||||
CreatePartitionJob* partJob = dynamic_cast<CreatePartitionJob*>( job.data() );
|
CreatePartitionJob* partJob = dynamic_cast< CreatePartitionJob* >( job.data() );
|
||||||
if ( partJob )
|
if ( partJob )
|
||||||
{
|
{
|
||||||
Partition* p = partJob->partition();
|
Partition* p = partJob->partition();
|
||||||
|
|
||||||
if ( p->fileSystem().type() == FileSystem::Type::Lvm2_PV )
|
if ( p->fileSystem().type() == FileSystem::Type::Lvm2_PV )
|
||||||
|
{
|
||||||
m_lvmPVs << p;
|
m_lvmPVs << p;
|
||||||
|
}
|
||||||
else if ( p->fileSystem().type() == FileSystem::Type::Luks )
|
else if ( p->fileSystem().type() == FileSystem::Type::Luks )
|
||||||
{
|
{
|
||||||
// Encrypted LVM PVs
|
// Encrypted LVM PVs
|
||||||
FileSystem* innerFS = static_cast<const FS::luks*>(&p->fileSystem())->innerFS();
|
FileSystem* innerFS = static_cast< const FS::luks* >( &p->fileSystem() )->innerFS();
|
||||||
|
|
||||||
if ( innerFS && innerFS->type() == FileSystem::Type::Lvm2_PV )
|
if ( innerFS && innerFS->type() == FileSystem::Type::Lvm2_PV )
|
||||||
|
{
|
||||||
m_lvmPVs << p;
|
m_lvmPVs << p;
|
||||||
}
|
}
|
||||||
#ifdef WITH_KPMCORE4API
|
}
|
||||||
|
#if defined( WITH_KPMCORE4API )
|
||||||
else if ( p->fileSystem().type() == FileSystem::Type::Luks2 )
|
else if ( p->fileSystem().type() == FileSystem::Type::Luks2 )
|
||||||
{
|
{
|
||||||
// Encrypted LVM PVs
|
// Encrypted LVM PVs
|
||||||
FileSystem* innerFS = static_cast<const FS::luks*>(&p->fileSystem())->innerFS();
|
FileSystem* innerFS = static_cast< const FS::luks* >( &p->fileSystem() )->innerFS();
|
||||||
|
|
||||||
if ( innerFS && innerFS->type() == FileSystem::Type::Lvm2_PV )
|
if ( innerFS && innerFS->type() == FileSystem::Type::Lvm2_PV )
|
||||||
|
{
|
||||||
m_lvmPVs << p;
|
m_lvmPVs << p;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -746,14 +787,17 @@ PartitionCoreModule::scanForLVMPVs()
|
|||||||
PartitionCoreModule::DeviceInfo*
|
PartitionCoreModule::DeviceInfo*
|
||||||
PartitionCoreModule::infoForDevice( const Device* device ) const
|
PartitionCoreModule::infoForDevice( const Device* device ) const
|
||||||
{
|
{
|
||||||
for ( auto it = m_deviceInfos.constBegin();
|
for ( auto it = m_deviceInfos.constBegin(); it != m_deviceInfos.constEnd(); ++it )
|
||||||
it != m_deviceInfos.constEnd(); ++it )
|
|
||||||
{
|
{
|
||||||
if ( ( *it )->device.data() == device )
|
if ( ( *it )->device.data() == device )
|
||||||
|
{
|
||||||
return *it;
|
return *it;
|
||||||
|
}
|
||||||
if ( ( *it )->immutableDevice.data() == device )
|
if ( ( *it )->immutableDevice.data() == device )
|
||||||
|
{
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -765,8 +809,10 @@ PartitionCoreModule::findPartitionByMountPoint( const QString& mountPoint ) cons
|
|||||||
Device* device = deviceInfo->device.data();
|
Device* device = deviceInfo->device.data();
|
||||||
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
||||||
if ( PartitionInfo::mountPoint( *it ) == mountPoint )
|
if ( PartitionInfo::mountPoint( *it ) == mountPoint )
|
||||||
|
{
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,7 +828,7 @@ PartitionCoreModule::initLayout()
|
|||||||
{
|
{
|
||||||
m_partLayout = new PartitionLayout();
|
m_partLayout = new PartitionLayout();
|
||||||
|
|
||||||
m_partLayout->addEntry( QString("/"), QString("100%") );
|
m_partLayout->addEntry( QString( "/" ), QString( "100%" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -798,42 +844,52 @@ PartitionCoreModule::initLayout( const QVariantList& config )
|
|||||||
{
|
{
|
||||||
QVariantMap pentry = r.toMap();
|
QVariantMap pentry = r.toMap();
|
||||||
|
|
||||||
if ( !pentry.contains( "name" ) || !pentry.contains( "mountPoint" ) ||
|
if ( !pentry.contains( "name" ) || !pentry.contains( "mountPoint" ) || !pentry.contains( "filesystem" )
|
||||||
!pentry.contains( "filesystem" ) || !pentry.contains( "size" ) )
|
|| !pentry.contains( "size" ) )
|
||||||
{
|
{
|
||||||
cError() << "Partition layout entry #" << config.indexOf(r)
|
cError() << "Partition layout entry #" << config.indexOf( r )
|
||||||
<< "lacks mandatory attributes, switching to default layout.";
|
<< "lacks mandatory attributes, switching to default layout.";
|
||||||
delete( m_partLayout );
|
delete ( m_partLayout );
|
||||||
initLayout();
|
initLayout();
|
||||||
break;
|
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 ) );
|
sizeString.setNum( CalamaresUtils::getInteger( pentry, "size", 0 ) );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
sizeString = CalamaresUtils::getString( pentry, "size" );
|
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 ) );
|
minSizeString.setNum( CalamaresUtils::getInteger( pentry, "minSize", 0 ) );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
minSizeString = CalamaresUtils::getString( pentry, "minSize" );
|
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 ) );
|
maxSizeString.setNum( CalamaresUtils::getInteger( pentry, "maxSize", 0 ) );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
maxSizeString = CalamaresUtils::getString( pentry, "maxSize" );
|
maxSizeString = CalamaresUtils::getString( pentry, "maxSize" );
|
||||||
|
}
|
||||||
|
|
||||||
if ( !m_partLayout->addEntry( CalamaresUtils::getString( pentry, "name" ),
|
if ( !m_partLayout->addEntry( CalamaresUtils::getString( pentry, "name" ),
|
||||||
CalamaresUtils::getString( pentry, "mountPoint" ),
|
CalamaresUtils::getString( pentry, "mountPoint" ),
|
||||||
CalamaresUtils::getString( pentry, "filesystem" ),
|
CalamaresUtils::getString( pentry, "filesystem" ),
|
||||||
sizeString,
|
sizeString,
|
||||||
minSizeString,
|
minSizeString,
|
||||||
maxSizeString
|
maxSizeString ) )
|
||||||
) )
|
|
||||||
{
|
{
|
||||||
cError() << "Partition layout entry #" << config.indexOf(r)
|
cError() << "Partition layout entry #" << config.indexOf( r ) << "is invalid, switching to default layout.";
|
||||||
<< "is invalid, switching to default layout.";
|
delete ( m_partLayout );
|
||||||
delete( m_partLayout );
|
|
||||||
initLayout();
|
initLayout();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -841,7 +897,7 @@ PartitionCoreModule::initLayout( const QVariantList& config )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionCoreModule::layoutApply( Device *dev,
|
PartitionCoreModule::layoutApply( Device* dev,
|
||||||
qint64 firstSector,
|
qint64 firstSector,
|
||||||
qint64 lastSector,
|
qint64 lastSector,
|
||||||
QString luksPassphrase,
|
QString luksPassphrase,
|
||||||
@ -849,17 +905,14 @@ PartitionCoreModule::layoutApply( Device *dev,
|
|||||||
const PartitionRole& role )
|
const PartitionRole& role )
|
||||||
{
|
{
|
||||||
bool isEfi = PartUtils::isEfiSystem();
|
bool isEfi = PartUtils::isEfiSystem();
|
||||||
QList< Partition* > partList = m_partLayout->execute( dev, firstSector, lastSector,
|
QList< Partition* > partList = m_partLayout->execute( dev, firstSector, lastSector, luksPassphrase, parent, role );
|
||||||
luksPassphrase, parent, role
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ( Partition *part, partList )
|
foreach ( Partition* part, partList )
|
||||||
{
|
{
|
||||||
if ( part->mountPoint() == "/" )
|
if ( part->mountPoint() == "/" )
|
||||||
{
|
{
|
||||||
createPartition( dev, part,
|
createPartition(
|
||||||
part->activeFlags() | ( isEfi ? KPM_PARTITION_FLAG(None) : KPM_PARTITION_FLAG(Boot) )
|
dev, part, part->activeFlags() | ( isEfi ? KPM_PARTITION_FLAG( None ) : KPM_PARTITION_FLAG( Boot ) ) );
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -869,14 +922,10 @@ PartitionCoreModule::layoutApply( Device *dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionCoreModule::layoutApply( Device *dev,
|
PartitionCoreModule::layoutApply( Device* dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase )
|
||||||
qint64 firstSector,
|
|
||||||
qint64 lastSector,
|
|
||||||
QString luksPassphrase )
|
|
||||||
{
|
{
|
||||||
layoutApply( dev, firstSector, lastSector, luksPassphrase, dev->partitionTable(),
|
layoutApply(
|
||||||
PartitionRole( PartitionRole::Primary )
|
dev, firstSector, lastSector, luksPassphrase, dev->partitionTable(), PartitionRole( PartitionRole::Primary ) );
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -897,13 +946,13 @@ PartitionCoreModule::revertAllDevices()
|
|||||||
for ( auto it = m_deviceInfos.begin(); it != m_deviceInfos.end(); )
|
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
|
// In new VGs device info, there will be always a CreateVolumeGroupJob as the first job in jobs list
|
||||||
if ( dynamic_cast<LvmDevice*>( ( *it )->device.data() ) )
|
if ( dynamic_cast< LvmDevice* >( ( *it )->device.data() ) )
|
||||||
{
|
{
|
||||||
( *it )->isAvailable = true;
|
( *it )->isAvailable = true;
|
||||||
|
|
||||||
if ( !( *it )->jobs.empty() )
|
if ( !( *it )->jobs.empty() )
|
||||||
{
|
{
|
||||||
CreateVolumeGroupJob* vgJob = dynamic_cast<CreateVolumeGroupJob*>( ( *it )->jobs[0].data() );
|
CreateVolumeGroupJob* vgJob = dynamic_cast< CreateVolumeGroupJob* >( ( *it )->jobs[ 0 ].data() );
|
||||||
|
|
||||||
if ( vgJob )
|
if ( vgJob )
|
||||||
{
|
{
|
||||||
@ -935,7 +984,9 @@ PartitionCoreModule::revertDevice( Device* dev, bool individualRevert )
|
|||||||
DeviceInfo* devInfo = infoForDevice( dev );
|
DeviceInfo* devInfo = infoForDevice( dev );
|
||||||
|
|
||||||
if ( !devInfo )
|
if ( !devInfo )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
devInfo->forgetChanges();
|
devInfo->forgetChanges();
|
||||||
CoreBackend* backend = CoreBackendManager::self()->backend();
|
CoreBackend* backend = CoreBackendManager::self()->backend();
|
||||||
Device* newDev = backend->scanDevice( devInfo->device->deviceNode() );
|
Device* newDev = backend->scanDevice( devInfo->device->deviceNode() );
|
||||||
@ -948,13 +999,17 @@ PartitionCoreModule::revertDevice( Device* dev, bool individualRevert )
|
|||||||
for ( DeviceInfo* const info : m_deviceInfos )
|
for ( DeviceInfo* const info : m_deviceInfos )
|
||||||
{
|
{
|
||||||
if ( info && !info->device.isNull() && info->device->type() == Device::Type::Disk_Device )
|
if ( info && !info->device.isNull() && info->device->type() == Device::Type::Disk_Device )
|
||||||
|
{
|
||||||
devices.append( info->device.data() );
|
devices.append( info->device.data() );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_bootLoaderModel->init( devices );
|
m_bootLoaderModel->init( devices );
|
||||||
|
|
||||||
if ( individualRevert )
|
if ( individualRevert )
|
||||||
|
{
|
||||||
refreshAfterModelChange();
|
refreshAfterModelChange();
|
||||||
|
}
|
||||||
emit deviceReverted( newDev );
|
emit deviceReverted( newDev );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -963,9 +1018,7 @@ void
|
|||||||
PartitionCoreModule::asyncRevertDevice( Device* dev, std::function< void() > callback )
|
PartitionCoreModule::asyncRevertDevice( Device* dev, std::function< void() > callback )
|
||||||
{
|
{
|
||||||
QFutureWatcher< void >* watcher = new QFutureWatcher< void >();
|
QFutureWatcher< void >* watcher = new QFutureWatcher< void >();
|
||||||
connect( watcher, &QFutureWatcher< void >::finished,
|
connect( watcher, &QFutureWatcher< void >::finished, this, [watcher, callback] {
|
||||||
this, [ watcher, callback ]
|
|
||||||
{
|
|
||||||
callback();
|
callback();
|
||||||
watcher->deleteLater();
|
watcher->deleteLater();
|
||||||
} );
|
} );
|
||||||
@ -979,7 +1032,9 @@ void
|
|||||||
PartitionCoreModule::clearJobs()
|
PartitionCoreModule::clearJobs()
|
||||||
{
|
{
|
||||||
foreach ( DeviceInfo* deviceInfo, m_deviceInfos )
|
foreach ( DeviceInfo* deviceInfo, m_deviceInfos )
|
||||||
|
{
|
||||||
deviceInfo->forgetChanges();
|
deviceInfo->forgetChanges();
|
||||||
|
}
|
||||||
updateIsDirty();
|
updateIsDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -991,11 +1046,13 @@ PartitionCoreModule::isDirty()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PartitionCoreModule::isVGdeactivated( LvmDevice *device )
|
PartitionCoreModule::isVGdeactivated( LvmDevice* device )
|
||||||
{
|
{
|
||||||
for ( DeviceInfo* deviceInfo : m_deviceInfos )
|
for ( DeviceInfo* deviceInfo : m_deviceInfos )
|
||||||
if ( device == deviceInfo->device.data() && !deviceInfo->isAvailable )
|
if ( device == deviceInfo->device.data() && !deviceInfo->isAvailable )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1007,7 +1064,9 @@ PartitionCoreModule::createSummaryInfo() const
|
|||||||
for ( auto deviceInfo : m_deviceInfos )
|
for ( auto deviceInfo : m_deviceInfos )
|
||||||
{
|
{
|
||||||
if ( !deviceInfo->isDirty() )
|
if ( !deviceInfo->isDirty() )
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
SummaryInfo summaryInfo;
|
SummaryInfo summaryInfo;
|
||||||
summaryInfo.deviceName = deviceInfo->device->name();
|
summaryInfo.deviceName = deviceInfo->device->name();
|
||||||
summaryInfo.deviceNode = deviceInfo->device->deviceNode();
|
summaryInfo.deviceNode = deviceInfo->device->deviceNode();
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "core/PartitionModel.h"
|
#include "core/PartitionModel.h"
|
||||||
|
|
||||||
#include "Job.h"
|
#include "Job.h"
|
||||||
|
#include "partition/KPMManager.h"
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
#include <kpmcore/core/lvmdevice.h>
|
#include <kpmcore/core/lvmdevice.h>
|
||||||
@ -138,10 +139,10 @@ public:
|
|||||||
* If @p flags is not FlagNone, then the given flags are
|
* If @p flags is not FlagNone, then the given flags are
|
||||||
* applied to the newly-created partition.
|
* applied to the newly-created partition.
|
||||||
*/
|
*/
|
||||||
void createPartition( Device* device, Partition* partition,
|
void
|
||||||
PartitionTable::Flags flags = KPM_PARTITION_FLAG(None) );
|
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 );
|
void resizeVolumeGroup( LvmDevice* device, QVector< const Partition* >& pvList );
|
||||||
|
|
||||||
@ -165,8 +166,13 @@ public:
|
|||||||
void initLayout();
|
void initLayout();
|
||||||
void initLayout( const QVariantList& config );
|
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 );
|
||||||
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,
|
||||||
|
PartitionNode* parent,
|
||||||
|
const PartitionRole& role );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief jobs creates and returns a list of jobs which can then apply the changes
|
* @brief jobs creates and returns a list of jobs which can then apply the changes
|
||||||
@ -202,7 +208,7 @@ public:
|
|||||||
* When @p individualRevert is true, calls refreshAfterModelChange(),
|
* When @p individualRevert is true, calls refreshAfterModelChange(),
|
||||||
* used to reduce number of refreshes when calling revertAllDevices().
|
* used to reduce number of refreshes when calling revertAllDevices().
|
||||||
*/
|
*/
|
||||||
void revertDevice( Device* dev, bool individualRevert=true );
|
void revertDevice( Device* dev, bool individualRevert = true );
|
||||||
void asyncRevertDevice( Device* dev, std::function< void() > callback ); //like revertDevice, but asynchronous
|
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
|
||||||
@ -235,6 +241,8 @@ Q_SIGNALS:
|
|||||||
void deviceReverted( Device* device );
|
void deviceReverted( Device* device );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CalamaresUtils::Partition::KPMManager m_kpmcore;
|
||||||
|
|
||||||
void refreshAfterModelChange();
|
void refreshAfterModelChange();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,15 +57,19 @@ setFormat( Partition* partition, bool value )
|
|||||||
partition->setProperty( FORMAT_PROPERTY, value );
|
partition->setProperty( FORMAT_PROPERTY, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionTable::Flags flags(const Partition* partition)
|
PartitionTable::Flags
|
||||||
|
flags( const Partition* partition )
|
||||||
{
|
{
|
||||||
auto v = partition->property( FLAGS_PROPERTY );
|
auto v = partition->property( FLAGS_PROPERTY );
|
||||||
if (v.type() == QVariant::Int )
|
if ( v.type() == QVariant::Int )
|
||||||
return static_cast<PartitionTable::Flags>( v.toInt() );
|
{
|
||||||
|
return static_cast< PartitionTable::Flags >( v.toInt() );
|
||||||
|
}
|
||||||
return partition->activeFlags();
|
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 ) );
|
partition->setProperty( FLAGS_PROPERTY, PartitionTable::Flags::Int( f ) );
|
||||||
}
|
}
|
||||||
@ -82,11 +86,11 @@ bool
|
|||||||
isDirty( Partition* partition )
|
isDirty( Partition* partition )
|
||||||
{
|
{
|
||||||
if ( LvmDevice::s_DirtyPVs.contains( partition ) )
|
if ( LvmDevice::s_DirtyPVs.contains( partition ) )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return !mountPoint( partition ).isEmpty()
|
return !mountPoint( partition ).isEmpty() || format( partition ) || flags( partition ) != partition->activeFlags();
|
||||||
|| format( partition )
|
|
||||||
|| flags( partition ) != partition->activeFlags();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace PartitionInfo
|
||||||
|
@ -60,6 +60,6 @@ void reset( Partition* partition );
|
|||||||
*/
|
*/
|
||||||
bool isDirty( Partition* partition );
|
bool isDirty( Partition* partition );
|
||||||
|
|
||||||
};
|
}; // namespace PartitionInfo
|
||||||
|
|
||||||
#endif /* PARTITIONINFO_H */
|
#endif /* PARTITIONINFO_H */
|
||||||
|
@ -26,9 +26,9 @@
|
|||||||
#include "core/PartitionLayout.h"
|
#include "core/PartitionLayout.h"
|
||||||
|
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
|
#include "core/PartUtils.h"
|
||||||
#include "core/PartitionActions.h"
|
#include "core/PartitionActions.h"
|
||||||
#include "core/PartitionInfo.h"
|
#include "core/PartitionInfo.h"
|
||||||
#include "core/PartUtils.h"
|
|
||||||
|
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
@ -42,10 +42,12 @@ getDefaultFileSystemType()
|
|||||||
|
|
||||||
if ( gs->contains( "defaultFileSystemType" ) )
|
if ( gs->contains( "defaultFileSystemType" ) )
|
||||||
{
|
{
|
||||||
PartUtils::findFS( gs->value( "defaultFileSystemType" ).toString(), &defaultFS);
|
PartUtils::findFS( gs->value( "defaultFileSystemType" ).toString(), &defaultFS );
|
||||||
if ( defaultFS == FileSystem::Unknown )
|
if ( defaultFS == FileSystem::Unknown )
|
||||||
|
{
|
||||||
defaultFS = FileSystem::Ext4;
|
defaultFS = FileSystem::Ext4;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return defaultFS;
|
return defaultFS;
|
||||||
}
|
}
|
||||||
@ -67,9 +69,7 @@ PartitionLayout::PartitionLayout( const PartitionLayout& layout )
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionLayout::~PartitionLayout()
|
PartitionLayout::~PartitionLayout() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PartitionLayout::addEntry( PartitionLayout::PartitionEntry entry )
|
PartitionLayout::addEntry( PartitionLayout::PartitionEntry entry )
|
||||||
@ -117,7 +117,12 @@ PartitionLayout::addEntry( const QString& mountPoint, const QString& size, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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 );
|
PartitionLayout::PartitionEntry entry( size, min, max );
|
||||||
|
|
||||||
@ -136,7 +141,9 @@ PartitionLayout::addEntry( const QString& label, const QString& mountPoint, cons
|
|||||||
entry.partMountPoint = mountPoint;
|
entry.partMountPoint = mountPoint;
|
||||||
PartUtils::findFS( fs, &entry.partFileSystem );
|
PartUtils::findFS( fs, &entry.partFileSystem );
|
||||||
if ( entry.partFileSystem == FileSystem::Unknown )
|
if ( entry.partFileSystem == FileSystem::Unknown )
|
||||||
|
{
|
||||||
entry.partFileSystem = m_defaultFsType;
|
entry.partFileSystem = m_defaultFsType;
|
||||||
|
}
|
||||||
|
|
||||||
m_partLayout.append( entry );
|
m_partLayout.append( entry );
|
||||||
|
|
||||||
@ -144,8 +151,10 @@ PartitionLayout::addEntry( const QString& label, const QString& mountPoint, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
QList< Partition* >
|
QList< Partition* >
|
||||||
PartitionLayout::execute( Device *dev, qint64 firstSector,
|
PartitionLayout::execute( Device* dev,
|
||||||
qint64 lastSector, QString luksPassphrase,
|
qint64 firstSector,
|
||||||
|
qint64 lastSector,
|
||||||
|
QString luksPassphrase,
|
||||||
PartitionNode* parent,
|
PartitionNode* parent,
|
||||||
const PartitionRole& role )
|
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
|
// TODO: Refine partition sizes to make sure there is room for every partition
|
||||||
// Use a default (200-500M ?) minimum size for partition without minSize
|
// 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;
|
qint64 size = -1;
|
||||||
// Calculate partition size
|
// Calculate partition size
|
||||||
@ -169,67 +178,67 @@ PartitionLayout::execute( Device *dev, qint64 firstSector,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cWarning() << "Partition" << part.partMountPoint << "size ("
|
cWarning() << "Partition" << part.partMountPoint << "size (" << size << "sectors) is invalid, skipping...";
|
||||||
<< size << "sectors) is invalid, skipping...";
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( part.partMinSize.isValid() )
|
if ( part.partMinSize.isValid() )
|
||||||
|
{
|
||||||
minSize = part.partMinSize.toSectors( totalSize, dev->logicalSize() );
|
minSize = part.partMinSize.toSectors( totalSize, dev->logicalSize() );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
minSize = 0;
|
minSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ( part.partMaxSize.isValid() )
|
if ( part.partMaxSize.isValid() )
|
||||||
|
{
|
||||||
maxSize = part.partMaxSize.toSectors( totalSize, dev->logicalSize() );
|
maxSize = part.partMaxSize.toSectors( totalSize, dev->logicalSize() );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
maxSize = availableSize;
|
maxSize = availableSize;
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure we never go under minSize once converted to sectors
|
// Make sure we never go under minSize once converted to sectors
|
||||||
if ( maxSize < minSize )
|
if ( maxSize < minSize )
|
||||||
{
|
{
|
||||||
cWarning() << "Partition" << part.partMountPoint << "max size (" << maxSize
|
cWarning() << "Partition" << part.partMountPoint << "max size (" << maxSize << "sectors) is < min size ("
|
||||||
<< "sectors) is < min size (" << minSize << "sectors), using min size";
|
<< minSize << "sectors), using min size";
|
||||||
maxSize = minSize;
|
maxSize = minSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust partition size based on user-defined boundaries and available space
|
// Adjust partition size based on user-defined boundaries and available space
|
||||||
if ( size < minSize )
|
if ( size < minSize )
|
||||||
|
{
|
||||||
size = minSize;
|
size = minSize;
|
||||||
|
}
|
||||||
if ( size > maxSize )
|
if ( size > maxSize )
|
||||||
|
{
|
||||||
size = maxSize;
|
size = maxSize;
|
||||||
|
}
|
||||||
if ( size > availableSize )
|
if ( size > availableSize )
|
||||||
|
{
|
||||||
size = availableSize;
|
size = availableSize;
|
||||||
|
}
|
||||||
end = firstSector + size - 1;
|
end = firstSector + size - 1;
|
||||||
|
|
||||||
if ( luksPassphrase.isEmpty() )
|
if ( luksPassphrase.isEmpty() )
|
||||||
{
|
{
|
||||||
currentPartition = KPMHelpers::createNewPartition(
|
currentPartition = KPMHelpers::createNewPartition(
|
||||||
parent,
|
parent, *dev, role, part.partFileSystem, firstSector, end, KPM_PARTITION_FLAG( None ) );
|
||||||
*dev,
|
|
||||||
role,
|
|
||||||
part.partFileSystem,
|
|
||||||
firstSector,
|
|
||||||
end,
|
|
||||||
KPM_PARTITION_FLAG(None)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentPartition = KPMHelpers::createNewEncryptedPartition(
|
currentPartition = KPMHelpers::createNewEncryptedPartition(
|
||||||
parent,
|
parent, *dev, role, part.partFileSystem, firstSector, end, luksPassphrase, KPM_PARTITION_FLAG( None ) );
|
||||||
*dev,
|
|
||||||
role,
|
|
||||||
part.partFileSystem,
|
|
||||||
firstSector,
|
|
||||||
end,
|
|
||||||
luksPassphrase,
|
|
||||||
KPM_PARTITION_FLAG(None)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
PartitionInfo::setFormat( currentPartition, true );
|
PartitionInfo::setFormat( currentPartition, true );
|
||||||
PartitionInfo::setMountPoint( currentPartition, part.partMountPoint );
|
PartitionInfo::setMountPoint( currentPartition, part.partMountPoint );
|
||||||
if ( !part.partLabel.isEmpty() )
|
if ( !part.partLabel.isEmpty() )
|
||||||
|
{
|
||||||
currentPartition->fileSystem().setLabel( part.partLabel );
|
currentPartition->fileSystem().setLabel( part.partLabel );
|
||||||
|
}
|
||||||
// Some buggy (legacy) BIOSes test if the bootflag of at least one partition is set.
|
// 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.
|
// Otherwise they ignore the device in boot-order, so add it here.
|
||||||
partList.append( currentPartition );
|
partList.append( currentPartition );
|
||||||
|
@ -37,7 +37,6 @@ class Partition;
|
|||||||
class PartitionLayout
|
class PartitionLayout
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct PartitionEntry
|
struct PartitionEntry
|
||||||
{
|
{
|
||||||
QString partLabel;
|
QString partLabel;
|
||||||
@ -54,9 +53,11 @@ public:
|
|||||||
|
|
||||||
bool isValid() const
|
bool isValid() const
|
||||||
{
|
{
|
||||||
if ( !partSize.isValid() ||
|
if ( !partSize.isValid()
|
||||||
( partMinSize.isValid() && partMaxSize.isValid() && partMinSize > partMaxSize ) )
|
|| ( partMinSize.isValid() && partMaxSize.isValid() && partMinSize > partMaxSize ) )
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -67,14 +68,27 @@ public:
|
|||||||
~PartitionLayout();
|
~PartitionLayout();
|
||||||
|
|
||||||
bool addEntry( PartitionEntry entry );
|
bool addEntry( PartitionEntry entry );
|
||||||
bool addEntry( const QString& mountPoint, const QString& size, const QString& min = QString(), const QString& max = QString() );
|
bool addEntry( const QString& mountPoint,
|
||||||
bool addEntry( const QString& label, const QString& mountPoint, const QString& fs, const QString& size, const QString& min = QString(), const QString& max = QString() );
|
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.
|
* @brief Apply the current partition layout to the selected drive space.
|
||||||
* @return A list of Partition objects.
|
* @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:
|
private:
|
||||||
FileSystem::Type m_defaultFsType;
|
FileSystem::Type m_defaultFsType;
|
||||||
|
@ -20,8 +20,11 @@
|
|||||||
#include "core/PartitionModel.h"
|
#include "core/PartitionModel.h"
|
||||||
|
|
||||||
#include "core/ColorUtils.h"
|
#include "core/ColorUtils.h"
|
||||||
#include "core/PartitionInfo.h"
|
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
|
#include "core/PartitionInfo.h"
|
||||||
|
|
||||||
|
#include "partition/FileSystem.h"
|
||||||
|
#include "partition/PartitionQuery.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
// CalaPM
|
// CalaPM
|
||||||
@ -36,6 +39,9 @@
|
|||||||
// Qt
|
// Qt
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
|
using CalamaresUtils::Partition::isPartitionFreeSpace;
|
||||||
|
using CalamaresUtils::Partition::isPartitionNew;
|
||||||
|
|
||||||
//- ResetHelper --------------------------------------------
|
//- ResetHelper --------------------------------------------
|
||||||
PartitionModel::ResetHelper::ResetHelper( PartitionModel* model )
|
PartitionModel::ResetHelper::ResetHelper( PartitionModel* model )
|
||||||
: m_model( model )
|
: m_model( model )
|
||||||
@ -61,9 +67,9 @@ PartitionModel::PartitionModel( QObject* parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionModel::init( Device* device , const OsproberEntryList& osproberEntries )
|
PartitionModel::init( Device* device, const OsproberEntryList& osproberEntries )
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_lock);
|
QMutexLocker lock( &m_lock );
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_device = device;
|
m_device = device;
|
||||||
m_osproberEntries = osproberEntries;
|
m_osproberEntries = osproberEntries;
|
||||||
@ -81,7 +87,9 @@ PartitionModel::rowCount( const QModelIndex& parent ) const
|
|||||||
{
|
{
|
||||||
Partition* parentPartition = partitionForIndex( parent );
|
Partition* parentPartition = partitionForIndex( parent );
|
||||||
if ( parentPartition )
|
if ( parentPartition )
|
||||||
|
{
|
||||||
return parentPartition->children().count();
|
return parentPartition->children().count();
|
||||||
|
}
|
||||||
PartitionTable* table = m_device->partitionTable();
|
PartitionTable* table = m_device->partitionTable();
|
||||||
return table ? table->children().count() : 0;
|
return table ? table->children().count() : 0;
|
||||||
}
|
}
|
||||||
@ -89,16 +97,21 @@ PartitionModel::rowCount( const QModelIndex& parent ) const
|
|||||||
QModelIndex
|
QModelIndex
|
||||||
PartitionModel::index( int row, int column, const QModelIndex& parent ) const
|
PartitionModel::index( int row, int column, const QModelIndex& parent ) const
|
||||||
{
|
{
|
||||||
PartitionNode* parentPartition = parent.isValid()
|
PartitionNode* parentPartition = parent.isValid() ? static_cast< PartitionNode* >( partitionForIndex( parent ) )
|
||||||
? static_cast< PartitionNode* >( partitionForIndex( parent ) )
|
|
||||||
: static_cast< PartitionNode* >( m_device->partitionTable() );
|
: static_cast< PartitionNode* >( m_device->partitionTable() );
|
||||||
if ( !parentPartition )
|
if ( !parentPartition )
|
||||||
|
{
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
}
|
||||||
auto lst = parentPartition->children();
|
auto lst = parentPartition->children();
|
||||||
if ( row < 0 || row >= lst.count() )
|
if ( row < 0 || row >= lst.count() )
|
||||||
|
{
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
}
|
||||||
if ( column < 0 || column >= ColumnCount )
|
if ( column < 0 || column >= ColumnCount )
|
||||||
|
{
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
}
|
||||||
Partition* partition = parentPartition->children().at( row );
|
Partition* partition = parentPartition->children().at( row );
|
||||||
return createIndex( row, column, partition );
|
return createIndex( row, column, partition );
|
||||||
}
|
}
|
||||||
@ -107,19 +120,27 @@ QModelIndex
|
|||||||
PartitionModel::parent( const QModelIndex& child ) const
|
PartitionModel::parent( const QModelIndex& child ) const
|
||||||
{
|
{
|
||||||
if ( !child.isValid() )
|
if ( !child.isValid() )
|
||||||
|
{
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
}
|
||||||
Partition* partition = partitionForIndex( child );
|
Partition* partition = partitionForIndex( child );
|
||||||
if ( !partition )
|
if ( !partition )
|
||||||
|
{
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
}
|
||||||
PartitionNode* parentNode = partition->parent();
|
PartitionNode* parentNode = partition->parent();
|
||||||
if ( parentNode == m_device->partitionTable() )
|
if ( parentNode == m_device->partitionTable() )
|
||||||
|
{
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
for ( auto p : m_device->partitionTable()->children() )
|
for ( auto p : m_device->partitionTable()->children() )
|
||||||
{
|
{
|
||||||
if ( parentNode == p )
|
if ( parentNode == p )
|
||||||
|
{
|
||||||
return createIndex( row, 0, parentNode );
|
return createIndex( row, 0, parentNode );
|
||||||
|
}
|
||||||
++row;
|
++row;
|
||||||
}
|
}
|
||||||
cWarning() << "No parent found!";
|
cWarning() << "No parent found!";
|
||||||
@ -131,7 +152,9 @@ PartitionModel::data( const QModelIndex& index, int role ) const
|
|||||||
{
|
{
|
||||||
Partition* partition = partitionForIndex( index );
|
Partition* partition = partitionForIndex( index );
|
||||||
if ( !partition )
|
if ( !partition )
|
||||||
|
{
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
switch ( role )
|
switch ( role )
|
||||||
{
|
{
|
||||||
@ -140,19 +163,23 @@ PartitionModel::data( const QModelIndex& index, int role ) const
|
|||||||
int col = index.column();
|
int col = index.column();
|
||||||
if ( col == NameColumn )
|
if ( col == NameColumn )
|
||||||
{
|
{
|
||||||
if ( KPMHelpers::isPartitionFreeSpace( partition ) )
|
if ( isPartitionFreeSpace( partition ) )
|
||||||
|
{
|
||||||
return tr( "Free Space" );
|
return tr( "Free Space" );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return KPMHelpers::isPartitionNew( partition )
|
return isPartitionNew( partition ) ? tr( "New partition" ) : partition->partitionPath();
|
||||||
? tr( "New partition" )
|
|
||||||
: partition->partitionPath();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( col == FileSystemColumn )
|
if ( col == FileSystemColumn )
|
||||||
return KPMHelpers::prettyNameForFileSystemType( partition->fileSystem().type() );
|
{
|
||||||
|
return CalamaresUtils::Partition::prettyNameForFileSystemType( partition->fileSystem().type() );
|
||||||
|
}
|
||||||
if ( col == MountPointColumn )
|
if ( col == MountPointColumn )
|
||||||
|
{
|
||||||
return PartitionInfo::mountPoint( partition );
|
return PartitionInfo::mountPoint( partition );
|
||||||
|
}
|
||||||
if ( col == SizeColumn )
|
if ( col == SizeColumn )
|
||||||
{
|
{
|
||||||
qint64 size = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSize();
|
qint64 size = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSize();
|
||||||
@ -163,41 +190,48 @@ PartitionModel::data( const QModelIndex& index, int role ) const
|
|||||||
}
|
}
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
if ( index.column() == NameColumn )
|
if ( index.column() == NameColumn )
|
||||||
|
{
|
||||||
return ColorUtils::colorForPartition( partition );
|
return ColorUtils::colorForPartition( partition );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
}
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
{
|
{
|
||||||
int col = index.column();
|
int col = index.column();
|
||||||
QString name;
|
QString name;
|
||||||
if ( col == NameColumn )
|
if ( col == NameColumn )
|
||||||
{
|
{
|
||||||
if ( KPMHelpers::isPartitionFreeSpace( partition ) )
|
if ( isPartitionFreeSpace( partition ) )
|
||||||
|
{
|
||||||
name = tr( "Free Space" );
|
name = tr( "Free Space" );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
name = KPMHelpers::isPartitionNew( partition )
|
name = isPartitionNew( partition ) ? tr( "New partition" ) : partition->partitionPath();
|
||||||
? tr( "New partition" )
|
|
||||||
: partition->partitionPath();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QString prettyFileSystem = KPMHelpers::prettyNameForFileSystemType( partition->fileSystem().type() );
|
QString prettyFileSystem
|
||||||
|
= CalamaresUtils::Partition::prettyNameForFileSystemType( partition->fileSystem().type() );
|
||||||
qint64 size = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSize();
|
qint64 size = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSize();
|
||||||
QString prettySize = KFormat().formatByteSize( size );
|
QString prettySize = KFormat().formatByteSize( size );
|
||||||
return QVariant(name + " " + prettyFileSystem + " " + prettySize);
|
return QVariant( name + " " + prettyFileSystem + " " + prettySize );
|
||||||
}
|
}
|
||||||
case SizeRole:
|
case SizeRole:
|
||||||
return ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSize();
|
return ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSize();
|
||||||
case IsFreeSpaceRole:
|
case IsFreeSpaceRole:
|
||||||
return KPMHelpers::isPartitionFreeSpace( partition );
|
return isPartitionFreeSpace( partition );
|
||||||
|
|
||||||
case IsPartitionNewRole:
|
case IsPartitionNewRole:
|
||||||
return KPMHelpers::isPartitionNew( partition );
|
return isPartitionNew( partition );
|
||||||
|
|
||||||
case FileSystemLabelRole:
|
case FileSystemLabelRole:
|
||||||
if ( partition->fileSystem().supportGetLabel() != FileSystem::cmdSupportNone &&
|
if ( partition->fileSystem().supportGetLabel() != FileSystem::cmdSupportNone
|
||||||
!partition->fileSystem().label().isEmpty() )
|
&& !partition->fileSystem().label().isEmpty() )
|
||||||
|
{
|
||||||
return partition->fileSystem().label();
|
return partition->fileSystem().label();
|
||||||
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
case FileSystemTypeRole:
|
case FileSystemTypeRole:
|
||||||
@ -212,38 +246,43 @@ PartitionModel::data( const QModelIndex& index, int role ) const
|
|||||||
// Osprober roles:
|
// Osprober roles:
|
||||||
case OsproberNameRole:
|
case OsproberNameRole:
|
||||||
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
|
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
|
||||||
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
|
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone
|
||||||
!partition->fileSystem().uuid().isEmpty() &&
|
&& !partition->fileSystem().uuid().isEmpty() && osproberEntry.uuid == partition->fileSystem().uuid() )
|
||||||
osproberEntry.uuid == partition->fileSystem().uuid() )
|
{
|
||||||
return osproberEntry.prettyName;
|
return osproberEntry.prettyName;
|
||||||
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
case OsproberPathRole:
|
case OsproberPathRole:
|
||||||
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
|
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
|
||||||
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
|
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone
|
||||||
!partition->fileSystem().uuid().isEmpty() &&
|
&& !partition->fileSystem().uuid().isEmpty() && osproberEntry.uuid == partition->fileSystem().uuid() )
|
||||||
osproberEntry.uuid == partition->fileSystem().uuid() )
|
{
|
||||||
return osproberEntry.path;
|
return osproberEntry.path;
|
||||||
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
case OsproberCanBeResizedRole:
|
case OsproberCanBeResizedRole:
|
||||||
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
|
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
|
||||||
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
|
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone
|
||||||
!partition->fileSystem().uuid().isEmpty() &&
|
&& !partition->fileSystem().uuid().isEmpty() && osproberEntry.uuid == partition->fileSystem().uuid() )
|
||||||
osproberEntry.uuid == partition->fileSystem().uuid() )
|
{
|
||||||
return osproberEntry.canBeResized;
|
return osproberEntry.canBeResized;
|
||||||
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
case OsproberRawLineRole:
|
case OsproberRawLineRole:
|
||||||
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
|
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
|
||||||
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
|
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone
|
||||||
!partition->fileSystem().uuid().isEmpty() &&
|
&& !partition->fileSystem().uuid().isEmpty() && osproberEntry.uuid == partition->fileSystem().uuid() )
|
||||||
osproberEntry.uuid == partition->fileSystem().uuid() )
|
{
|
||||||
return osproberEntry.line;
|
return osproberEntry.line;
|
||||||
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
case OsproberHomePartitionPathRole:
|
case OsproberHomePartitionPathRole:
|
||||||
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
|
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
|
||||||
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
|
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone
|
||||||
!partition->fileSystem().uuid().isEmpty() &&
|
&& !partition->fileSystem().uuid().isEmpty() && osproberEntry.uuid == partition->fileSystem().uuid() )
|
||||||
osproberEntry.uuid == partition->fileSystem().uuid() )
|
{
|
||||||
return osproberEntry.homePath;
|
return osproberEntry.homePath;
|
||||||
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
// end Osprober roles.
|
// end Osprober roles.
|
||||||
|
|
||||||
@ -256,7 +295,9 @@ QVariant
|
|||||||
PartitionModel::headerData( int section, Qt::Orientation, int role ) const
|
PartitionModel::headerData( int section, Qt::Orientation, int role ) const
|
||||||
{
|
{
|
||||||
if ( role != Qt::DisplayRole )
|
if ( role != Qt::DisplayRole )
|
||||||
|
{
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
switch ( section )
|
switch ( section )
|
||||||
{
|
{
|
||||||
@ -277,9 +318,11 @@ PartitionModel::headerData( int section, Qt::Orientation, int role ) const
|
|||||||
Partition*
|
Partition*
|
||||||
PartitionModel::partitionForIndex( const QModelIndex& index ) const
|
PartitionModel::partitionForIndex( const QModelIndex& index ) const
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_lock);
|
QMutexLocker lock( &m_lock );
|
||||||
if ( !index.isValid() )
|
if ( !index.isValid() )
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
return reinterpret_cast< Partition* >( index.internalPointer() );
|
return reinterpret_cast< Partition* >( index.internalPointer() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ public:
|
|||||||
|
|
||||||
ResetHelper( const ResetHelper& ) = delete;
|
ResetHelper( const ResetHelper& ) = delete;
|
||||||
ResetHelper& operator=( const ResetHelper& ) = delete;
|
ResetHelper& operator=( const ResetHelper& ) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PartitionModel* m_model;
|
PartitionModel* m_model;
|
||||||
};
|
};
|
||||||
@ -108,10 +109,7 @@ public:
|
|||||||
|
|
||||||
Partition* partitionForIndex( const QModelIndex& index ) const;
|
Partition* partitionForIndex( const QModelIndex& index ) const;
|
||||||
|
|
||||||
Device* device() const
|
Device* device() const { return m_device; }
|
||||||
{
|
|
||||||
return m_device;
|
|
||||||
}
|
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include "core/PartitionActions.h"
|
#include "core/PartitionActions.h"
|
||||||
#include "core/PartitionCoreModule.h"
|
#include "core/PartitionCoreModule.h"
|
||||||
#include "core/PartitionInfo.h"
|
#include "core/PartitionInfo.h"
|
||||||
#include "core/PartitionIterator.h"
|
|
||||||
#include "core/PartitionModel.h"
|
#include "core/PartitionModel.h"
|
||||||
|
|
||||||
#include "BootInfoWidget.h"
|
#include "BootInfoWidget.h"
|
||||||
@ -40,14 +39,16 @@
|
|||||||
#include "ReplaceWidget.h"
|
#include "ReplaceWidget.h"
|
||||||
#include "ScanningDialog.h"
|
#include "ScanningDialog.h"
|
||||||
|
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
#include "partition/PartitionIterator.h"
|
||||||
|
#include "partition/PartitionQuery.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Retranslator.h"
|
#include "utils/Retranslator.h"
|
||||||
#include "utils/Units.h"
|
#include "utils/Units.h"
|
||||||
|
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
#include "GlobalStorage.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
#include "JobQueue.h"
|
|
||||||
|
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
@ -65,6 +66,9 @@
|
|||||||
#include <QtConcurrent/QtConcurrent>
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
|
||||||
using PartitionActions::Choices::SwapChoice;
|
using PartitionActions::Choices::SwapChoice;
|
||||||
|
using CalamaresUtils::Partition::PartitionIterator;
|
||||||
|
using CalamaresUtils::Partition::isPartitionFreeSpace;
|
||||||
|
using CalamaresUtils::Partition::findPartitionByPath;
|
||||||
|
|
||||||
/** @brief Given a set of swap choices, return a sensible value from it.
|
/** @brief Given a set of swap choices, return a sensible value from it.
|
||||||
*
|
*
|
||||||
@ -691,7 +695,7 @@ ChoicePage::doAlongsideApply()
|
|||||||
for ( int i = 0; i < dm->rowCount(); ++i )
|
for ( int i = 0; i < dm->rowCount(); ++i )
|
||||||
{
|
{
|
||||||
Device* dev = dm->deviceForIndex( dm->index( i ) );
|
Device* dev = dm->deviceForIndex( dm->index( i ) );
|
||||||
Partition* candidate = KPMHelpers::findPartitionByPath( { dev }, path );
|
Partition* candidate = findPartitionByPath( { dev }, path );
|
||||||
if ( candidate )
|
if ( candidate )
|
||||||
{
|
{
|
||||||
qint64 firstSector = candidate->firstSector();
|
qint64 firstSector = candidate->firstSector();
|
||||||
@ -754,7 +758,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current )
|
|||||||
Partition* selectedPartition =
|
Partition* selectedPartition =
|
||||||
static_cast< Partition* >( current.data( PartitionModel::PartitionPtrRole )
|
static_cast< Partition* >( current.data( PartitionModel::PartitionPtrRole )
|
||||||
.value< void* >() );
|
.value< void* >() );
|
||||||
if ( KPMHelpers::isPartitionFreeSpace( selectedPartition ) )
|
if ( isPartitionFreeSpace( selectedPartition ) )
|
||||||
{
|
{
|
||||||
//NOTE: if the selected partition is free space, we don't deal with
|
//NOTE: if the selected partition is free space, we don't deal with
|
||||||
// a separate /home partition at all because there's no existing
|
// a separate /home partition at all because there's no existing
|
||||||
@ -768,7 +772,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current )
|
|||||||
if ( parent && parent->roles().has( PartitionRole::Extended ) )
|
if ( parent && parent->roles().has( PartitionRole::Extended ) )
|
||||||
{
|
{
|
||||||
newRoles = PartitionRole( PartitionRole::Logical );
|
newRoles = PartitionRole( PartitionRole::Logical );
|
||||||
newParent = KPMHelpers::findPartitionByPath( { selectedDevice() }, parent->partitionPath() );
|
newParent = findPartitionByPath( { selectedDevice() }, parent->partitionPath() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,7 +786,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current )
|
|||||||
// We can't use the PartitionPtrRole because we need to make changes to the
|
// We can't use the PartitionPtrRole because we need to make changes to the
|
||||||
// main DeviceModel, not the immutable copy.
|
// main DeviceModel, not the immutable copy.
|
||||||
QString partPath = current.data( PartitionModel::PartitionPathRole ).toString();
|
QString partPath = current.data( PartitionModel::PartitionPathRole ).toString();
|
||||||
selectedPartition = KPMHelpers::findPartitionByPath( { selectedDevice() },
|
selectedPartition = findPartitionByPath( { selectedDevice() },
|
||||||
partPath );
|
partPath );
|
||||||
if ( selectedPartition )
|
if ( selectedPartition )
|
||||||
{
|
{
|
||||||
@ -805,7 +809,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current )
|
|||||||
gs->value( "defaultFileSystemType" ).toString(),
|
gs->value( "defaultFileSystemType" ).toString(),
|
||||||
m_encryptWidget->passphrase()
|
m_encryptWidget->passphrase()
|
||||||
} );
|
} );
|
||||||
Partition* homePartition = KPMHelpers::findPartitionByPath( { selectedDevice() },
|
Partition* homePartition = findPartitionByPath( { selectedDevice() },
|
||||||
*homePartitionPath );
|
*homePartitionPath );
|
||||||
|
|
||||||
if ( homePartition && doReuseHomePartition )
|
if ( homePartition && doReuseHomePartition )
|
||||||
|
@ -20,7 +20,8 @@
|
|||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gui/CreatePartitionDialog.h"
|
#include "CreatePartitionDialog.h"
|
||||||
|
#include "ui_CreatePartitionDialog.h"
|
||||||
|
|
||||||
#include "core/ColorUtils.h"
|
#include "core/ColorUtils.h"
|
||||||
#include "core/PartitionInfo.h"
|
#include "core/PartitionInfo.h"
|
||||||
@ -29,20 +30,18 @@
|
|||||||
#include "gui/PartitionDialogHelpers.h"
|
#include "gui/PartitionDialogHelpers.h"
|
||||||
#include "gui/PartitionSizeController.h"
|
#include "gui/PartitionSizeController.h"
|
||||||
|
|
||||||
#include "ui_CreatePartitionDialog.h"
|
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
#include "partition/PartitionQuery.h"
|
||||||
|
#include "partition/FileSystem.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
// KPMcore
|
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
#include <kpmcore/fs/filesystem.h>
|
#include <kpmcore/fs/filesystem.h>
|
||||||
#include <kpmcore/fs/filesystemfactory.h>
|
#include <kpmcore/fs/filesystemfactory.h>
|
||||||
#include <kpmcore/fs/luks.h>
|
#include <kpmcore/fs/luks.h>
|
||||||
|
|
||||||
// Qt
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
@ -51,6 +50,9 @@
|
|||||||
#include <QRegularExpressionValidator>
|
#include <QRegularExpressionValidator>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
|
using CalamaresUtils::Partition::untranslatedFS;
|
||||||
|
using CalamaresUtils::Partition::userVisibleFS;
|
||||||
|
|
||||||
static QSet< FileSystem::Type > s_unmountableFS(
|
static QSet< FileSystem::Type > s_unmountableFS(
|
||||||
{
|
{
|
||||||
FileSystem::Unformatted,
|
FileSystem::Unformatted,
|
||||||
@ -112,7 +114,7 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par
|
|||||||
if ( fs->supportCreate() != FileSystem::cmdSupportNone &&
|
if ( fs->supportCreate() != FileSystem::cmdSupportNone &&
|
||||||
fs->type() != FileSystem::Extended )
|
fs->type() != FileSystem::Extended )
|
||||||
{
|
{
|
||||||
fsNames << KPMHelpers::userVisibleFS( fs ); // This is put into the combobox
|
fsNames << userVisibleFS( fs ); // This is put into the combobox
|
||||||
if ( fs->type() == defaultFSType )
|
if ( fs->type() == defaultFSType )
|
||||||
defaultFsIndex = fsCounter;
|
defaultFsIndex = fsCounter;
|
||||||
fsCounter++;
|
fsCounter++;
|
||||||
@ -279,7 +281,7 @@ CreatePartitionDialog::checkMountPointSelection()
|
|||||||
void
|
void
|
||||||
CreatePartitionDialog::initPartResizerWidget( Partition* partition )
|
CreatePartitionDialog::initPartResizerWidget( Partition* partition )
|
||||||
{
|
{
|
||||||
QColor color = KPMHelpers::isPartitionFreeSpace( partition )
|
QColor color = CalamaresUtils::Partition::isPartitionFreeSpace( partition )
|
||||||
? ColorUtils::colorForPartitionInFreeSpace( partition )
|
? ColorUtils::colorForPartitionInFreeSpace( partition )
|
||||||
: ColorUtils::colorForPartition( partition );
|
: ColorUtils::colorForPartition( partition );
|
||||||
m_partitionSizeController->init( m_device, partition, color );
|
m_partitionSizeController->init( m_device, partition, color );
|
||||||
|
@ -23,31 +23,31 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "EditExistingPartitionDialog.h"
|
#include "EditExistingPartitionDialog.h"
|
||||||
|
#include "ui_EditExistingPartitionDialog.h"
|
||||||
|
|
||||||
#include "core/ColorUtils.h"
|
#include "core/ColorUtils.h"
|
||||||
#include "core/PartitionCoreModule.h"
|
#include "core/PartitionCoreModule.h"
|
||||||
#include "core/PartitionInfo.h"
|
#include "core/PartitionInfo.h"
|
||||||
#include "core/PartUtils.h"
|
#include "core/PartUtils.h"
|
||||||
#include "core/KPMHelpers.h"
|
|
||||||
#include "gui/PartitionDialogHelpers.h"
|
#include "gui/PartitionDialogHelpers.h"
|
||||||
#include "gui/PartitionSizeController.h"
|
#include "gui/PartitionSizeController.h"
|
||||||
|
|
||||||
#include "ui_EditExistingPartitionDialog.h"
|
|
||||||
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
#include "partition/FileSystem.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
// KPMcore
|
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
#include <kpmcore/fs/filesystemfactory.h>
|
#include <kpmcore/fs/filesystemfactory.h>
|
||||||
|
|
||||||
// Qt
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
|
using CalamaresUtils::Partition::untranslatedFS;
|
||||||
|
using CalamaresUtils::Partition::userVisibleFS;
|
||||||
|
|
||||||
EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partition* partition, const QStringList& usedMountPoints, QWidget* parentWidget )
|
EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partition* partition, const QStringList& usedMountPoints, QWidget* parentWidget )
|
||||||
: QDialog( parentWidget )
|
: QDialog( parentWidget )
|
||||||
, m_ui( new Ui_EditExistingPartitionDialog )
|
, m_ui( new Ui_EditExistingPartitionDialog )
|
||||||
@ -77,7 +77,7 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit
|
|||||||
m_ui->fileSystemComboBox->setEnabled( doFormat );
|
m_ui->fileSystemComboBox->setEnabled( doFormat );
|
||||||
|
|
||||||
if ( !doFormat )
|
if ( !doFormat )
|
||||||
m_ui->fileSystemComboBox->setCurrentText( KPMHelpers::userVisibleFS( m_partition->fileSystem() ) );
|
m_ui->fileSystemComboBox->setCurrentText( userVisibleFS( m_partition->fileSystem() ) );
|
||||||
|
|
||||||
updateMountPointPicker();
|
updateMountPointPicker();
|
||||||
} );
|
} );
|
||||||
@ -93,7 +93,7 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit
|
|||||||
for ( auto fs : FileSystemFactory::map() )
|
for ( auto fs : FileSystemFactory::map() )
|
||||||
{
|
{
|
||||||
if ( fs->supportCreate() != FileSystem::cmdSupportNone && fs->type() != FileSystem::Extended )
|
if ( fs->supportCreate() != FileSystem::cmdSupportNone && fs->type() != FileSystem::Extended )
|
||||||
fsNames << KPMHelpers::userVisibleFS( fs ); // For the combo box
|
fsNames << userVisibleFS( fs ); // For the combo box
|
||||||
}
|
}
|
||||||
m_ui->fileSystemComboBox->addItems( fsNames );
|
m_ui->fileSystemComboBox->addItems( fsNames );
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit
|
|||||||
defaultFSType = FileSystem::Type::Ext4;
|
defaultFSType = FileSystem::Type::Ext4;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString thisFSNameForUser = KPMHelpers::userVisibleFS( m_partition->fileSystem() );
|
QString thisFSNameForUser = userVisibleFS( m_partition->fileSystem() );
|
||||||
if ( fsNames.contains( thisFSNameForUser ) )
|
if ( fsNames.contains( thisFSNameForUser ) )
|
||||||
m_ui->fileSystemComboBox->setCurrentText( thisFSNameForUser );
|
m_ui->fileSystemComboBox->setCurrentText( thisFSNameForUser );
|
||||||
else
|
else
|
||||||
|
@ -40,11 +40,13 @@
|
|||||||
#include "ui_PartitionPage.h"
|
#include "ui_PartitionPage.h"
|
||||||
#include "ui_CreatePartitionTableDialog.h"
|
#include "ui_CreatePartitionTableDialog.h"
|
||||||
|
|
||||||
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
#include "partition/PartitionQuery.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Retranslator.h"
|
#include "utils/Retranslator.h"
|
||||||
|
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
#include "JobQueue.h"
|
|
||||||
#include "GlobalStorage.h"
|
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
@ -132,7 +134,7 @@ PartitionPage::updateButtons()
|
|||||||
Q_ASSERT( model );
|
Q_ASSERT( model );
|
||||||
Partition* partition = model->partitionForIndex( index );
|
Partition* partition = model->partitionForIndex( index );
|
||||||
Q_ASSERT( partition );
|
Q_ASSERT( partition );
|
||||||
bool isFree = KPMHelpers::isPartitionFreeSpace( partition );
|
bool isFree = CalamaresUtils::Partition::isPartitionFreeSpace( partition );
|
||||||
bool isExtended = partition->roles().has( PartitionRole::Extended );
|
bool isExtended = partition->roles().has( PartitionRole::Extended );
|
||||||
|
|
||||||
bool isInVG = m_core->isInVG( partition );
|
bool isInVG = m_core->isInVG( partition );
|
||||||
@ -392,7 +394,7 @@ PartitionPage::onEditClicked()
|
|||||||
Partition* partition = model->partitionForIndex( index );
|
Partition* partition = model->partitionForIndex( index );
|
||||||
Q_ASSERT( partition );
|
Q_ASSERT( partition );
|
||||||
|
|
||||||
if ( KPMHelpers::isPartitionNew( partition ) )
|
if ( CalamaresUtils::Partition::isPartitionNew( partition ) )
|
||||||
updatePartitionToCreate( model->device(), partition );
|
updatePartitionToCreate( model->device(), partition );
|
||||||
else
|
else
|
||||||
editExistingPartition( model->device(), partition );
|
editExistingPartition( model->device(), partition );
|
||||||
@ -452,7 +454,7 @@ PartitionPage::onPartitionViewActivated()
|
|||||||
// but I don't expect there will be other occurences of triggering the same
|
// but I don't expect there will be other occurences of triggering the same
|
||||||
// action from multiple UI elements in this page, so it does not feel worth
|
// action from multiple UI elements in this page, so it does not feel worth
|
||||||
// the price.
|
// the price.
|
||||||
if ( KPMHelpers::isPartitionFreeSpace( partition ) )
|
if ( CalamaresUtils::Partition::isPartitionFreeSpace( partition ) )
|
||||||
m_ui->createButton->click();
|
m_ui->createButton->click();
|
||||||
else
|
else
|
||||||
m_ui->editButton->click();
|
m_ui->editButton->click();
|
||||||
|
@ -19,10 +19,12 @@
|
|||||||
#include "PartitionSplitterWidget.h"
|
#include "PartitionSplitterWidget.h"
|
||||||
|
|
||||||
#include "core/ColorUtils.h"
|
#include "core/ColorUtils.h"
|
||||||
#include "core/PartitionIterator.h"
|
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
|
|
||||||
|
#include "partition/PartitionIterator.h"
|
||||||
|
#include "partition/PartitionQuery.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
|
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
@ -33,6 +35,8 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
|
|
||||||
|
using CalamaresUtils::Partition::PartitionIterator;
|
||||||
|
|
||||||
static const int VIEW_HEIGHT = qMax( CalamaresUtils::defaultFontHeight() + 8, // wins out with big fonts
|
static const int VIEW_HEIGHT = qMax( CalamaresUtils::defaultFontHeight() + 8, // wins out with big fonts
|
||||||
int( CalamaresUtils::defaultFontHeight() * 0.6 ) + 22 ); // wins out with small fonts
|
int( CalamaresUtils::defaultFontHeight() * 0.6 ) + 22 ); // wins out with small fonts
|
||||||
static const int CORNER_RADIUS = 3;
|
static const int CORNER_RADIUS = 3;
|
||||||
@ -66,7 +70,7 @@ PartitionSplitterWidget::init( Device* dev, bool drawNestedPartitions )
|
|||||||
PartitionSplitterItem newItem = {
|
PartitionSplitterItem newItem = {
|
||||||
( *it )->partitionPath(),
|
( *it )->partitionPath(),
|
||||||
ColorUtils::colorForPartition( *it ),
|
ColorUtils::colorForPartition( *it ),
|
||||||
KPMHelpers::isPartitionFreeSpace( *it ),
|
CalamaresUtils::Partition::isPartitionFreeSpace( *it ),
|
||||||
( *it )->capacity(),
|
( *it )->capacity(),
|
||||||
PartitionSplitterItem::Normal,
|
PartitionSplitterItem::Normal,
|
||||||
{}
|
{}
|
||||||
|
@ -75,7 +75,7 @@ PartitionViewStep::PartitionViewStep( QObject* parent )
|
|||||||
|
|
||||||
m_waitingWidget = new WaitingWidget( QString() );
|
m_waitingWidget = new WaitingWidget( QString() );
|
||||||
m_widget->addWidget( m_waitingWidget );
|
m_widget->addWidget( m_waitingWidget );
|
||||||
CALAMARES_RETRANSLATE( qobject_cast< WaitingWidget* >( m_waitingWidget )->setText( tr( "Gathering system information..." ) ); )
|
CALAMARES_RETRANSLATE( m_waitingWidget->setText( tr( "Gathering system information..." ) ); )
|
||||||
|
|
||||||
m_core = new PartitionCoreModule( this ); // Unusable before init is complete!
|
m_core = new PartitionCoreModule( this ); // Unusable before init is complete!
|
||||||
// We're not done loading, but we need the configuration map first.
|
// We're not done loading, but we need the configuration map first.
|
||||||
|
@ -35,6 +35,7 @@ class ChoicePage;
|
|||||||
class PartitionPage;
|
class PartitionPage;
|
||||||
class PartitionCoreModule;
|
class PartitionCoreModule;
|
||||||
class QStackedWidget;
|
class QStackedWidget;
|
||||||
|
class WaitingWidget;
|
||||||
|
|
||||||
template<typename T> class QFutureWatcher;
|
template<typename T> class QFutureWatcher;
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ private:
|
|||||||
ChoicePage* m_choicePage;
|
ChoicePage* m_choicePage;
|
||||||
PartitionPage* m_manualPartitionPage;
|
PartitionPage* m_manualPartitionPage;
|
||||||
|
|
||||||
QWidget* m_waitingWidget;
|
WaitingWidget* m_waitingWidget;
|
||||||
QFutureWatcher<void>* m_future;
|
QFutureWatcher<void>* m_future;
|
||||||
|
|
||||||
QSet< PartitionActions::Choices::SwapChoice > m_swapChoices;
|
QSet< PartitionActions::Choices::SwapChoice > m_swapChoices;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -22,7 +22,6 @@
|
|||||||
#include "ui_ReplaceWidget.h"
|
#include "ui_ReplaceWidget.h"
|
||||||
|
|
||||||
#include "core/DeviceModel.h"
|
#include "core/DeviceModel.h"
|
||||||
#include "core/KPMHelpers.h"
|
|
||||||
#include "core/PartitionCoreModule.h"
|
#include "core/PartitionCoreModule.h"
|
||||||
#include "core/PartitionActions.h"
|
#include "core/PartitionActions.h"
|
||||||
#include "core/PartitionInfo.h"
|
#include "core/PartitionInfo.h"
|
||||||
@ -30,6 +29,7 @@
|
|||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
#include "partition/FileSystem.h"
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
#include "utils/Retranslator.h"
|
#include "utils/Retranslator.h"
|
||||||
|
|
||||||
@ -38,6 +38,9 @@
|
|||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
|
||||||
|
using CalamaresUtils::Partition::untranslatedFS;
|
||||||
|
using CalamaresUtils::Partition::userVisibleFS;
|
||||||
|
|
||||||
ReplaceWidget::ReplaceWidget( PartitionCoreModule* core,
|
ReplaceWidget::ReplaceWidget( PartitionCoreModule* core,
|
||||||
QComboBox* devicesComboBox,
|
QComboBox* devicesComboBox,
|
||||||
QWidget* parent )
|
QWidget* parent )
|
||||||
@ -193,7 +196,7 @@ ReplaceWidget::onPartitionSelected()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString fsNameForUser = KPMHelpers::userVisibleFS( partition->fileSystem() );
|
QString fsNameForUser = userVisibleFS( partition->fileSystem() );
|
||||||
QString prettyName = tr( "Data partition (%1)" ).arg( fsNameForUser );
|
QString prettyName = tr( "Data partition (%1)" ).arg( fsNameForUser );
|
||||||
for ( const QString& line : osproberLines )
|
for ( const QString& line : osproberLines )
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,9 @@
|
|||||||
#include "ClearMountsJob.h"
|
#include "ClearMountsJob.h"
|
||||||
|
|
||||||
#include "core/PartitionInfo.h"
|
#include "core/PartitionInfo.h"
|
||||||
#include "core/PartitionIterator.h"
|
|
||||||
|
#include "partition/Sync.h"
|
||||||
|
#include "partition/PartitionIterator.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
@ -33,6 +35,7 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
using CalamaresUtils::Partition::PartitionIterator;
|
||||||
|
|
||||||
ClearMountsJob::ClearMountsJob( Device* device )
|
ClearMountsJob::ClearMountsJob( Device* device )
|
||||||
: Calamares::Job()
|
: Calamares::Job()
|
||||||
@ -57,25 +60,47 @@ ClearMountsJob::prettyStatusMessage() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QStringList
|
||||||
|
getPartitionsForDevice( const QString& deviceName )
|
||||||
|
{
|
||||||
|
QStringList partitions;
|
||||||
|
|
||||||
|
QFile dev_partitions( "/proc/partitions" );
|
||||||
|
if ( dev_partitions.open( QFile::ReadOnly ) )
|
||||||
|
{
|
||||||
|
cDebug() << "Reading from" << dev_partitions.fileName();
|
||||||
|
QTextStream in( &dev_partitions );
|
||||||
|
(void) in.readLine(); // That's the header line, skip it
|
||||||
|
while ( !in.atEnd() )
|
||||||
|
{
|
||||||
|
// The fourth column (index from 0, so index 3) is the name of the device;
|
||||||
|
// keep it if it is followed by something.
|
||||||
|
QStringList columns = in.readLine().split( ' ', QString::SkipEmptyParts );
|
||||||
|
if ( ( columns.count() >= 4 ) && ( columns[3].startsWith( deviceName ) ) && ( columns[3] != deviceName ) )
|
||||||
|
{
|
||||||
|
partitions.append( columns[3] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cDebug() << "Could not open" << dev_partitions.fileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return partitions;
|
||||||
|
}
|
||||||
|
|
||||||
Calamares::JobResult
|
Calamares::JobResult
|
||||||
ClearMountsJob::exec()
|
ClearMountsJob::exec()
|
||||||
{
|
{
|
||||||
QStringList goodNews;
|
CalamaresUtils::Partition::Syncer s;
|
||||||
|
|
||||||
QString deviceName = m_device->deviceNode().split( '/' ).last();
|
QString deviceName = m_device->deviceNode().split( '/' ).last();
|
||||||
|
|
||||||
|
QStringList goodNews;
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProgram( "sh" );
|
|
||||||
process.setArguments( {
|
|
||||||
"-c",
|
|
||||||
QString( "echo $(awk '{print $4}' /proc/partitions | sed -e '/name/d' -e '/^$/d' -e '/[1-9]/!d' | grep %1)" )
|
|
||||||
.arg( deviceName )
|
|
||||||
} );
|
|
||||||
process.start();
|
|
||||||
process.waitForFinished();
|
|
||||||
|
|
||||||
const QString partitions = process.readAllStandardOutput();
|
QStringList partitionsList = getPartitionsForDevice( deviceName );
|
||||||
const QStringList partitionsList = partitions.simplified().split( ' ' );
|
|
||||||
|
|
||||||
// Build a list of partitions of type 82 (Linux swap / Solaris).
|
// Build a list of partitions of type 82 (Linux swap / Solaris).
|
||||||
// We then need to clear them just in case they contain something resumable from a
|
// We then need to clear them just in case they contain something resumable from a
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#ifndef CLEARMOUNTSJOB_H
|
#ifndef CLEARMOUNTSJOB_H
|
||||||
#define CLEARMOUNTSJOB_H
|
#define CLEARMOUNTSJOB_H
|
||||||
|
|
||||||
#include <Job.h>
|
#include "Job.h"
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#ifndef CLEARTEMPMOUNTSJOB_H
|
#ifndef CLEARTEMPMOUNTSJOB_H
|
||||||
#define CLEARTEMPMOUNTSJOB_H
|
#define CLEARTEMPMOUNTSJOB_H
|
||||||
|
|
||||||
#include <Job.h>
|
#include "Job.h"
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
|
@ -18,14 +18,12 @@
|
|||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "jobs/CreatePartitionJob.h"
|
#include "CreatePartitionJob.h"
|
||||||
|
|
||||||
#include "core/KPMHelpers.h"
|
|
||||||
|
|
||||||
|
#include "partition/FileSystem.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Units.h"
|
#include "utils/Units.h"
|
||||||
|
|
||||||
// KPMcore
|
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <kpmcore/core/lvmdevice.h>
|
#include <kpmcore/core/lvmdevice.h>
|
||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
@ -34,8 +32,8 @@
|
|||||||
#include <kpmcore/ops/newoperation.h>
|
#include <kpmcore/ops/newoperation.h>
|
||||||
#include <kpmcore/util/report.h>
|
#include <kpmcore/util/report.h>
|
||||||
|
|
||||||
using KPMHelpers::untranslatedFS;
|
using CalamaresUtils::Partition::untranslatedFS;
|
||||||
using KPMHelpers::userVisibleFS;
|
using CalamaresUtils::Partition::userVisibleFS;
|
||||||
|
|
||||||
CreatePartitionJob::CreatePartitionJob( Device* device, Partition* partition )
|
CreatePartitionJob::CreatePartitionJob( Device* device, Partition* partition )
|
||||||
: PartitionJob( partition )
|
: PartitionJob( partition )
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#ifndef CREATEPARTITIONJOB_H
|
#ifndef CREATEPARTITIONJOB_H
|
||||||
#define CREATEPARTITIONJOB_H
|
#define CREATEPARTITIONJOB_H
|
||||||
|
|
||||||
#include <jobs/PartitionJob.h>
|
#include "PartitionJob.h"
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class Partition;
|
class Partition;
|
||||||
|
@ -20,21 +20,22 @@
|
|||||||
|
|
||||||
#include "jobs/CreatePartitionTableJob.h"
|
#include "jobs/CreatePartitionTableJob.h"
|
||||||
|
|
||||||
#include "core/PartitionIterator.h"
|
#include "partition/PartitionIterator.h"
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
#include <core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
#include <core/partitiontable.h>
|
#include <kpmcore/core/partitiontable.h>
|
||||||
#include <fs/filesystem.h>
|
#include <kpmcore/fs/filesystem.h>
|
||||||
#include <ops/createpartitiontableoperation.h>
|
#include <kpmcore/ops/createpartitiontableoperation.h>
|
||||||
#include <util/report.h>
|
#include <kpmcore/util/report.h>
|
||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
|
using CalamaresUtils::Partition::PartitionIterator;
|
||||||
|
|
||||||
CreatePartitionTableJob::CreatePartitionTableJob( Device* device, PartitionTable::TableType type )
|
CreatePartitionTableJob::CreatePartitionTableJob( Device* device, PartitionTable::TableType type )
|
||||||
: m_device( device )
|
: m_device( device )
|
||||||
, m_type( type )
|
, m_type( type )
|
||||||
@ -99,7 +100,7 @@ CreatePartitionTableJob::exec()
|
|||||||
cDebug() << "lsblk:\n" << lsblk.readAllStandardOutput();
|
cDebug() << "lsblk:\n" << lsblk.readAllStandardOutput();
|
||||||
|
|
||||||
QProcess mount;
|
QProcess mount;
|
||||||
mount.setProgram( "mount" );
|
mount.setProgram( "mount" ); // Debug output only, not mounting something
|
||||||
mount.setProcessChannelMode( QProcess::MergedChannels );
|
mount.setProcessChannelMode( QProcess::MergedChannels );
|
||||||
mount.start();
|
mount.start();
|
||||||
mount.waitForFinished();
|
mount.waitForFinished();
|
||||||
|
@ -20,7 +20,8 @@
|
|||||||
#ifndef CREATEPARTITIONTABLEJOB_H
|
#ifndef CREATEPARTITIONTABLEJOB_H
|
||||||
#define CREATEPARTITIONTABLEJOB_H
|
#define CREATEPARTITIONTABLEJOB_H
|
||||||
|
|
||||||
#include <Job.h>
|
#include "Job.h"
|
||||||
|
#include "partition/KPMManager.h"
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
#include <kpmcore/core/partitiontable.h>
|
#include <kpmcore/core/partitiontable.h>
|
||||||
@ -50,6 +51,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CalamaresUtils::Partition::KPMManager m_kpmcore;
|
||||||
Device* m_device;
|
Device* m_device;
|
||||||
PartitionTable::TableType m_type;
|
PartitionTable::TableType m_type;
|
||||||
PartitionTable* createTable();
|
PartitionTable* createTable();
|
||||||
|
@ -19,12 +19,13 @@
|
|||||||
#ifndef CREATEVOLUMEGROUPJOB_H
|
#ifndef CREATEVOLUMEGROUPJOB_H
|
||||||
#define CREATEVOLUMEGROUPJOB_H
|
#define CREATEVOLUMEGROUPJOB_H
|
||||||
|
|
||||||
#include <Job.h>
|
#include "Job.h"
|
||||||
|
#include "partition/KPMManager.h"
|
||||||
#include <kpmcore/core/partition.h>
|
|
||||||
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
class Partition;
|
||||||
|
|
||||||
class CreateVolumeGroupJob : public Calamares::Job
|
class CreateVolumeGroupJob : public Calamares::Job
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -40,6 +41,7 @@ public:
|
|||||||
void undoPreview();
|
void undoPreview();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CalamaresUtils::Partition::KPMManager m_kpmcore;
|
||||||
QString m_vgName;
|
QString m_vgName;
|
||||||
QVector< const Partition* > m_pvList;
|
QVector< const Partition* > m_pvList;
|
||||||
qint32 m_peSize;
|
qint32 m_peSize;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#define DEACTIVATEVOLUMEGROUPJOB_H
|
#define DEACTIVATEVOLUMEGROUPJOB_H
|
||||||
|
|
||||||
#include "Job.h"
|
#include "Job.h"
|
||||||
|
#include "partition/KPMManager.h"
|
||||||
|
|
||||||
class LvmDevice;
|
class LvmDevice;
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ public:
|
|||||||
Calamares::JobResult exec() override;
|
Calamares::JobResult exec() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CalamaresUtils::Partition::KPMManager m_kpmcore;
|
||||||
LvmDevice* m_device;
|
LvmDevice* m_device;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,12 +21,12 @@
|
|||||||
#include "jobs/DeletePartitionJob.h"
|
#include "jobs/DeletePartitionJob.h"
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
#include <core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
#include <core/partitiontable.h>
|
#include <kpmcore/core/partitiontable.h>
|
||||||
#include <fs/filesystem.h>
|
#include <kpmcore/fs/filesystem.h>
|
||||||
#include <ops/deleteoperation.h>
|
#include <kpmcore/ops/deleteoperation.h>
|
||||||
#include <util/report.h>
|
#include <kpmcore/util/report.h>
|
||||||
|
|
||||||
DeletePartitionJob::DeletePartitionJob( Device* device, Partition* partition )
|
DeletePartitionJob::DeletePartitionJob( Device* device, Partition* partition )
|
||||||
: PartitionJob( partition )
|
: PartitionJob( partition )
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#ifndef DELETEPARTITIONJOB_H
|
#ifndef DELETEPARTITIONJOB_H
|
||||||
#define DELETEPARTITIONJOB_H
|
#define DELETEPARTITIONJOB_H
|
||||||
|
|
||||||
#include <jobs/PartitionJob.h>
|
#include "PartitionJob.h"
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class Partition;
|
class Partition;
|
||||||
|
@ -18,31 +18,31 @@
|
|||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "jobs/FillGlobalStorageJob.h"
|
#include "FillGlobalStorageJob.h"
|
||||||
|
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
#include "core/PartitionInfo.h"
|
#include "core/PartitionInfo.h"
|
||||||
#include "core/PartitionIterator.h"
|
|
||||||
|
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
#include "partition/FileSystem.h"
|
||||||
|
#include "partition/PartitionIterator.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
// KPMcore
|
#include <kpmcore/core/device.h>
|
||||||
#include <core/device.h>
|
#include <kpmcore/core/partition.h>
|
||||||
#include <core/partition.h>
|
#include <kpmcore/fs/filesystem.h>
|
||||||
#include <fs/filesystem.h>
|
#include <kpmcore/fs/luks.h>
|
||||||
#include <fs/luks.h>
|
|
||||||
|
|
||||||
// Qt
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
using KPMHelpers::untranslatedFS;
|
using CalamaresUtils::Partition::untranslatedFS;
|
||||||
using KPMHelpers::userVisibleFS;
|
using CalamaresUtils::Partition::userVisibleFS;
|
||||||
|
using CalamaresUtils::Partition::PartitionIterator;
|
||||||
|
|
||||||
typedef QHash< QString, QString > UuidForPartitionHash;
|
typedef QHash< QString, QString > UuidForPartitionHash;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#ifndef FILLGLOBALSTORAGEJOB_H
|
#ifndef FILLGLOBALSTORAGEJOB_H
|
||||||
#define FILLGLOBALSTORAGEJOB_H
|
#define FILLGLOBALSTORAGEJOB_H
|
||||||
|
|
||||||
#include <Job.h>
|
#include "Job.h"
|
||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
* Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2020, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -17,22 +18,20 @@
|
|||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "jobs/FormatPartitionJob.h"
|
#include "FormatPartitionJob.h"
|
||||||
|
|
||||||
#include "core/KPMHelpers.h"
|
|
||||||
|
|
||||||
|
#include "partition/FileSystem.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
// KPMcore
|
#include <kpmcore/core/device.h>
|
||||||
#include <core/device.h>
|
#include <kpmcore/core/partition.h>
|
||||||
#include <core/partition.h>
|
#include <kpmcore/core/partitiontable.h>
|
||||||
#include <core/partitiontable.h>
|
#include <kpmcore/fs/filesystem.h>
|
||||||
#include <fs/filesystem.h>
|
#include <kpmcore/ops/createfilesystemoperation.h>
|
||||||
#include <ops/createfilesystemoperation.h>
|
#include <kpmcore/util/report.h>
|
||||||
#include <util/report.h>
|
|
||||||
|
|
||||||
using KPMHelpers::untranslatedFS;
|
using CalamaresUtils::Partition::untranslatedFS;
|
||||||
using KPMHelpers::userVisibleFS;
|
using CalamaresUtils::Partition::userVisibleFS;
|
||||||
|
|
||||||
FormatPartitionJob::FormatPartitionJob( Device* device, Partition* partition )
|
FormatPartitionJob::FormatPartitionJob( Device* device, Partition* partition )
|
||||||
: PartitionJob( partition )
|
: PartitionJob( partition )
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#ifndef FORMATPARTITIONJOB_H
|
#ifndef FORMATPARTITIONJOB_H
|
||||||
#define FORMATPARTITIONJOB_H
|
#define FORMATPARTITIONJOB_H
|
||||||
|
|
||||||
#include <jobs/PartitionJob.h>
|
#include "PartitionJob.h"
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class Partition;
|
class Partition;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <jobs/PartitionJob.h>
|
#include "PartitionJob.h"
|
||||||
|
|
||||||
PartitionJob::PartitionJob( Partition* partition )
|
PartitionJob::PartitionJob( Partition* partition )
|
||||||
: m_partition( partition )
|
: m_partition( partition )
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -19,12 +20,13 @@
|
|||||||
#ifndef PARTITIONJOB_H
|
#ifndef PARTITIONJOB_H
|
||||||
#define PARTITIONJOB_H
|
#define PARTITIONJOB_H
|
||||||
|
|
||||||
#include <Job.h>
|
#include "Job.h"
|
||||||
|
#include "partition/KPMManager.h"
|
||||||
|
|
||||||
class Partition;
|
class Partition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for jobs which affect a partition.
|
* Base class for jobs which affect a partition and which use KPMCore.
|
||||||
*/
|
*/
|
||||||
class PartitionJob : public Calamares::Job
|
class PartitionJob : public Calamares::Job
|
||||||
{
|
{
|
||||||
@ -46,6 +48,7 @@ public slots:
|
|||||||
void iprogress( int percent );
|
void iprogress( int percent );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
CalamaresUtils::Partition::KPMManager m_kpmcore;
|
||||||
Partition* m_partition;
|
Partition* m_partition;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
#ifndef REMOVEVOLUMEGROUPJOB_H
|
#ifndef REMOVEVOLUMEGROUPJOB_H
|
||||||
#define REMOVEVOLUMEGROUPJOB_H
|
#define REMOVEVOLUMEGROUPJOB_H
|
||||||
|
|
||||||
#include <Job.h>
|
#include "Job.h"
|
||||||
|
#include "partition/KPMManager.h"
|
||||||
|
|
||||||
class LvmDevice;
|
class LvmDevice;
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ public:
|
|||||||
Calamares::JobResult exec() override;
|
Calamares::JobResult exec() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CalamaresUtils::Partition::KPMManager m_kpmcore;
|
||||||
LvmDevice* m_device;
|
LvmDevice* m_device;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@
|
|||||||
#include "utils/Units.h"
|
#include "utils/Units.h"
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
#include <core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <ops/resizeoperation.h>
|
#include <kpmcore/ops/resizeoperation.h>
|
||||||
#include <util/report.h>
|
#include <kpmcore/util/report.h>
|
||||||
|
|
||||||
using CalamaresUtils::BytesToMiB;
|
using CalamaresUtils::BytesToMiB;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#ifndef RESIZEPARTITIONJOB_H
|
#ifndef RESIZEPARTITIONJOB_H
|
||||||
#define RESIZEPARTITIONJOB_H
|
#define RESIZEPARTITIONJOB_H
|
||||||
|
|
||||||
#include <jobs/PartitionJob.h>
|
#include "PartitionJob.h"
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class Partition;
|
class Partition;
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
#ifndef RESIZEVOLUMEGROUPJOB_H
|
#ifndef RESIZEVOLUMEGROUPJOB_H
|
||||||
#define RESIZEVOLUMEGROUPJOB_H
|
#define RESIZEVOLUMEGROUPJOB_H
|
||||||
|
|
||||||
#include <Job.h>
|
#include "Job.h"
|
||||||
|
#include "partition/KPMManager.h"
|
||||||
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ private:
|
|||||||
QString targetPartitions() const;
|
QString targetPartitions() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CalamaresUtils::Partition::KPMManager m_kpmcore;
|
||||||
LvmDevice* m_device;
|
LvmDevice* m_device;
|
||||||
QVector< const Partition* > m_partitionList;
|
QVector< const Partition* > m_partitionList;
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2020, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Based on the SetPartFlagsJob class from KDE Partition Manager,
|
* Based on the SetPartFlagsJob class from KDE Partition Manager,
|
||||||
* Copyright 2008, 2010, Volker Lanz <vl@fidra.de>
|
* Copyright 2008, 2010, Volker Lanz <vl@fidra.de>
|
||||||
@ -21,21 +22,19 @@
|
|||||||
|
|
||||||
#include "SetPartitionFlagsJob.h"
|
#include "SetPartitionFlagsJob.h"
|
||||||
|
|
||||||
#include "core/KPMHelpers.h"
|
#include "partition/FileSystem.h"
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Units.h"
|
#include "utils/Units.h"
|
||||||
|
|
||||||
// KPMcore
|
#include <kpmcore/core/device.h>
|
||||||
#include <core/device.h>
|
#include <kpmcore/core/partition.h>
|
||||||
#include <core/partition.h>
|
#include <kpmcore/fs/filesystem.h>
|
||||||
#include <fs/filesystem.h>
|
#include <kpmcore/ops/setpartflagsoperation.h>
|
||||||
#include <ops/setpartflagsoperation.h>
|
#include <kpmcore/util/report.h>
|
||||||
#include <util/report.h>
|
|
||||||
|
|
||||||
using CalamaresUtils::BytesToMiB;
|
using CalamaresUtils::BytesToMiB;
|
||||||
using KPMHelpers::untranslatedFS;
|
using CalamaresUtils::Partition::untranslatedFS;
|
||||||
using KPMHelpers::userVisibleFS;
|
using CalamaresUtils::Partition::userVisibleFS;
|
||||||
|
|
||||||
SetPartFlagsJob::SetPartFlagsJob( Device* device,
|
SetPartFlagsJob::SetPartFlagsJob( Device* device,
|
||||||
Partition* partition,
|
Partition* partition,
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#ifndef SETPARTITIONFLAGSJOB_H
|
#ifndef SETPARTITIONFLAGSJOB_H
|
||||||
#define SETPARTITIONFLAGSJOB_H
|
#define SETPARTITIONFLAGSJOB_H
|
||||||
|
|
||||||
#include <jobs/PartitionJob.h>
|
#include "PartitionJob.h"
|
||||||
|
|
||||||
#include <kpmcore/core/partitiontable.h>
|
#include <kpmcore/core/partitiontable.h>
|
||||||
|
|
||||||
|
@ -26,7 +26,16 @@ calamares_add_test(
|
|||||||
SOURCES ${partitionjobtests_SRCS}
|
SOURCES ${partitionjobtests_SRCS}
|
||||||
LIBRARIES
|
LIBRARIES
|
||||||
kpmcore
|
kpmcore
|
||||||
|
DEFINITIONS ${_partition_defs}
|
||||||
)
|
)
|
||||||
if( TARGET partitionjobtests )
|
|
||||||
target_compile_definitions( partitionjobtests PRIVATE ${_partition_defs} )
|
calamares_add_test(
|
||||||
endif()
|
clearmountsjobtests
|
||||||
|
SOURCES
|
||||||
|
${PartitionModule_SOURCE_DIR}/jobs/ClearMountsJob.cpp
|
||||||
|
ClearMountsJobTests.cpp
|
||||||
|
LIBRARIES
|
||||||
|
kpmcore
|
||||||
|
DEFINITIONS ${_partition_defs}
|
||||||
|
)
|
||||||
|
|
||||||
|
66
src/modules/partition/tests/ClearMountsJobTests.cpp
Normal file
66
src/modules/partition/tests/ClearMountsJobTests.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ClearMountsJobTests.h"
|
||||||
|
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
|
QTEST_GUILESS_MAIN( ClearMountsJobTests )
|
||||||
|
|
||||||
|
|
||||||
|
/* Not exactly public API */
|
||||||
|
QStringList
|
||||||
|
getPartitionsForDevice( const QString& deviceName );
|
||||||
|
|
||||||
|
QStringList
|
||||||
|
getPartitionsForDevice_other(const QString& deviceName)
|
||||||
|
{
|
||||||
|
QProcess process;
|
||||||
|
process.setProgram( "sh" );
|
||||||
|
process.setArguments( {
|
||||||
|
"-c",
|
||||||
|
QString( "echo $(awk '{print $4}' /proc/partitions | sed -e '/name/d' -e '/^$/d' -e '/[1-9]/!d' | grep %1)" )
|
||||||
|
.arg( deviceName )
|
||||||
|
} );
|
||||||
|
process.start();
|
||||||
|
process.waitForFinished();
|
||||||
|
|
||||||
|
const QString partitions = process.readAllStandardOutput();
|
||||||
|
const QStringList partitionsList = partitions.simplified().split( ' ' );
|
||||||
|
|
||||||
|
return partitionsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ClearMountsJobTests::ClearMountsJobTests()
|
||||||
|
{
|
||||||
|
Logger::setupLogLevel(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearMountsJobTests::testFindPartitions()
|
||||||
|
{
|
||||||
|
QStringList partitions = getPartitionsForDevice( "sda" );
|
||||||
|
QStringList other_part = getPartitionsForDevice_other( "sda" );
|
||||||
|
|
||||||
|
cDebug() << "Initial implementation:" << Logger::DebugList( partitions );
|
||||||
|
cDebug() << "Other implementation:" << Logger::DebugList( other_part );
|
||||||
|
|
||||||
|
QCOMPARE( partitions, other_part );
|
||||||
|
}
|
34
src/modules/partition/tests/ClearMountsJobTests.h
Normal file
34
src/modules/partition/tests/ClearMountsJobTests.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CLEARMOUNTSJOBTESTS_H
|
||||||
|
#define CLEARMOUNTSJOBTESTS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class ClearMountsJobTests : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ClearMountsJobTests();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void testFindPartitions();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -19,16 +19,18 @@
|
|||||||
|
|
||||||
#include <PartitionJobTests.h>
|
#include <PartitionJobTests.h>
|
||||||
|
|
||||||
|
#include "partition/KPMManager.h"
|
||||||
|
#include "partition/PartitionQuery.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
#include "utils/Units.h"
|
#include "utils/Units.h"
|
||||||
|
|
||||||
|
#include <core/KPMHelpers.h>
|
||||||
#include <jobs/CreatePartitionJob.h>
|
#include <jobs/CreatePartitionJob.h>
|
||||||
#include <jobs/CreatePartitionTableJob.h>
|
#include <jobs/CreatePartitionTableJob.h>
|
||||||
#include <jobs/ResizePartitionJob.h>
|
#include <jobs/ResizePartitionJob.h>
|
||||||
#include <core/KPMHelpers.h>
|
|
||||||
|
|
||||||
// CalaPM
|
// CalaPM
|
||||||
#include <backend/corebackend.h>
|
#include <backend/corebackend.h>
|
||||||
#include <backend/corebackendmanager.h>
|
|
||||||
#include <fs/filesystemfactory.h>
|
#include <fs/filesystemfactory.h>
|
||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
@ -40,6 +42,7 @@ QTEST_GUILESS_MAIN( PartitionJobTests )
|
|||||||
|
|
||||||
using namespace Calamares;
|
using namespace Calamares;
|
||||||
using CalamaresUtils::operator""_MiB;
|
using CalamaresUtils::operator""_MiB;
|
||||||
|
using CalamaresUtils::Partition::isPartitionFreeSpace;
|
||||||
|
|
||||||
class PartitionMounter
|
class PartitionMounter
|
||||||
{
|
{
|
||||||
@ -56,15 +59,14 @@ public:
|
|||||||
~PartitionMounter()
|
~PartitionMounter()
|
||||||
{
|
{
|
||||||
if ( !m_mounted )
|
if ( !m_mounted )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
int ret = QProcess::execute( "umount", QStringList() << m_mountPointDir.path() );
|
int ret = QProcess::execute( "umount", QStringList() << m_mountPointDir.path() );
|
||||||
QCOMPARE( ret, 0 );
|
QCOMPARE( ret, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString mountPoint() const
|
QString mountPoint() const { return m_mounted ? m_mountPointDir.path() : QString(); }
|
||||||
{
|
|
||||||
return m_mounted ? m_mountPointDir.path() : QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_devicePath;
|
QString m_devicePath;
|
||||||
@ -77,9 +79,9 @@ static QByteArray
|
|||||||
generateTestData( qint64 size )
|
generateTestData( qint64 size )
|
||||||
{
|
{
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
ba.resize( static_cast<int>( size ) );
|
ba.resize( static_cast< int >( size ) );
|
||||||
// Fill the array explicitly to keep Valgrind happy
|
// Fill the array explicitly to keep Valgrind happy
|
||||||
for ( auto it = ba.data() ; it < ba.data() + size ; ++it )
|
for ( auto it = ba.data(); it < ba.data() + size; ++it )
|
||||||
{
|
{
|
||||||
*it = char( rand() & 0xff );
|
*it = char( rand() & 0xff );
|
||||||
}
|
}
|
||||||
@ -114,9 +116,11 @@ writeFile( const QString& path, const QByteArray data )
|
|||||||
static Partition*
|
static Partition*
|
||||||
firstFreePartition( PartitionNode* parent )
|
firstFreePartition( PartitionNode* parent )
|
||||||
{
|
{
|
||||||
for( auto child : parent->children() )
|
for ( auto child : parent->children() )
|
||||||
if ( KPMHelpers::isPartitionFreeSpace( child ) )
|
if ( isPartitionFreeSpace( child ) )
|
||||||
|
{
|
||||||
return child;
|
return child;
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +147,9 @@ QueueRunner::run()
|
|||||||
m_queue->start();
|
m_queue->start();
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
while ( !m_finished )
|
while ( !m_finished )
|
||||||
|
{
|
||||||
loop.processEvents();
|
loop.processEvents();
|
||||||
|
}
|
||||||
return m_success;
|
return m_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,10 +167,13 @@ QueueRunner::onFailed( const QString& message, const QString& details )
|
|||||||
QFAIL( qPrintable( msg ) );
|
QFAIL( qPrintable( msg ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CalamaresUtils::Partition::KPMManager* kpmcore = nullptr;
|
||||||
|
|
||||||
//- PartitionJobTests ------------------------------------------------------------------
|
//- PartitionJobTests ------------------------------------------------------------------
|
||||||
PartitionJobTests::PartitionJobTests()
|
PartitionJobTests::PartitionJobTests()
|
||||||
: m_runner( &m_queue )
|
: m_runner( &m_queue )
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionJobTests::initTestCase()
|
PartitionJobTests::initTestCase()
|
||||||
@ -173,21 +182,27 @@ PartitionJobTests::initTestCase()
|
|||||||
if ( devicePath.isEmpty() )
|
if ( devicePath.isEmpty() )
|
||||||
{
|
{
|
||||||
// The 0 is to keep the macro parameters happy
|
// The 0 is to keep the macro parameters happy
|
||||||
QSKIP( "Skipping test, CALAMARES_TEST_DISK is not set. It should point to a disk which can be safely formatted", 0 );
|
QSKIP( "Skipping test, CALAMARES_TEST_DISK is not set. It should point to a disk which can be safely formatted",
|
||||||
|
0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY( KPMHelpers::initKPMcore() );
|
kpmcore = new CalamaresUtils::Partition::KPMManager();
|
||||||
FileSystemFactory::init();
|
FileSystemFactory::init();
|
||||||
|
|
||||||
refreshDevice();
|
refreshDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionJobTests::cleanupTestCase()
|
||||||
|
{
|
||||||
|
delete kpmcore;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionJobTests::refreshDevice()
|
PartitionJobTests::refreshDevice()
|
||||||
{
|
{
|
||||||
QString devicePath = qgetenv( "CALAMARES_TEST_DISK" );
|
QString devicePath = qgetenv( "CALAMARES_TEST_DISK" );
|
||||||
CoreBackend* backend = CoreBackendManager::self()->backend();
|
m_device.reset( kpmcore->backend()->scanDevice( devicePath ) );
|
||||||
m_device.reset( backend->scanDevice( devicePath ) );
|
|
||||||
QVERIFY( !m_device.isNull() );
|
QVERIFY( !m_device.isNull() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +221,7 @@ PartitionJobTests::testPartitionTable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionJobTests::queuePartitionTableCreation( PartitionTable::TableType type)
|
PartitionJobTests::queuePartitionTableCreation( PartitionTable::TableType type )
|
||||||
{
|
{
|
||||||
auto job = new CreatePartitionTableJob( m_device.data(), type );
|
auto job = new CreatePartitionTableJob( m_device.data(), type );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
@ -214,7 +229,10 @@ PartitionJobTests::queuePartitionTableCreation( PartitionTable::TableType type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CreatePartitionJob*
|
CreatePartitionJob*
|
||||||
PartitionJobTests::newCreatePartitionJob( Partition* freeSpacePartition, PartitionRole role, FileSystem::Type type, qint64 size )
|
PartitionJobTests::newCreatePartitionJob( Partition* freeSpacePartition,
|
||||||
|
PartitionRole role,
|
||||||
|
FileSystem::Type type,
|
||||||
|
qint64 size )
|
||||||
{
|
{
|
||||||
Q_ASSERT( freeSpacePartition );
|
Q_ASSERT( freeSpacePartition );
|
||||||
|
|
||||||
@ -222,25 +240,27 @@ PartitionJobTests::newCreatePartitionJob( Partition* freeSpacePartition, Partiti
|
|||||||
qint64 lastSector;
|
qint64 lastSector;
|
||||||
|
|
||||||
if ( size > 0 )
|
if ( size > 0 )
|
||||||
|
{
|
||||||
lastSector = firstSector + size / m_device->logicalSize();
|
lastSector = firstSector + size / m_device->logicalSize();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
lastSector = freeSpacePartition->lastSector();
|
lastSector = freeSpacePartition->lastSector();
|
||||||
FileSystem* fs = FileSystemFactory::create( type, firstSector, lastSector
|
}
|
||||||
,m_device->logicalSize()
|
FileSystem* fs = FileSystemFactory::create( type, firstSector, lastSector, m_device->logicalSize() );
|
||||||
);
|
|
||||||
|
|
||||||
Partition* partition = new Partition(
|
Partition* partition = new Partition( freeSpacePartition->parent(),
|
||||||
freeSpacePartition->parent(),
|
|
||||||
*m_device,
|
*m_device,
|
||||||
role,
|
role,
|
||||||
fs, firstSector, lastSector,
|
fs,
|
||||||
|
firstSector,
|
||||||
|
lastSector,
|
||||||
QString() /* path */,
|
QString() /* path */,
|
||||||
KPM_PARTITION_FLAG(None) /* availableFlags */,
|
KPM_PARTITION_FLAG( None ) /* availableFlags */,
|
||||||
QString() /* mountPoint */,
|
QString() /* mountPoint */,
|
||||||
false /* mounted */,
|
false /* mounted */,
|
||||||
KPM_PARTITION_FLAG(None) /* activeFlags */,
|
KPM_PARTITION_FLAG( None ) /* activeFlags */,
|
||||||
KPM_PARTITION_STATE(New)
|
KPM_PARTITION_STATE( New ) );
|
||||||
);
|
|
||||||
return new CreatePartitionJob( m_device.data(), partition );
|
return new CreatePartitionJob( m_device.data(), partition );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +273,7 @@ PartitionJobTests::testCreatePartition()
|
|||||||
|
|
||||||
freePartition = firstFreePartition( m_device->partitionTable() );
|
freePartition = firstFreePartition( m_device->partitionTable() );
|
||||||
QVERIFY( freePartition );
|
QVERIFY( freePartition );
|
||||||
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Ext4, 1_MiB);
|
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Ext4, 1_MiB );
|
||||||
Partition* partition1 = job->partition();
|
Partition* partition1 = job->partition();
|
||||||
QVERIFY( partition1 );
|
QVERIFY( partition1 );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
@ -261,7 +281,7 @@ PartitionJobTests::testCreatePartition()
|
|||||||
|
|
||||||
freePartition = firstFreePartition( m_device->partitionTable() );
|
freePartition = firstFreePartition( m_device->partitionTable() );
|
||||||
QVERIFY( freePartition );
|
QVERIFY( freePartition );
|
||||||
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::LinuxSwap, 1_MiB);
|
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::LinuxSwap, 1_MiB );
|
||||||
Partition* partition2 = job->partition();
|
Partition* partition2 = job->partition();
|
||||||
QVERIFY( partition2 );
|
QVERIFY( partition2 );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
@ -269,7 +289,7 @@ PartitionJobTests::testCreatePartition()
|
|||||||
|
|
||||||
freePartition = firstFreePartition( m_device->partitionTable() );
|
freePartition = firstFreePartition( m_device->partitionTable() );
|
||||||
QVERIFY( freePartition );
|
QVERIFY( freePartition );
|
||||||
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Fat32, 1_MiB);
|
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Fat32, 1_MiB );
|
||||||
Partition* partition3 = job->partition();
|
Partition* partition3 = job->partition();
|
||||||
QVERIFY( partition3 );
|
QVERIFY( partition3 );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
@ -294,7 +314,7 @@ PartitionJobTests::testCreatePartitionExtended()
|
|||||||
|
|
||||||
freePartition = firstFreePartition( m_device->partitionTable() );
|
freePartition = firstFreePartition( m_device->partitionTable() );
|
||||||
QVERIFY( freePartition );
|
QVERIFY( freePartition );
|
||||||
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Ext4, 10_MiB);
|
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Ext4, 10_MiB );
|
||||||
Partition* partition1 = job->partition();
|
Partition* partition1 = job->partition();
|
||||||
QVERIFY( partition1 );
|
QVERIFY( partition1 );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
@ -302,14 +322,15 @@ PartitionJobTests::testCreatePartitionExtended()
|
|||||||
|
|
||||||
freePartition = firstFreePartition( m_device->partitionTable() );
|
freePartition = firstFreePartition( m_device->partitionTable() );
|
||||||
QVERIFY( freePartition );
|
QVERIFY( freePartition );
|
||||||
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Extended ), FileSystem::Extended, 10_MiB);
|
job = newCreatePartitionJob(
|
||||||
|
freePartition, PartitionRole( PartitionRole::Extended ), FileSystem::Extended, 10_MiB );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
m_queue.enqueue( job_ptr( job ) );
|
m_queue.enqueue( job_ptr( job ) );
|
||||||
Partition* extendedPartition = job->partition();
|
Partition* extendedPartition = job->partition();
|
||||||
|
|
||||||
freePartition = firstFreePartition( extendedPartition );
|
freePartition = firstFreePartition( extendedPartition );
|
||||||
QVERIFY( freePartition );
|
QVERIFY( freePartition );
|
||||||
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Logical ), FileSystem::Ext4, 0);
|
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Logical ), FileSystem::Ext4, 0 );
|
||||||
Partition* partition2 = job->partition();
|
Partition* partition2 = job->partition();
|
||||||
QVERIFY( partition2 );
|
QVERIFY( partition2 );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
@ -333,10 +354,10 @@ PartitionJobTests::testResizePartition_data()
|
|||||||
QTest::addColumn< unsigned int >( "newStartMiB" );
|
QTest::addColumn< unsigned int >( "newStartMiB" );
|
||||||
QTest::addColumn< unsigned int >( "newSizeMiB" );
|
QTest::addColumn< unsigned int >( "newSizeMiB" );
|
||||||
|
|
||||||
QTest::newRow("grow") << 10 << 50 << 10 << 70;
|
QTest::newRow( "grow" ) << 10 << 50 << 10 << 70;
|
||||||
QTest::newRow("shrink") << 10 << 70 << 10 << 50;
|
QTest::newRow( "shrink" ) << 10 << 70 << 10 << 50;
|
||||||
QTest::newRow("moveLeft") << 10 << 50 << 8 << 50;
|
QTest::newRow( "moveLeft" ) << 10 << 50 << 8 << 50;
|
||||||
QTest::newRow("moveRight") << 10 << 50 << 12 << 50;
|
QTest::newRow( "moveRight" ) << 10 << 50 << 12 << 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -366,15 +387,13 @@ PartitionJobTests::testResizePartition()
|
|||||||
|
|
||||||
Partition* freePartition = firstFreePartition( m_device->partitionTable() );
|
Partition* freePartition = firstFreePartition( m_device->partitionTable() );
|
||||||
QVERIFY( freePartition );
|
QVERIFY( freePartition );
|
||||||
Partition* partition = KPMHelpers::createNewPartition(
|
Partition* partition = KPMHelpers::createNewPartition( freePartition->parent(),
|
||||||
freePartition->parent(),
|
|
||||||
*m_device,
|
*m_device,
|
||||||
PartitionRole( PartitionRole::Primary ),
|
PartitionRole( PartitionRole::Primary ),
|
||||||
FileSystem::Ext4,
|
FileSystem::Ext4,
|
||||||
oldFirst,
|
oldFirst,
|
||||||
oldLast,
|
oldLast,
|
||||||
KPM_PARTITION_FLAG(None)
|
KPM_PARTITION_FLAG( None ) );
|
||||||
);
|
|
||||||
CreatePartitionJob* job = new CreatePartitionJob( m_device.data(), partition );
|
CreatePartitionJob* job = new CreatePartitionJob( m_device.data(), partition );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
m_queue.enqueue( job_ptr( job ) );
|
m_queue.enqueue( job_ptr( job ) );
|
||||||
@ -386,7 +405,8 @@ PartitionJobTests::testResizePartition()
|
|||||||
// Write a test file in the partition
|
// Write a test file in the partition
|
||||||
refreshDevice();
|
refreshDevice();
|
||||||
QVERIFY( m_device->partitionTable() );
|
QVERIFY( m_device->partitionTable() );
|
||||||
Partition* partition = m_device->partitionTable()->findPartitionBySector( oldFirst, PartitionRole( PartitionRole::Primary ) );
|
Partition* partition
|
||||||
|
= m_device->partitionTable()->findPartitionBySector( oldFirst, PartitionRole( PartitionRole::Primary ) );
|
||||||
QVERIFY( partition );
|
QVERIFY( partition );
|
||||||
QCOMPARE( partition->firstSector(), oldFirst );
|
QCOMPARE( partition->firstSector(), oldFirst );
|
||||||
QCOMPARE( partition->lastSector(), oldLast );
|
QCOMPARE( partition->lastSector(), oldLast );
|
||||||
@ -411,7 +431,8 @@ PartitionJobTests::testResizePartition()
|
|||||||
{
|
{
|
||||||
refreshDevice();
|
refreshDevice();
|
||||||
QVERIFY( m_device->partitionTable() );
|
QVERIFY( m_device->partitionTable() );
|
||||||
Partition* partition = m_device->partitionTable()->findPartitionBySector( newFirst, PartitionRole( PartitionRole::Primary ) );
|
Partition* partition
|
||||||
|
= m_device->partitionTable()->findPartitionBySector( newFirst, PartitionRole( PartitionRole::Primary ) );
|
||||||
QVERIFY( partition );
|
QVERIFY( partition );
|
||||||
QCOMPARE( partition->firstSector(), newFirst );
|
QCOMPARE( partition->firstSector(), newFirst );
|
||||||
QCOMPARE( partition->lastSector(), newLast );
|
QCOMPARE( partition->lastSector(), newLast );
|
||||||
|
@ -59,6 +59,7 @@ public:
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
|
void cleanupTestCase();
|
||||||
void testPartitionTable();
|
void testPartitionTable();
|
||||||
void testCreatePartition();
|
void testCreatePartition();
|
||||||
void testCreatePartitionExtended();
|
void testCreatePartitionExtended();
|
||||||
@ -71,7 +72,8 @@ private:
|
|||||||
QueueRunner m_runner;
|
QueueRunner m_runner;
|
||||||
|
|
||||||
void queuePartitionTableCreation( PartitionTable::TableType type );
|
void queuePartitionTableCreation( PartitionTable::TableType type );
|
||||||
CreatePartitionJob* newCreatePartitionJob( Partition* freeSpacePartition, PartitionRole, FileSystem::Type type, qint64 size );
|
CreatePartitionJob*
|
||||||
|
newCreatePartitionJob( Partition* freeSpacePartition, PartitionRole, FileSystem::Type type, qint64 size );
|
||||||
void refreshDevice();
|
void refreshDevice();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import sys
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from libcalamares import *
|
from libcalamares import *
|
||||||
|
from libcalamares.utils import mount
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
_ = gettext.translation("calamares-python",
|
_ = gettext.translation("calamares-python",
|
||||||
@ -277,34 +278,29 @@ class UnpackOperation:
|
|||||||
|
|
||||||
def mount_image(self, entry, imgmountdir):
|
def mount_image(self, entry, imgmountdir):
|
||||||
"""
|
"""
|
||||||
Mount given image as loop device.
|
Mount given @p entry as loop device on @p imgmountdir.
|
||||||
|
|
||||||
A *file* entry (e.g. one with *sourcefs* set to *file*)
|
A *file* entry (e.g. one with *sourcefs* set to *file*)
|
||||||
is not mounted and just ignored.
|
is not mounted and just ignored.
|
||||||
|
|
||||||
:param entry:
|
:param entry: the entry to mount (source is the important property)
|
||||||
:param imgmountdir:
|
:param imgmountdir: where to mount it
|
||||||
|
|
||||||
|
:returns: None, but throws if the mount failed
|
||||||
"""
|
"""
|
||||||
if entry.is_file():
|
if entry.is_file():
|
||||||
return
|
return
|
||||||
|
|
||||||
if os.path.isdir(entry.source):
|
if os.path.isdir(entry.source):
|
||||||
subprocess.check_call(["mount",
|
r = mount(entry.source, imgmountdir, "", "--bind")
|
||||||
"--bind", entry.source,
|
|
||||||
imgmountdir])
|
|
||||||
elif os.path.isfile(entry.source):
|
elif os.path.isfile(entry.source):
|
||||||
subprocess.check_call(["mount",
|
r = mount(entry.source, imgmountdir, entry.sourcefs, "loop")
|
||||||
entry.source,
|
|
||||||
imgmountdir,
|
|
||||||
"-t", entry.sourcefs,
|
|
||||||
"-o", "loop"
|
|
||||||
])
|
|
||||||
else: # entry.source is a device
|
else: # entry.source is a device
|
||||||
subprocess.check_call(["mount",
|
r = mount(entry.source, imgmountdir, entry.sourcefs, "")
|
||||||
entry.source,
|
|
||||||
imgmountdir,
|
if r != 0:
|
||||||
"-t", entry.sourcefs
|
raise subprocess.CalledProcessError(r, "mount")
|
||||||
])
|
|
||||||
|
|
||||||
def unpack_image(self, entry, imgmountdir):
|
def unpack_image(self, entry, imgmountdir):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user