首页 > 解决方案 > 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 问题。

标签: c++qtc++14embedded-linux

解决方案


QStorageInfo 正在尝试读取 /etc/mtab 以获取已安装的卷。/etc/mtab 由于只读 rootfs 无法生成。

/etc/mtab 是“../proc/self/mounts”的符号链接。

所以在创建只读系统之前需要生成从“../proc/self/mounts”到/etc/mtab的smbolink链接。


推荐阅读