2015-06-04 01:29:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
|
|
|
|
2018-04-05 21:52:17 +01:00
|
|
|
#ifndef KPMCORE_DEVICE_H
|
2017-09-10 20:12:52 +01:00
|
|
|
#define KPMCORE_DEVICE_H
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-05-06 22:36:24 +01:00
|
|
|
#include "util/libpartitionmanagerexport.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QObject>
|
|
|
|
|
2018-04-08 14:45:59 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
class PartitionTable;
|
|
|
|
class CreatePartitionTableOperation;
|
|
|
|
class CoreBackend;
|
|
|
|
class SmartStatus;
|
2018-04-09 00:34:45 +01:00
|
|
|
class DevicePrivate;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2017-10-03 10:23:10 +01:00
|
|
|
/** A device description.
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2017-10-03 10:23:10 +01:00
|
|
|
Represents a device like /dev/sda. Contains information about
|
|
|
|
the device (name, status, size ..) but does not operate on
|
|
|
|
the device itself. @see CoreBackendDevice
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
Devices are the outermost entity; they contain a PartitionTable that itself contains Partitions.
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
@see PartitionTable, Partition
|
|
|
|
@author Volker Lanz <vl@fidra.de>
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
class LIBKPMCORE_EXPORT Device : public QObject
|
|
|
|
{
|
2016-09-07 16:35:35 +01:00
|
|
|
Device &operator=(const Device &) = delete;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
friend class CreatePartitionTableOperation;
|
|
|
|
friend class CoreBackend;
|
|
|
|
|
|
|
|
public:
|
2018-04-09 02:57:45 +01:00
|
|
|
enum class Type {
|
|
|
|
Unknown_Device,
|
|
|
|
Disk_Device,
|
|
|
|
LVM_Device, /* VG */
|
2018-07-10 00:01:34 +01:00
|
|
|
SoftwareRAID_Device, /* software RAID device, i.e. mdraid */
|
2018-07-11 15:57:56 +01:00
|
|
|
FakeRAID_Device, /* fake RAID device, i.e. dmraid */
|
2016-05-31 19:28:31 +01:00
|
|
|
};
|
|
|
|
|
2018-04-09 02:57:45 +01:00
|
|
|
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);
|
2018-04-09 00:34:45 +01:00
|
|
|
|
2016-05-31 19:28:31 +01:00
|
|
|
public:
|
2016-09-08 17:11:04 +01:00
|
|
|
explicit Device(const Device& other);
|
2016-05-31 19:28:31 +01:00
|
|
|
virtual ~Device();
|
2015-07-13 15:16:36 +01:00
|
|
|
|
2016-05-31 19:28:31 +01:00
|
|
|
virtual bool operator==(const Device& other) const;
|
|
|
|
virtual bool operator!=(const Device& other) const;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
2018-04-08 14:45:59 +01:00
|
|
|
/**< @return the Device's name, usually some manufacturer string */
|
|
|
|
virtual QString& name();
|
|
|
|
virtual const QString& name() const;
|
2016-09-24 21:09:11 +01:00
|
|
|
|
2018-04-08 14:45:59 +01:00
|
|
|
/**< @return the Device's node, for example "/dev/sda" */
|
|
|
|
virtual const QString& deviceNode() const;
|
2016-09-20 22:56:48 +01:00
|
|
|
|
2018-04-08 14:45:59 +01:00
|
|
|
/**< @return the logical sector size the Device uses (would be extent size for e.g. LVM devices) */
|
|
|
|
virtual qint64 logicalSize() const;
|
2016-05-31 19:28:31 +01:00
|
|
|
|
2018-04-08 14:45:59 +01:00
|
|
|
/**< @return the total number of logical sectors on the device */
|
|
|
|
virtual qint64 totalLogical() const;
|
2016-09-20 22:56:48 +01:00
|
|
|
|
2018-04-08 14:45:59 +01:00
|
|
|
/**< @return the Device's PartitionTable */
|
|
|
|
virtual PartitionTable* partitionTable();
|
|
|
|
virtual const PartitionTable* partitionTable() const;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
2017-10-03 10:23:10 +01:00
|
|
|
/**
|
|
|
|
* Change the description of the partition table for different one.
|
|
|
|
* The device itself is not changed; use CreatePartitionTableOperation
|
|
|
|
* for that. The Device instance becomes the owner of @p ptable .
|
|
|
|
*/
|
2018-04-08 14:45:59 +01:00
|
|
|
virtual void setPartitionTable(PartitionTable* ptable);
|
2015-07-13 15:16:36 +01:00
|
|
|
|
2018-04-08 14:45:59 +01:00
|
|
|
virtual qint64 capacity() const { /**< @return the Device's capacity in bytes */
|
|
|
|
return logicalSize() * totalLogical();
|
2016-05-31 19:28:31 +01:00
|
|
|
}
|
2016-09-20 22:56:48 +01:00
|
|
|
|
2018-04-08 14:45:59 +01:00
|
|
|
/**< @return suggested icon name for this Device */
|
|
|
|
virtual const QString& iconName() const;
|
2016-05-31 19:28:31 +01:00
|
|
|
|
2018-04-08 14:45:59 +01:00
|
|
|
/**< @param name set the new Icon for this Device */
|
|
|
|
virtual void setIconName(const QString& name);
|
|
|
|
|
|
|
|
virtual SmartStatus& smartStatus();
|
|
|
|
virtual const SmartStatus& smartStatus() const;
|
|
|
|
|
|
|
|
virtual Device::Type type() const;
|
2016-05-31 19:28:31 +01:00
|
|
|
|
|
|
|
virtual QString prettyName() const;
|
|
|
|
|
|
|
|
protected:
|
2018-04-08 14:45:59 +01:00
|
|
|
std::shared_ptr<DevicePrivate> d;
|
2015-06-04 01:29:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|