Skip to content

Commit

Permalink
posix/block: Expose a placeholder size of a block device over sysfs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke committed Oct 23, 2023
1 parent f25752a commit 2c442b2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions posix/subsystem/src/subsystem/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,16 @@ struct DevAttribute : sysfs::Attribute {
async::result<std::string> show(sysfs::Object *object) override;
};

struct SizeAttribute : sysfs::Attribute {
SizeAttribute(std::string name)
: sysfs::Attribute{std::move(name), false} { }

async::result<std::string> show(sysfs::Object *object) override;
};

ReadOnlyAttribute roAttr{"ro"};
DevAttribute devAttr{"dev"};
SizeAttribute sizeAttr{"size"};

async::result<std::string> ReadOnlyAttribute::show(sysfs::Object *object) {
char buffer[3]; // The format is 0\n\0.
Expand All @@ -93,6 +101,13 @@ async::result<std::string> DevAttribute::show(sysfs::Object *object) {
co_return std::string{buffer};
}

async::result<std::string> 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"};

Expand Down Expand Up @@ -149,6 +164,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));
Expand Down

0 comments on commit 2c442b2

Please sign in to comment.