blob: b64c3702f26fb17c2d995364211f01641480ceff (
plain)
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
83
84
|
#include <kernel/filesystem/mount.hpp>
#include <kernel/filesystem/dentry.hpp>
#include <kernel/filesystem/filesystem.hpp>
#include <kapi/system.hpp>
#include <kstd/memory>
#include <kstd/string>
#include <cstddef>
#include <string_view>
namespace kernel::filesystem
{
mount::mount(kstd::shared_ptr<dentry> const & mount_dentry, kstd::shared_ptr<dentry> const & root_dentry,
kstd::shared_ptr<filesystem> const & fs, kstd::shared_ptr<mount> const & parent_mount)
: m_mount_dentry(mount_dentry)
, m_root_dentry(root_dentry)
, m_filesystem(fs)
, m_parent_mount(parent_mount)
, m_ref_count(0)
{
if (!m_filesystem)
{
kapi::system::panic("[FILESYSTEM] mount initialized with null filesystem.");
}
}
auto mount::mount_dentry() const -> kstd::shared_ptr<dentry> const &
{
return m_mount_dentry;
}
auto mount::get_filesystem() const -> kstd::shared_ptr<filesystem> const &
{
return m_filesystem;
}
auto mount::root_dentry() const -> kstd::shared_ptr<dentry> const &
{
return m_root_dentry;
}
auto mount::mount_path() const -> kstd::string
{
if (m_mount_dentry)
{
return m_mount_dentry->absolute_path();
}
return "/";
}
auto mount::parent_mount() const -> kstd::shared_ptr<mount> const &
{
return m_parent_mount;
}
auto mount::increment_ref_count() -> void
{
m_ref_count += 1;
}
auto mount::decrement_ref_count() -> bool
{
if (m_ref_count == 0)
{
return false;
}
m_ref_count -= 1;
return true;
}
auto mount::is_ready_to_unmount() const -> bool
{
return m_ref_count == 0;
}
auto mount::ref_count() const -> size_t
{
return m_ref_count;
}
} // namespace kernel::filesystem
|