Skip to content

Commit

Permalink
Fix fdisk(8) to create 2TB partitions on disks larger than 2TB, rathe…
Browse files Browse the repository at this point in the history
…r than

only being able to create 1TB partitions:
o) Use an unsigned 32-bit quantity to store the number of disk sectors.
o) Detect overflow of said 32-bit quantity and clamp to 2^32.
o) Rather than returning the disk sector count from get_params, return 0 on
   success, since its return value is only ever compared to -1 to detect
   failure.  This would cause returning 2^32 sectors to be interpreted as an
   error.

Reviewed by:	bde ("good for a quick fix")
  • Loading branch information
caladri committed Nov 27, 2013
1 parent 72d47a0 commit 3cb4d3e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sbin/fdisk/fdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ static int secsize = 0; /* the sensed sector size */

static char *disk;

static int cyls, sectors, heads, cylsecs, disksecs;
static int cyls, sectors, heads, cylsecs;
static u_int32_t disksecs;

struct mboot {
unsigned char *bootinst; /* boot code */
Expand Down Expand Up @@ -873,10 +874,13 @@ get_params()
o = g_mediasize(fd);
if (o < 0)
return (-1);
disksecs = o / u;
if (o / u <= NO_DISK_SECTORS)
disksecs = o / u;
else
disksecs = NO_DISK_SECTORS;
cyls = dos_cyls = o / (u * dos_heads * dos_sectors);

return (disksecs);
return (0);
}

static int
Expand Down

0 comments on commit 3cb4d3e

Please sign in to comment.