linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Forcing capacity sizes for block devices
@ 2009-12-20 12:05 Clemens Fruhwirth
  2009-12-20 13:19 ` [PATCH] Forcing capacity sizes for block devices - (sorry, gmail ruined inlining with wordwrapping in the last mail) Clemens Fruhwirth
  2009-12-20 17:43 ` [PATCH] Forcing capacity sizes for block devices Bartlomiej Zolnierkiewicz
  0 siblings, 2 replies; 8+ messages in thread
From: Clemens Fruhwirth @ 2009-12-20 12:05 UTC (permalink / raw)
  To: linux-scsi, grundler

Make the size attribute of block devices writable via sysfs. This
allows userspace to force
device boundaries in cases where the device driver is unable to detect
the correct size, as
with spec-incompliant SD card readers. Also see
http://marc.info/?t=125555550200010&r=1&w=2

diff -uprN -X linux-2.6.32-vanilla/Documentation/dontdiff
linux-2.6.32-vanilla/block/genhd.c linux-2.6.32-patched/block/genhd.c
--- linux-2.6.32-vanilla/block/genhd.c	2009-12-03 04:51:21.000000000 +0100
+++ linux-2.6.32-patched/block/genhd.c	2009-12-15 14:38:24.962463446 +0100
@@ -865,7 +865,7 @@ static DEVICE_ATTR(range, S_IRUGO, disk_
 static DEVICE_ATTR(ext_range, S_IRUGO, disk_ext_range_show, NULL);
 static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL);
 static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL);
-static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
+static DEVICE_ATTR(size, S_IRUGO | S_IWUSR, part_size_show, part_size_set);
 static DEVICE_ATTR(alignment_offset, S_IRUGO,
disk_alignment_offset_show, NULL);
 static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL);
 static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL);
diff -uprN -X linux-2.6.32-vanilla/Documentation/dontdiff
linux-2.6.32-vanilla/fs/partitions/check.c
linux-2.6.32-patched/fs/partitions/check.c
--- linux-2.6.32-vanilla/fs/partitions/check.c	2009-12-03
04:51:21.000000000 +0100
+++ linux-2.6.32-patched/fs/partitions/check.c	2009-12-19
10:38:58.745294907 +0100
@@ -219,6 +219,18 @@ ssize_t part_size_show(struct device *de
 	return sprintf(buf, "%llu\n",(unsigned long long)p->nr_sects);
 }

+ssize_t part_size_set(struct device *dev,
+		      struct device_attribute *attr, char *buf, size_t len)
+{
+	struct hd_struct *p = dev_to_part(dev);
+	unsigned long long val;
+	if (strict_strtoull(buf, 0, &val))
+		return -EINVAL;
+
+	p->nr_sects = val;
+	return len;
+}
+
 ssize_t part_alignment_offset_show(struct device *dev,
 				   struct device_attribute *attr, char *buf)
 {
diff -uprN -X linux-2.6.32-vanilla/Documentation/dontdiff
linux-2.6.32-vanilla/include/linux/genhd.h
linux-2.6.32-patched/include/linux/genhd.h
--- linux-2.6.32-vanilla/include/linux/genhd.h	2009-12-03
04:51:21.000000000 +0100
+++ linux-2.6.32-patched/include/linux/genhd.h	2009-12-19
10:40:30.900871273 +0100
@@ -549,6 +549,9 @@ extern void blk_unregister_region(dev_t

 extern ssize_t part_size_show(struct device *dev,
 			      struct device_attribute *attr, char *buf);
+extern ssize_t part_size_set(struct device *dev,
+			     struct device_attribute *attr, char *buf,
+			     size_t len);
 extern ssize_t part_stat_show(struct device *dev,
 			      struct device_attribute *attr, char *buf);
 extern ssize_t part_inflight_show(struct device *dev,

Signed-off-by: Clemens Fruhwirth <clemens@endorphin.org>
Reviewed-by: Grant Grundler <grundler@google.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-01-25 14:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-20 12:05 [PATCH] Forcing capacity sizes for block devices Clemens Fruhwirth
2009-12-20 13:19 ` [PATCH] Forcing capacity sizes for block devices - (sorry, gmail ruined inlining with wordwrapping in the last mail) Clemens Fruhwirth
2009-12-20 17:43 ` [PATCH] Forcing capacity sizes for block devices Bartlomiej Zolnierkiewicz
2009-12-21 20:04   ` Grant Grundler
2009-12-21 21:59     ` Bartlomiej Zolnierkiewicz
2009-12-22 20:15       ` Grant Grundler
     [not found]       ` <2f83750a0912240503g3aa7bcbw876a164d0e350b27@mail.gmail.com>
2009-12-24 13:40         ` Clemens Fruhwirth
2010-01-25 14:49           ` Clemens Fruhwirth

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).