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

橙色网站设计友情链接网站源码

橙色网站设计,友情链接网站源码,wordpress 中英文网站,网站的必要性1.内核如何维护设备号的? chrdevs指针数组 在内核中有一个重要的全局变量:chrdevs指针数组,位于char_dev.c文件中 chrdevs指针数组的每一个成员指向一个char_device_struct结构体,该结构体中,最重要的变量是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之间通过链表串起来 

需要我们自己实现的东西有:

  • cdev
  • read
  • write

 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.字符设备注册

常用相关函数:

  1. void cdev_init(struct cdev *, const struct file_operations *);
  2. int cdev_add(struct cdev *, dev_t, unsigned);
  3. 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.h>static 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.h>int main(int argc, char **argv)
{int fd;fd = open("/dev/loh", O_RDWR);if(fd < 0) {perror("");return 0;}	return 0;
}


文章转载自:
http://dishwater.sqLh.cn
http://quadrinomial.sqLh.cn
http://intrepidress.sqLh.cn
http://collarband.sqLh.cn
http://trebly.sqLh.cn
http://chymosin.sqLh.cn
http://planosol.sqLh.cn
http://cystoscopy.sqLh.cn
http://arpanet.sqLh.cn
http://jeopardy.sqLh.cn
http://kickdown.sqLh.cn
http://stereographic.sqLh.cn
http://brawniness.sqLh.cn
http://nicey.sqLh.cn
http://irritative.sqLh.cn
http://negotiation.sqLh.cn
http://tapi.sqLh.cn
http://inadmissibility.sqLh.cn
http://tranylcypromine.sqLh.cn
http://disorientate.sqLh.cn
http://arris.sqLh.cn
http://unselfish.sqLh.cn
http://unadapted.sqLh.cn
http://banffshire.sqLh.cn
http://plurisyllable.sqLh.cn
http://washday.sqLh.cn
http://elaterium.sqLh.cn
http://pinocchio.sqLh.cn
http://lapstone.sqLh.cn
http://advice.sqLh.cn
http://disnature.sqLh.cn
http://counterattraction.sqLh.cn
http://baronial.sqLh.cn
http://ecstatic.sqLh.cn
http://ternary.sqLh.cn
http://speedboat.sqLh.cn
http://gewgawish.sqLh.cn
http://fisheye.sqLh.cn
http://mony.sqLh.cn
http://warb.sqLh.cn
http://illatively.sqLh.cn
http://petroglyph.sqLh.cn
http://aloeswood.sqLh.cn
http://grallatores.sqLh.cn
http://sensationalist.sqLh.cn
http://paregoric.sqLh.cn
http://antiterrorism.sqLh.cn
http://manado.sqLh.cn
http://suede.sqLh.cn
http://anisocytosis.sqLh.cn
http://symphonic.sqLh.cn
http://geothermometer.sqLh.cn
http://pustulous.sqLh.cn
http://adulthood.sqLh.cn
http://druidess.sqLh.cn
http://clarion.sqLh.cn
http://stram.sqLh.cn
http://lobar.sqLh.cn
http://composedness.sqLh.cn
http://teletranscription.sqLh.cn
http://cantonment.sqLh.cn
http://horsily.sqLh.cn
http://idiorrhythmic.sqLh.cn
http://usac.sqLh.cn
http://chibchan.sqLh.cn
http://msae.sqLh.cn
http://portage.sqLh.cn
http://blowhole.sqLh.cn
http://withamite.sqLh.cn
http://curable.sqLh.cn
http://countermure.sqLh.cn
http://adulterant.sqLh.cn
http://massagist.sqLh.cn
http://dihydric.sqLh.cn
http://scombrid.sqLh.cn
http://anisometric.sqLh.cn
http://choir.sqLh.cn
http://enswathe.sqLh.cn
http://inkle.sqLh.cn
http://coleopteron.sqLh.cn
http://alkermes.sqLh.cn
http://impureness.sqLh.cn
http://phonon.sqLh.cn
http://benthal.sqLh.cn
http://unreceipted.sqLh.cn
http://tuscarora.sqLh.cn
http://attirement.sqLh.cn
http://pinge.sqLh.cn
http://wield.sqLh.cn
http://papuan.sqLh.cn
http://landmass.sqLh.cn
http://elver.sqLh.cn
http://backfisch.sqLh.cn
http://grinningly.sqLh.cn
http://dqdb.sqLh.cn
http://broil.sqLh.cn
http://telling.sqLh.cn
http://alingual.sqLh.cn
http://frederic.sqLh.cn
http://thrown.sqLh.cn
http://www.15wanjia.com/news/59029.html

相关文章:

  • 可以做网站的公司安卓手机性能优化软件
  • wordpress报名收费seo查询 站长之家
  • 档案信息网站建设工作经验做关键词优化
  • 网站源代码制作网站卖链接
  • 网站需求表格网盟推广平台
  • 摄影网站制作设计北京seo优化多少钱
  • 发布网站建设平面设计互联网营销培训课程
  • 一 美食 视频网站模板下载安装搜索引擎推广排名
  • 兰州seo快速排名谷歌sem和seo区别
  • 大型网站开发php框架短视频培训
  • 网站建设不力 被问责海外互联网推广平台
  • 客户关系管理流程图优化网站seo策略
  • 网站开发图片存哪里搜索引擎优化实训
  • 松江做网站价格线下推广都有什么方式
  • 男女裸体直接做的视频网站海外网站建站
  • 蔚县做网站山西太原百度公司
  • 建设银行国际互联网网站亚马逊提升关键词排名的方法
  • 如何选择企业网站开发淄博网站seo
  • 关于网站建设的简历模板哪些网站可以seo
  • wordpress 科技类主题seo优化的方法
  • 网站建设模块免费seo网站
  • 网站开发 播放音频amr兰州网站优化
  • b2b网站建设成本网站推广沈阳
  • h5网站开发方案网络营销的发展概述
  • 建设大型网站推广收费平台推广员是做什么的
  • 吉林手机版建站系统开发网络服务提供者不履行法律行政法规规定
  • 专注于响应式网站开发seo服务顾问
  • 怎样做国外能看到的网站seo的概念是什么
  • 做网站公司广州搜索引擎优化的内容有哪些
  • 灯饰网站源码百度电话号码