]> git.hungrycats.org Git - linux/commitdiff
[PATCH] add removeable sysfs block device attribute
authorOlaf Hering <olh@suse.de>
Wed, 14 Jul 2004 09:20:29 +0000 (02:20 -0700)
committerGreg Kroah-Hartman <greg@kroah.com>
Wed, 14 Jul 2004 09:20:29 +0000 (02:20 -0700)
This patch adds a /block/*/removeable sysfs attribute. A value of 1
indicates the media can change anytime. This is a hint for userland
to poll such devices for possible media changes, and leave all others alone.
There is currently no way to see if a connected usb-storage device is a
disk or a card reader. It will also show 1 for CD and ZIP drives.

It was done by Patrick Mansfield a while ago. I can probably not
sigh-off his work. ;)

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/block/genhd.c

index 00a5bfa133b22abae55214f7a276d4b9d37bfa1e..e82caa224d1fa80846b82f2d2d5f001e6e0ef4d2 100644 (file)
@@ -352,6 +352,12 @@ static ssize_t disk_range_read(struct gendisk * disk, char *page)
 {
        return sprintf(page, "%d\n", disk->minors);
 }
+static ssize_t disk_removable_read(struct gendisk * disk, char *page)
+{
+       return sprintf(page, "%d\n",
+                      (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0));
+
+}
 static ssize_t disk_size_read(struct gendisk * disk, char *page)
 {
        return sprintf(page, "%llu\n", (unsigned long long)get_capacity(disk));
@@ -384,6 +390,10 @@ static struct disk_attribute disk_attr_range = {
        .attr = {.name = "range", .mode = S_IRUGO },
        .show   = disk_range_read
 };
+static struct disk_attribute disk_attr_removable = {
+       .attr = {.name = "removable", .mode = S_IRUGO },
+       .show   = disk_removable_read
+};
 static struct disk_attribute disk_attr_size = {
        .attr = {.name = "size", .mode = S_IRUGO },
        .show   = disk_size_read
@@ -396,6 +406,7 @@ static struct disk_attribute disk_attr_stat = {
 static struct attribute * default_attrs[] = {
        &disk_attr_dev.attr,
        &disk_attr_range.attr,
+       &disk_attr_removable.attr,
        &disk_attr_size.attr,
        &disk_attr_stat.attr,
        NULL,