在之前的学习笔记一中实现了简单杂项字符设备驱动模型的注册,但是伴随着一些问题,读写函数没有发挥作用,写进去的数据没有读出来,经过这两天的学习我终于知道原来编写字符设备驱动代码不仅要编写上层(就是用户层)用户代码,还要编写底层(就是内核层)相关函数的代码才行,所以上次当然不会得到数据
这一次对上次的代码进行改动,用传参的方式实现简单的读写功能
首先是用户层代码app.c的编写,几乎没怎么改动
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc,char const*argv[])
{
int ret=0,i=0;
char buff[20]={
0};
int fd=open(argv[1],O_RDWR); //open打开
if(fd<0)
{
perror("open");
return -1;
}
printf("open is success\n");
ret=write(fd,argv[2],4); //write写入
if(ret<0)
{
perror("write");
return -1;
}
printf("write is success\n");
ret=</