[PATCH 1/6] kobject_add_dir

From: Jun'ichi Nomura
Date: Fri Mar 03 2006 - 19:53:49 EST


This patch is part of dm/md sysfs dependency tree.

This adds kobject_add_dir() function which creates a subdirectory
for a given kobject.

Thanks,
--
Jun'ichi Nomura, NEC Solutions (America), Inc.
Adding kobject_add_dir() function which creates a subdirectory
for a given kobject.

Signed-off-by: Jun'ichi Nomura <j-nomura@xxxxxxxxxxxxx>

include/linux/kobject.h | 2 ++
lib/kobject.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+)

--- linux-2.6.16-rc5.orig/include/linux/kobject.h 2006-02-27 00:09:35.000000000 -0500
+++ linux-2.6.16-rc5/include/linux/kobject.h 2006-03-02 14:26:26.000000000 -0500
@@ -80,6 +80,8 @@ extern void kobject_unregister(struct ko
extern struct kobject * kobject_get(struct kobject *);
extern void kobject_put(struct kobject *);

+extern struct kobject * kobject_add_dir(struct kobject *, const char *);
+
extern char * kobject_get_path(struct kobject *, gfp_t);

struct kobj_type {
--- linux-2.6.16-rc5.orig/lib/kobject.c 2006-02-27 00:09:35.000000000 -0500
+++ linux-2.6.16-rc5/lib/kobject.c 2006-03-02 14:26:26.000000000 -0500
@@ -379,6 +379,43 @@ void kobject_put(struct kobject * kobj)
}


+static void dir_release(struct kobject *kobj)
+{
+ kfree(kobj);
+}
+
+static struct kobj_type dir_ktype = {
+ .release = dir_release,
+ .sysfs_ops = NULL,
+ .default_attrs = NULL,
+};
+
+/**
+ * kobject_add_dir - add sub directory of object.
+ * @parent: object in which a directory is created.
+ * @name: directory name.
+ *
+ * Add a plain directory object as child of given object.
+ */
+struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
+{
+ struct kobject *k;
+
+ if (!parent)
+ return NULL;
+
+ k = kzalloc(sizeof(*k), GFP_KERNEL);
+ if (!k)
+ return NULL;
+
+ k->parent = parent;
+ k->ktype = &dir_ktype;
+ kobject_set_name(k, name);
+ kobject_register(k);
+
+ return k;
+}
+
/**
* kset_init - initialize a kset for use
* @k: kset