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 @@ -76,6 +76,7 @@ QString m_description; QString m_iconName; QPointer m_storageAccess; + bool m_isNetworkShare = false; }; } 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 @@ -23,8 +23,10 @@ #include "fstabnetworkshare.h" #include "fstabstorageaccess.h" #include "fstabservice.h" +#include "fstab_debug.h" #include #include +#include #include using namespace Solid::Backends::Fstab; @@ -36,15 +38,27 @@ m_device = m_uid; m_device.remove(parentUdi() + "/"); + const QString& fstype = FstabHandling::fstype(m_device); + qCDebug(FSTAB) << "Adding " << m_device << "type:" << fstype; + if (m_device.startsWith("//")) { m_vendor = m_device.mid(2, m_device.indexOf("/", 2) - 2); m_product = m_device.mid(m_device.indexOf("/", 2) + 1); - } else { + m_isNetworkShare = true; + } else if (fstype.startsWith("nfs")) { m_vendor = m_device.left(m_device.indexOf(":/")); m_product = m_device.mid(m_device.indexOf(":/") + 2); if (m_product.isEmpty()) { m_product = QStringLiteral("/"); } + m_isNetworkShare = true; + } else if (fstype.startsWith("fuse.")) { + 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 QStringList& gvfsOptions = FstabHandling::options(m_device); @@ -60,12 +74,21 @@ } if (m_description.isEmpty()) { - m_description = QCoreApplication::translate("", "%1 on %2", + if (m_isNetworkShare) { + m_description = QCoreApplication::translate("", "%1 on %2", "%1 is sharename, %2 is servername").arg(m_product, m_vendor); + } else { + m_description = QCoreApplication::translate("", "%1 (%2)", + "%1 is mountpoint, %2 is fs type").arg(m_product, m_vendor); + } } if (m_iconName.isEmpty()) { - m_iconName = QLatin1String("network-server"); + if (m_isNetworkShare) { + m_iconName = QLatin1String("network-server"); + } else { + m_iconName = QLatin1String("folder"); + } } } @@ -121,8 +144,10 @@ bool FstabDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type) const { - if (type == Solid::DeviceInterface::StorageAccess - || type == Solid::DeviceInterface::NetworkShare) { + if (type == Solid::DeviceInterface::StorageAccess) { + return true; + } + if (m_isNetworkShare && (type == Solid::DeviceInterface::NetworkShare)) { return true; } return false; @@ -135,7 +160,7 @@ m_storageAccess = new FstabStorageAccess(this); } return m_storageAccess; - } else if (type == Solid::DeviceInterface::NetworkShare) { + } else if (m_isNetworkShare && (type == Solid::DeviceInterface::NetworkShare)) { return new FstabNetworkShare(this); } return nullptr; 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 @@ -121,6 +121,24 @@ return false; } +bool _k_isFstabSupportedLocalFileSystem(const QString &fstype) +{ + if (fstype == "fuse.encfs" || + fstype == "fuse.cryfs") { + return true; + } + return false; +} + +QString _k_deviceNameForMountpoint(const QString &source, const QString &fstype, + const QString &mountpoint) +{ + if (fstype.startsWith("fuse.")) { + return fstype + mountpoint; + } + return source; +} + void Solid::Backends::Fstab::FstabHandling::_k_updateFstabMountPointsCache() { if (globalFstabCache->m_fstabCacheValid) { @@ -141,9 +159,10 @@ while ((fe = getmntent(fstab)) != nullptr) { const QString fsname = QFile::decodeName(fe->mnt_fsname); const QString fstype = QFile::decodeName(fe->mnt_type); - if (_k_isFstabNetworkFileSystem(fstype, fsname)) { + if (_k_isFstabNetworkFileSystem(fstype, fsname) || + _k_isFstabSupportedLocalFileSystem(fstype)) { const QString mountpoint = QFile::decodeName(fe->mnt_dir); - const QString device = fsname; + const QString device = _k_deviceNameForMountpoint(fsname, fstype, mountpoint); QStringList options = QFile::decodeName(fe->mnt_opts).split(QLatin1Char(',')); globalFstabCache->m_fstabCache.insert(device, mountpoint); @@ -185,7 +204,8 @@ } #endif //prevent accessing a blocking directory - if (_k_isFstabNetworkFileSystem(items.at(2), items.at(0))) { + if (_k_isFstabNetworkFileSystem(items.at(2), items.at(0)) || + _k_isFstabSupportedLocalFileSystem(items.at(2))) { const QString device = items.at(0); const QString mountpoint = items.at(1); @@ -282,9 +302,11 @@ for (int i = 0; i < num_fs; i++) { QString type = QFile::decodeName(mounted[i].f_fstypename); - if (_k_isFstabNetworkFileSystem(type, QString())) { - const QString device = QFile::decodeName(mounted[i].f_mntfromname); + if (_k_isFstabNetworkFileSystem(type, QString()) || + _k_isFstabSupportedLocalFileSystem(type)) { + 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->m_mtabCache.insert(device, mountpoint); globalFstabCache->m_fstabFstypeCache.insert(device, type); } @@ -299,9 +321,11 @@ STRUCT_MNTENT fe; while (GETMNTENT(mnttab, fe)) { QString type = QFile::decodeName(MOUNTTYPE(fe)); - if (_k_isFstabNetworkFileSystem(type, QString())) { - const QString device = QFile::decodeName(FSNAME(fe)); + if (_k_isFstabNetworkFileSystem(type, QString()) || + _k_isFstabSupportedLocalFileSystem(type)) { + const QString fsname = QFile::decodeName(FSNAME(fe)); const QString mountpoint = QFile::decodeName(MOUNTPOINT(fe)); + const QString device = _k_deviceNameForMountpoint(fsname, type, mountpoint); globalFstabCache->m_mtabCache.insert(device, mountpoint); globalFstabCache->m_fstabFstypeCache.insert(device, type); }