I am implementing a Linux device driver that can have partial reads and writes. For example, the caller may have requested to read N bytes from the device, but part of the way through an error was encountered and now the driver has M bytes available to pass back to userspace.
How do I report the error back to userspace? For example, I would normally do something like return -EIO;
in the event of an I/O error, but this does not tell the whole story (i.e., the caller might be interested in the fact that there still are M usable bytes).
I'm aware of the fact that setting errno
isn't a thing in kernel space (see here: "'errno' undeclared" when compile Linux kernel), but is there any way that in my scenario I can return M, but also indicate the cause of the short read? How is this generally handled by other device drivers? Do you just return the error code and don't try to indicate that part of the buffer might be usable?