-   Linux - Software (
-   -   make proc node in kernel 2.6 (

hiker04 10-01-2004 05:51 AM

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?



psisquare 10-02-2004 07:30 AM

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.

hiker04 10-04-2004 11:11 AM

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. :)

hiker04 10-05-2004 04:57 AM

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.

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 =
#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)
input_report_key(&mymodule_input_dev, key, 1);
input_report_key(&mymodule_input_dev, key, 0);
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 );


psisquare 10-06-2004 07:56 AM

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

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.

All times are GMT -5. The time now is 06:52 PM.