From cfa853a9312f131564a83642553237c00eb7f00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Mon, 2 Apr 2018 13:46:53 +0100 Subject: [PATCH] d-pointerize DiskDevice class. --- src/core/CMakeLists.txt | 1 - src/core/diskdevice.cpp | 59 ++++++++++++++++++++++++++++++----- src/core/diskdevice.h | 69 ++++++++++++++++++++++++----------------- 3 files changed, 92 insertions(+), 37 deletions(-) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 77cc332..504890a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -43,4 +43,3 @@ set(CORE_LIB_HDRS core/smartstatus.h core/volumemanagerdevice.h ) - diff --git a/src/core/diskdevice.cpp b/src/core/diskdevice.cpp index 6e6fac4..8922ea1 100644 --- a/src/core/diskdevice.cpp +++ b/src/core/diskdevice.cpp @@ -1,6 +1,6 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * - * Copyright (C) 2016 by Andrius Štikonas * + * Copyright (C) 2016-2018 by Andrius Štikonas * * * * 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(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()) { + 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(heads()) * cylinders() * sectorsPerTrack(); +} + +qint64 DiskDevice::cylinderSize() const +{ + return static_cast(heads()) * sectorsPerTrack(); } diff --git a/src/core/diskdevice.h b/src/core/diskdevice.h index 9c4a359..f535179 100644 --- a/src/core/diskdevice.h +++ b/src/core/diskdevice.h @@ -1,5 +1,6 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * + * Copyright (C) 2018 by Andrius Štikonas * * * * 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 .* *************************************************************************/ -#if !defined(KPMCORE_DISKDEVICE_H) - +#ifndef KPMCORE_DISKDEVICE_H #define KPMCORE_DISKDEVICE_H #include "util/libpartitionmanagerexport.h" #include "core/device.h" +#include + #include #include #include @@ -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 */ + 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(heads()) * cylinders() * sectorsPerTrack(); /**< @return the total number of sectors on the device */ - } - qint64 cylinderSize() const { - return static_cast(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 d; }; #endif