To handle a sysfs
read I need to create a show
function which is added to a kobj_attribute
structure. The prototype of the function is defined as:
ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
char *buf);
Obviously I need to write data to the buf
parameter, but what is the upper limit of the number of bytes which can be written? Is it defined anywhere?
According to Documentation/filesystems/sysfs.txt (search for "Reading/Writing Attribute Data") the buffer size is one page, or PAGE_SIZE
bytes.
To avoid the warning below, you can effectively only use PAGE_SIZE - 1
bytes though:
if (ret >= (ssize_t)PAGE_SIZE) {
printk("dev_attr_show: %pS returned bad count\n",
dev_attr->show);
}