Skip to content

Commit

Permalink
posix/block: Expose major:minor for block devices in sysfs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke committed Oct 23, 2023
1 parent ab5076d commit f25752a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions posix/subsystem/src/subsystem/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ struct ReadOnlyAttribute : sysfs::Attribute {
async::result<std::string> show(sysfs::Object *object) override;
};

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

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

ReadOnlyAttribute roAttr{"ro"};
DevAttribute devAttr{"dev"};

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

async::result<std::string> DevAttribute::show(sysfs::Object *object) {
char buffer[5]; // The format is 0:0\n\0.
auto device = static_cast<Device *>(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"};

Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit f25752a

Please sign in to comment.