一、分配cdev

cdev表示字符设备,使用cdev_alloc函数,cdev_alloc函数原型如下;

/**

* cdev_alloc() - allocate a cdev structure

*

* Allocates and returns a cdev structure, or NULL on failure.

*/

struct cdev *cdev_alloc(void)

得到cdev指针

二、初始化cdev

使用cdev_init函数,cdev_init的原型如下:

/**

* cdev_init() - initialize a cdev structure

* @cdev: the structure to initialize

* @fops: the file_operations for this device

*

* Initializes @cdev, remembering @fops, making it ready to add to the

* system with cdev_add().

*/

void cdev_init(struct cdev *cdev, const struct file_operations *fops)

将字符设备和设备的操作集合绑定在一起。

三、注册cdev

注册cdev用cdev_add函数,原型如下:

/**

* cdev_add() - add a char device to the system

* @p: the cdev structure for the device

* @dev: the first device number for which this device is responsible

* @count: the number of consecutive minor numbers corresponding to this

* device

*

* cdev_add() adds the device represented by @p to the system, making it

* live immediately. A negative error code is returned on failure.

*/

int cdev_add(struct cdev *p, dev_t dev, unsigned count)

四、注销cdev

用cdev_del函数

标签:struct,init,add,cdev,注册,linux,device,structure,设备

来源: https://www.cnblogs.com/Suzkfly/p/11768813.html

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐