Library for managing partitions. Common code for KDE Partition Manager and other projects. https://www.kde.org/applications/system/kdepartitionmanager/
Go to file
Gaël PORTAY 0529ebfb01 Add support for setting the specific GPT type
The GPT partition layout defines the type of the partition using a
UUID[1]. The type of the partition is not related to the underlying
filesystem but to its functionality: rootfs, home, var, swap, esp...

The UUID 4f68bce3-e8cd-4db1-96e7-fbcaf984b709 defines the root partition
(/), the UUID 933ac7e1-2eb4-4f13-b844-0e14e2aef915 defines the home
partition (/home), the UUID 4d21b016-b534-45c2-a9fb-5c16e091fd2d defines
the variable partition (/var)... Also, the UUIDs may vary depending on
the architecture (x86, x86_64, arm or aarch64).

KPMcore guesses the type depending on the underlying filesystem.

This commit enables the setting of a more specific GPT type if it is
specified through the method Partition::setType(). It falls back to the
previous guess type if the type is left unset.

[1]: https://systemd.io/DISCOVERABLE_PARTITIONS/
2020-03-20 22:15:50 -04:00
src Add support for setting the specific GPT type 2020-03-20 22:15:50 -04:00
test Fix minor issues found by EBN 2019-11-22 15:45:12 +02:00
.arcconfig Phabricator config file. 2016-03-02 13:14:58 +01:00
.krazy .krazy - skip src/fs/fat12.cpp since it makes i18ncheckarg hang 2019-04-06 15:35:11 +00:00
CMakeLists.txt Bump kpmcore soversion to 9. 2020-02-08 20:47:23 +00:00
COPYING.md Add GPLv3 in markdown format. 2019-01-07 00:23:29 +00:00
INSTALL.md Update INSTALL.md with new dependencies. 2019-02-16 11:49:51 +00:00
KPMcoreConfig.cmake.in Teach cmake config to find kpmcore include dir. 2016-01-11 23:51:28 +00:00
README.md Specify language for code snippets in README.md 2019-02-16 00:04:52 +00:00

README.md

KPMcore

KPMcore, the KDE Partition Manager core, is a library for examining and modifying partitions, disk devices, and filesystems on a Linux system. It provides a unified programming interface over top of (external) system-manipulation tools.

KPMcore is a library for examining and manipulating all facets of storage devices on a system:

  • raw disk devices
  • partition tables on a device
  • filesystems within a partition

There are multiple backends so that KPMcore can support different operating systems, although the only functional backend is the one for Linux systems:

  • sfdisk backend (Linux)
  • null backend

Using KPMcore

Most of the usage information on KPMcore is included in the API documentation; this section contains only high-level usage information.

Finding KPMcore with CMake

KPMcore supports CMake as (meta-)build system and installs suitable CMake support files. Typical use of of KPMcore in a CMakeLists.txt looks like this:

    find_package( KPMcore 3.2 REQUIRED )
    include_directories( ${KPMCORE_INCLUDE_DIR} )
    target_link_libraries( target kpmcore )

There are no imported targets defined for KPMcore.

Initialization

An application must initialize the library and load a suitable backend before using KPMcore functions. By convention, the environment variable KPMCORE_BACKEND names a backend, and typical initialization code will look like this (or use the class KPMCoreInitializer from test/helpers.h):

    #include <backend/corebackendmanager.h>
    #include <QDebug>

    bool initKPMcore()
    {
        static bool inited = false;
        if ( inited ) return true;

        QByteArray env = qgetenv( "KPMCORE_BACKEND" );
        auto backendName = env.isEmpty() ? CoreBackendManager::defaultBackendName() : env;
        if ( !CoreBackendManager::self()->load( backendName )
        {
            qWarning() << "Failed to load backend plugin" << backendName;
            return false;
        }
        inited = true;
        return true;
    }

This code uses the environment variable if set, and otherwise falls back to a default backend suitable for the current platform.

Calling KPMcore functions before the library is initialized will result in undefined behavior.

Devices

After the backend is initialized you can scan for available devices. If you only want devices from the loaded backend you can call

    QList<Device*> devices = backend->scanDevices( excludeReadOnly );

where bool option excludeReadOnly specifies whether to exclude read only devices.

KPMcore device scanner

Alternatively, you can use KPMcore device scanner

    #include <core/device.h>
    #include <core/devicescanner.h>
    #include <core/operationstack.h>

    // First create operationStack with another QObject as parent, we will use nullptr here.
    OperationStack *operationStack = new OperationStack(nullptr);
    DeviceScanner *deviceScanner = new DeviceScanner(nullptr, *operationStack);
    deviceScanner->scan(); // use start() for scanning in the background thread
    QList<Device*> devices = operationStack->previewDevices();

Then deviceScanner scans for the devices in a background thread. After scanning is complete DeviceScanner::finished() signal will be emitted. Then the devices can accessed using operationStack->previewDevices().