LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 04-17-2009, 12:48 PM   #1
rheosiva
LQ Newbie
 
Registered: Jan 2008
Location: india
Distribution: Fedora
Posts: 17

Rep: Reputation: 0
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
 
Old 04-30-2009, 11:49 AM   #2
ajerome
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
You need to set [*eof=1;] before returning (outside of the [offset > 0] case).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -5. The time now is 09:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration