summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ufs-fsck/pass5.c126
1 files changed, 68 insertions, 58 deletions
diff --git a/ufs-fsck/pass5.c b/ufs-fsck/pass5.c
index 47086cff..1311db28 100644
--- a/ufs-fsck/pass5.c
+++ b/ufs-fsck/pass5.c
@@ -20,17 +20,19 @@
#include "fsck.h"
+void
pass5 ()
{
- char cgbuf[MAXBSIZE];
- struct cg *newcg = cgbuf;
+ char cgbuf[sblock->fs_cgsize];
+ struct cg *newcg = (struct cg *)cgbuf;
struct ocg *ocg = (struct ocg *)cgbuf;
- int savednrpos;
+ int savednrpos = 0;
struct csum cstotal;
int i, j;
int c;
- struct cg *cg = alloca (sblock.fs_cgsize);
- char csumbuf[fragroundup (sizeof (struct csum) * sblock.fs_ncg)];
+ daddr_t d;
+ struct cg *cg = alloca (sblock->fs_cgsize);
+ char csumbuf[fragroundup (sblock, sizeof (struct csum) * sblock->fs_ncg)];
struct csum *sbcsums = (struct csum *)csumbuf;
int basesize; /* size of cg not counting flexibly sized */
@@ -44,41 +46,41 @@ pass5 ()
writesb = 0;
writecsum = 0;
- readblock (fsbtodb (&sblock, sblock.fs_csaddr), csumbuf,
- fragroundup (sizeof (struct csum) * sblock.fs_ncg));
+ readblock (fsbtodb (sblock, sblock->fs_csaddr), csumbuf,
+ fragroundup (sblock, sizeof (struct csum) * sblock->fs_ncg));
/* Construct a CG structure; initialize everything that's the same
in each cylinder group. */
- bzero (newcg, sblock.fs_cgsize);
- newcg->cg_niblk = sblock.fs_ipg;
- switch (sblock.fs_postblformat)
+ bzero (newcg, sblock->fs_cgsize);
+ newcg->cg_niblk = sblock->fs_ipg;
+ switch (sblock->fs_postblformat)
{
case FS_42POSTBLFMT:
/* Initialize size information */
basesize = (char *)(&ocg->cg_btot[0]) - (char *)(&ocg->cg_link);
sumsize = &ocg->cg_iused[0] - (char *)(&ocg->cg_btot[0]);
- mapsize = (&ocg->cg_free[howmany(sblock.fs_fpg, NBBY)]
+ mapsize = (&ocg->cg_free[howmany(sblock->fs_fpg, NBBY)]
- (u_char *)&ocg->cg_iused[0]);
- savednrpos = sblock.fs_nrpos;
- sblock.fs_nrpos = 8;
+ savednrpos = sblock->fs_nrpos;
+ sblock->fs_nrpos = 8;
break;
- case FS_DYNAMICPOSTBLFMT;
+ case FS_DYNAMICPOSTBLFMT:
/* Set fields unique to new cg structure */
newcg->cg_btotoff = &newcg->cg_space[0] - (u_char *)(&newcg->cg_link);
- newcg->cg_boff = newcg->cg_btotoff + sblock.fs_cpg * sizeof (long);
- newcg->cg_iusedoff = newcg->cg_boff + (sblock.fs_cpg
- * block.fs_nrpos
+ newcg->cg_boff = newcg->cg_btotoff + sblock->fs_cpg * sizeof (long);
+ newcg->cg_iusedoff = newcg->cg_boff + (sblock->fs_cpg
+ * sblock->fs_nrpos
* sizeof (short));
- newcg->cg_freeoff = newcg->cg_iusedoff + howmany (sblock.fs_ipg, NBBY);
+ newcg->cg_freeoff = newcg->cg_iusedoff + howmany (sblock->fs_ipg, NBBY);
- /* Only support sblock.fs_contigsumsize == 0 here */
+ /* Only support sblock->fs_contigsumsize == 0 here */
/* If we supported clustered filesystems, then we would set
clustersumoff and clusteroff and nextfree off would be past
them. */
newcg->cg_nextfreeoff =
(newcg->cg_freeoff
- + howmany (sblock.fs_cpg * sblock.fs_spc / NSPF (&sblock), NBBY));
+ + howmany (sblock->fs_cpg * sblock->fs_spc / NSPF (sblock), NBBY));
newcg->cg_magic = CG_MAGIC;
/* Set map sizes */
@@ -86,48 +88,51 @@ pass5 ()
sumsize = newcg->cg_iusedoff - newcg->cg_btotoff;
mapsize = newcg->cg_nextfreeoff - newcg->cg_iusedoff;
break;
+
+ default:
+ errexit ("UNKNOWN POSTBL FORMAT");
}
bzero (&cstotal, sizeof (struct csum));
/* Mark fragments past the end of the filesystem as used. */
- j = blknum (&sblock, sblock->fs_size + fs->fs_frag - 1);
- for (i = sblock.fs_size; i < j; i++)
+ j = blknum (sblock, sblock->fs_size + sblock->fs_frag - 1);
+ for (i = sblock->fs_size; i < j; i++)
setbmap (i);
/* Now walk through the cylinder groups, checking each one. */
- for (c = 0; c < sblock.fs_ncg; c++)
+ for (c = 0; c < sblock->fs_ncg; c++)
{
int dbase, dmax;
/* Read the cylinder group structure */
- readblock (fsbtodb (cgtod (&sblock, c)), cg, sblock.fs_cgsize);
+ readblock (fsbtodb (sblock, cgtod (sblock, c)), cg, sblock->fs_cgsize);
writecg = 0;
if (!cg_chkmagic (cg))
pfatal ("CG %d: BAD MAGIC NUMBER\n", c);
/* Compute first and last data block addresses in this group */
- dbase = cgbase (&sblock, c);
- dmax = dbase + sblock.fs_fpg;
- if (dmax > sblock.fs_size)
- dmax = sblock.fs_size;
+ dbase = cgbase (sblock, c);
+ dmax = dbase + sblock->fs_fpg;
+ if (dmax > sblock->fs_size)
+ dmax = sblock->fs_size;
/* Initialize newcg fully; values from cg for those
we can't check. */
newcg->cg_time = cg->cg_time;
newcg->cg_cgx = c;
- if (c == sblock.fs_ncg - 1)
- newcg->cg_ncyl = sblock.fs_ncyl % sblock.fs_cpg;
+ if (c == sblock->fs_ncg - 1)
+ newcg->cg_ncyl = sblock->fs_ncyl % sblock->fs_cpg;
else
- newcg->cg_ncyl = sblock.fs_cpg;
+ newcg->cg_ncyl = sblock->fs_cpg;
newcg->cg_ndblk = dmax - dbase;
/* Don't set nclusterblks; we don't support that */
newcg->cg_cs.cs_ndir = 0;
newcg->cg_cs.cs_nffree = 0;
newcg->cg_cs.cs_nbfree = 0;
- newcg->cg_cs.cs_nifree = sblock.fs_ipg;
+ newcg->cg_cs.cs_nifree = sblock->fs_ipg;
/* Check these for basic viability; if they are wrong
then clear them. */
@@ -174,22 +179,25 @@ pass5 ()
/* Zero the block maps and summary areas */
bzero (&newcg->cg_frsum[0], sizeof newcg->cg_frsum);
bzero (&cg_blktot (newcg)[0], sumsize + mapsize);
- if (sblock.fs_postblformat == FS_42POSTBLFMT)
+ if (sblock->fs_postblformat == FS_42POSTBLFMT)
ocg->cg_magic = CG_MAGIC;
/* Walk through each inode, accounting for it in
the inode map and in newcg->cg_cs. */
- j = fs->fs_ipg * c;
- for (i = 0; i < fs->fs_ipg; j++, i++)
+ j = sblock->fs_ipg * c;
+ for (i = 0; i < sblock->fs_ipg; j++, i++)
switch (inodestate[i])
{
- case DIR:
- case DIR | DIR_REF:
+ case DIRECTORY:
+ case DIRECTORY | DIR_REF:
+ case BADDIR:
newcg->cg_cs.cs_ndir++;
/* Fall through... */
case REG:
newcg->cg_cs.cs_nifree--;
setbit (cg_inosused (newcg), i);
+ default:
+ errexit ("UNKNOWN STATE I=%d", i);
}
/* Account for inodes 0 and 1 */
if (c == 0)
@@ -203,13 +211,13 @@ pass5 ()
the block map and in newcg->cg_cs. */
for (i = 0, d = dbase;
d < dmax;
- d += sblock.fs_frag, i += sblock.fs_frag)
+ d += sblock->fs_frag, i += sblock->fs_frag)
{
int frags = 0;
/* Set each free frag of this block in the block map;
count how many frags were free. */
- for (j = 0; j < fs->fs_frag; j++)
+ for (j = 0; j < sblock->fs_frag; j++)
{
if (testbmap (d + j))
continue;
@@ -219,40 +227,41 @@ pass5 ()
/* If all the frags were free, then count this as
a free block too. */
- if (frags == fs->fs_frag)
+ if (frags == sblock->fs_frag)
{
newcg->cg_cs.cs_nbfree++;
- j = cbtocylno (&sblock, i);
+ j = cbtocylno (sblock, i);
cg_blktot(newcg)[j]++;
- cg_blks(&sblock, newcg, j)[cktorpos(&sblock, i)]++;
+ cg_blks(sblock, newcg, j)[cbtorpos(sblock, i)]++;
/* If we support clustering, then we'd account for this
in the cluster map too. */
}
else if (frags)
{
/* Partial; account for the frags. */
+ int blk;
newcg->cg_cs.cs_nffree += frags;
- blk = blkmap (&sblock, cg_blksfree (newcg), i);
- ffs_fragacct (&sblock, blk, newcg->cg_frsum, 1);
+ blk = blkmap (sblock, cg_blksfree (newcg), i);
+ ffs_fragacct (sblock, blk, newcg->cg_frsum, 1);
}
}
/* Add this cylinder group's totals into the superblock's
totals. */
- cstotal.cs.nffree += newcg->cg_cs.cs_nffree;
+ cstotal.cs_nffree += newcg->cg_cs.cs_nffree;
cstotal.cs_nbfree += newcg->cg_cs.cs_nbfree;
cstotal.cs_nifree += newcg->cg_cs.cs_nifree;
cstotal.cs_ndir += newcg->cg_cs.cs_ndir;
/* Check counts in superblock */
- if (bcmp (&newcg->cg_cs, cs, sizeof (struct csum)))
+ if (bcmp (&newcg->cg_cs, &sbcsums[c], sizeof (struct csum)))
{
pwarn ("FREE BLK COUNTS FOR CG %d WRONG IN SUPERBLOCK", c);
if (preen || reply ("FIX"))
{
if (preen)
printf (" (FIXED)");
- bcopy (newcg->cg_cs, cs, sizeof (struct csum));
+ bcopy (&newcg->cg_cs, &sbcsums[c], sizeof (struct csum));
writecsum = 1;
}
}
@@ -277,7 +286,7 @@ pass5 ()
{
if (preen)
printf (" (FIXED)");
- bcopy (cg_blktot(newcg)[0], &cg_blktot(cg)[0], sumsize);
+ bcopy (&cg_blktot(newcg)[0], &cg_blktot(cg)[0], sumsize);
writecg = 1;
}
}
@@ -295,23 +304,24 @@ pass5 ()
}
if (writecg)
- writeblock (fsbtodb (cgtod (&sblock, c)), cg, sblock.fs_cgsize);
+ writeblock (fsbtodb (sblock, cgtod (sblock, c)),
+ cg, sblock->fs_cgsize);
}
/* Restore nrpos */
- if (sblock.fs_postblformat == FS_42POSTBLFMT)
- sblock.fs_nrpos = savednrpos;
+ if (sblock->fs_postblformat == FS_42POSTBLFMT)
+ sblock->fs_nrpos = savednrpos;
- if (bcmp (cstotal, sblock.fs_cstotal, sizeof (struct csum)))
+ if (bcmp (&cstotal, &sblock->fs_cstotal, sizeof (struct csum)))
{
- pwarn ("TOTAL FREE BLK COUNTS WRONG IN SUPERBLOCK", c);
+ pwarn ("TOTAL FREE BLK COUNTS WRONG IN SUPERBLOCK");
if (preen || reply ("FIX"))
{
if (preen)
printf (" (FIXED)");
- bcopy (&cstotal, sblock.fs_cstotal, sizeof (struct csum));
- sblock.fs_ronly = 0;
- sblock.fs_fmod = 0;
+ bcopy (&cstotal, &sblock->fs_cstotal, sizeof (struct csum));
+ sblock->fs_ronly = 0;
+ sblock->fs_fmod = 0;
writesb = 1;
}
}
@@ -319,6 +329,6 @@ pass5 ()
if (writesb)
writeblock (SBLOCK, &sblock, SBSIZE);
if (writecsum)
- writeblock (fsbtodb (&sblock, sblock.fs_csaddr), csumbuf,
- fragroundup (sizeof (struct csum) * sblock.fs_ncg));
+ writeblock (fsbtodb (sblock, sblock->fs_csaddr), csumbuf,
+ fragroundup (sblock, sizeof (struct csum) * sblock->fs_ncg));
}