1 /* 2 SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de> 3 SPDX-FileCopyrightText: 2008 Laurent Montel <montel@kde.org> 4 SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org> 5 SPDX-FileCopyrightText: 2015 Chris Campbell <c.j.campbell@ed.ac.uk> 6 SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com> 7 SPDX-FileCopyrightText: 2016-2018 Andrius Štikonas <andrius@stikonas.eu> 8 9 SPDX-License-Identifier: GPL-3.0-or-later 10 */ 11 12 #ifndef KPMCORE_DEVICE_H 13 #define KPMCORE_DEVICE_H 14 15 #include "util/libpartitionmanagerexport.h" 16 17 #include <QString> 18 #include <QObject> 19 20 #include <memory> 21 22 class PartitionTable; 23 class CreatePartitionTableOperation; 24 class CoreBackend; 25 class SmartStatus; 26 class DevicePrivate; 27 28 /** A device description. 29 30 Represents a device like /dev/sda. Contains information about 31 the device (name, status, size...) but does not operate on 32 the device itself. @see CoreBackendDevice 33 34 Devices are the outermost entity; they contain a PartitionTable that itself contains Partitions. 35 36 @see PartitionTable, Partition 37 @author Volker Lanz <vl@fidra.de> 38 */ 39 class LIBKPMCORE_EXPORT Device : public QObject 40 { 41 Device &operator=(const Device &) = delete; 42 43 friend class CreatePartitionTableOperation; 44 friend class CoreBackend; 45 46 public: 47 enum class Type { 48 Unknown_Device, 49 Disk_Device, 50 LVM_Device, /* VG */ 51 SoftwareRAID_Device, /* software RAID device, i.e. mdraid */ 52 FakeRAID_Device, /* fake RAID device, i.e. dmraid */ 53 }; 54 55 explicit Device(std::shared_ptr<DevicePrivate> d_ptr, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogicalSectors, const QString& iconName = QString(), Device::Type type = Device::Type::Disk_Device); 56 57 public: 58 explicit Device(const Device& other); 59 ~Device() override; 60 61 virtual bool operator==(const Device& other) const; 62 virtual bool operator!=(const Device& other) const; 63 64 /**< @return the Device's name, usually some manufacturer string */ 65 virtual QString& name(); 66 virtual const QString& name() const; 67 68 /**< @return the Device's node, for example "/dev/sda" */ 69 virtual const QString& deviceNode() const; 70 71 /**< @return the logical sector size the Device uses (would be extent size for e.g. LVM devices) */ 72 virtual qint64 logicalSize() const; 73 74 /**< @return the total number of logical sectors on the device */ 75 virtual qint64 totalLogical() const; 76 77 /**< @return the Device's PartitionTable */ 78 virtual PartitionTable* partitionTable(); 79 virtual const PartitionTable* partitionTable() const; 80 81 /** 82 * Change the description of the partition table for different one. 83 * The device itself is not changed; use CreatePartitionTableOperation 84 * for that. The Device instance becomes the owner of @p ptable . 85 */ 86 virtual void setPartitionTable(PartitionTable* ptable); 87 capacity()88 virtual qint64 capacity() const { /**< @return the Device's capacity in bytes */ 89 return logicalSize() * totalLogical(); 90 } 91 92 /**< @return suggested icon name for this Device */ 93 virtual const QString& iconName() const; 94 95 /**< @param name set the new Icon for this Device */ 96 virtual void setIconName(const QString& name); 97 98 virtual SmartStatus& smartStatus(); 99 virtual const SmartStatus& smartStatus() const; 100 101 virtual Device::Type type() const; 102 103 virtual QString prettyName() const; 104 105 protected: 106 std::shared_ptr<DevicePrivate> d; 107 }; 108 109 #endif 110