* 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
[] = "@(#)pass1.c 5.16 (Berkeley) 3/19/91";
struct dinode
*getnextinode();
register struct dinode
*dp
;
* Set file system reserved blocks in used block map.
for (c
= 0; c
< sblock
.fs_ncg
; c
++) {
cgd
= cgdmin(&sblock
, c
);
cgd
+= howmany(sblock
.fs_cssize
, sblock
.fs_fsize
);
i
= cgsblock(&sblock
, c
);
* Find all allocated blocks.
bzero((char *)&idesc
, sizeof(struct inodesc
));
idesc
.id_func
= pass1check
;
for (c
= 0; c
< sblock
.fs_ncg
; c
++) {
for (i
= 0; i
< sblock
.fs_ipg
; i
++, inumber
++) {
dp
= getnextinode(inumber
);
if ((dp
->di_mode
& IFMT
) == 0) {
if (bcmp((char *)dp
->di_db
, (char *)zino
.di_db
,
NDADDR
* sizeof(daddr_t
)) ||
bcmp((char *)dp
->di_ib
, (char *)zino
.di_ib
,
NIADDR
* sizeof(daddr_t
)) ||
dp
->di_mode
|| dp
->di_size
) {
pfatal("PARTIALLY ALLOCATED INODE I=%lu",
if (reply("CLEAR") == 1) {
statemap
[inumber
] = USTATE
;
if (/* dp->di_size < 0 || */
dp
->di_size
+ sblock
.fs_bsize
- 1 < dp
->di_size
) {
printf("bad size %lu:", dp
->di_size
);
if (!preen
&& (dp
->di_mode
& IFMT
) == IFMT
&&
reply("HOLD BAD BLOCK") == 1) {
dp
->di_size
= sblock
.fs_fsize
;
dp
->di_mode
= IFREG
|0600;
ndb
= howmany(dp
->di_size
, sblock
.fs_bsize
);
printf("bad size %lu ndb %d:",
if ((dp
->di_mode
& IFMT
) == IFBLK
||
(dp
->di_mode
& IFMT
) == IFCHR
)
for (j
= ndb
; j
< NDADDR
; j
++)
printf("bad direct addr: %ld\n",
for (j
= 0, ndb
-= NDADDR
; ndb
> 0; j
++)
printf("bad indirect addr: %ld\n",
lncntp
[inumber
] = dp
->di_nlink
;
zlnp
= (struct zlncnt
*)malloc(sizeof *zlnp
);
pfatal("LINK COUNT TABLE OVERFLOW");
if (reply("CONTINUE") == 0)
if ((dp
->di_mode
& IFMT
) == IFDIR
) {
statemap
[inumber
] = DCLEAR
;
statemap
[inumber
] = DSTATE
;
statemap
[inumber
] = FSTATE
;
idesc
.id_number
= inumber
;
(void)ckinode(dp
, &idesc
);
idesc
.id_entryno
*= btodb(sblock
.fs_fsize
);
if (dp
->di_blocks
!= idesc
.id_entryno
) {
pwarn("INCORRECT BLOCK COUNT I=%lu (%ld should be %ld)",
inumber
, dp
->di_blocks
, idesc
.id_entryno
);
printf(" (CORRECTED)\n");
else if (reply("CORRECT") == 0)
dp
->di_blocks
= idesc
.id_entryno
;
pfatal("UNKNOWN FILE TYPE I=%lu", inumber
);
statemap
[inumber
] = FCLEAR
;
if (reply("CLEAR") == 1) {
statemap
[inumber
] = USTATE
;
register struct inodesc
*idesc
;
daddr_t blkno
= idesc
->id_blkno
;
register struct dups
*dlp
;
if ((anyout
= chkrange(blkno
, idesc
->id_numfrags
)) != 0) {
blkerror(idesc
->id_number
, "BAD", blkno
);
if (badblk
++ >= MAXBAD
) {
pwarn("EXCESSIVE BAD BLKS I=%lu",
else if (reply("CONTINUE") == 0)
for (nfrags
= idesc
->id_numfrags
; nfrags
> 0; blkno
++, nfrags
--) {
if (anyout
&& chkrange(blkno
, 1)) {
} else if (!testbmap(blkno
)) {
blkerror(idesc
->id_number
, "DUP", blkno
);
if (dupblk
++ >= MAXDUP
) {
pwarn("EXCESSIVE DUP BLKS I=%lu",
else if (reply("CONTINUE") == 0)
new = (struct dups
*)malloc(sizeof(struct dups
));
pfatal("DUP TABLE OVERFLOW.");
if (reply("CONTINUE") == 0)
new->next
= muldup
->next
;
for (dlp
= duplist
; dlp
!= muldup
; dlp
= dlp
->next
)
if (dlp
== muldup
&& dlp
->dup
!= blkno
)
* count the number of blocks found in id_entryno