[partition] Move bytesToSectors() to CalamaresUtils namespace

In order to prepare for future refactoring of the PartSize class, move
the bytesToSectors() function to libcalamares in the CalamaresUtils
namespace.

Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
This commit is contained in:
Arnaud Ferraris 2019-05-08 19:20:38 +02:00
parent b840bce22d
commit 36bc0e6308
4 changed files with 17 additions and 17 deletions

View File

@ -78,5 +78,19 @@ constexpr int BytesToMiB( qint64 b )
return int( b / 1024 / 1024 );
}
constexpr qint64 alignBytesToBlockSize( qint64 bytes, qint64 blocksize )
{
qint64 blocks = bytes / blocksize;
if ( blocks * blocksize != bytes )
++blocks;
return blocks * blocksize;
}
constexpr qint64 bytesToSectors( qint64 bytes, qint64 blocksize )
{
return alignBytesToBlockSize( alignBytesToBlockSize( bytes, blocksize), MiBtoBytes(1ULL) ) / blocksize;
}
} // namespace
#endif

View File

@ -101,7 +101,7 @@ PartSize::toSectors( qint64 totalSectors, qint64 sectorSize ) const
case unit_t::KiB:
case unit_t::MiB:
case unit_t::GiB:
return bytesToSectors ( toBytes(), sectorSize );
return CalamaresUtils::bytesToSectors ( toBytes(), sectorSize );
}
return -1;

View File

@ -181,20 +181,6 @@ QString findFS( QString fsName, FileSystem::Type* fsType );
*/
qint64 sizeToSectors( double size, SizeUnit unit, qint64 totalSectors, qint64 logicalSize );
constexpr qint64 alignBytesToBlockSize( qint64 bytes, qint64 blocksize )
{
qint64 blocks = bytes / blocksize;
if ( blocks * blocksize != bytes )
++blocks;
return blocks * blocksize;
}
constexpr qint64 bytesToSectors( qint64 bytes, qint64 blocksize )
{
return alignBytesToBlockSize( alignBytesToBlockSize( bytes, blocksize), MiBtoBytes(1ULL) ) / blocksize;
}
}
#endif // PARTUTILS_H

View File

@ -115,11 +115,11 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO
// Since sectors count from 0, if the space is 2048 sectors in size,
// the first free sector has number 2048 (and there are 2048 sectors
// before that one, numbered 0..2047).
qint64 firstFreeSector = PartUtils::bytesToSectors( empty_space_sizeB, dev->logicalSize() );
qint64 firstFreeSector = CalamaresUtils::bytesToSectors( empty_space_sizeB, dev->logicalSize() );
if ( isEfi )
{
qint64 efiSectorCount = PartUtils::bytesToSectors( uefisys_part_sizeB, dev->logicalSize() );
qint64 efiSectorCount = CalamaresUtils::bytesToSectors( uefisys_part_sizeB, dev->logicalSize() );
Q_ASSERT( efiSectorCount > 0 );
// Since sectors count from 0, and this partition is created starting