File indexing completed on 2024-06-09 04:00:42
0001 /* 0002 SPDX-FileCopyrightText: 2010 Michael Zanetti <mzanetti@kde.org> 0003 SPDX-FileCopyrightText: 2010-2012 Lukáš Tinkl <ltinkl@redhat.com> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include "udisksstoragevolume.h" 0009 #include "udisks2.h" 0010 0011 #include <QDir> 0012 0013 using namespace Solid::Backends::UDisks2; 0014 0015 StorageVolume::StorageVolume(Device *device) 0016 : Block(device) 0017 { 0018 } 0019 0020 StorageVolume::~StorageVolume() 0021 { 0022 } 0023 0024 QString StorageVolume::encryptedContainerUdi() const 0025 { 0026 const QString path = m_device->prop("CryptoBackingDevice").value<QDBusObjectPath>().path(); 0027 if (path.isEmpty() || path == "/") { 0028 return QString(); 0029 } else { 0030 return path; 0031 } 0032 } 0033 0034 qulonglong StorageVolume::size() const 0035 { 0036 return m_device->prop("Size").toULongLong(); 0037 } 0038 0039 QString StorageVolume::uuid() const 0040 { 0041 return m_device->prop("IdUUID").toString(); 0042 } 0043 0044 QString StorageVolume::label() const 0045 { 0046 QString label = m_device->prop("HintName").toString(); 0047 if (label.isEmpty()) { 0048 label = m_device->prop("IdLabel").toString(); 0049 } 0050 if (label.isEmpty()) { 0051 label = m_device->prop("Name").toString(); 0052 } 0053 return label; 0054 } 0055 0056 QString StorageVolume::fsType() const 0057 { 0058 return m_device->prop("IdType").toString(); 0059 } 0060 0061 Solid::StorageVolume::UsageType StorageVolume::usage() const 0062 { 0063 const QString usage = m_device->prop("IdUsage").toString(); 0064 0065 if (m_device->hasInterface(UD2_DBUS_INTERFACE_FILESYSTEM)) { 0066 return Solid::StorageVolume::FileSystem; 0067 } else if (m_device->isPartitionTable()) { 0068 return Solid::StorageVolume::PartitionTable; 0069 } else if (usage == "raid") { 0070 return Solid::StorageVolume::Raid; 0071 } else if (m_device->isEncryptedContainer()) { 0072 return Solid::StorageVolume::Encrypted; 0073 } else if (usage == "unused" || usage.isEmpty()) { 0074 return Solid::StorageVolume::Unused; 0075 } else { 0076 return Solid::StorageVolume::Other; 0077 } 0078 } 0079 0080 bool StorageVolume::isIgnored() const 0081 { 0082 if (m_device->prop("HintIgnore").toBool()) { 0083 return true; 0084 } 0085 0086 const QStringList mountOptions = m_device->prop("UserspaceMountOptions").toStringList(); 0087 if (mountOptions.contains(QLatin1String("x-gdu.hide"))) { 0088 return true; 0089 } 0090 0091 const Solid::StorageVolume::UsageType usg = usage(); 0092 0093 /* clang-format off */ 0094 if (m_device->isSwap() 0095 || ((usg == Solid::StorageVolume::Unused 0096 || usg == Solid::StorageVolume::Other 0097 || usg == Solid::StorageVolume::PartitionTable) 0098 && !m_device->isOpticalDisc())) { /* clang-format on */ 0099 return true; 0100 } 0101 0102 const QString backingFile = m_device->prop("BackingFile").toString(); 0103 return !backingFile.isEmpty() && !backingFile.startsWith(QDir::homePath()); 0104 } 0105 0106 #include "moc_udisksstoragevolume.cpp"