From f25752accbd9f9c39fc5ef3253be6a6050dd903b Mon Sep 17 00:00:00 2001 From: Dennis Bonke Date: Tue, 24 Oct 2023 00:10:36 +0200 Subject: [PATCH] posix/block: Expose major:minor for block devices in sysfs --- posix/subsystem/src/subsystem/block.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/posix/subsystem/src/subsystem/block.cpp b/posix/subsystem/src/subsystem/block.cpp index ac629bb5b..82b075ab5 100644 --- a/posix/subsystem/src/subsystem/block.cpp +++ b/posix/subsystem/src/subsystem/block.cpp @@ -68,7 +68,15 @@ struct ReadOnlyAttribute : sysfs::Attribute { async::result show(sysfs::Object *object) override; }; +struct DevAttribute : sysfs::Attribute { + DevAttribute(std::string name) + : sysfs::Attribute{std::move(name), false} { } + + async::result show(sysfs::Object *object) override; +}; + ReadOnlyAttribute roAttr{"ro"}; +DevAttribute devAttr{"dev"}; async::result ReadOnlyAttribute::show(sysfs::Object *object) { char buffer[3]; // The format is 0\n\0. @@ -77,6 +85,14 @@ async::result ReadOnlyAttribute::show(sysfs::Object *object) { co_return std::string{buffer}; } +async::result DevAttribute::show(sysfs::Object *object) { + char buffer[5]; // The format is 0:0\n\0. + auto device = static_cast(object); + auto dev = device->getId(); + sprintf(buffer, "%d:%d\n", dev.first, dev.second); + co_return std::string{buffer}; +} + async::detached run() { sysfsSubsystem = new drvcore::ClassSubsystem{"block"}; @@ -132,6 +148,7 @@ async::detached run() { // TODO: Call realizeAttribute *before* installing the device. device->realizeAttribute(&roAttr); + device->realizeAttribute(&devAttr); }); co_await root.linkObserver(std::move(filter), std::move(handler));