blob: 2f99e915165166eb7cdb1b01c394cfbe6a7b7f23 (
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
|
#include "kernel/filesystem/dentry.hpp"
#include "kapi/system.hpp"
#include "kernel/filesystem/inode.hpp"
#include <kstd/memory>
#include <algorithm>
#include <cstdint>
#include <string_view>
namespace kernel::filesystem
{
dentry::dentry(kstd::shared_ptr<dentry> const & parent, kstd::shared_ptr<inode> const & node, std::string_view name)
: m_name(name)
, m_parent(parent)
, m_inode(node)
{
if (!m_inode)
{
kapi::system::panic("[FILESYSTEM] dentry constructed with null inode.");
}
}
auto dentry::get_inode() const -> kstd::shared_ptr<inode> const &
{
return m_inode;
}
auto dentry::get_parent() const -> kstd::shared_ptr<dentry> const &
{
return m_parent;
}
auto dentry::add_child(kstd::shared_ptr<dentry> const & child) -> void
{
m_children.push_back(child);
}
auto dentry::find_child(std::string_view name) const -> kstd::shared_ptr<dentry>
{
auto it = std::ranges::find_if(m_children, [&](auto const & child) { return child->m_name == name; });
return (it != m_children.end()) ? *it : nullptr;
}
auto dentry::set_flag(dentry_flags flag) -> void
{
m_flags |= static_cast<uint32_t>(flag);
}
auto dentry::unset_flag(dentry_flags flag) -> void
{
m_flags &= ~static_cast<uint32_t>(flag);
}
auto dentry::has_flag(dentry_flags flag) const -> bool
{
return (m_flags & static_cast<uint32_t>(flag)) != 0;
}
} // namespace kernel::filesystem
|