xref: /freebsd/sbin/fsck_ffs/pass4.c (revision 7180f1ab40e22f3f6b8d50d05c6ae186de54e90a)
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>
41780a5c1eSPeter Wemm 
428fae3551SRodney W. Grimes #include <ufs/ufs/dinode.h>
43d33e92f9SJulian Elischer #include <ufs/ffs/fs.h>
448fae3551SRodney W. Grimes 
45780a5c1eSPeter Wemm #include <err.h>
46623d7cb6SMatthew D Fleming #include <stdint.h>
47780a5c1eSPeter Wemm #include <string.h>
48780a5c1eSPeter Wemm 
49780a5c1eSPeter Wemm #include "fsck.h"
508fae3551SRodney W. Grimes 
5131f4ab50SBruce Evans void
52b70cd7eeSWarner Losh pass4(void)
538fae3551SRodney W. Grimes {
543d438ad6SDavid E. O'Brien 	ino_t inumber;
551c85e6a3SKirk McKusick 	union dinode *dp;
568fae3551SRodney W. Grimes 	struct inodesc idesc;
57d33e92f9SJulian Elischer 	int i, n, cg;
588fae3551SRodney W. Grimes 
59780a5c1eSPeter Wemm 	memset(&idesc, 0, sizeof(struct inodesc));
608fae3551SRodney W. Grimes 	idesc.id_type = ADDR;
61*7180f1abSKirk 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;
79d33e92f9SJulian Elischer 			switch (inoinfo(inumber)->ino_state) {
808fae3551SRodney W. Grimes 
81af6726e6SDon Lewis 			case FZLINK:
82af6726e6SDon Lewis 			case DZLINK:
83af6726e6SDon Lewis 				if (inoinfo(inumber)->ino_linkcnt == 0) {
84af6726e6SDon Lewis 					clri(&idesc, "UNREF", 1);
85af6726e6SDon Lewis 					break;
86af6726e6SDon Lewis 				}
87af6726e6SDon Lewis 				/* fall through */
88af6726e6SDon Lewis 
898fae3551SRodney W. Grimes 			case FSTATE:
908fae3551SRodney W. Grimes 			case DFOUND:
91d33e92f9SJulian Elischer 				n = inoinfo(inumber)->ino_linkcnt;
92d33e92f9SJulian Elischer 				if (n) {
938fae3551SRodney W. Grimes 					adjust(&idesc, (short)n);
94d33e92f9SJulian Elischer 					break;
95d33e92f9SJulian Elischer 				}
968fae3551SRodney W. Grimes 				break;
978fae3551SRodney W. Grimes 
988fae3551SRodney W. Grimes 			case DSTATE:
998fae3551SRodney W. Grimes 				clri(&idesc, "UNREF", 1);
1008fae3551SRodney W. Grimes 				break;
1018fae3551SRodney W. Grimes 
1028fae3551SRodney W. Grimes 			case DCLEAR:
10397fea87bSKirk McKusick 				/* if on snapshot, already cleared */
10497fea87bSKirk McKusick 				if (cursnapshot != 0)
10597fea87bSKirk McKusick 					break;
1068fae3551SRodney W. Grimes 				dp = ginode(inumber);
1071c85e6a3SKirk McKusick 				if (DIP(dp, di_size) == 0) {
1088fae3551SRodney W. Grimes 					clri(&idesc, "ZERO LENGTH", 1);
1098fae3551SRodney W. Grimes 					break;
1108fae3551SRodney W. Grimes 				}
1118fae3551SRodney W. Grimes 				/* fall through */
1128fae3551SRodney W. Grimes 			case FCLEAR:
1138fae3551SRodney W. Grimes 				clri(&idesc, "BAD/DUP", 1);
1148fae3551SRodney W. Grimes 				break;
1158fae3551SRodney W. Grimes 
1168fae3551SRodney W. Grimes 			case USTATE:
1178fae3551SRodney W. Grimes 				break;
1188fae3551SRodney W. Grimes 
1198fae3551SRodney W. Grimes 			default:
120623d7cb6SMatthew D Fleming 				errx(EEXIT, "BAD STATE %d FOR INODE I=%ju",
121623d7cb6SMatthew D Fleming 				    inoinfo(inumber)->ino_state,
122623d7cb6SMatthew D Fleming 				    (uintmax_t)inumber);
123d33e92f9SJulian Elischer 			}
1248fae3551SRodney W. Grimes 		}
1258fae3551SRodney W. Grimes 	}
1268fae3551SRodney W. Grimes }
127