diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index 1bb4f7f..e70510e 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -44,7 +44,6 @@ #include #include -#include #include #include @@ -356,57 +355,53 @@ FileSystem::Type LibPartedBackend::detectFileSystem(const QString& partitionPath { FileSystem::Type rval = FileSystem::Unknown; - ExternalCommand cmd(QString::fromLatin1("udevadm"), - { QString::fromLatin1("info"), - QString::fromLatin1("--query"), - QString::fromLatin1("property"), - partitionPath } ); - QRegularExpression re(QString::fromLatin1("(ID_FS_TYPE=)([\\w]+)")); + blkid_cache cache; + if (blkid_get_cache(&cache, nullptr) == 0) { + blkid_dev dev; - if (!cmd.run(-1) || !(cmd.exitCode() == 0)) - return rval; - QRegularExpressionMatch reFileSystemType = re.match(cmd.output()); - if (!reFileSystemType.hasMatch()) - 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); - QString s = reFileSystemType.captured(2); + 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; + } - if (s == QString::fromLatin1("ext2")) rval = FileSystem::Ext2; - else if (s == QString::fromLatin1("ext3")) rval = FileSystem::Ext3; - else if (s.startsWith(QString::fromLatin1("ext4"))) rval = FileSystem::Ext4; - else if (s == QString::fromLatin1("swap")) rval = FileSystem::LinuxSwap; - else if (s == QString::fromLatin1("ntfs")) rval = FileSystem::Ntfs; - else if (s == QString::fromLatin1("reiserfs")) rval = FileSystem::ReiserFS; - else if (s == QString::fromLatin1("reiser4")) rval = FileSystem::Reiser4; - else if (s == QString::fromLatin1("xfs")) rval = FileSystem::Xfs; - else if (s == QString::fromLatin1("jfs")) rval = FileSystem::Jfs; - else if (s == QString::fromLatin1("hfs")) rval = FileSystem::Hfs; - else if (s == QString::fromLatin1("hfsplus")) rval = FileSystem::HfsPlus; - else if (s == QString::fromLatin1("ufs")) rval = FileSystem::Ufs; - else if (s == QString::fromLatin1("vfat")) { - // udev uses ID_FS_VERSION to distinguish between FAT12, FAT16 and FAT32 - re.setPattern(QString::fromLatin1("(ID_FS_VERSION=)([\\w]+)")); - QRegularExpressionMatch reFileSystemType = re.match(cmd.output()); - if (!reFileSystemType.hasMatch()) - return rval; - QString fsVersion = reFileSystemType.captured(2); - if (fsVersion == QString::fromLatin1("FAT16")) - rval = FileSystem::Fat16; - if (fsVersion == QString::fromLatin1("FAT32")) - rval = FileSystem::Fat32; - else - rval = FileSystem::Fat16; // FIXME FAT12 - } else if (s == QString::fromLatin1("btrfs")) rval = FileSystem::Btrfs; - else if (s == QString::fromLatin1("ocfs2")) rval = FileSystem::Ocfs2; - else if (s == QString::fromLatin1("zfs_member")) rval = FileSystem::Zfs; - else if (s == QString::fromLatin1("hpfs")) rval = FileSystem::Hpfs; - else if (s == QString::fromLatin1("crypto_LUKS")) rval = FileSystem::Luks; - else if (s == QString::fromLatin1("exfat")) rval = FileSystem::Exfat; - else if (s == QString::fromLatin1("nilfs2")) rval = FileSystem::Nilfs2; - else if (s == QString::fromLatin1("LVM2_member")) rval = FileSystem::Lvm2_PV; - else if (s == QString::fromLatin1("f2fs")) rval = FileSystem::F2fs; - else - qWarning() << "udev: unknown file system type " << s << " on " << partitionPath; + blkid_put_cache(cache); + } return rval; }