]> git.hungrycats.org Git - linux/commitdiff
[PATCH] driver model updates (3/5)
authorPatrick Mochel <mochel@osdl.org>
Tue, 5 Feb 2002 08:36:52 +0000 (00:36 -0800)
committerPatrick Mochel <mochel@osdl.org>
Tue, 5 Feb 2002 08:36:52 +0000 (00:36 -0800)
Patch 3: Make default callbacks simpler.

I want to move as much to a 1 file/1 value model as possible. I haven't
come up with a clean way to enforce it except via social pressure.

This patch is a step in that direction. It:

- Reduces the output of 'power' to just the decimal state of the device
- Adds a 'name' file which exports just the device name
- Reduces the 'status' file to just export the bus ID. (This will change,
  since the bus ID is obvious based on what directory you're in, but it's
  another patch at another time)

drivers/base/interface.c

index b7c5c94db7100afe2160478f5f4fed6a21c8eac7..61a3fa5996566e4f6df02f57536b87ecff6c6274 100644 (file)
  */
 static ssize_t device_read_status(struct device * dev, char * page, size_t count, loff_t off)
 {
-       char *str = page;
-
-       if (off)
-               return 0;
-
-       str += sprintf(str,"Name:       %s\n",dev->name);
-       str += sprintf(str,"Bus ID:     %s\n",dev->bus_id);
-
-       return (str - page);
+       return off ? 0 : sprintf(page,"%s\n",dev->bus_id);
 }
 
 /**
@@ -84,17 +76,21 @@ static struct driver_file_entry device_status_entry = {
        store:          device_write_status,
 };
 
-static ssize_t
-device_read_power(struct device * dev, char * page, size_t count, loff_t off)
+static ssize_t device_read_name(struct device * dev, char * buf, size_t count, loff_t off)
 {
-       char    * str = page;
-
-       if (off)
-               return 0;
+       return off ? 0 : sprintf(buf,"%s\n",dev->name);
+}
 
-       str += sprintf(str,"State:      %d\n",dev->current_state);
+static struct driver_file_entry device_name_entry = {
+       name:   "name",
+       mode:   S_IRUGO,
+       show:   device_read_name,
+};
 
-       return (str - page);
+static ssize_t
+device_read_power(struct device * dev, char * page, size_t count, loff_t off)
+{
+       return off ? 0 : sprintf(page,"%d\n",dev->current_state);
 }
 
 static ssize_t
@@ -169,6 +165,7 @@ static struct driver_file_entry device_power_entry = {
 
 struct driver_file_entry * device_default_files[] = {
        &device_status_entry,
+       &device_name_entry,
        &device_power_entry,
        NULL,
 };