linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org, linux-hotplug-devel@lists.sourceforge.net
Subject: [PATCH] add sysfs class support for raw devices [06/10]
Date: Thu, 15 Jan 2004 20:42:41 +0000	[thread overview]
Message-ID: <20040115204241.GG22199@kroah.com> (raw)
In-Reply-To: <20040115204209.GF22199@kroah.com>


This adds class/raw/ support for all raw devices.  It also provides a
symlink to the block device that the raw device is mapped to.  For
example:

$ tree /sys/class/raw/
/sys/class/raw/
|-- raw1
|   |-- dev
|   `-- device -> ../../../block/sda
|-- raw2
|   |-- dev
|   `-- device -> ../../../block/sda/sda2
`-- rawctl
    `-- dev


Note, in order to get that symlink, I had to export get_gendisk() so that
modules can use it.  I hope this is ok with everyone.

This is based on a patch originally written by 
Leann Ogasawara <ogasawara@osdl.org>



diff -Nru a/drivers/block/genhd.c b/drivers/block/genhd.c
--- a/drivers/block/genhd.c	Thu Jan 15 11:05:57 2004
+++ b/drivers/block/genhd.c	Thu Jan 15 11:05:57 2004
@@ -224,6 +224,8 @@
 	return  kobj ? to_disk(kobj) : NULL;
 }
 
+EXPORT_SYMBOL(get_gendisk);
+
 #ifdef CONFIG_PROC_FS
 /* iterator */
 static void *part_start(struct seq_file *part, loff_t *pos)
diff -Nru a/drivers/char/raw.c b/drivers/char/raw.c
--- a/drivers/char/raw.c	Thu Jan 15 11:05:47 2004
+++ b/drivers/char/raw.c	Thu Jan 15 11:05:47 2004
@@ -17,6 +17,8 @@
 #include <linux/raw.h>
 #include <linux/capability.h>
 #include <linux/uio.h>
+#include <linux/device.h>
+#include <linux/genhd.h>
 
 #include <asm/uaccess.h>
 
@@ -25,6 +27,7 @@
 	int inuse;
 };
 
+static struct class_simple *raw_class;
 static struct raw_device_data raw_devices[MAX_RAW_MINORS];
 static DECLARE_MUTEX(raw_mutex);
 static struct file_operations raw_ctl_fops;	     /* forward declaration */
@@ -119,6 +122,29 @@
 	return ioctl_by_bdev(bdev, command, arg);
 }
 
+static void bind_device(struct raw_config_request rq)
+{
+	int part;
+	struct gendisk *gen;
+	struct class_device *dev;
+	struct kobject *target = NULL;
+
+	gen = get_gendisk(MKDEV(rq.block_major, rq.block_minor), &part);
+	if (gen) {
+		if (part && gen->part[part])
+			target = &gen->part[part]->kobj;
+		else
+			target = &gen->kobj;
+	}
+
+	class_simple_device_remove(MKDEV(RAW_MAJOR, rq.raw_minor));
+	dev = class_simple_device_add(raw_class, MKDEV(RAW_MAJOR, rq.raw_minor),
+				      NULL, "raw%d", rq.raw_minor);
+	if (dev && target) {
+		sysfs_create_link(&dev->kobj, target, "device");
+	}
+}
+
 /*
  * Deal with ioctls against the raw-device control interface, to bind
  * and unbind other raw devices.
@@ -187,12 +213,15 @@
 			if (rq.block_major = 0 && rq.block_minor = 0) {
 				/* unbind */
 				rawdev->binding = NULL;
+				class_simple_device_remove(MKDEV(RAW_MAJOR, rq.raw_minor));
 			} else {
 				rawdev->binding = bdget(dev);
 				if (rawdev->binding = NULL)
 					err = -ENOMEM;
-				else
+				else {
 					__module_get(THIS_MODULE);
+					bind_device(rq);
+				}
 			}
 			up(&raw_mutex);
 		} else {
@@ -262,6 +291,14 @@
 	int i;
 
 	register_chrdev(RAW_MAJOR, "raw", &raw_fops);
+
+	raw_class = class_simple_create(THIS_MODULE, "raw");
+	if (IS_ERR(raw_class)) {
+		printk (KERN_ERR "Error creating raw class.\n");
+		return PTR_ERR(raw_class);
+	}
+	class_simple_device_add(raw_class, MKDEV(RAW_MAJOR, 0), NULL, "rawctl");
+
 	devfs_mk_cdev(MKDEV(RAW_MAJOR, 0),
 		      S_IFCHR | S_IRUGO | S_IWUGO,
 		      "raw/rawctl");
@@ -280,6 +317,8 @@
 		devfs_remove("raw/raw%d", i);
 	devfs_remove("raw/rawctl");
 	devfs_remove("raw");
+	class_simple_device_remove(MKDEV(RAW_MAJOR, 0));
+	class_simple_destroy(raw_class);
 	unregister_chrdev(RAW_MAJOR, "raw");
 }
 


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

  reply	other threads:[~2004-01-15 20:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-15 20:40 [PATCH] sysfs class patch update [00/10] Greg KH
2004-01-15 20:41 ` [PATCH] add class_simple support [01/10] Greg KH
2004-01-15 20:41   ` [PATCH] add sysfs class support for input devices [02/10] Greg KH
2004-01-15 20:41     ` [PATCH] add class support for lp devices [03/10] Greg KH
2004-01-15 20:41       ` [PATCH] add sysfs class support for mem devices [04/10] Greg KH
2004-01-15 20:42         ` [PATCH] add sysfs class support for misc devices [05/10] Greg KH
2004-01-15 20:42           ` Greg KH [this message]
2004-01-15 20:42             ` [PATCH] add sysfs class support for OSS sound devices [07/10] Greg KH
2004-01-15 20:43               ` [PATCH] add sysfs class support for ALSA sound devices [08/10] Greg KH
2004-01-15 20:43                 ` [PATCH] clean up sysfs class support for tty devices [09/10] Greg KH
2004-01-15 20:43                   ` [PATCH] add sysfs class support for vc devices [10/10] Greg KH
2004-01-16  4:13                     ` Andrew Morton
     [not found]                       ` <1074279897.23742.754.camel@nosferatu.lan>
2004-01-16 19:17                         ` Andrew Morton
2004-01-16 22:15                 ` [PATCH] add sysfs class support for ALSA sound devices [08/10] Måns Rullgård
2004-01-17  0:10                   ` Greg KH
2004-01-15 21:23               ` [PATCH] add sysfs class support for OSS sound devices [07/10] Prakash K. Cheemplavam
2004-01-15 21:32                 ` Greg KH
2004-01-20  1:58   ` [PATCH] add class_simple support [01/10] Rusty Russell
2004-01-15 20:57 ` [PATCH] sysfs class patch update [00/10] Måns Rullgård
2004-01-15 22:56   ` 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=20040115204241.GG22199@kroah.com \
    --to=greg@kroah.com \
    --cc=akpm@osdl.org \
    --cc=linux-hotplug-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).