File indexing completed on 2024-04-28 05:45:47

0001 /*
0002     SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
0003     SPDX-FileCopyrightText: 2016-2018 Andrius Štikonas <andrius@stikonas.eu>
0004     SPDX-FileCopyrightText: 2019 Caio Jordão Carvalho <caiojcarvalho@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-3.0-or-later
0007 */
0008 
0009 #ifndef KPMCORE_VOLUMEMANAGERDEVICE_H
0010 #define KPMCORE_VOLUMEMANAGERDEVICE_H
0011 
0012 #include "util/libpartitionmanagerexport.h"
0013 #include "core/device.h"
0014 
0015 #include <QString>
0016 #include <QStringList>
0017 #include <QObject>
0018 #include <QtGlobal>
0019 
0020 class VolumeManagerDevicePrivate;
0021 
0022 /** A Volume Manager of physical devices represented as an abstract device.
0023  *
0024  *   VolumeManagerDevice is an abstract device class for volume manager. e.g: LVM, SoftRAID.
0025  *   example of physical device: /dev/sda, /dev/sdb1.
0026  *
0027  *   Devices are the outermost entity; they contain a PartitionTable that itself contains Partitions.
0028  *
0029  *   @see Device, PartitionTable, Partition
0030  */
0031 class LIBKPMCORE_EXPORT VolumeManagerDevice : public Device
0032 {
0033     Q_DISABLE_COPY(VolumeManagerDevice)
0034 
0035 public:
0036     VolumeManagerDevice(std::shared_ptr<VolumeManagerDevicePrivate> d, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Type::Unknown_Device);
0037 
0038     /**
0039      *  @return list of physical device's path that makes up volumeManagerDevice.(e.g: /dev/sda, /dev/sdb1)
0040      */
0041     virtual const QStringList deviceNodes() const = 0;
0042 
0043     /**
0044      * @return list of logical partition's path.
0045      */
0046     virtual const QStringList& partitionNodes() const = 0;
0047 
0048     /**
0049      * @return size of logical partition at the given path in bytes.
0050      */
0051     virtual qint64 partitionSize(QString& partitionPath) const = 0;
0052 
0053 protected:
0054 
0055     /** Initialize device's partition table and partitions.
0056      *
0057      */
0058     virtual void initPartitions() = 0;
0059 
0060     /** absolute sector as represented inside the device's partitionTable
0061      *
0062      *  For VolumeMangerDevice to works with the rest of the codebase, partitions are stringed
0063      *  one after another to create a representation of PartitionTable and partition just like
0064      *  real disk device.
0065      *
0066      *  @param partitionPath logical partition path
0067      *  @sector sector value to be mapped (if 0, will return start sector of the partition)
0068      *  @return absolute sector value as represented inside device's partitionTable
0069      */
0070     virtual qint64 mappedSector(const QString& partitionPath, qint64 sector) const = 0;
0071 
0072 public:
0073 
0074     static void scanDevices(QList<Device*>& devices);
0075 
0076     /** join deviceNodes together into comma-separated list
0077      *
0078      *  @return comma-separated list of deviceNodes
0079      */
0080     virtual QString prettyDeviceNodeList() const;
0081 
0082     /** Resize device total number of logical sectors.
0083      *
0084      * @param n Number of sectors.
0085      */
0086     void setTotalLogical(qint64 n);
0087 };
0088 
0089 #endif