File indexing completed on 2024-06-09 04:00:39

0001 /*
0002     SPDX-FileCopyrightText: 2017 René J.V. Bertin <rjvbertin@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "iokitvolume.h"
0008 #include "iokitgenericinterface.h"
0009 
0010 #include <CoreFoundation/CoreFoundation.h>
0011 
0012 using namespace Solid::Backends::IOKit;
0013 
0014 IOKitVolume::IOKitVolume(IOKitDevice *device)
0015     : Block(device)
0016     , daDict(new DADictionary(device))
0017 {
0018 }
0019 
0020 IOKitVolume::IOKitVolume(const IOKitDevice *device)
0021     : Block(device)
0022     , daDict(new DADictionary(device))
0023 {
0024 }
0025 
0026 IOKitVolume::~IOKitVolume()
0027 {
0028     delete daDict;
0029 }
0030 
0031 bool IOKitVolume::isIgnored() const
0032 {
0033     // ignore storage volumes that aren't mounted
0034     bool isIgnored = m_device->property(QStringLiteral("Open")).toBool() == false;
0035     m_device->setProperty("isIgnored", isIgnored);
0036     m_device->setProperty("isMounted", !isIgnored);
0037     return isIgnored;
0038 }
0039 
0040 Solid::StorageVolume::UsageType IOKitVolume::usage() const
0041 {
0042     const QString content = m_device->property(QStringLiteral("Content")).toString();
0043     if (content == QStringLiteral("CD_DA")) {
0044         // this is (probably) a CD track
0045         return Solid::StorageVolume::Other;
0046     }
0047     if (content.contains(QStringLiteral("partition_scheme"))) {
0048         return Solid::StorageVolume::PartitionTable;
0049     }
0050     return Solid::StorageVolume::FileSystem;
0051 }
0052 
0053 QString IOKitVolume::fsType() const
0054 {
0055     return daDict->stringForKey(kDADiskDescriptionVolumeKindKey);
0056 }
0057 
0058 QString IOKitVolume::label() const
0059 {
0060     return daDict->stringForKey(kDADiskDescriptionVolumeNameKey);
0061 }
0062 
0063 QString IOKitVolume::uuid() const
0064 {
0065     return m_device->property(QStringLiteral("UUID")).toString();
0066 }
0067 
0068 qulonglong IOKitVolume::size() const
0069 {
0070     return m_device->property(QStringLiteral("Size")).toULongLong();
0071 }
0072 
0073 QString IOKitVolume::encryptedContainerUdi() const
0074 {
0075     return QString();
0076 }
0077 
0078 QString IOKitVolume::vendor() const
0079 {
0080     return daDict->stringForKey(kDADiskDescriptionDeviceVendorKey);
0081 }
0082 
0083 QString IOKitVolume::product() const
0084 {
0085     return daDict->stringForKey(kDADiskDescriptionDeviceModelKey);
0086 }
0087 
0088 QString IOKitVolume::description() const
0089 {
0090     return daDict->stringForKey(kDADiskDescriptionMediaNameKey);
0091 }
0092 
0093 DADiskRef IOKitVolume::daRef() const
0094 {
0095     return daDict->daRef;
0096 }
0097 
0098 #include "moc_iokitvolume.cpp"