gpt4 book ai didi

c++ - QStorageInfo 不适用于只读 rootfs

转载 作者:行者123 更新时间:2023-12-03 07:00:25 28 4
gpt4 key购买 nike

我在我的 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 设置为读/写权限时工作正常。设置为只读时,它不能作为异常(exception)工作
请帮助我理解带有只读 rootfs 的 QStorageInfo 问题。

最佳答案

QStorageInfo 正在尝试读取/etc/mtab 以获取已安装的卷。
/etc/mtab 由于只读 rootfs 无法生成。
/etc/mtab 是“../proc/self/mounts”的符号链接(symbolic link)。
所以在创建只读系统之前需要生成从“../proc/self/mounts”到/etc/mtab的smbolink链接。

关于c++ - QStorageInfo 不适用于只读 rootfs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64536279/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com