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_Move = 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;
|
||||
}
|
||||
|
||||
bool luks::supportToolFound() const
|
||||
{
|
||||
m_cryptsetupFound =
|
||||
// m_GetUsed != cmdSupportNone &&
|
||||
m_GetLabel != cmdSupportNone &&
|
||||
m_SetLabel != cmdSupportNone &&
|
||||
m_Create != cmdSupportNone &&
|
||||
|
@ -264,7 +264,7 @@ bool luks::cryptOpen(QWidget* parent, const QString& deviceNode)
|
|||
commands.push_back(QStringLiteral("cryptsetup"));
|
||||
std::vector<QStringList> args;
|
||||
args.push_back({ passphrase });
|
||||
args.push_back({ QStringLiteral("luksOpen"),
|
||||
args.push_back({ QStringLiteral("open"),
|
||||
deviceNode,
|
||||
suggestedMapperName(deviceNode) });
|
||||
delete dlg;
|
||||
|
@ -320,6 +320,8 @@ bool luks::cryptClose(const QString& deviceNode)
|
|||
|
||||
m_passphrase.clear();
|
||||
setLabel({});
|
||||
setUUID(readUUID(deviceNode));
|
||||
setSectorsUsed(-1);
|
||||
|
||||
m_isCryptOpen = (m_innerFs != nullptr);
|
||||
|
||||
|
@ -334,6 +336,9 @@ void luks::loadInnerFileSystem(const QString& mapperNode)
|
|||
FileSystem::Type innerFsType = detectFileSystem(mapperNode);
|
||||
m_innerFs = FileSystemFactory::cloneWithNewType(innerFsType,
|
||||
*this);
|
||||
setLabel(m_innerFs->readLabel(mapperNode));
|
||||
setUUID(m_innerFs->readUUID(mapperNode));
|
||||
setSectorsUsed(m_innerFs->readUsedCapacity(mapperNode)/m_logicalSectorSize);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (!m_isCryptOpen)
|
||||
|
@ -488,6 +502,8 @@ bool luks::resize(Report& report, const QString& deviceNode, qint64) const
|
|||
|
||||
QString luks::readUUID(const QString& deviceNode) const
|
||||
{
|
||||
if (m_isCryptOpen && m_innerFs)
|
||||
return m_innerFs->readUUID(mapperName(deviceNode));
|
||||
ExternalCommand cmd(QStringLiteral("cryptsetup"),
|
||||
{ QStringLiteral("luksUUID"), deviceNode });
|
||||
if (cmd.run()) {
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
|
||||
public:
|
||||
static void init();
|
||||
virtual qint64 readUsedCapacity(const QString& deviceNode) const override;
|
||||
|
||||
virtual CommandSupportType supportGetUsed() const override {
|
||||
return m_GetUsed;
|
||||
|
@ -95,6 +96,10 @@ public:
|
|||
return m_GetUUID;
|
||||
}
|
||||
|
||||
void setLogicalSectorSize(unsigned int logicalSectorSize) {
|
||||
m_logicalSectorSize = logicalSectorSize;
|
||||
}
|
||||
|
||||
virtual bool check(Report& report, const QString& deviceNode) const override;
|
||||
virtual bool create(Report &report, const QString &deviceNode) const override;
|
||||
virtual qint64 minCapacity() const override;
|
||||
|
@ -166,6 +171,7 @@ private:
|
|||
mutable bool m_cryptsetupFound;
|
||||
QString m_passphrase;
|
||||
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);
|
||||
bool isCryptOpen = !mapperNode.isEmpty();
|
||||
luksFs->setCryptOpen(isCryptOpen);
|
||||
luksFs->setLogicalSectorSize(d.logicalSectorSize());
|
||||
|
||||
if (isCryptOpen) {
|
||||
luksFs->loadInnerFileSystem(mapperNode);
|
||||
luksFs->setSectorsUsed(luksFs->readUsedCapacity(mapperNode) / d.logicalSectorSize());
|
||||
|
||||
mountPoint = mountPoints.findByDevice(mapperNode) ?
|
||||
mountPoints.findByDevice(mapperNode)->mountPoint() :
|
||||
|
|
Loading…
Reference in New Issue