/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1980, 1986, 19934* The Regents of the University of California. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the University nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031#include <sys/param.h>32#include <sys/stat.h>3334#include <ufs/ufs/dinode.h>35#include <ufs/ffs/fs.h>3637#include <err.h>38#include <stdint.h>39#include <string.h>4041#include "fsck.h"4243void44pass4(void)45{46ino_t inumber;47struct inode ip;48struct inodesc idesc;49int i, n, cg;5051memset(&idesc, 0, sizeof(struct inodesc));52idesc.id_func = freeblock;53for (cg = 0; cg < sblock.fs_ncg; cg++) {54if (got_siginfo) {55printf("%s: phase 4: cyl group %d of %d (%d%%)\n",56cdevname, cg, sblock.fs_ncg,57cg * 100 / sblock.fs_ncg);58got_siginfo = 0;59}60if (got_sigalarm) {61setproctitle("%s p4 %d%%", cdevname,62cg * 100 / sblock.fs_ncg);63got_sigalarm = 0;64}65inumber = cg * sblock.fs_ipg;66for (i = 0; i < inostathead[cg].il_numalloced; i++, inumber++) {67if (inumber < UFS_ROOTINO)68continue;69idesc.id_number = inumber;70idesc.id_type = inoinfo(inumber)->ino_idtype;71switch (inoinfo(inumber)->ino_state) {7273case FZLINK:74case DZLINK:75if (inoinfo(inumber)->ino_linkcnt == 0) {76clri(&idesc, "UNREF", 1);77break;78}79/* fall through */8081case FSTATE:82case DFOUND:83n = inoinfo(inumber)->ino_linkcnt;84if (n) {85adjust(&idesc, (short)n);86break;87}88break;8990case DSTATE:91clri(&idesc, "UNREF", 1);92break;9394case DCLEAR:95/* if on snapshot, already cleared */96if (cursnapshot != 0)97break;98ginode(inumber, &ip);99if (DIP(ip.i_dp, di_size) == 0) {100clri(&idesc, "ZERO LENGTH", 1);101irelse(&ip);102break;103}104irelse(&ip);105/* fall through */106case FCLEAR:107clri(&idesc, "BAD/DUP", 1);108break;109110case USTATE:111break;112113default:114errx(EEXIT, "BAD STATE %d FOR INODE I=%ju",115inoinfo(inumber)->ino_state,116(uintmax_t)inumber);117}118}119}120}121122123