Skip to content

Sysfs Attributes

Purpose

Sysfs exposes device configuration and status as text-based files under /sys.

Common Callback Pattern

static ssize_t value_show(struct device *dev,
                          struct device_attribute *attr,
                          char *buf)
{
    return sysfs_emit(buf, "%d\n", value);
}

static ssize_t value_store(struct device *dev,
                           struct device_attribute *attr,
                           const char *buf,
                           size_t count)
{
    return count;
}

Good Use Cases

Use Case Suitable for sysfs?
Simple status value Yes
Simple configuration value Yes
Streaming data No
Complex binary command Usually no

Common Pitfalls

Warning

Sysfs files should expose one value or one logical setting per file.

Warning

Sysfs is not intended for high-rate event streaming.