c++ - QStorageInfo 不适用于只读 rootfs
问题描述
我在我的 debian strech 系统上使用 qt 修订版 5.7.1。我已使用 overlayfs 将 rootfs 安装为只读,我已使用 QStorageInfo 检查我的 SD 卡大小。
将 rootfs 安装为只读后,我在 QStorageInfo 安装卷中只获得了根目录。
下面是获取存储列表的源代码:
foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) {
if (storage.isValid() && storage.isReady())
{
qDebug() << "storage path" << storage.rootPath();
qDebug() << "storage name" << storage.name();
qDebug() << "storage readonly" << storage.isReadOnly();
qDebug() << "storage filesystem type " << storage.fileSystemType();
qDebug() << "storage device " << storage.device();
}
}
上述来源的输出:
storage path "/"
storage name ""
storage readonly true
storage filesystem type ""
storage device ""
我的 /etc/fstab 文件包含:
/dev/mmcblk0p1 / ext4 ro,noatime 0 1
mount_overlay /var fuse nofail,defaults 0 0
mount_overlay /home fuse nofail,defaults 0 0
mount_overlay /etc fuse nofail,defaults 0 0
none /tmp tmpfs defaults 0 0
如果我将 rootfs 挂载为“rw” QStorageInfo 工作正常。以下是“rw”选项中作为 rootfs 的输出:
storage path "/"
storage name ""
storage readonly false
storage filesystem type "ext4"
storage device "/dev/root"
storage path "/run"
storage name ""
storage readonly false
storage filesystem type "tmpfs"
storage device "tmpfs"
storage path "/run/lock"
storage name ""
storage readonly false
storage filesystem type "tmpfs"
storage device "tmpfs"
storage path "/tmp"
storage name ""
storage readonly false
storage filesystem type "tmpfs"
storage device "none"
storage path "/home"
storage name ""
storage readonly false
storage filesystem type "ext4"
storage device "/dev/root"
storage path "/var"
storage name ""
storage readonly false
storage filesystem type "ext4"
storage device "/dev/root"
storage path "/media/data"
storage name "Data"
storage readonly false
storage filesystem type "ext4"
storage device "/dev/mmcblk0p3"
storage path "/run/user/0"
storage name ""
storage readonly false
storage filesystem type "tmpfs"
storage device "tmpfs"
storage path "/home/user/SdCard"
storage name "SDCard"
storage readonly false
storage filesystem type "ext4"
storage device "/dev/mmcblk1p1"
storage path "/home_org/user/SdCard"
storage name "SDCard"
storage readonly false
storage filesystem type "ext4"
storage device "/dev/mmcblk1p1"
当将 rootfs 设置为读/写权限时工作正常。设置为只读时,它不能作为例外工作
请帮助我理解带有只读 rootfs 的 QStorageInfo 问题。
解决方案
QStorageInfo 正在尝试读取 /etc/mtab 以获取已安装的卷。/etc/mtab 由于只读 rootfs 无法生成。
/etc/mtab 是“../proc/self/mounts”的符号链接。
所以在创建只读系统之前需要生成从“../proc/self/mounts”到/etc/mtab的smbolink链接。
推荐阅读
- gradle - IntelliJ Gradle 与 libGdx 项目同步失败
- db2 - 在 DB2 的 SQL 查询中使用时添加 1 天日期字段
- sql - 尝试在 django 中使用游标删除表
- android - 强制 android studio 使用我的 android 包中定义的类
- sql - 为什么 PIVOT 子句中的 IN 语句必须是静态的
- amazon-web-services - AWS 上下文中的无头用户是什么?
- ios - 使 NSAttributeString backroundColor 覆盖所有标签区域?
- python - 为什么我会得到这个不能索引包含 NA / NaN 值错误的向量
- react-native - 在 React Native 中处理父组件中子组件的 onValueChange
- javascript - 滚动时如何停止页脚前面的块?