~aleteoryx/muditaos

ref: 25a5d90f4e12ee5d33f4202170f18b59e16a9564 muditaos/module-vfs/drivers/src/purefs/fs/mount_point_ext4.cpp -rw-r--r-- 1.6 KiB
25a5d90f — rrandomsky [CP-2156] Fixed no response when editing a contact to have the same number as another 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <purefs/fs/drivers/mount_point_ext4.hpp>
#include <mutex.hpp>
#include <string>
#include <cstdlib>
#include <log/log.hpp>

namespace purefs::fs::drivers
{
    namespace
    {
        inline auto mount_path_mod(std::string_view path)
        {
            std::string ret{path};
            if (ret.back() != '/') {
                ret.push_back('/');
            }
            return ret;
        }
    } // namespace

    mount_point_ext4::mount_point_ext4(std::shared_ptr<blkdev::internal::disk_handle> diskh,
                                       std::string_view path,
                                       unsigned flags,
                                       std::shared_ptr<filesystem_operations> fs)
        : mount_point(diskh, mount_path_mod(path), flags, fs), m_root(mount_path_mod(path)),
          m_lock(std::make_unique<cpp_freertos::MutexRecursive>())
    {}

    mount_point_ext4::~mount_point_ext4()
    {}

    auto mount_point_ext4::lock() noexcept -> void
    {
        m_lock->Lock();
    }

    auto mount_point_ext4::unlock() noexcept -> void
    {
        m_lock->Unlock();
    }

    ext4_locker::ext4_locker(std::shared_ptr<mount_point_ext4> mnt_ext) : m_mnt_ext(mnt_ext)
    {
        mnt_ext->lock();
    }

    ext4_locker::~ext4_locker()
    {
        auto ptr = m_mnt_ext.lock();
        if (ptr) {
            ptr->unlock();
        }
        else {
            LOG_FATAL("Unable to unlock ext4 filesystem");
            std::abort();
        }
    }

} // namespace purefs::fs::drivers