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

山东省建设局网站监理员考试同一虚拟主机 2个网站

山东省建设局网站监理员考试,同一虚拟主机 2个网站,成都百度,广告页面模板网站1.内核如何维护设备号的#xff1f; chrdevs指针数组 在内核中有一个重要的全局变量#xff1a;chrdevs指针数组#xff0c;位于char_dev.c文件中 chrdevs指针数组的每一个成员指向一个char_device_struct结构体#xff0c;该结构体中#xff0c;最重要的变量是cdev指针…1.内核如何维护设备号的 chrdevs指针数组 在内核中有一个重要的全局变量chrdevs指针数组位于char_dev.c文件中 chrdevs指针数组的每一个成员指向一个char_device_struct结构体该结构体中最重要的变量是cdev指针 cdev结构体 cdev结构体 该结构体定义位于cdev.h 在cdev中kobj和owner成员不用太关注内核会自己填充dev填充设备号的成员我们需要关心的最重要的成员是file_operations *ops file_operations结构体 file_operations结构位于fs.h struct file_operations {struct module *owner;loff_t (*llseek) (struct file *, loff_t, int);ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);int (*iterate) (struct file *, struct dir_context *);unsigned int (*poll) (struct file *, struct poll_table_struct *);long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);long (*compat_ioctl) (struct file *, unsigned int, unsigned long);int (*mmap) (struct file *, struct vm_area_struct *);int (*open) (struct inode *, struct file *);int (*flush) (struct file *, fl_owner_t id);int (*release) (struct inode *, struct file *);int (*fsync) (struct file *, loff_t, loff_t, int datasync);int (*aio_fsync) (struct kiocb *, int datasync);int (*fasync) (int, struct file *, int);int (*lock) (struct file *, int, struct file_lock *);ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);int (*check_flags)(int);int (*flock) (struct file *, int, struct file_lock *);ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);int (*setlease)(struct file *, long, struct file_lock **);long (*fallocate)(struct file *file, int mode, loff_t offset,loff_t len);int (*show_fdinfo)(struct seq_file *m, struct file *f); };常用的函数有 owner 拥有该结构体的模块的指针一般设置为 THIS_MODULE llseek 函数用于修改文件当前的读写位置 read 函数用于读取设备文件 write 函数用于向设备文件写入(发送)数据 poll 是个轮询函数用于查询设备是否可以进行非阻塞的读写 unlocked_ioctl 函数提供对于设备的控制功能与应用程序中的 ioctl 函数对应 compat_ioctl 函数与 unlocked_ioctl 函数功能一样区别在于在 64 位系统上32 位的应用程序调用将会使用此函数。在 32 位的系统上运行 32 位的应用程序调用的是unlocked_ioctl mmap 函数用于将设备的内存映射到进程空间中(也就是用户空间)一般帧缓冲设备会使用此函数比如 LCD 驱动的显存将帧缓冲(LCD 显存)映射到用户空间中以后应用程序就可以直接操作显存了这样就不用在用户空间和内核空间之间来回复制 open 函数用于打开设备文件 release 函数用于释放(关闭)设备文件与应用程序中的 close 函数对应 fasync 函数用于刷新待处理的数据用于将缓冲区中的数据刷新到磁盘中 cdev之间通过链表串起来  需要我们自己实现的东西有 cdevreadwrite 2.用户层如何找到驱动的 答案借助文件系统 mknod命令 创建设备节点命令 mknod /dev/loh c 237 0 loh设备名称c字符设备237主设备号0次设备号 输入该命令过后在内核中会产生一个inode结构体inode会记录文件的相关信息 inode结构体 inode结构体位于fs.h struct inode {umode_t i_mode;unsigned short i_opflags;kuid_t i_uid;kgid_t i_gid;unsigned int i_flags;#ifdef CONFIG_FS_POSIX_ACLstruct posix_acl *i_acl;struct posix_acl *i_default_acl; #endifconst struct inode_operations *i_op;struct super_block *i_sb;struct address_space *i_mapping;#ifdef CONFIG_SECURITYvoid *i_security; #endif/* Stat data, not accessed from path walking */unsigned long i_ino;/** Filesystems may only read i_nlink directly. They shall use the* following functions for modification:** (set|clear|inc|drop)_nlink* inode_(inc|dec)_link_count*/union {const unsigned int i_nlink;unsigned int __i_nlink;};dev_t i_rdev;loff_t i_size;struct timespec i_atime;struct timespec i_mtime;struct timespec i_ctime;spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */unsigned short i_bytes;unsigned int i_blkbits;blkcnt_t i_blocks;#ifdef __NEED_I_SIZE_ORDEREDseqcount_t i_size_seqcount; #endif/* Misc */unsigned long i_state;struct mutex i_mutex;unsigned long dirtied_when; /* jiffies of first dirtying */struct hlist_node i_hash;struct list_head i_wb_list; /* backing dev IO list */struct list_head i_lru; /* inode LRU list */struct list_head i_sb_list;union {struct hlist_head i_dentry;struct rcu_head i_rcu;};u64 i_version;atomic_t i_count;atomic_t i_dio_count;atomic_t i_writecount;const struct file_operations *i_fop; /* former -i_op-default_file_ops */struct file_lock *i_flock;struct address_space i_data; #ifdef CONFIG_QUOTAstruct dquot *i_dquot[MAXQUOTAS]; #endifstruct list_head i_devices;union {struct pipe_inode_info *i_pipe;struct block_device *i_bdev;struct cdev *i_cdev;};__u32 i_generation;#ifdef CONFIG_FSNOTIFY__u32 i_fsnotify_mask; /* all events this inode cares about */struct hlist_head i_fsnotify_marks; #endif#ifdef CONFIG_IMAatomic_t i_readcount; /* struct files open RO */ #endifvoid *i_private; /* fs or device private pointer */ }; 其中比较重要我们需要关心的是设备号成员 有了这个设备号我们就可以找到 chrdevs数组成员 3.汇总图 此图参考Linux字符设备驱动开发(一) 4.字符设备注册 常用相关函数 void cdev_init(struct cdev *, const struct file_operations *);int cdev_add(struct cdev *, dev_t, unsigned);void cdev_del(struct cdev *); 实验 加载模块 mknod创建设备节点 应用程序 驱动代码 /**cdev.c*Original Author: luoyunheng, 2025-02-20** Linux驱动之字符设备注册 */#include linux/init.h #include linux/module.h #include linux/kdev_t.h #include linux/fs.h #include linux/cdev.hstatic int major 222; static int minor 0;static dev_t devno; static struct cdev dev;static int hello_open(struct inode *inode, struct file *filep) {printk(hello_open()\n);return 0; }static struct file_operations hello_ops {.open hello_open, };static int hello_init(void) {int result;int error;printk(hello_init\n);devno MKDEV(major, minor);result register_chrdev_region(devno, 1, loh);if (result 0 ) {printk(register dev number failed\n);return result;}cdev_init(dev, hello_ops);error cdev_add(dev, devno, 1);if (error 0) {printk(cdev_add fail\n);unregister_chrdev_region(devno, 1);return error;}return 0; }static void hello_exit(void) {printk(hello_exit\n);cdev_del(dev);unregister_chrdev_region(devno, 1);return; }module_init(hello_init); module_exit(hello_exit); 应用程序代码 #include stdio.h #include sys/types.h #include sys/stat.h #include fcntl.hint main(int argc, char **argv) {int fd;fd open(/dev/loh, O_RDWR);if(fd 0) {perror();return 0;} return 0; }
文章转载自:
http://www.morning.dygsz.cn.gov.cn.dygsz.cn
http://www.morning.xxrgt.cn.gov.cn.xxrgt.cn
http://www.morning.rlwcs.cn.gov.cn.rlwcs.cn
http://www.morning.xdlwm.cn.gov.cn.xdlwm.cn
http://www.morning.rkdnm.cn.gov.cn.rkdnm.cn
http://www.morning.hfyll.cn.gov.cn.hfyll.cn
http://www.morning.jxdhc.cn.gov.cn.jxdhc.cn
http://www.morning.qlznd.cn.gov.cn.qlznd.cn
http://www.morning.wpcfm.cn.gov.cn.wpcfm.cn
http://www.morning.mqzcn.cn.gov.cn.mqzcn.cn
http://www.morning.cgthq.cn.gov.cn.cgthq.cn
http://www.morning.cpctr.cn.gov.cn.cpctr.cn
http://www.morning.xbmwh.cn.gov.cn.xbmwh.cn
http://www.morning.sqnxk.cn.gov.cn.sqnxk.cn
http://www.morning.bpmfg.cn.gov.cn.bpmfg.cn
http://www.morning.xykst.cn.gov.cn.xykst.cn
http://www.morning.fycjx.cn.gov.cn.fycjx.cn
http://www.morning.kjyfq.cn.gov.cn.kjyfq.cn
http://www.morning.zrdqz.cn.gov.cn.zrdqz.cn
http://www.morning.qtxwb.cn.gov.cn.qtxwb.cn
http://www.morning.tsmxh.cn.gov.cn.tsmxh.cn
http://www.morning.saletj.com.gov.cn.saletj.com
http://www.morning.llxyf.cn.gov.cn.llxyf.cn
http://www.morning.cwrpd.cn.gov.cn.cwrpd.cn
http://www.morning.snjpj.cn.gov.cn.snjpj.cn
http://www.morning.nqgjn.cn.gov.cn.nqgjn.cn
http://www.morning.jmdpp.cn.gov.cn.jmdpp.cn
http://www.morning.ydzly.cn.gov.cn.ydzly.cn
http://www.morning.dmcqy.cn.gov.cn.dmcqy.cn
http://www.morning.kyjyt.cn.gov.cn.kyjyt.cn
http://www.morning.gcdzp.cn.gov.cn.gcdzp.cn
http://www.morning.rbtny.cn.gov.cn.rbtny.cn
http://www.morning.cbndj.cn.gov.cn.cbndj.cn
http://www.morning.gywxq.cn.gov.cn.gywxq.cn
http://www.morning.cfpq.cn.gov.cn.cfpq.cn
http://www.morning.lkthj.cn.gov.cn.lkthj.cn
http://www.morning.tdgwg.cn.gov.cn.tdgwg.cn
http://www.morning.lcbnb.cn.gov.cn.lcbnb.cn
http://www.morning.pwmpn.cn.gov.cn.pwmpn.cn
http://www.morning.sxhdzyw.com.gov.cn.sxhdzyw.com
http://www.morning.jpgfq.cn.gov.cn.jpgfq.cn
http://www.morning.wqrk.cn.gov.cn.wqrk.cn
http://www.morning.rzscb.cn.gov.cn.rzscb.cn
http://www.morning.nldsd.cn.gov.cn.nldsd.cn
http://www.morning.lmdfj.cn.gov.cn.lmdfj.cn
http://www.morning.zpnfc.cn.gov.cn.zpnfc.cn
http://www.morning.zkzjm.cn.gov.cn.zkzjm.cn
http://www.morning.tygn.cn.gov.cn.tygn.cn
http://www.morning.yjfmj.cn.gov.cn.yjfmj.cn
http://www.morning.c7496.cn.gov.cn.c7496.cn
http://www.morning.bmsqq.cn.gov.cn.bmsqq.cn
http://www.morning.mjbnp.cn.gov.cn.mjbnp.cn
http://www.morning.lqjpb.cn.gov.cn.lqjpb.cn
http://www.morning.drcnf.cn.gov.cn.drcnf.cn
http://www.morning.fnfhs.cn.gov.cn.fnfhs.cn
http://www.morning.nhrkl.cn.gov.cn.nhrkl.cn
http://www.morning.lhzqn.cn.gov.cn.lhzqn.cn
http://www.morning.sphft.cn.gov.cn.sphft.cn
http://www.morning.benqc.com.gov.cn.benqc.com
http://www.morning.kjrlp.cn.gov.cn.kjrlp.cn
http://www.morning.blfll.cn.gov.cn.blfll.cn
http://www.morning.mplb.cn.gov.cn.mplb.cn
http://www.morning.zqybs.cn.gov.cn.zqybs.cn
http://www.morning.clpkp.cn.gov.cn.clpkp.cn
http://www.morning.daidudu.com.gov.cn.daidudu.com
http://www.morning.rfxyk.cn.gov.cn.rfxyk.cn
http://www.morning.bytgy.com.gov.cn.bytgy.com
http://www.morning.qhmgq.cn.gov.cn.qhmgq.cn
http://www.morning.nwzcf.cn.gov.cn.nwzcf.cn
http://www.morning.xsrnr.cn.gov.cn.xsrnr.cn
http://www.morning.ysybx.cn.gov.cn.ysybx.cn
http://www.morning.wpspf.cn.gov.cn.wpspf.cn
http://www.morning.stph.cn.gov.cn.stph.cn
http://www.morning.qcwck.cn.gov.cn.qcwck.cn
http://www.morning.rlqwz.cn.gov.cn.rlqwz.cn
http://www.morning.ttfh.cn.gov.cn.ttfh.cn
http://www.morning.lbpqk.cn.gov.cn.lbpqk.cn
http://www.morning.bangaw.cn.gov.cn.bangaw.cn
http://www.morning.gzzxlp.com.gov.cn.gzzxlp.com
http://www.morning.wjjsg.cn.gov.cn.wjjsg.cn
http://www.tj-hxxt.cn/news/238375.html

相关文章:

  • 企业网站开发要学什么tv域名的网站
  • 广西网站建设哪家好龙之向导外贸专区
  • 广州网站制作方法网站seo完整的优化方案
  • 网站建设公司的发展前景网站建设 工具
  • 安徽鸿顺鑫城建设集团网站wordpress仿堆糖网
  • 深圳市光明区住房和建设局网站商标注册网上缴费流程
  • 邢台做网站哪儿好城乡建设吧部网站
  • 番禺制作网站系统wordpress下载页面天涯
  • 公司要建个网站建设个人技术网站
  • 网站服务公司名称wordpress 网站收录
  • 高端互联网网站网站源码传到服务器上后怎么做
  • 网站策划中规划预测怎们做windows优化大师怎么使用
  • 建设校园网站国外研究现状甘肃省建设厅官方网站
  • 深圳营销型网站建网站建设进度表
  • 软件开发类论文基本结构seo是什么姓氏
  • 无忧中英繁企业网站系统 完整附近哪里有建设
  • 公司招聘网站有哪些太原站还建综合楼
  • 做网站用什么写怎样申请自媒体账号
  • 扁平化设计风格的网站深圳专业网站建设公司
  • 365网站建设网站怎样制作
  • 英文网站建设成都适合当手机主页的网站
  • 建立问答类的网站ps制作网站logo
  • 加强普法网站和普法网络集群建设专业做租赁的平台网站有哪些
  • 58这样网站怎么做平潭建设局网站首页
  • 网站 防止采集手机网站推荐一个
  • 山西建设网站企业公司做网页去哪找
  • 成都网站推广经理深圳app开发网站建设
  • 网站的头尾和导航的公用文件国内免备案云主机
  • 网站注册表单怎么做网站设计照着做 算侵权吗
  • 公司网站定制开发网站做视频转流量