From f35890901a4ab4f3504147eecc4f8e1e8343dd12 Mon Sep 17 00:00:00 2001 From: bde Date: Sun, 13 Oct 1996 18:18:50 +0000 Subject: The dos() function needs a new second argument, containing the size of the partition. Only if the size is 0 should the special handling of 0 as first argument be triggered. [This bug caused offset 0 to give C/H/S = 0/0/0 instead of 0/0/1.] The init_sector0 function needs to decrease the first argument to the second call to dos() by one to be consistent with the calls to dos() in change_part(). [This bug caused fdisk -i to create bogus partition tables with the ending C/H/S value 1 too high. This usually gives S = 1 instead of S = maximum, so the geometry guessing in the slice code and perhaps in SCSI BIOSes was defeated.] Submitted by: Tor Egge --- sbin/fdisk/fdisk.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'sbin/fdisk') diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index de26e60..13418c8 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -183,7 +183,8 @@ static void change_part(int i); static void print_params(); static void change_active(int which); static void get_params_to_use(); -static void dos(int sec, unsigned char *c, unsigned char *s, unsigned char *h); +static void dos(int sec, int size, unsigned char *c, unsigned char *s, + unsigned char *h); static int open_disk(int u_flag); static ssize_t read_disk(off_t sector, void *buf); static ssize_t write_disk(off_t sector, void *buf); @@ -372,8 +373,10 @@ unsigned long size = disksecs - start; partp->dp_start = start; partp->dp_size = size; - dos(partp->dp_start, &partp->dp_scyl, &partp->dp_ssect, &partp->dp_shd); - dos(partp->dp_start+partp->dp_size, &partp->dp_ecyl, &partp->dp_esect, &partp->dp_ehd); + dos(partp->dp_start, partp->dp_size, + &partp->dp_scyl, &partp->dp_ssect, &partp->dp_shd); + dos(partp->dp_start + partp->dp_size - 1, partp->dp_size, + &partp->dp_ecyl, &partp->dp_esect, &partp->dp_ehd); } static void @@ -424,10 +427,10 @@ struct dos_partition *partp = ((struct dos_partition *) &mboot.parts) + i; partp->dp_esect = DOSSECT(tsec,tcyl); partp->dp_ehd = thd; } else { - dos(partp->dp_start, - &partp->dp_scyl, &partp->dp_ssect, &partp->dp_shd); - dos(partp->dp_start+partp->dp_size - 1, - &partp->dp_ecyl, &partp->dp_esect, &partp->dp_ehd); + dos(partp->dp_start, partp->dp_size, + &partp->dp_scyl, &partp->dp_ssect, &partp->dp_shd); + dos(partp->dp_start + partp->dp_size - 1, partp->dp_size, + &partp->dp_ecyl, &partp->dp_esect, &partp->dp_ehd); } print_part(i); @@ -491,14 +494,14 @@ get_params_to_use() * Change real numbers into strange dos numbers * \***********************************************/ static void -dos(sec, c, s, h) -int sec; +dos(sec, size, c, s, h) +int sec, size; unsigned char *c, *s, *h; { int cy; int hd; - if (sec == 0) { + if (sec == 0 && size == 0) { *s = *c = *h = 0; return; } -- cgit v1.1