diff options
author | Kyle K <kylek389@gmail.com> | 2012-12-23 01:41:33 +0000 |
---|---|---|
committer | Kyle Kaminski <kyle@kkaminsk.com> | 2012-12-23 01:41:33 +0000 |
commit | f0531d88e958b5fa77f8dc9bb34e697e872aeba9 (patch) | |
tree | 873915769ff30f32953d58519131b3956190a584 /main.c | |
parent | adbfb7c71fe1e958a2a2397c7b88c3061043c54e (diff) | |
download | kernelhello-f0531d88e958b5fa77f8dc9bb34e697e872aeba9.tar.gz kernelhello-f0531d88e958b5fa77f8dc9bb34e697e872aeba9.tar.bz2 kernelhello-f0531d88e958b5fa77f8dc9bb34e697e872aeba9.zip |
register char device and prepare mknod script
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"); } |