From 0e9298baf895a2fadb2bd13250358f57154e5915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Fri, 29 Jul 2016 18:15:28 +0100 Subject: [PATCH] Revert "Add KAuth helper to detectFileSystem." This reverts commit 71921cf500c5ae0cdde0176cf240e4a9fb282320. --- src/plugins/libparted/helpers/CMakeLists.txt | 2 +- .../helpers/org.kde.kpmcore.scan.actions | 21 ----- src/plugins/libparted/helpers/scan.cpp | 35 ------- src/plugins/libparted/helpers/scan.h | 1 - src/plugins/libparted/libpartedbackend.cpp | 92 ++++++++++--------- src/plugins/libparted/libpartedbackend.h | 2 +- 6 files changed, 53 insertions(+), 100 deletions(-) diff --git a/src/plugins/libparted/helpers/CMakeLists.txt b/src/plugins/libparted/helpers/CMakeLists.txt index bc57e0a..fe13dd7 100644 --- a/src/plugins/libparted/helpers/CMakeLists.txt +++ b/src/plugins/libparted/helpers/CMakeLists.txt @@ -1,5 +1,5 @@ add_executable(kpmcore_scan scan.cpp) -target_link_libraries(kpmcore_scan ${LIBPARTED_LIBS} ${BLKID_LIBRARIES} KF5::Auth) +target_link_libraries(kpmcore_scan ${LIBPARTED_LIBS} KF5::Auth) install(TARGETS kpmcore_scan DESTINATION ${KAUTH_HELPER_INSTALL_DIR}) kauth_install_helper_files(kpmcore_scan org.kde.kpmcore.scan root) diff --git a/src/plugins/libparted/helpers/org.kde.kpmcore.scan.actions b/src/plugins/libparted/helpers/org.kde.kpmcore.scan.actions index 52252cc..03856b8 100644 --- a/src/plugins/libparted/helpers/org.kde.kpmcore.scan.actions +++ b/src/plugins/libparted/helpers/org.kde.kpmcore.scan.actions @@ -45,24 +45,3 @@ Description[uk]=Читання даних щодо використаних се Description[x-test]=xxRead used sectorsxx Policy=yes Persistence=session - -[org.kde.kpmcore.scan.detectfilesystem] -Name=Detect file system type action -Name[ca]=Acció de detecció del tipus de sistema de fitxers -Name[nl]=Actie voor type bestandssysteem detecteren -Name[pt]=Acção de detecção do tipo de sistema de ficheiros -Name[sl]=Dejanje zaznavanja vrste datotečnega sistema -Name[sv]=Åtgärd för att detektera typ av filsystem -Name[uk]=Дія із визначення типу файлової системи -Name[x-test]=xxDetect file system type actionxx -Description=Detect file system type -Description[ca]=Detecta el tipus de sistema de fitxers -Description[de]=Dateisystemtyp erkennen -Description[nl]=Type bestandssysteem detecteren -Description[pt]=Detectar o tipo de sistema de ficheiros -Description[sl]=Zaznaj vrsto datotečnega sistema -Description[sv]=Detektera typ av filsystem -Description[uk]=Визначення типу файлової системи -Description[x-test]=xxDetect file system typexx -Policy=yes -Persistence=session diff --git a/src/plugins/libparted/helpers/scan.cpp b/src/plugins/libparted/helpers/scan.cpp index dd65dbb..13e08fa 100644 --- a/src/plugins/libparted/helpers/scan.cpp +++ b/src/plugins/libparted/helpers/scan.cpp @@ -19,8 +19,6 @@ #include "core/partitiontable.h" #include "plugins/libparted/pedflags.h" -#include - ActionReply Scan::scandevice(const QVariantMap& args) { ActionReply reply; @@ -157,37 +155,4 @@ ActionReply Scan::readsectorsused(const QVariantMap& args) return reply; } -ActionReply Scan::detectfilesystem(const QVariantMap& args) -{ - ActionReply reply; - QString deviceNode = args[QStringLiteral("deviceNode")].toString(); - - blkid_cache cache; - if (blkid_get_cache(&cache, nullptr) == 0) { - blkid_dev dev; - - if ((dev = blkid_get_dev(cache, deviceNode.toLocal8Bit().constData(), BLKID_DEV_NORMAL)) != nullptr) { - char *string = blkid_get_tag_value(cache, "TYPE", deviceNode.toLocal8Bit().constData()); - QString s = QString::fromUtf8(string); - free(string); - - if (s == QStringLiteral("vfat")) { - // libblkid uses SEC_TYPE to distinguish between FAT16 and FAT32 - string = blkid_get_tag_value(cache, "SEC_TYPE", deviceNode.toLocal8Bit().constData()); - QString st = QString::fromUtf8(string); - free(string); - if (st == QStringLiteral("msdos")) - reply.addData(QStringLiteral("fileSystem"), QStringLiteral("fat16")); - else - reply.addData(QStringLiteral("fileSystem"), QStringLiteral("fat32")); - } - else - reply.addData(QStringLiteral("fileSystem"), s); - } - blkid_put_cache(cache); - } - - return reply; -} - KAUTH_HELPER_MAIN("org.kde.kpmcore.scan", Scan) diff --git a/src/plugins/libparted/helpers/scan.h b/src/plugins/libparted/helpers/scan.h index 9a11177..dca38da 100644 --- a/src/plugins/libparted/helpers/scan.h +++ b/src/plugins/libparted/helpers/scan.h @@ -31,7 +31,6 @@ class Scan : public QObject public Q_SLOTS: ActionReply scandevice(const QVariantMap& args); ActionReply readsectorsused(const QVariantMap& args); - ActionReply detectfilesystem(const QVariantMap& args); }; // -------------------------------------------------------------------------- diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index 5b87bf3..95ac69d 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -41,6 +41,8 @@ #include "util/externalcommand.h" #include "util/helpers.h" +#include + #include #include #include @@ -196,9 +198,6 @@ Device* LibPartedBackend::scanDevice(const QString& deviceNode) QList partitionEnd = job->data()[QLatin1String("partitionEnd")].toList(); QList partitionBusy = job->data()[QLatin1String("partitionBusy")].toList(); - QList availableFlags = job->data()[QLatin1String("availableFlags")].toList(); - QList activeFlags = job->data()[QLatin1String("activeFlags")].toList(); - quint32 totalPartitions = partitionPath.size(); QList partitions; for (quint32 i = 0; i < totalPartitions; ++i) { @@ -276,7 +275,9 @@ Device* LibPartedBackend::scanDevice(const QString& deviceNode) mounted = busy; } + QList availableFlags = job->data()[QLatin1String("availableFlags")].toList(); PartitionTable::Flags available = static_cast(availableFlags[i].toInt()); + QList activeFlags = job->data()[QLatin1String("activeFlags")].toList(); PartitionTable::Flags active = static_cast(activeFlags[i].toInt()); Partition* part = new Partition(parent, *d, PartitionRole(r), fs, start, end, partitionNode, available, mountPoint, mounted, active); @@ -345,52 +346,61 @@ QList LibPartedBackend::scanDevices(bool excludeReadOnly) } /** Detects the type of a FileSystem given a PedDevice and a PedPartition - @param deviceNode path to the partition + @param partitionPath path to the partition @return the detected FileSystem type (FileSystem::Unknown if not detected) */ -FileSystem::Type LibPartedBackend::detectFileSystem(const QString& deviceNode) +FileSystem::Type LibPartedBackend::detectFileSystem(const QString& partitionPath) { FileSystem::Type rval = FileSystem::Unknown; - KAuth::Action action = QStringLiteral("org.kde.kpmcore.scan.detectfilesystem"); - action.setHelperId(QStringLiteral("org.kde.kpmcore.scan")); - QVariantMap args = {{ QStringLiteral("deviceNode"), deviceNode }}; - action.setArguments(args); + blkid_cache cache; + if (blkid_get_cache(&cache, nullptr) == 0) { + blkid_dev dev; - KAuth::ExecuteJob *job = action.execute(); - if (!job->exec()) { - qWarning() << "KAuth returned an error code: " << job->errorString(); - return rval; + if ((dev = blkid_get_dev(cache, + partitionPath.toLocal8Bit().constData(), + BLKID_DEV_NORMAL)) != nullptr) { + char *string = blkid_get_tag_value(cache, "TYPE", partitionPath.toLocal8Bit().constData()); + QString s = QString::fromUtf8(string); + free(string); + + 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 + string = blkid_get_tag_value(cache, "SEC_TYPE", partitionPath.toLocal8Bit().constData()); + QString st = QString::fromUtf8(string); + free(string); + 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); } - QString s = job->data()[QLatin1String("fileSystem")].toString(); - - 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("fat16")) rval = FileSystem::Fat16; - else if (s == QStringLiteral("fat32")) 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 " << deviceNode; - return rval; } diff --git a/src/plugins/libparted/libpartedbackend.h b/src/plugins/libparted/libpartedbackend.h index c750a14..cae8664 100644 --- a/src/plugins/libparted/libpartedbackend.h +++ b/src/plugins/libparted/libpartedbackend.h @@ -66,7 +66,7 @@ public: bool closeDevice(CoreBackendDevice* core_device) override; Device* scanDevice(const QString& deviceNode) override; QList scanDevices(bool excludeReadOnly = true) override; - FileSystem::Type detectFileSystem(const QString& deviceNode) override; + FileSystem::Type detectFileSystem(const QString& partitionPath) override; static QString lastPartedExceptionMessage();