File indexing completed on 2024-05-12 04:01:52

0001 /*
0002     SPDX-FileCopyrightText: 2006-2007 Kevin Ottens <ervin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef SOLID_STORAGEVOLUME_H
0008 #define SOLID_STORAGEVOLUME_H
0009 
0010 #include <solid/solid_export.h>
0011 
0012 #include <solid/deviceinterface.h>
0013 
0014 namespace Solid
0015 {
0016 class StorageVolumePrivate;
0017 class Device;
0018 
0019 /**
0020  * @class Solid::StorageVolume storagevolume.h <Solid/StorageVolume>
0021  *
0022  * This device interface is available on volume devices.
0023  *
0024  * A volume is anything that can contain data (partition, optical disc,
0025  * memory card). It's a particular kind of block device.
0026  */
0027 class SOLID_EXPORT StorageVolume : public DeviceInterface
0028 {
0029     Q_OBJECT
0030     Q_PROPERTY(bool ignored READ isIgnored)
0031     Q_PROPERTY(UsageType usage READ usage)
0032     Q_PROPERTY(QString fsType READ fsType)
0033     Q_PROPERTY(QString label READ label)
0034     Q_PROPERTY(QString uuid READ uuid)
0035     Q_PROPERTY(qulonglong size READ size)
0036     Q_DECLARE_PRIVATE(StorageVolume)
0037     friend class Device;
0038 
0039 public:
0040     /**
0041      * This enum type defines the how a volume is used.
0042      *
0043      * - FileSystem : A mountable filesystem volume
0044      * - PartitionTable : A volume containing a partition table
0045      * - Raid : A volume member of a raid set (not mountable)
0046      * - Other : A not mountable volume (like a swap partition)
0047      * - Unused : An unused or free volume
0048      */
0049     enum UsageType { Other = 0, Unused = 1, FileSystem = 2, PartitionTable = 3, Raid = 4, Encrypted = 5 };
0050     Q_ENUM(UsageType)
0051 
0052 private:
0053     /**
0054      * Creates a new StorageVolume object.
0055      * You generally won't need this. It's created when necessary using
0056      * Device::as().
0057      *
0058      * @param backendObject the device interface object provided by the backend
0059      * @see Solid::Device::as()
0060      */
0061     SOLID_NO_EXPORT explicit StorageVolume(QObject *backendObject);
0062 
0063 public:
0064     /**
0065      * Destroys a StorageVolume object.
0066      */
0067     ~StorageVolume() override;
0068 
0069     /**
0070      * Get the Solid::DeviceInterface::Type of the StorageVolume device interface.
0071      *
0072      * @return the StorageVolume device interface type
0073      * @see Solid::DeviceInterface::Type
0074      */
0075     static Type deviceInterfaceType()
0076     {
0077         return DeviceInterface::StorageVolume;
0078     }
0079 
0080     /**
0081      * Indicates if this volume should be ignored by applications.
0082      *
0083      * If it should be ignored, it generally means that it should be
0084      * invisible to the user. It's useful for firmware partitions or
0085      * OS reinstall partitions on some systems.
0086      *
0087      * @return true if the volume should be ignored
0088      */
0089     bool isIgnored() const;
0090 
0091     /**
0092      * Retrieves the type of use for this volume (for example filesystem).
0093      *
0094      * @return the usage type
0095      * @see Solid::StorageVolume::UsageType
0096      */
0097     UsageType usage() const;
0098 
0099     /**
0100      * Retrieves the filesystem type of this volume.
0101      *
0102      * FIXME: It's a platform dependent string, maybe we should switch to
0103      * an enum?
0104      *
0105      * @return the filesystem type if applicable, QString() otherwise
0106      */
0107     QString fsType() const;
0108 
0109     /**
0110      * Retrieves this volume label.
0111      *
0112      * @return the volume label if available, QString() otherwise
0113      */
0114     QString label() const;
0115 
0116     /**
0117      * Retrieves this volume Universal Unique IDentifier (UUID).
0118      *
0119      * You can generally assume that this identifier is unique with reasonable
0120      * confidence. Except if the volume UUID has been forged to intentionally
0121      * provoke a collision, the probability to have two volumes having the same
0122      * UUID is low.
0123      *
0124      * @return the Universal Unique IDentifier if available, QString() otherwise
0125      */
0126     QString uuid() const;
0127 
0128     /**
0129      * Retrieves this volume size in bytes.
0130      *
0131      * @return the size of this volume
0132      */
0133     qulonglong size() const;
0134 
0135     /**
0136      * Retrieves the crypto container of this volume.
0137      *
0138      * @return the encrypted volume containing the current volume if applicable,
0139      * an invalid device otherwise
0140      */
0141     Device encryptedContainer() const;
0142 
0143 protected:
0144     /**
0145      * @internal
0146      */
0147     SOLID_NO_EXPORT StorageVolume(StorageVolumePrivate &dd, QObject *backendObject);
0148 };
0149 }
0150 
0151 #endif // SOLID_STORAGEVOLUME_H