From 0f8b45c0150ccb6dc188045886e90a9c31422e4d Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Sun, 18 Aug 2019 14:58:47 +0300 Subject: ProcFS: Expose info about devices in /proc/devices --- Kernel/FileSystem/ProcFS.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'Kernel') 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 procfs$pci(InodeIdentifier) return json.serialized(); } +Optional 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(); +} + Optional 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 }; -- cgit v1.2.3