xref: /freebsd/sbin/fsck_ffs/pass4.c (revision 5cc52631b3b88dfc36d8049dc8bece8573c5f9af)
18a16b7a1SPedro F. Giffuni /*-
28a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro F. Giffuni  *
48fae3551SRodney W. Grimes  * Copyright (c) 1980, 1986, 1993
58fae3551SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
68fae3551SRodney W. Grimes  *
78fae3551SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
88fae3551SRodney W. Grimes  * modification, are permitted provided that the following conditions
98fae3551SRodney W. Grimes  * are met:
108fae3551SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
118fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
128fae3551SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
138fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
148fae3551SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
168fae3551SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
178fae3551SRodney W. Grimes  *    without specific prior written permission.
188fae3551SRodney W. Grimes  *
198fae3551SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
208fae3551SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218fae3551SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
228fae3551SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
238fae3551SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
248fae3551SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
258fae3551SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
268fae3551SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
278fae3551SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288fae3551SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
298fae3551SRodney W. Grimes  * SUCH DAMAGE.
308fae3551SRodney W. Grimes  */
318fae3551SRodney W. Grimes 
326b100474SJulian Elischer #if 0
33c69284caSDavid E. O'Brien #ifndef lint
34780a5c1eSPeter Wemm static const char sccsid[] = "@(#)pass4.c	8.4 (Berkeley) 4/28/95";
358fae3551SRodney W. Grimes #endif /* not lint */
36c69284caSDavid E. O'Brien #endif
37c69284caSDavid E. O'Brien #include <sys/cdefs.h>
38c69284caSDavid E. O'Brien __FBSDID("$FreeBSD$");
398fae3551SRodney W. Grimes 
408fae3551SRodney W. Grimes #include <sys/param.h>
41*5cc52631SKirk McKusick #include <sys/stat.h>
42780a5c1eSPeter Wemm 
438fae3551SRodney W. Grimes #include <ufs/ufs/dinode.h>
44d33e92f9SJulian Elischer #include <ufs/ffs/fs.h>
458fae3551SRodney W. Grimes 
46780a5c1eSPeter Wemm #include <err.h>
47623d7cb6SMatthew D Fleming #include <stdint.h>
48780a5c1eSPeter Wemm #include <string.h>
49780a5c1eSPeter Wemm 
50780a5c1eSPeter Wemm #include "fsck.h"
518fae3551SRodney W. Grimes 
5231f4ab50SBruce Evans void
53b70cd7eeSWarner Losh pass4(void)
548fae3551SRodney W. Grimes {
553d438ad6SDavid E. O'Brien 	ino_t inumber;
56*5cc52631SKirk McKusick 	struct inode ip;
578fae3551SRodney W. Grimes 	struct inodesc idesc;
58d33e92f9SJulian Elischer 	int i, n, cg;
598fae3551SRodney W. Grimes 
60780a5c1eSPeter Wemm 	memset(&idesc, 0, sizeof(struct inodesc));
617180f1abSKirk McKusick 	idesc.id_func = freeblock;
62d33e92f9SJulian Elischer 	for (cg = 0; cg < sblock.fs_ncg; cg++) {
636db798caSIan Dowse 		if (got_siginfo) {
646db798caSIan Dowse 			printf("%s: phase 4: cyl group %d of %d (%d%%)\n",
656db798caSIan Dowse 			    cdevname, cg, sblock.fs_ncg,
666db798caSIan Dowse 			    cg * 100 / sblock.fs_ncg);
676db798caSIan Dowse 			got_siginfo = 0;
686db798caSIan Dowse 		}
691660ae87SScott Long 		if (got_sigalarm) {
701660ae87SScott Long 			setproctitle("%s p4 %d%%", cdevname,
711660ae87SScott Long 			    cg * 100 / sblock.fs_ncg);
721660ae87SScott Long 			got_sigalarm = 0;
731660ae87SScott Long 		}
74d33e92f9SJulian Elischer 		inumber = cg * sblock.fs_ipg;
75d33e92f9SJulian Elischer 		for (i = 0; i < inostathead[cg].il_numalloced; i++, inumber++) {
761dc349abSEd Maste 			if (inumber < UFS_ROOTINO)
77d33e92f9SJulian Elischer 				continue;
788fae3551SRodney W. Grimes 			idesc.id_number = inumber;
79*5cc52631SKirk McKusick 			idesc.id_type = inoinfo(inumber)->ino_idtype;
80d33e92f9SJulian Elischer 			switch (inoinfo(inumber)->ino_state) {
818fae3551SRodney W. Grimes 
82af6726e6SDon Lewis 			case FZLINK:
83af6726e6SDon Lewis 			case DZLINK:
84af6726e6SDon Lewis 				if (inoinfo(inumber)->ino_linkcnt == 0) {
85af6726e6SDon Lewis 					clri(&idesc, "UNREF", 1);
86af6726e6SDon Lewis 					break;
87af6726e6SDon Lewis 				}
88af6726e6SDon Lewis 				/* fall through */
89af6726e6SDon Lewis 
908fae3551SRodney W. Grimes 			case FSTATE:
918fae3551SRodney W. Grimes 			case DFOUND:
92d33e92f9SJulian Elischer 				n = inoinfo(inumber)->ino_linkcnt;
93d33e92f9SJulian Elischer 				if (n) {
948fae3551SRodney W. Grimes 					adjust(&idesc, (short)n);
95d33e92f9SJulian Elischer 					break;
96d33e92f9SJulian Elischer 				}
978fae3551SRodney W. Grimes 				break;
988fae3551SRodney W. Grimes 
998fae3551SRodney W. Grimes 			case DSTATE:
1008fae3551SRodney W. Grimes 				clri(&idesc, "UNREF", 1);
1018fae3551SRodney W. Grimes 				break;
1028fae3551SRodney W. Grimes 
1038fae3551SRodney W. Grimes 			case DCLEAR:
10497fea87bSKirk McKusick 				/* if on snapshot, already cleared */
10597fea87bSKirk McKusick 				if (cursnapshot != 0)
10697fea87bSKirk McKusick 					break;
107*5cc52631SKirk McKusick 				ginode(inumber, &ip);
108*5cc52631SKirk McKusick 				if (DIP(ip.i_dp, di_size) == 0) {
1098fae3551SRodney W. Grimes 					clri(&idesc, "ZERO LENGTH", 1);
110*5cc52631SKirk McKusick 					irelse(&ip);
1118fae3551SRodney W. Grimes 					break;
1128fae3551SRodney W. Grimes 				}
113*5cc52631SKirk McKusick 				irelse(&ip);
1148fae3551SRodney W. Grimes 				/* fall through */
1158fae3551SRodney W. Grimes 			case FCLEAR:
1168fae3551SRodney W. Grimes 				clri(&idesc, "BAD/DUP", 1);
1178fae3551SRodney W. Grimes 				break;
1188fae3551SRodney W. Grimes 
1198fae3551SRodney W. Grimes 			case USTATE:
1208fae3551SRodney W. Grimes 				break;
1218fae3551SRodney W. Grimes 
1228fae3551SRodney W. Grimes 			default:
123623d7cb6SMatthew D Fleming 				errx(EEXIT, "BAD STATE %d FOR INODE I=%ju",
124623d7cb6SMatthew D Fleming 				    inoinfo(inumber)->ino_state,
125623d7cb6SMatthew D Fleming 				    (uintmax_t)inumber);
126d33e92f9SJulian Elischer 			}
1278fae3551SRodney W. Grimes 		}
1288fae3551SRodney W. Grimes 	}
1298fae3551SRodney W. Grimes }
130