problem in proc_read..
From: Mozis (chokshi.jaydeep_at_gmail.com)
Date: 09/29/05
- Next message: Scott J. McCaughrin: "semantics of pthread locks"
- Previous message: Patrick Klos: "Re: Linux ARP and IP stack internals question"
- Next in thread: Mozis: "Re: problem in proc_read.."
- Reply: Mozis: "Re: problem in proc_read.."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Sep 2005 09:19:16 -0700
In my module I've following function which will be called when user
tries to read from "/proc/sample" file--> which I createed by
create_proc_file() function..
code snippet:
int proc_read(char *buffer,char **buffer_location, off_t offset,
buf_length, int *eof, void
*data)
{
int ret ;
if ( offset > 0) return 0 ;
ret = sprintf(buffer,"helloworld!") ;
return ret ;
}
Now I confused here, correct me up ahead where I'm wrong,
While any function in module being run, it is in kernel mode so all
address are of kernel mode addresses, but here as in 1st argument the
base address of buffer is user mode address same as what we get in as
1st argument is device_read(char* buff,.....) for reading from module.
So we should use "copy_to_user()" function.
So I used this function instead of "sprintf()" , But with surprise I
get some garbage values as the output of " cat /proc/sample". I'm not
getting why.
Now regarding offset please let me know whether is it updated
autometically or do we need to set up it in function? as I guess it
would be updated autometically because in above function it is being
updated, but then in device_read() funtion it not being updated when
user application issues a read() to my module.
Plese helpe me and treat me as "NOVICE".
Thanx.
Mozis.
- Next message: Scott J. McCaughrin: "semantics of pthread locks"
- Previous message: Patrick Klos: "Re: Linux ARP and IP stack internals question"
- Next in thread: Mozis: "Re: problem in proc_read.."
- Reply: Mozis: "Re: problem in proc_read.."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]