~aleteoryx/muditaos

ref: b83605d227599dd29c9d16a552a95f281c28aae4 muditaos/module-vfs/include/user/purefs/fs/mount_point.hpp -rw-r--r-- 2.3 KiB
b83605d2 — Lucjan Bryndza [EGD-7573] Add support for reliance edge fs 4 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once
#include <memory>
#include <string>
#include <iostream>
#include <purefs/fs/mount_flags.hpp>

namespace purefs::blkdev::internal
{
    class disk_handle;
}

namespace purefs::fs
{
    class filesystem_operations;
}

namespace purefs::fs::internal
{
    //! Mount point disk private structure
    class mount_point
    {
      public:
        mount_point(std::shared_ptr<blkdev::internal::disk_handle> diskh,
                    std::string_view path,
                    unsigned flags,
                    std::shared_ptr<filesystem_operations> fs)
            : m_diskh(diskh), m_path(path), m_fs(fs), m_flags(flags)
        {}
        mount_point(const mount_point &) = delete;
        auto operator=(const mount_point &) = delete;
        virtual ~mount_point()              = default;
        auto disk() const noexcept
        {
            return m_diskh.lock();
        }
        auto mount_path() const noexcept
        {
            return m_path;
        }
        auto fs_ops() const noexcept
        {
            return m_fs.lock();
        }
        auto flags() const noexcept -> unsigned
        {
            return m_flags;
        }
        auto is_ro() const noexcept -> bool
        {
            return (m_flags & mount_flags::read_only) == mount_flags::read_only;
        }
        void modify_flags(unsigned flags) noexcept
        {
            m_flags = flags;
        }
        auto native_path(std::string_view full_path) const noexcept -> std::string
        {
            const auto n1 = full_path.find(m_path);
            if (n1 == 0) {
                auto ret = std::string(native_root()).append(full_path.substr(m_path.size()));
                if (ret.empty())
                    ret.append("/");
                return ret;
            }
            else {
                return {};
            }
        }

      private:
        virtual auto native_root() const noexcept -> std::string = 0;

      private:
        const std::weak_ptr<blkdev::internal::disk_handle> m_diskh;
        const std::string m_path;                        //! Mounted path
        const std::weak_ptr<filesystem_operations> m_fs; //! Filesystem operation
        volatile unsigned m_flags;
    };
} // namespace purefs::fs::internal