编写一个字符设备驱动程序,实现module_init和module_exit中的注册函数和卸载函数,并在注册函数和卸载函数中打印注册成功信息和卸载成功信息,在/var/log/syslog日志文件中查看。#
#Makefile
obj-m := helo.o
KDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order
/*hello.c*/
#include
MODULE_LICENSE("Dual BSD/GPL");
#include
#include
#define nn 200
struct file_operations gk=
{
};
static int __init hello_init(void)
{
int k;
printk(KERN_ALERT "Hello,world!\n");
k=register_chrdev(nn ,"drive",&gk);
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_ALERT "Goodbye,cruel world!\n");
unregister_chrdev(nn,"drive");
}
module_init(hello_init);
module_exit(hello_exit);