lkml.org 
[lkml]   [2003]   [Aug]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] 3/8 Backport recent 2.6 IDE updates to 2.4.x
This patch fixes all cases where ide-disk displays MB to use
consistant logic, and properly use the do_div() macro rather than
strange non-obvious numerical sequences doing a similar task,

-Erik

--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--

--- linux/drivers/ide/ide-disk.c.orig 2003-08-16 19:52:24.000000000 -0600
+++ linux/drivers/ide/ide-disk.c 2003-08-16 20:42:04.000000000 -0600
@@ -69,6 +69,7 @@
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <asm/io.h>
+#include <asm/div64.h>

/* FIXME: some day we shouldnt need to look in here! */

@@ -1131,6 +1132,13 @@

#endif /* CONFIG_IDEDISK_STROKE */

+static unsigned long long sectors_to_MB(unsigned long long n)
+{
+ n <<= 9; /* make it bytes */
+ do_div(n, 1000000); /* make it MB */
+ return n;
+}
+
/*
* Tests if the drive supports Host Protected Area feature.
* Returns true if supported, false otherwise.
@@ -1231,7 +1239,7 @@
}
}

-static unsigned long idedisk_capacity (ide_drive_t *drive)
+static u64 idedisk_capacity (ide_drive_t *drive)
{
if (drive->id->cfs_enable_2 & 0x0400)
return (drive->capacity48 - drive->sect0);
@@ -1616,7 +1624,7 @@
int i;

struct hd_driveid *id = drive->id;
- unsigned long capacity;
+ unsigned long long capacity;

idedisk_add_settings(drive);

@@ -1683,14 +1691,23 @@
* by correcting bios_cyls:
*/
capacity = idedisk_capacity (drive);
- if ((capacity >= (drive->bios_cyl * drive->bios_sect * drive->bios_head)) &&
- (!drive->forced_geom) && drive->bios_sect && drive->bios_head)
- drive->bios_cyl = (capacity / drive->bios_sect) / drive->bios_head;
- printk (KERN_INFO "%s: %ld sectors", drive->name, capacity);
-
- /* Give size in megabytes (MB), not mebibytes (MiB). */
- /* We compute the exact rounded value, avoiding overflow. */
- printk (" (%ld MB)", (capacity - capacity/625 + 974)/1950);
+ if (!drive->forced_geom && drive->bios_sect && drive->bios_head) {
+ unsigned int cap0 = capacity; /* truncate to 32 bits */
+ unsigned int cylsz, cyl;
+
+ 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;
+ }
+ }
+ printk(KERN_INFO "%s: %llu sectors (%llu MB)",
+ drive->name, capacity, sectors_to_MB(capacity));

/* Only print cache size when it was specified */
if (id->buf_size)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 13:47    [W:0.601 / U:0.044 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site