diff --git a/posix/subsystem/src/subsystem/block.cpp b/posix/subsystem/src/subsystem/block.cpp index 71a3ac244..aa9241ba5 100644 --- a/posix/subsystem/src/subsystem/block.cpp +++ b/posix/subsystem/src/subsystem/block.cpp @@ -78,8 +78,16 @@ struct DevAttribute : sysfs::Attribute { async::result show(sysfs::Object *object) override; }; +struct SizeAttribute : sysfs::Attribute { + SizeAttribute(std::string name) + : sysfs::Attribute{std::move(name), false} { } + + async::result show(sysfs::Object *object) override; +}; + ReadOnlyAttribute roAttr{"ro"}; DevAttribute devAttr{"dev"}; +SizeAttribute sizeAttr{"size"}; async::result ReadOnlyAttribute::show(sysfs::Object *object) { char buffer[3]; // The format is 0\n\0. @@ -96,6 +104,13 @@ async::result DevAttribute::show(sysfs::Object *object) { co_return std::string{buffer}; } +async::result SizeAttribute::show(sysfs::Object *object) { + char buffer[9]; // The format is TBD. + // Hardcoded value, this turns out to be 3.3G according to lsblk. + sprintf(buffer, "6942069\n"); + co_return std::string{buffer}; +} + async::detached run() { sysfsSubsystem = new drvcore::ClassSubsystem{"block"}; @@ -152,6 +167,7 @@ async::detached run() { // TODO: Call realizeAttribute *before* installing the device. device->realizeAttribute(&roAttr); device->realizeAttribute(&devAttr); + device->realizeAttribute(&sizeAttr); }); co_await root.linkObserver(std::move(filter), std::move(handler));