前回の実験(10)で作成したdio_drv.cは次の通りであった。
#include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/fs.h> #define DRIVERNAME "dio_drv" int dio_major = 0; MODULE_LICENSE("GPL"); struct file_operations dio_fops = { .owner = NULL, .read = NULL, .write = NULL, .ioctl = NULL, .open = NULL, .release = NULL, }; int __init dio_init(void) { int ret; printk("initialize the dio_device \n"); ret = register_chrdev(dio_major, DRIVERNAME, &dio_fops); if (ret < 0) return ret; if (dio_major == 0) dio_major = ret; return 0; } void __exit dio_cleanup(void) { printk("cleanup the dio_device \n"); unregister_chrdev(dio_major, DRIVERNAME); } module_init(dio_init); module_exit(dio_cleanup);