diff options
author | Liav A <liavalb@gmail.com> | 2021-08-14 11:40:37 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-08 00:42:20 +0200 |
commit | 6a9c717a301c16b60e80ecd55b19909418561b5b (patch) | |
tree | 19a8fc87b583bd4e96a2acf239ae6d358a1ac4c1 /Kernel/Devices/Device.h | |
parent | 009feefee0dc45af2a38b0c6c9f6963ddda5468d (diff) | |
download | serenity-6a9c717a301c16b60e80ecd55b19909418561b5b.zip |
Kernel: Expose device presence in /sys/dev/char and /sys/dev/block
These files are not marked as block devices or character devices so they
are not meant to be used as device nodes. The filenames are formatted to
the pattern "major:minor", but a Userland program need to call the parse
these format and inspect the the major and minor numbers and create the
real device nodes in /dev.
Later on, it might be a good idea to ensure we don't create new
SysFSComponents on the heap for each Device, but rather generate
them only when required (and preferably to not create a SysFSComponent
at all if possible).
Diffstat (limited to 'Kernel/Devices/Device.h')
-rw-r--r-- | Kernel/Devices/Device.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Kernel/Devices/Device.h b/Kernel/Devices/Device.h index fcd503e1f6..cc1fc51827 100644 --- a/Kernel/Devices/Device.h +++ b/Kernel/Devices/Device.h @@ -17,15 +17,22 @@ #include <AK/DoublyLinkedList.h> #include <AK/Function.h> #include <AK/HashMap.h> +#include <AK/RefPtr.h> #include <Kernel/Devices/AsyncDeviceRequest.h> #include <Kernel/FileSystem/File.h> -#include <Kernel/FileSystem/SysFSComponent.h> +#include <Kernel/FileSystem/SysFS.h> #include <Kernel/Locking/Mutex.h> #include <Kernel/UnixTypes.h> namespace Kernel { class Device : public File { +protected: + enum class State { + Normal, + BeingRemoved, + }; + public: virtual ~Device() override; @@ -39,6 +46,7 @@ public: GroupID gid() const { return m_gid; } virtual bool is_device() const override { return true; } + virtual void before_removing(); static void for_each(Function<void(Device&)>); static Device* get_device(unsigned major, unsigned minor); @@ -70,8 +78,11 @@ private: UserID m_uid { 0 }; GroupID m_gid { 0 }; + State m_state { State::Normal }; + Spinlock m_requests_lock; DoublyLinkedList<RefPtr<AsyncDeviceRequest>> m_requests; + WeakPtr<SysFSDeviceComponent> m_sysfs_component; }; } |