Home | History | Annotate | Line # | Download | only in fsck_ffs
pass5.c revision 1.35
      1  1.35      fvdl /*	$NetBSD: pass5.c,v 1.35 2003/04/04 13:45:21 fvdl Exp $	*/
      2  1.13       cgd 
      3   1.1       cgd /*
      4   1.6   mycroft  * Copyright (c) 1980, 1986, 1993
      5   1.6   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  */
     35   1.1       cgd 
     36  1.17     lukem #include <sys/cdefs.h>
     37   1.1       cgd #ifndef lint
     38  1.13       cgd #if 0
     39  1.18     lukem static char sccsid[] = "@(#)pass5.c	8.9 (Berkeley) 4/28/95";
     40  1.13       cgd #else
     41  1.35      fvdl __RCSID("$NetBSD: pass5.c,v 1.35 2003/04/04 13:45:21 fvdl Exp $");
     42  1.13       cgd #endif
     43   1.1       cgd #endif /* not lint */
     44   1.1       cgd 
     45   1.1       cgd #include <sys/param.h>
     46   1.5       cgd #include <sys/time.h>
     47  1.18     lukem 
     48   1.6   mycroft #include <ufs/ufs/dinode.h>
     49   1.6   mycroft #include <ufs/ffs/fs.h>
     50  1.19    bouyer #include <ufs/ffs/ffs_extern.h>
     51  1.19    bouyer #include <ufs/ufs/ufs_bswap.h>
     52  1.18     lukem 
     53  1.18     lukem #include <err.h>
     54   1.1       cgd #include <string.h>
     55  1.19    bouyer #include <malloc.h>
     56  1.15  christos 
     57  1.16  christos #include "fsutil.h"
     58   1.1       cgd #include "fsck.h"
     59  1.10       cgd #include "extern.h"
     60   1.1       cgd 
     61  1.19    bouyer void print_bmap __P((u_char *,u_int32_t));
     62  1.35      fvdl static void dumpcg(struct cg *cg);
     63  1.35      fvdl static void dumptotal(struct csum_total *cs);
     64  1.19    bouyer 
     65  1.10       cgd void
     66  1.34      fvdl pass5(void)
     67   1.1       cgd {
     68  1.34      fvdl 	int c, blk, frags, basesize, mapsize;
     69  1.21      fvdl 	int inomapsize, blkmapsize;
     70  1.19    bouyer 	struct fs *fs = sblock;
     71  1.32      fvdl 	daddr_t dbase, dmax;
     72  1.32      fvdl 	daddr_t d;
     73  1.21      fvdl 	long i, j, k;
     74   1.1       cgd 	struct csum *cs;
     75  1.34      fvdl 	struct csum_total cstotal;
     76  1.26   thorpej 	struct inodesc idesc[4];
     77   1.1       cgd 	char buf[MAXBSIZE];
     78  1.17     lukem 	struct cg *newcg = (struct cg *)buf;
     79  1.21      fvdl 	struct cg *cg = cgrp;
     80  1.34      fvdl 	struct inostat *info;
     81   1.1       cgd 
     82  1.34      fvdl 	inoinfo(WINO)->ino_state = USTATE;
     83   1.7   mycroft 	memset(newcg, 0, (size_t)fs->fs_cgsize);
     84   1.1       cgd 	newcg->cg_niblk = fs->fs_ipg;
     85  1.12   mycroft 	if (cvtlevel >= 3) {
     86   1.6   mycroft 		if (fs->fs_maxcontig < 2 && fs->fs_contigsumsize > 0) {
     87   1.6   mycroft 			if (preen)
     88   1.6   mycroft 				pwarn("DELETING CLUSTERING MAPS\n");
     89   1.6   mycroft 			if (preen || reply("DELETE CLUSTERING MAPS")) {
     90   1.6   mycroft 				fs->fs_contigsumsize = 0;
     91   1.6   mycroft 				doinglevel1 = 1;
     92   1.6   mycroft 				sbdirty();
     93   1.6   mycroft 			}
     94   1.6   mycroft 		}
     95   1.6   mycroft 		if (fs->fs_maxcontig > 1) {
     96   1.6   mycroft 			char *doit = 0;
     97   1.6   mycroft 
     98   1.6   mycroft 			if (fs->fs_contigsumsize < 1) {
     99   1.6   mycroft 				doit = "CREAT";
    100   1.6   mycroft 			} else if (fs->fs_contigsumsize < fs->fs_maxcontig &&
    101   1.6   mycroft 				   fs->fs_contigsumsize < FS_MAXCONTIG) {
    102   1.6   mycroft 				doit = "EXPAND";
    103   1.6   mycroft 			}
    104   1.6   mycroft 			if (doit) {
    105   1.6   mycroft 				i = fs->fs_contigsumsize;
    106   1.6   mycroft 				fs->fs_contigsumsize =
    107   1.6   mycroft 				    MIN(fs->fs_maxcontig, FS_MAXCONTIG);
    108   1.6   mycroft 				if (CGSIZE(fs) > fs->fs_bsize) {
    109   1.6   mycroft 					pwarn("CANNOT %s CLUSTER MAPS\n", doit);
    110   1.6   mycroft 					fs->fs_contigsumsize = i;
    111   1.6   mycroft 				} else if (preen ||
    112   1.6   mycroft 				    reply("CREATE CLUSTER MAPS")) {
    113   1.6   mycroft 					if (preen)
    114   1.6   mycroft 						pwarn("%sING CLUSTER MAPS\n",
    115   1.6   mycroft 						    doit);
    116   1.6   mycroft 					fs->fs_cgsize =
    117   1.6   mycroft 					    fragroundup(fs, CGSIZE(fs));
    118  1.21      fvdl 					cg = cgrp =
    119  1.21      fvdl 					    realloc(cgrp, fs->fs_cgsize);
    120  1.21      fvdl 					if (cg == NULL)
    121  1.21      fvdl 						errx(EEXIT,
    122  1.21      fvdl 						"cannot reallocate cg space");
    123   1.6   mycroft 					doinglevel1 = 1;
    124   1.6   mycroft 					sbdirty();
    125   1.6   mycroft 				}
    126   1.6   mycroft 			}
    127   1.6   mycroft 		}
    128   1.6   mycroft 	}
    129  1.34      fvdl 	basesize = &newcg->cg_space[0] - (u_char *)(&newcg->cg_firstfield);
    130  1.34      fvdl 	if (is_ufs2) {
    131  1.34      fvdl 		newcg->cg_iusedoff = basesize;
    132  1.34      fvdl 	} else {
    133  1.34      fvdl 		/*
    134  1.34      fvdl 		 * We reserve the space for the old rotation summary
    135  1.34      fvdl 		 * tables for the benefit of old kernels, but do not
    136  1.34      fvdl 		 * maintain them in modern kernels. In time, they can
    137  1.34      fvdl 		 * go away.
    138  1.34      fvdl 		 */
    139  1.34      fvdl 		newcg->cg_old_btotoff = basesize;
    140  1.34      fvdl 		newcg->cg_old_boff = newcg->cg_old_btotoff +
    141  1.34      fvdl 		    fs->fs_old_cpg * sizeof(int32_t);
    142  1.34      fvdl 		newcg->cg_iusedoff = newcg->cg_old_boff +
    143  1.34      fvdl 		    fs->fs_old_cpg * fs->fs_old_nrpos * sizeof(u_int16_t);
    144  1.34      fvdl 		memset(&newcg->cg_space[0], 0, newcg->cg_iusedoff - basesize);
    145  1.34      fvdl 	}
    146  1.34      fvdl 	inomapsize = howmany(fs->fs_ipg, CHAR_BIT);
    147  1.34      fvdl 	newcg->cg_freeoff = newcg->cg_iusedoff + inomapsize;
    148  1.34      fvdl 	blkmapsize = howmany(fs->fs_fpg, CHAR_BIT);
    149  1.34      fvdl 	newcg->cg_nextfreeoff = newcg->cg_freeoff + blkmapsize;
    150  1.34      fvdl 	if (fs->fs_contigsumsize > 0) {
    151  1.34      fvdl 		newcg->cg_clustersumoff = newcg->cg_nextfreeoff -
    152  1.34      fvdl 		    sizeof(u_int32_t);
    153  1.34      fvdl 		newcg->cg_clustersumoff =
    154  1.34      fvdl 		    roundup(newcg->cg_clustersumoff, sizeof(u_int32_t));
    155  1.34      fvdl 		newcg->cg_clusteroff = newcg->cg_clustersumoff +
    156  1.34      fvdl 		    (fs->fs_contigsumsize + 1) * sizeof(u_int32_t);
    157  1.34      fvdl 		newcg->cg_nextfreeoff = newcg->cg_clusteroff +
    158  1.34      fvdl 		    howmany(fragstoblks(fs, fs->fs_fpg), CHAR_BIT);
    159   1.1       cgd 	}
    160  1.34      fvdl 	newcg->cg_magic = CG_MAGIC;
    161  1.34      fvdl 	mapsize = newcg->cg_nextfreeoff - newcg->cg_iusedoff;
    162   1.7   mycroft 	memset(&idesc[0], 0, sizeof idesc);
    163  1.26   thorpej 	for (i = 0; i < 4; i++) {
    164   1.1       cgd 		idesc[i].id_type = ADDR;
    165  1.34      fvdl 		if (!is_ufs2 && doinglevel2)
    166   1.6   mycroft 			idesc[i].id_fix = FIX;
    167   1.6   mycroft 	}
    168  1.34      fvdl 	memset(&cstotal, 0, sizeof(struct csum_total));
    169  1.34      fvdl 	dmax = blknum(fs, fs->fs_size + fs->fs_frag - 1);
    170  1.34      fvdl 	for (d = fs->fs_size; d < dmax; d++)
    171  1.34      fvdl 		setbmap(d);
    172   1.1       cgd 	for (c = 0; c < fs->fs_ncg; c++) {
    173  1.29     lukem 		if (got_siginfo) {
    174  1.29     lukem 			fprintf(stderr,
    175  1.29     lukem 			    "%s: phase 5: cyl group %d of %d (%d%%)\n",
    176  1.29     lukem 			    cdevname(), c, fs->fs_ncg,
    177  1.29     lukem 			    c * 100 / fs->fs_ncg);
    178  1.29     lukem 			got_siginfo = 0;
    179  1.29     lukem 		}
    180   1.1       cgd 		getblk(&cgblk, cgtod(fs, c), fs->fs_cgsize);
    181  1.19    bouyer 		memcpy(cg, cgblk.b_un.b_cg, fs->fs_cgsize);
    182  1.19    bouyer 		if((doswap && !needswap) || (!doswap && needswap))
    183  1.34      fvdl 			ffs_cg_swap(cgblk.b_un.b_cg, cg, sblock);
    184  1.19    bouyer 		if (!cg_chkmagic(cg, 0))
    185  1.21      fvdl 			pfatal("CG %d: PASS5: BAD MAGIC NUMBER\n", c);
    186  1.19    bouyer 		if(doswap)
    187  1.19    bouyer 			cgdirty();
    188  1.26   thorpej 		/*
    189  1.26   thorpej 		 * While we have the disk head where we want it,
    190  1.26   thorpej 		 * write back the superblock to the spare at this
    191  1.26   thorpej 		 * cylinder group.
    192  1.26   thorpej 		 */
    193  1.26   thorpej 		if ((cvtlevel && sblk.b_dirty) || doswap) {
    194  1.26   thorpej 			bwrite(fswritefd, sblk.b_un.b_buf,
    195  1.26   thorpej 			    fsbtodb(sblock, cgsblock(sblock, c)),
    196  1.26   thorpej 			    sblock->fs_sbsize);
    197  1.26   thorpej 		} else {
    198  1.26   thorpej 			/*
    199  1.26   thorpej 			 * Read in the current alternate superblock,
    200  1.26   thorpej 			 * and compare it to the master.  If it's
    201  1.26   thorpej 			 * wrong, fix it up.
    202  1.26   thorpej 			 */
    203  1.26   thorpej 			getblk(&asblk, cgsblock(sblock, c), sblock->fs_sbsize);
    204  1.26   thorpej 			if (asblk.b_errs)
    205  1.26   thorpej 				pfatal("CG %d: UNABLE TO READ ALTERNATE "
    206  1.26   thorpej 				    "SUPERBLK\n", c);
    207  1.26   thorpej 			else {
    208  1.26   thorpej 				memmove(altsblock, asblk.b_un.b_fs,
    209  1.26   thorpej 				    sblock->fs_sbsize);
    210  1.26   thorpej 				if (needswap)
    211  1.27     lukem 					ffs_sb_swap(asblk.b_un.b_fs, altsblock);
    212  1.26   thorpej 			}
    213  1.26   thorpej 			if ((asblk.b_errs || cmpsblks(sblock, altsblock)) &&
    214  1.26   thorpej 			     dofix(&idesc[3],
    215  1.26   thorpej 				   "ALTERNATE SUPERBLK(S) ARE INCORRECT")) {
    216  1.26   thorpej 				bwrite(fswritefd, sblk.b_un.b_buf,
    217  1.26   thorpej 				    fsbtodb(sblock, cgsblock(sblock, c)),
    218  1.26   thorpej 				    sblock->fs_sbsize);
    219  1.26   thorpej 			}
    220  1.26   thorpej 		}
    221   1.1       cgd 		dbase = cgbase(fs, c);
    222   1.1       cgd 		dmax = dbase + fs->fs_fpg;
    223   1.1       cgd 		if (dmax > fs->fs_size)
    224   1.1       cgd 			dmax = fs->fs_size;
    225   1.6   mycroft 		newcg->cg_time = cg->cg_time;
    226  1.34      fvdl 		newcg->cg_old_time = cg->cg_old_time;
    227   1.1       cgd 		newcg->cg_cgx = c;
    228   1.1       cgd 		newcg->cg_ndblk = dmax - dbase;
    229  1.34      fvdl 		if (!is_ufs2) {
    230  1.34      fvdl 			if (c == fs->fs_ncg - 1)
    231  1.34      fvdl 				newcg->cg_old_ncyl = howmany(newcg->cg_ndblk,
    232  1.34      fvdl 				    fs->fs_fpg / fs->fs_old_cpg);
    233  1.34      fvdl 			else
    234  1.34      fvdl 				newcg->cg_old_ncyl = fs->fs_old_cpg;
    235  1.34      fvdl 			newcg->cg_old_niblk = fs->fs_ipg;
    236  1.34      fvdl 			newcg->cg_niblk = 0;
    237  1.34      fvdl 		}
    238   1.6   mycroft 		if (fs->fs_contigsumsize > 0)
    239   1.6   mycroft 			newcg->cg_nclusterblks = newcg->cg_ndblk / fs->fs_frag;
    240   1.1       cgd 		newcg->cg_cs.cs_ndir = 0;
    241   1.1       cgd 		newcg->cg_cs.cs_nffree = 0;
    242   1.1       cgd 		newcg->cg_cs.cs_nbfree = 0;
    243   1.1       cgd 		newcg->cg_cs.cs_nifree = fs->fs_ipg;
    244  1.25   mycroft 		if (cg->cg_rotor >= 0 && cg->cg_rotor < newcg->cg_ndblk)
    245   1.1       cgd 			newcg->cg_rotor = cg->cg_rotor;
    246   1.1       cgd 		else
    247   1.1       cgd 			newcg->cg_rotor = 0;
    248  1.25   mycroft 		if (cg->cg_frotor >= 0 && cg->cg_frotor < newcg->cg_ndblk)
    249   1.1       cgd 			newcg->cg_frotor = cg->cg_frotor;
    250   1.1       cgd 		else
    251   1.1       cgd 			newcg->cg_frotor = 0;
    252  1.35      fvdl 		if (cg->cg_irotor >= 0 && cg->cg_irotor < fs->fs_ipg)
    253   1.1       cgd 			newcg->cg_irotor = cg->cg_irotor;
    254   1.1       cgd 		else
    255   1.1       cgd 			newcg->cg_irotor = 0;
    256  1.34      fvdl 		if (!is_ufs2) {
    257  1.34      fvdl 			newcg->cg_initediblk = 0;
    258  1.34      fvdl 		} else {
    259  1.34      fvdl 			if ((unsigned)cg->cg_initediblk > fs->fs_ipg)
    260  1.34      fvdl 				newcg->cg_initediblk = fs->fs_ipg;
    261  1.34      fvdl 			else
    262  1.34      fvdl 				newcg->cg_initediblk = cg->cg_initediblk;
    263  1.34      fvdl 		}
    264   1.7   mycroft 		memset(&newcg->cg_frsum[0], 0, sizeof newcg->cg_frsum);
    265  1.34      fvdl 		memset(cg_inosused(newcg, 0), 0, (size_t)(mapsize));
    266   1.1       cgd 		j = fs->fs_ipg * c;
    267   1.1       cgd 		for (i = 0; i < fs->fs_ipg; j++, i++) {
    268  1.34      fvdl 			info = inoinfo(j);
    269  1.34      fvdl 			switch (info->ino_state) {
    270   1.1       cgd 
    271   1.1       cgd 			case USTATE:
    272   1.1       cgd 				break;
    273   1.1       cgd 
    274   1.1       cgd 			case DSTATE:
    275   1.1       cgd 			case DCLEAR:
    276   1.1       cgd 			case DFOUND:
    277   1.1       cgd 				newcg->cg_cs.cs_ndir++;
    278   1.1       cgd 				/* fall through */
    279   1.1       cgd 
    280   1.1       cgd 			case FSTATE:
    281   1.1       cgd 			case FCLEAR:
    282   1.1       cgd 				newcg->cg_cs.cs_nifree--;
    283  1.19    bouyer 				setbit(cg_inosused(newcg, 0), i);
    284   1.1       cgd 				break;
    285   1.1       cgd 
    286   1.1       cgd 			default:
    287   1.1       cgd 				if (j < ROOTINO)
    288   1.1       cgd 					break;
    289  1.18     lukem 				errx(EEXIT, "BAD STATE %d FOR INODE I=%ld",
    290  1.34      fvdl 				    info->ino_state, (long)j);
    291   1.1       cgd 			}
    292   1.1       cgd 		}
    293   1.1       cgd 		if (c == 0)
    294   1.1       cgd 			for (i = 0; i < ROOTINO; i++) {
    295  1.19    bouyer 				setbit(cg_inosused(newcg, 0), i);
    296   1.1       cgd 				newcg->cg_cs.cs_nifree--;
    297   1.1       cgd 			}
    298   1.1       cgd 		for (i = 0, d = dbase;
    299   1.1       cgd 		     d < dmax;
    300   1.1       cgd 		     d += fs->fs_frag, i += fs->fs_frag) {
    301   1.1       cgd 			frags = 0;
    302   1.1       cgd 			for (j = 0; j < fs->fs_frag; j++) {
    303   1.1       cgd 				if (testbmap(d + j))
    304   1.1       cgd 					continue;
    305  1.19    bouyer 				setbit(cg_blksfree(newcg, 0), i + j);
    306   1.1       cgd 				frags++;
    307   1.1       cgd 			}
    308   1.1       cgd 			if (frags == fs->fs_frag) {
    309   1.1       cgd 				newcg->cg_cs.cs_nbfree++;
    310   1.6   mycroft 				if (fs->fs_contigsumsize > 0)
    311  1.19    bouyer 					setbit(cg_clustersfree(newcg, 0),
    312  1.28   mycroft 					    fragstoblks(fs, i));
    313   1.1       cgd 			} else if (frags > 0) {
    314   1.1       cgd 				newcg->cg_cs.cs_nffree += frags;
    315  1.19    bouyer 				blk = blkmap(fs, cg_blksfree(newcg, 0), i);
    316  1.19    bouyer 				ffs_fragacct(fs, blk, newcg->cg_frsum, 1, 0);
    317   1.6   mycroft 			}
    318   1.6   mycroft 		}
    319   1.6   mycroft 		if (fs->fs_contigsumsize > 0) {
    320  1.19    bouyer 			int32_t *sump = cg_clustersum(newcg, 0);
    321  1.19    bouyer 			u_char *mapp = cg_clustersfree(newcg, 0);
    322   1.6   mycroft 			int map = *mapp++;
    323   1.6   mycroft 			int bit = 1;
    324   1.6   mycroft 			int run = 0;
    325   1.6   mycroft 
    326   1.6   mycroft 			for (i = 0; i < newcg->cg_nclusterblks; i++) {
    327   1.6   mycroft 				if ((map & bit) != 0) {
    328   1.6   mycroft 					run++;
    329   1.6   mycroft 				} else if (run != 0) {
    330   1.6   mycroft 					if (run > fs->fs_contigsumsize)
    331   1.6   mycroft 						run = fs->fs_contigsumsize;
    332   1.6   mycroft 					sump[run]++;
    333   1.6   mycroft 					run = 0;
    334   1.6   mycroft 				}
    335   1.6   mycroft 				if ((i & (NBBY - 1)) != (NBBY - 1)) {
    336   1.6   mycroft 					bit <<= 1;
    337   1.6   mycroft 				} else {
    338   1.6   mycroft 					map = *mapp++;
    339   1.6   mycroft 					bit = 1;
    340   1.6   mycroft 				}
    341   1.6   mycroft 			}
    342   1.6   mycroft 			if (run != 0) {
    343   1.6   mycroft 				if (run > fs->fs_contigsumsize)
    344   1.6   mycroft 					run = fs->fs_contigsumsize;
    345   1.6   mycroft 				sump[run]++;
    346   1.1       cgd 			}
    347   1.1       cgd 		}
    348   1.1       cgd 		cstotal.cs_nffree += newcg->cg_cs.cs_nffree;
    349   1.1       cgd 		cstotal.cs_nbfree += newcg->cg_cs.cs_nbfree;
    350   1.1       cgd 		cstotal.cs_nifree += newcg->cg_cs.cs_nifree;
    351   1.1       cgd 		cstotal.cs_ndir += newcg->cg_cs.cs_ndir;
    352   1.1       cgd 		cs = &fs->fs_cs(fs, c);
    353  1.20      ross 		if (memcmp(&newcg->cg_cs, cs, sizeof *cs) != 0) {
    354  1.19    bouyer 			if (dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
    355  1.34      fvdl 				memmove(cs, &newcg->cg_cs, sizeof *cs);
    356  1.34      fvdl 				sbdirty();
    357  1.19    bouyer 			} else
    358  1.19    bouyer 				markclean = 0;
    359  1.20      ross 		}
    360   1.6   mycroft 		if (doinglevel1) {
    361  1.18     lukem 			memmove(cg, newcg, (size_t)fs->fs_cgsize);
    362   1.1       cgd 			cgdirty();
    363   1.1       cgd 			continue;
    364   1.1       cgd 		}
    365  1.34      fvdl 		if (memcmp(newcg, cg, basesize) != 0) {
    366  1.35      fvdl 			dumpcg(newcg);
    367  1.35      fvdl 			dumpcg(cg);
    368  1.34      fvdl 		 	if (dofix(&idesc[2], "SUMMARY INFORMATION BAD")) {
    369  1.34      fvdl 				memmove(cg, newcg, (size_t)basesize);
    370  1.34      fvdl 				cgdirty();
    371  1.21      fvdl 			} else
    372  1.21      fvdl 				markclean = 0;
    373  1.20      ross 		}
    374  1.21      fvdl 		if (usedsoftdep) {
    375  1.21      fvdl 			for (i = 0; i < inomapsize; i++) {
    376  1.21      fvdl 				j = cg_inosused(newcg, 0)[i];
    377  1.21      fvdl 				if ((cg_inosused(cg, 0)[i] & j) == j)
    378  1.21      fvdl 					continue;
    379  1.21      fvdl 				for (k = 0; k < NBBY; k++) {
    380  1.21      fvdl 					if ((j & (1 << k)) == 0)
    381  1.21      fvdl 						continue;
    382  1.21      fvdl 					if (cg_inosused(cg, 0)[i] & (1 << k))
    383  1.21      fvdl 						continue;
    384  1.23    bouyer 					pwarn("ALLOCATED INODE %ld "
    385  1.23    bouyer 					    "MARKED FREE\n",
    386  1.21      fvdl 					    c * fs->fs_ipg + i * 8 + k);
    387  1.21      fvdl 				}
    388  1.21      fvdl 			}
    389  1.21      fvdl 			for (i = 0; i < blkmapsize; i++) {
    390  1.21      fvdl 				j = cg_blksfree(cg, 0)[i];
    391  1.21      fvdl 				if ((cg_blksfree(newcg, 0)[i] & j) == j)
    392  1.21      fvdl 					continue;
    393  1.21      fvdl 				for (k = 0; k < NBBY; k++) {
    394  1.21      fvdl 					if ((j & (1 << k)) == 0)
    395  1.21      fvdl 						continue;
    396  1.21      fvdl 					if (cg_inosused(cg, 0)[i] & (1 << k))
    397  1.21      fvdl 						continue;
    398  1.24   mycroft 					pwarn("ALLOCATED FRAG %ld "
    399  1.24   mycroft 					    "MARKED FREE\n",
    400  1.21      fvdl 					    c * fs->fs_fpg + i * 8 + k);
    401  1.21      fvdl 				}
    402  1.21      fvdl 			}
    403  1.21      fvdl 		}
    404  1.21      fvdl 		if (memcmp(cg_inosused(newcg, 0), cg_inosused(cg, 0), mapsize)
    405  1.21      fvdl 		    != 0 && dofix(&idesc[1], "BLK(S) MISSING IN BIT MAPS")) {
    406  1.21      fvdl 			memmove(cg_inosused(cg, 0), cg_inosused(newcg, 0),
    407  1.21      fvdl 			    (size_t)mapsize);
    408  1.21      fvdl                         cgdirty();
    409  1.21      fvdl                 }
    410   1.1       cgd 	}
    411  1.34      fvdl 	if (memcmp(&cstotal, &fs->fs_cstotal, sizeof cstotal) != 0) {
    412  1.35      fvdl 		dumptotal(&cstotal);
    413  1.35      fvdl 		dumptotal(&fs->fs_cstotal);
    414  1.26   thorpej 		if (dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
    415  1.26   thorpej 			memmove(&fs->fs_cstotal, &cstotal, sizeof *cs);
    416  1.26   thorpej 			fs->fs_ronly = 0;
    417  1.26   thorpej 			fs->fs_fmod = 0;
    418  1.26   thorpej 			sbdirty();
    419  1.19    bouyer 		} else
    420  1.19    bouyer 			markclean = 0;
    421  1.20      ross 	}
    422  1.19    bouyer }
    423  1.19    bouyer 
    424  1.19    bouyer void
    425  1.19    bouyer print_bmap(map, size)
    426  1.19    bouyer 	u_char *map;
    427  1.19    bouyer 	u_int32_t size;
    428  1.19    bouyer {
    429  1.19    bouyer 	int i, j;
    430  1.19    bouyer 
    431  1.19    bouyer 	i = 0;
    432  1.19    bouyer 	while (i < size) {
    433  1.19    bouyer 		printf("%u: ",i);
    434  1.19    bouyer 		for (j = 0; j < 16; j++, i++)
    435  1.19    bouyer 			printf("%2x ", (u_int)map[i] & 0xff);
    436  1.19    bouyer 		printf("\n");
    437   1.1       cgd 	}
    438  1.35      fvdl }
    439  1.35      fvdl 
    440  1.35      fvdl static
    441  1.35      fvdl void dumpcg(struct cg *cg)
    442  1.35      fvdl {
    443  1.35      fvdl 	printf("======================================\n");
    444  1.35      fvdl 	printf("firstfield	%d\n", cg->cg_firstfield);
    445  1.35      fvdl 	printf("magic		%d\n", cg->cg_magic);
    446  1.35      fvdl 	printf("old_time	%d\n", cg->cg_old_time);
    447  1.35      fvdl 	printf("cgx		%d\n", cg->cg_cgx);
    448  1.35      fvdl 	printf("old_ncyl	%d\n", cg->cg_old_ncyl);
    449  1.35      fvdl 	printf("old_niblk	%d\n", cg->cg_old_niblk);
    450  1.35      fvdl 	printf("ndblk		%d\n", cg->cg_ndblk);
    451  1.35      fvdl 	printf("csum.ndir	%d\n", cg->cg_cs.cs_ndir);
    452  1.35      fvdl 	printf("csum.nbfree	%d\n", cg->cg_cs.cs_nbfree);
    453  1.35      fvdl 	printf("csum.nifree	%d\n", cg->cg_cs.cs_nifree);
    454  1.35      fvdl 	printf("csum.nffree	%d\n", cg->cg_cs.cs_nffree);
    455  1.35      fvdl 	printf("rotor		%d\n", cg->cg_rotor);
    456  1.35      fvdl 	printf("frotor		%d\n", cg->cg_frotor);
    457  1.35      fvdl 	printf("irotor		%d\n", cg->cg_irotor);
    458  1.35      fvdl 	printf("%d, %d, %d, %d, %d, %d, %d, %d\n",
    459  1.35      fvdl 	    cg->cg_frsum[0], cg->cg_frsum[1], cg->cg_frsum[2], cg->cg_frsum[3],
    460  1.35      fvdl 	    cg->cg_frsum[4], cg->cg_frsum[5], cg->cg_frsum[6], cg->cg_frsum[7]);
    461  1.35      fvdl 	printf("old_btotoff	%d\n", cg->cg_old_btotoff);
    462  1.35      fvdl 	printf("old_boff	%d\n", cg->cg_old_boff);
    463  1.35      fvdl 	printf("iusedoff	%d\n", cg->cg_iusedoff);
    464  1.35      fvdl 	printf("freeoff		%d\n", cg->cg_freeoff);
    465  1.35      fvdl 	printf("nextfreeoff	%d\n", cg->cg_nextfreeoff);
    466  1.35      fvdl 	printf("clustersumoff	%d\n", cg->cg_clustersumoff);
    467  1.35      fvdl 	printf("clusteroff	%d\n", cg->cg_clusteroff);
    468  1.35      fvdl 	printf("nclusterblks	%d\n", cg->cg_nclusterblks);
    469  1.35      fvdl 	printf("niblk		%d\n", cg->cg_niblk);
    470  1.35      fvdl 	printf("initediblk	%d\n", cg->cg_initediblk);
    471  1.35      fvdl 
    472  1.35      fvdl 	printf("time		%lld\n", cg->cg_time);
    473  1.35      fvdl }
    474  1.35      fvdl 
    475  1.35      fvdl static
    476  1.35      fvdl void dumptotal(struct csum_total *cs)
    477  1.35      fvdl {
    478  1.35      fvdl 	printf("===========================\n");
    479  1.35      fvdl 	printf("ndir		%lld\n", cs->cs_ndir);
    480  1.35      fvdl 	printf("nbfree		%lld\n", cs->cs_ndir);
    481  1.35      fvdl 	printf("nifree		%lld\n", cs->cs_ndir);
    482  1.35      fvdl 	printf("nffree		%lld\n", cs->cs_ndir);
    483  1.35      fvdl 	printf("numclusters	%lld\n", cs->cs_ndir);
    484   1.1       cgd }
    485