Skip to content

Commit ab67985

Browse files
committed
feat: Exclude removable devices when creating logical volume groups
When a user creates and mounts a logical volume on a removable device using deepin-diskmanager, there's no graphical way to stop the logical volume except by deleting the logical volume group. This prevents the user from safely removing the removable device, and even if they do manage to remove it safely, subsequent mounts of the logical volume will fail because it wasn't stopped. Therefore, let's exclude removable devices when creating logical volume groups. Log: Exclude removable devices when creating logical volume groups Bug: https://pms.uniontech.com/bug-view-340061.html
1 parent 6391e5e commit ab67985

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

application/widgets/createvgwidget.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,34 @@ void CreateVGWidget::updateData()
11401140
qDebug() << "CreateVGWidget::updateData completed";
11411141
}
11421142

1143+
static bool isDeviceRemovable(const QString &devicePath)
1144+
{
1145+
QFileInfo deviceInfo(devicePath);
1146+
QString deviceName = deviceInfo.fileName(); // e.g., "sda"
1147+
1148+
QString sysfsRemovablePath = QString("/sys/block/%1/removable").arg(deviceName);
1149+
QFile removableFile(sysfsRemovablePath);
1150+
bool removable = false;
1151+
QByteArray content;
1152+
1153+
if (!removableFile.exists()) {
1154+
qWarning() << "Sysfs path does not exist:" << sysfsRemovablePath;
1155+
goto quit;
1156+
}
1157+
1158+
if (!removableFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
1159+
qWarning() << "Could not open sysfs removable file:" << sysfsRemovablePath;
1160+
goto quit;
1161+
}
1162+
1163+
content = removableFile.readAll().trimmed(); // trimmed() 移除换行符和空格
1164+
removable = (content == "1");
1165+
1166+
quit:
1167+
qDebug() << "isDeviceRemovable:" << devicePath << removable;
1168+
return removable;
1169+
}
1170+
11431171
QList<DeviceInfo> CreateVGWidget::createAvailableDiskData()
11441172
{
11451173
qDebug() << "CreateVGWidget::createAvailableDiskData called.";
@@ -1155,6 +1183,11 @@ QList<DeviceInfo> CreateVGWidget::createAvailableDiskData()
11551183
continue;
11561184
}
11571185

1186+
// 排除可移动设备
1187+
if (isDeviceRemovable(info.m_path)) {
1188+
continue;
1189+
}
1190+
11581191
// 排除已加入VG的磁盘以及分区表错误的磁盘
11591192
if (isJoinAllVG.value(info.m_path) == "false") {//还需加上磁盘分区表是否错误的判断
11601193
PartitionVec lstNewPartition;

0 commit comments

Comments
 (0)