FS::luks is now a decorator for an actual FS composed inside.
Implement cryptOpen/cryptClose/mount/unmount operations. detectFileSystem, which only uses blkid, is now in FileSystem.cpp. FileSystem::mount now requires a mountPoint. Use umount -A to immediately umount all mount points in unmountCmds. Add override keywords, TODO: add them everywhere. LibPartedBackend no longer links against libblkid. Fix LUKS handling in LibPartedBackend::scanDevicePartitions.
This commit is contained in:
parent
95dfe648e9
commit
d8494a00a5
|
@ -1,5 +1,6 @@
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||||
|
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or *
|
* This program is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU General Public License as *
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
@ -292,7 +293,7 @@ bool Partition::mount(Report& report)
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
if (fileSystem().canMount(deviceNode()))
|
if (fileSystem().canMount(deviceNode()))
|
||||||
success = fileSystem().mount(deviceNode());
|
success = fileSystem().mount(deviceNode(), mountPoint());
|
||||||
else {
|
else {
|
||||||
ExternalCommand mountCmd(report, QStringLiteral("mount"), QStringList() << QStringLiteral("-v") << deviceNode() << mountPoint());
|
ExternalCommand mountCmd(report, QStringLiteral("mount"), QStringList() << QStringLiteral("-v") << deviceNode() << mountPoint());
|
||||||
if (mountCmd.run() && mountCmd.exitCode() == 0)
|
if (mountCmd.run() && mountCmd.exitCode() == 0)
|
||||||
|
@ -321,7 +322,11 @@ bool Partition::unmount(Report& report)
|
||||||
setMountPoint(QString());
|
setMountPoint(QString());
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
ExternalCommand umountCmd(report, QStringLiteral("umount"), QStringList() << QStringLiteral("-v") << deviceNode());
|
ExternalCommand umountCmd(report,
|
||||||
|
QStringLiteral("umount"),
|
||||||
|
{ QStringLiteral("-v"),
|
||||||
|
QStringLiteral("-A"),
|
||||||
|
deviceNode() });
|
||||||
if (!umountCmd.run() || umountCmd.exitCode() != 0)
|
if (!umountCmd.run() || umountCmd.exitCode() != 0)
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Copyright (C) 2012 by Volker Lanz <vl@fidra.de> *
|
* Copyright (C) 2012 by Volker Lanz <vl@fidra.de> *
|
||||||
|
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or *
|
* This program is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU General Public License as *
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
@ -21,8 +22,10 @@
|
||||||
#include "util/capacity.h"
|
#include "util/capacity.h"
|
||||||
|
|
||||||
#include <blkid/blkid.h>
|
#include <blkid/blkid.h>
|
||||||
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
const std::array< QColor, FileSystem::__lastType > FileSystem::defaultColorCode =
|
const std::array< QColor, FileSystem::__lastType > FileSystem::defaultColorCode =
|
||||||
{
|
{
|
||||||
|
@ -103,6 +106,60 @@ static QString readBlkIdValue(const QString& deviceNode, const QString& tag)
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileSystem::Type FileSystem::detectFileSystem(const QString& partitionPath)
|
||||||
|
{
|
||||||
|
FileSystem::Type rval = FileSystem::Unknown;
|
||||||
|
|
||||||
|
blkid_cache cache;
|
||||||
|
if (blkid_get_cache(&cache, nullptr) == 0) {
|
||||||
|
blkid_dev dev;
|
||||||
|
|
||||||
|
if ((dev = blkid_get_dev(cache,
|
||||||
|
partitionPath.toLocal8Bit().constData(),
|
||||||
|
BLKID_DEV_NORMAL)) != nullptr) {
|
||||||
|
QString s = QString::fromUtf8(blkid_get_tag_value(cache,
|
||||||
|
"TYPE",
|
||||||
|
partitionPath.toLocal8Bit().constData()));
|
||||||
|
|
||||||
|
if (s == QStringLiteral("ext2")) rval = FileSystem::Ext2;
|
||||||
|
else if (s == QStringLiteral("ext3")) rval = FileSystem::Ext3;
|
||||||
|
else if (s.startsWith(QStringLiteral("ext4"))) rval = FileSystem::Ext4;
|
||||||
|
else if (s == QStringLiteral("swap")) rval = FileSystem::LinuxSwap;
|
||||||
|
else if (s == QStringLiteral("ntfs")) rval = FileSystem::Ntfs;
|
||||||
|
else if (s == QStringLiteral("reiserfs")) rval = FileSystem::ReiserFS;
|
||||||
|
else if (s == QStringLiteral("reiser4")) rval = FileSystem::Reiser4;
|
||||||
|
else if (s == QStringLiteral("xfs")) rval = FileSystem::Xfs;
|
||||||
|
else if (s == QStringLiteral("jfs")) rval = FileSystem::Jfs;
|
||||||
|
else if (s == QStringLiteral("hfs")) rval = FileSystem::Hfs;
|
||||||
|
else if (s == QStringLiteral("hfsplus")) rval = FileSystem::HfsPlus;
|
||||||
|
else if (s == QStringLiteral("ufs")) rval = FileSystem::Ufs;
|
||||||
|
else if (s == QStringLiteral("vfat")) {
|
||||||
|
// libblkid uses SEC_TYPE to distinguish between FAT16 and FAT32
|
||||||
|
QString st = QString::fromUtf8(blkid_get_tag_value(cache,
|
||||||
|
"SEC_TYPE",
|
||||||
|
partitionPath.toLocal8Bit().constData()));
|
||||||
|
if (st == QStringLiteral("msdos"))
|
||||||
|
rval = FileSystem::Fat16;
|
||||||
|
else
|
||||||
|
rval = FileSystem::Fat32;
|
||||||
|
} else if (s == QStringLiteral("btrfs")) rval = FileSystem::Btrfs;
|
||||||
|
else if (s == QStringLiteral("ocfs2")) rval = FileSystem::Ocfs2;
|
||||||
|
else if (s == QStringLiteral("zfs_member")) rval = FileSystem::Zfs;
|
||||||
|
else if (s == QStringLiteral("hpfs")) rval = FileSystem::Hpfs;
|
||||||
|
else if (s == QStringLiteral("crypto_LUKS")) rval = FileSystem::Luks;
|
||||||
|
else if (s == QStringLiteral("exfat")) rval = FileSystem::Exfat;
|
||||||
|
else if (s == QStringLiteral("nilfs2")) rval = FileSystem::Nilfs2;
|
||||||
|
else if (s == QStringLiteral("LVM2_member")) rval = FileSystem::Lvm2_PV;
|
||||||
|
else
|
||||||
|
qWarning() << "blkid: unknown file system type " << s << " on " << partitionPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
blkid_put_cache(cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
/** Reads the label for this FileSystem
|
/** Reads the label for this FileSystem
|
||||||
@param deviceNode the device node for the Partition the FileSystem is on
|
@param deviceNode the device node for the Partition the FileSystem is on
|
||||||
@return the FileSystem label or an empty string in case of error
|
@return the FileSystem label or an empty string in case of error
|
||||||
|
@ -384,8 +441,9 @@ void FileSystem::move(qint64 newStartSector)
|
||||||
@param mountPoint the mount point to mount the FileSystem on
|
@param mountPoint the mount point to mount the FileSystem on
|
||||||
@return true on success
|
@return true on success
|
||||||
*/
|
*/
|
||||||
bool FileSystem::mount(const QString& mountPoint)
|
bool FileSystem::mount(const QString &deviceNode, const QString &mountPoint)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(deviceNode);
|
||||||
Q_UNUSED(mountPoint);
|
Q_UNUSED(mountPoint);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Copyright (C) 2012 by Volker Lanz <vl@fidra.de> *
|
* Copyright (C) 2012 by Volker Lanz <vl@fidra.de> *
|
||||||
|
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or *
|
* This program is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU General Public License as *
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
@ -170,6 +171,7 @@ public:
|
||||||
static QString nameForType(FileSystem::Type t);
|
static QString nameForType(FileSystem::Type t);
|
||||||
static QList<FileSystem::Type> types();
|
static QList<FileSystem::Type> types();
|
||||||
static FileSystem::Type typeForName(const QString& s);
|
static FileSystem::Type typeForName(const QString& s);
|
||||||
|
static FileSystem::Type detectFileSystem(const QString& partitionPath);
|
||||||
|
|
||||||
virtual bool canMount(const QString&) const {
|
virtual bool canMount(const QString&) const {
|
||||||
return false; /**< @return true if this FileSystem can be mounted */
|
return false; /**< @return true if this FileSystem can be mounted */
|
||||||
|
@ -181,8 +183,8 @@ public:
|
||||||
virtual QString mountTitle() const;
|
virtual QString mountTitle() const;
|
||||||
virtual QString unmountTitle() const;
|
virtual QString unmountTitle() const;
|
||||||
|
|
||||||
virtual bool mount(const QString& mountPoint);
|
virtual bool mount(const QString& deviceNode, const QString& mountPoint);
|
||||||
virtual bool unmount(const QString& mountPoint);
|
virtual bool unmount(const QString& deviceNode);
|
||||||
|
|
||||||
qint64 firstSector() const {
|
qint64 firstSector() const {
|
||||||
return m_FirstSector; /**< @return the FileSystem's first sector */
|
return m_FirstSector; /**< @return the FileSystem's first sector */
|
||||||
|
|
|
@ -130,8 +130,10 @@ QString linuxswap::unmountTitle() const
|
||||||
return i18nc("@title:menu", "Deactivate swap");
|
return i18nc("@title:menu", "Deactivate swap");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool linuxswap::mount(const QString& deviceNode)
|
bool linuxswap::mount(const QString& deviceNode, const QString& mountPoint)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(mountPoint);
|
||||||
|
|
||||||
ExternalCommand cmd(QStringLiteral("swapon"), QStringList() << deviceNode);
|
ExternalCommand cmd(QStringLiteral("swapon"), QStringList() << deviceNode);
|
||||||
return cmd.run(-1) && cmd.exitCode() == 0;
|
return cmd.run(-1) && cmd.exitCode() == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,11 +55,11 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool mount(const QString& deviceNode);
|
virtual bool mount(const QString& deviceNode, const QString& mountPoint) override;
|
||||||
virtual bool unmount(const QString& deviceNode);
|
virtual bool unmount(const QString& deviceNode) override;
|
||||||
|
|
||||||
virtual QString mountTitle() const;
|
virtual QString mountTitle() const override;
|
||||||
virtual QString unmountTitle() const;
|
virtual QString unmountTitle() const override;
|
||||||
|
|
||||||
virtual CommandSupportType supportCreate() const {
|
virtual CommandSupportType supportCreate() const {
|
||||||
return m_Create;
|
return m_Create;
|
||||||
|
|
256
src/fs/luks.cpp
256
src/fs/luks.cpp
|
@ -1,6 +1,7 @@
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Copyright (C) 2012 by Volker Lanz <vl@fidra.de> *
|
* Copyright (C) 2012 by Volker Lanz <vl@fidra.de> *
|
||||||
* Copyright (C) 2013 by Andrius Štikonas <andrius@stikonas.eu> *
|
* Copyright (C) 2013 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||||
|
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or *
|
* This program is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU General Public License as *
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
@ -18,11 +19,14 @@
|
||||||
|
|
||||||
#include "fs/luks.h"
|
#include "fs/luks.h"
|
||||||
|
|
||||||
|
#include "fs/filesystemfactory.h"
|
||||||
|
|
||||||
#include "gui/decryptluksdialog.h"
|
#include "gui/decryptluksdialog.h"
|
||||||
|
|
||||||
#include "util/capacity.h"
|
#include "util/capacity.h"
|
||||||
#include "util/externalcommand.h"
|
#include "util/externalcommand.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
@ -45,11 +49,22 @@ FileSystem::CommandSupportType luks::m_SetLabel = FileSystem::cmdSupportNone;
|
||||||
FileSystem::CommandSupportType luks::m_UpdateUUID = FileSystem::cmdSupportNone;
|
FileSystem::CommandSupportType luks::m_UpdateUUID = FileSystem::cmdSupportNone;
|
||||||
FileSystem::CommandSupportType luks::m_GetUUID = FileSystem::cmdSupportNone;
|
FileSystem::CommandSupportType luks::m_GetUUID = FileSystem::cmdSupportNone;
|
||||||
|
|
||||||
luks::luks(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) :
|
luks::luks(qint64 firstsector,
|
||||||
FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Luks)
|
qint64 lastsector,
|
||||||
|
qint64 sectorsused,
|
||||||
|
const QString& label)
|
||||||
|
: FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Luks)
|
||||||
|
, m_innerFs(nullptr)
|
||||||
|
, m_isCryptOpen(false)
|
||||||
|
, m_isMounted(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
luks::~luks()
|
||||||
|
{
|
||||||
|
delete m_innerFs;
|
||||||
|
}
|
||||||
|
|
||||||
void luks::init()
|
void luks::init()
|
||||||
{
|
{
|
||||||
m_UpdateUUID = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone;
|
m_UpdateUUID = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone;
|
||||||
|
@ -88,39 +103,236 @@ qint64 luks::minCapacity() const
|
||||||
|
|
||||||
QString luks::mountTitle() const
|
QString luks::mountTitle() const
|
||||||
{
|
{
|
||||||
return i18nc("@title:menu", "Decrypt");
|
return i18nc("@title:menu", "Mount");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString luks::unmountTitle() const
|
QString luks::unmountTitle() const
|
||||||
|
{
|
||||||
|
return i18nc("@title:menu", "Unmount");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString luks::cryptOpenTitle() const
|
||||||
|
{
|
||||||
|
return i18nc("@title:menu", "Decrypt");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString luks::cryptCloseTitle() const
|
||||||
{
|
{
|
||||||
return i18nc("@title:menu", "Deactivate");
|
return i18nc("@title:menu", "Deactivate");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool luks::mount(const QString& deviceNode)
|
bool luks::canMount(const QString& deviceNode) const
|
||||||
{
|
{
|
||||||
QPointer<DecryptLuksDialog> dlg = new DecryptLuksDialog(0, deviceNode); //TODO: parent widget instead of 0
|
return m_isCryptOpen &&
|
||||||
|
!m_isMounted &&
|
||||||
|
m_innerFs &&
|
||||||
|
m_innerFs->canMount(deviceNode);
|
||||||
|
}
|
||||||
|
|
||||||
if (dlg->exec() == QDialog::Accepted)
|
bool luks::canUnmount(const QString& deviceNode) const
|
||||||
|
{
|
||||||
|
return m_isCryptOpen &&
|
||||||
|
m_isMounted &&
|
||||||
|
m_innerFs &&
|
||||||
|
m_innerFs->canUnmount(deviceNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool luks::isMounted() const
|
||||||
|
{
|
||||||
|
return m_isCryptOpen && m_isMounted;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool luks::canCryptOpen(const QString&) const
|
||||||
|
{
|
||||||
|
return !m_isCryptOpen && !m_isMounted;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool luks::canCryptClose(const QString&) const
|
||||||
|
{
|
||||||
|
return m_isCryptOpen && !m_isMounted;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool luks::isCryptOpen() const
|
||||||
|
{
|
||||||
|
return m_isCryptOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool luks::cryptOpen(const QString& deviceNode)
|
||||||
|
{
|
||||||
|
if (m_isCryptOpen)
|
||||||
{
|
{
|
||||||
std::vector<QString> commands;
|
if (!mapperName(deviceNode).isEmpty())
|
||||||
commands.push_back(QStringLiteral("echo"));
|
{
|
||||||
commands.push_back(QStringLiteral("cryptsetup"));
|
qWarning() << "LUKS device" << deviceNode
|
||||||
std::vector<QStringList> args;
|
<< "already decrypted."
|
||||||
args.push_back(QStringList() << dlg->luksPassphrase().text());
|
<< "Cannot decrypt again.";
|
||||||
args.push_back(QStringList() << QStringLiteral("luksOpen") << deviceNode << dlg->luksName().text());
|
return false;
|
||||||
ExternalCommand cmd(commands, args);
|
}
|
||||||
delete dlg;
|
else
|
||||||
return cmd.run(-1) && cmd.exitCode() == 0;
|
{
|
||||||
|
qWarning() << "LUKS device" << deviceNode
|
||||||
|
<< "reportedly decrypted but mapper node not found."
|
||||||
|
<< "Marking device as NOT decrypted and trying to "
|
||||||
|
"decrypt again anyway.";
|
||||||
|
m_isCryptOpen = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPointer<DecryptLuksDialog> dlg = new DecryptLuksDialog(0, deviceNode); //TODO: parent widget instead of 0
|
||||||
|
|
||||||
|
if (dlg->exec() != QDialog::Accepted)
|
||||||
|
{
|
||||||
|
delete dlg;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<QString> commands;
|
||||||
|
commands.push_back(QStringLiteral("echo"));
|
||||||
|
commands.push_back(QStringLiteral("cryptsetup"));
|
||||||
|
std::vector<QStringList> args;
|
||||||
|
args.push_back(QStringList() << dlg->luksPassphrase().text());
|
||||||
|
args.push_back(QStringList() << QStringLiteral("luksOpen") << deviceNode << dlg->luksName().text());
|
||||||
delete dlg;
|
delete dlg;
|
||||||
|
|
||||||
|
ExternalCommand cmd(commands, args);
|
||||||
|
if (!(cmd.run(-1) && cmd.exitCode() == 0))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (m_innerFs)
|
||||||
|
{
|
||||||
|
delete m_innerFs;
|
||||||
|
m_innerFs = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString mapperNode = mapperName(deviceNode);
|
||||||
|
if (mapperNode.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
FileSystem::Type innerFsType = detectFileSystem(mapperNode);
|
||||||
|
m_innerFs = FileSystemFactory::cloneWithNewType(innerFsType,
|
||||||
|
*this);
|
||||||
|
|
||||||
|
m_isCryptOpen = (m_innerFs != nullptr);
|
||||||
|
|
||||||
|
if (m_isCryptOpen)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool luks::cryptClose(const QString& deviceNode)
|
||||||
|
{
|
||||||
|
if (!m_isCryptOpen)
|
||||||
|
{
|
||||||
|
qWarning() << "Cannot close LUKS device" << deviceNode
|
||||||
|
<< "because it's not open.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_isMounted)
|
||||||
|
{
|
||||||
|
qWarning() << "Cannot close LUKS device" << deviceNode
|
||||||
|
<< "because the filesystem is mounted.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExternalCommand cmd(QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksClose") << mapperName(deviceNode));
|
||||||
|
if (!(cmd.run(-1) && cmd.exitCode() == 0))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
delete m_innerFs;
|
||||||
|
m_innerFs = nullptr;
|
||||||
|
|
||||||
|
m_isCryptOpen = (m_innerFs != nullptr);
|
||||||
|
|
||||||
|
if (!m_isCryptOpen)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool luks::mount(const QString& deviceNode, const QString& mountPoint)
|
||||||
|
{
|
||||||
|
if (!m_isCryptOpen)
|
||||||
|
{
|
||||||
|
qWarning() << "Cannot mount device" << deviceNode
|
||||||
|
<< "before decrypting it first.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_isMounted)
|
||||||
|
{
|
||||||
|
qWarning() << "Cannot mount device" << deviceNode
|
||||||
|
<< "because it's already mounted.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_ASSERT(m_innerFs);
|
||||||
|
|
||||||
|
QString mapperNode = mapperName(deviceNode);
|
||||||
|
if (mapperNode.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (m_innerFs->canMount(mapperNode))
|
||||||
|
{
|
||||||
|
if (m_innerFs->mount(mapperNode, mountPoint))
|
||||||
|
{
|
||||||
|
m_isMounted = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ExternalCommand mountCmd(
|
||||||
|
QStringLiteral("mount"),
|
||||||
|
{ QStringLiteral("-v"), mapperNode, mountPoint });
|
||||||
|
if (mountCmd.run() && mountCmd.exitCode() == 0)
|
||||||
|
{
|
||||||
|
m_isMounted = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool luks::unmount(const QString& deviceNode)
|
bool luks::unmount(const QString& deviceNode)
|
||||||
{
|
{
|
||||||
ExternalCommand cmd(QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksClose") << mapperName(deviceNode));
|
if (!m_isCryptOpen)
|
||||||
return cmd.run(-1) && cmd.exitCode() == 0;
|
{
|
||||||
|
qWarning() << "Cannot unmount device" << deviceNode
|
||||||
|
<< "before decrypting it first.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_isMounted)
|
||||||
|
{
|
||||||
|
qWarning() << "Cannot unmount device" << deviceNode
|
||||||
|
<< "because it's not mounted.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_ASSERT(m_innerFs);
|
||||||
|
|
||||||
|
QString mapperNode = mapperName(deviceNode);
|
||||||
|
if (mapperNode.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (m_innerFs->canUnmount(mapperNode))
|
||||||
|
{
|
||||||
|
if (m_innerFs->unmount(mapperNode))
|
||||||
|
{
|
||||||
|
m_isMounted = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ExternalCommand unmountCmd(
|
||||||
|
QStringLiteral("mount"),
|
||||||
|
{ QStringLiteral("-v"), QStringLiteral("-A"), mapperNode });
|
||||||
|
if (unmountCmd.run() && unmountCmd.exitCode() == 0)
|
||||||
|
{
|
||||||
|
m_isMounted = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString luks::readUUID(const QString& deviceNode) const
|
QString luks::readUUID(const QString& deviceNode) const
|
||||||
|
@ -140,16 +352,6 @@ bool luks::updateUUID(Report& report, const QString& deviceNode) const
|
||||||
return cmd.run(-1) && cmd.exitCode() == 0;
|
return cmd.run(-1) && cmd.exitCode() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool luks::canMount(const QString&) const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool luks::canUnmount(const QString&) const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString luks::mapperName(const QString& deviceNode)
|
QString luks::mapperName(const QString& deviceNode)
|
||||||
{
|
{
|
||||||
ExternalCommand cmd(QStringLiteral("find"), QStringList() << QStringLiteral("/dev/mapper/") << QStringLiteral("-exec") << QStringLiteral("cryptsetup") << QStringLiteral("status") << QStringLiteral("{}") << QStringLiteral(";"));
|
ExternalCommand cmd(QStringLiteral("find"), QStringList() << QStringLiteral("/dev/mapper/") << QStringLiteral("-exec") << QStringLiteral("cryptsetup") << QStringLiteral("status") << QStringLiteral("{}") << QStringLiteral(";"));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Copyright (C) 2012 by Volker Lanz <vl@fidra.de> *
|
* Copyright (C) 2012 by Volker Lanz <vl@fidra.de> *
|
||||||
|
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or *
|
* This program is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU General Public License as *
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
@ -23,7 +24,8 @@
|
||||||
|
|
||||||
#include "../fs/filesystem.h"
|
#include "../fs/filesystem.h"
|
||||||
|
|
||||||
#include <qglobal.h>
|
#include <QtGlobal>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
class Report;
|
class Report;
|
||||||
|
|
||||||
|
@ -38,6 +40,7 @@ class LIBKPMCORE_EXPORT luks : public FileSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
luks(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label);
|
luks(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label);
|
||||||
|
virtual ~luks();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void init();
|
static void init();
|
||||||
|
@ -85,13 +88,24 @@ public:
|
||||||
virtual QString readUUID(const QString& deviceNode) const;
|
virtual QString readUUID(const QString& deviceNode) const;
|
||||||
virtual bool updateUUID(Report& report, const QString& deviceNode) const;
|
virtual bool updateUUID(Report& report, const QString& deviceNode) const;
|
||||||
|
|
||||||
|
virtual QString mountTitle() const override;
|
||||||
|
virtual QString unmountTitle() const override;
|
||||||
|
QString cryptOpenTitle() const;
|
||||||
|
QString cryptCloseTitle() const;
|
||||||
|
|
||||||
virtual bool canMount(const QString&) const;
|
virtual bool canMount(const QString&) const;
|
||||||
virtual bool canUnmount(const QString&) const;
|
virtual bool canUnmount(const QString&) const;
|
||||||
|
bool isMounted() const;
|
||||||
|
|
||||||
virtual bool mount(const QString& deviceNode);
|
bool canCryptOpen(const QString& deviceNode) const;
|
||||||
virtual bool unmount(const QString& deviceNode);
|
bool canCryptClose(const QString& deviceNode) const;
|
||||||
virtual QString mountTitle() const;
|
bool isCryptOpen() const;
|
||||||
virtual QString unmountTitle() const;
|
|
||||||
|
bool cryptOpen(const QString& deviceNode);
|
||||||
|
bool cryptClose(const QString& deviceNode);
|
||||||
|
|
||||||
|
virtual bool mount(const QString& deviceNode, const QString& mountPoint) override;
|
||||||
|
virtual bool unmount(const QString& deviceNode) override;
|
||||||
|
|
||||||
static QString mapperName(const QString& deviceNode);
|
static QString mapperName(const QString& deviceNode);
|
||||||
|
|
||||||
|
@ -114,6 +128,12 @@ public:
|
||||||
static CommandSupportType m_SetLabel;
|
static CommandSupportType m_SetLabel;
|
||||||
static CommandSupportType m_UpdateUUID;
|
static CommandSupportType m_UpdateUUID;
|
||||||
static CommandSupportType m_GetUUID;
|
static CommandSupportType m_GetUUID;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FileSystem* m_innerFs;
|
||||||
|
|
||||||
|
bool m_isCryptOpen;
|
||||||
|
bool m_isMounted;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ file (GLOB pmlibpartedbackendplugin_SRCS *.cpp)
|
||||||
|
|
||||||
add_library(pmlibpartedbackendplugin SHARED ${pmlibpartedbackendplugin_SRCS})
|
add_library(pmlibpartedbackendplugin SHARED ${pmlibpartedbackendplugin_SRCS})
|
||||||
|
|
||||||
target_link_libraries(pmlibpartedbackendplugin kpmcore ${LIBPARTED_LIBS} ${BLKID_LIBRARIES} KF5::KIOCore KF5::I18n)
|
target_link_libraries(pmlibpartedbackendplugin kpmcore ${LIBPARTED_LIBS} KF5::KIOCore KF5::I18n)
|
||||||
|
|
||||||
install(TARGETS pmlibpartedbackendplugin DESTINATION ${PLUGIN_INSTALL_DIR})
|
install(TARGETS pmlibpartedbackendplugin DESTINATION ${PLUGIN_INSTALL_DIR})
|
||||||
kcoreaddons_desktop_to_json(pmlibpartedbackendplugin pmlibpartedbackendplugin.desktop)
|
kcoreaddons_desktop_to_json(pmlibpartedbackendplugin pmlibpartedbackendplugin.desktop)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Copyright (C) 2008-2012 by Volker Lanz <vl@fidra.de> *
|
* Copyright (C) 2008-2012 by Volker Lanz <vl@fidra.de> *
|
||||||
|
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or *
|
* This program is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU General Public License as *
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
@ -48,7 +49,6 @@
|
||||||
|
|
||||||
#include <parted/parted.h>
|
#include <parted/parted.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <blkid/blkid.h>
|
|
||||||
|
|
||||||
K_PLUGIN_FACTORY_WITH_JSON(LibPartedBackendFactory, "pmlibpartedbackendplugin.json", registerPlugin<LibPartedBackend>();)
|
K_PLUGIN_FACTORY_WITH_JSON(LibPartedBackendFactory, "pmlibpartedbackendplugin.json", registerPlugin<LibPartedBackend>();)
|
||||||
|
|
||||||
|
@ -345,8 +345,10 @@ void LibPartedBackend::scanDevicePartitions(PedDevice*, Device& d, PedDisk* pedD
|
||||||
QString mountPoint;
|
QString mountPoint;
|
||||||
bool mounted;
|
bool mounted;
|
||||||
if (fs->type() == FileSystem::Luks) {
|
if (fs->type() == FileSystem::Luks) {
|
||||||
mountPoint = FS::luks::mapperName(node);
|
mounted = dynamic_cast<FS::luks*>(fs)->isMounted();
|
||||||
mounted = (mountPoint != QString()) ? true : false;
|
mountPoint = mountPoints.findByDevice(FS::luks::mapperName(node)) ?
|
||||||
|
mountPoints.findByDevice(FS::luks::mapperName(node))->mountPoint() :
|
||||||
|
QString();
|
||||||
} else {
|
} else {
|
||||||
mountPoint = mountPoints.findByDevice(node) ? mountPoints.findByDevice(node)->mountPoint() : QString();
|
mountPoint = mountPoints.findByDevice(node) ? mountPoints.findByDevice(node)->mountPoint() : QString();
|
||||||
mounted = ped_partition_is_busy(pedPartition);
|
mounted = ped_partition_is_busy(pedPartition);
|
||||||
|
@ -481,67 +483,13 @@ FileSystem::Type LibPartedBackend::detectFileSystem(PedPartition* pedPartition)
|
||||||
char* pedPath = ped_partition_get_path(pedPartition);
|
char* pedPath = ped_partition_get_path(pedPartition);
|
||||||
|
|
||||||
if (pedPath)
|
if (pedPath)
|
||||||
rval = detectFileSystem(QString::fromUtf8(pedPath));
|
rval = FileSystem::detectFileSystem(QString::fromUtf8(pedPath));
|
||||||
|
|
||||||
free(pedPath);
|
free(pedPath);
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSystem::Type LibPartedBackend::detectFileSystem(const QString& partitionPath)
|
|
||||||
{
|
|
||||||
FileSystem::Type rval = FileSystem::Unknown;
|
|
||||||
|
|
||||||
blkid_cache cache;
|
|
||||||
if (blkid_get_cache(&cache, nullptr) == 0) {
|
|
||||||
blkid_dev dev;
|
|
||||||
|
|
||||||
if ((dev = blkid_get_dev(cache,
|
|
||||||
partitionPath.toLocal8Bit().constData(),
|
|
||||||
BLKID_DEV_NORMAL)) != nullptr) {
|
|
||||||
QString s = QString::fromUtf8(blkid_get_tag_value(cache,
|
|
||||||
"TYPE",
|
|
||||||
partitionPath.toLocal8Bit().constData()));
|
|
||||||
|
|
||||||
if (s == QStringLiteral("ext2")) rval = FileSystem::Ext2;
|
|
||||||
else if (s == QStringLiteral("ext3")) rval = FileSystem::Ext3;
|
|
||||||
else if (s.startsWith(QStringLiteral("ext4"))) rval = FileSystem::Ext4;
|
|
||||||
else if (s == QStringLiteral("swap")) rval = FileSystem::LinuxSwap;
|
|
||||||
else if (s == QStringLiteral("ntfs")) rval = FileSystem::Ntfs;
|
|
||||||
else if (s == QStringLiteral("reiserfs")) rval = FileSystem::ReiserFS;
|
|
||||||
else if (s == QStringLiteral("reiser4")) rval = FileSystem::Reiser4;
|
|
||||||
else if (s == QStringLiteral("xfs")) rval = FileSystem::Xfs;
|
|
||||||
else if (s == QStringLiteral("jfs")) rval = FileSystem::Jfs;
|
|
||||||
else if (s == QStringLiteral("hfs")) rval = FileSystem::Hfs;
|
|
||||||
else if (s == QStringLiteral("hfsplus")) rval = FileSystem::HfsPlus;
|
|
||||||
else if (s == QStringLiteral("ufs")) rval = FileSystem::Ufs;
|
|
||||||
else if (s == QStringLiteral("vfat")) {
|
|
||||||
// libblkid uses SEC_TYPE to distinguish between FAT16 and FAT32
|
|
||||||
QString st = QString::fromUtf8(blkid_get_tag_value(cache,
|
|
||||||
"SEC_TYPE",
|
|
||||||
partitionPath.toLocal8Bit().constData()));
|
|
||||||
if (st == QStringLiteral("msdos"))
|
|
||||||
rval = FileSystem::Fat16;
|
|
||||||
else
|
|
||||||
rval = FileSystem::Fat32;
|
|
||||||
} else if (s == QStringLiteral("btrfs")) rval = FileSystem::Btrfs;
|
|
||||||
else if (s == QStringLiteral("ocfs2")) rval = FileSystem::Ocfs2;
|
|
||||||
else if (s == QStringLiteral("zfs_member")) rval = FileSystem::Zfs;
|
|
||||||
else if (s == QStringLiteral("hpfs")) rval = FileSystem::Hpfs;
|
|
||||||
else if (s == QStringLiteral("crypto_LUKS")) rval = FileSystem::Luks;
|
|
||||||
else if (s == QStringLiteral("exfat")) rval = FileSystem::Exfat;
|
|
||||||
else if (s == QStringLiteral("nilfs2")) rval = FileSystem::Nilfs2;
|
|
||||||
else if (s == QStringLiteral("LVM2_member")) rval = FileSystem::Lvm2_PV;
|
|
||||||
else
|
|
||||||
qWarning() << "blkid: unknown file system type " << s << " on " << partitionPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
blkid_put_cache(cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
PedPartitionFlag LibPartedBackend::getPedFlag(PartitionTable::Flag flag)
|
PedPartitionFlag LibPartedBackend::getPedFlag(PartitionTable::Flag flag)
|
||||||
{
|
{
|
||||||
for (quint32 i = 0; i < sizeof(flagmap) / sizeof(flagmap[0]); i++)
|
for (quint32 i = 0; i < sizeof(flagmap) / sizeof(flagmap[0]); i++)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Copyright (C) 2008, 2010 by Volker Lanz <vl@fidra.de> *
|
* Copyright (C) 2008, 2010 by Volker Lanz <vl@fidra.de> *
|
||||||
|
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or *
|
* This program is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU General Public License as *
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
@ -70,7 +71,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static FileSystem::Type detectFileSystem(PedPartition* pedPartition);
|
static FileSystem::Type detectFileSystem(PedPartition* pedPartition);
|
||||||
static FileSystem::Type detectFileSystem(const QString& partitionPath);
|
|
||||||
static PedPartitionFlag getPedFlag(PartitionTable::Flag flag);
|
static PedPartitionFlag getPedFlag(PartitionTable::Flag flag);
|
||||||
static void scanDevicePartitions(PedDevice* pedDevice, Device& d, PedDisk* pedDisk);
|
static void scanDevicePartitions(PedDevice* pedDevice, Device& d, PedDisk* pedDisk);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue