• Patrick Mochel's avatar
    [sysfs] Add attribute groups · 7bf68565
    Patrick Mochel authored
    Attribute groups provide the ability to register a set of sysfs attributes
    for a kobject all at once, and optionally create a subdirectory to hold 
    them.
    
    The constructs are simple:
                                                                                                             
    struct attribute_group {
            char                    * name;
            struct attribute        * attrs;
    };
    
    int sysfs_create_group(struct kobject *, struct attribute_group *);
    void sysfs_remove_group(struct kobject *, struct attribute_group *);
    
    
    If ->name is not NULL, then we create a subdirectory of that name to hold
    the attributes. We then iterate over ->attrs and create a file for each,
    in the subdirectory if we created one.
    
    This prevents one from having to register a kobject (and define a new
    kobj_type) to create a subdirectory for a group of attributes. Attributes
    currently defined in that way can be converted to use attribute_groups
    easily, with one caveat:
    
    The attributes that are added for a kobject, even if in a subdirectory,
    must be declared as the high-level attribute type (with an embedded struct
    attribute) for the kobject, and conform to the kobj_type's calling
    convention for reading/writing attributes.
    
    The kobject that you're creating attributes for owns the directory, and
    will assume ownership of the subdirectory. sysfs will reference this
    kobject, and it's kobj_type, when the attribute file is opened to
    determine the methods for reading/writing the attribute.
    
    sysfs will call the kobj_type's show()/store() methods, which will convert
    the kobject into a high-level object type, and convert the attribute into
    a high-level attribute type, which (depending on the kobj_type) is
    expected to have a show() and/or store() method.
    
    Note that this makes it only slightly easier to create attributes en masse,
    though it is a bit technically superior, since it doesn't require a new 
    kobj_type and kobject register. More will come in this area.. 
    7bf68565
Makefile 119 Bytes