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