summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/UnveilNode.h
blob: 69d41792394565d3507890326717708464ccd27a (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
/*
 * Copyright (c) 2020, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Trie.h>
#include <Kernel/KString.h>

namespace Kernel {

enum UnveilAccess {
    Read = 1,
    Write = 2,
    Execute = 4,
    CreateOrRemove = 8,
    Browse = 16,

    None = 0,
};

struct UnveilNode;

struct UnveilMetadata {
    NonnullOwnPtr<KString> full_path;
    UnveilAccess permissions { None };
    bool explicitly_unveiled { false };

    UnveilMetadata(UnveilMetadata const&) = delete;
    UnveilMetadata(UnveilMetadata&&) = default;

    // Note: Intentionally not explicit.
    UnveilMetadata(NonnullOwnPtr<KString>&& full_path, UnveilAccess permissions = None, bool explicitly_unveiled = false)
        : full_path(move(full_path))
        , permissions(permissions)
        , explicitly_unveiled(explicitly_unveiled)
    {
    }

    ErrorOr<UnveilMetadata> copy() const
    {
        return UnveilMetadata {
            TRY(full_path->try_clone()),
            permissions,
            explicitly_unveiled,
        };
    }
};

struct UnveilNode final : public Trie<NonnullOwnPtr<KString>, UnveilMetadata, Traits<NonnullOwnPtr<KString>>, UnveilNode> {
    using Trie<NonnullOwnPtr<KString>, UnveilMetadata, Traits<NonnullOwnPtr<KString>>, UnveilNode>::Trie;

    bool was_explicitly_unveiled() const { return this->metadata_value().explicitly_unveiled; }
    UnveilAccess permissions() const { return this->metadata_value().permissions; }
    StringView path() const { return this->metadata_value().full_path->view(); }
};

}