Commit 5f1fde8b authored by Bartlomiej Zolnierkiewicz's avatar Bartlomiej Zolnierkiewicz Committed by Linus Torvalds

[PATCH] capacity related fixes

From Andries.Brouwer@cwi.nl:

- store capacities in sector_t
- add generic sectors_to_MB() helper to ide-disk.c
- fix drive->bios_cyls calculation (limiting it to 65535) for disks
parent 1916c835
...@@ -3228,7 +3228,7 @@ int ide_cdrom_setup (ide_drive_t *drive) ...@@ -3228,7 +3228,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
} }
static static
unsigned long ide_cdrom_capacity (ide_drive_t *drive) sector_t ide_cdrom_capacity (ide_drive_t *drive)
{ {
unsigned long capacity; unsigned long capacity;
......
...@@ -1066,6 +1066,13 @@ static unsigned long long idedisk_set_max_address_ext(ide_drive_t *drive, unsign ...@@ -1066,6 +1066,13 @@ static unsigned long long idedisk_set_max_address_ext(ide_drive_t *drive, unsign
#endif /* CONFIG_IDEDISK_STROKE */ #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. * Tests if the drive supports Host Protected Area feature.
* Returns true if supported, false otherwise. * Returns true if supported, false otherwise.
...@@ -1166,7 +1173,7 @@ static void init_idedisk_capacity (ide_drive_t *drive) ...@@ -1166,7 +1173,7 @@ static void init_idedisk_capacity (ide_drive_t *drive)
} }
} }
static unsigned long idedisk_capacity (ide_drive_t *drive) static sector_t idedisk_capacity (ide_drive_t *drive)
{ {
if (drive->id->cfs_enable_2 & 0x0400) if (drive->id->cfs_enable_2 & 0x0400)
return (drive->capacity48 - drive->sect0); return (drive->capacity48 - drive->sect0);
...@@ -1565,7 +1572,7 @@ static ide_startstop_t idedisk_start_power_step (ide_drive_t *drive, struct requ ...@@ -1565,7 +1572,7 @@ static ide_startstop_t idedisk_start_power_step (ide_drive_t *drive, struct requ
static void idedisk_setup (ide_drive_t *drive) static void idedisk_setup (ide_drive_t *drive)
{ {
struct hd_driveid *id = drive->id; struct hd_driveid *id = drive->id;
unsigned long capacity; unsigned long long capacity;
idedisk_add_settings(drive); idedisk_add_settings(drive);
...@@ -1629,14 +1636,23 @@ static void idedisk_setup (ide_drive_t *drive) ...@@ -1629,14 +1636,23 @@ static void idedisk_setup (ide_drive_t *drive)
* by correcting bios_cyls: * by correcting bios_cyls:
*/ */
capacity = idedisk_capacity (drive); capacity = idedisk_capacity (drive);
if ((capacity >= (drive->bios_cyl * drive->bios_sect * drive->bios_head)) && if (!drive->forced_geom && drive->bios_sect && drive->bios_head) {
(!drive->forced_geom) && drive->bios_sect && drive->bios_head) unsigned int cap0 = capacity; /* truncate to 32 bits */
drive->bios_cyl = (capacity / drive->bios_sect) / drive->bios_head; unsigned int cylsz, cyl;
printk (KERN_INFO "%s: %ld sectors", drive->name, capacity);
if (cap0 != capacity)
/* Give size in megabytes (MB), not mebibytes (MiB). */ drive->bios_cyl = 65535;
/* We compute the exact rounded value, avoiding overflow. */ else {
printk (" (%ld MB)", (capacity - capacity/625 + 974)/1950); 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 */ /* Only print cache size when it was specified */
if (id->buf_size) if (id->buf_size)
......
...@@ -1626,7 +1626,7 @@ static int idefloppy_get_format_progress(ide_drive_t *drive, int *arg) ...@@ -1626,7 +1626,7 @@ static int idefloppy_get_format_progress(ide_drive_t *drive, int *arg)
/* /*
* Return the current floppy capacity to ide.c. * Return the current floppy capacity to ide.c.
*/ */
static unsigned long idefloppy_capacity (ide_drive_t *drive) static sector_t idefloppy_capacity (ide_drive_t *drive)
{ {
idefloppy_floppy_t *floppy = drive->driver_data; idefloppy_floppy_t *floppy = drive->driver_data;
unsigned long capacity = floppy->blocks * floppy->bs_factor; unsigned long capacity = floppy->blocks * floppy->bs_factor;
......
...@@ -351,7 +351,7 @@ int ide_system_bus_speed (void) ...@@ -351,7 +351,7 @@ int ide_system_bus_speed (void)
* current_capacity() returns the capacity (in sectors) of a drive * current_capacity() returns the capacity (in sectors) of a drive
* according to its current geometry/LBA settings. * according to its current geometry/LBA settings.
*/ */
unsigned long current_capacity (ide_drive_t *drive) sector_t current_capacity (ide_drive_t *drive)
{ {
if (!drive->present) if (!drive->present)
return 0; return 0;
...@@ -2410,7 +2410,7 @@ static void default_pre_reset (ide_drive_t *drive) ...@@ -2410,7 +2410,7 @@ static void default_pre_reset (ide_drive_t *drive)
{ {
} }
static unsigned long default_capacity (ide_drive_t *drive) static sector_t default_capacity (ide_drive_t *drive)
{ {
return 0x7fffffff; return 0x7fffffff;
} }
......
...@@ -1226,7 +1226,7 @@ typedef struct ide_driver_s { ...@@ -1226,7 +1226,7 @@ typedef struct ide_driver_s {
ide_startstop_t (*abort)(ide_drive_t *, const char *); ide_startstop_t (*abort)(ide_drive_t *, const char *);
int (*ioctl)(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long); int (*ioctl)(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
void (*pre_reset)(ide_drive_t *); void (*pre_reset)(ide_drive_t *);
unsigned long (*capacity)(ide_drive_t *); sector_t (*capacity)(ide_drive_t *);
ide_startstop_t (*special)(ide_drive_t *); ide_startstop_t (*special)(ide_drive_t *);
ide_proc_entry_t *proc; ide_proc_entry_t *proc;
int (*attach)(ide_drive_t *); int (*attach)(ide_drive_t *);
...@@ -1359,7 +1359,7 @@ extern int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long ...@@ -1359,7 +1359,7 @@ extern int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long
/* /*
* Return the current idea about the total capacity of this drive. * Return the current idea about the total capacity of this drive.
*/ */
extern unsigned long current_capacity (ide_drive_t *drive); extern sector_t current_capacity (ide_drive_t *drive);
/* /*
* Start a reset operation for an IDE interface. * Start a reset operation for an IDE interface.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment