Latest LQ Deal: Linux Power User Bundle
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 11-10-2004, 02:07 AM   #1
Registered: Jun 2003
Posts: 32

Rep: Reputation: 15
Character Device kernel(2.4.18) - module problem

Hi everybody,
I am facing some problem in writing a character device driver under linux. Its open function is not called whenever I am openning the device from the user space. My driver registers the device in the init_module function as

if ((test_major = register_chrdev(0, "test", &test_fops))
== -EBUSY) {
printk("unable to get major for test device\n");
return -EIO;

printk("<4> Device is registered ");

test_fops structure looks like as follows
struct file_operations test_fops = {
open : open_test,
release : release_test,
ioctl : test_ioctl,

now in open_test function
static int open_test(struct inode *i, struct file *f) {
printk("<4> The /dev/test is opened \n");
return 0;

I am calling open("/dev/test", O_RDONLY, 0666);

Now when I am inserting the module using insmod dmesg output shows "Device is registered" but when I call open it is not prinitng "device is opened". ls /dev/test shows there is a device present and when I close the test program lsmod shows the module with count as -1.

I would be grateful if anybody can point out what I am doing wrong?
Old 11-10-2004, 10:53 PM   #2
Registered: May 2004
Distribution: Gentoo, Debian, OpenBSD, NetBSD
Posts: 158

Rep: Reputation: 16
I remember long ago having trouble with this. As I recall the struct file_operations had to be synced up with the kernel version carefully.. the order was important and exactly what the functions returned was also important. I remember having just a comma seperated list with NULLs for the things I didn't want to do. But maybe its different now. I would look into the kernel source of your kernel for the struct file_operations structure and yada yada, and make sure your stuff matches up.
Old 11-11-2004, 03:52 AM   #3
Registered: Jun 2003
Posts: 32

Original Poster
Rep: Reputation: 15
The problem is resolved, may be it is with the open call. Using the open with two parameters only solved the problem. In case of file_operations structure I started with NULL stuffs for the functions that I don't want to include but later after seeing some drivers code and definition in linux/fs.h I found out it would be better to go with the syntex of the function pointer name and then the actual function name.



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
C++ or pure C for Linux kernel module, Linux device driver development. What to use? Igor007 Programming 91 07-19-2014 11:55 AM
Problem installing module in Fedora Core 2 (2.6 kernel vs 2.4 problem?) Arodef Linux - Kernel 3 11-30-2007 02:55 PM
Problem in inserting a device driver module rajesh_b Programming 5 05-10-2007 12:20 AM
problem in kernel module cranium2004 Programming 1 04-14-2005 03:10 AM
How to change character device file name? taphos Linux - General 2 03-28-2004 08:12 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:02 PM.

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