diff --git a/src/backend/corebackend.h b/src/backend/corebackend.h index 4210965..738cf1c 100644 --- a/src/backend/corebackend.h +++ b/src/backend/corebackend.h @@ -1,177 +1,179 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * Copyright (C) 2016 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 * * 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 .* *************************************************************************/ #if !defined(KPMCORE_COREBACKEND_H) #define KPMCORE_COREBACKEND_H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" #include #include class CoreBackendManager; class CoreBackendDevice; class Device; class PartitionTable; class QString; /** * Interface class for backend plugins. * @author Volker Lanz */ class LIBKPMCORE_EXPORT CoreBackend : public QObject { Q_OBJECT Q_DISABLE_COPY(CoreBackend) friend class CoreBackendManager; protected: CoreBackend(); virtual ~CoreBackend(); Q_SIGNALS: /** * Emitted to inform about progress of any kind. * @param i the progress in percent (from 0 to 100) */ void progress(int i); /** * Emitted to inform about scan progress. * @param deviceNode the device being scanned just now (e.g. "/dev/sda") * @param i the progress in percent (from 0 to 100) */ void scanProgress(const QString& deviceNode, int i); public: /** * Return the plugin's unique Id from JSON metadata * @return the plugin's unique Id from JSON metadata */ QString id() { return m_id; } /** * Return the plugin's version from JSON metadata * @return the plugin's version from JSON metadata */ QString version() { return m_version; } /** * Initialize the plugin's FileSystem support */ virtual void initFSSupport() = 0; /** * Scan for devices in the system. * @param excludeReadOnly when true, devices that are read-only * according to the kernel are left out of the list. * When false (the default) all devices, writable or * not, including CD ROM devices, are returned. * @return a QList of pointers to Device instances. The caller is responsible * for deleting these objects. + * @note A Device object is a description of the device, not + * an object to operate on. See openDevice(). */ virtual QList scanDevices(bool excludeReadOnly = false) = 0; /** * Scan a single device in the system. * @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda) * @return FileSystem type of the device on deviceNode */ virtual FileSystem::Type detectFileSystem(const QString& deviceNode) = 0; /** * Scan a single device in the system. * @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda) * @return a pointer to a Device instance. The caller is responsible for deleting * this object. */ virtual Device* scanDevice(const QString& deviceNode) = 0; /** * Open a device for reading. * @param deviceNode The path of the device that is to be opened (e.g. /dev/sda) * @return a pointer to a CoreBackendDevice or nullptr if the open failed. If a pointer to * an instance is returned, it's the caller's responsibility to delete the * object. */ virtual CoreBackendDevice* openDevice(const QString& deviceNode) = 0; /** * Open a device in exclusive mode for writing. * @param deviceNode The path of the device that is to be opened (e.g. /dev/sda) * @return a pointer to a CoreBackendDevice or nullptr if the open failed. If a pointer to * an instance is returned, it's the caller's responsibility to delete the * object. */ virtual CoreBackendDevice* openDeviceExclusive(const QString& deviceNode) = 0; /** * Close a CoreBackendDevice that has previously been opened. * @param core_device Pointer to the CoreBackendDevice to be closed. Must not be nullptr. * @return true if closing the CoreBackendDevice succeeded, otherwise false. * * This method does not delete the object. */ virtual bool closeDevice(CoreBackendDevice* core_device) = 0; /** * Emit progress. * @param i the progress in percent (from 0 to 100) * This is used to emit a progress() signal from somewhere deep inside the plugin * backend code if that is ever necessary. */ virtual void emitProgress(int i); /** * Emit scan progress. * @param deviceNode the path to the device just being scanned (e.g. /dev/sda) * @param i the progress in percent (from 0 to 100) * This is used to emit a scanProgress() signal from the backend device scanning * code. */ virtual void emitScanProgress(const QString& deviceNode, int i); protected: static void setPartitionTableForDevice(Device& d, PartitionTable* p); static void setPartitionTableMaxPrimaries(PartitionTable& p, qint32 max_primaries); private: void setId(const QString& id) { m_id = id; } void setVersion(const QString& version) { m_version = version; } private: QString m_id, m_version; class CoreBackendPrivate; CoreBackendPrivate* d; }; #endif diff --git a/src/backend/corebackenddevice.h b/src/backend/corebackenddevice.h index b35adc8..cd8c835 100644 --- a/src/backend/corebackenddevice.h +++ b/src/backend/corebackenddevice.h @@ -1,120 +1,124 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * * * 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 .* *************************************************************************/ #if !defined(KPMCORE_COREBACKENDDEVICE_H) #define KPMCORE_COREBACKENDDEVICE_H #include "util/libpartitionmanagerexport.h" #include class CoreBackendPartition; class CoreBackendPartitionTable; class Partition; class PartitionTable; class Report; /** - * Interface class representing a device in the backend plugin. + * Interface class for devices in the backend plugin. + * For a device description, see Device. This + * CoreBackendDevice can be used for (read- and) write + * operations on the raw device. + * * @author Volker Lanz */ class LIBKPMCORE_EXPORT CoreBackendDevice { public: CoreBackendDevice(const QString& device_node); virtual ~CoreBackendDevice() {} public: /** * Get the device path for this device (e.g. "/dev/sda") * @return the device path */ virtual const QString& deviceNode() const { return m_DeviceNode; } /** * Determine if this device is opened in exclusive mode. * @return true if it is opened in exclusive mode, otherwise false */ virtual bool isExclusive() const { return m_Exclusive; } /** * Open the backend device * @return true if successful */ virtual bool open() = 0; /** * Open the backend device in exclusive mode * @return true if successful */ virtual bool openExclusive() = 0; /** * Close the backend device * @return true if successful */ virtual bool close() = 0; /** * Open this backend device's partition table * @return a pointer to the CoreBackendPartitionTable for this device or nullptr in case * of errors */ virtual CoreBackendPartitionTable* openPartitionTable() = 0; /** * Create a new partition table on this device. * @param report the Report to write information to * @param ptable the PartitionTable to create on this backend device * @return true if successful */ virtual bool createPartitionTable(Report& report, const PartitionTable& ptable) = 0; /** * Read sectors from an opened device into a buffer. * @param buffer the buffer to write the read data to * @param offset offset sector where to start reading on the device * @param numSectors number of sectors to read * @return true on success */ virtual bool readSectors(void* buffer, qint64 offset, qint64 numSectors) = 0; /** * Write sectors from a buffer to an exclusively opened device. * @param buffer the buffer with the data * @param offset offset sector where to start writing to the device * @param numSectors number of sectors to write * @return true on success */ virtual bool writeSectors(void* buffer, qint64 offset, qint64 numSectors) = 0; protected: void setExclusive(bool b) { m_Exclusive = b; } private: const QString m_DeviceNode; bool m_Exclusive; }; #endif diff --git a/src/core/device.h b/src/core/device.h index 7a6968b..a32f77b 100644 --- a/src/core/device.h +++ b/src/core/device.h @@ -1,136 +1,143 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * 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 .* *************************************************************************/ #if !defined(KPMCORE_DEVICE_H) #define KPMCORE_DEVICE_H #include "util/libpartitionmanagerexport.h" #include #include class PartitionTable; class CreatePartitionTableOperation; class CoreBackend; class SmartStatus; -/** A abstract device interface. +/** A device description. - Represents a device like /dev/sda. + Represents a device like /dev/sda. Contains information about + the device (name, status, size ..) but does not operate on + the device itself. @see CoreBackendDevice Devices are the outermost entity; they contain a PartitionTable that itself contains Partitions. @see PartitionTable, Partition @author Volker Lanz */ class LIBKPMCORE_EXPORT Device : public QObject { Device &operator=(const Device &) = delete; friend class CreatePartitionTableOperation; friend class CoreBackend; public: enum Type { Disk_Device = 0, LVM_Device = 1, /* VG */ RAID_Device = 2, /* software RAID device */ Unknown_Device = 4 }; protected: explicit Device(const QString& name, const QString& deviceNode, const qint64 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Disk_Device); public: explicit Device(const Device& other); virtual ~Device(); public: virtual bool operator==(const Device& other) const; virtual bool operator!=(const Device& other) const; virtual QString& name() { return m_Name; /**< @return the Device's name, usually some manufacturer string */ } virtual const QString& name() const { return m_Name; /**< @return the Device's name, usually some manufacturer string */ } virtual const QString& deviceNode() const { return m_DeviceNode; /**< @return the Device's node, for example "/dev/sda" */ } virtual PartitionTable* partitionTable() { return m_PartitionTable; /**< @return the Device's PartitionTable */ } virtual const PartitionTable* partitionTable() const { return m_PartitionTable; /**< @return the Device's PartitionTable */ } virtual qint64 capacity() const { /**< @return the Device's capacity in bytes */ return logicalSize() * totalLogical(); } virtual void setIconName(const QString& name) { m_IconName = name; } virtual const QString& iconName() const { return m_IconName; /**< @return suggested icon name for this Device */ } virtual SmartStatus& smartStatus() { return *m_SmartStatus; } virtual const SmartStatus& smartStatus() const { return *m_SmartStatus; } + /** + * 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 . + */ virtual void setPartitionTable(PartitionTable* ptable) { m_PartitionTable = ptable; } virtual qint64 logicalSize() const { return m_LogicalSize; } virtual qint64 totalLogical() const { return m_TotalLogical; } virtual Device::Type type() const { return m_Type; } virtual QString prettyName() const; protected: QString m_Name; QString m_DeviceNode; qint64 m_LogicalSize; qint64 m_TotalLogical; PartitionTable* m_PartitionTable; QString m_IconName; SmartStatus* m_SmartStatus; Device::Type m_Type; }; #endif