blob: 0e30e2266f38612131879b87bf57ba1a69210701 (
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
|
#ifndef TEACHOS_KERNEL_FILESYSTEM_DEVICE_NUMBER_REGISTRY_HPP
#define TEACHOS_KERNEL_FILESYSTEM_DEVICE_NUMBER_REGISTRY_HPP
#include <kernel/filesystem/file_type.hpp>
#include <kapi/devices.hpp>
#include <kapi/filesystem.hpp>
#include <kstd/memory.hpp>
#include <kstd/result.hpp>
#include <kstd/string.hpp>
#include <kstd/vector.hpp>
namespace kernel::filesystem
{
struct device_number_registry
{
//! A single numbered device.
//!
//! Theses entries are used, for example, in devfs to provide access to devices.
struct entry
{
kapi::filesystem::device_number number;
file_type type;
kstd::string name;
kstd::weak_ptr<kapi::devices::device> device;
};
explicit device_number_registry(kapi::devices::interface_registry & interface_registry);
//! Get the system global instance of the registry.
[[nodiscard]] auto static get() -> device_number_registry &;
//! Resolve a device number and file type to a device.
//!
//! @param number The device number.
//! @param type The expected file type of the device.
//! @return A device if a fitting entry is found, an error otherwise.
[[nodiscard]] auto resolve(kapi::filesystem::device_number number, file_type type) const
-> kstd::result<kstd::shared_ptr<kapi::devices::device>>;
//! Resolve a device to it's device number.
//!
//! @param device The device to find the number for.
//! @return The device number associated with the given device, or an error otherwise.
[[nodiscard]] auto number_of(kapi::devices::device const & device) const
-> kstd::result<kapi::filesystem::device_number>;
//! Get all currently registered devices.
//!
//! @return A range containing all currently registered devices numbers mappings.
[[nodiscard]] auto all() const -> kstd::vector<entry>;
private:
auto populate() const -> void;
kstd::observer_ptr<kapi::devices::interface_registry> m_interface_registry;
mutable kstd::vector<entry> m_entries{};
};
} // namespace kernel::filesystem
#endif
|