Regarding how the parameters to the read function is passed in simple char driver
I am newbei to driver programming i am started writing the simple char driver
which i have attached . Then i created special file for my char driver
mknod /dev/simple-driver c 250 0 .when it type cat /dev/simple-driver. it shows the string "Hello world tamil_vanan!". i know that function
static ssize_t device_file_read(
struct file *file_ptr
, char __user *user_buffer
, size_t count
, loff_t *possition)
printk( KERN_NOTICE "Simple-driver: Device file is read at offset = %i, read bytes count = %u"
, (unsigned int)count );
if( *possition >= g_s_Hello_World_size )
if( *possition + count > g_s_Hello_World_size )
count = g_s_Hello_World_size - *possition;
if( copy_to_user(user_buffer, g_s_Hello_World_string + *possition, count) != 0 )
*possition += count;
is get called . This is mapped to (*read) in file_opreation structure of my driver .My question is how this function is get called , how the parameters like struct file,char,count, offset are passed bcoz is i simply typed cat command ..Please elabroate how this happening
Tamil Vanan K
means you want to print the contents of "/dev/simple_driver", that means you want to read, so your read function is called. it same as
fd = open("/dev/simple_driver");
nr = read(fd, buf, 80);
similarly if you do
echo "write to simple driver" > /dev/simple_driver will call your write function.
Kernel knows this as you specified the name of the device(simple_device) during char device registering in init function.
Regarding simple char driver
Ya thanks for the information. i know the that read and write requested are redirected to driver read ,write functions. but i like to know how its happening and how the read operation in my driver gets all the four parameters.
Tamil Vanan K
You will probably be best served by looking in the kernel sources to find the answer to that. Or ask on a forum or mailing list where the inhabitants deal specifically in kernel internals.
A more general answer is that the kernel maps the device node to your driver when you load your driver. When a userspace system call is made for reading or writing your device, the kernel uses the association it has previously remembered, and dispatches the accordant function in your driver. The cat and echo commands are userspace applications that do read and write system calls, and these result in the calls that you are witnessing. Any application that calls read(), write(), open(), close(), seek(), ioctl(), stat(), etc on a device supported by your driver will cause the respective function in your driver to be invoked.
|All times are GMT -5. The time now is 01:38 AM.|