From b60eb39594edad8415871dd887a946622b33a60b Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Thu, 15 Sep 1994 20:19:51 +0000 Subject: [PATCH] Don't exit early if the device is not character special or if the device driver cannot supply a label (real or faked). This allows you to practice using fdisk on disposable media (e.g., "dd count=1 /tmp/junk; fdisk /tmp/junk", "dd count=1 /tmp/fix-up-the-mess; fdisk /tmp/fix-up-the-mess") and allows me to test DOSpartitioning and labelling on floppies. --- sbin/fdisk/fdisk.c | 15 +++++++++++---- sbin/i386/fdisk/fdisk.c | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index 7fb728d67d20..933906056f9f 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -452,11 +452,10 @@ struct stat st; fprintf(stderr, "%s: Can't get file status of %s\n", name, disk); return -1; - } else if ( !(st.st_mode & S_IFCHR) ) { + } + if ( !(st.st_mode & S_IFCHR) ) fprintf(stderr,"%s: Device %s is not character special\n", name, disk); - return -1; - } if ((fd = open(disk, u_flag?O_RDWR:O_RDONLY)) == -1) { fprintf(stderr,"%s: Can't open device %s\n", name, disk); return -1; @@ -486,7 +485,15 @@ get_params(verbose) { if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) { - return -1; + fprintf(stderr, + "%s: Can't get disk parameters on %s; supplying dummy ones\n", + name, disk); + dos_cyls = cyls = 1; + dos_heads = heads = 1; + dos_sectors = sectors = 1; + dos_cylsecs = cylsecs = heads * sectors; + disksecs = cyls * heads * sectors; + return disksecs; } dos_cyls = cyls = disklabel.d_ncylinders; diff --git a/sbin/i386/fdisk/fdisk.c b/sbin/i386/fdisk/fdisk.c index 7fb728d67d20..933906056f9f 100644 --- a/sbin/i386/fdisk/fdisk.c +++ b/sbin/i386/fdisk/fdisk.c @@ -452,11 +452,10 @@ struct stat st; fprintf(stderr, "%s: Can't get file status of %s\n", name, disk); return -1; - } else if ( !(st.st_mode & S_IFCHR) ) { + } + if ( !(st.st_mode & S_IFCHR) ) fprintf(stderr,"%s: Device %s is not character special\n", name, disk); - return -1; - } if ((fd = open(disk, u_flag?O_RDWR:O_RDONLY)) == -1) { fprintf(stderr,"%s: Can't open device %s\n", name, disk); return -1; @@ -486,7 +485,15 @@ get_params(verbose) { if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) { - return -1; + fprintf(stderr, + "%s: Can't get disk parameters on %s; supplying dummy ones\n", + name, disk); + dos_cyls = cyls = 1; + dos_heads = heads = 1; + dos_sectors = sectors = 1; + dos_cylsecs = cylsecs = heads * sectors; + disksecs = cyls * heads * sectors; + return disksecs; } dos_cyls = cyls = disklabel.d_ncylinders;