Do not set LUKS logical sector size to 512.

This breaks used space reporting for LUKS encrypted LVM LV.
This commit is contained in:
Andrius Štikonas 2017-01-25 18:21:25 +01:00
parent f34b13f545
commit 901d01185f
4 changed files with 12 additions and 6 deletions

View File

@ -132,7 +132,7 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl
if (fs->type() == FileSystem::Luks) {
r |= PartitionRole::Luks;
FS::luks* luksFs = static_cast<FS::luks*>(fs);
luksFs->initLUKS();
luksFs->initLUKS(logicalSize());
QString mapperNode = luksFs->mapperName();
mountPoint = FileSystem::detectMountPoint(fs, mapperNode);

View File

@ -62,6 +62,7 @@ luks::luks(qint64 firstsector,
, m_isCryptOpen(false)
, m_cryptsetupFound(m_Create != cmdSupportNone)
, m_isMounted(false)
, m_logicalSectorSize(512)
, m_KeySize(-1)
, m_PayloadOffset(-1)
{
@ -495,7 +496,7 @@ bool luks::resize(Report& report, const QString& deviceNode, qint64 newLength) c
else if (m_innerFs->resize(report, mapperName(), payloadLength))
{
ExternalCommand cryptResizeCmd(report, QStringLiteral("cryptsetup"),
{ QStringLiteral("--size"), QString::number(payloadLength / m_logicalSectorSize), // LUKS assumes 512 bytes sector
{ QStringLiteral("--size"), QString::number(payloadLength / 512), // LUKS payload length is specified in multiples of 512 bytes
QStringLiteral("resize"), mapperName() });
report.line() << xi18nc("@info:progress", "Resizing LUKS crypt on partition <filename>%1</filename>.", deviceNode);
if (cryptResizeCmd.run(-1) && cryptResizeCmd.exitCode() == 0)
@ -650,8 +651,9 @@ bool luks::canEncryptType(FileSystem::Type type)
}
}
void luks::initLUKS()
void luks::initLUKS(unsigned int sectorSize)
{
setLogicalSectorSize(sectorSize);
QString mapperNode = mapperName();
bool isCryptOpen = !mapperNode.isEmpty();
setCryptOpen(isCryptOpen);

View File

@ -126,6 +126,10 @@ public:
return m_GetUUID;
}
void setLogicalSectorSize(unsigned int logicalSectorSize) {
m_logicalSectorSize = logicalSectorSize;
}
bool check(Report& report, const QString& deviceNode) const override;
bool create(Report& report, const QString& deviceNode) override;
SupportTool supportToolName() const override;
@ -182,7 +186,7 @@ public:
qint64 payloadOffset() const { return m_PayloadOffset; }
static bool canEncryptType(FileSystem::Type type);
void initLUKS();
void initLUKS(unsigned int sectorSize);
protected:
virtual QString readOuterUUID(const QString& deviceNode) const;
@ -208,7 +212,7 @@ private:
mutable bool m_cryptsetupFound;
QString m_passphrase;
bool m_isMounted;
constexpr static unsigned int m_logicalSectorSize = 512;
unsigned int m_logicalSectorSize;
QString m_MapperName;
QString m_CipherName;

View File

@ -341,7 +341,7 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk)
if (fs->type() == FileSystem::Luks) {
r |= PartitionRole::Luks;
FS::luks* luksFs = static_cast<FS::luks*>(fs);
luksFs->initLUKS();
luksFs->initLUKS(d.logicalSize());
QString mapperNode = luksFs->mapperName();
mountPoint = FileSystem::detectMountPoint(fs, mapperNode);
mounted = FileSystem::detectMountStatus(fs, mapperNode);