5.2.11.添加读写接口
Posted ocean-star
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了5.2.11.添加读写接口相关的知识,希望对你有一定的参考价值。
- ./app
如果app只使用了write(fd, "hellowrite", 10);没有read的话,./app没有反应
error:如果该写了驱动,则应该重新安装驱动
#lsmod
Module Size Used by Not tainted
module_test 1087 0
# cat /proc/devices
# lsmod
# insmod module_test.ko
#mknod /dev/test c 250 0
#ls /dev/test -l
#./app
[ 143.016905] test_chrdev_open
open /dev/test su[ 143.175274] test_chrdev_write
[ 143.179043] test_chrdev_release
ccess.
j--->
[ 143.016905] test_chrdev_open ----------------->test_chrdev_open --------->test_chrdev_open 1. fd = open(FILE, O_RDWR);
open /dev/test success. -------------------->main 2.printf("open %s success.
", FILE);
[ 143.175274] test_chrdev_write ----------------->test_chrdev_write --------->test_chrdev_write 3.write(fd, "hellowrite", 10);
[ 143.179043] test_chrdev_release ----------------->test_chrdev_release --------->test_chrdev_release 4.close(fd);
#./app
[ 566.922098] test_chrdev_open ----------------->test_chrdev_open --------->test_chrdev_open 1. fd = open(FILE, O_RDWR);
[ 566.923665] test_chrdev_write ----------------->test_chrdev_write --------->test_chrdev_write 3.write(fd, "hellowrite", 10);
[ 566.926485] test_chrdev_read ----------------->test_chrdev_read --------->test_chrdev_read 4.read(fd, buffer, 10);
[ 566.929342] test_chrdev_release ----------------->test_chrdev_release --------->test_chrdev_release 5.close(fd);
open /dev/test success. -------------------->main 2.printf("open %s success.
", FILE);
- 写函数的本质是将应用层传递过来的数据先复制到内核中,然后以正确的方式写入硬件
应用和驱动之间的数据交换:
copy_from_user:将数据从用户空间复制到内核空间
copy_to_user:
注意:复制是和mmap的映射相对应区分的
以上是关于5.2.11.添加读写接口的主要内容,如果未能解决你的问题,请参考以下文章