All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adam Belay <ambx1@netscape.net>
To: Patrick Mochel <mochel@osdl.org>
Cc: Greg KH <greg@kroah.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] 2.5.31 driverfs: patch for your consideration
Date: Fri, 16 Aug 2002 22:36:00 +0000	[thread overview]
Message-ID: <3D5D7E50.4030307@netscape.net> (raw)

Here's the patch as we discussed.

diff -ur --new-file a/drivers/base/interface.c b/drivers/base/interface.c
--- a/drivers/base/interface.c    Wed Aug 14 17:09:28 2002
+++ b/drivers/base/interface.c    Fri Aug 16 22:03:18 2002
@@ -88,8 +88,20 @@
 static DEVICE_ATTR(power,"power",S_IWUSR | S_IRUGO,
            device_read_power,device_write_power);
 
+
+static ssize_t device_read_driver(struct device * dev, char * buf, 
size_t count, loff_t off)
+{
+    if (dev->driver)
+        return off ? 0 : sprintf(buf,"%s\n",dev->driver->name);
+    else
+        return 0;
+}
+
+static DEVICE_ATTR(driver,"driver",S_IRUGO,device_read_driver,NULL);
+
 struct device_attribute * device_default_files[] = {
     &dev_attr_name,
     &dev_attr_power,
+    &dev_attr_driver,
     NULL,
 };





Also if You're interested here's the write support for "driver".

diff -ur --new-file a/drivers/base/base.h b/drivers/base/base.h
--- a/drivers/base/base.h    Fri Aug 16 12:20:18 2002
+++ b/drivers/base/base.h    Fri Aug 16 22:17:26 2002
@@ -26,3 +26,5 @@
 
 extern int driver_attach(struct device_driver * drv);
 extern void driver_detach(struct device_driver * drv);
+extern int do_driver_detach(struct device * dev, struct device_driver * 
drv);
+extern int do_driver_attach(struct device * dev, void * data);
diff -ur --new-file a/drivers/base/core.c b/drivers/base/core.c
--- a/drivers/base/core.c    Wed Aug 14 17:09:28 2002
+++ b/drivers/base/core.c    Fri Aug 16 22:16:30 2002
@@ -98,7 +98,7 @@
 
 static void device_detach(struct device * dev)
 {
-    struct device_driver * drv;
+    struct device_driver * drv;
 
     if (dev->driver) {
         lock_device(dev);
@@ -117,7 +117,7 @@
     }
 }
 
-static int do_driver_attach(struct device * dev, void * data)
+int do_driver_attach(struct device * dev, void * data)
 {
     struct device_driver * drv = (struct device_driver *)data;
     int error = 0;
@@ -134,7 +134,7 @@
     return bus_for_each_dev(drv->bus,drv,do_driver_attach);
 }
 
-static int do_driver_detach(struct device * dev, struct device_driver * 
drv)
+int do_driver_detach(struct device * dev, struct device_driver * drv)
 {
     lock_device(dev);
     if (dev->driver == drv) {
diff -ur --new-file a/drivers/base/interface.c b/drivers/base/interface.c
--- a/drivers/base/interface.c    Fri Aug 16 22:06:41 2002
+++ b/drivers/base/interface.c    Fri Aug 16 22:15:29 2002
@@ -8,6 +8,7 @@
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/stat.h>
+#include "base.h"
 
 static ssize_t device_read_name(struct device * dev, char * buf, size_t 
count, loff_t off)
 {
@@ -97,7 +98,44 @@
         return 0;
 }
 
-static DEVICE_ATTR(driver,"driver",S_IRUGO,device_read_driver,NULL);
+struct device_driver * find_driver_by_name(struct bus_type * bus, char 
* name)
+{
+    struct list_head * pos;
+    struct device_driver * drv;
+    list_for_each (pos, &bus->drivers)
+    {
+        drv = list_entry(pos, struct device_driver, bus_list);
+        if (!strncmp(drv->name,name,strlen(name) - 1))
+            return drv;
+
+    }
+    return NULL;
+
+}
+
+static ssize_t device_write_driver(struct device * dev, char * buf, 
size_t count, loff_t off)
+{
+    struct device_driver * drv = NULL;
+    int error = 0;
+    if (off)
+        return 0;
+    if (!dev->bus)
+        return count;
+    if (!dev->driver)
+    {
+        drv = find_driver_by_name(dev->bus, buf);
+        if (drv)
+            error = do_driver_attach(dev,drv);
+
+    } else if (!strnicmp(buf,"remove",6))
+    {
+        error = do_driver_detach(dev, dev->driver);
+    }
+    return error < 0 ? error : count;
+}
+
+static DEVICE_ATTR(driver,"driver",S_IWUSR | S_IRUGO,
+           device_read_driver,device_write_driver);
 
 struct device_attribute * device_default_files[] = {
     &dev_attr_name,



I look forward to hearing from you.

Thanks,
Adam

PS:   Would you be interested in a patch that would port the pnpbios 
driver to the driver model?


             reply	other threads:[~2002-08-17  2:29 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-16 22:36 Adam Belay [this message]
2002-08-17  3:06 ` [PATCH] 2.5.31 driverfs: patch for your consideration Greg KH
2002-08-17 14:10   ` Adam Belay
2002-08-17 19:03     ` Greg KH
2002-08-17 22:32       ` Adam Belay
2002-08-18 21:46         ` Greg KH
2002-08-18 21:47         ` Greg KH
2002-08-23 17:45           ` [PATCH] 2.5.31 port PnP BIOS to the driver model Adam Belay
2002-08-27 21:40           ` [PATCH] 2.5.32 port PnP BIOS to the driver model RESEND #1 Adam Belay
2002-08-28  5:14             ` Greg KH
2002-08-29 20:36               ` Adam Belay
2002-08-30  5:28                 ` Greg KH
2002-08-30 14:47                   ` Adam Belay
2002-08-30 14:48                   ` [PATCH] 2.5.32 port PnP BIOS to the driver model - ready for inclusion Adam Belay
2002-08-19 18:10         ` [PATCH] 2.5.31 driverfs: patch for your consideration Patrick Mochel
2002-08-19 15:35           ` Adam Belay
2002-08-17 13:52 ` David D. Hagood
2002-08-17 19:43 ` Alan Cox
2002-08-19 18:19 ` Patrick Mochel
2002-08-19 15:50   ` Adam Belay
2002-08-19 19:59     ` Greg KH
2002-08-19 21:54       ` Adam Belay
2002-08-20  3:32         ` Greg KH
2002-08-20  6:51           ` jw schultz
2002-08-20 18:32             ` 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=3D5D7E50.4030307@netscape.net \
    --to=ambx1@netscape.net \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mochel@osdl.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.