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

0001 /*
0002     SPDX-FileCopyrightText: 2010-2011 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: 2020 Gaël PORTAY <gael.portay@collabora.com>
0007 
0008     SPDX-License-Identifier: GPL-3.0-or-later
0009 */
0010 
0011 #ifndef KPMCORE_COREBACKENDPARTITIONTABLE_H
0012 #define KPMCORE_COREBACKENDPARTITIONTABLE_H
0013 
0014 #include "core/partitiontable.h"
0015 #include "fs/filesystem.h"
0016 
0017 #include <QtGlobal>
0018 
0019 class CoreBackendPartition;
0020 class Report;
0021 class Partition;
0022 
0023 /**
0024   * Interface class to represent a partition table in the backend.
0025   * @author Volker Lanz <vl@fidra.de>
0026   */
0027 class CoreBackendPartitionTable
0028 {
0029 public:
0030     virtual ~CoreBackendPartitionTable() {}
0031 
0032 public:
0033     /**
0034       * Open the partition table
0035       * @return true on success
0036       */
0037     virtual bool open() = 0;
0038 
0039     /**
0040       * Commit changes to the partition table to disk and to the OS.
0041       * @param timeout timeout in seconds to wait for the commit to succeed
0042       * @return true on success
0043     */
0044     virtual bool commit(quint32 timeout = 10) = 0;
0045 
0046     /**
0047       * Delete a partition.
0048       * @param report the report to write information to
0049       * @param partition the Partition to delete
0050       * @return true on success
0051       */
0052     virtual bool deletePartition(Report& report, const Partition& partition) = 0;
0053 
0054     /**
0055       * Delete a file system on disk so it cannot be detected anymore.
0056       * @param report the report to write information to
0057       * @param partition the Partition for which to clobber the file system
0058       * @return true on success
0059       */
0060     virtual bool clobberFileSystem(Report& report, const Partition& partition) = 0;
0061 
0062     /**
0063       * Resize a file system to a new length.
0064       * @param report the report to write information to
0065       * @param partition the partition the FileSystem to resize is on
0066       * @param newLength the new length for the FileSystem in sectors
0067       * @return true on success
0068       */
0069     virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) = 0;
0070 
0071     /**
0072       * Detect which FileSystem is present at a given start sector.
0073       * @param report the report to write information to
0074       * @param device the Device on which the FileSystem resides
0075       * @param sector the sector where to look for a FileSystem
0076       * @return the detected FileSystem::Type
0077       */
0078     virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) = 0;
0079 
0080     /**
0081       * Create a new partition.
0082       * @param report the report to write information to
0083       * @param partition the new partition to create on disk
0084       * @return the new number the OS sees the partition under (e.g. 7 for "/dev/sda7") or -1 on failure
0085       */
0086     virtual QString createPartition(Report& report, const Partition& partition) = 0;
0087 
0088     /**
0089       * Update the geometry for a partition in the partition table.
0090       * @param report the report to write information to
0091       * @param partition the partition to update the geometry for
0092       * @param sector_start the new start sector for the partition
0093       * @param sector_end the new last sector for the partition
0094       * @return true on success
0095       */
0096     virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) = 0;
0097 
0098     /**
0099      * Get the UUID of a partition in the partition table (GPT only).
0100      * The partition UUID is known as PARTUUID by several utilities. The device-manager links
0101      * the device under /dev/disk/by-partuuid/<uuid>.
0102      * @param report the report to write information to
0103      * @param partition the partition to get the UUID for
0104      * @return the partition UUID
0105      */
0106     virtual QString getPartitionUUID(Report& report, const Partition& partition) = 0;
0107 
0108     /**
0109      * Set the label of a partition in the partition table (GPT only).
0110      * The label is set in the GPT partition name entry. The partition name is known as PARTLABEL by
0111      * several utilities. The device-manager links the device under /dev/disk/by-partlabel/<label>.
0112      * @param report the report to write information to
0113      * @param partition the partition to set the label for
0114      * @param label the new label for the partition
0115      * @return true on success
0116      */
0117     virtual bool setPartitionLabel(Report& report, const Partition& partition, const QString& label) = 0;
0118 
0119     /**
0120      * Set the UUID of a partition in the partition table (GPT only).
0121      * The partition UUID is known as PARTUUID by several utilities. The device-manager links
0122      * the device under /dev/disk/by-partuuid/<uuid>.
0123      * @param report the report to write information to
0124      * @param partition the partition to set the UUID for
0125      * @param uuid the new UUID for the partition
0126      * @return true on success
0127      */
0128     virtual bool setPartitionUUID(Report& report, const Partition& partition, const QString& uuid) = 0;
0129 
0130     /**
0131      * Set the attributes of a partition in the partition table (GPT only).
0132      * @param report the report to write information to
0133      * @param partition the partition to set the attributes for
0134      * @param attrs the new attributes for the partition
0135      * @return true on success
0136      */
0137     virtual bool setPartitionAttributes(Report& report, const Partition& partition, quint64 attrs) = 0;
0138 
0139     /**
0140      * Set the system type (e.g. 83 for Linux) of a partition. The type to set is taken from
0141      * the partition's file system.
0142      * @param report the report to write information to
0143      * @param partition the partition to set the system type for
0144      * @return true on success
0145      */
0146     virtual bool setPartitionSystemType(Report& report, const Partition& partition) = 0;
0147 
0148     /**
0149       * Set a flag for the partition
0150       * @param report the Report to write information to
0151       * @param flag the flag to set
0152       * @param state the state to set the flag to (i.e., on or off)
0153       * @return true on success
0154       */
0155     virtual bool setFlag(Report& report, const Partition& partition, PartitionTable::Flag flag, bool state) = 0;
0156 };
0157 
0158 #endif