diff --git a/src/solid/devices/backends/fstab/fstabdevice.h b/src/solid/devices/backends/fstab/fstabdevice.h --- a/src/solid/devices/backends/fstab/fstabdevice.h +++ b/src/solid/devices/backends/fstab/fstabdevice.h @@ -80,6 +80,7 @@ Other = 0, NetworkShare, Encrypted, + Iso, }; StorageType m_storageType = StorageType::Other; }; diff --git a/src/solid/devices/backends/fstab/fstabdevice.cpp b/src/solid/devices/backends/fstab/fstabdevice.cpp --- a/src/solid/devices/backends/fstab/fstabdevice.cpp +++ b/src/solid/devices/backends/fstab/fstabdevice.cpp @@ -31,6 +31,32 @@ using namespace Solid::Backends::Fstab; +namespace { + +QString ShortenPath(const QString& path) +{ + QString home = QDir::homePath(); + if (path.startsWith(home)) { + return QLatin1Literal("~") + path.mid(home.length()); + } + return path; +} + +QString GetFilePathFromFuseIsoMtabFile(const QString& mountPath) +{ + QMultiHash activeMounts; + QHash activeFstype; + FstabHandling::parseMtabFile(QDir::homePath() + QLatin1Literal("/.mtab.fuseiso"), activeMounts, activeFstype); + for (auto it = activeMounts.constKeyValueBegin(); it != activeMounts.constKeyValueEnd(); ++it) { + if ((*it).second == mountPath) { + return (*it).first; + } + } + return QString(); +} + +} + FstabDevice::FstabDevice(QString uid) : Solid::Ifaces::Device(), m_uid(uid) @@ -55,14 +81,17 @@ } else if (fstype.startsWith("fuse.") || fstype == QLatin1String("overlay")) { m_vendor = fstype; - m_product = m_device.mid(m_device.indexOf(fstype) + fstype.length()); - QString home = QDir::homePath(); - if (m_product.startsWith(home)) { - m_product = "~" + m_product.mid(home.length()); - } + const QString mountPath = m_device.mid(m_device.indexOf(fstype) + fstype.length()); + m_product = ShortenPath(mountPath); if ((fstype == QLatin1String("fuse.encfs")) || (fstype == QLatin1String("fuse.cryfs"))) { m_storageType = StorageType::Encrypted; + } else if (fstype == QLatin1String("fuse.fuseiso")) { + const QString isoFilePath = GetFilePathFromFuseIsoMtabFile(mountPath); + if (!isoFilePath.isEmpty()) { + m_description = ShortenPath(isoFilePath) + QLatin1String(" on ") + m_product; + } + m_storageType = StorageType::Iso; } } @@ -93,6 +122,8 @@ m_iconName = QLatin1String("network-server"); } else if (m_storageType == StorageType::Encrypted) { m_iconName = QLatin1String("folder-decrypted"); + } else if (m_storageType == StorageType::Iso) { + m_iconName = QLatin1String("media-optical-data"); } else { const QStringList& mountPoints = FstabHandling::mountPoints(m_device); const QString home = QDir::homePath(); diff --git a/src/solid/devices/backends/fstab/fstabhandling.h b/src/solid/devices/backends/fstab/fstabhandling.h --- a/src/solid/devices/backends/fstab/fstabhandling.h +++ b/src/solid/devices/backends/fstab/fstabhandling.h @@ -50,6 +50,7 @@ static bool callSystemCommand(const QString &commandName, const QStringList &args, const QObject *recvr, std::function callback); static void flushMtabCache(); static void flushFstabCache(); + static void parseMtabFile(const QString& mtabPath, QMultiHash& activeMounts, QHash& activeFstype); private: static void _k_updateMtabMountPointsCache(); diff --git a/src/solid/devices/backends/fstab/fstabhandling.cpp b/src/solid/devices/backends/fstab/fstabhandling.cpp --- a/src/solid/devices/backends/fstab/fstabhandling.cpp +++ b/src/solid/devices/backends/fstab/fstabhandling.cpp @@ -125,7 +125,8 @@ { if (fstype == "fuse.encfs" || fstype == "fuse.cryfs" || - fstype == "overlay") { + fstype == "overlay" || + fstype == "fuse.fuseiso" || fstype == "fuseiso") { return true; } return false; @@ -292,6 +293,13 @@ globalFstabCache->localData().m_mtabCache.clear(); + parseMtabFile(MNTTAB, globalFstabCache->localData().m_mtabCache, globalFstabCache->localData().m_fstabFstypeCache); + + globalFstabCache->localData().m_mtabCacheValid = true; +} + +void Solid::Backends::Fstab::FstabHandling::parseMtabFile(const QString& mtabPath, QMultiHash& activeMounts, QHash& activeFstype) +{ #if HAVE_GETMNTINFO #if GETMNTINFO_USES_STATVFS @@ -309,14 +317,14 @@ const QString fsname = QFile::decodeName(mounted[i].f_mntfromname); const QString mountpoint = QFile::decodeName(mounted[i].f_mntonname); const QString device = _k_deviceNameForMountpoint(fsname, type, mountpoint); - globalFstabCache->localData().m_mtabCache.insert(device, mountpoint); - globalFstabCache->localData().m_fstabFstypeCache.insert(device, type); + activeMounts.insert(device, mountpoint); + activeFstype.insert(device, type); } } #else STRUCT_SETMNTENT mnttab; - if ((mnttab = SETMNTENT(MNTTAB, "r")) == nullptr) { + if ((mnttab = SETMNTENT(mtabPath.toLocal8Bit().data(), "r")) == nullptr) { return; } @@ -328,14 +336,12 @@ const QString fsname = QFile::decodeName(FSNAME(fe)); const QString mountpoint = QFile::decodeName(MOUNTPOINT(fe)); const QString device = _k_deviceNameForMountpoint(fsname, type, mountpoint); - globalFstabCache->localData().m_mtabCache.insert(device, mountpoint); - globalFstabCache->localData().m_fstabFstypeCache.insert(device, type); + activeMounts.insert(device, mountpoint); + activeFstype.insert(device, type); } } ENDMNTENT(mnttab); #endif - - globalFstabCache->localData().m_mtabCacheValid = true; } QStringList Solid::Backends::Fstab::FstabHandling::currentMountPoints(const QString &device)