386BSD 0.1 development
[unix-history] / usr / src / sbin / fsck / setup.c
index 8c79252..e29d8e5 100644 (file)
 /*
 /*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1980, 1986 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)setup.c    5.4 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)setup.c    5.33 (Berkeley) 2/22/91";
+#endif /* not lint */
 
 #define DKTYPENAMES
 #include <sys/param.h>
 
 #define DKTYPENAMES
 #include <sys/param.h>
-#include <sys/inode.h>
-#include <sys/fs.h>
+#include <ufs/dinode.h>
+#include <ufs/fs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/disklabel.h>
 #include <sys/file.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/disklabel.h>
 #include <sys/file.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
 #include <ctype.h>
 #include "fsck.h"
 
 #include <ctype.h>
 #include "fsck.h"
 
+struct bufarea asblk;
+#define altsblock (*asblk.b_un.b_fs)
 #define POWEROF2(num)  (((num) & ((num) - 1)) == 0)
 
 #define POWEROF2(num)  (((num) & ((num) - 1)) == 0)
 
-char   *calloc();
+/*
+ * The size of a cylinder group is calculated by CGSIZE. The maximum size
+ * is limited by the fact that cylinder groups are at most one block.
+ * Its size is derived from the size of the maps maintained in the 
+ * cylinder group and the (struct cg) size.
+ */
+#define CGSIZE(fs) \
+    /* base cg */      (sizeof(struct cg) + \
+    /* blktot size */  (fs)->fs_cpg * sizeof(long) + \
+    /* blks size */    (fs)->fs_cpg * (fs)->fs_nrpos * sizeof(short) + \
+    /* inode map */    howmany((fs)->fs_ipg, NBBY) + \
+    /* block map */    howmany((fs)->fs_cpg * (fs)->fs_spc / NSPF(fs), NBBY))
+
 char   *index();
 char   *index();
+struct disklabel *getdisklabel();
 
 setup(dev)
        char *dev;
 {
 
 setup(dev)
        char *dev;
 {
-       dev_t rootdev;
-       long cg, ncg, size, i, j;
+       long cg, size, asked, i, j;
+       long bmapsize;
+       struct disklabel *lp;
        struct stat statb;
        struct fs proto;
 
        struct stat statb;
        struct fs proto;
 
-       if (stat("/", &statb) < 0)
-               errexit("Can't stat root\n");
-       rootdev = statb.st_dev;
+       havesb = 0;
        if (stat(dev, &statb) < 0) {
        if (stat(dev, &statb) < 0) {
-               printf("Can't stat %s\n", dev);
+               printf("Can't stat %s: %s\n", dev, strerror(errno));
                return (0);
        }
                return (0);
        }
-       rawflg = 0;
-       if ((statb.st_mode & S_IFMT) == S_IFBLK)
-               ;
-       else if ((statb.st_mode & S_IFMT) == S_IFCHR)
-               rawflg++;
-       else {
-               if (reply("file is not a block or character device; OK") == 0)
+       if ((statb.st_mode & S_IFMT) != S_IFCHR) {
+               pfatal("%s is not a character device", dev);
+               if (reply("CONTINUE") == 0)
                        return (0);
        }
                        return (0);
        }
-       if (rootdev == statb.st_rdev)
-               hotroot++;
-       if ((dfile.rfdes = open(dev, O_RDONLY)) < 0) {
-               printf("Can't open %s\n", dev);
+       if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
+               printf("Can't open %s: %s\n", dev, strerror(errno));
                return (0);
        }
        if (preen == 0)
                printf("** %s", dev);
                return (0);
        }
        if (preen == 0)
                printf("** %s", dev);
-       if (nflag || (dfile.wfdes = open(dev, O_WRONLY)) < 0) {
-               dfile.wfdes = -1;
+       if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) {
+               fswritefd = -1;
                if (preen)
                        pfatal("NO WRITE ACCESS");
                printf(" (NO WRITE)");
        }
        if (preen == 0)
                printf("\n");
                if (preen)
                        pfatal("NO WRITE ACCESS");
                printf(" (NO WRITE)");
        }
        if (preen == 0)
                printf("\n");
-       dfile.mod = 0;
+       fsmodified = 0;
        lfdir = 0;
        initbarea(&sblk);
        lfdir = 0;
        initbarea(&sblk);
-       initbarea(&fileblk);
-       initbarea(&inoblk);
-       initbarea(&cgblk);
+       initbarea(&asblk);
+       sblk.b_un.b_buf = malloc(SBSIZE);
+       asblk.b_un.b_buf = malloc(SBSIZE);
+       if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
+               errexit("cannot allocate space for superblock\n");
+       if (lp = getdisklabel((char *)NULL, fsreadfd))
+               dev_bsize = secsize = lp->d_secsize;
+       else
+               dev_bsize = secsize = DEV_BSIZE;
+#ifdef tahoe
+       /*
+        * On the tahoe, the disk label and the disk driver disagree.
+        * The label knows that sectors are 512 bytes, but the disk
+        * drivers will only transfer in 1024 sized pieces.
+        */
+       secsize = 1024;
+#endif
        /*
         * Read in the superblock, looking for alternates if necessary
         */
        if (readsb(1) == 0) {
        /*
         * Read in the superblock, looking for alternates if necessary
         */
        if (readsb(1) == 0) {
-               if (bflag || calcsb(dev, dfile.rfdes, &proto) == 0 || preen)
+               if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0)
                        return(0);
                if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
                        return (0);
                        return(0);
                if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
                        return (0);
@@ -95,8 +147,8 @@ setup(dev)
                }
                pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag);
        }
                }
                pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag);
        }
-       fmax = sblock.fs_size;
-       imax = sblock.fs_ncg * sblock.fs_ipg;
+       maxfsblock = sblock.fs_size;
+       maxino = sblock.fs_ncg * sblock.fs_ipg;
        /*
         * Check and potentially fix certain fields in the super block.
         */
        /*
         * Check and potentially fix certain fields in the super block.
         */
@@ -115,39 +167,146 @@ setup(dev)
                        sbdirty();
                }
        }
                        sbdirty();
                }
        }
+       if (sblock.fs_interleave < 1 || 
+           sblock.fs_interleave > sblock.fs_nsect) {
+               pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK",
+                       sblock.fs_interleave);
+               sblock.fs_interleave = 1;
+               if (preen)
+                       printf(" (FIXED)\n");
+               if (preen || reply("SET TO DEFAULT") == 1) {
+                       sbdirty();
+                       dirty(&asblk);
+               }
+       }
+       if (sblock.fs_npsect < sblock.fs_nsect || 
+           sblock.fs_npsect > sblock.fs_nsect*2) {
+               pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK",
+                       sblock.fs_npsect);
+               sblock.fs_npsect = sblock.fs_nsect;
+               if (preen)
+                       printf(" (FIXED)\n");
+               if (preen || reply("SET TO DEFAULT") == 1) {
+                       sbdirty();
+                       dirty(&asblk);
+               }
+       }
+       if (cvtflag) {
+               if (sblock.fs_postblformat == FS_42POSTBLFMT) {
+                       /*
+                        * Requested to convert from old format to new format
+                        */
+                       if (preen)
+                               pwarn("CONVERTING TO NEW FILE SYSTEM FORMAT\n");
+                       else if (!reply("CONVERT TO NEW FILE SYSTEM FORMAT"))
+                               return(0);
+                       sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT;
+                       sblock.fs_nrpos = 8;
+                       sblock.fs_postbloff =
+                           (char *)(&sblock.fs_opostbl[0][0]) -
+                           (char *)(&sblock.fs_link);
+                       sblock.fs_rotbloff = &sblock.fs_space[0] -
+                           (u_char *)(&sblock.fs_link);
+                       sblock.fs_cgsize =
+                               fragroundup(&sblock, CGSIZE(&sblock));
+                       /*
+                        * Planning now for future expansion.
+                        */
+#                      if (BYTE_ORDER == BIG_ENDIAN)
+                               sblock.fs_qbmask.val[0] = 0;
+                               sblock.fs_qbmask.val[1] = ~sblock.fs_bmask;
+                               sblock.fs_qfmask.val[0] = 0;
+                               sblock.fs_qfmask.val[1] = ~sblock.fs_fmask;
+#                      endif /* BIG_ENDIAN */
+#                      if (BYTE_ORDER == LITTLE_ENDIAN)
+                               sblock.fs_qbmask.val[0] = ~sblock.fs_bmask;
+                               sblock.fs_qbmask.val[1] = 0;
+                               sblock.fs_qfmask.val[0] = ~sblock.fs_fmask;
+                               sblock.fs_qfmask.val[1] = 0;
+#                      endif /* LITTLE_ENDIAN */
+                       sbdirty();
+                       dirty(&asblk);
+               } else if (sblock.fs_postblformat == FS_DYNAMICPOSTBLFMT) {
+                       /*
+                        * Requested to convert from new format to old format
+                        */
+                       if (sblock.fs_nrpos != 8 || sblock.fs_ipg > 2048 ||
+                           sblock.fs_cpg > 32 || sblock.fs_cpc > 16) {
+                               printf(
+                               "PARAMETERS OF CURRENT FILE SYSTEM DO NOT\n\t");
+                               errexit(
+                               "ALLOW CONVERSION TO OLD FILE SYSTEM FORMAT\n");
+                       }
+                       if (preen)
+                               pwarn("CONVERTING TO OLD FILE SYSTEM FORMAT\n");
+                       else if (!reply("CONVERT TO OLD FILE SYSTEM FORMAT"))
+                               return(0);
+                       sblock.fs_postblformat = FS_42POSTBLFMT;
+                       sblock.fs_cgsize = fragroundup(&sblock,
+                           sizeof(struct ocg) + howmany(sblock.fs_fpg, NBBY));
+                       sbdirty();
+                       dirty(&asblk);
+               } else {
+                       errexit("UNKNOWN FILE SYSTEM FORMAT\n");
+               }
+       }
+       if (asblk.b_dirty) {
+               bcopy((char *)&sblock, (char *)&altsblock,
+                       (size_t)sblock.fs_sbsize);
+               flush(fswritefd, &asblk);
+       }
        /*
         * read in the summary info.
         */
        /*
         * read in the summary info.
         */
+       asked = 0;
        for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
                size = sblock.fs_cssize - i < sblock.fs_bsize ?
                    sblock.fs_cssize - i : sblock.fs_bsize;
                sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
        for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
                size = sblock.fs_cssize - i < sblock.fs_bsize ?
                    sblock.fs_cssize - i : sblock.fs_bsize;
                sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
-               if (bread(&dfile, (char *)sblock.fs_csp[j],
+               if (bread(fsreadfd, (char *)sblock.fs_csp[j],
                    fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
                    fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
-                   size) != 0)
-                       return (0);
+                   size) != 0 && !asked) {
+                       pfatal("BAD SUMMARY INFORMATION");
+                       if (reply("CONTINUE") == 0)
+                               errexit("");
+                       asked++;
+               }
        }
        /*
         * allocate and initialize the necessary maps
         */
        }
        /*
         * allocate and initialize the necessary maps
         */
-       bmapsz = roundup(howmany(fmax, NBBY), sizeof(short));
-       blockmap = calloc((unsigned)bmapsz, sizeof (char));
+       bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short));
+       blockmap = calloc((unsigned)bmapsize, sizeof (char));
        if (blockmap == NULL) {
        if (blockmap == NULL) {
-               printf("cannot alloc %d bytes for blockmap\n", bmapsz);
+               printf("cannot alloc %u bytes for blockmap\n",
+                   (unsigned)bmapsize);
                goto badsb;
        }
                goto badsb;
        }
-       statemap = calloc((unsigned)(imax + 1), sizeof(char));
+       statemap = calloc((unsigned)(maxino + 1), sizeof(char));
        if (statemap == NULL) {
        if (statemap == NULL) {
-               printf("cannot alloc %d bytes for statemap\n", imax + 1);
+               printf("cannot alloc %u bytes for statemap\n",
+                   (unsigned)(maxino + 1));
                goto badsb;
        }
                goto badsb;
        }
-       lncntp = (short *)calloc((unsigned)(imax + 1), sizeof(short));
+       lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short));
        if (lncntp == NULL) {
        if (lncntp == NULL) {
-               printf("cannot alloc %d bytes for lncntp\n", 
-                   (imax + 1) * sizeof(short));
+               printf("cannot alloc %u bytes for lncntp\n", 
+                   (unsigned)(maxino + 1) * sizeof(short));
                goto badsb;
        }
                goto badsb;
        }
-
+       numdirs = sblock.fs_cstotal.cs_ndir;
+       inplast = 0;
+       listmax = numdirs + 10;
+       inpsort = (struct inoinfo **)calloc((unsigned)listmax,
+           sizeof(struct inoinfo *));
+       inphead = (struct inoinfo **)calloc((unsigned)numdirs,
+           sizeof(struct inoinfo *));
+       if (inpsort == NULL || inphead == NULL) {
+               printf("cannot alloc %u bytes for inphead\n", 
+                   (unsigned)numdirs * sizeof(struct inoinfo *));
+               goto badsb;
+       }
+       bufinit();
        return (1);
 
 badsb:
        return (1);
 
 badsb:
@@ -161,12 +320,9 @@ badsb:
 readsb(listerr)
        int listerr;
 {
 readsb(listerr)
        int listerr;
 {
-       BUFAREA asblk;
-#      define altsblock asblk.b_un.b_fs
-       daddr_t super = bflag ? bflag : SBLOCK;
+       daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
 
 
-       initbarea(&asblk);
-       if (bread(&dfile, (char *)&sblock, super, (long)SBSIZE) != 0)
+       if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0)
                return (0);
        sblk.b_bno = super;
        sblk.b_size = SBSIZE;
                return (0);
        sblk.b_bno = super;
        sblk.b_size = SBSIZE;
@@ -177,23 +333,33 @@ readsb(listerr)
                { badsb(listerr, "MAGIC NUMBER WRONG"); return (0); }
        if (sblock.fs_ncg < 1)
                { badsb(listerr, "NCG OUT OF RANGE"); return (0); }
                { badsb(listerr, "MAGIC NUMBER WRONG"); return (0); }
        if (sblock.fs_ncg < 1)
                { badsb(listerr, "NCG OUT OF RANGE"); return (0); }
-       if (sblock.fs_cpg < 1 || sblock.fs_cpg > MAXCPG)
+       if (sblock.fs_cpg < 1)
                { badsb(listerr, "CPG OUT OF RANGE"); return (0); }
        if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl ||
            (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl)
                { badsb(listerr, "NCYL LESS THAN NCG*CPG"); return (0); }
        if (sblock.fs_sbsize > SBSIZE)
                { badsb(listerr, "SIZE PREPOSTEROUSLY LARGE"); return (0); }
                { badsb(listerr, "CPG OUT OF RANGE"); return (0); }
        if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl ||
            (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl)
                { badsb(listerr, "NCYL LESS THAN NCG*CPG"); return (0); }
        if (sblock.fs_sbsize > SBSIZE)
                { badsb(listerr, "SIZE PREPOSTEROUSLY LARGE"); return (0); }
+       /*
+        * Compute block size that the filesystem is based on,
+        * according to fsbtodb, and adjust superblock block number
+        * so we can tell if this is an alternate later.
+        */
+       super *= dev_bsize;
+       dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
+       sblk.b_bno = super / dev_bsize;
        /*
         * Set all possible fields that could differ, then do check
         * of whole super block against an alternate super block.
         * When an alternate super-block is specified this check is skipped.
         */
        /*
         * Set all possible fields that could differ, then do check
         * of whole super block against an alternate super block.
         * When an alternate super-block is specified this check is skipped.
         */
-       if (bflag)
-               return (1);
        getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
        getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
-       if (asblk.b_errs != NULL)
+       if (asblk.b_errs)
                return (0);
                return (0);
+       if (bflag) {
+               havesb = 1;
+               return (1);
+       }
        altsblock.fs_link = sblock.fs_link;
        altsblock.fs_rlink = sblock.fs_rlink;
        altsblock.fs_time = sblock.fs_time;
        altsblock.fs_link = sblock.fs_link;
        altsblock.fs_rlink = sblock.fs_rlink;
        altsblock.fs_time = sblock.fs_time;
@@ -212,10 +378,22 @@ readsb(listerr)
                sizeof sblock.fs_csp);
        bcopy((char *)sblock.fs_fsmnt, (char *)altsblock.fs_fsmnt,
                sizeof sblock.fs_fsmnt);
                sizeof sblock.fs_csp);
        bcopy((char *)sblock.fs_fsmnt, (char *)altsblock.fs_fsmnt,
                sizeof sblock.fs_fsmnt);
-       if (bcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize))
-               { badsb(listerr, "TRASHED VALUES IN SUPER BLOCK"); return (0); }
+       bcopy((char *)sblock.fs_sparecon, (char *)altsblock.fs_sparecon,
+               sizeof sblock.fs_sparecon);
+       /*
+        * The following should not have to be copied.
+        */
+       altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
+       altsblock.fs_interleave = sblock.fs_interleave;
+       altsblock.fs_npsect = sblock.fs_npsect;
+       altsblock.fs_nrpos = sblock.fs_nrpos;
+       if (bcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
+               badsb(listerr,
+               "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
+               return (0);
+       }
+       havesb = 1;
        return (1);
        return (1);
-#      undef altsblock
 }
 
 badsb(listerr, s)
 }
 
 badsb(listerr, s)
@@ -244,7 +422,6 @@ calcsb(dev, devfd, fs)
        register struct disklabel *lp;
        register struct partition *pp;
        register char *cp;
        register struct disklabel *lp;
        register struct partition *pp;
        register char *cp;
-       struct disklabel *getdisklabel();
        int i;
 
        cp = index(dev, '\0') - 1;
        int i;
 
        cp = index(dev, '\0') - 1;
@@ -258,12 +435,12 @@ calcsb(dev, devfd, fs)
        else
                pp = &lp->d_partitions[*cp - 'a'];
        if (pp->p_fstype != FS_BSDFFS) {
        else
                pp = &lp->d_partitions[*cp - 'a'];
        if (pp->p_fstype != FS_BSDFFS) {
-               pfatal("%s: NOT FORMATTED AS A BSD FILE SYSTEM (%s)\n",
+               pfatal("%s: NOT LABELED AS A BSD FILE SYSTEM (%s)\n",
                        dev, pp->p_fstype < FSMAXTYPES ?
                        fstypenames[pp->p_fstype] : "unknown");
                return (0);
        }
                        dev, pp->p_fstype < FSMAXTYPES ?
                        fstypenames[pp->p_fstype] : "unknown");
                return (0);
        }
-       bzero(fs, sizeof(struct fs));
+       bzero((char *)fs, sizeof(struct fs));
        fs->fs_fsize = pp->p_fsize;
        fs->fs_frag = pp->p_frag;
        fs->fs_cpg = pp->p_cpg;
        fs->fs_fsize = pp->p_fsize;
        fs->fs_frag = pp->p_frag;
        fs->fs_cpg = pp->p_cpg;
@@ -286,10 +463,10 @@ calcsb(dev, devfd, fs)
        fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg);
        for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1)
                fs->fs_fsbtodb++;
        fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg);
        for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1)
                fs->fs_fsbtodb++;
+       dev_bsize = lp->d_secsize;
        return (1);
 }
 
        return (1);
 }
 
-#ifdef byioctl
 struct disklabel *
 getdisklabel(s, fd)
        char *s;
 struct disklabel *
 getdisklabel(s, fd)
        char *s;
@@ -298,60 +475,10 @@ getdisklabel(s, fd)
        static struct disklabel lab;
 
        if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) {
        static struct disklabel lab;
 
        if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) {
-               perror("ioctl (GDINFO)");
-               fatal("%s: can't read disk label", s);
+               if (s == NULL)
+                       return ((struct disklabel *)NULL);
+               pwarn("ioctl (GCINFO): %s\n", strerror(errno));
+               errexit("%s: can't read disk label\n", s);
        }
        return (&lab);
 }
        }
        return (&lab);
 }
-#else byioctl
-char specname[64];
-char boot[BBSIZE];
-
-struct disklabel *
-getdisklabel(s, fd)
-       char *s;
-       int     fd;
-{
-       char *cp;
-       u_long magic = htonl(DISKMAGIC);
-       register struct disklabel *lp;
-       int cfd;
-
-       /*
-        * Make name for 'c' partition.
-        */
-       strcpy(specname, s);
-       cp = specname + strlen(specname) - 1;
-       if (!isdigit(*cp))
-               *cp = 'c';
-       cfd = open(specname, O_RDONLY);
-       if (cfd < 0) {
-               perror(specname);
-               exit(2);
-       }
-
-       if (read(cfd, boot, BBSIZE) < BBSIZE) {
-               perror(specname);
-               exit(2);
-       }
-       close(cfd);
-       for (lp = (struct disklabel *)(boot + LABELOFFSET);
-           lp <= (struct disklabel *)(boot + BBSIZE -
-           sizeof(struct disklabel));
-           lp = (struct disklabel *)((char *)lp + 128))
-               if (lp->d_magic == magic && lp->d_magic2 == magic)
-                       break;
-       if (lp > (struct disklabel *)(boot + BBSIZE -
-           sizeof(struct disklabel)) ||
-           lp->d_magic != magic || lp->d_magic2 != magic ||
-           dkcksum(lp) != 0) {
-               printf("Bad pack magic number %s\n",
-                       "(label is damaged, or pack is unlabeled)");
-               exit(1);
-       }
-#if ENDIAN != BIG
-       swablabel(lp);
-#endif
-       return (lp);
-}
-#endif byioctl