I’m writing a linux device driver that, among other things, exposes a readonly binary attribute in sysfs, the interface for which is
static ssize_t read_dump_fifo(struct file *filp, struct kobject *kobj, struct bin_attribute *attr, char __user *buffer, loff_t f_pos, size_t size)
When I try to cat
or hexdump
the file, after the first 4096 bytes, my driver will be given a zero-sized read (It is passed 0 for size
). Why is this happening, and how should my driver respond if it’s not logically at EOF? (A response of 0 would indicate EOF, but any longer response seems like it would be inviting some sort of a buffer overflow. Currently, I return -EINVAL
.)
Are sysfs binary attributes allowed to return more than one page of information?
Advertisement
Answer
It turns out I had set the maximum size when registering the attribute to 4096… Oops.