~aleteoryx/muditaos

13483910021955a64dc4047d3e4871fff39bea70 — Lucjan Bryndza 4 years ago 4cec2dd
[EGD-7742] Fix stat() on the ext4 fs

Fix stat() on the ext4 rootfs

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>
M module-platform/linux/tests/CMakeLists.txt => module-platform/linux/tests/CMakeLists.txt +1 -0
@@ 63,6 63,7 @@ add_catch2_executable(
        ${CMAKE_CURRENT_LIST_DIR}/unittest_filesystem_ext4.cpp
    LIBS
        platform
        module-vfs
    DEPS
        ${EXT4_IMAGE}
    USE_FS

M module-platform/linux/tests/unittest_filesystem_ext4.cpp => module-platform/linux/tests/unittest_filesystem_ext4.cpp +1 -0
@@ 64,6 64,7 @@ TEST_CASE("ext4: Basic mount and functionality")
    REQUIRE(fscore.mount("emmc0part0", "/path", "vfat") == -EBUSY);
    struct statvfs ssv;
    REQUIRE(fscore.stat_vfs("/sys/", ssv) == 0);
    REQUIRE(fscore.stat_vfs("/sys", ssv) == 0);

    REQUIRE(fscore.umount("/sys") == 0);
    REQUIRE(vfs_ext->mount_count() == 0);

M module-vfs/drivers/src/purefs/fs/filesystem_ext4.cpp => module-vfs/drivers/src/purefs/fs/filesystem_ext4.cpp +6 -2
@@ 345,12 345,16 @@ namespace purefs::fs::drivers

    auto filesystem_ext4::stat(fsmount mnt, std::string_view file, struct stat &st) noexcept -> int
    {
        auto mntp = std::static_pointer_cast<mount_point_ext4>(mnt);
        auto mntp = std::dynamic_pointer_cast<mount_point_ext4>(mnt);
        if (!mntp) {
            LOG_ERROR("Non ext4 mount point");
            return -EBADF;
        }
        const auto npath = mntp->native_path(file);
        // NOTE: mod path fix for lwext4 open root dir
        auto npath = mntp->native_path(file);
        if (npath.empty()) {
            npath = mntp->mount_path();
        }
        ext4_locker _lck(mntp);
        return stat(mntp->mount_path().c_str(), npath.c_str(), &st, mntp->is_ro());
    }