2 * SPDX-License-Identifier: BSD-3-Clause AND BSD-2-Clause-FreeBSD
4 * Copyright (c) 2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * Copyright (c) 1982, 1986, 1989, 1993
29 * The Regents of the University of California. All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 #include <sys/cdefs.h>
57 __FBSDID("$FreeBSD$");
61 #include <ufs/ffs/fs.h>
65 gjournal_check(const char *filesys)
78 /* Are there any unreferenced inodes in this file system? */
79 if (fs->fs_unrefs == 0) {
80 //printf("No unreferenced inodes.\n");
86 for (cg = 0; cg < fs->fs_ncg; cg++) {
87 /* Show progress if requested. */
89 printf("%s: phase j: cyl group %d of %d (%d%%)\n",
90 cdevname, cg, fs->fs_ncg, cg * 100 / fs->fs_ncg);
94 setproctitle("%s pj %d%%", cdevname,
95 cg * 100 / fs->fs_ncg);
99 cgp = cgbp->b_un.b_cg;
100 if (!check_cgmagic(cg, cgbp, 0)) {
105 /* Are there any unreferenced inodes in this cylinder group? */
106 if (cgp->cg_unrefs == 0)
108 //printf("Analizing cylinder group %d (count=%d)\n", cg, cgp->cg_unrefs);
110 * Now go through the list of all inodes in this cylinder group
111 * to find unreferenced ones.
113 inosused = cg_inosused(cgp);
114 for (cino = 0; cino < fs->fs_ipg; cino++) {
115 ino = fs->fs_ipg * cg + cino;
116 /* Unallocated? Skip it. */
117 if (isclr(inosused, cino))
121 /* Not a regular file nor directory? Skip it. */
122 if (!S_ISREG(dp->dp2.di_mode) &&
123 !S_ISDIR(dp->dp2.di_mode)) {
127 /* Has reference(s)? Skip it. */
128 if (dp->dp2.di_nlink > 0) {
132 /* printf("Clearing inode=%d (size=%jd)\n", ino,
133 (intmax_t)dp->dp2->di_size); */
135 memset(&idesc, 0, sizeof(struct inodesc));
136 idesc.id_type = ADDR;
137 idesc.id_func = freeblock;
138 idesc.id_number = ino;
139 clri(&idesc, "UNREF", 1);
140 clrbit(inosused, cino);
141 /* Update position of last used inode. */
142 if (ino < cgp->cg_irotor)
143 cgp->cg_irotor = ino;
144 /* Update statistics. */
147 /* Zero-fill the inode. */
149 /* Write the inode back. */
153 if (cgp->cg_unrefs == 0) {
154 //printf("No more unreferenced inodes in cg=%d.\n", cg);
159 * If there are no more unreferenced inodes, there is no need to
160 * check other cylinder groups.
162 if (fs->fs_unrefs == 0) {
163 //printf("No more unreferenced inodes (cg=%d/%d).\n", cg,
168 /* Write back updated statistics and super-block. */