All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Bellon <mbellon@mvista.com>
To: unlisted-recipients:; (no To-header on input)
Cc: linux-kernel@vger.kernel.org, akpm@osdl.org
Subject: [PATCH]  IDE disks show invalid geometries in /proc/ide/hd*/geometry
Date: Tue, 02 Aug 2005 14:27:35 -0700	[thread overview]
Message-ID: <42EFE547.3010206@mvista.com> (raw)
In-Reply-To: <42EAA7C8.5010206@mvista.com>

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

The ATA specification tells large disk drives to return C/H/S data of 
16383/16/63 regardless of their actual size (other variations on this 
return include 15 heads and/or 4092 cylinders). Unfortunately these CHS 
data confuse the existing IDE code and cause it to report invalid 
geometries in /proc when the disk runs in LBA mode.

The invalid geometries can cause failures in the partitioning tools; 
partitioning may be impossible or illogical size limitations occur. This 
also leads to various forms of human confusion.

I attach a patch that fixes this problem while strongly attempting to 
not break any existing side effects and await any comments.

mark

Signed-off-by: Mark Bellon <mbellon@mvista.com>


[-- Attachment #2: ide-geom-patch --]
[-- Type: text/plain, Size: 2063 bytes --]

diff -Naur linux-2.6.13-rc3-git9-orig/drivers/ide/ide-disk.c linux-2.6.13-rc3-git9/drivers/ide/ide-disk.c
--- linux-2.6.13-rc3-git9-orig/drivers/ide/ide-disk.c	2005-08-01 13:48:21.000000000 -0700
+++ linux-2.6.13-rc3-git9/drivers/ide/ide-disk.c	2005-08-02 12:14:43.000000000 -0700
@@ -884,10 +884,17 @@
  	ide_add_setting(drive,	"max_failures",		SETTING_RW,					-1,			-1,			TYPE_INT,	0,	65535,				1,	1,	&drive->max_failures,		NULL);
 }
 
+static uint32_t do_div64_32 (__u64 n, uint32_t d)
+{
+	do_div(n, d);
+
+	return n;
+}
+
 static void idedisk_setup (ide_drive_t *drive)
 {
 	struct hd_driveid *id = drive->id;
-	unsigned long long capacity;
+	__u64 capacity;
 	int barrier;
 
 	idedisk_add_settings(drive);
@@ -949,27 +956,32 @@
 	 */
 	capacity = idedisk_capacity (drive);
 	if (!drive->forced_geom) {
+		uint32_t cylsz, cyl;
 
-		if (idedisk_supports_lba48(drive->id)) {
-			/* compatibility */
-			drive->bios_sect = 63;
-			drive->bios_head = 255;
+		/*
+		 * In LBA mode the geometry isn't used to talk to the drive
+		 * so always create a "rational" geometry from the capacity.
+		 */
+		if (drive->select.b.lba) {
+			drive->bios_sect = drive->sect = 63;
+			drive->bios_head = drive->head = 255;
+
+			cylsz = drive->bios_sect * drive->bios_head;
+			cyl = do_div64_32(capacity, cylsz);
+
+			/* "fake out" works up to ~500 GB */
+			cyl = (cyl > 65535) ? 65535 : cyl;
+			drive->bios_cyl = drive->cyl = cyl;
 		}
 
 		if (drive->bios_sect && drive->bios_head) {
-			unsigned int cap0 = capacity; /* truncate to 32 bits */
-			unsigned int cylsz, cyl;
+			cylsz = drive->bios_sect * drive->bios_head;
+			cyl = do_div64_32(capacity, cylsz);
 
-			if (cap0 != capacity)
-				drive->bios_cyl = 65535;
-			else {
-				cylsz = drive->bios_sect * drive->bios_head;
-				cyl = cap0 / cylsz;
-				if (cyl > 65535)
-					cyl = 65535;
-				if (cyl > drive->bios_cyl)
-					drive->bios_cyl = cyl;
-			}
+			if (cyl > 65535)
+				cyl = 65535;
+			if (cyl > drive->bios_cyl)
+				drive->bios_cyl = cyl;
 		}
 	}
 	printk(KERN_INFO "%s: %llu sectors (%llu MB)",

  reply	other threads:[~2005-08-02 21:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-29  0:03 [PATCH] disk quotas fail when /etc/mtab is symlinked to /proc/mounts Mark Bellon
2005-07-29  0:13 ` Nathan Scott
2005-07-29  0:15   ` Mark Bellon
2005-07-29  0:19 ` Mark Bellon
2005-07-29  0:23 ` Andrew Morton
2005-07-29  0:29   ` Mark Bellon
2005-07-29  0:46     ` Mark Bellon
2005-07-29 13:46 ` Jan Kara
2005-07-29 15:47   ` Mark Bellon
2005-07-29 17:21 ` [PATCH] (REPOST/REVISION) " Mark Bellon
2005-07-29 22:03   ` [PATCH] (TAKE 3) " Mark Bellon
2005-08-02 21:27     ` Mark Bellon [this message]
2005-08-03  7:19       ` [PATCH] IDE disks show invalid geometries in /proc/ide/hd*/geometry Andre Hedrick
2005-08-03 16:54         ` Mark Bellon
2005-08-03 17:19         ` Bartlomiej Zolnierkiewicz
2005-08-03 17:37           ` Mark Bellon
2005-08-03 18:05             ` Bartlomiej Zolnierkiewicz
2005-08-03 18:32               ` Mark Bellon
2005-08-03 18:51                 ` Bartlomiej Zolnierkiewicz
2005-08-04  6:03                   ` Jan Engelhardt
2005-08-04 16:44                     ` Mark Bellon
2005-08-04 23:45                     ` Eric D. Mudama
2005-08-08 16:02     ` [PATCH] (TAKE 3) disk quotas fail when /etc/mtab is symlinked to /proc/mounts Jan Kara
2005-08-08 17:55   ` [PATCH] PPC64: large INITRD causes kernel not to boot Mark Bellon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42EFE547.3010206@mvista.com \
    --to=mbellon@mvista.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.