Add support for reading used capacity of innerFS.
Also make sure labels, used capacity and UUID are properly updated when opening or closing luks volumes."
This commit is contained in:
parent
85aca763a2
commit
e2f21360bb
|
@ -77,13 +77,13 @@ void luks::init()
|
||||||
m_Copy = cmdSupportCore;
|
m_Copy = cmdSupportCore;
|
||||||
m_Move = cmdSupportCore;
|
m_Move = cmdSupportCore;
|
||||||
m_Backup = cmdSupportCore;
|
m_Backup = cmdSupportCore;
|
||||||
|
m_GetUsed = cmdSupportNone; // libparted does not support LUKS, we do this as a special case
|
||||||
m_GetUUID = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone;
|
m_GetUUID = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool luks::supportToolFound() const
|
bool luks::supportToolFound() const
|
||||||
{
|
{
|
||||||
m_cryptsetupFound =
|
m_cryptsetupFound =
|
||||||
// m_GetUsed != cmdSupportNone &&
|
|
||||||
m_GetLabel != cmdSupportNone &&
|
m_GetLabel != cmdSupportNone &&
|
||||||
m_SetLabel != cmdSupportNone &&
|
m_SetLabel != cmdSupportNone &&
|
||||||
m_Create != cmdSupportNone &&
|
m_Create != cmdSupportNone &&
|
||||||
|
@ -264,7 +264,7 @@ bool luks::cryptOpen(QWidget* parent, const QString& deviceNode)
|
||||||
commands.push_back(QStringLiteral("cryptsetup"));
|
commands.push_back(QStringLiteral("cryptsetup"));
|
||||||
std::vector<QStringList> args;
|
std::vector<QStringList> args;
|
||||||
args.push_back({ passphrase });
|
args.push_back({ passphrase });
|
||||||
args.push_back({ QStringLiteral("luksOpen"),
|
args.push_back({ QStringLiteral("open"),
|
||||||
deviceNode,
|
deviceNode,
|
||||||
suggestedMapperName(deviceNode) });
|
suggestedMapperName(deviceNode) });
|
||||||
delete dlg;
|
delete dlg;
|
||||||
|
@ -320,6 +320,8 @@ bool luks::cryptClose(const QString& deviceNode)
|
||||||
|
|
||||||
m_passphrase.clear();
|
m_passphrase.clear();
|
||||||
setLabel({});
|
setLabel({});
|
||||||
|
setUUID(readUUID(deviceNode));
|
||||||
|
setSectorsUsed(-1);
|
||||||
|
|
||||||
m_isCryptOpen = (m_innerFs != nullptr);
|
m_isCryptOpen = (m_innerFs != nullptr);
|
||||||
|
|
||||||
|
@ -334,6 +336,9 @@ void luks::loadInnerFileSystem(const QString& mapperNode)
|
||||||
FileSystem::Type innerFsType = detectFileSystem(mapperNode);
|
FileSystem::Type innerFsType = detectFileSystem(mapperNode);
|
||||||
m_innerFs = FileSystemFactory::cloneWithNewType(innerFsType,
|
m_innerFs = FileSystemFactory::cloneWithNewType(innerFsType,
|
||||||
*this);
|
*this);
|
||||||
|
setLabel(m_innerFs->readLabel(mapperNode));
|
||||||
|
setUUID(m_innerFs->readUUID(mapperNode));
|
||||||
|
setSectorsUsed(m_innerFs->readUsedCapacity(mapperNode)/m_logicalSectorSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void luks::createInnerFileSystem(FileSystem::Type type)
|
void luks::createInnerFileSystem(FileSystem::Type type)
|
||||||
|
@ -353,6 +358,15 @@ bool luks::check(Report& report, const QString& deviceNode) const
|
||||||
return m_innerFs->check(report, mapperNode);
|
return m_innerFs->check(report, mapperNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint64 luks::readUsedCapacity(const QString& deviceNode) const
|
||||||
|
{
|
||||||
|
if (!m_isCryptOpen)
|
||||||
|
return -1;
|
||||||
|
if (m_innerFs)
|
||||||
|
return m_innerFs->readUsedCapacity(deviceNode);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
bool luks::mount(const QString& deviceNode, const QString& mountPoint)
|
bool luks::mount(const QString& deviceNode, const QString& mountPoint)
|
||||||
{
|
{
|
||||||
if (!m_isCryptOpen)
|
if (!m_isCryptOpen)
|
||||||
|
@ -488,6 +502,8 @@ bool luks::resize(Report& report, const QString& deviceNode, qint64) const
|
||||||
|
|
||||||
QString luks::readUUID(const QString& deviceNode) const
|
QString luks::readUUID(const QString& deviceNode) const
|
||||||
{
|
{
|
||||||
|
if (m_isCryptOpen && m_innerFs)
|
||||||
|
return m_innerFs->readUUID(mapperName(deviceNode));
|
||||||
ExternalCommand cmd(QStringLiteral("cryptsetup"),
|
ExternalCommand cmd(QStringLiteral("cryptsetup"),
|
||||||
{ QStringLiteral("luksUUID"), deviceNode });
|
{ QStringLiteral("luksUUID"), deviceNode });
|
||||||
if (cmd.run()) {
|
if (cmd.run()) {
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void init();
|
static void init();
|
||||||
|
virtual qint64 readUsedCapacity(const QString& deviceNode) const override;
|
||||||
|
|
||||||
virtual CommandSupportType supportGetUsed() const override {
|
virtual CommandSupportType supportGetUsed() const override {
|
||||||
return m_GetUsed;
|
return m_GetUsed;
|
||||||
|
@ -95,6 +96,10 @@ public:
|
||||||
return m_GetUUID;
|
return m_GetUUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setLogicalSectorSize(unsigned int logicalSectorSize) {
|
||||||
|
m_logicalSectorSize = logicalSectorSize;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool check(Report& report, const QString& deviceNode) const override;
|
virtual bool check(Report& report, const QString& deviceNode) const override;
|
||||||
virtual bool create(Report &report, const QString &deviceNode) const override;
|
virtual bool create(Report &report, const QString &deviceNode) const override;
|
||||||
virtual qint64 minCapacity() const override;
|
virtual qint64 minCapacity() const override;
|
||||||
|
@ -166,6 +171,7 @@ private:
|
||||||
mutable bool m_cryptsetupFound;
|
mutable bool m_cryptsetupFound;
|
||||||
QString m_passphrase;
|
QString m_passphrase;
|
||||||
bool m_isMounted;
|
bool m_isMounted;
|
||||||
|
unsigned int m_logicalSectorSize;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -358,9 +358,11 @@ void LibPartedBackend::scanDevicePartitions(PedDevice*, Device& d, PedDisk* pedD
|
||||||
QString mapperNode = FS::luks::mapperName(node);
|
QString mapperNode = FS::luks::mapperName(node);
|
||||||
bool isCryptOpen = !mapperNode.isEmpty();
|
bool isCryptOpen = !mapperNode.isEmpty();
|
||||||
luksFs->setCryptOpen(isCryptOpen);
|
luksFs->setCryptOpen(isCryptOpen);
|
||||||
|
luksFs->setLogicalSectorSize(d.logicalSectorSize());
|
||||||
|
|
||||||
if (isCryptOpen) {
|
if (isCryptOpen) {
|
||||||
luksFs->loadInnerFileSystem(mapperNode);
|
luksFs->loadInnerFileSystem(mapperNode);
|
||||||
|
luksFs->setSectorsUsed(luksFs->readUsedCapacity(mapperNode) / d.logicalSectorSize());
|
||||||
|
|
||||||
mountPoint = mountPoints.findByDevice(mapperNode) ?
|
mountPoint = mountPoints.findByDevice(mapperNode) ?
|
||||||
mountPoints.findByDevice(mapperNode)->mountPoint() :
|
mountPoints.findByDevice(mapperNode)->mountPoint() :
|
||||||
|
|
Loading…
Reference in New Issue