类子系统是向用户空间导出信息的最好方法,

cjjust@cjjust-laptop:/sys/class/i2c-adapter$ ls

i2c-0  i2c-1  i2c-2  i2c-3  i2c-4  i2c-5

cjjust@cjjust-laptop:/sys/class/i2c-adapter$ ls -l

total 0

lrwxrwxrwx 1 root root 0 2010-09-14 08:46 i2c-0 -> http://www.cnblogs.com/devices/pci0000:00/0000:00:01.0/0000:01:00.0/i2c-0

lrwxrwxrwx 1 root root 0 2010-09-14 08:46 i2c-1 -> http://www.cnblogs.com/devices/pci0000:00/0000:00:01.0/0000:01:00.0/i2c-1

lrwxrwxrwx 1 root root 0 2010-09-14 08:46 i2c-2 -> http://www.cnblogs.com/devices/pci0000:00/0000:00:01.0/0000:01:00.0/i2c-2

lrwxrwxrwx 1 root root 0 2010-09-14 08:46 i2c-3 -> http://www.cnblogs.com/devices/pci0000:00/0000:00:01.0/0000:01:00.0/i2c-3

lrwxrwxrwx 1 root root 0 2010-09-14 08:46 i2c-4 -> http://www.cnblogs.com/devices/pci0000:00/0000:00:01.0/0000:01:00.0/i2c-4

lrwxrwxrwx 1 root root 0 2010-09-14 08:46 i2c-5 -> http://www.cnblogs.com/devices/pci0000:00/0000:00:01.0/0000:01:00.0/i2c-5

你希望看到的肯定是上面这部分的信息,而不是  sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/i2c-5之类的信息。

类有两个接口

class_simple接口和完整的类接口

struct class_simple *class_simple_create

struct class_device *class_simple_device_add

int class_simple_set_hotplug(struct class_simple *cs, int (*hotplug)(...));

完整类接口

struct class{

char *name;

struct class_attribute* 

struct class_device_attribute* 

int (*hotplug)

void (*release)

void (*class_release)

};

类设备:

struct class_device{

struct kobject kobj;

struct class *class;

struct device *dev;

void *class_data;

char class_id[BUS_ID_SIZE]

};

类接口:把一个类添加到类接口包含的类中,会调用add函数。

struct class_interface{

struct class *class;

int (*add) (struct class_device* cd);

void (*remove) (struct class_device *cd);

};

posted on 2010-09-14 11:42  灰太狼大王  阅读(457)  评论(0编辑  收藏  举报