* reading /proc files larger than one buffer
@ 2002-09-28 20:10 Don Cohen
2002-09-28 20:31 ` Jeff Garzik
0 siblings, 1 reply; 3+ messages in thread
From: Don Cohen @ 2002-09-28 20:10 UTC (permalink / raw)
To: linux-kernel
If you follow the directions in Documentation/DocBook/procfs-guide.tmpl
then your file read will not work correctly unless the whole file is
read in one call.
After examining (and experimenting with) fs/proc/generic.c I now see
what you have to do: in addition to writing bytes in the page
parameter, setting eof as appropriate and returning the number of
bytes written, you also need to do:
*start = page;
At minimum the documentation should be corrected.
Actually I think this is a bug in proc_file_read.
The problem seems to be in this code, executed after the read function:
if (!start) {
/*
* For proc files that are less than 4k
*/
start = page + *ppos;
n -= *ppos;
if (n <= 0)
break;
if (n > count)
n = count;
}
Can anyone explain what it's supposed to do?
What does it have to do with files < 4k ?
The addition of "*start = page;" both sets start to the correct value
and avoids executing the problematic code above.
[Note: The "start" in your read function is actually the address of
the "start" in proc_file_read.]
Therefore I think that code should be
if (!start) start=page;
The current code normally works for the first read because *ppos is 0.
Otherwise:
- start is given the wrong value (should be page)
- n is the number of bytes read, and it makes no sense to reduce that
by ppos, which is the file position at which you were supposed to
start reading.
The behavior I saw was that on the second buffer count and ppos were
both 512 (asked to read bytes 512-1023). My function returned 512,
so n was set to 0, which was then interpreted as eof.
Please cc me on replies.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: reading /proc files larger than one buffer
2002-09-28 20:10 reading /proc files larger than one buffer Don Cohen
@ 2002-09-28 20:31 ` Jeff Garzik
2002-09-28 21:05 ` Don Cohen
0 siblings, 1 reply; 3+ messages in thread
From: Jeff Garzik @ 2002-09-28 20:31 UTC (permalink / raw)
To: Don Cohen; +Cc: linux-kernel
Don Cohen wrote:
> If you follow the directions in Documentation/DocBook/procfs-guide.tmpl
> then your file read will not work correctly unless the whole file is
> read in one call.
>
> After examining (and experimenting with) fs/proc/generic.c I now see
> what you have to do: in addition to writing bytes in the page
> parameter, setting eof as appropriate and returning the number of
> bytes written, you also need to do:
> *start = page;
> At minimum the documentation should be corrected.
There is a new seq_xxx API that covers this quite well... the
documentation should be updated to include that, especially. seq_xxx
should take care of a large number of complex or potentially-large
procfs output.
Any change you would be interested in updating the docs? ;-)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: reading /proc files larger than one buffer
2002-09-28 20:31 ` Jeff Garzik
@ 2002-09-28 21:05 ` Don Cohen
0 siblings, 0 replies; 3+ messages in thread
From: Don Cohen @ 2002-09-28 21:05 UTC (permalink / raw)
To: Jeff Garzik; +Cc: linux-kernel
> There is a new seq_xxx API that covers this quite well... the
Where can I find code or doc for this?
> documentation should be updated to include that, especially. seq_xxx
> should take care of a large number of complex or potentially-large
> procfs output.
>
> Any change you would be interested in updating the docs? ;-)
(you mean chance?)
I'd prefer to have the code updated so the current doc is correct.
However, if updating doc is much easier or faster then I suggest
adding that one line as something else you should do in your read
function.
BTW there were other things I found confusing about that doc, and I'd
be happy to suggest other improvements to someone who can make them.
Wouldn't it be better, though, for the people who write the code to
write doc instead of someone like me who is only trying to hallucinate
intent from the code? I'd be much happier to review doc written by
the author of the code.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-09-28 20:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-28 20:10 reading /proc files larger than one buffer Don Cohen
2002-09-28 20:31 ` Jeff Garzik
2002-09-28 21:05 ` Don Cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox