From f0531d88e958b5fa77f8dc9bb34e697e872aeba9 Mon Sep 17 00:00:00 2001 From: Kyle K Date: Sun, 23 Dec 2012 01:41:33 +0000 Subject: register char device and prepare mknod script --- main.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 6a65f3c..b6975a4 100644 --- a/main.c +++ b/main.c @@ -5,6 +5,7 @@ #include /* used for kmalloc */ #include +#include #include @@ -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"); } -- cgit v1.2.3