字符设备注册

1、内核中使用struct cdev结构来表示字符设备。

2、获取一个独立的cdev结构:

  struct cdev *my_cdev=cdev_alloc();

  my_cdev->ops= &my_fops;

3、初始化一个已经分配到的cdev结构:

  void cdev_init(struct cdev *cdev, struct file_oprations *fops);

4、告诉内核该结构的信息:

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

  内核一旦得到该结构的信息,则就会对该设备进行操作,所以在设备没有完全准备好的情况下,不要调用该命令。

5、移除一个字符设备:

  void cdev_del(struct cdev *dev);

原文地址:https://www.cnblogs.com/hxu7373/p/3491729.html