1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

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).
This commit is contained in:
Liav A 2021-08-14 11:40:37 +03:00 committed by Andreas Kling
parent 009feefee0
commit 6a9c717a30
5 changed files with 183 additions and 2 deletions

View file

@ -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;
};
}