File indexing completed on 2024-05-05 05:48:38

0001 /*
0002     SPDX-FileCopyrightText: 2010 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2014-2018 Andrius Štikonas <andrius@stikonas.eu>
0004     SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
0005     SPDX-FileCopyrightText: 2015 Chris Campbell <c.j.campbell@ed.ac.uk>
0006     SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
0007     SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net
0008 
0009     SPDX-License-Identifier: GPL-3.0-or-later
0010 */
0011 
0012 #ifndef KPMCORE_COREBACKENDDEVICE_H
0013 #define KPMCORE_COREBACKENDDEVICE_H
0014 
0015 #include <memory>
0016 #include <QString>
0017 
0018 class CoreBackendPartition;
0019 class CoreBackendPartitionTable;
0020 class Partition;
0021 class PartitionTable;
0022 class Report;
0023 
0024 /**
0025   * Interface class for devices in the backend plugin.
0026   * For a device description, see Device. This
0027   * CoreBackendDevice can be used for (read- and) write
0028   * operations on the raw device.
0029   *
0030   * @author Volker Lanz <vl@fidra.de>
0031   */
0032 class CoreBackendDevice
0033 {
0034 public:
0035     explicit CoreBackendDevice(const QString& deviceNode);
0036     virtual ~CoreBackendDevice() {}
0037 
0038 public:
0039     /**
0040       * Get the device path for this device (e.g. "/dev/sda")
0041       * @return the device path
0042       */
0043     virtual const QString& deviceNode() const {
0044         return m_DeviceNode;
0045     }
0046 
0047     /**
0048       * Determine if this device is opened in exclusive mode.
0049       * @return true if it is opened in exclusive mode, otherwise false
0050       */
0051     virtual bool isExclusive() const {
0052         return m_Exclusive;
0053     }
0054 
0055     /**
0056       * Open the backend device
0057       * @return true if successful
0058       */
0059     virtual bool open() = 0;
0060 
0061     /**
0062       * Open the backend device in exclusive mode
0063       * @return true if successful
0064       */
0065     virtual bool openExclusive() = 0;
0066 
0067     /**
0068       * Close the backend device
0069       * @return true if successful
0070       */
0071     virtual bool close() = 0;
0072 
0073     /**
0074       * Open this backend device's partition table
0075       * @return a pointer to the CoreBackendPartitionTable for this device or nullptr in case
0076       *         of errors
0077       */
0078     virtual std::unique_ptr<CoreBackendPartitionTable> openPartitionTable() = 0;
0079 
0080     /**
0081       * Create a new partition table on this device.
0082       * @param report the Report to write information to
0083       * @param ptable the PartitionTable to create on this backend device
0084       * @return true if successful
0085       */
0086     virtual bool createPartitionTable(Report& report, const PartitionTable& ptable) = 0;
0087 
0088 protected:
0089     void setExclusive(bool b) {
0090         m_Exclusive = b;
0091     }
0092 
0093 private:
0094     const QString m_DeviceNode;
0095     bool m_Exclusive;
0096 };
0097 
0098 #endif