LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-01-2004, 05:51 AM   #1
hiker04
LQ Newbie
 
Registered: Oct 2004
Posts: 6

Rep: Reputation: 0
Lightbulb make proc node in kernel 2.6


I created a simple module for kernel 2.4 where I use
procnode = proc_mknod( nodename, mode, NULL, (dev_t)dev );
This is not available anmore in kernel 2.6

Does anyone know which function replaces this?

Same for MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT

H.
 
Old 10-02-2004, 07:30 AM   #2
psisquare
Member
 
Registered: Sep 2004
Location: Germany
Distribution: Gentoo
Posts: 164

Rep: Reputation: 31
the new function is
struct proc_dir_entry *create_proc_entry(char *name, mode_t mode, struct proc_dir_entry *parent)
see llinux/proc_fs.h

USE_COUNT is now managed by the kernel. set .owner = THIS_MODULE in your struct file_operations to use it.
 
Old 10-04-2004, 11:11 AM   #3
hiker04
LQ Newbie
 
Registered: Oct 2004
Posts: 6

Original Poster
Rep: Reputation: 0
thanks a lot. this helped.
especially the hint for THIS_MODULE
create_proc_entry did not work for me in kernel 2.4 but now it is exactly what I need.
 
Old 10-05-2004, 04:57 AM   #4
hiker04
LQ Newbie
 
Registered: Oct 2004
Posts: 6

Original Poster
Rep: Reputation: 0
unfortunately I was too fast with my reply. create_proc_entry does not work as expected. The major and minor numbers are shown as 0, 0. In /proc/devices the major number is set to 254. But the ioctl() returns ENOTTY.

If I create an entry with (i.e) "mknod /dev/mymodule c 254 10" it works as expected. I can do the ioctl() from my test program.

Is there any function that can be used from the module to create a char device entry in /dev?? I tried mknod(2) and sysmknod. The linker doesn't know them.

Any help appreciated.
H.

Here is some piece of code:

static int mymodule_major;
static struct input_dev mymodule_input_dev;
static struct proc_dir_entry *mymodule_procdirentry;

static struct file_operations mymodule_fops =
{
#ifdef THIS_MODULE
owner: THIS_MODULE,
#endif /*| THIS_MODULE |*/
open: mymodule_open,
read: mymodule_read,
ioctl: mymodule_ioctl,
release: mymodule_release,
};

static int mymodule_ioctl(struct inode *ip, struct file *mymodule_fp, unsigned int cmd, unsigned long key)
{
switch (cmd)
{
case MYMODULE_KEYPRESS:
input_report_key(&mymodule_input_dev, key, 1);
break;
case MYMODULE_KEYRELEASE:
input_report_key(&mymodule_input_dev, key, 0);
break;
};
return 0;
}


static int __init mymodule_init(void)
{
mode_t mode;
int loop;

register_chrdev ( 0,"mymodule", &mymodule_fops);
mode = S_IFCHR | 0666;
mymodule_procdirentry = create_proc_entry( "mymodule", mode, NULL );
mymodule_input_dev.evbit[0] = BIT(EV_KEY);
for ( loop = KEY_ESC; loop <= KEY_CLOSE; loop++ )
{
/*| KEY_ESC = 1 -- KEY_CLOSE = 206 -- from input.h |*/
set_bit( loop, mymodule_input_dev.keybit);
};
input_register_device( &mymodule_input_dev );
return 0;
}

static void __exit mymodule_cleanup(void)
{
remove_proc_entry ( "mymodule", NULL);
unregister_chrdev(mymodule_major, "mymodule");
input_unregister_device ( &mymodule_input_dev );
}

module_init(mymodule_init);
module_exit(mymodule_cleanup);
 
Old 10-06-2004, 07:56 AM   #5
psisquare
Member
 
Registered: Sep 2004
Location: Germany
Distribution: Gentoo
Posts: 164

Rep: Reputation: 31
unfortunately, i'm not an expert kernel hacker myself. i just picked some things up from an article series in a magazine ...
you might want to have a look at

http://lwn.net/Articles/driver-porting/

as to the creation of the device file: that should be done from user-space (by the admin, that is). you could use devfs, but that's deprecated in favor of udev.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
making sense of /proc for 2.4.x kernel? thanhvn Linux - General 2 11-16-2005 08:19 PM
is /proc/pci kernel dependent? shanenin Linux - Hardware 2 01-23-2005 04:40 PM
AM XP-M proc and kernel? Jaster Debian 6 11-17-2004 07:58 PM
Hypertherad Kernel 2.5.75 and your /proc/cpuinfo Kayaker Slackware 2 09-16-2003 09:11 PM
DHCP works but node won't DL kernel tasadar Linux - Networking 1 08-20-2003 01:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration