diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -5,6 +5,7 @@ #include <linux/string.h> /* used for kmalloc */ #include <linux/slab.h> +#include <linux/fs.h> #include <debug.h> @@ -12,6 +13,8 @@ char *debugmsg = "Tesla coil is a hi freq transformer"; struct dentry *debug_dir = NULL; struct dentry *debug_file = NULL; +dev_t devnum; + /* __init is a hint that the func is only used at initialization time, then module * loader drops the function after module is loaded making its memory available for other uses */ @@ -25,6 +28,10 @@ static int __init hello_init(void) printk("%s\n", msg); kfree(msg); + /* device numbers, major will be picked for us */ + err = alloc_chrdev_region(&devnum, 0 /* first minor */, 1, "skull"); + printk("major: %d, minor: %d\n", MAJOR(devnum), MINOR(devnum)); + /* modifies passed in ptrs */ err = debug_init(&debug_dir, &debug_file); if (err) @@ -35,6 +42,7 @@ static int __init hello_init(void) static void __exit hello_exit(void) { + unregister_chrdev_region(devnum, 1); debug_destroy(debug_dir, debug_file); printk("module named hello removed\n"); } |