read_proc help
i have written a module. it will create a proc entry, in that proc entry i have mapped the below read function like.
proc->read_proc=st_read;
st_read
~~~~~~~
unsigned char init_status=0xff; // Declared Globally inside module
int st_read(char *buf,char **start,off_t offset,int count,int *eof,void *data)
{
printk(KERN_ALERT "Read Called \n");
if(offset > 0)
{
*eof = 1;
return 0;
}
return sprintf(buf,"%x\n",init_status);
}
now if i use cat to read the contents of that proc file then i m getting
output
~~~~~~
Read Called
Read Called
Read Called
ffffff
i want to read the init_status variable as ff only. but i dont know why the st_read function called thrice and printing ffffff.
I m confused please help me in this regards
|