cdev 结构体的dev_t 定义了设备号为32 位,其中12位为主设备号,20 位为次设备号。

MAJOR(dev_t dev);  MINOR(dev_t dev);通过 MKDEV(int major,int minor)生成dev_t.

cdev_init()用于初始化cdev,并建立cdev和file_opration之间的关系连接。

cdev_alloc()函数用于动态申请一个cdev内存:struct cdev *p=kzmalloc(sizeof(struct cdev),GFP_KERNEL);

 

cdev_add,cdev_del分别向系统添加和删除一个cdev,完成注册和注销,分别在模块加载函数 和模块卸载函数中。

 

int register_chrdev_region(dev_t from,unsigned count, const char *name);用于已知设备号的情况。

int alloc_chrdev_region(dev_t *dev,unsigned base minor,unsigned count,const char *name);

用于设备号未知的情况,动态申请

释放设备号:unregister_chrdev_region(dev_t from,unsigned count);

 

ssize_t xx_read(struct file *filp,char _user *buf,size_t count ,loff_t *f_pos):copy_to_user();

ssize_t xx_write(struct file *filp,char _user *buf,size_t count ,loff_t *f_pos):copy_from_user();

long xx_ioctl(struct file *filp,unsigned int cmd ,unsigned long arg)

 

posted on 2016-09-30 18:28  碧海蓝天88888888  阅读(113)  评论(0编辑  收藏  举报