Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-22-2013, 04:32 AM   #1
LQ Newbie
Registered: Sep 2012
Posts: 10

Rep: Reputation: Disabled
Regarding how the parameters to the read function is passed in simple char driver

Hi everyone,

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"
, (int)*possition
, (unsigned int)count );

if( *possition >= g_s_Hello_World_size )
return 0;

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 )
return -EFAULT;

*possition += count;
return 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
Attached Files
File Type: txt simple_driver.txt (3.4 KB, 11 views)
Old 03-22-2013, 11:00 AM   #2
Registered: Mar 2013
Posts: 33

Rep: Reputation: Disabled
cat /dev/simple_driver

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.
Old 03-23-2013, 09:40 AM   #3
LQ Newbie
Registered: Sep 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Regarding simple char driver

Hi ,

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
Old 03-24-2013, 09:57 AM   #4
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.

--- rod.


drivers, read

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
CHAR driver's open function issue barunparichha Linux - Software 3 02-18-2013 11:32 PM
Problem with char driver write function - infinite loop Cherubim Linux - Kernel 1 10-13-2009 01:08 AM
can't read from the device driver using read() function. parthi_s Linux - Newbie 1 03-23-2009 06:16 AM
how to test a simple char driver in FC5? agpperera Linux - Newbie 2 10-17-2007 01:16 AM
Can parameters passed to a php be hide ? cjagdish69 Linux - Software 1 11-11-2003 07:09 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:14 AM.

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