2020-09-20 20:33:16 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2010-2011 Volker Lanz <vl@fidra.de>
|
|
|
|
SPDX-FileCopyrightText: 2014-2018 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2015 Chris Campbell <c.j.campbell@ed.ac.uk>
|
|
|
|
SPDX-FileCopyrightText: 2020 Gaël PORTAY <gael.portay@collabora.com>
|
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_COREBACKENDPARTITIONTABLE_H
|
2017-09-10 20:12:52 +01:00
|
|
|
#define KPMCORE_COREBACKENDPARTITIONTABLE_H
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2017-11-07 22:55:28 +00:00
|
|
|
#include "core/partitiontable.h"
|
2016-05-06 22:36:24 +01:00
|
|
|
#include "fs/filesystem.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-04-18 17:14:31 +01:00
|
|
|
#include <QtGlobal>
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
class CoreBackendPartition;
|
|
|
|
class Report;
|
|
|
|
class Partition;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface class to represent a partition table in the backend.
|
|
|
|
* @author Volker Lanz <vl@fidra.de>
|
|
|
|
*/
|
2018-01-21 13:53:07 +00:00
|
|
|
class CoreBackendPartitionTable
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
public:
|
|
|
|
virtual ~CoreBackendPartitionTable() {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Open the partition table
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
virtual bool open() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Commit changes to the partition table to disk and to the OS.
|
|
|
|
* @param timeout timeout in seconds to wait for the commit to succeed
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
virtual bool commit(quint32 timeout = 10) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a partition.
|
|
|
|
* @param report the report to write information to
|
|
|
|
* @param partition the Partition to delete
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
virtual bool deletePartition(Report& report, const Partition& partition) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a file system on disk so it cannot be detected anymore.
|
|
|
|
* @param report the report to write information to
|
|
|
|
* @param partition the Partition for which to clobber the file system
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
virtual bool clobberFileSystem(Report& report, const Partition& partition) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize a file system to a new length.
|
|
|
|
* @param report the report to write information to
|
|
|
|
* @param partition the partition the FileSystem to resize is on
|
|
|
|
* @param newLength the new length for the FileSystem in sectors
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detect which FileSystem is present at a given start sector.
|
|
|
|
* @param report the report to write information to
|
|
|
|
* @param device the Device on which the FileSystem resides
|
|
|
|
* @param sector the sector where to look for a FileSystem
|
|
|
|
* @return the detected FileSystem::Type
|
|
|
|
*/
|
|
|
|
virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new partition.
|
|
|
|
* @param report the report to write information to
|
|
|
|
* @param partition the new partition to create on disk
|
|
|
|
* @return the new number the OS sees the partition under (e.g. 7 for "/dev/sda7") or -1 on failure
|
|
|
|
*/
|
|
|
|
virtual QString createPartition(Report& report, const Partition& partition) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the geometry for a partition in the partition table.
|
|
|
|
* @param report the report to write information to
|
|
|
|
* @param partition the partition to update the geometry for
|
|
|
|
* @param sector_start the new start sector for the partition
|
|
|
|
* @param sector_end the new last sector for the partition
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) = 0;
|
|
|
|
|
2020-05-15 16:22:57 +01:00
|
|
|
/**
|
|
|
|
* Get the UUID of a partition in the partition table (GPT only).
|
|
|
|
* The partition UUID is known as PARTUUID by several utilities. The device-manager links
|
|
|
|
* the device under /dev/disk/by-partuuid/<uuid>.
|
|
|
|
* @param report the report to write information to
|
|
|
|
* @param partition the partition to get the UUID for
|
|
|
|
* @return the partition UUID
|
|
|
|
*/
|
|
|
|
virtual QString getPartitionUUID(Report& report, const Partition& partition) = 0;
|
|
|
|
|
2020-03-18 18:24:27 +00:00
|
|
|
/**
|
|
|
|
* Set the label of a partition in the partition table (GPT only).
|
|
|
|
* The label is set in the GPT partition name entry. The partition name is known as PARTLABEL by
|
|
|
|
* several utilities. The device-manager links the device under /dev/disk/by-partlabel/<label>.
|
|
|
|
* @param report the report to write information to
|
|
|
|
* @param partition the partition to set the label for
|
|
|
|
* @param label the new label for the partition
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
virtual bool setPartitionLabel(Report& report, const Partition& partition, const QString& label) = 0;
|
|
|
|
|
Add new job to set the GPT partition UUID
The GPT partition layout supports unique GUID partitions.
The CLI sfdisk sets the partition UUID using the option --part-uuid.
See the examples below:
$ cat <<EOF | sfdisk disk.img
label: gpt
type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, size=64M
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
EOF
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=BBE806BB-8567-A843-9FF5-9B6B35D2908E
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7DB39F08-C138-664B-B38E-ED2DEB549AA6
$ sfdisk --part-uuid disk.img 1 00000000^C000-0000-0000-000000000000
(...)
$ sfdisk --part-uuid disk.img 2 11111111-1111-1111-1111-111111111111
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=00000000-0000-0000-0000-000000000000
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=11111111-1111-1111-1111-111111111111
This commit introduces the new job set-partition-uuid that is used in
the new-operation to set the UUID of the partition. The job uses the
newly introduced method setPartitionUUID that is implemented by the
sfdisk and dummy backends.
Note: This is a copypaste of what was done for GTP partition label in
commit f585f6c (Add new job to set the GPT partition label).
2020-03-18 18:24:27 +00:00
|
|
|
/**
|
|
|
|
* Set the UUID of a partition in the partition table (GPT only).
|
|
|
|
* The partition UUID is known as PARTUUID by several utilities. The device-manager links
|
|
|
|
* the device under /dev/disk/by-partuuid/<uuid>.
|
|
|
|
* @param report the report to write information to
|
|
|
|
* @param partition the partition to set the UUID for
|
|
|
|
* @param uuid the new UUID for the partition
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
virtual bool setPartitionUUID(Report& report, const Partition& partition, const QString& uuid) = 0;
|
|
|
|
|
Add new job to set the GPT partition attributes
The GPT partition layout supports partition attributes.
The CLI sfdisk sets the partition attributes using the option
--part-attrs. See the examples below:
$ cat <<EOF | sfdisk disk.img
label: gpt
type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, size=64M
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
EOF
(...)
$ sfdisk --part-attrs disk.img 1 RequiredPartition,NoBlockIOProtocol,LegacyBIOSBootable,48
(...)
$ sfdisk --part-attrs disk.img 2 60,61,62,63
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=BBE806BB-8567-A843-9FF5-9B6B35D2908E, attrs="RequiredPartition NoBlockIOProtocol LegacyBIOSBootable GUID:48"
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7DB39F08-C138-664B-B38E-ED2DEB549AA6, attrs="GUID:60,61,62,63"
This commit introduces the new job set-partition-attributes that is used
in the new-operation to set the attributes of the partition. The job
uses the newly introduced method setPartitionAttributes that is
implemented by the sfdisk and dummy backends.
Note: This is a copypaste of what was done for GPT partition label in
commit f585f6c (Add new job to set the GPT partition label) and GPT
partition UUID in commit 1dde035 (Add new job to set the GPT partition
UUID).
Note: RequiredPartition, NoBlockIOProtocol, LegacyBIOSBootable are
key words for 0, 1 and 2.
2020-05-15 17:24:06 +01:00
|
|
|
/**
|
|
|
|
* Set the attributes of a partition in the partition table (GPT only).
|
|
|
|
* @param report the report to write information to
|
|
|
|
* @param partition the partition to set the attributes for
|
|
|
|
* @param attrs the new attributes for the partition
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
virtual bool setPartitionAttributes(Report& report, const Partition& partition, quint64 attrs) = 0;
|
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
/**
|
|
|
|
* Set the system type (e.g. 83 for Linux) of a partition. The type to set is taken from
|
|
|
|
* the partition's file system.
|
|
|
|
* @param report the report to write information to
|
|
|
|
* @param partition the partition to set the system type for
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
virtual bool setPartitionSystemType(Report& report, const Partition& partition) = 0;
|
2017-11-07 22:55:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a flag for the partition
|
|
|
|
* @param report the Report to write information to
|
|
|
|
* @param flag the flag to set
|
|
|
|
* @param state the state to set the flag to (i.e., on or off)
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
virtual bool setFlag(Report& report, const Partition& partition, PartitionTable::Flag flag, bool state) = 0;
|
2015-06-04 01:29:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|