当前位置: 首页 > news >正文

网站设计页面如何做居中福田欧辉氢燃料电池客车

网站设计页面如何做居中,福田欧辉氢燃料电池客车,青海wap网站建设比较好,微信微网站是什么情况驱动程序请使用第二章https://blog.csdn.net/chenhequanlalala/article/details/140034424 用户app与驱动交互最常见的做法是insmod驱动后#xff0c;生成一个设备节点#xff0c;app通过open#xff0c;read等系统调用去操作这个设备节点#xff0c;这里先用mknode命令调…驱动程序请使用第二章https://blog.csdn.net/chenhequanlalala/article/details/140034424 用户app与驱动交互最常见的做法是insmod驱动后生成一个设备节点app通过openread等系统调用去操作这个设备节点这里先用mknode命令调试。 mknod 设备名 设备类型(b块设备/c字符设备/p管道) 主设备号 次设备号 mknod /dev/hello c 240 0 使用mknode后生成了/dev/hello节点写入数据到hello节点中查看dmesg的输出发现调用了驱动的open write release echo 1 /dev/hello [  802.771723] /home/book/nfs_rootfs/drivers_projects/01_hello_drv/hello_drv.c hello_open 48 [  802.773196] /home/book/nfs_rootfs/drivers_projects/01_hello_drv/hello_drv.c hello_write 40 [  802.773285] /home/book/nfs_rootfs/drivers_projects/01_hello_drv/hello_drv.c hello_release 56   这里写一个C程序来读写这个设备节点 #include linux/string.h #include unistd.h #include sys/types.h #include sys/stat.h #include fcntl.h #include stdio.h/* 读数据 ./hello_test xxx(设备节点名字) 写数据 ./hello_test xxx(设备节点名字) string */int main(int argc, char **argv) {int fd;int len;char buf[1024];if(argc 2){printf(Usage :\n);printf(%s dev [str]\n, argv[0]);return -1;}//openfd open(argv[1], O_RDWR);if(fd 0){printf(open %s failed\n, argv[1]);return -1;}//readif(argc 2){len read(fd, buf, sizeof(buf));printf(%s\n, buf);}//writeelse if(argc 3){len write(fd, argv[2], strlen(argv[2]));}else{printf(Too many parameters\n);}close(fd); } 分别调用 ./hello_test /dev/hello 123 和 ./hello_test /dev/hello 后查看dmesg输出显示 [ 2770.434595] /home/book/nfs_rootfs/drivers_projects/01_hello_drv/hello_drv.c hello_open 48 [ 2770.434664] /home/book/nfs_rootfs/drivers_projects/01_hello_drv/hello_drv.c hello_write 40 [ 2770.434705] /home/book/nfs_rootfs/drivers_projects/01_hello_drv/hello_drv.c hello_release 56 [ 2772.388372] /home/book/nfs_rootfs/drivers_projects/01_hello_drv/hello_drv.c hello_open 48 [ 2772.388439] /home/book/nfs_rootfs/drivers_projects/01_hello_drv/hello_drv.c hello_read 32 [ 2772.389257] /home/book/nfs_rootfs/drivers_projects/01_hello_drv/hello_drv.c hello_release 56 app的open write read release都一一对应上了。 这里的./hello_test /dev/hello其实没有读到数据因为驱动程序中并没有和app交互数据。 [root100ask:/mnt/drivers_projects/01_hello_drv]# ./hello_test /dev/hello read size 1024 data     app与驱动交换数据通过copy_from_user和copy_to_user来实现 copy_to_user(void __user *to, const void *from, unsigned long n); copy_from_user(void *to, const void __user *from, unsigned long n); 在驱动程序中添加一个buf用来保存用户的数据用copy_from_user保存数据用copy_to_user读取数据。 #include asm/uaccess.h #include linux/scatterlist.h #include linux/types.h #include linux/mm.h #include linux/miscdevice.h #include linux/slab.h #include linux/vmalloc.h #include linux/mman.h #include linux/random.h #include linux/init.h #include linux/raw.h #include linux/tty.h #include linux/capability.h #include linux/ptrace.h #include linux/device.h #include linux/highmem.h #include linux/backing-dev.h #include linux/shmem_fs.h #include linux/splice.h #include linux/pfn.h #include linux/export.h #include linux/io.h #include linux/uio.h #include linux/module.h#include linux/uaccess.h#define DEVICE_NAME hello_device static int major; #define hello_buf_size 100 static unsigned char hello_buf[hello_buf_size];//ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); //参数含义依次为 要读取的文件指针 用户保存数据的buf 读取数据大小 文件内容的偏移量 static ssize_t hello_read (struct file * filp, char __user *buf, size_t size, loff_t *offset) {unsigned long len size hello_buf_size ? hello_buf_size : size;copy_to_user(buf, hello_buf, len);printk(%s %s %d\n, __FILE__, __FUNCTION__, __LINE__);return len; }//ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); //参数含义依次为 要写入的文件指针 用户要写入的数据buf 写入数据大小 文件内容的偏移量 static ssize_t hello_write (struct file *filp, const char __user *buf, size_t size, loff_t *offset) {unsigned long len size hello_buf_size ? hello_buf_size : size;copy_from_user(hello_buf, buf, len);printk(%s %s %d\n, __FILE__, __FUNCTION__, __LINE__);return len; }//int (*open) (struct inode *, struct file *); //参数含义依次为 文件索引节点 文件指针 static int hello_open (struct inode *node, struct file *filp) {printk(%s %s %d\n, __FILE__, __FUNCTION__, __LINE__);return 0; }//int (*release) (struct inode *, struct file *); //参数含义依次为 文件索引节点 文件指针 static int hello_release (struct inode *node, struct file *filp) {printk(%s %s %d\n, __FILE__, __FUNCTION__, __LINE__);return 0; }/*构建file_operations结构体*/ static const struct file_operations hello_fops {.owner THIS_MODULE,.read hello_read,.write hello_write,.open hello_open,.release hello_release, };/*init函数,实现register_chrdev*/ static int __init hello_init(void) {//数含义依次为 主设备号如果为0内核会自动分配一个可用的。设备名会在/proc/devices中显示。 file_operations结构体//注册成功就返回主设备号major register_chrdev(0, DEVICE_NAME, hello_fops);printk(%s %s %d\n, __FILE__, __FUNCTION__, __LINE__);return 0; }/*exit函数unregister_chrdev*/ static void __exit hello_exit(void) {//数含义依次为 主设备号 设备名unregister_chrdev(major, DEVICE_NAME);printk(%s %s %d\n, __FILE__, __FUNCTION__, __LINE__); }module_init(hello_init); module_exit(hello_exit); //遵循GPL协议 MODULE_LICENSE(GPL); 重新insmod驱动后执行测试程序 [root100ask:/mnt/drivers_projects/01_hello_drv]# ./hello_test /dev/hello 123456 [root100ask:/mnt/drivers_projects/01_hello_drv]# ./hello_test /dev/hello        read size 100 data 123456 [root100ask:/mnt/drivers_projects/01_hello_drv]# ./hello_test /dev/hello hello [root100ask:/mnt/drivers_projects/01_hello_drv]# ./hello_test /dev/hello  read size 100 data hello6   这里第二次输出hello6是因为copy_from_user只是写入指定长度的数据第一次写入的123456只覆盖了前5字节。
http://www.dnsts.com.cn/news/187817.html

相关文章:

  • 海淀网站建设电话营销网点是什么意思
  • 韩都衣舍网站建设的改进徐州专业制作网站
  • 如何用快站做pc端网站中国建设银行春招网站
  • 小程序开发 网站建设如何让网站火起来
  • 做网站 工商 非法经营百度视频下载
  • 网站建设教程在线观看wordpress建站方法
  • 网站建站怎么分前端和后端中山网站建设文化效果
  • 东莞建站公司速推全网天下首选长沙网页设计培训价格
  • 有关小城镇建设网站域名查询ip地址138
  • 个人做视频网站烧钱极捷号网站建设
  • 湖南智能网站建设公司wordpress文章编辑器可视化
  • 博客网站怎么建设商标注册45类明细
  • 广州网站开发定制深圳网站seo哪家快
  • 高唐住房建设局网站网站备案归
  • 企业网站每年要多少钱互联网网站备案流程
  • 建筑师网站做网站关键词
  • 福州网站设计要多少钱产品经理培训哪个机构好
  • 青海住房和建设厅网站佛山专业建设网站平台
  • 赣州网上注册公司网站论坛类网站设计
  • 淘客单网站南昌网站建设优化
  • 湛江建站公司模板建设银行储蓄卡申请网站
  • 站长网seo综合查询工具西安营销网站建设公司
  • 电脑打不开建设银行网站做食品企业网站的费用
  • 灵璧县建设局网站珠海企业营销型网站建设公司
  • 营销型公司网站建设网站开发用px还是rem
  • 网站建设过程中应该注意的事项有wordpress 统计插件
  • wordpress托管建站河南衣柜网站建设公司
  • wordpress网站刷新专业东莞网站制作公司
  • 石家庄微网站免费搭建网站 优帮云
  • 哈尔滨网站建设哪家好而且价格不贵企业网站建设运营方案