1.±³¾°
¡¡¡¡Ëæ×ÅÉ豸ÍØÆ˽ṹԽÀ´Ô½¸´ÔÓ£¬ÐèҪΪÄں˽¨Á¢Ò»¸öͳһµÄÉ豸ģÐÍ£¬¶Ôϵͳ½á¹¹×öÒ»°ãÐԵijéÏóÃèÊö¡£
¡¡¡¡ÓÐÁ˸óéÏó½á¹¹£¬¿ÉÖ§³Ö¶àÖÖ²»Í¬µÄÈÎÎñ£º
¡¡¡¡a) µçÔ´¹ÜÀí Íê³ÉµçÔ´¹ÜÀí¹¤×÷ÐèÒª¶Ôϵͳ½á¹¹µÄÀí½â£¬ÇÒÓÐÑϸñµÄ˳Ðò£¬È磺һ¸öUSBËÞÖ÷ÊÊÅäÆ÷£¬ÔÚ´¦ÀíÍêËùÓÐÓëÆäÏàÁ¬½ÓµÄÉ豸ÃæÇ°ÊDz»Äܹرյģ»
¡¡¡¡b) ÓëÓû§¿Õ¼äͨÐÅ ÓÉ/sysfsÐéÄâÎļþϵͳչʾÉ豸µÄÊôÐÔ
¡¡¡¡c) ÈȲå°ÎÉ豸
¡¡¡¡d) ¶ÔÏóÉúÃüÖÜÆÚ
2.sysfs ÐéÄâÎļþϵͳ
¡¡¡¡sysfs ÊÇÒ»¸öÌØÊâµÄÎļþϵͳ£¬ÀàËÆÓÚ/proc¡£sysfs²»½öÏó/procÒ»ÑùÔÊÐíÓû§¿Õ¼ä·ÃÎÊÄں˵ÄÊý¾Ý£¬¶øÇÒËüÒÔ¸ü½á¹¹»¯µÄ·½Ê½ÏòÓû§ÌṩÄÚºËÊý¾ÝÐÅÏ¢¡£
¡¡¡¡sysfsµÄÒ»¸öÄ¿µÄ¾ÍÊÇչʾÉ豸Çý¶¯Ä£ÐÍÖи÷×é¼þµÄ²ã´Î¹Øϵ¡£Æ䶥¼¶Ä¿Â¼°üÀ¨£º
[code]bordercolorlight = "black" bordercolordark = "#FFFFFF" align="center">
a) block
b) device
c) bus
d) drivers
e) class
f) power
g) firmware[/code]
¡¡¡¡Ã¿¸öĿ¼´ú±íÒ»¸ökobject¶ÔÏó£¬Ã¿¸öÎļþ´ú±íkobjectµÄÊôÐÔ¡£
3. Kobject¡¢Kset ºÍ subsystem
¡¡¡¡3.1 Kobject
¡¡¡¡Kobject ÊÇ×é³ÉÉ豸ģÐ͵Ļù±¾½á¹¹¡£ÀàËÆÓÚC++ÖеĻùÀ࣬ËüǶÈëÓÚ¸ü´óµÄ¶ÔÏóµÄ¶ÔÏóÖÐ--ËùνµÄÈÝÆ÷--ÓÃÀ´ÃèÊöÉ豸ģÐ͵Ä×é¼þ¡£Èçbus, devices, drivers ¶¼ÊǵäÐ͵ÄÈÝÆ÷¡£
¡¡¡¡ÈÝÆ÷ÓÐÁËkobjectÖ®ºó£¬ÔÊÐíÄںˣº
¡¡¡¡a) ±£´æ¶ÔÈÝÆ÷µÄÒýÓüÆÊý
¡¡¡¡b) ±£´æÈÝÆ÷Ö®¼äµÄ²ã´Î¹Øϵ
¡¡¡¡c) Ϊÿ¸öÈÝÆ÷µÄÊôÐÔÌṩһ¸öÓû§ÊÓͼ
[code]bordercolorlight = "black" bordercolordark = "#FFFFFF" align="center">
struct kobject{
char * k_name;
char name[20];
struct k_ref kref;
struct list_head entry;
struct kobject * parent;
struct kset * kset;
struct ktype * ktype;
struct dentry * dentry;
};
struct kobj_type{
void (*release) (struct kobject *);
struct sysfs_ops *sysfs_ops;
struct attribute **default_attrs;
};[/code]
¡¡¡¡3.2 Kset
¡¡¡¡Ò»¸öksetÊÇǶÈëÏàͬÀàÐͽṹµÄkobject¼¯ºÏ¡£
[code]bordercolorlight = "black" bordercolordark = "#FFFFFF" align="center">
struct kset{
struct subsystem * subsys;
struct kobj_type ktype;
struct list_head list;
struct kobject kobj;
struct kset_hotplug_ops * hotplug_ops;
};[/code]
¡¡¡¡3.3 Subsystem
¡¡¡¡Ò»ÏµÁеÄkset¾Í×é³ÉÁËsubsystem. subsystem¿ÉÒÔ°üÀ¨²»Í¬ÀàÐ͵Äkset£¬ ËüÖ»ÓÐÁ½¸ö³ÉÔ±
[code]bordercolorlight = "black" bordercolordark = "#FFFFFF" align="center">
struct subsystem{
struct kset kset;
struct rw_semaphore rwsem;
};[/code]
4.É豸Çý¶¯Ä£Ð͵Ä×é¼þ
¡¡¡¡4.1 device
¡¡¡¡4.2 drive
¡¡¡¡4.3 bus
¡¡¡¡4.4 class