diff options
author | Sergey Bugaev <bugaevc@gmail.com> | 2019-08-18 14:58:47 +0300 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-18 15:59:59 +0200 |
commit | 0f8b45c0150ccb6dc188045886e90a9c31422e4d (patch) | |
tree | 426985c5ce2d74e41ba9c3634f579e473f0654ee /Kernel/FileSystem | |
parent | acccf9ccda13e134c3fb75b78d26c9465aa23510 (diff) | |
download | serenity-0f8b45c0150ccb6dc188045886e90a9c31422e4d.zip |
ProcFS: Expose info about devices in /proc/devices
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/ProcFS.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index d01cc969bc..cc6a1d0f8a 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -47,6 +47,7 @@ enum ProcFileType { FI_Root_inodes, FI_Root_dmesg, FI_Root_pci, + FI_Root_devices, FI_Root_uptime, FI_Root_cmdline, FI_Root_self, // symlink @@ -269,6 +270,27 @@ Optional<KBuffer> procfs$pci(InodeIdentifier) return json.serialized<KBufferBuilder>(); } +Optional<KBuffer> procfs$devices(InodeIdentifier) +{ + JsonArray json; + Device::for_each([&json](auto& device) { + JsonObject obj; + obj.set("major", device.major()); + obj.set("minor", device.minor()); + obj.set("class_name", device.class_name()); + + if (device.is_block_device()) + obj.set("type", "block"); + else if (device.is_character_device()) + obj.set("type", "character"); + else + ASSERT_NOT_REACHED(); + + json.append(move(obj)); + }); + return json.serialized<KBufferBuilder>(); +} + Optional<KBuffer> procfs$uptime(InodeIdentifier) { KBufferBuilder builder; @@ -1198,6 +1220,7 @@ ProcFS::ProcFS() m_entries[FI_Root_dmesg] = { "dmesg", FI_Root_dmesg, procfs$dmesg }; m_entries[FI_Root_self] = { "self", FI_Root_self, procfs$self }; m_entries[FI_Root_pci] = { "pci", FI_Root_pci, procfs$pci }; + m_entries[FI_Root_devices] = { "devices", FI_Root_devices, procfs$devices }; m_entries[FI_Root_uptime] = { "uptime", FI_Root_uptime, procfs$uptime }; m_entries[FI_Root_cmdline] = { "cmdline", FI_Root_cmdline, procfs$cmdline }; m_entries[FI_Root_sys] = { "sys", FI_Root_sys }; |