Are you developing a simple kernel module? If your module need just one device file under /dev directory, try to use miscdevice.h to develop it.
With miscdevice you don't need worry about MAJOR numbers, you register a new device and the kernel assign only a MINOR number to it. The major points to misc driver, that uses the minor number as index to points to your module.
Take a look:
------8<------- cut here ---------8<-----------------------
#include <linux/init.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kdev_t.h>
#include <linux/miscdevice.h>
#include <linux/fs.h>
MODULE_LICENSE("GPL");
static int trymisc_read(struct file *file, char __user *buf,
size_t count, loff_t *pos)
{
// your read functions goes here
return 0;
}
// a operation as example
static const struct file_operations trymisc_fops = {
.owner = THIS_MODULE,
.read = trymisc_read,
};
static struct miscdevice trymisc_dev = {
MISC_DYNAMIC_MINOR,
"trymisc",
&trymisc_fops,
};
static int trymisc_init(void){
int ret;
ret = misc_register(&trymisc_dev); if (ret < 0) {
printk(KERN_ALERT "Problem registering device\n");
return 2;
}
return 0;
}
static void trymisc_exit(void){
misc_deregister(&trymisc_dev);}
module_init(trymisc_init);
module_exit(trymisc_exit);
------8<------- and here ---------8<-----------------------
Compile and load module:
root@slackware-note:/usr/src/linux/drive
rs/misc# insmod ./trymisc.ko
root@slackware-note:/usr/src/linux/drive
rs/misc# lsmod
Module Size Used by
trymisc 1664 0
root@slackware-note:/usr/src/linux/drive
rs/misc# ls -la /dev/trymisc
crw-rw---- 1 root root
10, 62 2007-11-07 15:51
/dev/trymiscroot@slackware-note:/usr/src/linux/drive
rs/misc# grep 10 /proc/devices
10 miscroot@slackware-note:/usr/src/linux/drive
rs/misc# grep trymisc /proc/misc
62 trymiscroot@slackware-note:/usr/src/linux/drive
rs/misc#
Its very easy and funny. Try yourself.