Browse Source

genhd: expose AN to user space

Allow user space to determine if a disk supports Asynchronous Notification of
media changes.  This is done by adding a new sysfs file "capability_flags",
which is documented in (insert file name).  This sysfs file will export all
disk capabilities flags to user space.  We also define a new flag to define
the media change notification capability.

Signed-off-by: Kristen Carlson Accardi <kristen.c.accardi@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Kristen Carlson Accardi 18 years ago
parent
commit
86ce18d7b7
3 changed files with 25 additions and 1 deletions
  1. 15 0
      Documentation/block/capability.txt
  2. 9 1
      block/genhd.c
  3. 1 0
      include/linux/genhd.h

+ 15 - 0
Documentation/block/capability.txt

@@ -0,0 +1,15 @@
+Generic Block Device Capability
+===============================================================================
+This file documents the sysfs file block/<disk>/capability
+
+capability is a hex word indicating which capabilities a specific disk
+supports.  For more information on bits not listed here, see
+include/linux/genhd.h
+
+Capability				Value
+-------------------------------------------------------------------------------
+GENHD_FL_MEDIA_CHANGE_NOTIFY		4
+	When this bit is set, the disk supports Asynchronous Notification
+	of media change events.  These events will be broadcast to user
+	space via kernel uevent.
+

+ 9 - 1
block/genhd.c

@@ -423,7 +423,10 @@ static ssize_t disk_size_read(struct gendisk * disk, char *page)
 {
 {
 	return sprintf(page, "%llu\n", (unsigned long long)get_capacity(disk));
 	return sprintf(page, "%llu\n", (unsigned long long)get_capacity(disk));
 }
 }
-
+static ssize_t disk_capability_read(struct gendisk *disk, char *page)
+{
+	return sprintf(page, "%x\n", disk->flags);
+}
 static ssize_t disk_stats_read(struct gendisk * disk, char *page)
 static ssize_t disk_stats_read(struct gendisk * disk, char *page)
 {
 {
 	preempt_disable();
 	preempt_disable();
@@ -466,6 +469,10 @@ static struct disk_attribute disk_attr_size = {
 	.attr = {.name = "size", .mode = S_IRUGO },
 	.attr = {.name = "size", .mode = S_IRUGO },
 	.show	= disk_size_read
 	.show	= disk_size_read
 };
 };
+static struct disk_attribute disk_attr_capability = {
+	.attr = {.name = "capability", .mode = S_IRUGO },
+	.show	= disk_capability_read
+};
 static struct disk_attribute disk_attr_stat = {
 static struct disk_attribute disk_attr_stat = {
 	.attr = {.name = "stat", .mode = S_IRUGO },
 	.attr = {.name = "stat", .mode = S_IRUGO },
 	.show	= disk_stats_read
 	.show	= disk_stats_read
@@ -506,6 +513,7 @@ static struct attribute * default_attrs[] = {
 	&disk_attr_removable.attr,
 	&disk_attr_removable.attr,
 	&disk_attr_size.attr,
 	&disk_attr_size.attr,
 	&disk_attr_stat.attr,
 	&disk_attr_stat.attr,
+	&disk_attr_capability.attr,
 #ifdef CONFIG_FAIL_MAKE_REQUEST
 #ifdef CONFIG_FAIL_MAKE_REQUEST
 	&disk_attr_fail.attr,
 	&disk_attr_fail.attr,
 #endif
 #endif

+ 1 - 0
include/linux/genhd.h

@@ -94,6 +94,7 @@ struct hd_struct {
 
 
 #define GENHD_FL_REMOVABLE			1
 #define GENHD_FL_REMOVABLE			1
 #define GENHD_FL_DRIVERFS			2
 #define GENHD_FL_DRIVERFS			2
+#define GENHD_FL_MEDIA_CHANGE_NOTIFY		4
 #define GENHD_FL_CD				8
 #define GENHD_FL_CD				8
 #define GENHD_FL_UP				16
 #define GENHD_FL_UP				16
 #define GENHD_FL_SUPPRESS_PARTITION_INFO	32
 #define GENHD_FL_SUPPRESS_PARTITION_INFO	32