1 /*
2     Copyright 2006-2007 Kevin Ottens <ervin@kde.org>
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License as published by the Free Software Foundation; either
7     version 2.1 of the License, or (at your option) version 3, or any
8     later version accepted by the membership of KDE e.V. (or its
9     successor approved by the membership of KDE e.V.), which shall
10     act as a proxy defined in Section 6 of version 3 of the license.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Lesser General Public License for more details.
16 
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef SOLID_STORAGEVOLUME_H
22 #define SOLID_STORAGEVOLUME_H
23 
24 #include <solid-lite/solid_export.h>
25 
26 #include <solid-lite/deviceinterface.h>
27 
28 namespace Solid
29 {
30     class StorageVolumePrivate;
31     class Device;
32 
33     /**
34      * This device interface is available on volume devices.
35      *
36      * A volume is anything that can contain data (partition, optical disc,
37      * memory card). It's a particular kind of block device.
38      */
39     class SOLID_EXPORT StorageVolume : public DeviceInterface
40     {
41         Q_OBJECT
42         Q_ENUMS(UsageType)
43         Q_PROPERTY(bool ignored READ isIgnored)
44         Q_PROPERTY(UsageType usage READ usage)
45         Q_PROPERTY(QString fsType READ fsType)
46         Q_PROPERTY(QString label READ label)
47         Q_PROPERTY(QString uuid READ uuid)
48         Q_PROPERTY(qulonglong size READ size)
49         Q_DECLARE_PRIVATE(StorageVolume)
50         friend class Device;
51 
52     public:
53         /**
54          * This enum type defines the how a volume is used.
55          *
56          * - FileSystem : A mountable filesystem volume
57          * - PartitionTable : A volume containing a partition table
58          * - Raid : A volume member of a raid set (not mountable)
59          * - Other : A not mountable volume (like a swap partition)
60          * - Unused : An unused or free volume
61          */
62         enum UsageType { Other = 0, Unused = 1, FileSystem = 2, PartitionTable = 3, Raid = 4, Encrypted = 5 };
63 
64 
65     private:
66         /**
67          * Creates a new StorageVolume object.
68          * You generally won't need this. It's created when necessary using
69          * Device::as().
70          *
71          * @param backendObject the device interface object provided by the backend
72          * @see Solid::Device::as()
73          */
74         explicit StorageVolume(QObject *backendObject);
75 
76     public:
77         /**
78          * Destroys a StorageVolume object.
79          */
80         ~StorageVolume() override;
81 
82 
83         /**
84          * Get the Solid::DeviceInterface::Type of the StorageVolume device interface.
85          *
86          * @return the StorageVolume device interface type
87          * @see Solid::DeviceInterface::Type
88          */
deviceInterfaceType()89         static Type deviceInterfaceType() { return DeviceInterface::StorageVolume; }
90 
91 
92         /**
93          * Indicates if this volume should be ignored by applications.
94          *
95          * If it should be ignored, it generally means that it should be
96          * invisible to the user. It's useful for firmware partitions or
97          * OS reinstall partitions on some systems.
98          *
99          * @return true if the volume should be ignored
100          */
101         bool isIgnored() const;
102 
103         /**
104          * Retrieves the type of use for this volume (for example filesystem).
105          *
106          * @return the usage type
107          * @see Solid::StorageVolume::UsageType
108          */
109         UsageType usage() const;
110 
111         /**
112          * Retrieves the filesystem type of this volume.
113          *
114          * FIXME: It's a platform dependent string, maybe we should switch to
115          * an enum?
116          *
117          * @return the filesystem type if applicable, QString() otherwise
118          */
119         QString fsType() const;
120 
121         /**
122          * Retrieves this volume label.
123          *
124          * @return the volume label if available, QString() otherwise
125          */
126         QString label() const;
127 
128         /**
129          * Retrieves this volume Universal Unique IDentifier (UUID).
130          *
131          * You can generally assume that this identifier is unique with reasonable
132          * confidence. Except if the volume UUID has been forged to intentionally
133          * provoke a collision, the probability to have two volumes having the same
134          * UUID is low.
135          *
136          * @return the Universal Unique IDentifier if available, QString() otherwise
137          */
138         QString uuid() const;
139 
140         /**
141          * Retrieves this volume size in bytes.
142          *
143          * @return the size of this volume
144          */
145         qulonglong size() const;
146 
147         /**
148          * Retrieves the crypto container of this volume.
149          *
150          * @return the encrypted volume containing the current volume if appliable,
151          * an invalid device otherwise
152          */
153         Device encryptedContainer() const;
154 
155     protected:
156         /**
157          * @internal
158          */
159         StorageVolume(StorageVolumePrivate &dd, QObject *backendObject);
160     };
161 }
162 
163 #endif // SOLID_STORAGEVOLUME_H
164