Reimplement group interface in terms of sd-based interface in
fs/sysfs/kobject.c.

This patch doesn't introduce any behavior change to the original API.

Signed-off-by: Tejun Heo <[EMAIL PROTECTED]>
---
 fs/sysfs/Makefile  |    3 +-
 fs/sysfs/group.c   |   87 ----------------------------------------------------
 fs/sysfs/kobject.c |   72 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 89 deletions(-)
 delete mode 100644 fs/sysfs/group.c

diff --git a/fs/sysfs/Makefile b/fs/sysfs/Makefile
index f58bce9..b25ed0d 100644
--- a/fs/sysfs/Makefile
+++ b/fs/sysfs/Makefile
@@ -2,5 +2,4 @@
 # Makefile for the sysfs virtual filesystem
 #
 
-obj-y          := inode.o file.o dir.o symlink.o mount.o bin.o \
-                  group.o kobject.o
+obj-y          := inode.o file.o dir.o symlink.o mount.o bin.o kobject.o
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
deleted file mode 100644
index bb94f6a..0000000
--- a/fs/sysfs/group.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * fs/sysfs/group.c - Operations for adding/removing multiple files at once.
- *
- * Copyright (c) 2003 Patrick Mochel
- * Copyright (c) 2003 Open Source Development Lab
- *
- * This file is released undert the GPL v2. 
- *
- */
-
-#include <linux/kobject.h>
-#include <linux/module.h>
-#include <linux/dcache.h>
-#include <linux/namei.h>
-#include <linux/err.h>
-#include "sysfs.h"
-
-
-static void remove_files(struct sysfs_dirent *dir_sd,
-                        const struct attribute_group *grp)
-{
-       struct attribute *const* attr;
-
-       for (attr = grp->attrs; *attr; attr++)
-               sysfs_hash_and_remove(dir_sd, (*attr)->name);
-}
-
-static int create_files(struct sysfs_dirent *dir_sd,
-                       const struct attribute_group *grp)
-{
-       struct attribute *const* attr;
-       int error = 0;
-
-       for (attr = grp->attrs; *attr && !error; attr++)
-               error = __sysfs_add_file(dir_sd, *attr, SYSFS_FILE);
-       if (error)
-               remove_files(dir_sd, grp);
-       return error;
-}
-
-
-int sysfs_create_group(struct kobject * kobj,
-                      const struct attribute_group * grp)
-{
-       struct sysfs_dirent *sd;
-       int error;
-
-       BUG_ON(!kobj || !kobj->sd);
-
-       if (grp->name) {
-               sd = sysfs_add_dir(kobj->sd, grp->name, SYSFS_DIR_MODE, kobj);
-               if (IS_ERR(sd))
-                       return PTR_ERR(sd);
-       } else
-               sd = kobj->sd;
-       sysfs_get(sd);
-       error = create_files(sd, grp);
-       if (error) {
-               if (grp->name)
-                       sysfs_remove(sd);
-       }
-       sysfs_put(sd);
-       return error;
-}
-
-void sysfs_remove_group(struct kobject * kobj, 
-                       const struct attribute_group * grp)
-{
-       struct sysfs_dirent *dir_sd = kobj->sd;
-       struct sysfs_dirent *sd;
-
-       if (grp->name) {
-               sd = sysfs_get_dirent(dir_sd, grp->name);
-               BUG_ON(!sd);
-       } else
-               sd = sysfs_get(dir_sd);
-
-       remove_files(sd, grp);
-       if (grp->name)
-               sysfs_remove(sd);
-
-       sysfs_put(sd);
-}
-
-
-EXPORT_SYMBOL_GPL(sysfs_create_group);
-EXPORT_SYMBOL_GPL(sysfs_remove_group);
diff --git a/fs/sysfs/kobject.c b/fs/sysfs/kobject.c
index 7400575..0a0d583 100644
--- a/fs/sysfs/kobject.c
+++ b/fs/sysfs/kobject.c
@@ -413,6 +413,78 @@ void sysfs_remove_link(struct kobject * kobj, const char * 
name)
 }
 EXPORT_SYMBOL_GPL(sysfs_remove_link);
 
+/*
+ * group interface
+ */
+static void remove_files(struct sysfs_dirent *dir_sd,
+                        const struct attribute_group *grp)
+{
+       struct attribute *const* attr;
+
+       for (attr = grp->attrs; *attr; attr++)
+               sysfs_remove_child(dir_sd, (*attr)->name);
+}
+
+static int create_files(struct kobject *kobj, struct sysfs_dirent *dir_sd,
+                       const struct attribute_group *grp)
+{
+       struct attribute *const* attr;
+       struct sysfs_dirent *sd;
+
+       for (attr = grp->attrs; *attr; attr++) {
+               sd = sysfs_add_file(dir_sd, (*attr)->name, (*attr)->mode,
+                                   sysfs_attr_fops(kobj), (void *)*attr);
+               if (IS_ERR(sd)) {
+                       remove_files(dir_sd, grp);
+                       return PTR_ERR(sd);
+               }
+       }
+
+       return 0;
+}
+
+int sysfs_create_group(struct kobject *kobj, const struct attribute_group *grp)
+{
+       struct sysfs_dirent *sd;
+       int error;
+
+       BUG_ON(!kobj || !kobj->sd);
+
+       if (grp->name) {
+               sd = sysfs_add_dir(kobj->sd, grp->name,
+                                  SYSFS_DIR_MODE | SYSFS_COPY_NAME, kobj);
+               if (IS_ERR(sd))
+                       return PTR_ERR(sd);
+       } else
+               sd = kobj->sd;
+       sysfs_get(sd);
+       error = create_files(kobj, sd, grp);
+       if (error && grp->name)
+               sysfs_remove(sd);
+       sysfs_put(sd);
+       return error;
+}
+EXPORT_SYMBOL_GPL(sysfs_create_group);
+
+void sysfs_remove_group(struct kobject *kobj, const struct attribute_group 
*grp)
+{
+       struct sysfs_dirent *dir_sd = kobj->sd;
+       struct sysfs_dirent *sd;
+
+       if (grp->name) {
+               sd = sysfs_get_dirent(dir_sd, grp->name);
+               BUG_ON(!sd);
+       } else
+               sd = sysfs_get(dir_sd);
+
+       remove_files(sd, grp);
+       if (grp->name)
+               sysfs_remove(sd);
+
+       sysfs_put(sd);
+}
+EXPORT_SYMBOL_GPL(sysfs_remove_group);
+
 /**
  * sysfs_add_file_to_group - add an attribute file to a pre-existing group.
  * @kobj: object we're acting for.
-- 
1.5.0.3


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to