inode获取设备号
来源:互联网 发布:windows 网络重置 编辑:程序博客网 时间:2024/06/10 21:40
当我们打开一个设备文件时,我们如何从该设备文件获取到设备文件的设备号呢?
当然是从代表一个设备文件的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; this
field 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, };
0 0
- inode获取设备号
- 建议直接从inode 获取设备号
- inode 设备文件
- iphone 获取 设备号
- 获取手机设备号
- 获取设备号
- 获取设备号
- ios 获取设备号
- 获取手机设备号
- 设备驱动中的inode(kernel-4.7)
- 获取各种设备号/UIDevice 设备信息
- Inode
- inode
- Inode
- Inode
- inode
- inode
- inode
- 数据库智能提示和源代码管理工具(支持SVN)SQLPrompt_7.0.0.40, RedGate_SQL_SourceControl.V3.0.13.4214
- Android-transulcent-status-bar总结
- gen already exists but is not a source folder. Convert to a source folder or rename it.
- HDOJ-2037今年暑假不AC
- HDU 1046 & POJ 1450 Gridland【有趣的数学题】
- inode获取设备号
- HDOJ1013大数处理
- poj Heavy Transportation
- 微信红包算法-php代码
- LARS 最小角回归算法程序代码使用归类使用
- Codeforces 614C Peter and Snow Blower
- nginx应用场景
- VC封装Ping命令的实现
- http请求报文介绍