~aleteoryx/muditaos

b281a39f42281729514103bf92a66f1148e5f9eb — Lefucjusz 3 years ago f4aaf4e
[MOS-744] Fix MTP integration

Fixed issues with integration
of MTP with filesystem:
- fixed memory corruption in
get_disk_properties();
- removed spare space hack
causing MTP to return invalid
free space and capacity of
the storage;
- added mtime and ctime
handling;
- minor code cleanup.
M module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpointCommon.cpp => module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpointCommon.cpp +1 -1
@@ 169,6 169,6 @@ namespace sdesktop::endpoints
            totalDeviceSpaceMiB += totalSpace;
        }

        return {totalDeviceSpaceMiB, reservedSystemSpaceMiB, usedUserSpaceMiB + purefs::userSpaceOffset};
        return {totalDeviceSpaceMiB, reservedSystemSpaceMiB, usedUserSpaceMiB};
    }
} // namespace sdesktop::endpoints

M module-services/service-desktop/endpoints/filesystem/FS_Helper.cpp => module-services/service-desktop/endpoints/filesystem/FS_Helper.cpp +11 -7
@@ 14,6 14,11 @@

namespace sdesktop::endpoints
{
    namespace
    {
        constexpr auto bytesInMebibyte = 1024LLU * 1024LLU;
    }

    using sender::putToSendQueue;
    namespace fs = std::filesystem;



@@ 209,8 214,7 @@ namespace sdesktop::endpoints
            return ResponseContext{.status = code};
        }

        auto freeSpaceLeftForUserFilesMiB = getFreeSpaceForUserFilesMiB();
        constexpr auto bytesInMebibyte    = 1048576;
        const auto freeSpaceLeftForUserFilesMiB = getFreeSpaceForUserFilesMiB();

        if (fileSize / bytesInMebibyte > freeSpaceLeftForUserFilesMiB) {
            LOG_ERROR("Not enough space left on device!");


@@ 351,10 355,10 @@ namespace sdesktop::endpoints
            return 0;
        }

        unsigned long freeMbytes =
            (static_cast<std::uint64_t>(vfstat->f_bfree) * static_cast<std::uint64_t>(vfstat->f_bsize)) /
                (1024LLU * 1024LLU) -
            purefs::userSpaceOffset;
        return freeMbytes;
        const auto freeBytes =
            (static_cast<std::uint64_t>(vfstat->f_bfree) * static_cast<std::uint64_t>(vfstat->f_bsize));
        const auto freeMiBs = freeBytes / bytesInMebibyte;

        return freeMiBs;
    }
} // namespace sdesktop::endpoints

M module-vfs/drivers/src/purefs/fs/filesystem_ext4.cpp => module-vfs/drivers/src/purefs/fs/filesystem_ext4.cpp +24 -11
@@ 17,7 17,6 @@
#include <climits>
#include <syslimits.h>
#include <sys/statvfs.h>
#include <fcntl.h>
#include <errno.h>
#include <cstring>
#include <algorithm>


@@ 166,7 165,7 @@ namespace purefs::fs::drivers
        // Start journaling
        err = ext4_journal_start(mnt_path.c_str());
        if (err) {
            LOG_WARN("Unable to start journalling errno %i", err);
            LOG_WARN("Unable to start journaling errno %i", err);
        }
        err = ext4_block_cache_write_back(bd, true);
        if (err) {


@@ 256,6 255,9 @@ namespace purefs::fs::drivers
        const auto fspath = vmnt->native_path(path);
        auto filp         = std::make_shared<file_handle_ext4>(mnt, fspath, flags);
        auto err          = ext4_fopen2(filp->filp(), fspath.c_str(), flags);
        if (err == EOK) {
            ext4_atime_set(fspath.c_str(), time(nullptr));
        }
        filp->error(-err);
        return filp;
    }


@@ 268,7 270,16 @@ namespace purefs::fs::drivers
    auto filesystem_ext4::write(fsfile zfile, const char *ptr, size_t len) noexcept -> ssize_t
    {
        size_t n_written;
        auto err = invoke_efs(zfile, ::ext4_fwrite, ptr, len, &n_written);
        const auto err = invoke_efs(zfile, ::ext4_fwrite, ptr, len, &n_written);
        if (err == EOK) {
            const auto vfile     = std::dynamic_pointer_cast<file_handle_ext4>(zfile);
            const auto vmnt      = std::dynamic_pointer_cast<mount_point_ext4>(vfile->mntpoint());
            const auto timestamp = time(nullptr);

            ext4_locker _lck(vmnt);
            ext4_ctime_set(vfile->open_path().c_str(), timestamp);
            ext4_mtime_set(vfile->open_path().c_str(), timestamp);
        }
        return (err) ? (-err) : (n_written);
    }



@@ 281,7 292,6 @@ namespace purefs::fs::drivers

    auto filesystem_ext4::seek(fsfile zfile, off_t pos, int dir) noexcept -> off_t
    {

        auto vfile = std::dynamic_pointer_cast<file_handle_ext4>(zfile);
        if (!vfile) {
            LOG_ERROR("Non ext4 filesystem file pointer");


@@ 322,13 332,16 @@ namespace purefs::fs::drivers
            st->st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
        }
        // Update file type
        st->st_nlink   = ext4_inode_get_links_cnt(&ino);
        st->st_uid     = ext4_inode_get_uid(&ino);
        st->st_gid     = ext4_inode_get_gid(&ino);
        st->st_blocks  = ext4_inode_get_blocks_count(sb, &ino);
        st->st_size    = ext4_inode_get_size(sb, &ino);
        st->st_blksize = ext4_sb_get_block_size(sb);
        st->st_dev     = ext4_inode_get_dev(&ino);
        st->st_nlink       = ext4_inode_get_links_cnt(&ino);
        st->st_uid         = ext4_inode_get_uid(&ino);
        st->st_gid         = ext4_inode_get_gid(&ino);
        st->st_blocks      = ext4_inode_get_blocks_count(sb, &ino);
        st->st_size        = ext4_inode_get_size(sb, &ino);
        st->st_blksize     = ext4_sb_get_block_size(sb);
        st->st_dev         = ext4_inode_get_dev(&ino);
        st->st_atim.tv_sec = ext4_inode_get_access_time(&ino);
        st->st_ctim.tv_sec = ext4_inode_get_change_inode_time(&ino);
        st->st_mtim.tv_sec = ext4_inode_get_modif_time(&ino);
        return err;
    }


M module-vfs/paths/include/purefs/filesystem_paths.hpp => module-vfs/paths/include/purefs/filesystem_paths.hpp +0 -2
@@ 8,8 8,6 @@
namespace purefs
{
    std::filesystem::path createPath(const std::string &parent, const std::string &child) noexcept;
    constexpr inline auto userSpaceOffset = 1023; // This space is additionally reserved on the user partition,
                                                  // and it's excluded from the space that user can use for his files

    namespace dir
    {

M pure_changelog.md => pure_changelog.md +1 -0
@@ 9,6 9,7 @@
* Made windows flow in SIM cards settings more robust
* Improve refreshing of the display.
* Fixed music files extension case sensitivity
* Fixed MTP issues

### Fixed
* Fixed wrong time displayed on password locked screen with 'Quotes' or 'Logo' wallpaper

M third-party/usb_stack => third-party/usb_stack +1 -1
@@ 1,1 1,1 @@
Subproject commit 6caba85bdcdf31ebd30beb91f28810ecc4016c56
Subproject commit ff6c7d31592f859de8555780a259978289df81ef