From 0b461cd7de442d2fdc1ec09461c4d8ccda99284e Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Wed, 19 Oct 1994 21:25:28 +0000 Subject: [PATCH] Don't change the active partition when the user says not to change it. Convert absolute sector 0 to C/H/S 0/0/0, not 0/0/1. Open in O_RDWR mode for the undocumented -a option, so that -a can be used without -u. --- sbin/fdisk/fdisk.c | 17 +++++++++++------ sbin/i386/fdisk/fdisk.c | 17 +++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index 933906056f9f..cc8b564712f9 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -390,11 +390,11 @@ struct dos_partition *partp = ((struct dos_partition *) &mboot.parts); if (a_flag && which != -1) active = which; - if (ok("Do you want to change the active partition?")) { - do - Decimal("active partition", active, tmp); - while(!ok("Are you happy with this choice")); - } + if (!ok("Do you want to change the active partition?")) + return; + do + Decimal("active partition", active, tmp); + while (!ok("Are you happy with this choice")); for (i = 0; i < NDOSPART; i++) partp[i].dp_flag = 0; partp[active].dp_flag = ACTIVE; @@ -429,6 +429,11 @@ unsigned char *c, *s, *h; int cy; int hd; + if (sec == 0) { + *s = *c = *h = 0; + return; + } + cy = sec / ( dos_cylsecs ); sec = sec - cy * ( dos_cylsecs ); @@ -456,7 +461,7 @@ struct stat st; if ( !(st.st_mode & S_IFCHR) ) fprintf(stderr,"%s: Device %s is not character special\n", name, disk); - if ((fd = open(disk, u_flag?O_RDWR:O_RDONLY)) == -1) { + if ((fd = open(disk, a_flag || u_flag ? O_RDWR : O_RDONLY)) == -1) { fprintf(stderr,"%s: Can't open device %s\n", name, disk); return -1; } diff --git a/sbin/i386/fdisk/fdisk.c b/sbin/i386/fdisk/fdisk.c index 933906056f9f..cc8b564712f9 100644 --- a/sbin/i386/fdisk/fdisk.c +++ b/sbin/i386/fdisk/fdisk.c @@ -390,11 +390,11 @@ struct dos_partition *partp = ((struct dos_partition *) &mboot.parts); if (a_flag && which != -1) active = which; - if (ok("Do you want to change the active partition?")) { - do - Decimal("active partition", active, tmp); - while(!ok("Are you happy with this choice")); - } + if (!ok("Do you want to change the active partition?")) + return; + do + Decimal("active partition", active, tmp); + while (!ok("Are you happy with this choice")); for (i = 0; i < NDOSPART; i++) partp[i].dp_flag = 0; partp[active].dp_flag = ACTIVE; @@ -429,6 +429,11 @@ unsigned char *c, *s, *h; int cy; int hd; + if (sec == 0) { + *s = *c = *h = 0; + return; + } + cy = sec / ( dos_cylsecs ); sec = sec - cy * ( dos_cylsecs ); @@ -456,7 +461,7 @@ struct stat st; if ( !(st.st_mode & S_IFCHR) ) fprintf(stderr,"%s: Device %s is not character special\n", name, disk); - if ((fd = open(disk, u_flag?O_RDWR:O_RDONLY)) == -1) { + if ((fd = open(disk, a_flag || u_flag ? O_RDWR : O_RDONLY)) == -1) { fprintf(stderr,"%s: Can't open device %s\n", name, disk); return -1; }