添加一个新的设备驱动;编写一个使用新增设备驱动的应用程序进行演示。
- 一.首先编写一个基本的内核模块,代码如下:
-
#include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> MODULE_LICENSE("GPL"); MODULE_AUTHOR("Mystety"); unsigned int fzq_major = 0; char message[32] = " ";//存数据 static ssize_t fzq_read(struct file *file, char *buf, size_t length, loff_t *offset)//读 { if(copy_to_user(buf,message,sizeof(message))) { return -2; } return sizeof(message); } static ssize_t fzq_write( struct file *file, const char *buf, size_t length,loff_t *offset)//写 { if(copy_from_user(message,buf,sizeof(message))) { return -3; } retu