From: Tejun Heo <htejun@gmail.com>
To: ebiederm@xmission.com, cornelia.huck@de.ibm.com, greg@kroah.com,
stern@rowland.harvard.edu, kay.sievers@vrfy.org,
linux-kernel@vger.kernel.org, htejun@gmail.com
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 02/22] sysfs: separate out sysfs-kobject.h and fs/sysfs/kobject.c
Date: Thu, 20 Sep 2007 17:05:39 +0900 [thread overview]
Message-ID: <11902755391604-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <11902755392688-git-send-email-htejun@gmail.com>
Sysfs is about to get a new interface which is independent from the
driver model and kobject. Create include sysfs-kobject.h and move all
kobject based interface into it. Also, create fs/sysfs/kobject.c
which is currently empty but will host compatibility interface
functions based on the new interface.
sysfs-kobject.h is automatically included from sysfs.h for
compatibility for now.
Signed-off-by: Tejun Heo <htejun@gmail.com>
---
fs/sysfs/Makefile | 2 +-
fs/sysfs/kobject.c | 15 +++
include/linux/sysfs-kobject.h | 200 +++++++++++++++++++++++++++++++++++++++++
include/linux/sysfs.h | 197 +++-------------------------------------
4 files changed, 230 insertions(+), 184 deletions(-)
create mode 100644 fs/sysfs/kobject.c
create mode 100644 include/linux/sysfs-kobject.h
diff --git a/fs/sysfs/Makefile b/fs/sysfs/Makefile
index 7a1ceb9..f58bce9 100644
--- a/fs/sysfs/Makefile
+++ b/fs/sysfs/Makefile
@@ -3,4 +3,4 @@
#
obj-y := inode.o file.o dir.o symlink.o mount.o bin.o \
- group.o
+ group.o kobject.o
diff --git a/fs/sysfs/kobject.c b/fs/sysfs/kobject.c
new file mode 100644
index 0000000..5ebd755
--- /dev/null
+++ b/fs/sysfs/kobject.c
@@ -0,0 +1,15 @@
+/*
+ * sysfs/kobject.c - compatibility sysfs interface based on kobject
+ *
+ * Copyright (c) 2001,2002 Patrick Mochel
+ * Copyright (c) 2004 Silicon Graphics, Inc.
+ *
+ * This is compatibility interface which wraps the primary interface
+ * defined in linux/sysfs.h to remain compatible with the original
+ * kobject based interface.
+ *
+ * Please see Documentation/filesystems/sysfs.txt for more information.
+ */
+
+#include <linux/sysfs.h>
+#include <linux/sysfs-kobject.h>
diff --git a/include/linux/sysfs-kobject.h b/include/linux/sysfs-kobject.h
new file mode 100644
index 0000000..4c821c2
--- /dev/null
+++ b/include/linux/sysfs-kobject.h
@@ -0,0 +1,200 @@
+/*
+ * sysfs-kobject.h - compatibility sysfs interface based on kobject
+ *
+ * Copyright (c) 2001,2002 Patrick Mochel
+ * Copyright (c) 2004 Silicon Graphics, Inc.
+ *
+ * This is compatibility interface which wraps the primary interface
+ * defined in linux/sysfs.h to remain compatible with the original
+ * kobject based interface. Please don't use in new codes.
+ *
+ * Please see Documentation/filesystems/sysfs.txt for more information.
+ */
+
+#ifndef _SYSFS_KOBJECT_H
+#define _SYSFS_KOBJECT_H
+
+#include <linux/sysfs.h>
+
+struct kobject;
+struct module;
+
+/* FIXME
+ * The *owner field is no longer used, but leave around
+ * until the tree gets cleaned up fully.
+ */
+struct attribute {
+ const char *name;
+ struct module *owner;
+ mode_t mode;
+};
+
+struct attribute_group {
+ const char *name;
+ struct attribute **attrs;
+};
+
+/**
+ * Use these macros to make defining attributes easier. See include/linux/device.h
+ * for examples..
+ */
+
+#define __ATTR(_name,_mode,_show,_store) { \
+ .attr = {.name = __stringify(_name), .mode = _mode }, \
+ .show = _show, \
+ .store = _store, \
+}
+
+#define __ATTR_RO(_name) { \
+ .attr = { .name = __stringify(_name), .mode = 0444 }, \
+ .show = _name##_show, \
+}
+
+#define __ATTR_NULL { .attr = { .name = NULL } }
+
+#define attr_name(_attr) (_attr).attr.name
+
+struct bin_attribute {
+ struct attribute attr;
+ size_t size;
+ void *private;
+ ssize_t (*read)(struct kobject *, struct bin_attribute *,
+ char *, loff_t, size_t);
+ ssize_t (*write)(struct kobject *, struct bin_attribute *,
+ char *, loff_t, size_t);
+ int (*mmap)(struct kobject *, struct bin_attribute *attr,
+ struct vm_area_struct *vma);
+};
+
+struct sysfs_ops {
+ ssize_t (*show)(struct kobject *, struct attribute *,char *);
+ ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
+};
+
+#ifdef CONFIG_SYSFS
+
+int __must_check sysfs_create_dir(struct kobject *kobj);
+void sysfs_remove_dir(struct kobject *kobj);
+int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name);
+int __must_check sysfs_move_dir(struct kobject *kobj,
+ struct kobject *new_parent_kobj);
+
+int __must_check sysfs_create_file(struct kobject *kobj,
+ const struct attribute *attr);
+int __must_check sysfs_chmod_file(struct kobject *kobj, struct attribute *attr,
+ mode_t mode);
+void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr);
+
+int __must_check sysfs_create_bin_file(struct kobject *kobj,
+ struct bin_attribute *attr);
+void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr);
+
+int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
+ const char *name);
+void sysfs_remove_link(struct kobject *kobj, const char *name);
+
+int __must_check sysfs_create_group(struct kobject *kobj,
+ const struct attribute_group *grp);
+void sysfs_remove_group(struct kobject *kobj,
+ const struct attribute_group *grp);
+int sysfs_add_file_to_group(struct kobject *kobj,
+ const struct attribute *attr, const char *group);
+void sysfs_remove_file_from_group(struct kobject *kobj,
+ const struct attribute *attr, const char *group);
+
+void sysfs_notify(struct kobject *kobj, char *dir, char *attr);
+
+#else /* CONFIG_SYSFS */
+
+static inline int sysfs_create_dir(struct kobject *kobj)
+{
+ return 0;
+}
+
+static inline void sysfs_remove_dir(struct kobject *kobj)
+{
+ ;
+}
+
+static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
+{
+ return 0;
+}
+
+static inline int sysfs_move_dir(struct kobject *kobj,
+ struct kobject *new_parent_kobj)
+{
+ return 0;
+}
+
+static inline int sysfs_create_file(struct kobject *kobj,
+ const struct attribute *attr)
+{
+ return 0;
+}
+
+static inline int sysfs_chmod_file(struct kobject *kobj,
+ struct attribute *attr, mode_t mode)
+{
+ return 0;
+}
+
+static inline void sysfs_remove_file(struct kobject *kobj,
+ const struct attribute *attr)
+{
+ ;
+}
+
+static inline int sysfs_create_bin_file(struct kobject *kobj,
+ struct bin_attribute *attr)
+{
+ return 0;
+}
+
+static inline int sysfs_remove_bin_file(struct kobject *kobj,
+ struct bin_attribute *attr)
+{
+ return 0;
+}
+
+static inline int sysfs_create_link(struct kobject *kobj,
+ struct kobject *target, const char *name)
+{
+ return 0;
+}
+
+static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
+{
+ ;
+}
+
+static inline int sysfs_create_group(struct kobject *kobj,
+ const struct attribute_group *grp)
+{
+ return 0;
+}
+
+static inline void sysfs_remove_group(struct kobject *kobj,
+ const struct attribute_group *grp)
+{
+ ;
+}
+
+static inline int sysfs_add_file_to_group(struct kobject *kobj,
+ const struct attribute *attr, const char *group)
+{
+ return 0;
+}
+
+static inline void sysfs_remove_file_from_group(struct kobject *kobj,
+ const struct attribute *attr, const char *group)
+{
+}
+
+static inline void sysfs_notify(struct kobject *kobj, char *dir, char *attr)
+{
+}
+
+#endif /* CONFIG_SYSFS */
+
+#endif /* _SYSFS_KOBJECT_H */
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 8af072e..38b73f9 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -1,8 +1,13 @@
/*
* sysfs.h - definitions for the device driver filesystem
*
- * Copyright (c) 2001,2002 Patrick Mochel
- * Copyright (c) 2004 Silicon Graphics, Inc.
+ * Primary sysfs interface based on sysfs_dirent
+ *
+ * If you're using sysfs directly instead of via driver model, please
+ * use this interface. It's independent from the driver model and
+ * kobject, cleaner and includes more features such as plugging of
+ * subtree while building it. Kobject-based compatibility interface
+ * is defined in linux/sysfs-kobject.h
*
* Please see Documentation/filesystems/sysfs.txt for more information.
*/
@@ -11,195 +16,16 @@
#define _SYSFS_H_
#include <linux/compiler.h>
-#include <linux/errno.h>
-#include <linux/list.h>
-#include <asm/atomic.h>
-
-struct kobject;
-struct module;
-
-/* FIXME
- * The *owner field is no longer used, but leave around
- * until the tree gets cleaned up fully.
- */
-struct attribute {
- const char *name;
- struct module *owner;
- mode_t mode;
-};
-
-struct attribute_group {
- const char *name;
- struct attribute **attrs;
-};
-
-
-
-/**
- * Use these macros to make defining attributes easier. See include/linux/device.h
- * for examples..
- */
-
-#define __ATTR(_name,_mode,_show,_store) { \
- .attr = {.name = __stringify(_name), .mode = _mode }, \
- .show = _show, \
- .store = _store, \
-}
-
-#define __ATTR_RO(_name) { \
- .attr = { .name = __stringify(_name), .mode = 0444 }, \
- .show = _name##_show, \
-}
-
-#define __ATTR_NULL { .attr = { .name = NULL } }
-
-#define attr_name(_attr) (_attr).attr.name
+#include <linux/types.h>
struct vm_area_struct;
-struct bin_attribute {
- struct attribute attr;
- size_t size;
- void *private;
- ssize_t (*read)(struct kobject *, struct bin_attribute *,
- char *, loff_t, size_t);
- ssize_t (*write)(struct kobject *, struct bin_attribute *,
- char *, loff_t, size_t);
- int (*mmap)(struct kobject *, struct bin_attribute *attr,
- struct vm_area_struct *vma);
-};
-
-struct sysfs_ops {
- ssize_t (*show)(struct kobject *, struct attribute *,char *);
- ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
-};
-
#ifdef CONFIG_SYSFS
-int __must_check sysfs_create_dir(struct kobject *kobj);
-void sysfs_remove_dir(struct kobject *kobj);
-int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name);
-int __must_check sysfs_move_dir(struct kobject *kobj,
- struct kobject *new_parent_kobj);
-
-int __must_check sysfs_create_file(struct kobject *kobj,
- const struct attribute *attr);
-int __must_check sysfs_chmod_file(struct kobject *kobj, struct attribute *attr,
- mode_t mode);
-void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr);
-
-int __must_check sysfs_create_bin_file(struct kobject *kobj,
- struct bin_attribute *attr);
-void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr);
-
-int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
- const char *name);
-void sysfs_remove_link(struct kobject *kobj, const char *name);
-
-int __must_check sysfs_create_group(struct kobject *kobj,
- const struct attribute_group *grp);
-void sysfs_remove_group(struct kobject *kobj,
- const struct attribute_group *grp);
-int sysfs_add_file_to_group(struct kobject *kobj,
- const struct attribute *attr, const char *group);
-void sysfs_remove_file_from_group(struct kobject *kobj,
- const struct attribute *attr, const char *group);
-
-void sysfs_notify(struct kobject *kobj, char *dir, char *attr);
-
-extern int __must_check sysfs_init(void);
+int __must_check sysfs_init(void);
#else /* CONFIG_SYSFS */
-static inline int sysfs_create_dir(struct kobject *kobj)
-{
- return 0;
-}
-
-static inline void sysfs_remove_dir(struct kobject *kobj)
-{
- ;
-}
-
-static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
-{
- return 0;
-}
-
-static inline int sysfs_move_dir(struct kobject *kobj,
- struct kobject *new_parent_kobj)
-{
- return 0;
-}
-
-static inline int sysfs_create_file(struct kobject *kobj,
- const struct attribute *attr)
-{
- return 0;
-}
-
-static inline int sysfs_chmod_file(struct kobject *kobj,
- struct attribute *attr, mode_t mode)
-{
- return 0;
-}
-
-static inline void sysfs_remove_file(struct kobject *kobj,
- const struct attribute *attr)
-{
- ;
-}
-
-static inline int sysfs_create_bin_file(struct kobject *kobj,
- struct bin_attribute *attr)
-{
- return 0;
-}
-
-static inline int sysfs_remove_bin_file(struct kobject *kobj,
- struct bin_attribute *attr)
-{
- return 0;
-}
-
-static inline int sysfs_create_link(struct kobject *kobj,
- struct kobject *target, const char *name)
-{
- return 0;
-}
-
-static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
-{
- ;
-}
-
-static inline int sysfs_create_group(struct kobject *kobj,
- const struct attribute_group *grp)
-{
- return 0;
-}
-
-static inline void sysfs_remove_group(struct kobject *kobj,
- const struct attribute_group *grp)
-{
- ;
-}
-
-static inline int sysfs_add_file_to_group(struct kobject *kobj,
- const struct attribute *attr, const char *group)
-{
- return 0;
-}
-
-static inline void sysfs_remove_file_from_group(struct kobject *kobj,
- const struct attribute *attr, const char *group)
-{
-}
-
-static inline void sysfs_notify(struct kobject *kobj, char *dir, char *attr)
-{
-}
-
static inline int __must_check sysfs_init(void)
{
return 0;
@@ -207,4 +33,9 @@ static inline int __must_check sysfs_init(void)
#endif /* CONFIG_SYSFS */
+/*
+ * Implicitly include kobject based compatibility interface for now
+ */
+#include <linux/sysfs-kobject.h>
+
#endif /* _SYSFS_H_ */
--
1.5.0.3
next prev parent reply other threads:[~2007-09-20 8:07 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-20 8:05 [PATCHSET 3/4] sysfs: divorce sysfs from kobject and driver model Tejun Heo
2007-09-20 8:05 ` [PATCH 04/22] sysfs: make SYSFS_COPY_NAME a flag Tejun Heo
2007-09-20 8:05 ` [PATCH 01/22] sysfs: make sysfs_root a pointer Tejun Heo
2007-09-20 8:05 ` [PATCH 06/22] sysfs: restructure addrm helpers Tejun Heo
2007-09-20 8:05 ` Tejun Heo [this message]
2007-09-20 8:05 ` [PATCH 05/22] sysfs: implement sysfs_find_child() Tejun Heo
2007-09-20 8:05 ` [PATCH 03/22] sysfs: make sysfs_new_dirent() normalize @mode and determine file type Tejun Heo
2007-09-20 8:05 ` [PATCH 14/22] sysfs: s/symlink/link/g Tejun Heo
2007-09-20 8:05 ` [PATCH 13/22] sysfs: implement sysfs_dirent based bin interface Tejun Heo
2007-09-20 8:05 ` [PATCH 09/22] sysfs: rename internal function sysfs_add_file() Tejun Heo
2007-09-20 8:05 ` [PATCH 08/22] sysfs: implement sysfs_dirent based directory interface Tejun Heo
2007-09-20 8:05 ` [PATCH 10/22] sysfs: drop kobj and attr from file related symbols Tejun Heo
2007-09-20 8:05 ` [PATCH 11/22] sysfs: implement sysfs_dirent based file interface Tejun Heo
2007-09-20 8:05 ` [PATCH 12/22] sysfs: drop kobj and attr from bin related symbols Tejun Heo
2007-09-20 8:05 ` [PATCH 07/22] sysfs: implement sysfs_dirent based remove interface sysfs_remove() Tejun Heo
2007-09-20 8:05 ` [PATCH 16/22] sysfs: convert group implementation to use sd-based interface Tejun Heo
2007-09-20 8:05 ` [PATCH 18/22] kobject: implement __kobject_set_name() Tejun Heo
2007-09-20 8:05 ` [PATCH 17/22] sysfs: s/sysfs_rename_mutex/sysfs_op_mutex/ and protect all tree modifying ops Tejun Heo
2007-09-20 8:05 ` [PATCH 15/22] sysfs: implement sysfs_dirent based link interface Tejun Heo
2007-09-20 8:05 ` [PATCH 21/22] sysfs: kill sysfs_hash_and_remove() Tejun Heo
2007-09-20 8:05 ` [PATCH 20/22] sysfs: kill now unused __sysfs_add_file() Tejun Heo
2007-09-20 8:05 ` [PATCH 22/22] sysfs: move sysfs_assoc_lock into fs/sysfs/kobject.c and make it static Tejun Heo
2007-09-20 8:05 ` [PATCH 19/22] sysfs: implement sysfs_dirent based rename - sysfs_rename() Tejun Heo
2007-09-25 22:17 ` [PATCHSET 3/4] sysfs: divorce sysfs from kobject and driver model Greg KH
2007-09-27 11:35 ` Tejun Heo
2007-09-27 19:25 ` Eric W. Biederman
2007-09-29 22:06 ` Tejun Heo
2007-10-05 6:23 ` Greg KH
2007-10-05 12:12 ` Eric W. Biederman
2007-10-05 13:03 ` [Devel] " Kirill Korotaev
2007-10-05 13:24 ` Eric W. Biederman
2007-10-09 22:51 ` Greg KH
2007-10-10 13:16 ` Eric W. Biederman
2007-10-10 20:44 ` Greg KH
2007-10-10 21:16 ` Eric W. Biederman
2007-10-16 22:18 ` sukadev
2007-10-16 23:54 ` Eric W. Biederman
2007-10-05 12:44 ` Eric W. Biederman
2007-10-09 22:53 ` Greg KH
2007-10-05 6:18 ` Greg KH
2007-10-05 8:00 ` Tejun Heo
2007-10-09 9:29 ` Cornelia Huck
2007-10-09 22:26 ` Greg KH
2007-10-09 23:20 ` Roland Dreier
2007-10-09 23:28 ` Greg KH
2007-10-10 9:11 ` Cornelia Huck
2007-10-10 9:05 ` Cornelia Huck
2007-10-09 22:48 ` Greg KH
2007-10-10 15:38 ` Alan Stern
2007-10-10 16:16 ` Cornelia Huck
2007-10-10 17:24 ` Martin Bligh
2007-10-10 17:30 ` Greg KH
2007-10-10 18:26 ` Martin Bligh
2007-10-10 18:44 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11902755391604-git-send-email-htejun@gmail.com \
--to=htejun@gmail.com \
--cc=cornelia.huck@de.ibm.com \
--cc=ebiederm@xmission.com \
--cc=greg@kroah.com \
--cc=kay.sievers@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox