Linux Kernel Driver Program:
3_Statically_Allocating_Major_Number
neelkanth_surekha#cat hello_world_module.c
#include<linux/kernel.h>#include<linux/init.h>
#include<linux/module.h>
#include <linux/fs.h>
dev_t dev = MKDEV(235, 0);
static int __init hello_world_init(void)
{
/* register_chrdev_region — register a range of device numbers */
/* SYNTAX
* int register_chrdev_region (dev_t from, unsigned count, const char *name);
*/
register_chrdev_region(dev, 1, "Neelkanth");
printk(KERN_INFO "Major = %d Minor = %d \n",MAJOR(dev), MINOR(dev));
printk(KERN_INFO "Kernel Module Inserted Successfully...\n");
return 0;
}
void __exit hello_world_exit(void)
{
unregister_chrdev_region(dev, 1);
printk(KERN_INFO "Kernel Module Removed Successfully...\n");
}
module_init(hello_world_init);
module_exit(hello_world_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Neelkanth <www.neelkanth.13@gmail.com>");
MODULE_DESCRIPTION("A simple hello world driver");
MODULE_VERSION("1.0");
neelkanth_surekha#cat Makefile
obj-m += hello_world_module.oKDIR = /lib/modules/$(shell uname -r)/build
all:
make -C $(KDIR) M=$(shell pwd) modules
clean:
make -C $(KDIR) M=$(shell pwd) clean