struct list_head entry;
struct kobject * parent;
struct subsystem * subsys;
- struct sysfs_dir dir;
+ struct dentry * dentry;
};
void kobject_init(struct kobject *);
subsystem (the embedder objects in which kobjects live) are all of the
same type. The interface looks like:
+
struct subsystem {
struct kobject kobj;
struct list_head list;
struct rw_semaphore rwsem;
struct subsystem * parent;
- struct sysfs_ops * sysfs_ops;
void (*release)(struct kobject *);
+ struct sysfs_ops * sysfs_ops;
+ struct attribute ** default_attrs;
};
void subsystem_init(struct subsystem *);
all kobjects.
+Default Attributes
+
+Most subsystems have a set of default attributes associated with an
+object that registers with them. A subsystem definition may contain a
+NULL-terminated array of attributes that will be exported when an
+object is registered with the subsystem.
+
+
Reference Counting
All objects contain reference counts. All functions accessing objects
#include <linux/stat.h>
/**
+ * kobject_populate_dir - populate directory with attributes.
+ * @kobj: object we're working on.
+ *
+ * Most subsystems have a set of default attributes that
+ * are associated with an object that registers with them.
+ * This is a helper called during object registration that
+ * loops through the default attributes of the subsystem
+ * and creates attributes files for them in sysfs.
+ *
+ */
+
+static int kobject_populate_dir(struct kobject * kobj)
+{
+ struct subsystem * s = kobj->subsys;
+ struct attribute * attr;
+ int error = 0;
+ int i;
+
+ if (s && s->default_attrs) {
+ for (i = 0; (attr = s->default_attrs[i]); i++) {
+ if ((error = sysfs_create_file(kobj,attr)))
+ break;
+ }
+ }
+ return error;
+}
+
+/**
* kobject_init - initialize object.
* @kobj: object in question.
*/
int kobject_register(struct kobject * kobj)
{
+ int error = 0;
struct subsystem * s = subsys_get(kobj->subsys);
struct kobject * parent = kobject_get(kobj->parent);
pr_debug("kobject %s: registering\n",kobj->name);
+ if (parent)
+ pr_debug(" parent is %s\n",parent->name);
if (s) {
down_write(&s->rwsem);
if (parent)
}
up_write(&s->rwsem);
}
- return sysfs_create_dir(kobj);
+ error = sysfs_create_dir(kobj);
+ if (!error) {
+ error = kobject_populate_dir(kobj);
+ if (error)
+ sysfs_remove_dir(kobj);
+ }
+ return error;
}
/**
if (s->parent)
s->kobj.parent = &s->parent->kobj;
pr_debug("subsystem %s: registering\n",s->kobj.name);
+ if (s->parent)
+ pr_debug(" parent is %s\n",s->parent->kobj.name);
return kobject_register(&s->kobj);
}