[libcalamares] Add a KiB unit
This commit creates a _KiB operator for future use by the partition module. It also fixes a typo in one instance of MiBtoBytes(), requiring a couple extra fixes. Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
This commit is contained in:
parent
90eb6afd52
commit
c3ccc0de0e
@ -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 2017, Adriaan de Groot <groot@kde.org>
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
||||||
|
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@ -24,10 +25,16 @@
|
|||||||
namespace CalamaresUtils
|
namespace CalamaresUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** User defined literals, 1_KiB is 1 KibiByte (= 2^10 bytes) */
|
||||||
|
constexpr qint64 operator ""_KiB( unsigned long long m )
|
||||||
|
{
|
||||||
|
return qint64(m) * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
/** User defined literals, 1_MiB is 1 MibiByte (= 2^20 bytes) */
|
/** User defined literals, 1_MiB is 1 MibiByte (= 2^20 bytes) */
|
||||||
constexpr qint64 operator ""_MiB( unsigned long long m )
|
constexpr qint64 operator ""_MiB( unsigned long long m )
|
||||||
{
|
{
|
||||||
return qint64(m) * 1024 * 1024;
|
return operator ""_KiB(m) * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** User defined literals, 1_GiB is 1 GibiByte (= 2^30 bytes) */
|
/** User defined literals, 1_GiB is 1 GibiByte (= 2^30 bytes) */
|
||||||
@ -36,6 +43,11 @@ constexpr qint64 operator ""_GiB( unsigned long long m )
|
|||||||
return operator ""_MiB(m) * 1024;
|
return operator ""_MiB(m) * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr qint64 KiBtoBytes( unsigned long long m )
|
||||||
|
{
|
||||||
|
return operator ""_KiB( m );
|
||||||
|
}
|
||||||
|
|
||||||
constexpr qint64 MiBtoBytes( unsigned long long m )
|
constexpr qint64 MiBtoBytes( unsigned long long m )
|
||||||
{
|
{
|
||||||
return operator ""_MiB( m );
|
return operator ""_MiB( m );
|
||||||
@ -46,7 +58,12 @@ constexpr qint64 GiBtoBytes( unsigned long long m )
|
|||||||
return operator ""_GiB( m );
|
return operator ""_GiB( m );
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr qint64 MiBToBytes( double m )
|
constexpr qint64 KiBtoBytes( double m )
|
||||||
|
{
|
||||||
|
return qint64(m * 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr qint64 MiBtoBytes( double m )
|
||||||
{
|
{
|
||||||
return qint64(m * 1024 * 1024);
|
return qint64(m * 1024 * 1024);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ ResizeFSJob::RelativeSize::apply( qint64 totalSectors, qint64 sectorSize )
|
|||||||
case unit_t::None:
|
case unit_t::None:
|
||||||
return -1;
|
return -1;
|
||||||
case unit_t::Absolute:
|
case unit_t::Absolute:
|
||||||
return CalamaresUtils::MiBtoBytes( value() ) / sectorSize;
|
return CalamaresUtils::MiBtoBytes( static_cast<unsigned long long>( value() ) ) / sectorSize;
|
||||||
case unit_t::Percent:
|
case unit_t::Percent:
|
||||||
if ( value() == 100 )
|
if ( value() == 100 )
|
||||||
return totalSectors; // Common-case, avoid futzing around
|
return totalSectors; // Common-case, avoid futzing around
|
||||||
|
@ -349,7 +349,8 @@ 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( CalamaresUtils::MiBtoBytes( qMin( oldSizeMB, newSizeMB ) ) * 3 / 4 );
|
const unsigned long long minSizeMB = qMin( oldSizeMB, newSizeMB );
|
||||||
|
const QByteArray testData = generateTestData( CalamaresUtils::MiBtoBytes( minSizeMB ) * 3 / 4 );
|
||||||
const QString testName = "test.data";
|
const QString testName = "test.data";
|
||||||
|
|
||||||
// Setup: create the test partition
|
// Setup: create the test partition
|
||||||
|
Loading…
Reference in New Issue
Block a user