The read function is a call back function that allows userland processes to read data from the kernel. The read function should have the following format:
int read_func( | char* | page, |
| char** | start, | |
| off_t | off, | |
| int | count, | |
| int* | eof, | |
| void* | data); |
The read function should write its information into the
page. For proper use, the function
should start writing at an offset of
off in page and
write at most count bytes, but because
most read functions are quite simple and only return a small
amount of information, these two parameters are usually
ignored (it breaks pagers like more and
less, but cat still
works).
If the off and
count parameters are properly used,
eof should be used to signal that the
end of the file has been reached by writing
1 to the memory location
eof points to.
The parameter start doesn't seem to be
used anywhere in the kernel. The data
parameter can be used to create a single call back function for
several files, see the section called “A single call back for many files”.
The read_func function must return the
number of bytes written into the page.
Chapter 5, Example shows how to use a read call back function.