cg_link => cg_firstfield; fs_link => fs_firstfield
[unix-history] / usr / src / sbin / fsck / setup.c
index 7cbcc34..fa6899f 100644 (file)
@@ -1,16 +1,17 @@
 /*
 /*
- * Copyright (c) 1980, 1986 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1986, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * %sccs.include.redist.c%
  */
 
 #ifndef lint
  *
  * %sccs.include.redist.c%
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)setup.c    5.35 (Berkeley) %G%";
+static char sccsid[] = "@(#)setup.c    8.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #define DKTYPENAMES
 #include <sys/param.h>
 #endif /* not lint */
 
 #define DKTYPENAMES
 #include <sys/param.h>
+#include <sys/time.h>
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
 #include <sys/stat.h>
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
 #include <sys/stat.h>
@@ -27,20 +28,6 @@ struct bufarea asblk;
 #define altsblock (*asblk.b_un.b_fs)
 #define POWEROF2(num)  (((num) & ((num) - 1)) == 0)
 
 #define altsblock (*asblk.b_un.b_fs)
 #define POWEROF2(num)  (((num) & ((num) - 1)) == 0)
 
-/*
- * 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();
 struct disklabel *getdisklabel();
 
 setup(dev)
 struct disklabel *getdisklabel();
 
 setup(dev)
@@ -49,10 +36,12 @@ setup(dev)
        long cg, size, asked, i, j;
        long bmapsize;
        struct disklabel *lp;
        long cg, size, asked, i, j;
        long bmapsize;
        struct disklabel *lp;
+       off_t sizepb;
        struct stat statb;
        struct fs proto;
 
        havesb = 0;
        struct stat statb;
        struct fs proto;
 
        havesb = 0;
+       fswritefd = -1;
        if (stat(dev, &statb) < 0) {
                printf("Can't stat %s: %s\n", dev, strerror(errno));
                return (0);
        if (stat(dev, &statb) < 0) {
                printf("Can't stat %s: %s\n", dev, strerror(errno));
                return (0);
@@ -88,14 +77,6 @@ setup(dev)
                dev_bsize = secsize = lp->d_secsize;
        else
                dev_bsize = secsize = DEV_BSIZE;
                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
         */
        /*
         * Read in the superblock, looking for alternates if necessary
         */
@@ -157,63 +138,55 @@ setup(dev)
                        dirty(&asblk);
                }
        }
                        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.
-                        */
-#                      ifdef _NOQUAD
-                               sblock.fs_qbmask.val[_QUAD_HIGHWORD] = 0;
-                               sblock.fs_qbmask.val[_QUAD_LOWWORD] =
-                                   ~sblock.fs_bmask;
-                               sblock.fs_qfmask.val[_QUAD_HIGHWORD] = 0;
-                               sblock.fs_qfmask.val[_QUAD_LOWWORD] =
-                                   ~sblock.fs_fmask;
-#                      else /* QUAD */
-                               sblock.fs_qbmask = ~sblock.fs_bmask;
-                               sblock.fs_qfmask = ~sblock.fs_fmask;
-#                      endif /* QUAD */
-                       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 (sblock.fs_inodefmt >= FS_44INODEFMT) {
+               newinofmt = 1;
+       } else {
+               sblock.fs_qbmask = ~sblock.fs_bmask;
+               sblock.fs_qfmask = ~sblock.fs_fmask;
+               newinofmt = 0;
+       }
+       /*
+        * Convert to new inode format.
+        */
+       if (cvtlevel >= 2 && sblock.fs_inodefmt < FS_44INODEFMT) {
+               if (preen)
+                       pwarn("CONVERTING TO NEW INODE FORMAT\n");
+               else if (!reply("CONVERT TO NEW INODE FORMAT"))
+                       return(0);
+               doinglevel2++;
+               sblock.fs_inodefmt = FS_44INODEFMT;
+               sizepb = sblock.fs_bsize;
+               sblock.fs_maxfilesize = sblock.fs_bsize * NDADDR - 1;
+               for (i = 0; i < NIADDR; i++) {
+                       sizepb *= NINDIR(&sblock);
+                       sblock.fs_maxfilesize += sizepb;
                }
                }
+               sblock.fs_maxsymlinklen = MAXSYMLINKLEN;
+               sblock.fs_qbmask = ~sblock.fs_bmask;
+               sblock.fs_qfmask = ~sblock.fs_fmask;
+               sbdirty();
+               dirty(&asblk);
+       }
+       /*
+        * Convert to new cylinder group format.
+        */
+       if (cvtlevel >= 1 && sblock.fs_postblformat == FS_42POSTBLFMT) {
+               if (preen)
+                       pwarn("CONVERTING TO NEW CYLINDER GROUP FORMAT\n");
+               else if (!reply("CONVERT TO NEW CYLINDER GROUP FORMAT"))
+                       return(0);
+               doinglevel1++;
+               sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT;
+               sblock.fs_nrpos = 8;
+               sblock.fs_postbloff =
+                   (char *)(&sblock.fs_opostbl[0][0]) -
+                   (char *)(&sblock.fs_firstfield);
+               sblock.fs_rotbloff = &sblock.fs_space[0] -
+                   (u_char *)(&sblock.fs_firstfield);
+               sblock.fs_cgsize =
+                       fragroundup(&sblock, CGSIZE(&sblock));
+               sbdirty();
+               dirty(&asblk);
        }
        if (asblk.b_dirty) {
                bcopy((char *)&sblock, (char *)&altsblock,
        }
        if (asblk.b_dirty) {
                bcopy((char *)&sblock, (char *)&altsblock,
@@ -253,6 +226,12 @@ setup(dev)
                    (unsigned)(maxino + 1));
                goto badsb;
        }
                    (unsigned)(maxino + 1));
                goto badsb;
        }
+       typemap = calloc((unsigned)(maxino + 1), sizeof(char));
+       if (typemap == NULL) {
+               printf("cannot alloc %u bytes for typemap\n",
+                   (unsigned)(maxino + 1));
+               goto badsb;
+       }
        lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short));
        if (lncntp == NULL) {
                printf("cannot alloc %u bytes for lncntp\n", 
        lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short));
        if (lncntp == NULL) {
                printf("cannot alloc %u bytes for lncntp\n", 
@@ -313,6 +292,10 @@ readsb(listerr)
        super *= dev_bsize;
        dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
        sblk.b_bno = super / dev_bsize;
        super *= dev_bsize;
        dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
        sblk.b_bno = super / dev_bsize;
+       if (bflag) {
+               havesb = 1;
+               return (1);
+       }
        /*
         * Set all possible fields that could differ, then do check
         * of whole super block against an alternate super block.
        /*
         * Set all possible fields that could differ, then do check
         * of whole super block against an alternate super block.
@@ -321,12 +304,6 @@ readsb(listerr)
        getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
        if (asblk.b_errs)
                return (0);
        getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
        if (asblk.b_errs)
                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_cstotal = sblock.fs_cstotal;
        altsblock.fs_cgrotor = sblock.fs_cgrotor;
        altsblock.fs_time = sblock.fs_time;
        altsblock.fs_cstotal = sblock.fs_cstotal;
        altsblock.fs_cgrotor = sblock.fs_cgrotor;
@@ -352,6 +329,11 @@ readsb(listerr)
        altsblock.fs_interleave = sblock.fs_interleave;
        altsblock.fs_npsect = sblock.fs_npsect;
        altsblock.fs_nrpos = sblock.fs_nrpos;
        altsblock.fs_interleave = sblock.fs_interleave;
        altsblock.fs_npsect = sblock.fs_npsect;
        altsblock.fs_nrpos = sblock.fs_nrpos;
+       altsblock.fs_state = sblock.fs_state;
+       altsblock.fs_qbmask = sblock.fs_qbmask;
+       altsblock.fs_qfmask = sblock.fs_qfmask;
+       altsblock.fs_state = sblock.fs_state;
+       altsblock.fs_maxfilesize = sblock.fs_maxfilesize;
        if (bcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
                badsb(listerr,
                "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
        if (bcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
                badsb(listerr,
                "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
@@ -369,7 +351,7 @@ badsb(listerr, s)
        if (!listerr)
                return;
        if (preen)
        if (!listerr)
                return;
        if (preen)
-               printf("%s: ", devname);
+               printf("%s: ", cdevname);
        pfatal("BAD SUPER BLOCK: %s\n", s);
 }
 
        pfatal("BAD SUPER BLOCK: %s\n", s);
 }