inode获取设备号
2016-07-22 10:51
435 查看
当我们打开一个设备文件时,我们如何从该设备文件获取到设备文件的设备号呢?
当然是从代表一个设备文件的struct inode中找到代表设备文件的dev_t啦!
struct inode
field contains a pointer to that structure when the inode refers to a char device
file.
struct cdev 是内核内部的结构,其作用是用来表示一字符设备(即c前缀的原因),该域包含了一个指针,当该节点指向一个设备文件时,该指针指向那个设备文件的节点。
static struct file_operations chery_drv_fops = { .owner = THIS_MODULE, /* 这是一个宏,指向编译模块时自动创建的__this_module变量 */ .open = chery_drv_open, };
当然是从代表一个设备文件的struct inode中找到代表设备文件的dev_t啦!
struct inode
struct inode { ... <span style="font-size:18px;color:#ff0000;">dev_ti_rdev; /*设备号*/</span> ... const struct inode_operations*i_op; const struct file_operations*i_fop;/* former ->i_op->default_file_ops */ ... struct list_headi_devices; union { struct pipe_inode_info*i_pipe; struct block_device*i_bdev; struct cdev*i_cdev; /*此处指向的内容的次设备号是0*/ }; .... }
struct file_operations { struct module *owner; l ... <span style="font-size:18px;color:#ff0000;">int (*open) (struct inode *, struct file *);</span> int (*flush) (struct file *, fl_owner_t id); int (*release) (struct inode *, struct file *); ... };
struct cdev *i_cdev
struct cdev is the kernel’s internal structure that represents char devices; thisfield contains a pointer to that structure when the inode refers to a char device
file.
struct cdev 是内核内部的结构,其作用是用来表示一字符设备(即c前缀的原因),该域包含了一个指针,当该节点指向一个设备文件时,该指针指向那个设备文件的节点。
<pre name="code" class="plain">static int chery_drv_open(struct inode *inode, struct file *file) { dev_t cdev = inode->i_cdev->dev; printk("minor %d\n",MINOR(inode->i_rdev<span style="font-family: Arial, Helvetica, sans-serif;">));</span>
return 0; }
static struct file_operations chery_drv_fops = { .owner = THIS_MODULE, /* 这是一个宏,指向编译模块时自动创建的__this_module变量 */ .open = chery_drv_open, };
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍