2020-09-20 20:33:16 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2010 Volker Lanz <vl@fidra.de>
|
|
|
|
SPDX-FileCopyrightText: 2014-2020 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2015 Chris Campbell <c.j.campbell@ed.ac.uk>
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2020-09-20 20:33:16 +01:00
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KPMCORE_COREBACKEND_H
|
2017-09-10 20:12:52 +01:00
|
|
|
#define KPMCORE_COREBACKEND_H
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-05-06 19:14:01 +01:00
|
|
|
#include "util/libpartitionmanagerexport.h"
|
|
|
|
#include "fs/filesystem.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2018-03-31 12:56:34 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QList>
|
|
|
|
|
|
|
|
class CoreBackendManager;
|
|
|
|
class CoreBackendDevice;
|
2018-04-18 19:46:15 +01:00
|
|
|
struct CoreBackendPrivate;
|
2015-06-04 01:29:22 +01:00
|
|
|
class Device;
|
|
|
|
class PartitionTable;
|
|
|
|
|
|
|
|
class QString;
|
|
|
|
|
2019-02-09 15:40:06 +00:00
|
|
|
enum class ScanFlag : uint8_t {
|
|
|
|
includeReadOnly = 0x1, /**< devices that are read-only according to the kernel */
|
|
|
|
includeLoopback = 0x2,
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(ScanFlags, ScanFlag)
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(ScanFlags)
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
/**
|
|
|
|
* Interface class for backend plugins.
|
|
|
|
* @author Volker Lanz <vl@fidra.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
class LIBKPMCORE_EXPORT CoreBackend : public QObject
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_OBJECT
|
|
|
|
Q_DISABLE_COPY(CoreBackend)
|
|
|
|
|
|
|
|
friend class CoreBackendManager;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
CoreBackend();
|
2020-10-24 01:33:52 +01:00
|
|
|
~CoreBackend() override;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
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.
|
2016-07-21 13:16:29 +01:00
|
|
|
* @param deviceNode the device being scanned just now (e.g. "/dev/sda")
|
2015-07-13 15:16:36 +01:00
|
|
|
* @param i the progress in percent (from 0 to 100)
|
|
|
|
*/
|
2016-07-21 13:16:29 +01:00
|
|
|
void scanProgress(const QString& deviceNode, int i);
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Return the plugin's unique Id from JSON metadata
|
|
|
|
* @return the plugin's unique Id from JSON metadata
|
|
|
|
*/
|
2018-03-31 22:08:55 +01:00
|
|
|
QString id();
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the plugin's version from JSON metadata
|
|
|
|
* @return the plugin's version from JSON metadata
|
|
|
|
*/
|
2018-03-31 22:08:55 +01:00
|
|
|
QString version();
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the plugin's FileSystem support
|
|
|
|
*/
|
|
|
|
virtual void initFSSupport() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scan for devices in the system.
|
2019-02-09 15:40:06 +00:00
|
|
|
* @param excludeReadOnly when true, are left out of the list.
|
2017-10-03 09:45:44 +01:00
|
|
|
* When false (the default) all devices, writable or
|
|
|
|
* not, including CD ROM devices, are returned.
|
2015-07-13 15:16:36 +01:00
|
|
|
* @return a QList of pointers to Device instances. The caller is responsible
|
|
|
|
* for deleting these objects.
|
2017-10-03 10:23:10 +01:00
|
|
|
* @note A Device object is a description of the device, not
|
|
|
|
* an object to operate on. See openDevice().
|
2015-07-13 15:16:36 +01:00
|
|
|
*/
|
2019-02-09 15:40:06 +00:00
|
|
|
[[deprecated("port to scanDevices(ScanFlags)")]] virtual QList<Device*> scanDevices(bool excludeReadOnly = false) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scan for devices in the system.
|
|
|
|
* @param scanFlags can be used to expand the list of scanned devices.
|
|
|
|
* @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<Device*> scanDevices(const ScanFlags scanFlags) = 0;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
2016-05-06 19:14:01 +01:00
|
|
|
/**
|
|
|
|
* Scan a single device in the system.
|
2018-01-31 15:04:55 +00:00
|
|
|
* @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda1)
|
2016-05-06 19:14:01 +01:00
|
|
|
* @return FileSystem type of the device on deviceNode
|
|
|
|
*/
|
|
|
|
virtual FileSystem::Type detectFileSystem(const QString& deviceNode) = 0;
|
|
|
|
|
2018-01-31 15:04:55 +00:00
|
|
|
/**
|
|
|
|
* Read a file system label
|
|
|
|
* @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda1)
|
|
|
|
* @return FileSystem label on deviceNode
|
|
|
|
*/
|
|
|
|
virtual QString readLabel(const QString& deviceNode) const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a file system UUID
|
|
|
|
* @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda1)
|
|
|
|
* @return FileSystem UUID on deviceNode
|
|
|
|
*/
|
|
|
|
virtual QString readUUID(const QString& deviceNode) const = 0;
|
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
/**
|
|
|
|
* Scan a single device in the system.
|
2016-07-21 13:16:29 +01:00
|
|
|
* @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda)
|
2015-07-13 15:16:36 +01:00
|
|
|
* @return a pointer to a Device instance. The caller is responsible for deleting
|
|
|
|
* this object.
|
|
|
|
*/
|
2016-07-21 13:16:29 +01:00
|
|
|
virtual Device* scanDevice(const QString& deviceNode) = 0;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a device for reading.
|
2016-07-21 13:16:29 +01:00
|
|
|
* @param deviceNode The path of the device that is to be opened (e.g. /dev/sda)
|
2018-03-31 21:49:20 +01:00
|
|
|
* @return a pointer to a CoreBackendDevice or nullptr if the open failed.
|
2015-07-13 15:16:36 +01:00
|
|
|
*/
|
2018-03-31 14:44:40 +01:00
|
|
|
virtual std::unique_ptr<CoreBackendDevice> openDevice(const Device& d) = 0;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a device in exclusive mode for writing.
|
2016-07-21 13:16:29 +01:00
|
|
|
* @param deviceNode The path of the device that is to be opened (e.g. /dev/sda)
|
2018-03-31 14:44:40 +01:00
|
|
|
* @return a pointer to a CoreBackendDevice or nullptr if the open failed.
|
2015-07-13 15:16:36 +01:00
|
|
|
*/
|
2018-03-31 14:44:40 +01:00
|
|
|
virtual std::unique_ptr<CoreBackendDevice> openDeviceExclusive(const Device& d) = 0;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Close a CoreBackendDevice that has previously been opened.
|
2015-07-22 14:48:03 +01:00
|
|
|
* @param core_device Pointer to the CoreBackendDevice to be closed. Must not be nullptr.
|
2015-07-13 15:16:36 +01:00
|
|
|
* @return true if closing the CoreBackendDevice succeeded, otherwise false.
|
|
|
|
*/
|
2018-03-31 14:44:40 +01:00
|
|
|
virtual bool closeDevice(std::unique_ptr<CoreBackendDevice> coreDevice) = 0;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2016-07-21 13:16:29 +01:00
|
|
|
* @param deviceNode the path to the device just being scanned (e.g. /dev/sda)
|
2015-07-13 15:16:36 +01:00
|
|
|
* @param i the progress in percent (from 0 to 100)
|
|
|
|
* This is used to emit a scanProgress() signal from the backend device scanning
|
|
|
|
* code.
|
|
|
|
*/
|
2016-07-21 13:16:29 +01:00
|
|
|
virtual void emitScanProgress(const QString& deviceNode, int i);
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void setPartitionTableForDevice(Device& d, PartitionTable* p);
|
|
|
|
static void setPartitionTableMaxPrimaries(PartitionTable& p, qint32 max_primaries);
|
|
|
|
|
|
|
|
private:
|
2018-03-31 22:08:55 +01:00
|
|
|
void setId(const QString& id);
|
|
|
|
void setVersion(const QString& version);
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
private:
|
2018-03-31 12:56:34 +01:00
|
|
|
std::unique_ptr<CoreBackendPrivate> d;
|
2015-06-04 01:29:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|