d-pointerize DiskDevice class.
This commit is contained in:
parent
0b6d91bbdb
commit
cfa853a931
|
@ -43,4 +43,3 @@ set(CORE_LIB_HDRS
|
|||
core/smartstatus.h
|
||||
core/volumemanagerdevice.h
|
||||
)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* Copyright (C) 2016-2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -39,14 +39,21 @@
|
|||
#define BLKPBSZGET _IO(0x12,123)/* get block physical sector size */
|
||||
#endif
|
||||
|
||||
struct DiskDevicePrivate {
|
||||
qint32 m_Heads;
|
||||
qint32 m_SectorsPerTrack;
|
||||
qint32 m_Cylinders;
|
||||
qint64 m_LogicalSectorSize;
|
||||
qint64 m_PhysicalSectorSize;
|
||||
};
|
||||
|
||||
static qint64 getPhysicalSectorSize(const QString& device_node)
|
||||
{
|
||||
/*
|
||||
* possible ways of getting the physical sector size for a drive:
|
||||
* - ioctl(BLKPBSZGET) -- supported with Linux 2.6.32 and later
|
||||
* - /sys/block/sda/queue/physical_block_size
|
||||
* - libblkid from util-linux-ng 2.17 or later
|
||||
* TODO: implement the blkid method
|
||||
* - libblkid from util-linux 2.17 or later (not implemented)
|
||||
*/
|
||||
|
||||
#if defined(BLKPBSZGET)
|
||||
|
@ -88,10 +95,46 @@ DiskDevice::DiskDevice(const QString& name,
|
|||
qint64 sectorSize,
|
||||
const QString& iconName)
|
||||
: Device(name, deviceNode, sectorSize, (static_cast<qint64>(heads) * cylinders * numSectors), iconName, Device::Disk_Device)
|
||||
, m_Heads(heads)
|
||||
, m_SectorsPerTrack(numSectors)
|
||||
, m_Cylinders(cylinders)
|
||||
, m_LogicalSectorSize(sectorSize)
|
||||
, m_PhysicalSectorSize(getPhysicalSectorSize(deviceNode))
|
||||
, d(std::make_unique<DiskDevicePrivate>())
|
||||
{
|
||||
d->m_Heads = heads;
|
||||
d->m_SectorsPerTrack = numSectors;
|
||||
d->m_Cylinders = cylinders;
|
||||
d->m_LogicalSectorSize = sectorSize;
|
||||
d->m_PhysicalSectorSize = getPhysicalSectorSize(deviceNode);
|
||||
}
|
||||
|
||||
qint32 DiskDevice::heads() const
|
||||
{
|
||||
return d->m_Heads;
|
||||
}
|
||||
|
||||
qint32 DiskDevice::cylinders() const
|
||||
{
|
||||
return d->m_Cylinders;
|
||||
}
|
||||
|
||||
qint32 DiskDevice::sectorsPerTrack() const
|
||||
{
|
||||
return d->m_SectorsPerTrack;
|
||||
}
|
||||
|
||||
qint64 DiskDevice::physicalSectorSize() const
|
||||
{
|
||||
return d->m_PhysicalSectorSize;
|
||||
}
|
||||
|
||||
qint64 DiskDevice::logicalSectorSize() const
|
||||
{
|
||||
return d->m_LogicalSectorSize;
|
||||
}
|
||||
|
||||
qint64 DiskDevice::totalSectors() const
|
||||
{
|
||||
return static_cast<qint64>(heads()) * cylinders() * sectorsPerTrack();
|
||||
}
|
||||
|
||||
qint64 DiskDevice::cylinderSize() const
|
||||
{
|
||||
return static_cast<qint64>(heads()) * sectorsPerTrack();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -15,13 +16,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#if !defined(KPMCORE_DISKDEVICE_H)
|
||||
|
||||
#ifndef KPMCORE_DISKDEVICE_H
|
||||
#define KPMCORE_DISKDEVICE_H
|
||||
|
||||
#include "util/libpartitionmanagerexport.h"
|
||||
#include "core/device.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
#include <QtGlobal>
|
||||
|
@ -30,6 +32,7 @@ class PartitionTable;
|
|||
class CreatePartitionTableOperation;
|
||||
class CoreBackend;
|
||||
class SmartStatus;
|
||||
struct DiskDevicePrivate;
|
||||
|
||||
/** A disk device.
|
||||
|
||||
|
@ -40,6 +43,7 @@ class SmartStatus;
|
|||
@see PartitionTable, Partition
|
||||
@author Volker Lanz <vl@fidra.de>
|
||||
*/
|
||||
|
||||
class LIBKPMCORE_EXPORT DiskDevice : public Device
|
||||
{
|
||||
Q_DISABLE_COPY(DiskDevice)
|
||||
|
@ -51,34 +55,43 @@ public:
|
|||
DiskDevice(const QString& name, const QString& deviceNode, qint32 heads, qint32 numSectors, qint32 cylinders, qint64 sectorSize, const QString& iconName = QString());
|
||||
|
||||
public:
|
||||
qint32 heads() const {
|
||||
return m_Heads; /**< @return the number of heads on the Device in CHS notation */
|
||||
}
|
||||
qint32 cylinders() const {
|
||||
return m_Cylinders; /**< @return the number of cylinders on the Device in CHS notation */
|
||||
}
|
||||
qint32 sectorsPerTrack() const {
|
||||
return m_SectorsPerTrack; /**< @return the number of sectors on the Device in CHS notation */
|
||||
}
|
||||
qint64 physicalSectorSize() const {
|
||||
return m_PhysicalSectorSize; /**< @return the physical sector size the Device uses or -1 if unknown */
|
||||
}
|
||||
qint64 logicalSectorSize() const {
|
||||
return m_LogicalSectorSize; /**< @return the logical sector size the Device uses */
|
||||
}
|
||||
qint64 totalSectors() const {
|
||||
return static_cast<qint64>(heads()) * cylinders() * sectorsPerTrack(); /**< @return the total number of sectors on the device */
|
||||
}
|
||||
qint64 cylinderSize() const {
|
||||
return static_cast<qint64>(heads()) * sectorsPerTrack(); /**< @return the size of a cylinder on this Device in sectors */
|
||||
}
|
||||
/**
|
||||
* @return the number of heads on the Device in CHS notation
|
||||
*/
|
||||
qint32 heads() const;
|
||||
|
||||
/**
|
||||
* @return the number of cylinders on the Device in CHS notation
|
||||
*/
|
||||
qint32 cylinders() const;
|
||||
|
||||
/**
|
||||
* @return the number of sectors on the Device in CHS notation
|
||||
*/
|
||||
qint32 sectorsPerTrack() const;
|
||||
|
||||
/**
|
||||
* @return the physical sector size the Device uses or -1 if unknown
|
||||
*/
|
||||
qint64 physicalSectorSize() const;
|
||||
|
||||
/**
|
||||
* @return the logical sector size the Device uses
|
||||
*/
|
||||
qint64 logicalSectorSize() const;
|
||||
|
||||
/**
|
||||
* @return the total number of sectors on the device
|
||||
*/
|
||||
qint64 totalSectors() const;
|
||||
|
||||
/**
|
||||
* @return the size of a cylinder on this Device in sectors
|
||||
*/
|
||||
qint64 cylinderSize() const;
|
||||
|
||||
private:
|
||||
qint32 m_Heads;
|
||||
qint32 m_SectorsPerTrack;
|
||||
qint32 m_Cylinders;
|
||||
qint64 m_LogicalSectorSize;
|
||||
qint64 m_PhysicalSectorSize;
|
||||
std::unique_ptr<DiskDevicePrivate> d;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue