类是设备的一个高级视图,实现了底层细节。通过对设备进行分类,同类代码可共享,减少了内核代码的冗余。
struct class { const char *name; /* class的名称,会在“/sys/class/”目录下体现 */ struct class_attribute *class_attrs; struct device_attribute *dev_attrs; /* 该class下每个设备的attribute */ struct kobject *dev_kobj; /* 当该class下有设备发生变化时,会调用class的uevent回调函数 */ int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); char *(*devnode)(struct device *dev, mode_t *mode); void (*class_release)(struct class *class); void (*dev_release)(struct device *dev); int (*suspend)(struct device *dev, pm_message_t state); int (*resume)(struct device *dev); struct class_private *p; }; int class_register(struct class *cls); void class_unregister(struct class *cls); CLASS_ATTR(name, mode, show, store); int class_create_file(struct class *cls,const struct class_attribute *attr); void class_remove_file(struct class *cls,const struct class_attribute *attr); Putting It All TogetherLinux设备驱动之设备模型(5)
内容版权声明:除非注明,否则皆为本站原创文章。