~aleteoryx/muditaos

ref: c13eb5ade997b28b81dd35e916d80756986bb48f muditaos/module-vfs/include/internal/purefs/fs/mount_point.hpp -rw-r--r-- 2.0 KiB
c13eb5ad — Lucjan Bryndza [EGD-4498] Fix vfscore-ut 5 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
// Copyright (c) 2017-2020, 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>

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)
        {}
        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
        {
            return m_flags;
        }
        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_view = 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
        unsigned m_flags;
    };
} // namespace purefs::fs::internal