How to deal with multiple read in function int (read_proc_t) (...)
From: derek chen (u8526505_at_ms27.hinet.net)
Date: 11/19/04
- Next message: Rigo: "set_64bit"
- Previous message: Norm Dresner: "Re: Signal generation on parallel port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 19 Nov 2004 07:12:18 -0800
If I implement my proc_read as below
static int proc_read(char *page, char **start,
off_t off, int count,
int *eof, void *data)
{
int len = 0;
if (count < 5) *eof=1;
else
len += sprintf(page + len,"12345");
return len + off;
}
and call read(fd,buf,13) once from a user space program I found my
proc_read will be invoked 3 times with each parameter like this
1st, off = 0 page = c30bb000 start = 0 count = 13 data = 0
2nd, off = 5 page = c30bb000 start = 0 count = 8 data = 0
3rd, off = 10 page = c30bb000 start = 0 count = 3 data = 0
although the total bytes returned is correct the content in my buffer
is wrong.
suppose I should get "1234512345" but I end up with the data "12345" +
5 random characters. Another thing confusing me is that I have to
return len+off to get the correct amount of data (thought the content
is wrong). If I just return len I'll get only 5 bytes.
I guess I did not set the correct value to parameter **start but I
really don't know how to fix it. Could somebody give me a clue?
Thanks.
Derek
- Next message: Rigo: "set_64bit"
- Previous message: Norm Dresner: "Re: Signal generation on parallel port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|