diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dfc46f..f429f37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ find_package(KF5 REQUIRED IconThemes KIO Service + WidgetsAddons ) # use sane compile flags diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 47fa648..40f4c7c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,6 +45,7 @@ target_link_libraries( kpmcore KF5::IconThemes KF5::KIOCore KF5::Service + KF5::WidgetsAddons ) install(TARGETS kpmcore EXPORT KPMcoreTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/src/core/copysourcedevice.h b/src/core/copysourcedevice.h index cccfbe2..eaf08e1 100644 --- a/src/core/copysourcedevice.h +++ b/src/core/copysourcedevice.h @@ -43,16 +43,16 @@ public: ~CopySourceDevice(); public: - virtual bool open(); - virtual qint32 sectorSize() const; - virtual bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors); - virtual qint64 length() const; - virtual bool overlaps(const CopyTarget& target) const; + virtual bool open() override; + virtual qint32 sectorSize() const override; + virtual bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors) override; + virtual qint64 length() const override; + virtual bool overlaps(const CopyTarget& target) const override; - virtual qint64 firstSector() const { + virtual qint64 firstSector() const override { return m_FirstSector; /**< @return first sector to copying */ } - virtual qint64 lastSector() const { + virtual qint64 lastSector() const override { return m_LastSector; /**< @return last sector to copy */ } diff --git a/src/core/copysourcefile.h b/src/core/copysourcefile.h index 6d21a18..66f3e39 100644 --- a/src/core/copysourcefile.h +++ b/src/core/copysourcefile.h @@ -39,20 +39,20 @@ public: CopySourceFile(const QString& filename, qint32 sectorsize); public: - virtual bool open(); - virtual bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors); - virtual qint64 length() const; + virtual bool open() override; + virtual bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors) override; + virtual qint64 length() const override; - virtual qint32 sectorSize() const { + virtual qint32 sectorSize() const override { return m_SectorSize; /**< @return the file's sector size */ } - virtual bool overlaps(const CopyTarget&) const { + virtual bool overlaps(const CopyTarget&) const override { return false; /**< @return false for file */ } - virtual qint64 firstSector() const { + virtual qint64 firstSector() const override { return 0; /**< @return 0 for file */ } - virtual qint64 lastSector() const { + virtual qint64 lastSector() const override { return length(); /**< @return equal to length for file. @see length() */ } diff --git a/src/core/copysourceshred.h b/src/core/copysourceshred.h index 8fa2e8b..79aa1e0 100644 --- a/src/core/copysourceshred.h +++ b/src/core/copysourceshred.h @@ -37,20 +37,20 @@ public: CopySourceShred(qint64 size, qint32 sectorsize, bool randomShred); public: - virtual bool open(); - virtual bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors); - virtual qint64 length() const; + virtual bool open() override; + virtual bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors) override; + virtual qint64 length() const override; - virtual qint32 sectorSize() const { + virtual qint32 sectorSize() const override { return m_SectorSize; /**< @return the file's sector size */ } - virtual bool overlaps(const CopyTarget&) const { + virtual bool overlaps(const CopyTarget&) const override { return false; /**< @return false for shred source */ } - virtual qint64 firstSector() const { + virtual qint64 firstSector() const override { return 0; /**< @return 0 for shred source */ } - virtual qint64 lastSector() const { + virtual qint64 lastSector() const override { return length(); /**< @return equal to length for shred source. @see length() */ } diff --git a/src/core/copytargetdevice.h b/src/core/copytargetdevice.h index 00eb155..5b63eef 100644 --- a/src/core/copytargetdevice.h +++ b/src/core/copytargetdevice.h @@ -45,13 +45,13 @@ public: ~CopyTargetDevice(); public: - virtual bool open(); - virtual qint32 sectorSize() const; - virtual bool writeSectors(void* buffer, qint64 writeOffset, qint64 numSectors); - virtual qint64 firstSector() const { + virtual bool open() override; + virtual qint32 sectorSize() const override; + virtual bool writeSectors(void* buffer, qint64 writeOffset, qint64 numSectors) override; + virtual qint64 firstSector() const override { return m_FirstSector; /**< @return the first sector to write to */ } - virtual qint64 lastSector() const { + virtual qint64 lastSector() const override { return m_LastSector; /**< @return the last sector to write to */ } diff --git a/src/core/copytargetfile.h b/src/core/copytargetfile.h index 5e2e9ba..7a2624f 100644 --- a/src/core/copytargetfile.h +++ b/src/core/copytargetfile.h @@ -39,16 +39,16 @@ public: CopyTargetFile(const QString& filename, qint32 sectorsize); public: - virtual bool open(); - virtual bool writeSectors(void* buffer, qint64 writeOffset, qint64 numSectors); + virtual bool open() override; + virtual bool writeSectors(void* buffer, qint64 writeOffset, qint64 numSectors) override; - virtual qint32 sectorSize() const { + virtual qint32 sectorSize() const override { return m_SectorSize; /**< @return the file's sector size */ } - virtual qint64 firstSector() const { + virtual qint64 firstSector() const override { return 0; /**< @return always 0 for a file */ } - virtual qint64 lastSector() const { + virtual qint64 lastSector() const override { return sectorsWritten(); /**< @return the number of sectors written so far */ } diff --git a/src/core/device.cpp b/src/core/device.cpp index fd99e12..46bdc86 100644 --- a/src/core/device.cpp +++ b/src/core/device.cpp @@ -66,7 +66,7 @@ static qint32 getPhysicalSectorSize(const QString& device_node) if (f.open(QIODevice::ReadOnly)) { QByteArray a = f.readLine(); - return a.simplified().toInt(); + return a.trimmed().toInt(); } return -1; diff --git a/src/core/devicescanner.h b/src/core/devicescanner.h index 037eec6..24d78a0 100644 --- a/src/core/devicescanner.h +++ b/src/core/devicescanner.h @@ -46,7 +46,7 @@ Q_SIGNALS: void progress(const QString& device_node, int progress); protected: - virtual void run(); + virtual void run() override; OperationStack& operationStack() { return m_OperationStack; } diff --git a/src/core/partition.cpp b/src/core/partition.cpp index 36b4a94..d756621 100644 --- a/src/core/partition.cpp +++ b/src/core/partition.cpp @@ -1,5 +1,6 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * + * Copyright (C) 2015 by Teo Mrnjavac * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * @@ -294,7 +295,7 @@ bool Partition::mount(Report& report) bool success = false; if (fileSystem().canMount(deviceNode())) - success = fileSystem().mount(deviceNode()); + success = fileSystem().mount(deviceNode(), mountPoint()); else { ExternalCommand mountCmd(report, QStringLiteral("mount"), QStringList() << QStringLiteral("-v") << deviceNode() << mountPoint()); if (mountCmd.run() && mountCmd.exitCode() == 0) @@ -323,7 +324,11 @@ bool Partition::unmount(Report& report) setMountPoint(QString()); } 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) success = false; } diff --git a/src/core/partition.h b/src/core/partition.h index bbda5a3..9872392 100644 --- a/src/core/partition.h +++ b/src/core/partition.h @@ -124,21 +124,21 @@ public: return m_Number; /**< @return the Partition's device number, e.g. 7 for /dev/sdd7 */ } - bool isRoot() const { + bool isRoot() const override { return false; /**< @return always false for Partition */ } - PartitionNode* parent() { + PartitionNode* parent() override { return m_Parent; /**< @return the Partition's parent PartitionNode */ } - const PartitionNode* parent() const { + const PartitionNode* parent() const override { return m_Parent; /**< @return the Partition's parent PartitionNode */ } - Partitions& children() { + Partitions& children() override { return m_Children; /**< @return the Partition's children. empty for non-extended. */ } - const Partitions& children() const { + const Partitions& children() const override { return m_Children; /**< @return the Partition's children. empty for non-extended. */ } @@ -226,7 +226,7 @@ public: } protected: - void append(Partition* p) { + void append(Partition* p) override { m_Children.append(p); } void setDevicePath(const QString& s) { diff --git a/src/core/partitionrole.cpp b/src/core/partitionrole.cpp index 2805ce4..2900b89 100644 --- a/src/core/partitionrole.cpp +++ b/src/core/partitionrole.cpp @@ -1,6 +1,7 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * + * Copyright (C) 2016 by Teo Mrnjavac * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -36,5 +37,8 @@ QString PartitionRole::toString() const if (roles() & Primary) return i18nc("@item partition role", "primary"); + if (roles() & Luks) + return i18nc("@item partition role", "LUKS"); + return i18nc("@item partition role", "none"); } diff --git a/src/core/partitionrole.h b/src/core/partitionrole.h index 07b3cf1..4bc0e39 100644 --- a/src/core/partitionrole.h +++ b/src/core/partitionrole.h @@ -1,5 +1,6 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * + * Copyright (C) 2016 by Teo Mrnjavac * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -41,6 +42,7 @@ public: Extended = 2, /**< Extended */ Logical = 4, /**< Logical inside an extended */ Unallocated = 8, /**< No real Partition, just unallocated space */ + Luks = 16, /**< Encrypted partition with LUKS key management */ Any = 255 /**< In case we're looking for a Partition with a PartitionRole, any will do */ }; diff --git a/src/core/partitiontable.h b/src/core/partitiontable.h index 1531bc4..a67520f 100644 --- a/src/core/partitiontable.h +++ b/src/core/partitiontable.h @@ -97,30 +97,30 @@ public: ~PartitionTable(); public: - PartitionNode* parent() { + PartitionNode* parent() override { return nullptr; /**< @return always nullptr for PartitionTable */ } - const PartitionNode* parent() const { + const PartitionNode* parent() const override { return nullptr; /**< @return always nullptr for PartitionTable */ } - bool isRoot() const { + bool isRoot() const override { return true; /**< @return always true for PartitionTable */ } bool isReadOnly() const { return tableTypeIsReadOnly(type()); /**< @return true if the PartitionTable is read only */ } - Partitions& children() { + Partitions& children() override { return m_Children; /**< @return the children in this PartitionTable */ } - const Partitions& children() const { + const Partitions& children() const override { return m_Children; /**< @return the children in this PartitionTable */ } void setType(const Device& d, TableType t); - void append(Partition* partition); + void append(Partition* partition) override; qint64 freeSectorsBefore(const Partition& p) const; qint64 freeSectorsAfter(const Partition& p) const; diff --git a/src/fs/btrfs.cpp b/src/fs/btrfs.cpp index 32b41ed..cbf2de6 100644 --- a/src/fs/btrfs.cpp +++ b/src/fs/btrfs.cpp @@ -91,7 +91,7 @@ FileSystem::SupportTool btrfs::supportToolName() const qint64 btrfs::minCapacity() const { - return 40 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); + return 100 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } qint64 btrfs::maxCapacity() const @@ -145,7 +145,8 @@ bool btrfs::resize(Report& report, const QString& deviceNode, qint64 length) con { QStringLiteral("--verbose"), QStringLiteral("--types"), QStringLiteral("btrfs"), deviceNode, tempDir.path() }); if (mountCmd.run(-1) && mountCmd.exitCode() == 0) { - ExternalCommand resizeCmd(report, QStringLiteral("btrfs"), { QStringLiteral("filesystem"), QStringLiteral("resize"), QString::number(length), tempDir.path() }); + QString len = length == -1 ? QStringLiteral("max") : QString::number(length); + ExternalCommand resizeCmd(report, QStringLiteral("btrfs"), { QStringLiteral("filesystem"), QStringLiteral("resize"), len, tempDir.path() }); if (resizeCmd.run(-1) && resizeCmd.exitCode() == 0) rval = true; diff --git a/src/fs/btrfs.h b/src/fs/btrfs.h index 45b5326..c94dfe3 100644 --- a/src/fs/btrfs.h +++ b/src/fs/btrfs.h @@ -43,55 +43,55 @@ public: public: static void init(); - virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; - virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); - virtual bool updateUUID(Report& report, const QString& deviceNode) const; + virtual qint64 readUsedCapacity(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 resize(Report& report, const QString& deviceNode, qint64 length) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; + virtual bool updateUUID(Report& report, const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 minCapacity() const override; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/exfat.h b/src/fs/exfat.h index 16dd6e7..70ae9b2 100644 --- a/src/fs/exfat.h +++ b/src/fs/exfat.h @@ -42,55 +42,55 @@ public: public: static void init(); -// virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; -// virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); - virtual bool updateUUID(Report& report, const QString& deviceNode) const; +// virtual qint64 readUsedCapacity(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 resize(Report& report, const QString& deviceNode, qint64 length) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; + virtual bool updateUUID(Report& report, const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } // virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/ext2.cpp b/src/fs/ext2.cpp index 3ced65a..78f95af 100644 --- a/src/fs/ext2.cpp +++ b/src/fs/ext2.cpp @@ -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"), { deviceNode, len }); + const QStringList args = length == -1 ? QStringList() << deviceNode : QStringList() << deviceNode << len; + + ExternalCommand cmd(report, QStringLiteral("resize2fs"), args); return cmd.run(-1) && cmd.exitCode() == 0; } diff --git a/src/fs/ext2.h b/src/fs/ext2.h index 1c37b53..6f2426a 100644 --- a/src/fs/ext2.h +++ b/src/fs/ext2.h @@ -42,54 +42,54 @@ public: public: static void init(); - virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; - virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); - virtual bool updateUUID(Report& report, const QString& deviceNode) const; + virtual qint64 readUsedCapacity(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 resize(Report& report, const QString& deviceNode, qint64 length) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; + virtual bool updateUUID(Report& report, const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/ext3.h b/src/fs/ext3.h index 8a34b4f..3ebb02b 100644 --- a/src/fs/ext3.h +++ b/src/fs/ext3.h @@ -44,8 +44,8 @@ public: public: static void init() {} - virtual bool create(Report& report, const QString& deviceNode) const; - virtual qint64 maxCapacity() const; + virtual bool create(Report& report, const QString& deviceNode) const override; + virtual qint64 maxCapacity() const override; }; } diff --git a/src/fs/ext4.h b/src/fs/ext4.h index 7f971f0..3e12809 100644 --- a/src/fs/ext4.h +++ b/src/fs/ext4.h @@ -44,8 +44,8 @@ public: public: static void init() {} - virtual bool create(Report& report, const QString& deviceNode) const; - virtual qint64 maxCapacity() const; + virtual bool create(Report& report, const QString& deviceNode) const override; + virtual qint64 maxCapacity() const override; }; } diff --git a/src/fs/extended.h b/src/fs/extended.h index 571bc52..1a70340 100644 --- a/src/fs/extended.h +++ b/src/fs/extended.h @@ -45,22 +45,22 @@ public: public: static void init() {} - virtual bool create(Report&, const QString&) const; + virtual bool create(Report&, const QString&) const override; - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual bool supportToolFound() const { + virtual bool supportToolFound() const override { return true; } diff --git a/src/fs/f2fs.h b/src/fs/f2fs.h index 021a18e..8c2feb4 100644 --- a/src/fs/f2fs.h +++ b/src/fs/f2fs.h @@ -42,56 +42,56 @@ public: public: static void init(); -// virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; -// virtual qint64 readUsedCapacity(const QString& deviceNode) const; -// virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; -// virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); -// virtual bool updateUUID(Report& report, const QString& deviceNode) const; +// virtual qint64 readUsedCapacity(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 qint64 readUsedCapacity(const QString& deviceNode) const override; +// virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const override; +// virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; +// virtual bool updateUUID(Report& report, const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 minCapacity() const override; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/fat16.h b/src/fs/fat16.h index 94bb093..cc7fbc5 100644 --- a/src/fs/fat16.h +++ b/src/fs/fat16.h @@ -42,54 +42,54 @@ public: public: static void init(); - virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; - virtual bool updateUUID(Report& report, const QString& deviceNode) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); + virtual qint64 readUsedCapacity(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 updateUUID(Report& report, const QString& deviceNode) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 minCapacity() const override; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/fat32.h b/src/fs/fat32.h index 2999836..aac7b12 100644 --- a/src/fs/fat32.h +++ b/src/fs/fat32.h @@ -45,11 +45,11 @@ public: public: static void init() {} - virtual bool create(Report& report, const QString& deviceNode) const; - virtual bool updateUUID(Report& report, const QString& deviceNode) const; + virtual bool create(Report& report, const QString& deviceNode) const override; + virtual bool updateUUID(Report& report, const QString& deviceNode) const override; - virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; + virtual qint64 minCapacity() const override; + virtual qint64 maxCapacity() const override; }; } diff --git a/src/fs/filesystem.cpp b/src/fs/filesystem.cpp index f327ff7..8f87611 100644 --- a/src/fs/filesystem.cpp +++ b/src/fs/filesystem.cpp @@ -1,5 +1,6 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * + * Copyright (C) 2015 by Teo Mrnjavac * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * @@ -22,8 +23,10 @@ #include "util/capacity.h" #include + #include +#include const std::array< QColor, FileSystem::__lastType > FileSystem::defaultColorCode = { @@ -105,6 +108,61 @@ static QString readBlkIdValue(const QString& deviceNode, const QString& tag) 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 if (s == QStringLiteral("f2fs")) rval = FileSystem::F2fs; + else + qWarning() << "blkid: unknown file system type " << s << " on " << partitionPath; + } + + blkid_put_cache(cache); + } + + return rval; +} + /** Reads the label for this FileSystem @param deviceNode the device node for the Partition the FileSystem is on @return the FileSystem label or an empty string in case of error @@ -127,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 @@ -387,8 +445,9 @@ void FileSystem::move(qint64 newStartSector) @param mountPoint the mount point to mount the FileSystem on @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); return false; diff --git a/src/fs/filesystem.h b/src/fs/filesystem.h index c971758..be495a8 100644 --- a/src/fs/filesystem.h +++ b/src/fs/filesystem.h @@ -1,5 +1,6 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * + * Copyright (C) 2015 by Teo Mrnjavac * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * @@ -172,6 +173,7 @@ public: static QString nameForType(FileSystem::Type t); static QList types(); static FileSystem::Type typeForName(const QString& s); + static FileSystem::Type detectFileSystem(const QString& partitionPath); virtual bool canMount(const QString&) const { return false; /**< @return true if this FileSystem can be mounted */ @@ -183,8 +185,8 @@ public: virtual QString mountTitle() const; virtual QString unmountTitle() const; - virtual bool mount(const QString& mountPoint); - virtual bool unmount(const QString& mountPoint); + virtual bool mount(const QString& deviceNode, const QString& mountPoint); + virtual bool unmount(const QString& deviceNode); qint64 firstSector() const { return m_FirstSector; /**< @return the FileSystem's first sector */ diff --git a/src/fs/hfs.h b/src/fs/hfs.h index fa28d2e..35a9a7c 100644 --- a/src/fs/hfs.h +++ b/src/fs/hfs.h @@ -42,38 +42,38 @@ public: public: static void init(); - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; + virtual bool check(Report& report, const QString& deviceNode) const override; + virtual bool create(Report& report, const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/hfsplus.h b/src/fs/hfsplus.h index 8166b0f..3c23fd6 100644 --- a/src/fs/hfsplus.h +++ b/src/fs/hfsplus.h @@ -42,31 +42,31 @@ public: public: static void init(); - virtual bool check(Report& report, const QString& deviceNode) const; + virtual bool check(Report& report, const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/hpfs.h b/src/fs/hpfs.h index 59f783b..0ed004f 100644 --- a/src/fs/hpfs.h +++ b/src/fs/hpfs.h @@ -42,45 +42,45 @@ public: public: static void init(); - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 maxCapacity() const; - virtual bool supportToolFound() const { + virtual qint64 maxCapacity() const override; + virtual bool supportToolFound() const override { return true; } diff --git a/src/fs/jfs.h b/src/fs/jfs.h index 6b338e8..024f1eb 100644 --- a/src/fs/jfs.h +++ b/src/fs/jfs.h @@ -42,45 +42,45 @@ public: public: static void init(); - virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; - virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); + virtual qint64 readUsedCapacity(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 resize(Report& report, const QString& deviceNode, qint64 length) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 minCapacity() const override; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/linuxswap.cpp b/src/fs/linuxswap.cpp index 44fda2e..9645d6b 100644 --- a/src/fs/linuxswap.cpp +++ b/src/fs/linuxswap.cpp @@ -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("--uuid") << uuid; - args << deviceNode << QString::number(length / 1024); + args << deviceNode; ExternalCommand cmd(report, QStringLiteral("mkswap"), args); return cmd.run(-1) && cmd.exitCode() == 0; @@ -131,8 +132,9 @@ QString linuxswap::unmountTitle() const 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"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } diff --git a/src/fs/linuxswap.h b/src/fs/linuxswap.h index 4feec02..ed647e2 100644 --- a/src/fs/linuxswap.h +++ b/src/fs/linuxswap.h @@ -42,56 +42,56 @@ public: public: static void init(); - virtual bool create(Report& report, const QString& deviceNode) const; - virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); - virtual bool copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const; - virtual bool updateUUID(Report& report, const QString& deviceNode) const; + virtual bool create(Report& report, const QString& deviceNode) const override; + virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; + virtual bool copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const override; + virtual bool updateUUID(Report& report, const QString& deviceNode) const override; - virtual bool canMount(const QString&) const { + virtual bool canMount(const QString&) const override { return true; } - virtual bool canUnmount(const QString&) const { + virtual bool canUnmount(const QString&) const override { return true; } - virtual bool mount(const QString& deviceNode); - virtual bool unmount(const QString& deviceNode); + virtual bool mount(const QString& deviceNode, const QString& mountPoint) override; + virtual bool unmount(const QString& deviceNode) override; - virtual QString mountTitle() const; - virtual QString unmountTitle() const; + virtual QString mountTitle() const override; + virtual QString unmountTitle() const override; - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_Create; diff --git a/src/fs/luks.cpp b/src/fs/luks.cpp index 7782e11..15b903b 100644 --- a/src/fs/luks.cpp +++ b/src/fs/luks.cpp @@ -1,6 +1,7 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * Copyright (C) 2013 by Andrius Štikonas * + * Copyright (C) 2015-2016 by Teo Mrnjavac * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -18,17 +19,20 @@ #include "fs/luks.h" -#include "gui/decryptluksdialog.h" +#include "fs/filesystemfactory.h" #include "util/capacity.h" #include "util/externalcommand.h" +#include "util/report.h" +#include #include #include #include #include #include +#include namespace FS { @@ -45,89 +49,478 @@ FileSystem::CommandSupportType luks::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_GetUUID = FileSystem::cmdSupportNone; -luks::luks(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : - FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Luks) +luks::luks(qint64 firstsector, + 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() { + m_Create = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone; + m_SetLabel = cmdSupportFileSystem; + m_GetLabel = cmdSupportFileSystem; m_UpdateUUID = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone; + m_Grow = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone; + m_Shrink = m_Grow; + m_Check = cmdSupportCore; 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 { - return -// m_GetUsed != cmdSupportNone && -// m_GetLabel != cmdSupportNone && -// m_SetLabel != cmdSupportNone && -// m_Create != cmdSupportNone && -// m_Check != cmdSupportNone && + m_cryptsetupFound = + m_GetLabel != cmdSupportNone && + m_SetLabel != cmdSupportNone && + m_Create != cmdSupportNone && + m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && -// m_Grow != cmdSupportNone && -// m_Shrink != cmdSupportNone && + m_Grow != cmdSupportNone && + m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; + return m_cryptsetupFound && + ((m_isCryptOpen && m_innerFs) ? m_innerFs->supportToolFound() : true); } FileSystem::SupportTool luks::supportToolName() const { - return SupportTool(QStringLiteral("cryptsetup"), QUrl(QStringLiteral("https://code.google.com/p/cryptsetup/"))); + if (m_isCryptOpen && m_innerFs && m_cryptsetupFound) + return m_innerFs->supportToolName(); + return SupportTool(QStringLiteral("cryptsetup"), + QUrl(QStringLiteral("https://code.google.com/p/cryptsetup/"))); } -qint64 luks::minCapacity() const +bool luks::create(Report& report, const QString& deviceNode) const { - return 3 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); + Q_ASSERT(m_innerFs); + Q_ASSERT(!m_passphrase.isEmpty()); + + std::vector commands; + commands.push_back(QStringLiteral("echo")); + commands.push_back(QStringLiteral("cryptsetup")); + std::vector args; + args.push_back({ m_passphrase }); + args.push_back({ QStringLiteral("-s"), + QStringLiteral("512"), + QStringLiteral("luksFormat"), + deviceNode }); + + ExternalCommand createCmd(commands, args); + if (!(createCmd.run(-1) && createCmd.exitCode() == 0)) + return false; + + commands.clear(); + commands.push_back(QStringLiteral("echo")); + commands.push_back(QStringLiteral("cryptsetup")); + args.clear(); + args.push_back({ m_passphrase }); + args.push_back({ QStringLiteral("open"), + deviceNode, + suggestedMapperName(deviceNode) }); + + ExternalCommand openCmd(commands, args); + if (!(openCmd.run(-1) && openCmd.exitCode() == 0)) + return false; + + QString mapperNode = mapperName(deviceNode); + if (mapperNode.isEmpty()) + return false; + + if (!m_innerFs->create(report, mapperNode)) + return false; + + m_isCryptOpen = (m_innerFs != nullptr); + + if (m_isCryptOpen) + return true; + return false; } QString luks::mountTitle() const { - return i18nc("@title:menu", "Decrypt"); + return i18nc("@title:menu", "Mount"); } 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"); } -bool luks::mount(const QString& deviceNode) +void luks::setPassphrase(const QString& passphrase) { - QPointer dlg = new DecryptLuksDialog(0, deviceNode); //TODO: parent widget instead of 0 + m_passphrase = passphrase; +} - if (dlg->exec() == QDialog::Accepted) +QString luks::passphrase() const +{ + return m_passphrase; +} + +bool luks::canMount(const QString& deviceNode) const +{ + return m_isCryptOpen && + !m_isMounted && + m_innerFs && + m_innerFs->canMount(mapperName(deviceNode)); +} + +bool luks::canUnmount(const QString& deviceNode) const +{ + return m_isCryptOpen && + m_isMounted && + m_innerFs && + m_innerFs->canUnmount(mapperName(deviceNode)); +} + +bool luks::isMounted() const +{ + return m_isCryptOpen && m_isMounted; +} + +void luks::setMounted(bool mounted) +{ + m_isMounted = mounted; +} + +bool luks::canCryptOpen(const QString&) const +{ + return !m_isCryptOpen && !m_isMounted && supportToolFound(); +} + +bool luks::canCryptClose(const QString&) const +{ + return m_isCryptOpen && !m_isMounted && m_cryptsetupFound; +} + +bool luks::isCryptOpen() const +{ + return m_isCryptOpen; +} + +void luks::setCryptOpen(bool cryptOpen) +{ + m_isCryptOpen = cryptOpen; +} + +bool luks::cryptOpen(QWidget* parent, const QString& deviceNode) +{ + if (m_isCryptOpen) { - std::vector commands; - commands.push_back(QStringLiteral("echo")); - commands.push_back(QStringLiteral("cryptsetup")); - std::vector args; - args.push_back(QStringList() << dlg->luksPassphrase().text()); - args.push_back(QStringList() << QStringLiteral("luksOpen") << deviceNode << dlg->luksName().text()); - ExternalCommand cmd(commands, args); - delete dlg; - return cmd.run(-1) && cmd.exitCode() == 0; + if (!mapperName(deviceNode).isEmpty()) + { + qWarning() << "LUKS device" << deviceNode + << "already decrypted." + << "Cannot decrypt again."; + return false; + } + else + { + 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; + } } - delete dlg; + KPasswordDialog dlg( parent ); + dlg.setPrompt(i18n("Enter passphrase for %1:", deviceNode)); + if( !dlg.exec() ) + return false; + + QString passphrase = dlg.password(); + std::vector commands; + commands.push_back(QStringLiteral("echo")); + commands.push_back(QStringLiteral("cryptsetup")); + std::vector args; + args.push_back({ passphrase }); + args.push_back({ QStringLiteral("open"), + deviceNode, + suggestedMapperName(deviceNode) }); + + 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; + + loadInnerFileSystem(mapperNode); + m_isCryptOpen = (m_innerFs != nullptr); + + if (m_isCryptOpen) + { + m_passphrase = passphrase; + 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"), + { QStringLiteral("close"), mapperName(deviceNode) }); + if (!(cmd.run(-1) && cmd.exitCode() == 0)) + return false; + + delete m_innerFs; + m_innerFs = nullptr; + + m_passphrase.clear(); + setLabel({}); + setUUID(readUUID(deviceNode)); + setSectorsUsed(-1); + + m_isCryptOpen = (m_innerFs != nullptr); + + if (!m_isCryptOpen) + return true; + return false; +} + +void luks::loadInnerFileSystem(const QString& mapperNode) +{ + Q_ASSERT(!m_innerFs); + FileSystem::Type innerFsType = detectFileSystem(mapperNode); + m_innerFs = FileSystemFactory::cloneWithNewType(innerFsType, + *this); + setLabel(m_innerFs->readLabel(mapperNode)); + setUUID(m_innerFs->readUUID(mapperNode)); + if (m_innerFs->supportGetUsed() == FileSystem::cmdSupportFileSystem) // FIXME:also implement checking space if partition is mounted + setSectorsUsed(m_innerFs->readUsedCapacity(mapperNode)/m_logicalSectorSize); +} + +void luks::createInnerFileSystem(FileSystem::Type type) +{ + Q_ASSERT(!m_innerFs); + m_innerFs = FileSystemFactory::cloneWithNewType(type, *this); +} + +bool luks::check(Report& report, const QString& deviceNode) const +{ + Q_ASSERT(m_innerFs); + + QString mapperNode = mapperName(deviceNode); + if (mapperNode.isEmpty()) + return false; + + 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) + { + 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; } bool luks::unmount(const QString& deviceNode) { - ExternalCommand cmd(QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksClose") << mapperName(deviceNode)); - return cmd.run(-1) && cmd.exitCode() == 0; + if (!m_isCryptOpen) + { + 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("umount"), + { QStringLiteral("--verbose"), mapperNode }); + if (unmountCmd.run() && unmountCmd.exitCode() == 0) + { + m_isMounted = false; + return true; + } + } + return false; +} + +FileSystem::Type luks::type() const +{ + if (m_isCryptOpen && m_innerFs) + return m_innerFs->type(); + return FileSystem::Luks; +} + +QString luks::suggestedMapperName(const QString& deviceNode) const +{ + return QStringLiteral("luks-") + readOuterUUID(deviceNode); +} + +QString luks::readLabel(const QString& deviceNode) const +{ + if (m_isCryptOpen && m_innerFs) + return m_innerFs->readLabel(mapperName(deviceNode)); + return QString(); +} + +bool luks::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) +{ + Q_ASSERT(m_innerFs); + return m_innerFs->writeLabel(report, mapperName(deviceNode), newLabel); +} + +bool luks::resize(Report& report, const QString& deviceNode, qint64 newLength) const +{ + Q_ASSERT(m_innerFs); + + QString mapperNode = mapperName(deviceNode); + if (mapperNode.isEmpty()) + return false; + + qint64 payloadLength = newLength - getPayloadOffset(deviceNode).toInt() * m_logicalSectorSize; + if ( newLength - length() * m_logicalSectorSize > 0 ) + { + ExternalCommand cryptResizeCmd(report, QStringLiteral("cryptsetup"), { QStringLiteral("resize"), mapperNode }); + report.line() << xi18nc("@info/plain", "Resizing LUKS crypt on partition %1.", deviceNode); + + if (cryptResizeCmd.run(-1) && cryptResizeCmd.exitCode() == 0) + { + return m_innerFs->resize(report, mapperNode, newLength - getPayloadOffset(deviceNode).toInt() * m_logicalSectorSize); + } + else + report.line() << xi18nc("@info/plain", "Resizing encrypted file system on partition %1 failed.", deviceNode); + } + else if (m_innerFs->resize(report, mapperNode, payloadLength)) + { + ExternalCommand cryptResizeCmd(report, QStringLiteral("cryptsetup"), { QStringLiteral("--size"), QString::number(payloadLength / m_logicalSectorSize), QStringLiteral("resize"), mapperNode }); + report.line() << xi18nc("@info/plain", "Resizing LUKS crypt on partition %1.", deviceNode); + if (cryptResizeCmd.run(-1) && cryptResizeCmd.exitCode() == 0) + { + return true; + } + } + return false; } QString luks::readUUID(const QString& deviceNode) const { - ExternalCommand cmd(QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksUUID") << deviceNode); + if (m_isCryptOpen && m_innerFs) + return m_innerFs->readUUID(mapperName(deviceNode)); + return readOuterUUID(deviceNode); +} + +QString luks::readOuterUUID(const QString &deviceNode) const +{ + ExternalCommand cmd(QStringLiteral("cryptsetup"), + { QStringLiteral("luksUUID"), deviceNode }); if (cmd.run()) { - return cmd.output().simplified(); + return cmd.output().trimmed(); } return QStringLiteral("---"); } @@ -136,34 +529,36 @@ bool luks::updateUUID(Report& report, const QString& deviceNode) const { QUuid uuid = QUuid::createUuid(); - ExternalCommand cmd(report, QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksUUID") << deviceNode << QStringLiteral("--uuid") << uuid.toString()); + ExternalCommand cmd(report, + QStringLiteral("cryptsetup"), + { QStringLiteral("luksUUID"), + deviceNode, + QStringLiteral("--uuid"), + uuid.toString() }); 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) { - ExternalCommand cmd(QStringLiteral("find"), QStringList() << QStringLiteral("/dev/mapper/") << QStringLiteral("-exec") << QStringLiteral("cryptsetup") << QStringLiteral("status") << QStringLiteral("{}") << QStringLiteral(";")); - if (cmd.run()) { - QRegExp rxDeviceName(QStringLiteral("(/dev/mapper/[A-Za-z0-9-/]+) is active[A-Za-z0-9- \\.\n]+[A-Za-z0-9-: \n]+") + deviceNode); - if (rxDeviceName.indexIn(cmd.output()) > -1) - return rxDeviceName.cap(1); + ExternalCommand cmd(QStringLiteral("lsblk"), + { QStringLiteral("--raw"), + QStringLiteral("--noheadings"), + QStringLiteral("--output"), + QStringLiteral("name"), + deviceNode }); + if (cmd.run(-1) && cmd.exitCode() == 0) { + QStringList output=cmd.output().split(QStringLiteral("\n")); + output.removeFirst(); + if (!output.first().isEmpty()) + return QStringLiteral("/dev/mapper/") + output.first(); } return QString(); } QString luks::getCipherName(const QString& deviceNode) { - ExternalCommand cmd(QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksDump") << deviceNode); + ExternalCommand cmd(QStringLiteral("cryptsetup"), + { QStringLiteral("luksDump"), deviceNode }); if (cmd.run()) { QRegExp rxCipherName(QStringLiteral("(?:Cipher name:\\s+)([A-Za-z0-9-]+)")); if (rxCipherName.indexIn(cmd.output()) > -1) @@ -174,7 +569,8 @@ QString luks::getCipherName(const QString& deviceNode) QString luks::getCipherMode(const QString& deviceNode) { - ExternalCommand cmd(QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksDump") << deviceNode); + ExternalCommand cmd(QStringLiteral("cryptsetup"), + { QStringLiteral("luksDump"), deviceNode }); if (cmd.run()) { QRegExp rxCipherMode(QStringLiteral("(?:Cipher mode:\\s+)([A-Za-z0-9-]+)")); if (rxCipherMode.indexIn(cmd.output()) > -1) @@ -185,7 +581,8 @@ QString luks::getCipherMode(const QString& deviceNode) QString luks::getHashName(const QString& deviceNode) { - ExternalCommand cmd(QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksDump") << deviceNode); + ExternalCommand cmd(QStringLiteral("cryptsetup"), + { QStringLiteral("luksDump"), deviceNode }); if (cmd.run()) { QRegExp rxHash(QStringLiteral("(?:Hash spec:\\s+)([A-Za-z0-9-]+)")); if (rxHash.indexIn(cmd.output()) > -1) @@ -196,7 +593,8 @@ QString luks::getHashName(const QString& deviceNode) QString luks::getKeySize(const QString& deviceNode) { - ExternalCommand cmd(QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksDump") << deviceNode); + ExternalCommand cmd(QStringLiteral("cryptsetup"), + { QStringLiteral("luksDump"), deviceNode }); if (cmd.run()) { QRegExp rxKeySize(QStringLiteral("(?:MK bits:\\s+)(\\d+)")); if (rxKeySize.indexIn(cmd.output()) > -1) @@ -207,7 +605,8 @@ QString luks::getKeySize(const QString& deviceNode) QString luks::getPayloadOffset(const QString& deviceNode) { - ExternalCommand cmd(QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksDump") << deviceNode); + ExternalCommand cmd(QStringLiteral("cryptsetup"), + { QStringLiteral("luksDump"), deviceNode }); if (cmd.run()) { QRegExp rxPayloadOffset(QStringLiteral("(?:Payload offset:\\s+)(\\d+)")); if (rxPayloadOffset.indexIn(cmd.output()) > -1) @@ -215,4 +614,26 @@ 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; + } +} + } diff --git a/src/fs/luks.h b/src/fs/luks.h index de914d9..fbafe70 100644 --- a/src/fs/luks.h +++ b/src/fs/luks.h @@ -1,6 +1,7 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * Copyright (C) 2013 by Andrius Štikonas * + * Copyright (C) 2015-2016 by Teo Mrnjavac * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -25,6 +26,7 @@ #include "../fs/filesystem.h" #include +#include class Report; @@ -39,60 +41,105 @@ class LIBKPMCORE_EXPORT luks : public FileSystem { public: luks(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); + virtual ~luks(); public: static void init(); + virtual qint64 readUsedCapacity(const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { - return m_Grow; + virtual CommandSupportType supportGrow() const override { + if (!m_isCryptOpen) + return cmdSupportNone; + if (m_Grow && m_innerFs) + return m_innerFs->supportGrow(); + return cmdSupportNone; } - virtual CommandSupportType supportShrink() const { - return m_Shrink; + virtual CommandSupportType supportShrink() const override { + if (!m_isCryptOpen) + return cmdSupportNone; + if (m_Shrink && m_innerFs) + return m_innerFs->supportShrink(); + return cmdSupportNone; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { - return m_Check; + virtual CommandSupportType supportCheck() const override { + if (!m_isCryptOpen) + return cmdSupportNone; + if (m_Check && m_innerFs) + return m_innerFs->supportCheck(); + return cmdSupportNone; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 minCapacity() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; - virtual QString readUUID(const QString& deviceNode) const; - virtual bool updateUUID(Report& report, const QString& deviceNode) const; + void setLogicalSectorSize(unsigned int logicalSectorSize) { + m_logicalSectorSize = logicalSectorSize; + } - virtual bool canMount(const QString&) const; - virtual bool canUnmount(const QString&) const; + virtual bool check(Report& report, const QString& deviceNode) const override; + virtual bool create(Report &report, const QString &deviceNode) const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; + virtual QString readUUID(const QString& deviceNode) const override; + virtual bool updateUUID(Report& report, const QString& deviceNode) const override; + virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const override; + virtual QString readLabel(const QString& deviceNode) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; - virtual bool mount(const QString& deviceNode); - virtual bool unmount(const QString& deviceNode); - virtual QString mountTitle() const; - virtual QString unmountTitle() const; + virtual QString mountTitle() const override; + virtual QString unmountTitle() const override; + QString cryptOpenTitle() const; + QString cryptCloseTitle() const; + + void setPassphrase(const QString&); + QString passphrase() const; + + virtual bool canMount(const QString&) const override; + virtual bool canUnmount(const QString&) const override; + bool isMounted() const; + void setMounted(bool mounted); + + bool canCryptOpen(const QString& deviceNode) const; + bool canCryptClose(const QString& deviceNode) const; + bool isCryptOpen() const; + void setCryptOpen(bool cryptOpen); + + bool cryptOpen(QWidget* parent, const QString& deviceNode); + bool cryptClose(const QString& deviceNode); + + 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; + + QString suggestedMapperName(const QString& deviceNode) const; static QString mapperName(const QString& deviceNode); @@ -101,6 +148,10 @@ 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); + +protected: + virtual QString readOuterUUID(const QString& deviceNode) const; public: static CommandSupportType m_GetUsed; @@ -115,6 +166,15 @@ public: static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; + +private: + mutable FileSystem* m_innerFs; + + mutable bool m_isCryptOpen; + mutable bool m_cryptsetupFound; + QString m_passphrase; + bool m_isMounted; + unsigned int m_logicalSectorSize; }; } diff --git a/src/fs/lvm2_pv.h b/src/fs/lvm2_pv.h index 700548d..4dcba37 100644 --- a/src/fs/lvm2_pv.h +++ b/src/fs/lvm2_pv.h @@ -43,54 +43,54 @@ public: public: static void init(); -// virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; - virtual bool remove(Report& report, const QString& deviceNode) const; -// virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; -// virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); - virtual bool updateUUID(Report& report, const QString& deviceNode) const; +// virtual qint64 readUsedCapacity(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 remove(Report& report, const QString& deviceNode) const override; +// virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const override; +// virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; + virtual bool updateUUID(Report& report, const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 maxCapacity() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 maxCapacity() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/nilfs2.h b/src/fs/nilfs2.h index 04e40a2..44eb6d1 100644 --- a/src/fs/nilfs2.h +++ b/src/fs/nilfs2.h @@ -43,56 +43,56 @@ public: public: static void init(); -// virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; - virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); - virtual bool updateUUID(Report& report, const QString& deviceNode) const; +// virtual qint64 readUsedCapacity(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 qint64 readUsedCapacity(const QString& deviceNode) const override; + virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; + virtual bool updateUUID(Report& report, const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 minCapacity() const override; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/ntfs.cpp b/src/fs/ntfs.cpp index 9ee775d..fd21c30 100644 --- a/src/fs/ntfs.cpp +++ b/src/fs/ntfs.cpp @@ -123,19 +123,13 @@ qint64 ntfs::readUsedCapacity(const QString& deviceNode) const bool ntfs::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { - ExternalCommand writeCmd(report, QStringLiteral("ntfslabel"), { QStringLiteral("--force"), deviceNode, newLabel.simplified() }); + ExternalCommand writeCmd(report, QStringLiteral("ntfslabel"), { QStringLiteral("--force"), deviceNode, newLabel }); writeCmd.setProcessChannelMode(QProcess::SeparateChannels); if (!writeCmd.run(-1)) return false; - ExternalCommand testCmd(QStringLiteral("ntfslabel"), { QStringLiteral("--force"), deviceNode }); - testCmd.setProcessChannelMode(QProcess::SeparateChannels); - - if (!testCmd.run(-1)) - return false; - - return testCmd.output().simplified() == newLabel.simplified(); + return true; } bool ntfs::check(Report& report, const QString& deviceNode) const diff --git a/src/fs/ntfs.h b/src/fs/ntfs.h index 6c6f8a0..b8089cb 100644 --- a/src/fs/ntfs.h +++ b/src/fs/ntfs.h @@ -42,57 +42,57 @@ public: public: static void init(); - virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; - virtual bool copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const; - virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); - virtual bool updateUUID(Report& report, const QString& deviceNode) const; - virtual bool updateBootSector(Report& report, const QString& deviceNode) const; + virtual qint64 readUsedCapacity(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 copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const override; + virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; + virtual bool updateUUID(Report& report, const QString& deviceNode) const override; + virtual bool updateBootSector(Report& report, const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 minCapacity() const override; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/ocfs2.h b/src/fs/ocfs2.h index 4f477be..a9817b3 100644 --- a/src/fs/ocfs2.h +++ b/src/fs/ocfs2.h @@ -42,54 +42,54 @@ public: public: static void init(); - virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; - virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); - virtual bool updateUUID(Report& report, const QString& deviceNode) const; + virtual qint64 readUsedCapacity(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 resize(Report& report, const QString& deviceNode, qint64 length) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; + virtual bool updateUUID(Report& report, const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 minCapacity() const override; + virtual qint64 maxCapacity() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/reiser4.h b/src/fs/reiser4.h index f5edc14..6d85351 100644 --- a/src/fs/reiser4.h +++ b/src/fs/reiser4.h @@ -42,36 +42,36 @@ public: public: static void init(); - virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; + virtual qint64 readUsedCapacity(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 CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/reiserfs.cpp b/src/fs/reiserfs.cpp index 337969c..41925fb 100644 --- a/src/fs/reiserfs.cpp +++ b/src/fs/reiserfs.cpp @@ -148,7 +148,10 @@ bool reiserfs::create(Report& report, const QString& deviceNode) const bool reiserfs::resize(Report& report, const QString& deviceNode, qint64 length) const { - ExternalCommand cmd(report, QStringLiteral("resize_reiserfs"), { deviceNode, QStringLiteral("-q"), QStringLiteral("-s"), QString::number(length) }); + const QStringList args = length == -1 ? + QStringList() << deviceNode << QStringLiteral("-q") : + QStringList() << deviceNode << QStringLiteral("-q") << QStringLiteral("-s") << QString::number(length); + ExternalCommand cmd(report, QStringLiteral("resize_reiserfs"), args); bool rval = cmd.start(-1); diff --git a/src/fs/reiserfs.h b/src/fs/reiserfs.h index aa5ed60..f1edefe 100644 --- a/src/fs/reiserfs.h +++ b/src/fs/reiserfs.h @@ -44,55 +44,55 @@ public: public: static void init(); - virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; - virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); - virtual bool updateUUID(Report& report, const QString& deviceNode) const; + virtual qint64 readUsedCapacity(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 resize(Report& report, const QString& deviceNode, qint64 length) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; + virtual bool updateUUID(Report& report, const QString& deviceNode) const override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 minCapacity() const override; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/ufs.h b/src/fs/ufs.h index b07f0ed..dadee83 100644 --- a/src/fs/ufs.h +++ b/src/fs/ufs.h @@ -40,17 +40,17 @@ public: public: static void init() {} - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual bool supportToolFound() const { + virtual bool supportToolFound() const override { return true; } diff --git a/src/fs/unformatted.h b/src/fs/unformatted.h index d38283a..167e9b2 100644 --- a/src/fs/unformatted.h +++ b/src/fs/unformatted.h @@ -42,13 +42,13 @@ public: public: static void init() {} - virtual bool create(Report&, const QString&) const; + virtual bool create(Report&, const QString&) const override; - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual bool supportToolFound() const { + virtual bool supportToolFound() const override { return true; } diff --git a/src/fs/unknown.h b/src/fs/unknown.h index 6cc0cde..85a2b27 100644 --- a/src/fs/unknown.h +++ b/src/fs/unknown.h @@ -37,7 +37,7 @@ public: public: static void init() {} - virtual bool supportToolFound() const { + virtual bool supportToolFound() const override { return true; } }; diff --git a/src/fs/xfs.h b/src/fs/xfs.h index 520a33c..fe1f37e 100644 --- a/src/fs/xfs.h +++ b/src/fs/xfs.h @@ -42,46 +42,46 @@ public: public: static void init(); - virtual qint64 readUsedCapacity(const QString& deviceNode) const; - virtual bool check(Report& report, const QString& deviceNode) const; - virtual bool create(Report& report, const QString& deviceNode) const; - virtual bool copy(Report& report, const QString&, const QString&) const; - virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); + virtual qint64 readUsedCapacity(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 copy(Report& report, const QString&, const QString&) const override; + virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; - virtual qint64 maxLabelLength() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 minCapacity() const override; + virtual qint64 maxCapacity() const override; + virtual qint64 maxLabelLength() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/fs/zfs.h b/src/fs/zfs.h index b9d7845..5deb538 100644 --- a/src/fs/zfs.h +++ b/src/fs/zfs.h @@ -43,50 +43,50 @@ public: public: static void init(); - virtual bool remove(Report& report, const QString& deviceNode) const; - virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); + virtual bool remove(Report& report, const QString& deviceNode) const override; + virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; - virtual CommandSupportType supportGetUsed() const { + virtual CommandSupportType supportGetUsed() const override { return m_GetUsed; } - virtual CommandSupportType supportGetLabel() const { + virtual CommandSupportType supportGetLabel() const override { return m_GetLabel; } - virtual CommandSupportType supportCreate() const { + virtual CommandSupportType supportCreate() const override { return m_Create; } - virtual CommandSupportType supportGrow() const { + virtual CommandSupportType supportGrow() const override { return m_Grow; } - virtual CommandSupportType supportShrink() const { + virtual CommandSupportType supportShrink() const override { return m_Shrink; } - virtual CommandSupportType supportMove() const { + virtual CommandSupportType supportMove() const override { return m_Move; } - virtual CommandSupportType supportCheck() const { + virtual CommandSupportType supportCheck() const override { return m_Check; } - virtual CommandSupportType supportCopy() const { + virtual CommandSupportType supportCopy() const override { return m_Copy; } - virtual CommandSupportType supportBackup() const { + virtual CommandSupportType supportBackup() const override { return m_Backup; } - virtual CommandSupportType supportSetLabel() const { + virtual CommandSupportType supportSetLabel() const override { return m_SetLabel; } - virtual CommandSupportType supportUpdateUUID() const { + virtual CommandSupportType supportUpdateUUID() const override { return m_UpdateUUID; } - virtual CommandSupportType supportGetUUID() const { + virtual CommandSupportType supportGetUUID() const override { return m_GetUUID; } - virtual qint64 minCapacity() const; - virtual qint64 maxCapacity() const; - virtual SupportTool supportToolName() const; - virtual bool supportToolFound() const; + virtual qint64 minCapacity() const override; + virtual qint64 maxCapacity() const override; + virtual SupportTool supportToolName() const override; + virtual bool supportToolFound() const override; public: static CommandSupportType m_GetUsed; diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index be2f27a..9852f78 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -1,19 +1,11 @@ set(GUI_SRC - gui/decryptluksdialog.cpp - gui/decryptluksdialogwidget.cpp gui/partresizerwidget.cpp gui/partwidget.cpp gui/partwidgetbase.cpp ) set(GUI_LIB_HDRS - gui/decryptluksdialog.h - gui/decryptluksdialogwidget.h gui/partresizerwidget.h gui/partwidget.h gui/partwidgetbase.h ) - -set(gui_UIFILES - gui/decryptluksdialogwidgetbase.ui -) diff --git a/src/gui/decryptluksdialog.cpp b/src/gui/decryptluksdialog.cpp deleted file mode 100644 index d5a0cec..0000000 --- a/src/gui/decryptluksdialog.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/************************************************************************* - * Copyright (C) 2013 by Andrius Štikonas * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of * - * the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see .* - *************************************************************************/ - -#include "gui/decryptluksdialog.h" -#include "gui/decryptluksdialogwidget.h" - -#include "core/device.h" -#include "core/partitiontable.h" - -#include - -#include -#include - -DecryptLuksDialog::DecryptLuksDialog(QWidget* parent, const QString& deviceNode) : - QDialog(parent), - m_DialogWidget(new DecryptLuksDialogWidget(this)), - m_DeviceNode(deviceNode) -{ - QVBoxLayout *mainLayout = new QVBoxLayout(this); - setLayout(mainLayout); - mainLayout->addWidget(&widget()); - setWindowTitle(xi18nc("@title:window", "Decrypt LUKS partition on %1", this->deviceNode())); - - QDialogButtonBox* dialogButtonBox = new QDialogButtonBox; - QPushButton* decryptButton = new QPushButton; - decryptButton->setText(i18nc("@action:button", "&Decrypt")); - decryptButton->setIcon(QIcon::fromTheme(QStringLiteral("object-unlocked"))); - dialogButtonBox->addButton(decryptButton, QDialogButtonBox::AcceptRole); - mainLayout->addWidget(dialogButtonBox); - connect(dialogButtonBox, SIGNAL(accepted()), this, SLOT(accept())); -} diff --git a/src/gui/decryptluksdialog.h b/src/gui/decryptluksdialog.h deleted file mode 100644 index a8e5ffe..0000000 --- a/src/gui/decryptluksdialog.h +++ /dev/null @@ -1,53 +0,0 @@ -/************************************************************************* - * Copyright (C) 2013 by Andrius Štikonas * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of * - * the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see .* - *************************************************************************/ - -#if !defined(DECRYPTLUKSDIALOG__H) - -#define DECRYPTLUKSDIALOG__H - -#include "gui/decryptluksdialogwidget.h" - -#include - -class Device; - -class DecryptLuksDialog : public QDialog -{ - Q_OBJECT - - public: - DecryptLuksDialog(QWidget* parent, const QString& deviceNode); - - protected: - DecryptLuksDialogWidget& widget() { return *m_DialogWidget; } - const DecryptLuksDialogWidget& widget() const { return *m_DialogWidget; } - const QString& deviceNode() const { return m_DeviceNode; } - - private: - DecryptLuksDialogWidget* m_DialogWidget; - const QString& m_DeviceNode; - - public: - QLineEdit& luksName() { return widget().luksName(); } - const QLineEdit& luksName() const { return widget().luksName(); } - - QLineEdit& luksPassphrase() { return widget().luksPassphrase(); } - const QLineEdit& luksPassphrase() const { return widget().luksPassphrase(); } -}; - - -#endif diff --git a/src/gui/decryptluksdialogwidget.cpp b/src/gui/decryptluksdialogwidget.cpp deleted file mode 100644 index bd80e30..0000000 --- a/src/gui/decryptluksdialogwidget.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************************************* - * Copyright (C) 2013 by Andrius Štikonas * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of * - * the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see .* - *************************************************************************/ - -#include "gui/decryptluksdialogwidget.h" - -DecryptLuksDialogWidget::DecryptLuksDialogWidget(QWidget* parent) : - QWidget(parent) -{ - setupUi(this); -} diff --git a/src/gui/decryptluksdialogwidget.h b/src/gui/decryptluksdialogwidget.h deleted file mode 100644 index d4d10b0..0000000 --- a/src/gui/decryptluksdialogwidget.h +++ /dev/null @@ -1,42 +0,0 @@ -/************************************************************************* - * Copyright (C) 2013 by Andrius Štikonas * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of * - * the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see .* - *************************************************************************/ - -#if !defined(DECRYPTLUKSDIALOGWIDGET__H) - -#define DECRYPTLUKSDIALOGWIDGET__H - -#include "ui_decryptluksdialogwidgetbase.h" - -#include -#include - -class DecryptLuksDialogWidget : public QWidget, public Ui::DecryptLuksDialogWidgetBase -{ - Q_OBJECT - - public: - DecryptLuksDialogWidget(QWidget* parent); - - public: - QLineEdit& luksName() { return *m_LineEditName; } - const QLineEdit& luksName() const { return *m_LineEditName; } - - QLineEdit& luksPassphrase() { return *m_LineEditPassphrase; } - const QLineEdit& luksPassphrase() const { return *m_LineEditPassphrase; } -}; - -#endif diff --git a/src/gui/decryptluksdialogwidgetbase.ui b/src/gui/decryptluksdialogwidgetbase.ui deleted file mode 100644 index a26346d..0000000 --- a/src/gui/decryptluksdialogwidgetbase.ui +++ /dev/null @@ -1,71 +0,0 @@ - - - DecryptLuksDialogWidgetBase - - - - 0 - 0 - 377 - 122 - - - - - 10 - - - - - - - &Name: - - - m_LineEditName - - - - - - - - - - &Passphrase: - - - m_LineEditPassphrase - - - - - - - QLineEdit::Password - - - - - - - - - Qt::Vertical - - - QSizePolicy::MinimumExpanding - - - - 20 - 20 - - - - - - - - - diff --git a/src/jobs/backupfilesystemjob.h b/src/jobs/backupfilesystemjob.h index 3d8da48..3ab4e18 100644 --- a/src/jobs/backupfilesystemjob.h +++ b/src/jobs/backupfilesystemjob.h @@ -39,9 +39,9 @@ public: BackupFileSystemJob(Device& sourcedevice, Partition& sourcepartition, const QString& filename); public: - virtual bool run(Report& parent); - virtual qint32 numSteps() const; - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual qint32 numSteps() const override; + virtual QString description() const override; protected: Partition& sourcePartition() { diff --git a/src/jobs/checkfilesystemjob.h b/src/jobs/checkfilesystemjob.h index 7e84743..2f82282 100644 --- a/src/jobs/checkfilesystemjob.h +++ b/src/jobs/checkfilesystemjob.h @@ -35,8 +35,8 @@ public: CheckFileSystemJob(Partition& p); public: - virtual bool run(Report& parent); - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual QString description() const override; protected: Partition& partition() { diff --git a/src/jobs/copyfilesystemjob.h b/src/jobs/copyfilesystemjob.h index dd4b39f..18ecfd8 100644 --- a/src/jobs/copyfilesystemjob.h +++ b/src/jobs/copyfilesystemjob.h @@ -41,9 +41,9 @@ public: CopyFileSystemJob(Device& targetdevice, Partition& targetpartition, Device& sourcedevice, Partition& sourcepartition); public: - virtual bool run(Report& parent); - virtual qint32 numSteps() const; - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual qint32 numSteps() const override; + virtual QString description() const override; protected: Partition& targetPartition() { diff --git a/src/jobs/createfilesystemjob.h b/src/jobs/createfilesystemjob.h index c9ced7c..b8573bb 100644 --- a/src/jobs/createfilesystemjob.h +++ b/src/jobs/createfilesystemjob.h @@ -36,8 +36,8 @@ public: CreateFileSystemJob(Device& d, Partition& p); public: - virtual bool run(Report& parent); - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual QString description() const override; protected: Partition& partition() { diff --git a/src/jobs/createpartitionjob.h b/src/jobs/createpartitionjob.h index cf86f10..077a0bf 100644 --- a/src/jobs/createpartitionjob.h +++ b/src/jobs/createpartitionjob.h @@ -36,8 +36,8 @@ public: CreatePartitionJob(Device& d, Partition& p); public: - virtual bool run(Report& parent); - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual QString description() const override; protected: Partition& partition() { diff --git a/src/jobs/createpartitiontablejob.h b/src/jobs/createpartitiontablejob.h index 7089ee4..67e1857 100644 --- a/src/jobs/createpartitiontablejob.h +++ b/src/jobs/createpartitiontablejob.h @@ -35,8 +35,8 @@ public: CreatePartitionTableJob(Device& d); public: - virtual bool run(Report& parent); - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual QString description() const override; protected: Device& device() { diff --git a/src/jobs/deletefilesystemjob.h b/src/jobs/deletefilesystemjob.h index 36e53ad..db305a4 100644 --- a/src/jobs/deletefilesystemjob.h +++ b/src/jobs/deletefilesystemjob.h @@ -39,8 +39,8 @@ public: DeleteFileSystemJob(Device& d, Partition& p); public: - virtual bool run(Report& parent); - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual QString description() const override; protected: Partition& partition() { diff --git a/src/jobs/deletepartitionjob.h b/src/jobs/deletepartitionjob.h index 9bf642f..fa55ce4 100644 --- a/src/jobs/deletepartitionjob.h +++ b/src/jobs/deletepartitionjob.h @@ -36,8 +36,8 @@ public: DeletePartitionJob(Device& d, Partition& p); public: - virtual bool run(Report& parent); - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual QString description() const override; protected: Partition& partition() { diff --git a/src/jobs/movefilesystemjob.h b/src/jobs/movefilesystemjob.h index be0c171..44b4b44 100644 --- a/src/jobs/movefilesystemjob.h +++ b/src/jobs/movefilesystemjob.h @@ -39,9 +39,9 @@ public: MoveFileSystemJob(Device& d, Partition& p, qint64 newstart); public: - virtual bool run(Report& parent); - virtual qint32 numSteps() const; - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual qint32 numSteps() const override; + virtual QString description() const override; protected: Partition& partition() { diff --git a/src/jobs/resizefilesystemjob.h b/src/jobs/resizefilesystemjob.h index 13129cf..56d6865 100644 --- a/src/jobs/resizefilesystemjob.h +++ b/src/jobs/resizefilesystemjob.h @@ -40,9 +40,9 @@ public: ResizeFileSystemJob(Device& d, Partition& p, qint64 newlength = -1); public: - virtual bool run(Report& parent); - virtual qint32 numSteps() const; - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual qint32 numSteps() const override; + virtual QString description() const override; protected: bool resizeFileSystemBackend(Report& report); diff --git a/src/jobs/restorefilesystemjob.h b/src/jobs/restorefilesystemjob.h index 1b36db4..fecca52 100644 --- a/src/jobs/restorefilesystemjob.h +++ b/src/jobs/restorefilesystemjob.h @@ -39,9 +39,9 @@ public: RestoreFileSystemJob(Device& targetdevice, Partition& targetpartition, const QString& filename); public: - virtual bool run(Report& parent); - virtual qint32 numSteps() const; - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual qint32 numSteps() const override; + virtual QString description() const override; protected: Partition& targetPartition() { diff --git a/src/jobs/setfilesystemlabeljob.h b/src/jobs/setfilesystemlabeljob.h index a426d70..49573a4 100644 --- a/src/jobs/setfilesystemlabeljob.h +++ b/src/jobs/setfilesystemlabeljob.h @@ -38,8 +38,8 @@ public: SetFileSystemLabelJob(Partition& p, const QString& newlabel); public: - virtual bool run(Report& parent); - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual QString description() const override; protected: Partition& partition() { diff --git a/src/jobs/setpartflagsjob.h b/src/jobs/setpartflagsjob.h index 4a1b87c..51ca4a4 100644 --- a/src/jobs/setpartflagsjob.h +++ b/src/jobs/setpartflagsjob.h @@ -41,9 +41,9 @@ public: SetPartFlagsJob(Device& d, Partition& p, PartitionTable::Flags flags); public: - virtual bool run(Report& parent); - virtual qint32 numSteps() const; - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual qint32 numSteps() const override; + virtual QString description() const override; protected: Device& device() { diff --git a/src/jobs/setpartgeometryjob.h b/src/jobs/setpartgeometryjob.h index 08ec789..d413083 100644 --- a/src/jobs/setpartgeometryjob.h +++ b/src/jobs/setpartgeometryjob.h @@ -43,8 +43,8 @@ public: SetPartGeometryJob(Device& d, Partition& p, qint64 newstart, qint64 newlength); public: - virtual bool run(Report& parent); - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual QString description() const override; protected: Partition& partition() { diff --git a/src/jobs/shredfilesystemjob.h b/src/jobs/shredfilesystemjob.h index 0f28c13..785a416 100644 --- a/src/jobs/shredfilesystemjob.h +++ b/src/jobs/shredfilesystemjob.h @@ -39,9 +39,9 @@ public: ShredFileSystemJob(Device& d, Partition& p, bool randomShred); public: - virtual bool run(Report& parent); - virtual qint32 numSteps() const; - virtual QString description() const; + virtual bool run(Report& parent) override; + virtual qint32 numSteps() const override; + virtual QString description() const override; protected: Partition& partition() { diff --git a/src/ops/backupoperation.h b/src/ops/backupoperation.h index fc65758..0526463 100644 --- a/src/ops/backupoperation.h +++ b/src/ops/backupoperation.h @@ -42,17 +42,17 @@ public: BackupOperation(Device& targetDevice, Partition& backupPartition, const QString& filename); public: - QString iconName() const { + QString iconName() const override { return QStringLiteral("document-export"); } - QString description() const; - void preview() {} - void undo() {} + QString description() const override; + void preview() override {} + void undo() override {} - virtual bool targets(const Device&) const { + virtual bool targets(const Device&) const override { return false; } - virtual bool targets(const Partition&) const { + virtual bool targets(const Partition&) const override{ return false; } diff --git a/src/ops/checkoperation.h b/src/ops/checkoperation.h index d16d6e0..cb523c8 100644 --- a/src/ops/checkoperation.h +++ b/src/ops/checkoperation.h @@ -45,15 +45,15 @@ public: CheckOperation(Device& targetDevice, Partition& checkedPartition); public: - QString iconName() const { + QString iconName() const override { return QStringLiteral("flag"); } - QString description() const; - void preview() {} - void undo() {} + QString description() const override; + void preview() override {} + void undo() override {} - virtual bool targets(const Device& d) const; - virtual bool targets(const Partition& p) const; + virtual bool targets(const Device& d) const override; + virtual bool targets(const Partition& p) const override; static bool canCheck(const Partition* p); diff --git a/src/ops/copyoperation.h b/src/ops/copyoperation.h index 9c9a501..a62f67f 100644 --- a/src/ops/copyoperation.h +++ b/src/ops/copyoperation.h @@ -55,19 +55,19 @@ public: ~CopyOperation(); public: - QString iconName() const { + QString iconName() const override { return QStringLiteral("edit-copy"); } - QString description() const { + QString description() const override { return m_Description; } - bool execute(Report& parent); - void preview(); - void undo(); + bool execute(Report& parent) override; + void preview() override; + void undo() override; - virtual bool targets(const Device& d) const; - virtual bool targets(const Partition& p) const; + virtual bool targets(const Device& d) const override; + virtual bool targets(const Partition& p) const override; static bool canCopy(const Partition* p); static bool canPaste(const Partition* p, const Partition* source); diff --git a/src/ops/createfilesystemoperation.h b/src/ops/createfilesystemoperation.h index bed0db8..53581bb 100644 --- a/src/ops/createfilesystemoperation.h +++ b/src/ops/createfilesystemoperation.h @@ -53,16 +53,16 @@ public: ~CreateFileSystemOperation(); public: - QString iconName() const { + QString iconName() const override { return QStringLiteral("draw-eraser"); } - QString description() const; - void preview(); - void undo(); - bool execute(Report& parent); + QString description() const override; + void preview() override; + void undo() override; + bool execute(Report& parent) override; - virtual bool targets(const Device& d) const; - virtual bool targets(const Partition& p) const; + virtual bool targets(const Device& d) const override; + virtual bool targets(const Partition& p) const override; protected: Device& targetDevice() { diff --git a/src/ops/createpartitiontableoperation.h b/src/ops/createpartitiontableoperation.h index e4b12b0..153dcab 100644 --- a/src/ops/createpartitiontableoperation.h +++ b/src/ops/createpartitiontableoperation.h @@ -49,16 +49,16 @@ public: ~CreatePartitionTableOperation(); public: - QString iconName() const { + QString iconName() const override { return QStringLiteral("edit-clear"); } - QString description() const; - void preview(); - void undo(); - bool execute(Report& parent); + QString description() const override; + void preview() override; + void undo() override; + bool execute(Report& parent) override; - virtual bool targets(const Device& d) const; - virtual bool targets(const Partition&) const { + virtual bool targets(const Device& d) const override; + virtual bool targets(const Partition&) const override{ return false; } diff --git a/src/ops/deleteoperation.cpp b/src/ops/deleteoperation.cpp index 6f4fe34..8b8f996 100644 --- a/src/ops/deleteoperation.cpp +++ b/src/ops/deleteoperation.cpp @@ -21,6 +21,7 @@ #include "core/partition.h" #include "core/device.h" #include "core/partitiontable.h" +#include "fs/luks.h" #include "jobs/deletepartitionjob.h" #include "jobs/deletefilesystemjob.h" @@ -123,5 +124,16 @@ bool DeleteOperation::canDelete(const Partition* p) if (p->roles().has(PartitionRole::Extended)) return p->children().size() == 1 && p->children()[0]->roles().has(PartitionRole::Unallocated); + if (p->roles().has(PartitionRole::Luks)) + { + const FileSystem& fsRef = p->fileSystem(); + const FS::luks* luksFs = dynamic_cast(&fsRef); + if (!luksFs) + return false; + + if (luksFs->isCryptOpen() || luksFs->isMounted()) + return false; + } + return true; } diff --git a/src/ops/deleteoperation.h b/src/ops/deleteoperation.h index 73972dd..be0b2cd 100644 --- a/src/ops/deleteoperation.h +++ b/src/ops/deleteoperation.h @@ -54,20 +54,20 @@ public: ~DeleteOperation(); public: - QString iconName() const { + QString iconName() const override { return shredAction() == NoShred ? QStringLiteral("edit-delete") : QStringLiteral("edit-delete-shred"); } - QString description() const; - void preview(); - void undo(); + QString description() const override; + void preview() override; + void undo() override; ShredAction shredAction() const { return m_ShredAction; } - virtual bool targets(const Device& d) const; - virtual bool targets(const Partition& p) const; + virtual bool targets(const Device& d) const override; + virtual bool targets(const Partition& p) const override; static bool canDelete(const Partition* p); diff --git a/src/ops/newoperation.h b/src/ops/newoperation.h index 080adc0..9abad30 100644 --- a/src/ops/newoperation.h +++ b/src/ops/newoperation.h @@ -53,15 +53,15 @@ public: ~NewOperation(); public: - QString iconName() const { + QString iconName() const override { return QStringLiteral("document-new"); } - QString description() const; - void preview(); - void undo(); + QString description() const override; + void preview() override; + void undo() override; - virtual bool targets(const Device& d) const; - virtual bool targets(const Partition& p) const; + virtual bool targets(const Device& d) const override; + virtual bool targets(const Partition& p) const override; static bool canCreateNew(const Partition* p); static Partition* createNew(const Partition& cloneFrom, FileSystem::Type type); diff --git a/src/ops/resizeoperation.h b/src/ops/resizeoperation.h index 4eed013..cffc2b1 100644 --- a/src/ops/resizeoperation.h +++ b/src/ops/resizeoperation.h @@ -75,16 +75,16 @@ public: ResizeOperation(Device& d, Partition& p, qint64 newfirst, qint64 newlast); public: - QString iconName() const { + QString iconName() const override { return QStringLiteral("arrow-right-double"); } - QString description() const; - bool execute(Report& parent); - void preview(); - void undo(); + QString description() const override; + bool execute(Report& parent) override; + void preview() override; + void undo() override; - virtual bool targets(const Device& d) const; - virtual bool targets(const Partition& p) const; + virtual bool targets(const Device& d) const override; + virtual bool targets(const Partition& p) const override; static bool canGrow(const Partition* p); static bool canShrink(const Partition* p); diff --git a/src/ops/restoreoperation.h b/src/ops/restoreoperation.h index c261241..c4e4de8 100644 --- a/src/ops/restoreoperation.h +++ b/src/ops/restoreoperation.h @@ -56,17 +56,17 @@ public: ~RestoreOperation(); public: - QString iconName() const { + QString iconName() const override { return QStringLiteral("document-import"); } - QString description() const; - bool execute(Report& parent); - void undo(); + QString description() const override; + bool execute(Report& parent) override; + void undo() override; - void preview(); + void preview() override; - virtual bool targets(const Device& d) const; - virtual bool targets(const Partition& p) const; + virtual bool targets(const Device& d) const override; + virtual bool targets(const Partition& p) const override; static bool canRestore(const Partition* p); static Partition* createRestorePartition(const Device& device, PartitionNode& parent, qint64 start, const QString& fileName); diff --git a/src/ops/setfilesystemlabeloperation.h b/src/ops/setfilesystemlabeloperation.h index 23fa189..666fbb3 100644 --- a/src/ops/setfilesystemlabeloperation.h +++ b/src/ops/setfilesystemlabeloperation.h @@ -48,15 +48,15 @@ public: SetFileSystemLabelOperation(Partition& p, const QString& newlabel); public: - QString iconName() const { + QString iconName() const override { return QStringLiteral("edit-rename"); } - QString description() const; - void preview(); - void undo(); + QString description() const override; + void preview() override; + void undo() override; - virtual bool targets(const Device& d) const; - virtual bool targets(const Partition& p) const; + virtual bool targets(const Device& d) const override; + virtual bool targets(const Partition& p) const override; protected: Partition& labeledPartition() { diff --git a/src/ops/setpartflagsoperation.h b/src/ops/setpartflagsoperation.h index 4732976..aeb0015 100644 --- a/src/ops/setpartflagsoperation.h +++ b/src/ops/setpartflagsoperation.h @@ -51,15 +51,15 @@ public: SetPartFlagsOperation(Device& d, Partition& p, const PartitionTable::Flags& flags); public: - QString iconName() const { + QString iconName() const override { return QStringLiteral("flag-blue"); } - QString description() const; - void preview(); - void undo(); + QString description() const override; + void preview() override; + void undo() override; - virtual bool targets(const Device& d) const; - virtual bool targets(const Partition& p) const; + virtual bool targets(const Device& d) const override; + virtual bool targets(const Partition& p) const override; protected: Partition& flagPartition() { diff --git a/src/plugins/dummy/dummybackend.h b/src/plugins/dummy/dummybackend.h index 47776a1..9fa5be7 100644 --- a/src/plugins/dummy/dummybackend.h +++ b/src/plugins/dummy/dummybackend.h @@ -42,7 +42,7 @@ private: DummyBackend(QObject* parent, const QList& args); public: - virtual void initFSSupport(); + virtual void initFSSupport() override; virtual QList scanDevices(bool excludeReadOnly = false) override; virtual CoreBackendDevice* openDevice(const QString& device_node) override; diff --git a/src/plugins/dummy/dummydevice.h b/src/plugins/dummy/dummydevice.h index f374a07..51a3d38 100644 --- a/src/plugins/dummy/dummydevice.h +++ b/src/plugins/dummy/dummydevice.h @@ -37,16 +37,16 @@ public: ~DummyDevice(); public: - virtual bool open(); - virtual bool openExclusive(); - virtual bool close(); + virtual bool open() override; + virtual bool openExclusive() override; + virtual bool close() override; - virtual CoreBackendPartitionTable* openPartitionTable(); + virtual CoreBackendPartitionTable* openPartitionTable() override; - virtual bool createPartitionTable(Report& report, const PartitionTable& ptable); + virtual bool createPartitionTable(Report& report, const PartitionTable& ptable) override; - virtual bool readSectors(void* buffer, qint64 offset, qint64 numSectors); - virtual bool writeSectors(void* buffer, qint64 offset, qint64 numSectors); + virtual bool readSectors(void* buffer, qint64 offset, qint64 numSectors) override; + virtual bool writeSectors(void* buffer, qint64 offset, qint64 numSectors) override; }; #endif diff --git a/src/plugins/dummy/dummypartition.h b/src/plugins/dummy/dummypartition.h index f8d0f50..4cbbb06 100644 --- a/src/plugins/dummy/dummypartition.h +++ b/src/plugins/dummy/dummypartition.h @@ -33,7 +33,7 @@ public: DummyPartition(); public: - virtual bool setFlag(Report& report, PartitionTable::Flag flag, bool state); + virtual bool setFlag(Report& report, PartitionTable::Flag flag, bool state) override; }; diff --git a/src/plugins/dummy/dummypartitiontable.h b/src/plugins/dummy/dummypartitiontable.h index 90a1179..7cb4a1e 100644 --- a/src/plugins/dummy/dummypartitiontable.h +++ b/src/plugins/dummy/dummypartitiontable.h @@ -36,20 +36,20 @@ public: ~DummyPartitionTable(); public: - virtual bool open(); + virtual bool open() override; - virtual bool commit(quint32 timeout = 10); + virtual bool commit(quint32 timeout = 10) override; - virtual CoreBackendPartition* getExtendedPartition(); - virtual CoreBackendPartition* getPartitionBySector(qint64 sector); + virtual CoreBackendPartition* getExtendedPartition() override; + virtual CoreBackendPartition* getPartitionBySector(qint64 sector) override; - virtual QString createPartition(Report& report, const Partition& partition); - virtual bool deletePartition(Report& report, const Partition& partition); - virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end); - virtual bool clobberFileSystem(Report& report, const Partition& partition); - virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength); - virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector); - virtual bool setPartitionSystemType(Report& report, const Partition& partition); + virtual QString createPartition(Report& report, const Partition& partition) override; + virtual bool deletePartition(Report& report, const Partition& partition) override; + virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) override; + virtual bool clobberFileSystem(Report& report, const Partition& partition) override; + virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) override; + virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) override; + virtual bool setPartitionSystemType(Report& report, const Partition& partition) override; }; #endif diff --git a/src/plugins/libparted/CMakeLists.txt b/src/plugins/libparted/CMakeLists.txt index ebeec19..aca131e 100644 --- a/src/plugins/libparted/CMakeLists.txt +++ b/src/plugins/libparted/CMakeLists.txt @@ -34,7 +34,7 @@ set (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 ${KDE_INSTALL_PLUGINDIR}) kcoreaddons_desktop_to_json(pmlibpartedbackendplugin pmlibpartedbackendplugin.desktop) diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index c927c2d..eab12c7 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -1,7 +1,7 @@ /************************************************************************* * Copyright (C) 2008-2012 by Volker Lanz * + * Copyright (C) 2015-2016 by Teo Mrnjavac * * Copyright (C) 2016 by Andrius Štikonas * - * Copyright (C) 2016 by Teo Mrnjavac * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -50,7 +50,6 @@ #include #include -#include K_PLUGIN_FACTORY_WITH_JSON(LibPartedBackendFactory, "pmlibpartedbackendplugin.json", registerPlugin();) @@ -215,7 +214,7 @@ static void readSectorsUsed(PedDisk* pedDisk, const Device& d, Partition& p, con const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint); - if (p.isMounted() && freeSpaceInfo.isValid() && mountPoint != QStringLiteral()) + if (p.isMounted() && freeSpaceInfo.isValid() && mountPoint != QString()) p.fileSystem().setSectorsUsed(freeSpaceInfo.used() / d.logicalSectorSize()); else if (p.fileSystem().supportGetUsed() == FileSystem::cmdSupportFileSystem) p.fileSystem().setSectorsUsed(p.fileSystem().readUsedCapacity(p.deviceNode()) / d.logicalSectorSize()); @@ -351,12 +350,36 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk) // libparted does not handle LUKS partitions QString mountPoint; - bool mounted; - if (fs->type() == FileSystem::Luks) { - mountPoint = FS::luks::mapperName(node); - mounted = (mountPoint != QString()) ? true : false; + bool mounted = false; + if (type == FileSystem::Luks) { + r |= PartitionRole::Luks; + FS::luks* luksFs = dynamic_cast(fs); + QString mapperNode = FS::luks::mapperName(node); + bool isCryptOpen = !mapperNode.isEmpty(); + luksFs->setCryptOpen(isCryptOpen); + luksFs->setLogicalSectorSize(d.logicalSectorSize()); + + if (isCryptOpen) { + luksFs->loadInnerFileSystem(mapperNode); + + mountPoint = mountPoints.findByDevice(mapperNode) ? + mountPoints.findByDevice(mapperNode)->mountPoint() : + QString(); + // We cannot use libparted to check the mounted status because + // we don't have a PedPartition for the mapper device, so we use + // check_mount_point from util-linux instead, defined in the + // private header ismounted.h and copied into KPMcore & wrapped + // in helpers.h for convenience. + mounted = isMounted(mapperNode); + } else { + mounted = false; + } + + luksFs->setMounted(mounted); } 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); } @@ -484,50 +507,12 @@ FileSystem::Type LibPartedBackend::detectFileSystem(PedPartition* pedPartition) { FileSystem::Type rval = FileSystem::Unknown; - blkid_cache cache; - char* pedPath = nullptr; + char* pedPath = ped_partition_get_path(pedPartition); - if (blkid_get_cache(&cache, nullptr) == 0 && (pedPath = ped_partition_get_path(pedPartition))) { - blkid_dev dev; + if (pedPath) + rval = FileSystem::detectFileSystem(QString::fromUtf8(pedPath)); - if ((dev = blkid_get_dev(cache, pedPath, BLKID_DEV_NORMAL)) != nullptr) { - QString s = QString::fromUtf8(blkid_get_tag_value(cache, "TYPE", pedPath)); - 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", pedPath)); - 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 if (s == QStringLiteral("f2fs")) rval = FileSystem::F2fs; - else - qWarning() << "blkid: unknown file system type " << s << " on " << pedPath; - } - - blkid_put_cache(cache); - - free(pedPath); - } + free(pedPath); return rval; } diff --git a/src/plugins/libparted/libpartedbackend.h b/src/plugins/libparted/libpartedbackend.h index 53e764e..39f832b 100644 --- a/src/plugins/libparted/libpartedbackend.h +++ b/src/plugins/libparted/libpartedbackend.h @@ -1,5 +1,6 @@ /************************************************************************* * Copyright (C) 2008, 2010 by Volker Lanz * + * Copyright (C) 2015 by Teo Mrnjavac * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -58,7 +59,7 @@ private: LibPartedBackend(QObject* parent, const QList& args); public: - virtual void initFSSupport(); + virtual void initFSSupport() override; virtual CoreBackendDevice* openDevice(const QString& device_node) override; virtual CoreBackendDevice* openDeviceExclusive(const QString& device_node) override; diff --git a/src/plugins/libparted/libparteddevice.h b/src/plugins/libparted/libparteddevice.h index 2a5a10d..2a36315 100644 --- a/src/plugins/libparted/libparteddevice.h +++ b/src/plugins/libparted/libparteddevice.h @@ -39,16 +39,16 @@ public: ~LibPartedDevice(); public: - virtual bool open(); - virtual bool openExclusive(); - virtual bool close(); + virtual bool open() override; + virtual bool openExclusive() override; + virtual bool close() override; - virtual CoreBackendPartitionTable* openPartitionTable(); + virtual CoreBackendPartitionTable* openPartitionTable() override; - virtual bool createPartitionTable(Report& report, const PartitionTable& ptable); + virtual bool createPartitionTable(Report& report, const PartitionTable& ptable) override; - virtual bool readSectors(void* buffer, qint64 offset, qint64 numSectors); - virtual bool writeSectors(void* buffer, qint64 offset, qint64 numSectors); + virtual bool readSectors(void* buffer, qint64 offset, qint64 numSectors) override; + virtual bool writeSectors(void* buffer, qint64 offset, qint64 numSectors) override; protected: PedDevice* pedDevice() { diff --git a/src/plugins/libparted/libpartedpartition.h b/src/plugins/libparted/libpartedpartition.h index f626f39..4bfed4a 100644 --- a/src/plugins/libparted/libpartedpartition.h +++ b/src/plugins/libparted/libpartedpartition.h @@ -35,7 +35,7 @@ public: LibPartedPartition(PedPartition* ped_partition); public: - virtual bool setFlag(Report& report, PartitionTable::Flag flag, bool state); + virtual bool setFlag(Report& report, PartitionTable::Flag flag, bool state) override; private: PedPartition* pedPartition() { diff --git a/src/plugins/libparted/libpartedpartitiontable.h b/src/plugins/libparted/libpartedpartitiontable.h index c41e45e..c2ad610 100644 --- a/src/plugins/libparted/libpartedpartitiontable.h +++ b/src/plugins/libparted/libpartedpartitiontable.h @@ -38,21 +38,21 @@ public: ~LibPartedPartitionTable(); public: - virtual bool open(); + virtual bool open() override; - virtual bool commit(quint32 timeout = 10); + virtual bool commit(quint32 timeout = 10) override; static bool commit(PedDisk* pd, quint32 timeout = 10); - virtual CoreBackendPartition* getExtendedPartition(); - virtual CoreBackendPartition* getPartitionBySector(qint64 sector); + virtual CoreBackendPartition* getExtendedPartition() override; + virtual CoreBackendPartition* getPartitionBySector(qint64 sector) override; - virtual QString createPartition(Report& report, const Partition& partition); - virtual bool deletePartition(Report& report, const Partition& partition); - virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end); - virtual bool clobberFileSystem(Report& report, const Partition& partition); - virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength); - virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector); - virtual bool setPartitionSystemType(Report& report, const Partition& partition); + virtual QString createPartition(Report& report, const Partition& partition) override; + virtual bool deletePartition(Report& report, const Partition& partition) override; + virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) override; + virtual bool clobberFileSystem(Report& report, const Partition& partition) override; + virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) override; + virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) override; + virtual bool setPartitionSystemType(Report& report, const Partition& partition) override; private: PedDevice* pedDevice() { diff --git a/src/util/helpers.cpp b/src/util/helpers.cpp index 9a17311..192fdcf 100644 --- a/src/util/helpers.cpp +++ b/src/util/helpers.cpp @@ -17,9 +17,10 @@ *************************************************************************/ #include "util/helpers.h" -#include "../util/globallog.h" +#include "util/externalcommand.h" +#include "util/globallog.h" -#include "../ops/operation.h" +#include "ops/operation.h" #include #include @@ -67,3 +68,18 @@ void showColumnsContextMenu(const QPoint& p, QTreeWidget& tree) tree.resizeColumnToContents(action->data().toInt()); } } + +bool isMounted(const QString& deviceNode) +{ + ExternalCommand cmd(QStringLiteral("lsblk"), + { QStringLiteral("--noheadings"), + QStringLiteral("--nodeps"), + QStringLiteral("--output"), + QStringLiteral("mountpoint"), + deviceNode }); + + if (cmd.run(-1) && cmd.exitCode() == 0) { + return !cmd.output().trimmed().isEmpty(); + } + return false; +} diff --git a/src/util/helpers.h b/src/util/helpers.h index fe033ad..aad5f78 100644 --- a/src/util/helpers.h +++ b/src/util/helpers.h @@ -19,11 +19,10 @@ #define HELPERS__H -#include "../util/libpartitionmanagerexport.h" +#include "fs/filesystem.h" -#include "../fs/filesystem.h" +#include "util/libpartitionmanagerexport.h" -class KAboutData; class QString; class QPoint; class QTreeWidget; @@ -36,4 +35,6 @@ LIBKPMCORE_EXPORT void showColumnsContextMenu(const QPoint& p, QTreeWidget& tree LIBKPMCORE_EXPORT bool checkAccessibleDevices(); +LIBKPMCORE_EXPORT bool isMounted(const QString& deviceNode); + #endif diff --git a/src/util/ismounted.c b/src/util/ismounted.c deleted file mode 100644 index 20cc568..0000000 --- a/src/util/ismounted.c +++ /dev/null @@ -1,400 +0,0 @@ -/* - * ismounted.c --- Check to see if the filesystem was mounted - * - * Copyright (C) 1995,1996,1997,1998,1999,2000,2008 Theodore Ts'o. - * - * This file may be redistributed under the terms of the GNU Public - * License. - */ -#include -#include -#include -#include -#include -#ifdef HAVE_MNTENT_H -#include -#endif -#include -#include -#include -#include -#ifdef __APPLE__ -#include -#include -#endif - -#include "pathnames.h" -#include "ismounted.h" -#ifdef __linux__ -# include "loopdev.h" -#endif - - -/* - * Fallback defines for old versions of glibc - */ -#ifdef O_CLOEXEC -#define UL_CLOEXECSTR "e" -#else -#define UL_CLOEXECSTR "" -#endif - -#ifndef O_CLOEXEC -#define O_CLOEXEC 0 -#endif - - -#ifdef HAVE_MNTENT_H -/* - * Helper function which checks a file in /etc/mtab format to see if a - * filesystem is mounted. Returns an error if the file doesn't exist - * or can't be opened. - */ -static int check_mntent_file(const char *mtab_file, const char *file, - int *mount_flags, char *mtpt, int mtlen) -{ - struct mntent *mnt; - struct stat st_buf; - int retval = 0; - dev_t file_dev=0, file_rdev=0; - ino_t file_ino=0; - FILE *f; - int fd; - - *mount_flags = 0; - if ((f = setmntent (mtab_file, "r")) == NULL) - return errno; - - if (stat(file, &st_buf) == 0) { - if (S_ISBLK(st_buf.st_mode)) { -#ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */ - file_rdev = st_buf.st_rdev; -#endif /* __GNU__ */ - } else { - file_dev = st_buf.st_dev; - file_ino = st_buf.st_ino; - } - } - - while ((mnt = getmntent (f)) != NULL) { - if (mnt->mnt_fsname[0] != '/') - continue; - if (strcmp(file, mnt->mnt_fsname) == 0) - break; - if (stat(mnt->mnt_fsname, &st_buf) != 0) - continue; - - if (S_ISBLK(st_buf.st_mode)) { -#ifndef __GNU__ - if (file_rdev && file_rdev == st_buf.st_rdev) - break; -#ifdef __linux__ - /* maybe the file is loopdev backing file */ - if (file_dev - && major(st_buf.st_rdev) == LOOPDEV_MAJOR - && loopdev_is_used(mnt->mnt_fsname, file, 0, 0)) - break; -#endif /* __linux__ */ -#endif /* __GNU__ */ - } else { - if (file_dev && ((file_dev == st_buf.st_dev) && - (file_ino == st_buf.st_ino))) - break; - } - } - - if (mnt == NULL) { -#ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */ - /* - * Do an extra check to see if this is the root device. We - * can't trust /etc/mtab, and /proc/mounts will only list - * /dev/root for the root filesystem. Argh. Instead we - * check if the given device has the same major/minor number - * as the device that the root directory is on. - */ - if (file_rdev && stat("/", &st_buf) == 0 && - st_buf.st_dev == file_rdev) { - *mount_flags = MF_MOUNTED; - if (mtpt) - strncpy(mtpt, "/", mtlen); - goto is_root; - } -#endif /* __GNU__ */ - goto errout; - } -#ifndef __GNU__ /* The GNU hurd is deficient; what else is new? */ - /* Validate the entry in case /etc/mtab is out of date */ - /* - * We need to be paranoid, because some broken distributions - * (read: Slackware) don't initialize /etc/mtab before checking - * all of the non-root filesystems on the disk. - */ - if (stat(mnt->mnt_dir, &st_buf) < 0) { - retval = errno; - if (retval == ENOENT) { -#ifdef DEBUG - printf("Bogus entry in %s! (%s does not exist)\n", - mtab_file, mnt->mnt_dir); -#endif /* DEBUG */ - retval = 0; - } - goto errout; - } - if (file_rdev && (st_buf.st_dev != file_rdev)) { -#ifdef DEBUG - printf("Bogus entry in %s! (%s not mounted on %s)\n", - mtab_file, file, mnt->mnt_dir); -#endif /* DEBUG */ - goto errout; - } -#endif /* __GNU__ */ - *mount_flags = MF_MOUNTED; - -#ifdef MNTOPT_RO - /* Check to see if the ro option is set */ - if (hasmntopt(mnt, MNTOPT_RO)) - *mount_flags |= MF_READONLY; -#endif - - if (mtpt) - strncpy(mtpt, mnt->mnt_dir, mtlen); - /* - * Check to see if we're referring to the root filesystem. - * If so, do a manual check to see if we can open /etc/mtab - * read/write, since if the root is mounted read/only, the - * contents of /etc/mtab may not be accurate. - */ - if (!strcmp(mnt->mnt_dir, "/")) { -is_root: -#define TEST_FILE "/.ismount-test-file" - *mount_flags |= MF_ISROOT; - fd = open(TEST_FILE, O_RDWR|O_CREAT|O_CLOEXEC, 0600); - if (fd < 0) { - if (errno == EROFS) - *mount_flags |= MF_READONLY; - } else - close(fd); - (void) unlink(TEST_FILE); - } - retval = 0; -errout: - endmntent (f); - return retval; -} - -static int check_mntent(const char *file, int *mount_flags, - char *mtpt, int mtlen) -{ - int retval; - -#ifdef DEBUG - retval = check_mntent_file("/tmp/mtab", file, mount_flags, - mtpt, mtlen); - if (retval == 0) - return 0; -#endif /* DEBUG */ -#ifdef __linux__ - retval = check_mntent_file("/proc/mounts", file, mount_flags, - mtpt, mtlen); - if (retval == 0 && (*mount_flags != 0)) - return 0; - if (access("/proc/mounts", R_OK) == 0) { - *mount_flags = 0; - return retval; - } -#endif /* __linux__ */ -#if defined(MOUNTED) || defined(_PATH_MOUNTED) -#ifndef MOUNTED -#define MOUNTED _PATH_MOUNTED -#endif /* MOUNTED */ - retval = check_mntent_file(MOUNTED, file, mount_flags, mtpt, mtlen); - return retval; -#else - *mount_flags = 0; - return 0; -#endif /* defined(MOUNTED) || defined(_PATH_MOUNTED) */ -} - -#else -#if defined(HAVE_GETMNTINFO) - -static int check_getmntinfo(const char *file, int *mount_flags, - char *mtpt, int mtlen) -{ - struct statfs *mp; - int len, n; - const char *s1; - char *s2; - - n = getmntinfo(&mp, MNT_NOWAIT); - if (n == 0) - return errno; - - len = sizeof(_PATH_DEV) - 1; - s1 = file; - if (strncmp(_PATH_DEV, s1, len) == 0) - s1 += len; - - *mount_flags = 0; - while (--n >= 0) { - s2 = mp->f_mntfromname; - if (strncmp(_PATH_DEV, s2, len) == 0) { - s2 += len - 1; - *s2 = 'r'; - } - if (strcmp(s1, s2) == 0 || strcmp(s1, &s2[1]) == 0) { - *mount_flags = MF_MOUNTED; - break; - } - ++mp; - } - if (mtpt) - strncpy(mtpt, mp->f_mntonname, mtlen); - return 0; -} -#endif /* HAVE_GETMNTINFO */ -#endif /* HAVE_MNTENT_H */ - -/* - * Check to see if we're dealing with the swap device. - */ -static int is_swap_device(const char *file) -{ - FILE *f; - char buf[1024], *cp; - dev_t file_dev; - struct stat st_buf; - int ret = 0; - - file_dev = 0; -#ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */ - if ((stat(file, &st_buf) == 0) && - S_ISBLK(st_buf.st_mode)) - file_dev = st_buf.st_rdev; -#endif /* __GNU__ */ - - if (!(f = fopen("/proc/swaps", "r" UL_CLOEXECSTR))) - return 0; - /* Skip the first line */ - if (!fgets(buf, sizeof(buf), f)) - goto leave; - if (*buf && strncmp(buf, "Filename\t", 9)) - /* Linux <=2.6.19 contained a bug in the /proc/swaps - * code where the header would not be displayed - */ - goto valid_first_line; - - while (fgets(buf, sizeof(buf), f)) { -valid_first_line: - if ((cp = strchr(buf, ' ')) != NULL) - *cp = 0; - if ((cp = strchr(buf, '\t')) != NULL) - *cp = 0; - if (strcmp(buf, file) == 0) { - ret++; - break; - } -#ifndef __GNU__ - if (file_dev && (stat(buf, &st_buf) == 0) && - S_ISBLK(st_buf.st_mode) && - file_dev == st_buf.st_rdev) { - ret++; - break; - } -#endif /* __GNU__ */ - } - -leave: - fclose(f); - return ret; -} - - -/* - * check_mount_point() fills determines if the device is mounted or otherwise - * busy, and fills in mount_flags with one or more of the following flags: - * MF_MOUNTED, MF_ISROOT, MF_READONLY, MF_SWAP, and MF_BUSY. If mtpt is - * non-NULL, the directory where the device is mounted is copied to where mtpt - * is pointing, up to mtlen characters. - */ -#ifdef __TURBOC__ - #pragma argsused -#endif -int check_mount_point(const char *device, int *mount_flags, - char *mtpt, int mtlen) -{ - struct stat st_buf; - int retval = 0; - int fd; - - if (is_swap_device(device)) { - *mount_flags = MF_MOUNTED | MF_SWAP; - if (mtpt && mtlen) - strncpy(mtpt, "[SWAP]", mtlen); - } else { -#ifdef HAVE_MNTENT_H - retval = check_mntent(device, mount_flags, mtpt, mtlen); -#else -#ifdef HAVE_GETMNTINFO - retval = check_getmntinfo(device, mount_flags, mtpt, mtlen); -#else -#ifdef __GNUC__ - #warning "Can't use getmntent or getmntinfo to check for mounted filesystems!" -#endif - *mount_flags = 0; -#endif /* HAVE_GETMNTINFO */ -#endif /* HAVE_MNTENT_H */ - } - if (retval) - return retval; - -#ifdef __linux__ /* This only works on Linux 2.6+ systems */ - if ((stat(device, &st_buf) != 0) || - !S_ISBLK(st_buf.st_mode)) - return 0; - fd = open(device, O_RDONLY|O_EXCL|O_CLOEXEC); - if (fd < 0) { - if (errno == EBUSY) - *mount_flags |= MF_BUSY; - } else - close(fd); -#endif - - return 0; -} - -int is_mounted(const char *file) -{ - int retval; - int mount_flags = 0; - - retval = check_mount_point(file, &mount_flags, NULL, 0); - if (retval) - return 0; - return mount_flags & MF_MOUNTED; -} - -#ifdef TEST_PROGRAM -int main(int argc, char **argv) -{ - int flags = 0; - char devname[PATH_MAX]; - - if (argc < 2) { - fprintf(stderr, "Usage: %s device\n", argv[0]); - return EXIT_FAILURE; - } - - if (check_mount_point(argv[1], &flags, devname, sizeof(devname)) == 0 && - (flags & MF_MOUNTED)) { - if (flags & MF_SWAP) - printf("used swap device\n"); - else - printf("mounted on %s\n", devname); - return EXIT_SUCCESS; - } - - printf("not mounted\n"); - return EXIT_FAILURE; -} -#endif /* DEBUG */ diff --git a/src/util/ismounted.h b/src/util/ismounted.h deleted file mode 100644 index c3a0226..0000000 --- a/src/util/ismounted.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef IS_MOUNTED_H -#define IS_MOUNTED_H - -#define MF_MOUNTED 1 -#define MF_ISROOT 2 -#define MF_READONLY 4 -#define MF_SWAP 8 -#define MF_BUSY 16 - -extern int is_mounted(const char *file); -extern int check_mount_point(const char *device, int *mount_flags, - char *mtpt, int mtlen); - -#endif /* IS_MOUNTED_H */ diff --git a/src/util/loopdev.h b/src/util/loopdev.h deleted file mode 100644 index 573a569..0000000 --- a/src/util/loopdev.h +++ /dev/null @@ -1,193 +0,0 @@ -#ifndef UTIL_LINUX_LOOPDEV_H -#define UTIL_LINUX_LOOPDEV_H - -#include "sysfs.h" - -/* - * loop_info.lo_encrypt_type - */ -#define LO_CRYPT_NONE 0 -#define LO_CRYPT_XOR 1 -#define LO_CRYPT_DES 2 -#define LO_CRYPT_CRYPTOAPI 18 - -#define LOOP_SET_FD 0x4C00 -#define LOOP_CLR_FD 0x4C01 -/* - * Obsolete (kernel < 2.6) - * - * #define LOOP_SET_STATUS 0x4C02 - * #define LOOP_GET_STATUS 0x4C03 - */ -#define LOOP_SET_STATUS64 0x4C04 -#define LOOP_GET_STATUS64 0x4C05 -/* #define LOOP_CHANGE_FD 0x4C06 */ -#define LOOP_SET_CAPACITY 0x4C07 - -/* /dev/loop-control interface */ -#ifndef LOOP_CTL_ADD -# define LOOP_CTL_ADD 0x4C80 -# define LOOP_CTL_REMOVE 0x4C81 -# define LOOP_CTL_GET_FREE 0x4C82 -#endif - -/* - * loop_info.lo_flags - */ -enum { - LO_FLAGS_READ_ONLY = 1, - LO_FLAGS_USE_AOPS = 2, - LO_FLAGS_AUTOCLEAR = 4, /* kernel >= 2.6.25 */ - LO_FLAGS_PARTSCAN = 8, /* kernel >= 3.2 */ -}; - -#define LO_NAME_SIZE 64 -#define LO_KEY_SIZE 32 - -/* - * Linux LOOP_{SET,GET}_STATUS64 ioctl struct - */ -struct loop_info64 { - uint64_t lo_device; - uint64_t lo_inode; - uint64_t lo_rdevice; - uint64_t lo_offset; - uint64_t lo_sizelimit; /* bytes, 0 == max available */ - uint32_t lo_number; - uint32_t lo_encrypt_type; - uint32_t lo_encrypt_key_size; - uint32_t lo_flags; - uint8_t lo_file_name[LO_NAME_SIZE]; - uint8_t lo_crypt_name[LO_NAME_SIZE]; - uint8_t lo_encrypt_key[LO_KEY_SIZE]; - uint64_t lo_init[2]; -}; - -#define LOOPDEV_MAJOR 7 /* loop major number */ -#define LOOPDEV_DEFAULT_NNODES 8 /* default number of loop devices */ - -struct loopdev_iter { - FILE *proc; /* /proc/partitions */ - DIR *sysblock; /* /sys/block */ - int ncur; /* current position */ - int *minors; /* ary of minor numbers (when scan whole /dev) */ - int nminors; /* number of items in *minors */ - int ct_perm; /* count permission problems */ - int ct_succ; /* count number of detected devices */ - - unsigned int done:1; /* scanning done */ - unsigned int default_check:1;/* check first LOOPDEV_NLOOPS */ - int flags; /* LOOPITER_FL_* flags */ -}; - -enum { - LOOPITER_FL_FREE = (1 << 0), - LOOPITER_FL_USED = (1 << 1) -}; - -/* - * handler for work with loop devices - */ -struct loopdev_cxt { - char device[128]; /* device path (e.g. /dev/loop) */ - char *filename; /* backing file for loopcxt_set_... */ - int fd; /* open(/dev/looo) */ - int mode; /* fd mode O_{RDONLY,RDWR} */ - - int flags; /* LOOPDEV_FL_* flags */ - unsigned int has_info:1; /* .info contains data */ - unsigned int extra_check:1; /* unusual stuff for iterator */ - unsigned int info_failed:1; /* LOOP_GET_STATUS ioctl failed */ - unsigned int control_ok:1; /* /dev/loop-control success */ - - struct sysfs_cxt sysfs; /* pointer to /sys/dev/block// */ - struct loop_info64 info; /* for GET/SET ioctl */ - struct loopdev_iter iter; /* scans /sys or /dev for used/free devices */ -}; - -#define UL_LOOPDEVCXT_EMPTY { .fd = -1, .sysfs = UL_SYSFSCXT_EMPTY } - -/* - * loopdev_cxt.flags - */ -enum { - LOOPDEV_FL_RDONLY = (1 << 0), /* open(/dev/loop) mode; default */ - LOOPDEV_FL_RDWR = (1 << 1), /* necessary for loop setup only */ - LOOPDEV_FL_OFFSET = (1 << 4), - LOOPDEV_FL_NOSYSFS = (1 << 5), - LOOPDEV_FL_NOIOCTL = (1 << 6), - LOOPDEV_FL_DEVSUBDIR = (1 << 7), - LOOPDEV_FL_CONTROL = (1 << 8), /* system with /dev/loop-control */ - LOOPDEV_FL_SIZELIMIT = (1 << 9) -}; - -/* - * High-level - */ -extern int loopmod_supports_partscan(void); - -extern int is_loopdev(const char *device); -extern int loopdev_is_autoclear(const char *device); - -extern char *loopdev_get_backing_file(const char *device); -extern int loopdev_is_used(const char *device, const char *filename, - uint64_t offset, int flags); -extern char *loopdev_find_by_backing_file(const char *filename, - uint64_t offset, int flags); -extern int loopcxt_find_unused(struct loopdev_cxt *lc); -extern int loopdev_delete(const char *device); -extern int loopdev_count_by_backing_file(const char *filename, char **loopdev); - -/* - * Low-level - */ -extern int loopcxt_init(struct loopdev_cxt *lc, int flags) - __attribute__ ((warn_unused_result)); -extern void loopcxt_deinit(struct loopdev_cxt *lc); - -extern int loopcxt_set_device(struct loopdev_cxt *lc, const char *device) - __attribute__ ((warn_unused_result)); -extern int loopcxt_has_device(struct loopdev_cxt *lc); -extern int loopcxt_add_device(struct loopdev_cxt *lc); -extern char *loopcxt_strdup_device(struct loopdev_cxt *lc); -extern const char *loopcxt_get_device(struct loopdev_cxt *lc); -extern struct sysfs_cxt *loopcxt_get_sysfs(struct loopdev_cxt *lc); -extern struct loop_info64 *loopcxt_get_info(struct loopdev_cxt *lc); - -extern int loopcxt_get_fd(struct loopdev_cxt *lc); -extern int loopcxt_set_fd(struct loopdev_cxt *lc, int fd, int mode); - -extern int loopcxt_init_iterator(struct loopdev_cxt *lc, int flags); -extern int loopcxt_deinit_iterator(struct loopdev_cxt *lc); -extern int loopcxt_next(struct loopdev_cxt *lc); - -extern int loopcxt_setup_device(struct loopdev_cxt *lc); -extern int loopcxt_delete_device(struct loopdev_cxt *lc); -extern int loopcxt_set_capacity(struct loopdev_cxt *lc); - -int loopcxt_set_offset(struct loopdev_cxt *lc, uint64_t offset); -int loopcxt_set_sizelimit(struct loopdev_cxt *lc, uint64_t sizelimit); -int loopcxt_set_flags(struct loopdev_cxt *lc, uint32_t flags); -int loopcxt_set_backing_file(struct loopdev_cxt *lc, const char *filename); - -extern char *loopcxt_get_backing_file(struct loopdev_cxt *lc); -extern int loopcxt_get_backing_devno(struct loopdev_cxt *lc, dev_t *devno); -extern int loopcxt_get_backing_inode(struct loopdev_cxt *lc, ino_t *ino); -extern int loopcxt_get_offset(struct loopdev_cxt *lc, uint64_t *offset); -extern int loopcxt_get_sizelimit(struct loopdev_cxt *lc, uint64_t *size); -extern int loopcxt_get_encrypt_type(struct loopdev_cxt *lc, uint32_t *type); -extern const char *loopcxt_get_crypt_name(struct loopdev_cxt *lc); -extern int loopcxt_is_autoclear(struct loopdev_cxt *lc); -extern int loopcxt_is_readonly(struct loopdev_cxt *lc); -extern int loopcxt_is_partscan(struct loopdev_cxt *lc); -extern int loopcxt_find_by_backing_file(struct loopdev_cxt *lc, - const char *filename, - uint64_t offset, int flags); - -extern int loopcxt_is_used(struct loopdev_cxt *lc, - struct stat *st, - const char *backing_file, - uint64_t offset, - int flags); - -#endif /* UTIL_LINUX_LOOPDEV_H */ diff --git a/src/util/pathnames.h b/src/util/pathnames.h deleted file mode 100644 index e68ac7d..0000000 --- a/src/util/pathnames.h +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Vaguely based on - * @(#)pathnames.h 5.3 (Berkeley) 5/9/89 - * This code is in the public domain. - */ -#ifndef PATHNAMES_H -#define PATHNAMES_H - -#ifdef HAVE_PATHS_H -#include -#endif - -#ifndef __STDC__ -# error "we need an ANSI compiler" -#endif - -/* used by kernel in /proc (e.g. /proc/swaps) for deleted files */ -#define PATH_DELETED_SUFFIX "\\040(deleted)" -#define PATH_DELETED_SUFFIX_SZ (sizeof(PATH_DELETED_SUFFIX) - 1) - -/* DEFPATHs from don't include /usr/local */ -#undef _PATH_DEFPATH - -#ifdef USE_USRDIR_PATHS_ONLY -# define _PATH_DEFPATH "/usr/local/bin:/usr/bin" -#else -# define _PATH_DEFPATH "/usr/local/bin:/bin:/usr/bin" -#endif - -#undef _PATH_DEFPATH_ROOT - -#ifdef USE_USRDIR_PATHS_ONLY -# define _PATH_DEFPATH_ROOT "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" -#else -# define _PATH_DEFPATH_ROOT "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" -#endif - -#define _PATH_SECURETTY "/etc/securetty" -#define _PATH_WTMPLOCK "/etc/wtmplock" - -#define _PATH_HUSHLOGIN ".hushlogin" -#define _PATH_HUSHLOGINS "/etc/hushlogins" - -#define _PATH_NOLOGIN_TXT "/etc/nologin.txt" - -#ifndef _PATH_MAILDIR -#define _PATH_MAILDIR "/var/spool/mail" -#endif -#define _PATH_MOTDFILE "/etc/motd" -#define _PATH_NOLOGIN "/etc/nologin" -#define _PATH_VAR_NOLOGIN "/var/run/nologin" - -#define _PATH_LOGIN "/bin/login" -#define _PATH_INITTAB "/etc/inittab" -#define _PATH_RC "/etc/rc" -#define _PATH_REBOOT "/sbin/reboot" -#define _PATH_SHUTDOWN "/sbin/shutdown" -#define _PATH_SINGLE "/etc/singleboot" -#define _PATH_SHUTDOWN_CONF "/etc/shutdown.conf" - -#define _PATH_SECURE "/etc/securesingle" -#define _PATH_USERTTY "/etc/usertty" - -#define _PATH_TERMCOLORS_DIRNAME "terminal-colors.d" -#define _PATH_TERMCOLORS_DIR "/etc/" _PATH_TERMCOLORS_DIRNAME - -/* used in login-utils/shutdown.c */ - -/* used in login-utils/setpwnam.h and login-utils/islocal.c */ -#define _PATH_PASSWD "/etc/passwd" - -/* used in login-utils/newgrp and login-utils/setpwnam.h*/ -#define _PATH_GSHADOW "/etc/gshadow" - -/* used in login-utils/setpwnam.h */ -#define _PATH_GROUP "/etc/group" -#define _PATH_SHADOW_PASSWD "/etc/shadow" -#define _PATH_SHELLS "/etc/shells" - -/* used in term-utils/agetty.c */ -#define _PATH_ISSUE "/etc/issue" -#define _PATH_OS_RELEASE_ETC "/etc/os-release" -#define _PATH_OS_RELEASE_USR "/usr/lib/os-release" - -#define _PATH_NUMLOCK_ON _PATH_LOCALSTATEDIR "/numlock-on" - -#define _PATH_LOGINDEFS "/etc/login.defs" - -/* used in misc-utils/look.c */ -#define _PATH_WORDS "/usr/share/dict/words" -#define _PATH_WORDS_ALT "/usr/share/dict/web2" - -/* mount paths */ -#define _PATH_UMOUNT "/bin/umount" - -#define _PATH_FILESYSTEMS "/etc/filesystems" -#define _PATH_PROC_SWAPS "/proc/swaps" -#define _PATH_PROC_FILESYSTEMS "/proc/filesystems" -#define _PATH_PROC_MOUNTS "/proc/mounts" -#define _PATH_PROC_PARTITIONS "/proc/partitions" -#define _PATH_PROC_DEVICES "/proc/devices" -#define _PATH_PROC_MOUNTINFO "/proc/self/mountinfo" -#define _PATH_PROC_LOCKS "/proc/locks" -#define _PATH_PROC_CDROMINFO "/proc/sys/dev/cdrom/info" - -#define _PATH_PROC_UIDMAP "/proc/self/uid_map" -#define _PATH_PROC_GIDMAP "/proc/self/gid_map" -#define _PATH_PROC_SETGROUPS "/proc/self/setgroups" - -#define _PATH_PROC_ATTR_CURRENT "/proc/self/attr/current" -#define _PATH_PROC_ATTR_EXEC "/proc/self/attr/exec" -#define _PATH_PROC_CAPLASTCAP "/proc/sys/kernel/cap_last_cap" - - -#define _PATH_SYS_BLOCK "/sys/block" -#define _PATH_SYS_DEVBLOCK "/sys/dev/block" -#define _PATH_SYS_CLASS "/sys/class" -#define _PATH_SYS_SCSI "/sys/bus/scsi" - -#define _PATH_SYS_SELINUX "/sys/fs/selinux" -#define _PATH_SYS_APPARMOR "/sys/kernel/security/apparmor" - -#ifndef _PATH_MOUNTED -# ifdef MOUNTED /* deprecated */ -# define _PATH_MOUNTED MOUNTED -# else -# define _PATH_MOUNTED "/etc/mtab" -# endif -#endif - -#ifndef _PATH_MNTTAB -# ifdef MNTTAB /* deprecated */ -# define _PATH_MNTTAB MNTTAB -# else -# define _PATH_MNTTAB "/etc/fstab" -# endif -#endif - -#define _PATH_MNTTAB_DIR _PATH_MNTTAB ".d" - -#define _PATH_MOUNTED_LOCK _PATH_MOUNTED "~" -#define _PATH_MOUNTED_TMP _PATH_MOUNTED ".tmp" - -#ifndef _PATH_DEV - /* - * The tailing '/' in _PATH_DEV is there for compatibility with libc. - */ -# define _PATH_DEV "/dev/" -#endif - -#define _PATH_DEV_MEM "/dev/mem" - -#define _PATH_DEV_LOOP "/dev/loop" -#define _PATH_DEV_LOOPCTL "/dev/loop-control" -#define _PATH_DEV_TTY "/dev/tty" - - -/* udev paths */ -#define _PATH_DEV_BYLABEL "/dev/disk/by-label" -#define _PATH_DEV_BYUUID "/dev/disk/by-uuid" -#define _PATH_DEV_BYID "/dev/disk/by-id" -#define _PATH_DEV_BYPATH "/dev/disk/by-path" -#define _PATH_DEV_BYPARTLABEL "/dev/disk/by-partlabel" -#define _PATH_DEV_BYPARTUUID "/dev/disk/by-partuuid" - -/* hwclock paths */ -#ifdef CONFIG_ADJTIME_PATH -# define _PATH_ADJTIME CONFIG_ADJTIME_PATH -#else -# define _PATH_ADJTIME "/etc/adjtime" -#endif - -#define _PATH_LASTDATE "/var/lib/lastdate" -#ifdef __ia64__ -# define _PATH_RTC_DEV "/dev/efirtc" -#else -# define _PATH_RTC_DEV "/dev/rtc" -#endif - -#ifndef _PATH_BTMP -#define _PATH_BTMP "/var/log/btmp" -#endif - -/* raw paths*/ -#define _PATH_RAWDEVDIR "/dev/raw/" -#define _PATH_RAWDEVCTL _PATH_RAWDEVDIR "rawctl" -/* deprecated */ -#define _PATH_RAWDEVCTL_OLD "/dev/rawctl" - -/* wdctl path */ -#define _PATH_WATCHDOG_DEV "/dev/watchdog" - -/* ipc paths */ -#define _PATH_PROC_SYSV_MSG "/proc/sysvipc/msg" -#define _PATH_PROC_SYSV_SEM "/proc/sysvipc/sem" -#define _PATH_PROC_SYSV_SHM "/proc/sysvipc/shm" -#define _PATH_PROC_IPC_MSGMAX "/proc/sys/kernel/msgmax" -#define _PATH_PROC_IPC_MSGMNB "/proc/sys/kernel/msgmnb" -#define _PATH_PROC_IPC_MSGMNI "/proc/sys/kernel/msgmni" -#define _PATH_PROC_IPC_SEM "/proc/sys/kernel/sem" -#define _PATH_PROC_IPC_SHMALL "/proc/sys/kernel/shmall" -#define _PATH_PROC_IPC_SHMMAX "/proc/sys/kernel/shmmax" -#define _PATH_PROC_IPC_SHMMNI "/proc/sys/kernel/shmmni" - -/* kernel command line */ -#define _PATH_PROC_CMDLINE "/proc/cmdline" - -/* logger paths */ -#define _PATH_DEVLOG "/dev/log" - -#endif /* PATHNAMES_H */ - diff --git a/src/util/sysfs.h b/src/util/sysfs.h deleted file mode 100644 index 5521378..0000000 --- a/src/util/sysfs.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2011 Karel Zak - */ -#ifndef UTIL_LINUX_SYSFS_H -#define UTIL_LINUX_SYSFS_H - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct sysfs_cxt { - dev_t devno; - int dir_fd; /* /sys/block/ */ - char *dir_path; - struct sysfs_cxt *parent; - - unsigned int scsi_host, - scsi_channel, - scsi_target, - scsi_lun; - - unsigned int has_hctl : 1; -}; - -#define UL_SYSFSCXT_EMPTY { 0, -1, NULL, NULL, 0, 0, 0, 0, 0 } - -extern char *sysfs_devno_attribute_path(dev_t devno, char *buf, - size_t bufsiz, const char *attr); -extern int sysfs_devno_has_attribute(dev_t devno, const char *attr); -extern char *sysfs_devno_path(dev_t devno, char *buf, size_t bufsiz); -extern char *sysfs_devno_to_devpath(dev_t devno, char *buf, size_t bufsiz); -extern dev_t sysfs_devname_to_devno(const char *name, const char *parent); - -extern int sysfs_init(struct sysfs_cxt *cxt, dev_t devno, struct sysfs_cxt *parent) - __attribute__ ((warn_unused_result)); -extern void sysfs_deinit(struct sysfs_cxt *cxt); - -extern DIR *sysfs_opendir(struct sysfs_cxt *cxt, const char *attr); - -extern int sysfs_stat(struct sysfs_cxt *cxt, const char *attr, struct stat *st); -extern ssize_t sysfs_readlink(struct sysfs_cxt *cxt, const char *attr, - char *buf, size_t bufsiz); -extern int sysfs_has_attribute(struct sysfs_cxt *cxt, const char *attr); - -extern int sysfs_scanf(struct sysfs_cxt *cxt, const char *attr, - const char *fmt, ...) - __attribute__ ((format (scanf, 3, 4))); - -extern int sysfs_read_s64(struct sysfs_cxt *cxt, const char *attr, int64_t *res); -extern int sysfs_read_u64(struct sysfs_cxt *cxt, const char *attr, uint64_t *res); -extern int sysfs_read_int(struct sysfs_cxt *cxt, const char *attr, int *res); - -extern int sysfs_write_string(struct sysfs_cxt *cxt, const char *attr, const char *str); -extern int sysfs_write_u64(struct sysfs_cxt *cxt, const char *attr, uint64_t num); - -extern char *sysfs_get_devname(struct sysfs_cxt *cxt, char *buf, size_t bufsiz); - -extern char *sysfs_strdup(struct sysfs_cxt *cxt, const char *attr); - -extern int sysfs_count_dirents(struct sysfs_cxt *cxt, const char *attr); -extern int sysfs_count_partitions(struct sysfs_cxt *cxt, const char *devname); -extern dev_t sysfs_partno_to_devno(struct sysfs_cxt *cxt, int partno); -extern char *sysfs_get_slave(struct sysfs_cxt *cxt); - -extern char *sysfs_get_devchain(struct sysfs_cxt *cxt, char *buf, size_t bufsz); -extern int sysfs_next_subsystem(struct sysfs_cxt *cxt, char *devchain, char **subsys); -extern int sysfs_is_hotpluggable(struct sysfs_cxt *cxt); - -extern int sysfs_is_partition_dirent(DIR *dir, struct dirent *d, - const char *parent_name); - -extern int sysfs_devno_to_wholedisk(dev_t dev, char *diskname, - size_t len, dev_t *diskdevno); - -extern int sysfs_devno_is_lvm_private(dev_t devno); -extern int sysfs_devno_is_wholedisk(dev_t devno); - -extern int sysfs_scsi_get_hctl(struct sysfs_cxt *cxt, int *h, - int *c, int *t, int *l); -extern char *sysfs_scsi_host_strdup_attribute(struct sysfs_cxt *cxt, - const char *type, const char *attr); -extern int sysfs_scsi_host_is(struct sysfs_cxt *cxt, const char *type); -extern int sysfs_scsi_has_attribute(struct sysfs_cxt *cxt, const char *attr); -extern int sysfs_scsi_path_contains(struct sysfs_cxt *cxt, const char *pattern); - -/** - * sysfs_devname_sys_to_dev: - * @name: devname to be converted in place - * - * Linux kernel linux/drivers/base/core.c: device_get_devnode() - * defines a replacement of '!' in the /sys device name by '/' in the - * /dev device name. This helper replaces all ocurrences of '!' in - * @name by '/' to convert from /sys to /dev. - */ -static inline void sysfs_devname_sys_to_dev(char *name) -{ - char *c; - - if (name) - while ((c = strchr(name, '!'))) - c[0] = '/'; -} - -/** - * sysfs_devname_dev_to_sys: - * @name: devname to be converted in place - * - * See sysfs_devname_sys_to_dev(). - */ -static inline void sysfs_devname_dev_to_sys(char *name) -{ - char *c; - - if (name) - while ((c = strchr(name, '/'))) - c[0] = '!'; -} - -#endif /* UTIL_LINUX_SYSFS_H */