2020-12-26 13:24:34 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-12-26 13:24:34 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Trie.h>
|
2022-02-15 21:59:25 +03:00
|
|
|
#include <Kernel/KString.h>
|
2020-12-26 13:24:34 +03:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
enum UnveilAccess {
|
|
|
|
Read = 1,
|
|
|
|
Write = 2,
|
|
|
|
Execute = 4,
|
|
|
|
CreateOrRemove = 8,
|
|
|
|
Browse = 16,
|
|
|
|
|
|
|
|
None = 0,
|
|
|
|
};
|
|
|
|
|
2020-12-26 17:24:01 +03:00
|
|
|
struct UnveilNode;
|
|
|
|
|
2020-12-26 13:24:34 +03:00
|
|
|
struct UnveilMetadata {
|
2022-02-14 16:19:53 +03:00
|
|
|
NonnullOwnPtr<KString> full_path;
|
2020-12-26 13:24:34 +03:00
|
|
|
UnveilAccess permissions { None };
|
|
|
|
bool explicitly_unveiled { false };
|
2022-02-14 16:19:53 +03:00
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
}
|
2020-12-26 13:24:34 +03:00
|
|
|
};
|
|
|
|
|
2022-02-15 21:59:25 +03:00
|
|
|
struct UnveilNode final : public Trie<NonnullOwnPtr<KString>, UnveilMetadata, Traits<NonnullOwnPtr<KString>>, UnveilNode> {
|
|
|
|
using Trie<NonnullOwnPtr<KString>, UnveilMetadata, Traits<NonnullOwnPtr<KString>>, UnveilNode>::Trie;
|
2020-12-26 13:24:34 +03:00
|
|
|
|
|
|
|
bool was_explicitly_unveiled() const { return this->metadata_value().explicitly_unveiled; }
|
|
|
|
UnveilAccess permissions() const { return this->metadata_value().permissions; }
|
2022-02-14 16:19:53 +03:00
|
|
|
StringView path() const { return this->metadata_value().full_path->view(); }
|
2020-12-26 13:24:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|