Solid

iokitstorage.cpp
1/*
2 SPDX-FileCopyrightText: 2017 René J.V. Bertin <rjvbertin@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "iokitstorage.h"
8
9#include <CoreFoundation/CoreFoundation.h>
10#include <DiskArbitration/DiskArbitration.h>
11
12using namespace Solid::Backends::IOKit;
13
14IOKitStorage::IOKitStorage(IOKitDevice *device)
15 : Block(device)
16 , daDict(new DADictionary(device))
17{
18}
19
20IOKitStorage::IOKitStorage(const IOKitDevice *device)
21 : Block(device)
22 , daDict(new DADictionary(device))
23{
24}
25
26IOKitStorage::~IOKitStorage()
27{
28 delete daDict;
29}
30
31Solid::StorageDrive::Bus IOKitStorage::bus() const
32{
33 const QString udi = m_device->udi();
34 // TODO: figure out how to return something useful here.
35 if (udi.contains(QStringLiteral("/SATA@"))) {
36 return Solid::StorageDrive::Sata;
37 }
38 if (udi.contains(QStringLiteral("/SDXC@"))) {
39 // TODO: return something finer grained; the built-in card reader
40 // is NOT connected via USB on Macs, for instance (but there's no PCI option)
41 return Solid::StorageDrive::Usb;
42 }
43 if (udi.contains(QStringLiteral("/IOUSBInterface@"))) {
44 return Solid::StorageDrive::Usb;
45 }
46 if (daDict->stringForKey(kDADiskDescriptionDeviceProtocolKey) == QStringLiteral("USB")) {
47 return Solid::StorageDrive::Usb;
48 }
49 return Solid::StorageDrive::Platform;
50}
51
52Solid::StorageDrive::DriveType IOKitStorage::driveType() const
53{
54 const QString udi = m_device->udi();
55 const QString type = m_device->property(QLatin1String("className")).toString();
56
57 if (type == QStringLiteral("IOCDMedia") //
58 || type == QStringLiteral("IOBDMedia") //
59 || type == QStringLiteral("IODVDMedia")) {
60 return Solid::StorageDrive::CdromDrive;
61 }
62 if (udi.contains(QStringLiteral("/SDXC@"))) {
63 return Solid::StorageDrive::SdMmc;
64 }
65 if (daDict->stringForKey(kDADiskDescriptionDeviceModelKey) == QStringLiteral("Compact Flash")) {
66 return Solid::StorageDrive::CompactFlash;
67 }
68 return Solid::StorageDrive::HardDisk;
69}
70
71bool IOKitStorage::isRemovable() const
72{
73 bool isInternal = false;
74 daDict->boolForKey(kDADiskDescriptionDeviceInternalKey, isInternal);
75 return !isInternal || m_device->property(QLatin1String("Removable")).toBool();
76}
77
78bool IOKitStorage::isHotpluggable() const
79{
80 const Solid::StorageDrive::DriveType type = driveType();
81 return bus() == Solid::StorageDrive::Usb //
82 || type == Solid::StorageDrive::CdromDrive //
83 || type == Solid::StorageDrive::SdMmc;
84}
85
86qulonglong IOKitStorage::size() const
87{
88 return m_device->property(QLatin1String("Size")).toULongLong();
89}
90
91QString IOKitStorage::vendor() const
92{
93 return daDict->stringForKey(kDADiskDescriptionDeviceVendorKey);
94}
95
96QString IOKitStorage::product() const
97{
98 return daDict->stringForKey(kDADiskDescriptionDeviceModelKey);
99}
100
101QString IOKitStorage::description() const
102{
103 return daDict->stringForKey(kDADiskDescriptionMediaNameKey);
104}
105
106#include "moc_iokitstorage.cpp"
DriveType
This enum type defines the type of drive a storage device can be.
Bus
This enum type defines the type of bus a storage device is attached to.
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool toBool() const const
QString toString() const const
qulonglong toULongLong(bool *ok) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:01:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.