Skip to contentSkip to conversation

Export disk->policy to sysfs

PATCH New Alberto Bertogli 1 participant 1 message Dec 9, 2004 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Export disk->policy to sysfs

Hi!

This small patch against 2.6.10-rc3 exports the disk->policy variable to sysfs as /sys/block/DEVICE/read_only.

It can be useful for people or scripts wanting to check the state of a device, specially now that USB storage has write protect detection.

Thanks,
Alberto

drivers/block/genhd.c renamed from drivers/block/genhd.c.orig +9 -0
@@ -384,6 +384,10 @@
 		jiffies_to_msecs(disk_stat_read(disk, io_ticks)),
 		jiffies_to_msecs(disk_stat_read(disk, time_in_queue)));
 }
+static ssize_t disk_read_only_read(struct gendisk * disk, char *page)
+{
+	return sprintf(page, "%d\n", disk->policy);
+}
 static struct disk_attribute disk_attr_dev = {
 	.attr = {.name = "dev", .mode = S_IRUGO },
 	.show	= disk_dev_read
@@ -404,6 +408,10 @@
 	.attr = {.name = "stat", .mode = S_IRUGO },
 	.show	= disk_stats_read
 };
+static struct disk_attribute disk_attr_read_only = {
+	.attr = {.name = "read_only", .mode = S_IRUGO },
+	.show	= disk_read_only_read
+};
 
 static struct attribute * default_attrs[] = {
 	&disk_attr_dev.attr,
@@ -411,6 +419,7 @@
 	&disk_attr_removable.attr,
 	&disk_attr_size.attr,
 	&disk_attr_stat.attr,
+	&disk_attr_read_only.attr,
 	NULL,
 };