Assume the inner FS is already set when creating LUKS FS.

An open LUKS FS now reports the type of its inner FS.
Build a list of "LUKS-encryptable" filesystem types.
This commit is contained in:
Teo Mrnjavac 2016-04-15 15:33:32 +02:00
parent 4c8b531bf4
commit e1383df143
2 changed files with 43 additions and 16 deletions

View File

@ -77,7 +77,7 @@ void luks::init()
bool luks::create(Report& report, const QString& deviceNode) const
{
Q_ASSERT(m_innerFs);
QPointer<DecryptLuksDialog> dlg = new DecryptLuksDialog(0, deviceNode); //TODO: parent widget instead of 0
if (dlg->exec() != QDialog::Accepted)
@ -114,21 +114,10 @@ bool luks::create(Report& report, const QString& deviceNode) const
if (!(openCmd.run(-1) && openCmd.exitCode() == 0))
return false;
if (m_innerFs)
{
delete m_innerFs;
m_innerFs = nullptr;
}
QString mapperNode = mapperName(deviceNode);
if (mapperNode.isEmpty())
return false;
//FIXME: don't hardcode inner fs type
FileSystem::Type innerFsType = FileSystem::Ext4;
m_innerFs = FileSystemFactory::cloneWithNewType(innerFsType,
*this);
m_innerFs->create(report, mapperNode);
m_isCryptOpen = (m_innerFs != nullptr);
@ -136,7 +125,6 @@ bool luks::create(Report& report, const QString& deviceNode) const
if (m_isCryptOpen)
return true;
return false;
}
bool luks::supportToolFound() const
@ -286,7 +274,7 @@ bool luks::cryptOpen(const QString& deviceNode)
if (mapperNode.isEmpty())
return false;
loadInnerFilesystem(mapperNode);
loadInnerFileSystem(mapperNode);
m_isCryptOpen = (m_innerFs != nullptr);
if (m_isCryptOpen)
@ -325,13 +313,20 @@ bool luks::cryptClose(const QString& deviceNode)
return false;
}
void luks::loadInnerFilesystem(const QString& mapperNode)
void luks::loadInnerFileSystem(const QString& mapperNode)
{
Q_ASSERT(!m_innerFs);
FileSystem::Type innerFsType = detectFileSystem(mapperNode);
m_innerFs = FileSystemFactory::cloneWithNewType(innerFsType,
*this);
}
void luks::createInnerFileSystem(FileSystem::Type type)
{
Q_ASSERT(!m_innerFs);
m_innerFs = FileSystemFactory::cloneWithNewType(type, *this);
}
bool luks::mount(const QString& deviceNode, const QString& mountPoint)
{
if (!m_isCryptOpen)
@ -418,6 +413,13 @@ bool luks::unmount(const QString& deviceNode)
return false;
}
FileSystem::Type luks::type() const
{
if (m_isCryptOpen && m_innerFs)
return m_innerFs->type();
return FileSystem::Luks;
}
QString luks::readUUID(const QString& deviceNode) const
{
ExternalCommand cmd(QStringLiteral("cryptsetup"),
@ -519,4 +521,25 @@ QString luks::getPayloadOffset(const QString& deviceNode)
return QStringLiteral("---");
}
bool luks::canEncryptType(FileSystem::Type type)
{
switch (type)
{
case Ext2:
case Ext3:
case Ext4:
case LinuxSwap:
case ReiserFS:
case Reiser4:
case Xfs:
case Jfs:
case Btrfs:
case Zfs:
case Lvm2_PV:
return true;
default:
return false;
}
}
}

View File

@ -108,11 +108,14 @@ public:
bool cryptOpen(const QString& deviceNode);
bool cryptClose(const QString& deviceNode);
void loadInnerFilesystem(const QString& mapperNode);
void loadInnerFileSystem(const QString& mapperNode);
void createInnerFileSystem(Type type);
virtual bool mount(const QString& deviceNode, const QString& mountPoint) override;
virtual bool unmount(const QString& deviceNode) override;
virtual FileSystem::Type type() const override;
static QString mapperName(const QString& deviceNode);
static QString getCipherName(const QString& deviceNode);
@ -120,6 +123,7 @@ public:
static QString getHashName(const QString& deviceNode);
static QString getKeySize(const QString& deviceNode);
static QString getPayloadOffset(const QString& deviceNode);
static bool canEncryptType(FileSystem::Type type);
public:
static CommandSupportType m_GetUsed;