* Copyright (c) 1980, 1986 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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
static char sccsid
[] = "@(#)pass5.c 5.13 (Berkeley) 7/20/90";
int c
, blk
, frags
, basesize
, sumsize
, mapsize
, savednrpos
;
register struct fs
*fs
= &sblock
;
register struct cg
*cg
= &cgrp
;
register struct cg
*newcg
= (struct cg
*)buf
;
struct ocg
*ocg
= (struct ocg
*)buf
;
bzero((char *)newcg
, (size_t)fs
->fs_cgsize
);
newcg
->cg_niblk
= fs
->fs_ipg
;
switch ((int)fs
->fs_postblformat
) {
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(fs
->fs_fpg
, NBBY
)] -
(u_char
*)&ocg
->cg_iused
[0];
ocg
->cg_magic
= CG_MAGIC
;
savednrpos
= fs
->fs_nrpos
;
case FS_DYNAMICPOSTBLFMT
:
&newcg
->cg_space
[0] - (u_char
*)(&newcg
->cg_link
);
newcg
->cg_btotoff
+ fs
->fs_cpg
* sizeof(long);
newcg
->cg_iusedoff
= newcg
->cg_boff
+
fs
->fs_cpg
* fs
->fs_nrpos
* sizeof(short);
newcg
->cg_iusedoff
+ howmany(fs
->fs_ipg
, NBBY
);
newcg
->cg_nextfreeoff
= newcg
->cg_freeoff
+
howmany(fs
->fs_cpg
* fs
->fs_spc
/ NSPF(fs
),
newcg
->cg_magic
= CG_MAGIC
;
basesize
= &newcg
->cg_space
[0] - (u_char
*)(&newcg
->cg_link
);
sumsize
= newcg
->cg_iusedoff
- newcg
->cg_btotoff
;
mapsize
= newcg
->cg_nextfreeoff
- newcg
->cg_iusedoff
;
errexit("UNKNOWN ROTATIONAL TABLE FORMAT %d\n",
bzero((char *)&idesc
[0], sizeof idesc
);
bzero((char *)&cstotal
, sizeof(struct csum
));
j
= blknum(fs
, fs
->fs_size
+ fs
->fs_frag
- 1);
for (i
= fs
->fs_size
; i
< j
; i
++)
for (c
= 0; c
< fs
->fs_ncg
; c
++) {
getblk(&cgblk
, cgtod(fs
, c
), fs
->fs_cgsize
);
pfatal("CG %d: BAD MAGIC NUMBER\n", c
);
dmax
= dbase
+ fs
->fs_fpg
;
newcg
->cg_time
= cg
->cg_time
;
newcg
->cg_ncyl
= fs
->fs_ncyl
% fs
->fs_cpg
;
newcg
->cg_ncyl
= fs
->fs_cpg
;
newcg
->cg_ndblk
= dmax
- dbase
;
newcg
->cg_cs
.cs_ndir
= 0;
newcg
->cg_cs
.cs_nffree
= 0;
newcg
->cg_cs
.cs_nbfree
= 0;
newcg
->cg_cs
.cs_nifree
= fs
->fs_ipg
;
if (cg
->cg_rotor
< newcg
->cg_ndblk
)
newcg
->cg_rotor
= cg
->cg_rotor
;
if (cg
->cg_frotor
< newcg
->cg_ndblk
)
newcg
->cg_frotor
= cg
->cg_frotor
;
if (cg
->cg_irotor
< newcg
->cg_niblk
)
newcg
->cg_irotor
= cg
->cg_irotor
;
bzero((char *)&newcg
->cg_frsum
[0], sizeof newcg
->cg_frsum
);
bzero((char *)&cg_blktot(newcg
)[0],
(size_t)(sumsize
+ mapsize
));
if (fs
->fs_postblformat
== FS_42POSTBLFMT
)
ocg
->cg_magic
= CG_MAGIC
;
for (i
= 0; i
< fs
->fs_ipg
; j
++, i
++) {
newcg
->cg_cs
.cs_nifree
--;
setbit(cg_inosused(newcg
), i
);
errexit("BAD STATE %d FOR INODE I=%d",
for (i
= 0; i
< ROOTINO
; i
++) {
setbit(cg_inosused(newcg
), i
);
newcg
->cg_cs
.cs_nifree
--;
d
+= fs
->fs_frag
, i
+= fs
->fs_frag
) {
for (j
= 0; j
< fs
->fs_frag
; j
++) {
setbit(cg_blksfree(newcg
), i
+ j
);
if (frags
== fs
->fs_frag
) {
newcg
->cg_cs
.cs_nbfree
++;
cg_blks(fs
, newcg
, j
)[cbtorpos(fs
, i
)]++;
newcg
->cg_cs
.cs_nffree
+= frags
;
blk
= blkmap(fs
, cg_blksfree(newcg
), i
);
fragacct(fs
, blk
, newcg
->cg_frsum
, 1);
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
;
if (bcmp((char *)&newcg
->cg_cs
, (char *)cs
, sizeof *cs
) != 0 &&
dofix(&idesc
[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
bcopy((char *)&newcg
->cg_cs
, (char *)cs
, sizeof *cs
);
bcopy((char *)newcg
, (char *)cg
, (size_t)fs
->fs_cgsize
);
if (bcmp(cg_inosused(newcg
),
cg_inosused(cg
), mapsize
) != 0 &&
dofix(&idesc
[1], "BLK(S) MISSING IN BIT MAPS")) {
bcopy(cg_inosused(newcg
), cg_inosused(cg
),
if ((bcmp((char *)newcg
, (char *)cg
, basesize
) != 0 ||
bcmp((char *)&cg_blktot(newcg
)[0],
(char *)&cg_blktot(cg
)[0], sumsize
) != 0) &&
dofix(&idesc
[2], "SUMMARY INFORMATION BAD")) {
bcopy((char *)newcg
, (char *)cg
, (size_t)basesize
);
bcopy((char *)&cg_blktot(newcg
)[0],
(char *)&cg_blktot(cg
)[0], (size_t)sumsize
);
if (fs
->fs_postblformat
== FS_42POSTBLFMT
)
fs
->fs_nrpos
= savednrpos
;
if (bcmp((char *)&cstotal
, (char *)&fs
->fs_cstotal
, sizeof *cs
) != 0
&& dofix(&idesc
[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
bcopy((char *)&cstotal
, (char *)&fs
->fs_cstotal
, sizeof *cs
);