Add initial support for growing LUKS volumes.

Added support for filling btrfs, ext and swap partitions.
This commit is contained in:
Andrius Štikonas 2016-04-21 17:22:48 +01:00
parent 7edc601a36
commit d126f04886
Signed by: andrius
GPG Key ID: C86115C8091792EC
6 changed files with 34 additions and 5 deletions

View File

@ -143,7 +143,8 @@ bool btrfs::resize(Report& report, const QString& deviceNode, qint64 length) con
ExternalCommand mountCmd(report, QStringLiteral("mount"), QStringList() << QStringLiteral("-v") << QStringLiteral("-t") << QStringLiteral("btrfs") << deviceNode << tempDir.path());
if (mountCmd.run(-1) && mountCmd.exitCode() == 0) {
ExternalCommand resizeCmd(report, QStringLiteral("btrfs"), QStringList() << QStringLiteral("filesystem") << QStringLiteral("resize") << QString::number(length) << tempDir.path());
QString len = length == -1 ? QStringLiteral("max") : QString::number(length);
ExternalCommand resizeCmd(report, QStringLiteral("btrfs"), QStringList() << QStringLiteral("filesystem") << QStringLiteral("resize") << len << tempDir.path());
if (resizeCmd.run(-1) && resizeCmd.exitCode() == 0)
rval = true;

View File

@ -137,7 +137,9 @@ bool ext2::create(Report& report, const QString& deviceNode) const
bool ext2::resize(Report& report, const QString& deviceNode, qint64 length) const
{
const QString len = QString::number(length / 512) + QStringLiteral("s");
ExternalCommand cmd(report, QStringLiteral("resize2fs"), QStringList() << deviceNode << len);
const QStringList command = length == -1 ? QStringList() << deviceNode : QStringList() << deviceNode << len;
ExternalCommand cmd(report, QStringLiteral("resize2fs"), command);
return cmd.run(-1) && cmd.exitCode() == 0;
}

View File

@ -185,7 +185,7 @@ bool FileSystem::create(Report& report, const QString& deviceNode) const
return true;
}
/** Resized a FileSystem to a given new length
/** Resize a FileSystem to a given new length
@param report Report to write status information to
@param deviceNode the device node for the Partition the FileSystem is on
@param newLength the new length for the FileSystem in bytes

View File

@ -83,6 +83,7 @@ bool linuxswap::create(Report& report, const QString& deviceNode) const
bool linuxswap::resize(Report& report, const QString& deviceNode, qint64 length) const
{
Q_UNUSED(length);
const QString label = readLabel(deviceNode);
const QString uuid = readUUID(deviceNode);
@ -92,7 +93,7 @@ bool linuxswap::resize(Report& report, const QString& deviceNode, qint64 length)
if (!uuid.isEmpty())
args << QStringLiteral("-U") << uuid;
args << deviceNode << QString::number(length / 1024);
args << deviceNode;
ExternalCommand cmd(report, QStringLiteral("mkswap"), args);
return cmd.run(-1) && cmd.exitCode() == 0;

View File

@ -25,6 +25,7 @@
#include "util/capacity.h"
#include "util/externalcommand.h"
#include "util/report.h"
#include <QDebug>
#include <QDialog>
@ -69,6 +70,7 @@ void luks::init()
{
m_Create = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone;
m_UpdateUUID = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone;
m_Grow = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone;
m_Copy = cmdSupportCore;
m_Move = cmdSupportCore;
m_Backup = cmdSupportCore;
@ -129,7 +131,7 @@ bool luks::supportToolFound() const
m_Create != cmdSupportNone &&
// m_Check != cmdSupportNone &&
m_UpdateUUID != cmdSupportNone &&
// m_Grow != cmdSupportNone &&
m_Grow != cmdSupportNone &&
// m_Shrink != cmdSupportNone &&
m_Copy != cmdSupportNone &&
m_Move != cmdSupportNone &&
@ -418,6 +420,28 @@ FileSystem::Type luks::type() const
return FileSystem::Luks;
}
bool luks::resize(Report& report, const QString& deviceNode, qint64) const
{
Q_ASSERT(m_innerFs);
QString mapperNode = mapperName(deviceNode);
if (mapperNode.isEmpty())
return false;
ExternalCommand cryptResizeCmd(report, QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("resize") << mapperNode);
report.line() << xi18nc("@info/plain", "Resizing LUKS crypt on partition <filename>%1</filename>.", deviceNode);
bool rval = false;
if (cryptResizeCmd.run(-1))
{
rval = m_innerFs->resize(report, mapperNode, -1);
}
else
report.line() << xi18nc("@info/plain", "Resizing encrypted file system on partition <filename>%1</filename> failed.", deviceNode);
return rval;
}
QString luks::readUUID(const QString& deviceNode) const
{
ExternalCommand cmd(QStringLiteral("cryptsetup"),

View File

@ -89,6 +89,7 @@ public:
virtual bool supportToolFound() const;
virtual QString readUUID(const QString& deviceNode) const;
virtual bool updateUUID(Report& report, const QString& deviceNode) const;
virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const;
virtual QString mountTitle() const override;
virtual QString unmountTitle() const override;