Skip to content

Commit cf65ca3

Browse files
wangrong1069deepin-bot[bot]
authored andcommitted
fix: fix udisks fail to mount disk for invalid fstab
Diskmanager will modify fstab when mounting a disk, which may cause udisks to fail to mount the disk under certain conditions. Let’s not modify fstab anymore. Log: Diskmanager no longer supports mounting disks at boot time Bug: https://pms.uniontech.com/bug-view-286623.html
1 parent 711c391 commit cf65ca3

1 file changed

Lines changed: 1 addition & 59 deletions

File tree

service/diskoperation/partedcore.cpp

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,65 +3793,7 @@ bool PartedCore::umontDevice(QVector<QString> mountPoints, QString devPath)
37933793

37943794
bool PartedCore::writeFstab(const QString &uuid, const QString &mountpath, const QString &type, bool isMount)
37953795
{
3796-
//写入fstab 永久挂载
3797-
qDebug() << __FUNCTION__ << "Write fstab start";
3798-
if (uuid.isEmpty() || (mountpath.isEmpty() && isMount) || type.isEmpty()) { //非挂载 不需要挂载点 可以传空值
3799-
qDebug() << __FUNCTION__ << "Write fstabt argument error";
3800-
return false;
3801-
}
3802-
3803-
QFile file("/etc/fstab");
3804-
QStringList list;
3805-
3806-
// open fstab
3807-
if (!file.open(QIODevice::ReadOnly)) { //打开指定文件
3808-
qDebug() << __FUNCTION__ << "Write fstabt: open file error";
3809-
return false;
3810-
}
3811-
3812-
//此处修改:因为mount读取/etc/fstab配置文件 开机自动挂载 而fat32或fat16 mount不识别,所以要改成vfat
3813-
QString type2 = (type.contains("fat32") || type.contains("fat16")) ? QString("vfat") : type;
3814-
3815-
// read fstab
3816-
bool findflag = false; //目前默认只改第一个发现的uuid findflag 标志位:是否已经查找到uuid
3817-
while (!file.atEnd()) {
3818-
QByteArray line = file.readLine();//获取数据
3819-
QString str = line;
3820-
if (isMount) {
3821-
//vfat 1051系统上vfat格式不指定utf8挂载 通过文件管理器右键菜单新建文件夹会乱码 导致创建错误 为了规避该问题加上utf8属性
3822-
QString mountStr = (type2 == "vfat") ? QString("UUID=%1 %2 %3 defaults,nofail,utf8,dmask=000,fmask=111 0 0\n").arg(uuid).arg(mountpath).arg(type2)
3823-
: QString("UUID=%1 %2 %3 defaults,nofail 0 0\n").arg(uuid).arg(mountpath).arg(type2);
3824-
3825-
if (str.contains(uuid) && !findflag) { //首次查找到uuid
3826-
findflag = true;
3827-
list << mountStr;
3828-
continue;
3829-
} else if (file.atEnd() && !findflag) { //查找到结尾且没有查找到uuid
3830-
list << str << mountStr;
3831-
break;
3832-
}
3833-
list << str;
3834-
} else {
3835-
if (!str.contains(uuid)) {
3836-
list << str;
3837-
}
3838-
}
3839-
}
3840-
file.close();
3841-
3842-
//write fstab
3843-
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
3844-
qDebug() << __FUNCTION__ << "Write fstabt: open file error";
3845-
return false;
3846-
}
3847-
3848-
QTextStream out(&file);
3849-
for (int i = 0; i < list.count(); i++) {
3850-
out << list.at(i);
3851-
}
3852-
out.flush();
3853-
file.close();
3854-
qDebug() << __FUNCTION__ << "Write fstabt end";
3796+
/* 禁止修改 fstab 以避免干扰 udisks 运行 */
38553797
return true;
38563798
}
38573799

0 commit comments

Comments
 (0)