--- a/usr/src/grub/grub-0.97/lib/device.c Tue Jun 02 12:23:04 2009 -0700
+++ b/usr/src/grub/grub-0.97/lib/device.c Tue Jun 02 12:37:44 2009 -0700
@@ -236,7 +236,8 @@
geom->cylinders = dkg.dkg_ncyl;
geom->heads = dkg.dkg_nhead;
geom->sectors = dkg.dkg_nsect;
- geom->total_sectors = dkg.dkg_ncyl * dkg.dkg_nhead * dkg.dkg_nsect;
+ geom->total_sectors = (unsigned long long)dkg.dkg_ncyl * dkg.dkg_nhead
+ * dkg.dkg_nsect;
goto success;
}
@@ -270,7 +271,8 @@
if (! fstat (fd, &st) && st.st_blocks)
geom->total_sectors = st.st_blocks >> SECTOR_BITS;
else
- geom->total_sectors = geom->cylinders * geom->heads * geom->sectors;
+ geom->total_sectors = (unsigned long long)geom->cylinders *
+ geom->heads * geom->sectors;
}
success:
--- a/usr/src/grub/grub-0.97/stage2/bios.c Tue Jun 02 12:23:04 2009 -0700
+++ b/usr/src/grub/grub-0.97/stage2/bios.c Tue Jun 02 12:37:44 2009 -0700
@@ -96,7 +96,7 @@
return err;
geometry->flags &= ~BIOSDISK_FLAG_LBA_EXTENSION;
- geometry->total_sectors = (geometry->cylinders
+ geometry->total_sectors = ((unsigned long long)geometry->cylinders
* geometry->heads
* geometry->sectors);
return biosdisk (read, drive, geometry, sector, nsec, segment);
@@ -174,7 +174,7 @@
geometry->heads = cdrp.heads;
geometry->sectors = cdrp.sectors & 0x3F;
geometry->sector_size = SECTOR_SIZE;
- geometry->total_sectors = (geometry->cylinders
+ geometry->total_sectors = ((unsigned long long)geometry->cylinders
* geometry->heads
* geometry->sectors);
return -1;
@@ -216,7 +216,7 @@
{
/* hard disk or CD-ROM */
int version;
- unsigned long total_sectors = 0;
+ unsigned long long total_sectors = 0;
version = check_int13_extensions (drive);
@@ -278,16 +278,14 @@
so I omit the check for now. - okuji */
/* if (drp.flags & (1 << 1)) */
- /* FIXME: when the 2TB limit becomes critical, we must
- change the type of TOTAL_SECTORS to unsigned long
- long. */
if (drp.total_sectors)
- total_sectors = drp.total_sectors & ~0L;
+ total_sectors = drp.total_sectors;
else
/* Some buggy BIOSes doesn't return the total sectors
correctly but returns zero. So if it is zero, compute
it by C/H/S returned by the LBA BIOS call. */
- total_sectors = drp.cylinders * drp.heads * drp.sectors;
+ total_sectors = (unsigned long long)drp.cylinders *
+ drp.heads * drp.sectors;
}
}
@@ -302,7 +300,7 @@
if (! total_sectors)
{
- total_sectors = (geometry->cylinders
+ total_sectors = ((unsigned long long)geometry->cylinders
* geometry->heads
* geometry->sectors);
}
@@ -331,7 +329,7 @@
if (err)
return err;
- geometry->total_sectors = (geometry->cylinders
+ geometry->total_sectors = ((unsigned long long)geometry->cylinders
* geometry->heads
* geometry->sectors);
geometry->sector_size = SECTOR_SIZE;
--- a/usr/src/grub/grub-0.97/stage2/builtins.c Tue Jun 02 12:23:04 2009 -0700
+++ b/usr/src/grub/grub-0.97/stage2/builtins.c Tue Jun 02 12:37:44 2009 -0700
@@ -3721,13 +3721,6 @@
if (! rawread (current_drive, 0, 0, SECTOR_SIZE, mbr))
return 1;
- /* Check if the new partition will fit in the disk. */
- if (new_start + new_len > buf_geom.total_sectors)
- {
- errnum = ERR_GEOM;
- return 1;
- }
-
/* Store the partition information in the MBR. */
lba_to_chs (new_start, &start_cl, &start_ch, &start_dh);
lba_to_chs (new_start + new_len - 1, &end_cl, &end_ch, &end_dh);
--- a/usr/src/grub/grub-0.97/stage2/disk_io.c Tue Jun 02 12:23:04 2009 -0700
+++ b/usr/src/grub/grub-0.97/stage2/disk_io.c Tue Jun 02 12:37:44 2009 -0700
@@ -185,13 +185,6 @@
sector_size_bits = log2 (buf_geom.sector_size);
}
- /* Make sure that SECTOR is valid. */
- if (sector >= buf_geom.total_sectors)
- {
- errnum = ERR_GEOM;
- return 0;
- }
-
slen = ((byte_offset + byte_len + buf_geom.sector_size - 1)
>> sector_size_bits);
@@ -874,7 +867,8 @@
buf_drive = current_drive;
buf_track = BUF_CACHE_INVALID;
}
- part_length = buf_geom.total_sectors;
+ part_length =
+ (buf_geom.total_sectors > MAXUINT) ? MAXUINT : buf_geom.total_sectors;
/* If this is the whole disk, return here. */
if (! flags && current_partition == 0xFFFFFF)
--- a/usr/src/grub/grub-0.97/stage2/shared.h Tue Jun 02 12:23:04 2009 -0700
+++ b/usr/src/grub/grub-0.97/stage2/shared.h Tue Jun 02 12:37:44 2009 -0700
@@ -69,6 +69,7 @@
*/
#define MAXINT 0x7FFFFFFF
+#define MAXUINT 0xFFFFFFFF
/* Maximum command line size. Before you blindly increase this value,
see the comment in char_io.c (get_cmdline). */
@@ -705,7 +706,7 @@
/* The number of sectors */
unsigned long sectors;
/* The total number of sectors */
- unsigned long total_sectors;
+ unsigned long long total_sectors;
/* Device sector size */
unsigned long sector_size;
/* Flags */