首页 > 代码库 > 字符设备集中编程模型

字符设备集中编程模型

1.重要数据结构

  - struct file_operaions

  - struct inode

  - struct file

2.杂设备驱动模板:struct miscdevice

  - 注册:int misc_register(struct miscdevice *misc)

  - 注销:int misc_deregister(struct miscdevice *misc)

3.早期标准字符设备驱动模板:

  - 注册:int register_chrdev(unsigned int major, const char *name, const struct file_operations *fops)

  - 注销:void unregister_chrdev(unsigned int major, const char *name)

4.Linux2.6标准字符设备驱动模型

  - 核心数据结构:struct cdev

  - 注册:int register_chrdev_region(dev_t first, unsigned int count, char *name)

  - 注销:void unregister_chrdev_region(dev_t first, unsigned int count)

5.自动创建设备文件

  - 核心数据:struct class:设备类对象

  - struct class* class_create

  - struct device *device

6.ioctl控制接口

  - 定义命令:_IO(type, nr), _IOR(type, nr, datatype), _IOW(type, nr, datatype), _IOWR(type, nr, datatype)

字符设备集中编程模型