Hello,
I have written a kernel module which introduces a new subsystem in
sysfs, and it contains several attributes, one of which is binary. So
far, I've been testing it using text. My problem is, attempting to read
data continues forever. For example:
# echo "test data" > /sys/mystuff/binaryattrib
# cat /sys/mystuff/binaryattrib
test data
test data
test data
test data
test data
test data
test data
test data
test data
test data
test data
test data
.. and so on forever.
Here are the read and write functions for the binary attribute:
'void *input_params' is a pointer to PAGE_SIZE (4096 for me) bytes, and
'size_t input_params_size' contains the actual number of bytes which
were written to input_params by the _write function. input_params_size
is initialized to zero when the module is first loaded.
static ssize_t binaryattrib_read(struct kobject *kobj, char *buf, loff_t
pos,
size_t count) {
if(input_params_size + sizeof(size_t) > count)
return -EINVAL;
memcpy(buf, (void *)&input_params_size, sizeof(size_t));
memcpy(buf+sizeof(size_t), input_params, input_params_size);
return input_params_size + sizeof(size_t);