Solid

winstoragedrive.cpp
1/*
2 SPDX-FileCopyrightText: 2013 Patrick von Reth <vonreth@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6#include "winstoragedrive.h"
7
8#include <qt_windows.h>
9#include <winioctl.h>
10
11#if defined(__MINGW32__) && !defined(IOCTL_STORAGE_QUERY_PROPERTY)
12#include <winioctl_backport.h>
13#endif
14
15using namespace Solid::Backends::Win;
16
17WinStorageDrive::WinStorageDrive(WinDevice *device)
18 : WinBlock(device)
19{
20 updateCache();
21}
22
23WinStorageDrive::~WinStorageDrive()
24{
25}
26
27Solid::StorageDrive::Bus WinStorageDrive::bus() const
28{
29 return m_bus;
30}
31
32Solid::StorageDrive::DriveType WinStorageDrive::driveType() const
33{
34 if (m_device->type() == Solid::DeviceInterface::OpticalDrive) {
35 return Solid::StorageDrive::CdromDrive;
36 }
37 if (bus() == Solid::StorageDrive::Usb) {
38 return Solid::StorageDrive::MemoryStick;
39 }
40 return Solid::StorageDrive::HardDisk;
41}
42
43bool WinStorageDrive::isRemovable() const
44{
45 return m_isRemovable;
46}
47
48bool WinStorageDrive::isHotpluggable() const
49{
50 return m_isHotplugges;
51}
52
53qulonglong WinStorageDrive::size() const
54{
55 return m_size;
56}
57
58void WinStorageDrive::updateCache()
59{
60 STORAGE_PROPERTY_QUERY storageProperty;
61 storageProperty.PropertyId = StorageAdapterProperty;
62 storageProperty.QueryType = PropertyStandardQuery;
63
64 QString dev;
65 if (m_device->type() == Solid::DeviceInterface::OpticalDrive) {
66 dev = WinBlock::driveLetterFromUdi(m_device->udi());
67 } else {
68 dev = QLatin1String("PhysicalDrive") + QString::number(deviceMajor());
69 }
70 STORAGE_ADAPTER_DESCRIPTOR busInfo = WinDeviceManager::getDeviceInfo<STORAGE_ADAPTER_DESCRIPTOR>(dev, IOCTL_STORAGE_QUERY_PROPERTY, &storageProperty);
71
72 switch (busInfo.BusType) {
73 case BusTypeUsb:
74 m_bus = Solid::StorageDrive::Usb;
75 break;
76 case BusType1394:
77 m_bus = Solid::StorageDrive::Ieee1394;
78 break;
79 case BusTypeScsi:
80 m_bus = Solid::StorageDrive::Scsi;
81 break;
82 case BusTypeAta:
83 default:
84 m_bus = Solid::StorageDrive::Ide;
85 }
86
87 DISK_GEOMETRY sizeInfo = WinDeviceManager::getDeviceInfo<DISK_GEOMETRY>(dev, IOCTL_DISK_GET_DRIVE_GEOMETRY);
88 m_size = sizeInfo.Cylinders.QuadPart * sizeInfo.TracksPerCylinder * sizeInfo.SectorsPerTrack * sizeInfo.BytesPerSector;
89
90 STORAGE_HOTPLUG_INFO plugInfo = WinDeviceManager::getDeviceInfo<STORAGE_HOTPLUG_INFO>(dev, IOCTL_STORAGE_GET_HOTPLUG_INFO);
91 m_isHotplugges = plugInfo.DeviceHotplug;
92 m_isRemovable = plugInfo.MediaRemovable;
93}
94
95#include "moc_winstoragedrive.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.
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:53:48 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.