Warning, /system/kpmcore/README.md is written in an unsupported language. File is not indexed.
0001 <!-- SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org> 0002 SPDX-FileCopyrightText: 2017-2020 Andrius Štikonas <andrius@stikonas.eu> 0003 SPDX-License-Identifier: CC-BY-4.0 0004 --> 0005 0006 # KPMcore 0007 0008 > KPMcore, the KDE Partition Manager core, is a library for examining 0009 > and modifying partitions, disk devices, and filesystems on a 0010 > Linux system. It provides a unified programming interface over 0011 > top of (external) system-manipulation tools. 0012 0013 KPMcore is a library for examining and manipulating all facets 0014 of storage devices on a system: 0015 * raw disk devices 0016 * partition tables on a device 0017 * filesystems within a partition 0018 0019 There are multiple backends so that KPMcore can support different 0020 operating systems, although the only functional backend is the 0021 one for Linux systems: 0022 * sfdisk backend (Linux) 0023 * null backend 0024 0025 ## Using KPMcore 0026 0027 Most of the usage information on KPMcore is included in the API 0028 documentation; this section contains only high-level usage information. 0029 0030 ### Finding KPMcore with CMake 0031 0032 KPMcore supports CMake as (meta-)build system and installs suitable 0033 CMake support files. Typical use of of KPMcore in a `CMakeLists.txt` 0034 looks like this: 0035 0036 ```cmake 0037 find_package( KPMcore 3.2 REQUIRED ) 0038 target_link_libraries( target kpmcore ) 0039 ``` 0040 0041 There are no imported targets defined for KPMcore. 0042 0043 ### Initialization 0044 0045 An application must initialize the library and load a suitable 0046 backend before using KPMcore functions. By convention, the 0047 environment variable `KPMCORE_BACKEND` names a backend, 0048 and typical initialization code will look like this (or use the 0049 class `KPMCoreInitializer` from `test/helpers.h`): 0050 0051 ```cpp 0052 #include <backend/corebackendmanager.h> 0053 #include <QDebug> 0054 0055 bool initKPMcore() 0056 { 0057 static bool inited = false; 0058 if ( inited ) return true; 0059 0060 QByteArray env = qgetenv( "KPMCORE_BACKEND" ); 0061 auto backendName = env.isEmpty() ? CoreBackendManager::defaultBackendName() : env; 0062 if ( !CoreBackendManager::self()->load( backendName ) ) 0063 { 0064 qWarning() << "Failed to load backend plugin" << backendName; 0065 return false; 0066 } 0067 inited = true; 0068 return true; 0069 } 0070 ``` 0071 0072 This code uses the environment variable if set, and otherwise falls 0073 back to a default backend suitable for the current platform. 0074 0075 Calling KPMcore functions before the library is initialized will 0076 result in undefined behavior. 0077 0078 ### Devices 0079 0080 After the backend is initialized you can scan for available devices. 0081 If you only want devices from the loaded backend you can call 0082 0083 ```cpp 0084 QList<Device*> devices = backend->scanDevices( excludeReadOnly ); 0085 ``` 0086 0087 where `bool` option `excludeReadOnly` specifies whether to exclude 0088 read only devices. 0089 0090 #### KPMcore device scanner 0091 0092 Alternatively, you can use KPMcore device scanner 0093 0094 ```cpp 0095 #include <core/device.h> 0096 #include <core/devicescanner.h> 0097 #include <core/operationstack.h> 0098 0099 // First create operationStack with another QObject as parent, we will use nullptr here. 0100 OperationStack *operationStack = new OperationStack(nullptr); 0101 DeviceScanner *deviceScanner = new DeviceScanner(nullptr, *operationStack); 0102 deviceScanner->scan(); // use start() for scanning in the background thread 0103 QList<Device*> devices = operationStack->previewDevices(); 0104 ``` 0105 0106 Then `deviceScanner` scans for the devices in a background thread. After 0107 scanning is complete `DeviceScanner::finished()` signal will be emitted. 0108 Then the devices can accessed using `operationStack->previewDevices()`.