public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix disk geometry calculation for large disks
@ 2005-05-02 16:48 Tom Coughlan
  2005-05-02 17:18 ` Tony Battersby
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Coughlan @ 2005-05-02 16:48 UTC (permalink / raw)
  To: linux-scsi

[-- Attachment #1: Type: text/plain, Size: 483 bytes --]

Testing with multi-terabyte disks shows that HDIO_GETGEO sometimes
returns heads=0. This causes parted to die with a Floating Point
Exception, among other possible effects. 

The problem occurs because several routines in scsicam_bios_param cast
sector_t capacity to unsigned long. 

The attached patch avoids this, by checking first to see if the capacity
exceeds the maximum allowed values for cylinder/sector/head
(65535*63*255). If so, just return those values right away. 

Tom

[-- Attachment #2: scsicam-geom-fix-2.6.12-rc3.patch --]
[-- Type: text/plain, Size: 692 bytes --]

--- linux-2.6.12-rc3/drivers/scsi/scsicam.c.orig
+++ linux-2.6.12-rc3/drivers/scsi/scsicam.c
@@ -59,6 +59,15 @@ int scsicam_bios_param(struct block_devi
 	unsigned char *p;
 	int ret;
 
+	/* Are we above the max. allowed for cylinder/sector/head? */
+	if (capacity > 65535*63*255) {
+		ip[0] = 255;
+		ip[1] = 63;
+		ip[2] = 65535;
+
+		return 0;
+	}
+
 	p = scsi_bios_ptable(bdev);
 	if (!p)
 		return -1;
@@ -86,11 +95,7 @@ int scsicam_bios_param(struct block_devi
 			ip[0] = 64;
 			ip[1] = 32;
 		}
-
-		if (capacity > 65535*63*255)
-			ip[2] = 65535;
-		else
-			ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
+		ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
 	}
 
 	return 0;

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

* RE: [PATCH] fix disk geometry calculation for large disks
  2005-05-02 16:48 [PATCH] fix disk geometry calculation for large disks Tom Coughlan
@ 2005-05-02 17:18 ` Tony Battersby
  0 siblings, 0 replies; 2+ messages in thread
From: Tony Battersby @ 2005-05-02 17:18 UTC (permalink / raw)
  To: 'Tom Coughlan', linux-scsi

> Testing with multi-terabyte disks shows that HDIO_GETGEO sometimes
> returns heads=0. This causes parted to die with a Floating Point
> Exception, among other possible effects.
>
> The problem occurs because several routines in scsicam_bios_param cast
> sector_t capacity to unsigned long.
>
> The attached patch avoids this, by checking first to see if
> the capacity
> exceeds the maximum allowed values for cylinder/sector/head
> (65535*63*255). If so, just return those values right away.

I brought up this issue a few months ago
(http://marc.theaimsgroup.com/?t=110383771000001&r=1&w=2), but no one
replied.  There are actually many other drivers with custom bios_param()
routines that should be reviewed as well.

Anthony J. Battersby
Cybernetics


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

end of thread, other threads:[~2005-05-02 17:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-02 16:48 [PATCH] fix disk geometry calculation for large disks Tom Coughlan
2005-05-02 17:18 ` Tony Battersby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox