summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorPatrick Mochel <mochel@osdl.org>2002-07-31 22:07:33 -0700
committerPatrick Mochel <mochel@osdl.org>2002-07-31 22:07:33 -0700
commit137973c1a3ee75e3d28af550a5e33737ac9acc5b (patch)
treed9834c4900a6939f86074f8e893cd80bcb304379 /include/linux
parent9bb83ce6ec5908758f0999362c0297720ca9b5ac (diff)
driverfs: define struct driverfs_ops and remove struct device dependencies
In order to read/write attributes, you have to deal directly with the object that owns them. driverfs really wants to be generic and not deal directly with those objects. So, we create an intermediate layer that subsystems must implement that converts between the generic objects and the specific objects that own the attributes. This allows allows attributes to be exported for any object type. In doing so, it places the responsibility on the subsystems to do the following: - define their own object-specific attribute structures - define their own driverfs_ops - set the ops pointer in struct driver_dir_entry when creating an object's directory - do object reference counting on open() and close() - call the show() and store() callbacks of their attribute structure - convert between the generic objects and the specific objects from the struct driver_dir_entry and struct attribute pointers (using container_of) The implementation of this layer for struct device is intended to be used as an example of the interface. Because this layer of abstraction is now in place, we can move the device attribute structure into include/linux/device.h, and driverfs should be free of references to it completely.
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/device.h18
-rw-r--r--include/linux/driverfs_fs.h28
2 files changed, 27 insertions, 19 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index 670be49d1718..5dfa05c2dd3a 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -160,8 +160,6 @@ struct device {
void (*release)(struct device * dev);
};
-#define to_device(d) container_of(d, struct device, dir)
-
static inline struct device *
list_to_dev(struct list_head *node)
{
@@ -179,6 +177,22 @@ g_list_to_dev(struct list_head *g_list)
*/
extern int device_register(struct device * dev);
+
+/* driverfs interface for exporting device attributes */
+
+struct device_attribute {
+ struct attribute attr;
+ ssize_t (*show)(struct device * dev, char * buf, size_t count, loff_t off);
+ ssize_t (*store)(struct device * dev, const char * buf, size_t count, loff_t off);
+};
+
+#define DEVICE_ATTR(_name,_str,_mode,_show,_store) \
+struct device_attribute dev_attr_##_name = { \
+ .attr = {.name = _str, .mode = _mode }, \
+ .show = _show, \
+ .store = _store, \
+};
+
extern int device_create_file(struct device *device, struct device_attribute * entry);
extern void device_remove_file(struct device * dev, struct device_attribute * attr);
diff --git a/include/linux/driverfs_fs.h b/include/linux/driverfs_fs.h
index d00ee61fce07..d859f8c2e041 100644
--- a/include/linux/driverfs_fs.h
+++ b/include/linux/driverfs_fs.h
@@ -26,10 +26,21 @@
#ifndef _DRIVER_FS_H_
#define _DRIVER_FS_H_
+struct driver_dir_entry;
+struct attribute;
+
+struct driverfs_ops {
+ int (*open)(struct driver_dir_entry *);
+ int (*close)(struct driver_dir_entry *);
+ ssize_t (*show)(struct driver_dir_entry *, struct attribute *,char *, size_t, loff_t);
+ ssize_t (*store)(struct driver_dir_entry *,struct attribute *,const char *, size_t, loff_t);
+};
+
struct driver_dir_entry {
char * name;
struct dentry * dentry;
mode_t mode;
+ struct driverfs_ops * ops;
};
struct attribute {
@@ -37,23 +48,6 @@ struct attribute {
mode_t mode;
};
-struct device;
-
-struct device_attribute {
- struct attribute attr;
- ssize_t (*show)(struct device * dev, char * buf, size_t count, loff_t off);
- ssize_t (*store)(struct device * dev, const char * buf, size_t count, loff_t off);
-};
-
-#define DEVICE_ATTR(_name,_str,_mode,_show,_store) \
-struct device_attribute dev_attr_##_name = { \
- .attr = {.name = _str, .mode = _mode }, \
- .show = _show, \
- .store = _store, \
-};
-
-#define to_dev_attr(_attr) container_of(_attr,struct device_attribute,attr)
-
extern int
driverfs_create_dir(struct driver_dir_entry *, struct driver_dir_entry *);