Add luks2::create method.

This commit is contained in:
Andrius Štikonas 2017-12-29 20:38:36 +00:00
parent 4773f49edc
commit 1802b7ad05
3 changed files with 42 additions and 0 deletions

View File

@ -126,6 +126,7 @@ bool luks::create(Report& report, const QString& deviceNode)
QStringLiteral("512"),
QStringLiteral("--batch-mode"),
QStringLiteral("--force-password"),
QStringLiteral("--type"), QStringLiteral("luks1"),
QStringLiteral("luksFormat"),
deviceNode });
if (!( createCmd.start(-1) &&

View File

@ -43,6 +43,46 @@ FileSystem::Type luks2::type() const
return FileSystem::Luks2;
}
bool luks2::create(Report& report, const QString& deviceNode)
{
Q_ASSERT(m_innerFs);
Q_ASSERT(!m_passphrase.isEmpty());
ExternalCommand createCmd(report, QStringLiteral("cryptsetup"),
{ QStringLiteral("-s"),
QStringLiteral("512"),
QStringLiteral("--batch-mode"),
QStringLiteral("--force-password"),
QStringLiteral("--type"), QStringLiteral("luks2"),
QStringLiteral("luksFormat"),
deviceNode });
if (!( createCmd.start(-1) &&
createCmd.write(m_passphrase.toLocal8Bit() + '\n') == m_passphrase.toLocal8Bit().length() + 1 &&
createCmd.waitFor() && createCmd.exitCode() == 0))
{
return false;
}
ExternalCommand openCmd(report, QStringLiteral("cryptsetup"),
{ QStringLiteral("open"),
deviceNode,
suggestedMapperName(deviceNode) });
if (!( openCmd.start(-1) && openCmd.write(m_passphrase.toLocal8Bit() + '\n') == m_passphrase.toLocal8Bit().length() + 1 && openCmd.waitFor()))
return false;
setPayloadSize();
scan(deviceNode);
if (mapperName().isEmpty())
return false;
if (!m_innerFs->create(report, mapperName()))
return false;
return true;
}
bool luks2::resize(Report& report, const QString& deviceNode, qint64 newLength) const
{
Q_ASSERT(m_innerFs);

View File

@ -38,6 +38,7 @@ public:
luks2(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label);
~luks2() override;
bool create(Report& report, const QString& deviceNode) override;
bool resize(Report& report, const QString& deviceNode, qint64 length) const override;
FileSystem::Type type() const override;