Library for managing partitions. Common code for KDE Partition Manager and other projects. https://www.kde.org/applications/system/kdepartitionmanager/
Go to file
Yaroslav Sidlovsky 8746ef72fd Fix smartctl exit status success check
According to the smartctl man page:
```
EXIT STATUS
The  exit  statuses of smartctl are defined by a bitmask.  If all is well with the disk, the exit status (return value) of smartctl is 0 (all bits turned off).  If a problem occurs, or an error, potential error, or fault is detected, then a non-zero status is
returned.  In this case, the eight different bits in the exit status have the following meanings for ATA disks; some of these values may also be returned for SCSI disks.

Bit 0: Command line did not parse.

Bit 1: Device open failed, device did not return an IDENTIFY DEVICE structure, or device is in a low-power mode (see '-n' option above).

Bit 2: Some SMART or other ATA command to the disk failed, or there was a checksum error in a SMART data structure (see '-b' option above).

Bit 3: SMART status check returned "DISK FAILING".

Bit 4: We found prefail Attributes <= threshold.

Bit 5: SMART status check returned "DISK OK" but we found that some (usage or prefail) Attributes have been <= threshold at some time in the past.

Bit 6: The device error log contains records of errors.

Bit 7: The device self-test log contains records of errors.  [ATA only] Failed self-tests outdated by a newer successful extended self-test are ignored.
```

BUG: 429028
2021-03-17 16:03:32 +03:00
.reuse reuse: Add SPDX info to src/util/org.kde.kpmcore.externalcommand.policy. 2020-10-27 12:20:34 +00:00
LICENSES REUSE: licensing information for misc files. 2020-10-01 00:51:30 +01:00
src Fix smartctl exit status success check 2021-03-17 16:03:32 +03:00
test testhelpers: link kpmcore to get the include directories from the interface 2020-11-16 20:56:57 +00:00
.gitignore SPDX: Use CC0 for .gitignore. 2020-10-05 22:00:33 +01:00
.krazy REUSE: licensing information for misc files. 2020-10-01 00:51:30 +01:00
CMakeLists.txt GIT_SILENT Upgrade release service version to 21.07.70. 2021-03-13 22:28:27 +01:00
INSTALL.md REUSE: licensing information for misc files. 2020-10-01 00:51:30 +01:00
KPMcoreConfig.cmake.in CMake config file: check for Qt5Core in the needed version 2020-11-16 20:21:16 +01:00
README.md REUSE: licensing information for misc files. 2020-10-01 00:51:30 +01: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().