Clang: refactor units-converters, reduce warnings
This commit is contained in:
parent
31fa9e4251
commit
a06911e9aa
60
src/libcalamares/utils/Units.h
Normal file
60
src/libcalamares/utils/Units.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2017, 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 LIBCALAMARES_UTILS_UNITS_H
|
||||||
|
#define LIBCALAMARES_UTILS_UNITS_H
|
||||||
|
|
||||||
|
#include <QtCore/QIntegerForSize>
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
|
||||||
|
/** User defined literals, 1_MiB is 1 MibiByte (= 2^20 bytes) */
|
||||||
|
constexpr qint64 operator ""_MiB( unsigned long long m )
|
||||||
|
{
|
||||||
|
return qint64(m) * 1024 * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** User defined literals, 1_GiB is 1 GibiByte (= 2^30 bytes) */
|
||||||
|
constexpr qint64 operator ""_GiB( unsigned long long m )
|
||||||
|
{
|
||||||
|
return operator ""_MiB(m) * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr qint64 MiBtoBytes( unsigned long long m )
|
||||||
|
{
|
||||||
|
return operator ""_MiB( m );
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr qint64 GiBtoBytes( unsigned long long m )
|
||||||
|
{
|
||||||
|
return operator ""_GiB( m );
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr qint64 MiBToBytes( double m )
|
||||||
|
{
|
||||||
|
return qint64(m * 1024 * 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr qint64 GiBtoBytes( double m )
|
||||||
|
{
|
||||||
|
return qint64(m * 1024 * 1024 * 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
#endif
|
@ -25,6 +25,7 @@
|
|||||||
#include "core/PartUtils.h"
|
#include "core/PartUtils.h"
|
||||||
|
|
||||||
#include "utils/CalamaresUtilsSystem.h"
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
|
#include "utils/Units.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
@ -36,25 +37,10 @@
|
|||||||
|
|
||||||
namespace PartitionActions
|
namespace PartitionActions
|
||||||
{
|
{
|
||||||
constexpr qint64 operator ""_MiB( unsigned long long m )
|
using CalamaresUtils::GiBtoBytes;
|
||||||
{
|
using CalamaresUtils::MiBtoBytes;
|
||||||
return m * static_cast< qint64 >( 1024 ) * 1024;
|
using CalamaresUtils::operator""_GiB;
|
||||||
}
|
using CalamaresUtils::operator""_MiB;
|
||||||
|
|
||||||
constexpr qint64 operator ""_GiB( unsigned long long m )
|
|
||||||
{
|
|
||||||
return operator ""_MiB(m) * static_cast< qint64 >( 1024 );
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr qint64 toMiB( unsigned long long m )
|
|
||||||
{
|
|
||||||
return operator ""_MiB( m );
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr qint64 toGiB( unsigned long long m )
|
|
||||||
{
|
|
||||||
return operator ""_GiB( m );
|
|
||||||
}
|
|
||||||
|
|
||||||
qint64
|
qint64
|
||||||
swapSuggestion( const qint64 availableSpaceB )
|
swapSuggestion( const qint64 availableSpaceB )
|
||||||
@ -140,11 +126,11 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass
|
|||||||
empty_space_size = 1;
|
empty_space_size = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 firstFreeSector = toMiB(empty_space_size) / dev->logicalSize() + 1;
|
qint64 firstFreeSector = MiBtoBytes(empty_space_size) / dev->logicalSize() + 1;
|
||||||
|
|
||||||
if ( isEfi )
|
if ( isEfi )
|
||||||
{
|
{
|
||||||
qint64 lastSector = firstFreeSector + ( toMiB(uefisys_part_size) / dev->logicalSize() );
|
qint64 lastSector = firstFreeSector + ( MiBtoBytes(uefisys_part_size) / dev->logicalSize() );
|
||||||
core->createPartitionTable( dev, PartitionTable::gpt );
|
core->createPartitionTable( dev, PartitionTable::gpt );
|
||||||
Partition* efiPartition = KPMHelpers::createNewPartition(
|
Partition* efiPartition = KPMHelpers::createNewPartition(
|
||||||
dev->partitionTable(),
|
dev->partitionTable(),
|
||||||
@ -175,7 +161,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass
|
|||||||
qint64 availableSpaceB = ( dev->totalLogical() - firstFreeSector ) * dev->logicalSize();
|
qint64 availableSpaceB = ( dev->totalLogical() - firstFreeSector ) * dev->logicalSize();
|
||||||
suggestedSwapSizeB = swapSuggestion( availableSpaceB );
|
suggestedSwapSizeB = swapSuggestion( availableSpaceB );
|
||||||
qint64 requiredSpaceB =
|
qint64 requiredSpaceB =
|
||||||
toGiB( gs->value( "requiredStorageGB" ).toDouble() + 0.1 + 2.0 ) +
|
GiBtoBytes( gs->value( "requiredStorageGB" ).toDouble() + 0.1 + 2.0 ) +
|
||||||
suggestedSwapSizeB;
|
suggestedSwapSizeB;
|
||||||
|
|
||||||
// If there is enough room for ESP + root + swap, create swap, otherwise don't.
|
// If there is enough room for ESP + root + swap, create swap, otherwise don't.
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include <PartitionJobTests.h>
|
#include <PartitionJobTests.h>
|
||||||
|
|
||||||
|
#include "utils/Units.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>
|
||||||
@ -36,9 +38,8 @@
|
|||||||
|
|
||||||
QTEST_GUILESS_MAIN( PartitionJobTests )
|
QTEST_GUILESS_MAIN( PartitionJobTests )
|
||||||
|
|
||||||
static const qint64 MB = 1024 * 1024;
|
|
||||||
|
|
||||||
using namespace Calamares;
|
using namespace Calamares;
|
||||||
|
using CalamaresUtils::operator""_MiB;
|
||||||
|
|
||||||
class PartitionMounter
|
class PartitionMounter
|
||||||
{
|
{
|
||||||
@ -247,7 +248,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 * MB);
|
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();
|
||||||
@ -255,7 +256,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 * MB);
|
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();
|
||||||
@ -263,7 +264,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 * MB);
|
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();
|
||||||
@ -288,7 +289,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 * MB);
|
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();
|
||||||
@ -296,7 +297,7 @@ 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 * MB);
|
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();
|
||||||
@ -341,7 +342,7 @@ PartitionJobTests::testResizePartition()
|
|||||||
QFETCH( int, newStartMB );
|
QFETCH( int, newStartMB );
|
||||||
QFETCH( int, newSizeMB );
|
QFETCH( int, newSizeMB );
|
||||||
|
|
||||||
const qint64 sectorForMB = MB / m_device->logicalSize();
|
const qint64 sectorForMB = 1_MiB / m_device->logicalSize();
|
||||||
|
|
||||||
qint64 oldFirst = sectorForMB * oldStartMB;
|
qint64 oldFirst = sectorForMB * oldStartMB;
|
||||||
qint64 oldLast = oldFirst + sectorForMB * oldSizeMB - 1;
|
qint64 oldLast = oldFirst + sectorForMB * oldSizeMB - 1;
|
||||||
@ -350,7 +351,7 @@ PartitionJobTests::testResizePartition()
|
|||||||
|
|
||||||
// Make the test data file smaller than the full size of the partition to
|
// Make the test data file smaller than the full size of the partition to
|
||||||
// accomodate for the file system overhead
|
// accomodate for the file system overhead
|
||||||
const QByteArray testData = generateTestData( ( qMin( oldSizeMB, newSizeMB ) ) * MB * 3 / 4 );
|
const QByteArray testData = generateTestData( CalamaresUtils::MiBtoBytes( qMin( oldSizeMB, newSizeMB ) ) * 3 / 4 );
|
||||||
const QString testName = "test.data";
|
const QString testName = "test.data";
|
||||||
|
|
||||||
// Setup: create the test partition
|
// Setup: create the test partition
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Retranslator.h"
|
#include "utils/Retranslator.h"
|
||||||
#include "utils/CalamaresUtilsSystem.h"
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
|
#include "utils/Units.h"
|
||||||
|
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
|
|
||||||
@ -77,12 +79,12 @@ RequirementsChecker::RequirementsChecker( QObject* parent )
|
|||||||
bool isRoot = false;
|
bool isRoot = false;
|
||||||
bool enoughScreen = (availableSize.width() >= CalamaresUtils::windowPreferredWidth) && (availableSize.height() >= CalamaresUtils::windowPreferredHeight);
|
bool enoughScreen = (availableSize.width() >= CalamaresUtils::windowPreferredWidth) && (availableSize.height() >= CalamaresUtils::windowPreferredHeight);
|
||||||
|
|
||||||
qint64 requiredStorageB = m_requiredStorageGB * 1073741824L; /*powers of 2*/
|
qint64 requiredStorageB = CalamaresUtils::GiBtoBytes(m_requiredStorageGB);
|
||||||
cDebug() << "Need at least storage bytes:" << requiredStorageB;
|
cDebug() << "Need at least storage bytes:" << requiredStorageB;
|
||||||
if ( m_entriesToCheck.contains( "storage" ) )
|
if ( m_entriesToCheck.contains( "storage" ) )
|
||||||
enoughStorage = checkEnoughStorage( requiredStorageB );
|
enoughStorage = checkEnoughStorage( requiredStorageB );
|
||||||
|
|
||||||
qint64 requiredRamB = m_requiredRamGB * 1073741824L; /*powers of 2*/
|
qint64 requiredRamB = CalamaresUtils::GiBtoBytes(m_requiredRamGB);
|
||||||
cDebug() << "Need at least ram bytes:" << requiredRamB;
|
cDebug() << "Need at least ram bytes:" << requiredRamB;
|
||||||
if ( m_entriesToCheck.contains( "ram" ) )
|
if ( m_entriesToCheck.contains( "ram" ) )
|
||||||
enoughRam = checkEnoughRam( requiredRamB );
|
enoughRam = checkEnoughRam( requiredRamB );
|
||||||
|
Loading…
Reference in New Issue
Block a user