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

网站建设合同续签申请书网站建设步骤图

网站建设合同续签申请书,网站建设步骤图,开源网站管理系统,网站做动态虚线编写驱动程序,并将内核模块加载到内核中,等待被用户程序调用。 在控制台中借助第一步申请到的设备号,使用 mknod 命令创建一个设备节点,并拟一个设备名称。 在用户程序中,使用 open 打开第二步中的设备名称&#xff…
  1. 编写驱动程序,并将内核模块加载到内核中,等待被用户程序调用。

  2. 在控制台中借助第一步申请到的设备号,使用 mknod 命令创建一个设备节点,并拟一个设备名称。

  3. 在用户程序中,使用 open 打开第二步中的设备名称,通过设备节点间接控制驱动程序。

1. 驱动程序编写

cdev_driver.c

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/uaccess.h>MODULE_LICENSE("GPL");
MODULE_AUTHOR("zz");static dev_t devno;#define KMAX_LEN 32static int demo_open(struct inode *ind, struct file *fp)
{printk("demo open\n");return 0;
}static int demo_release(struct inode *ind, struct file *fp)
{printk("demo release\n");return 0;
}static ssize_t demo_read(struct file *fp, char __user *buf, size_t size, loff_t *pos)
{int rc;char kbuf[KMAX_LEN] = "read test\n"; if (size > KMAX_LEN)size = KMAX_LEN;rc = copy_to_user(buf, kbuf, size);if(rc < 0) {return -EFAULT;pr_err("copy_to_user failed!");}return size;
}static ssize_t demo_write(struct file *fp, const char __user *buf, size_t size, loff_t *pos)
{int rc;char kbuf[KMAX_LEN];if (size > KMAX_LEN)size = KMAX_LEN;rc = copy_from_user(kbuf, buf, size);if(rc < 0) {return -EFAULT;pr_err("copy_from_user failed!");}printk("%s", kbuf);return size;
}static struct file_operations fops = {.open = demo_open,.release = demo_release,.read = demo_read,  .write = demo_write,  
};static struct cdev cd;  static int demo_init(void)  
{int rc;  rc = alloc_chrdev_region(&devno, 0, 1, "test"); // int alloc_chardev_region(dev_t *dev, unsigned baseminor, unsigned count, const char *name); 用于设备号未知,向系统动态申请未被占用的设备号的情况if(rc < 0) {  pr_err("alloc_chrdev_region failed!");  return rc;  }printk("MAJOR is %d\n", MAJOR(devno));  printk("MINOR is %d\n", MINOR(devno));  cdev_init(&cd, &fops); // void cdev_init(struct cdev *, struct file_operations *); 建立cdev和file_operations的连接rc = cdev_add(&cd, devno, 1); // int cdev_add(struct cdev *, dev_t, unsigned); 完成字符设备的注册if (rc < 0) {  pr_err("cdev_add failed!");  return rc;  }return 0;  
}static void demo_exit(void)  
{cdev_del(&cd); // 注销字符设备unregister_chrdev_region(devno, 1); // 释放设备号 return;  
}module_init(demo_init);  
module_exit(demo_exit);  

2. 应用程序编写

app.c

#include <stdio.h>       
#include <fcntl.h>       
#include <unistd.h>       int main()       
{int rc;       char buf[32];       int fd = open("/dev/test_chr_dev", O_RDWR);       if (fd < 0) {       printf("open file failed!\n");           return -1;           }read(fd, buf, 32);           printf("%s", buf);           write(fd, "write test\n", 32);           close(fd);           return 0;           
}

3. Makefile编写

ifneq ($(KERNELRELEASE),)    obj-m := cdev_driver.o    
else    KDIR    := /lib/modules/$(shell uname -r)/build    PWD     := $(shell pwd)    
endif     
all:     make -C $(KDIR) M=$(PWD) modules     
clean:     make -C $(KDIR) M=$(PWD) clean     

程序运行

1. make 编译驱动代码

在这里插入图片描述

2. gcc 编译用户程序代码

在这里插入图片描述

3. insmod 加载模块

在这里插入图片描述

4. dmesg 查看系统为设备分配的设备号

在这里插入图片描述
5. 使用 mknod 命令在系统中创建设备节点并运行程序

设备号与 dmesg 中查看的系统分配设备号一致,节点名称与用户程序中打开的设备文件名一致。

在这里插入图片描述


文章转载自:

http://XeEtbZDC.fhhry.cn
http://tcC3oz2j.fhhry.cn
http://HSDusfml.fhhry.cn
http://z8xYAw5h.fhhry.cn
http://cNJdD9KO.fhhry.cn
http://o7te2tDV.fhhry.cn
http://gxoPmEu0.fhhry.cn
http://YVjqvGRs.fhhry.cn
http://eWAEI1qk.fhhry.cn
http://0TyfyPPa.fhhry.cn
http://LHFCWkrh.fhhry.cn
http://0GrfI2mO.fhhry.cn
http://1yHEY4nP.fhhry.cn
http://YX80ffsT.fhhry.cn
http://WdCmzdS5.fhhry.cn
http://l8yY2vfW.fhhry.cn
http://gCcSTXt4.fhhry.cn
http://YLKEpV4k.fhhry.cn
http://PuV9UJaN.fhhry.cn
http://h2JxqIcK.fhhry.cn
http://Hux2fRWO.fhhry.cn
http://6QdBkI6G.fhhry.cn
http://28sno1uQ.fhhry.cn
http://pzrlP9u8.fhhry.cn
http://lS3DXi0E.fhhry.cn
http://Bzw9FuQ3.fhhry.cn
http://fEHAxEpH.fhhry.cn
http://39TkGZ20.fhhry.cn
http://V2JBFwx6.fhhry.cn
http://1PERFRfG.fhhry.cn
http://www.dtcms.com/wzjs/667499.html

相关文章:

  • logo设计网站平台平台推广应用
  • 网站qq未启用网站备案导致网站被k
  • 东莞微网站商城类网站功能列表
  • wordpress几个网站共用用户物流网站毕业设计
  • 现在个人都在哪个网站做外贸怎么搞wordpress
  • 福州网站建设熊掌号untitled怎么做网页
  • 网站建设的基本目标大淘客网站推广位怎么做
  • 网站开发的初始密码wordpress页面显示分类文章
  • 做技术分享网站有哪些做网站有什么优势
  • 一个在线做笔记的网站安国市住房和城乡建设局网站
  • 番禺网站开发设计成都两条传播链在成华区
  • 网站建设业务客户来源seo职位具体做什么
  • 网站开发适配做企业网站设计与实现
  • 网站登录账号密码保存在哪里南京网站制作公司排名前十
  • vps网站能打开推广软文是什么
  • 去国外做非法网站吗wordpress模板淘客
  • 一个小型购物网站开发大学生创新创业大赛官网入口
  • 网站开发全包如何购买一个网站的域名
  • 网站开发有哪些方式怎么用h5做网站
  • 做电影网站 需要进那些群建设网站 系统占用空间
  • wordpress做文字站做网站怎么挣钱最快
  • 花都网站建设哪家好免费网络推广软件
  • 自己做下载网站吗公司建设网站需要注意什么
  • 网站建设的主题什么比较好58黄页网推广效果怎样
  • 网站内部优化建设wordpress 自带主题修改
  • 婚纱网站phpxp 做网站服务器
  • wordpress 更新问题春哥seo博客
  • 官方网站建设建议固安网络公司推荐筑梦网络
  • 网站开发交流网站聚合页面模板
  • 中文网站搭建网站开发职业定位