dtkio
dtk library for dtkio.
载入中...
搜索中...
未找到
dblockdevice.h
浏览该文件的文档.
1// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DBLOCKDEVICE_H
6#define DBLOCKDEVICE_H
7
8#include <DtkMountGlobal>
9
10#include <QObject>
11#include <QDBusError>
12#include <QVariantMap>
13
14#include <DExpected>
15
16QT_BEGIN_NAMESPACE
17class QDBusObjectPath;
18QT_END_NAMESPACE
19
20DCORE_USE_NAMESPACE
21DMOUNT_BEGIN_NAMESPACE
22
23class DBlockDevice;
24namespace DDeviceManager {
25DExpected<DBlockDevice *> createBlockDevice(const QString &path, QObject *parent);
26DExpected<DBlockDevice *> createBlockDeviceByDevicePath(const QByteArray &path, QObject *parent);
27} // namespace DDeviceManager
28
29class DBlockDevicePrivate;
30class DBlockDevice : public QObject
31{
32 Q_OBJECT
33 Q_DECLARE_PRIVATE(DBlockDevice)
34
35 Q_PROPERTY(QString path READ path CONSTANT FINAL);
36 Q_PROPERTY(bool watchChanges READ watchChanges WRITE setWatchChanges);
37 Q_PROPERTY(bool hasFileSystem READ hasFileSystem NOTIFY hasFileSystemChanged);
38 Q_PROPERTY(bool hasPartition READ hasPartition NOTIFY hasPartitionChanged);
39 Q_PROPERTY(bool isEncrypted READ isEncrypted NOTIFY isEncryptedChanged);
40 Q_PROPERTY(bool isLoopDevice READ isLoopDevice CONSTANT);
41 Q_PROPERTY(QList<QPair<QString, QVariantMap>> configuration READ configuration NOTIFY configurationChanged);
42 Q_PROPERTY(QString cryptoBackingDevice READ cryptoBackingDevice NOTIFY cryptoBackingDeviceChanged);
43 Q_PROPERTY(QByteArray device READ device CONSTANT);
44 Q_PROPERTY(quint64 deviceNumber READ deviceNumber CONSTANT);
45 Q_PROPERTY(QString drive READ drive CONSTANT);
46 Q_PROPERTY(bool hintAuto READ hintAuto NOTIFY hintAutoChanged);
47 Q_PROPERTY(QString hintIconName READ hintIconName NOTIFY hintIconNameChanged);
48 Q_PROPERTY(bool hintIgnore READ hintIgnore NOTIFY hintIgnoreChanged);
49 Q_PROPERTY(QString hintName READ hintName NOTIFY hintNameChanged);
50 Q_PROPERTY(bool hintPartitionable READ hintPartitionable NOTIFY hintPartitionableChanged);
51 Q_PROPERTY(QString hintSymbolicIconName READ hintSymbolicIconName NOTIFY hintSymbolicIconNameChanged);
52 Q_PROPERTY(bool hintSystem READ hintSystem CONSTANT);
53 Q_PROPERTY(QString id READ id CONSTANT);
54 Q_PROPERTY(QString idLabel READ idLabel NOTIFY idLabelChanged);
55 Q_PROPERTY(QString idType READ idType NOTIFY idTypeChanged);
56 // TODO(zhangs); Q_PROPERTY(FSType fsType READ fsType NOTIFY fsTypeChanged);
57 Q_PROPERTY(QString idUUID READ idUUID NOTIFY idUUIDChanged);
58 Q_PROPERTY(QString idUsage READ idUsage NOTIFY idUsageChanged);
59 Q_PROPERTY(QString idVersion READ idVersion NOTIFY idVersionChanged);
60 Q_PROPERTY(QString mDRaid READ mDRaid NOTIFY mDRaidChanged);
61 Q_PROPERTY(QString mDRaidMember READ mDRaidMember NOTIFY mDRaidMemberChanged);
62 Q_PROPERTY(QByteArray preferredDevice READ preferredDevice NOTIFY preferredDeviceChanged);
63 Q_PROPERTY(bool readOnly READ readOnly NOTIFY readOnlyChanged);
64 Q_PROPERTY(quint64 size READ size NOTIFY sizeChanged);
65 Q_PROPERTY(QByteArrayList symlinks READ symlinks NOTIFY symlinksChanged);
66 Q_PROPERTY(QStringList userspaceMountOptions READ userspaceMountOptions NOTIFY userspaceMountOptionsChanged);
67 Q_PROPERTY(QByteArrayList mountPoints READ mountPoints NOTIFY mountPointsChanged);
68 Q_PROPERTY(PartitionTableType partitionTableType READ partitionTableType NOTIFY ptTypeChanged);
69 Q_PROPERTY(QList<QPair<QString, QVariantMap>> childConfiguration READ childConfiguration NOTIFY childConfigurationChanged);
70 Q_PROPERTY(QString cleartextDevice READ cleartextDevice NOTIFY cleartextDeviceChanged);
71
72public:
79
80 Q_ENUM(PartitionTableType)
81
82 ~DBlockDevice() override;
83
84public:
85 bool isValid() const;
86 void setWatchChanges(bool watchChanges);
87 bool watchChanges() const;
88
89 QString path() const;
90 QList<QPair<QString, QVariantMap>> configuration() const;
91 QString cryptoBackingDevice() const;
92 QByteArray device() const;
93 quint64 deviceNumber() const;
94 QString drive() const;
95 bool hintAuto() const;
96 QString hintIconName() const;
97 bool hintIgnore() const;
98 QString hintName() const;
99 bool hintPartitionable() const;
100 QString hintSymbolicIconName() const;
101 bool hintSystem() const;
102 QString id() const;
103 QString idLabel() const;
104 QString idType() const;
105 // TODO(zhangs): FSType fsType() const;
106 QString idUUID() const;
107 QString idUsage() const;
108 QString idVersion() const;
109 QString mDRaid() const;
110 QString mDRaidMember() const;
111 QByteArray preferredDevice() const;
112 bool readOnly() const;
113 quint64 size() const;
114 QByteArrayList symlinks() const;
115 QStringList userspaceMountOptions() const;
116 bool canSetLabel() const;
117
118 bool hasFileSystem() const;
119 bool hasPartition() const;
120 bool isEncrypted() const;
121 bool isLoopDevice() const;
122
123 static bool hasFileSystem(const QString &path);
124 static bool hasPartition(const QString &path);
125 static bool isEncrypted(const QString &path);
126 static bool isLoopDevice(const QString &path);
127
128 QByteArrayList mountPoints() const;
130
131 QList<QPair<QString, QVariantMap>> childConfiguration() const;
132
133public Q_SLOTS:
134 void format(const QString &type, const QVariantMap &options);
135 // TODO(zhangs): void format(const FSType &type, const QVariantMap &options);
136 QList<QPair<QString, QVariantMap>> getSecretConfiguration(const QVariantMap &options);
137 void addConfigurationItem(const QPair<QString, QVariantMap> &item, const QVariantMap &options);
138 void removeConfigurationItem(const QPair<QString, QVariantMap> &item, const QVariantMap &options);
139 void updateConfigurationItem(const QPair<QString, QVariantMap> &oldItem, const QPair<QString, QVariantMap> &newItem, const QVariantMap &options);
140 int openDevice(const QString &mode, const QVariantMap &options);
141 int openForBackup(const QVariantMap &options);
142 int openForBenchmark(const QVariantMap &options);
143 int openForRestore(const QVariantMap &options);
144 void rescan(const QVariantMap &options);
145
146 QString mount(const QVariantMap &options);
147 void unmount(const QVariantMap &options);
148 // TODO(zhangs): async interfaces
149 void setLabel(const QString &label, const QVariantMap &options);
150
151 void changePassphrase(const QString &passphrase, const QString &newPassphrase, const QVariantMap &options);
152 void lock(const QVariantMap &options);
153 QString unlock(const QString &passphrase, const QVariantMap &options);
154 // TODO(zhangs): async interfaces
156
157Q_SIGNALS:
158 void hasFileSystemChanged(bool hasFileSystem);
159 void hasPartitionChanged(bool hasPartition);
160 void isEncryptedChanged(bool isEncrypted);
161 void configurationChanged(QList<QPair<QString, QVariantMap>> configuration);
162 void cryptoBackingDeviceChanged(QString cryptoBackingDevice);
163 void hintAutoChanged(bool hintAuto);
164 void hintIconNameChanged(QString hintIconName);
165 void hintIgnoreChanged(bool hintIgnore);
166 void hintNameChanged(QString hintName);
167 void hintPartitionableChanged(bool hintPartitionable);
168 void hintSymbolicIconNameChanged(QString hintSymbolicIconName);
169 void idLabelChanged(QString idLabel);
170 void idTypeChanged(QString idType);
171 void fsTypeChanged(QString fsType);
172 void idUUIDChanged(QString idUUID);
173 void idUsageChanged(QString idUsage);
174 void idVersionChanged(QString idVersion);
175 void mDRaidChanged(QString mDRaid);
176 void mDRaidMemberChanged(QString mDRaidMember);
177 void preferredDeviceChanged(QByteArray preferredDevice);
178 void readOnlyChanged(bool readOnly);
179 void sizeChanged(quint64 size);
180 void symlinksChanged(QByteArrayList symlinks);
181 void userspaceMountOptionsChanged(QStringList userspaceMountOptions);
183 void mountPointsChanged(const QByteArrayList &mountPoints);
184 void childConfigurationChanged(QList<QPair<QString, QVariantMap>> childConfiguration);
185 void cleartextDeviceChanged(const QString &cleartextDevice);
186
187protected:
188 explicit DBlockDevice(const QString &path, QObject *parent = nullptr);
189 explicit DBlockDevice(DBlockDevicePrivate &dd, const QString &path, QObject *parent = nullptr);
190
191 QScopedPointer<DBlockDevicePrivate> d_ptr;
192
193 friend DExpected<DBlockDevice *> DDeviceManager::createBlockDevice(const QString &path, QObject *parent);
194 friend DExpected<DBlockDevice *> DDeviceManager::createBlockDeviceByDevicePath(const QByteArray &path, QObject *parent);
195};
196
197DMOUNT_END_NAMESPACE
198
199#endif // DBLOCKDEVICE_H
用于管理系统中块设备的类,对设备进行挂载、卸载等操作,以及获取其基本属性
Definition dblockdevice.h:31
void changePassphrase(const QString &passphrase, const QString &newPassphrase, const QVariantMap &options)
修改磁盘密码
void symlinksChanged(QByteArrayList symlinks)
通知磁盘设备链接发生变化
QString path() const
获取设备路径,该路径在构造对象时传入
void cryptoBackingDeviceChanged(QString cryptoBackingDevice)
通知加密设备路径发生变化
QString idVersion() const
设备文件系统版本或其他结构属性
void sizeChanged(quint64 size)
通知磁盘大小发生变化
void ptTypeChanged()
通知磁盘分区类型发生变化
int openForBenchmark(const QVariantMap &options)
打开设备以便可以对设备进行跑分操作
QByteArrayList symlinks() const
获取设备对应的链接列表
QString idUUID() const
获取设备 UUID
void idVersionChanged(QString idVersion)
通知磁盘文件系统版本发生变化
void format(const QString &type, const QVariantMap &options)
格式化设备
void isEncryptedChanged(bool isEncrypted)
通知加密状态发生变化
bool readOnly() const
获取是否为只读设备
void addConfigurationItem(const QPair< QString, QVariantMap > &item, const QVariantMap &options)
添加新的配置项
quint64 size() const
获取块设备大小
PartitionTableType
磁盘分区类型
Definition dblockdevice.h:73
@ InvalidPT
Definition dblockdevice.h:74
@ GPT
Definition dblockdevice.h:76
@ MBR
Definition dblockdevice.h:75
bool hintPartitionable() const
获取设备是否可分区,软盘、光驱和 LVM 逻辑卷除外
QString idUsage() const
获取设备 ID 用途
quint64 deviceNumber() const
获取设备对应的 dev_t 设备号
static bool isEncrypted(const QString &path)
获取设备是否是加密
PartitionTableType partitionTableType() const
获取设备分区表类型
QByteArrayList mountPoints() const
获取设备挂载点列表
static bool hasPartition(const QString &path)
获取设备是否有分区
void setLabel(const QString &label, const QVariantMap &options)
设置磁盘卷标
QList< QPair< QString, QVariantMap > > configuration() const
获取设备配置列表
void hintIconNameChanged(QString hintIconName)
通知磁盘建议图标名称变化
QString cleartextDevice()
获取加密设备对应的明文设备对象路径
void unmount(const QVariantMap &options)
卸载设备
static bool isLoopDevice(const QString &path)
获取是否为回环设备
void mDRaidMemberChanged(QString mDRaidMember)
通知磁盘阵列成员发生变化
QString unlock(const QString &passphrase, const QVariantMap &options)
给加密设备解锁
void readOnlyChanged(bool readOnly)
通知磁盘只读属性发生变化
void removeConfigurationItem(const QPair< QString, QVariantMap > &item, const QVariantMap &options)
移除配置项
void idUsageChanged(QString idUsage)
通知磁盘 idUsage 发生变化
QString cryptoBackingDevice() const
获取设备的加密块设备
void configurationChanged(QList< QPair< QString, QVariantMap > > configuration)
通知配置列表发生变化
QStringList userspaceMountOptions() const
获取挂载时的参数列表
QList< QPair< QString, QVariantMap > > childConfiguration() const
获取设备子配置列表
void setWatchChanges(bool watchChanges)
设置是否监听设备属性变化
void idUUIDChanged(QString idUUID)
通知磁盘 UUID 发生变化
QString idType() const
通常情况下,用于获取设备文件系统,但在 idUsage 为非 fileSystem 时,有其他表意
QString hintIconName() const
获取用于展示设备的图标名称
bool canSetLabel() const
获取磁盘能否设置卷标
void mountPointsChanged(const QByteArrayList &mountPoints)
通知磁盘设备挂载点发生变化
QString drive() const
获取设备对应的磁盘驱动器路径
void rescan(const QVariantMap &options)
重新扫描设备
QString hintSymbolicIconName() const
获取用于展示设备的符号图标
void idLabelChanged(QString idLabel)
通知磁盘卷标发生变化
bool hintAuto() const
获取设备是否应自动启动
QString mDRaid() const
如果是阵列设备,该函数返回设备的阵列对象路径
void preferredDeviceChanged(QByteArray preferredDevice)
通知磁盘最佳设备描述符发生变化
int openDevice(const QString &mode, const QVariantMap &options)
打开设备
bool hasPartition() const
获取设备是否有分区
QList< QPair< QString, QVariantMap > > getSecretConfiguration(const QVariantMap &options)
获取包含加密信息的配置信息
void hintIgnoreChanged(bool hintIgnore)
通知磁盘忽略属性变化
bool isEncrypted() const
获取设备是否是加密设备
void userspaceMountOptionsChanged(QStringList userspaceMountOptions)
通知磁盘用户态挂载选项发生变化
QString mDRaidMember() const
如果设备是阵列成员,则返回阵列对象路径
void hasFileSystemChanged(bool hasFileSystem)
通知文件系统的有无发生变化
bool hintIgnore() const
获取设备是否应被忽略
QByteArray device() const
获取块设备在系统中的设备描述符
QString idLabel() const
获取磁盘卷标,通常用于显示磁盘名称
bool isLoopDevice() const
获取设备是否是回环设备
void cleartextDeviceChanged(const QString &cleartextDevice)
通知磁盘明文设备内容发生变化
void idTypeChanged(QString idType)
通知磁盘 idType 发生变化
void mDRaidChanged(QString mDRaid)
通知磁盘阵列属性发生变化
int openForRestore(const QVariantMap &options)
打开一个可写设备,用于还原设备数据,仅在设备未使用是该方法有效
bool hintSystem() const
获取设备是否为系统内置磁盘
void hintPartitionableChanged(bool hintPartitionable)
通知磁盘可分区属性发生变化
QString id() const
获取设备唯一标识符
void hintSymbolicIconNameChanged(QString hintSymbolicIconName)
通知磁盘建议符号图标名称发生变化
bool watchChanges() const
获取当前设备监听状态
void updateConfigurationItem(const QPair< QString, QVariantMap > &oldItem, const QPair< QString, QVariantMap > &newItem, const QVariantMap &options)
更新配置项
void childConfigurationChanged(QList< QPair< QString, QVariantMap > > childConfiguration)
通知磁盘子配置列表发生变化
int openForBackup(const QVariantMap &options)
以只读方式打开设备以便可以按字节镜像设备内容,仅在设备未使用时该方法操作有效
bool hasFileSystem() const
获取设备是否有文件系统
QString mount(const QVariantMap &options)
挂载设备
bool isValid() const
判断设备是否为有效设备,若构造时传入了无效的路径,则返回 False
void hintNameChanged(QString hintName)
通知磁盘建议名称发生变化
static bool hasFileSystem(const QString &path)
获取设备是否有文件系统
void lock(const QVariantMap &options)
给加密设备上锁
void fsTypeChanged(QString fsType)
通知磁盘文件系统类型发生变化
void hintAutoChanged(bool hintAuto)
通知自动开启属性变化
QByteArray preferredDevice() const
获取最佳设备路径,例如,对于设备 /dev/mapper/mpathk,对应的路径为 /dev/dm-9
QString hintName() const
用于展示设备的磁盘名称
void hasPartitionChanged(bool hasPartition)
通知分区有无状态发生变化
DExpected< DBlockDevice * > createBlockDevice(const QString &path, QObject *parent)
创建一个块设备对象
DExpected< DBlockDevice * > createBlockDeviceByDevicePath(const QByteArray &path, QObject *parent)
通过设备路径创建块设备对象