struct class_device {
struct list_headnode;/*for internal use by the driver core only*/
struct kobjectkobj;/*for internal use by the driver core only*/
struct class* class;/*指向该设备所属的类,必须*/
dev_tdevt;/* dev_t, creates the sysfs "dev",for internal use by the driver core only*/
struct class_device_attribute *devt_attr;/*for internal use by the driver core only*/
struct class_device_attribute uevent_attr;
struct device* dev;/*指向此设备相关的device结构体,可选。若不为NULL,应是一个从类入口到/sys/devices下相应入口的符号连接,以便用户空间查找设备入口*/
void* class_data;/*私有数据指针*/
struct class_device*parent;/* parent of this child device, if there is one */
struct attribute_group ** groups;/* optional groups */
void(*release)(struct class_device *dev);
int(*uevent)(struct class_device *dev, char **envp,int num_envp, char *buffer, int buffer_size);
charclass_id[BUS_ID_SIZE];/*此类中的唯一的名字*/
};
/*类设备注册函数:*/
int class_device_register(struct class_device *cd);
void class_device_unregister(struct class_device *cd);
/*重命名一个已经注册的类设备入口:*/
int class_device_rename(struct class_device *cd, char *new_name);
/*类设备入口属性:*/
struct class_device_attribute {
struct attribute attr;
ssize_t (*show)(struct class_device *cls, char *buf);
ssize_t (*store)(struct class_device *cls, const char *buf,
size_t count);
};
CLASS_DEVICE_ATTR(_name, _mode, _show, _store);
/*创建和删除除struct class中设备默认属性外的属性*/
int class_device_create_file(struct class_device *cls, const struct class_device_attribute *attr);
void class_device_remove_file(struct class_device *cls, const struct class_device_attribute *attr);