You must realize that by implementing a sysfs file, you are trying to behave like a file.
Let's see this from the other side first. From the man page of fwrite(3)
:
RETURN VALUE
fread() and fwrite() return the number of items successfully read or written (i.e., not the number of characters). If an error occurs, or the end-of-file is
reached, the return value is a short item count (or zero).
And even better, from the man page of write(2)
:
The number of bytes written may be less than count if, for example, there is insufficient space on the underlying physical medium, or the RLIMIT_FSIZE resource
limit is encountered (see setrlimit(2)), or the call was interrupted by a signal handler after having written less than count bytes. (See also pipe(7).)
What this means is that store()
, which is implementing the other end of the write(2)
function for your particular file should return the number of bytes written (i.e. read by you), in the very least so that write(2)
can return that value to the user.
In most cases, if there is no error in the input, you would just want to return count
to acknowledge that you have read everything and all is ok.