Skip to contentSkip to conversation

sr: consider the last written sector when determining media size

PATCH In review Tejun Heo 2 participants 3 messages Sep 4, 2009 – Sep 15, 2009

Subsystems (2)
lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 sr: consider the last written sector when determining media size

On certain cases, UDF disc doesn't report capacity correctly via READ_CAPACITY but TOC or trackinfo contains valid information which can be obtained using cdrom_get_last_written(). ide-cd considers both values and uses the larger one. Do the same in sr. This fixes bko#9668.

http://bugzilla.kernel.org/show_bug.cgi?id=9668

---
 drivers/scsi/sr.c |   22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/scsi/sr.c +14 -8
index cce0fe4..76bdcfc 100644
@@ -684,14 +684,20 @@ static void get_sectorsize(struct scsi_cd *cd)
 		cd->capacity = 0x1fffff;
 		sector_size = 2048;	/* A guess, just in case */
 	} else {
-#if 0
-		if (cdrom_get_last_written(&cd->cdi,
-					   &cd->capacity))
-#endif
-			cd->capacity = 1 + ((buffer[0] << 24) |
-						    (buffer[1] << 16) |
-						    (buffer[2] << 8) |
-						    buffer[3]);
+		long last_written;
+
+		cd->capacity = 1 + ((buffer[0] << 24) | (buffer[1] << 16) |
+				    (buffer[2] << 8) | buffer[3]);
+		/*
+		 * READ_CAPACITY doesn't return the correct size on
+		 * certain UDF media.  If last_written is larger, use
+		 * it instead.
+		 *
+		 * http://bugzilla.kernel.org/show_bug.cgi?id=9668
+		 */
+		if (!cdrom_get_last_written(&cd->cdi, &last_written))
+			cd->capacity = max_t(long, cd->capacity, last_written);
+
 		sector_size = (buffer[4] << 24) |
 		    (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
 		switch (sector_size) {
author
#1 lore raw
Quoted 11 lines · Tejun Heo

On certain cases, UDF disc doesn't report capacity correctly via READ_CAPACITY but TOC or trackinfo contains valid information which can be obtained using cdrom_get_last_written(). ide-cd considers both values and uses the larger one. Do the same in sr. This fixes bko#9668.

http://bugzilla.kernel.org/show_bug.cgi?id=9668

PING.

Signature · 1 line
tejun
Tested-by
#2 lore raw
Quoted 7 lines · Tejun Heo
Quoted 6 lines · Tejun Heo

On certain cases, UDF disc doesn't report capacity correctly via READ_CAPACITY but TOC or trackinfo contains valid information which can be obtained using cdrom_get_last_written(). ide-cd considers both values and uses the larger one. Do the same in sr. This fixes bko#9668.

Quoted 11 lines
Quoted 5 lines

http://bugzilla.kernel.org/show_bug.cgi?id=9668

PING.

Signature · 1 line
tejun

yes, works for me. You can add :

:-)

Signature · 1 line
Milan Kocian