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
325942b4b6SKonstantin Belousov #define _WANT_P_OSREL
338fae3551SRodney W. Grimes #include <sys/param.h>
3438375c40SKirk McKusick #include <sys/file.h>
358fae3551SRodney W. Grimes #include <sys/mount.h>
3633966081SMatt Jacob #include <sys/resource.h>
377649cb00SKirk McKusick #include <sys/stat.h>
38bf58d635SIan Dowse #include <sys/sysctl.h>
3924adb851SCraig Rodrigues #include <sys/uio.h>
401c85e6a3SKirk McKusick #include <sys/disklabel.h>
41780a5c1eSPeter Wemm
428fae3551SRodney W. Grimes #include <ufs/ufs/dinode.h>
438fae3551SRodney W. Grimes #include <ufs/ffs/fs.h>
44780a5c1eSPeter Wemm
45780a5c1eSPeter Wemm #include <err.h>
46d0e1503bSPeter Wemm #include <errno.h>
478fae3551SRodney W. Grimes #include <fstab.h>
48ff76fc7fSKirk McKusick #include <grp.h>
496a5972dbSKirk McKusick #include <inttypes.h>
5024adb851SCraig Rodrigues #include <mntopts.h>
51d0e1503bSPeter Wemm #include <paths.h>
5284fc0d7eSMaxime Henrion #include <stdint.h>
53bf58d635SIan Dowse #include <string.h>
547649cb00SKirk McKusick #include <time.h>
55780a5c1eSPeter Wemm
568fae3551SRodney W. Grimes #include "fsck.h"
57780a5c1eSPeter Wemm
585cc52631SKirk McKusick static int restarts;
59*d3a36e4bSKirk McKusick static char snapname[BUFSIZ]; /* when doing snapshots, the name of the file */
607703a6ffSScott Long
61b70cd7eeSWarner Losh static void usage(void) __dead2;
626a5972dbSKirk McKusick static intmax_t argtoimax(int flag, const char *req, const char *str, int base);
63b70cd7eeSWarner Losh static int checkfilesys(char *filesys);
64c0bfa109SKirk McKusick static int setup_bkgrdchk(struct statfs *mntp, int sbrdfailed, char **filesys);
658fae3551SRodney W. Grimes
6631f4ab50SBruce Evans int
main(int argc,char * argv[])67b70cd7eeSWarner Losh main(int argc, char *argv[])
688fae3551SRodney W. Grimes {
698fae3551SRodney W. Grimes int ch;
70d33e92f9SJulian Elischer struct rlimit rlimit;
711660ae87SScott Long struct itimerval itimerval;
72469759f8SDavid Bright int fsret;
739ea6f4f0SAdrian Chadd int ret = 0;
748fae3551SRodney W. Grimes
758fae3551SRodney W. Grimes sync();
769ea6f4f0SAdrian Chadd skipclean = 1;
77910b491eSKirk McKusick inoopt = 0;
780061238fSKirk McKusick while ((ch = getopt(argc, argv, "b:Bc:CdEfFm:npRrSyZz")) != -1) {
798fae3551SRodney W. Grimes switch (ch) {
808fae3551SRodney W. Grimes case 'b':
819ea6f4f0SAdrian Chadd skipclean = 0;
826a5972dbSKirk McKusick bflag = argtoimax('b', "number", optarg, 10);
836a5972dbSKirk McKusick printf("Alternate super block location: %jd\n", bflag);
848fae3551SRodney W. Grimes break;
858fae3551SRodney W. Grimes
867578c6abSKirk McKusick case 'B':
877578c6abSKirk McKusick bkgrdflag = 1;
887578c6abSKirk McKusick break;
897578c6abSKirk McKusick
908fae3551SRodney W. Grimes case 'c':
919ea6f4f0SAdrian Chadd skipclean = 0;
926a5972dbSKirk McKusick cvtlevel = argtoimax('c', "conversion level", optarg,
936a5972dbSKirk McKusick 10);
941c85e6a3SKirk McKusick if (cvtlevel < 3)
951c85e6a3SKirk McKusick errx(EEXIT, "cannot do level %d conversion",
961c85e6a3SKirk McKusick cvtlevel);
978fae3551SRodney W. Grimes break;
988fae3551SRodney W. Grimes
998fae3551SRodney W. Grimes case 'd':
1008fae3551SRodney W. Grimes debug++;
1018fae3551SRodney W. Grimes break;
1028fae3551SRodney W. Grimes
1038d3dfc26SDag-Erling Smørgrav case 'E':
1048d3dfc26SDag-Erling Smørgrav Eflag++;
1058d3dfc26SDag-Erling Smørgrav break;
1068d3dfc26SDag-Erling Smørgrav
10741cee58cSDavid Greenman case 'f':
1089ea6f4f0SAdrian Chadd skipclean = 0;
1098fae3551SRodney W. Grimes break;
1108fae3551SRodney W. Grimes
11115fca934SKirk McKusick case 'F':
11215fca934SKirk McKusick bkgrdcheck = 1;
11315fca934SKirk McKusick break;
11415fca934SKirk McKusick
1158fae3551SRodney W. Grimes case 'm':
1166a5972dbSKirk McKusick lfmode = argtoimax('m', "mode", optarg, 8);
1178fae3551SRodney W. Grimes if (lfmode &~ 07777)
118780a5c1eSPeter Wemm errx(EEXIT, "bad mode to -m: %o", lfmode);
1198fae3551SRodney W. Grimes printf("** lost+found creation mode %o\n", lfmode);
1208fae3551SRodney W. Grimes break;
1218fae3551SRodney W. Grimes
1228fae3551SRodney W. Grimes case 'n':
1238fae3551SRodney W. Grimes nflag++;
1248fae3551SRodney W. Grimes yflag = 0;
1258fae3551SRodney W. Grimes break;
1268fae3551SRodney W. Grimes
1279ea6f4f0SAdrian Chadd case 'p':
1289ea6f4f0SAdrian Chadd preen++;
129111a5220SDavid E. O'Brien /*FALLTHROUGH*/
130111a5220SDavid E. O'Brien
131111a5220SDavid E. O'Brien case 'C':
132111a5220SDavid E. O'Brien ckclean++;
1339ea6f4f0SAdrian Chadd break;
1349ea6f4f0SAdrian Chadd
1357703a6ffSScott Long case 'R':
1367703a6ffSScott Long wantrestart = 1;
1377703a6ffSScott Long break;
138910b491eSKirk McKusick case 'r':
139910b491eSKirk McKusick inoopt++;
140910b491eSKirk McKusick break;
141910b491eSKirk McKusick
142ce779f37SScott Long case 'S':
143ce779f37SScott Long surrender = 1;
144ce779f37SScott Long break;
145ce779f37SScott Long
1468fae3551SRodney W. Grimes case 'y':
1478fae3551SRodney W. Grimes yflag++;
1488fae3551SRodney W. Grimes nflag = 0;
1498fae3551SRodney W. Grimes break;
1508fae3551SRodney W. Grimes
1512b5373deSDag-Erling Smørgrav case 'Z':
1522b5373deSDag-Erling Smørgrav Zflag++;
1532b5373deSDag-Erling Smørgrav break;
1542b5373deSDag-Erling Smørgrav
1550061238fSKirk McKusick case 'z':
1560061238fSKirk McKusick zflag++;
1570061238fSKirk McKusick break;
1580061238fSKirk McKusick
1598fae3551SRodney W. Grimes default:
1609ea6f4f0SAdrian Chadd usage();
1618fae3551SRodney W. Grimes }
1628fae3551SRodney W. Grimes }
1638fae3551SRodney W. Grimes argc -= optind;
1648fae3551SRodney W. Grimes argv += optind;
1659ea6f4f0SAdrian Chadd
1669ea6f4f0SAdrian Chadd if (!argc)
1679ea6f4f0SAdrian Chadd usage();
1689ea6f4f0SAdrian Chadd
169c0bfa109SKirk McKusick if (bkgrdflag && cvtlevel > 0) {
170c0bfa109SKirk McKusick pfatal("CANNOT CONVERT A SNAPSHOT\n");
171c0bfa109SKirk McKusick exit(EEXIT);
172c0bfa109SKirk McKusick }
173c0bfa109SKirk McKusick
1748fae3551SRodney W. Grimes if (signal(SIGINT, SIG_IGN) != SIG_IGN)
1758fae3551SRodney W. Grimes (void)signal(SIGINT, catch);
176111a5220SDavid E. O'Brien if (ckclean)
1778fae3551SRodney W. Grimes (void)signal(SIGQUIT, catchquit);
1786db798caSIan Dowse signal(SIGINFO, infohandler);
1791660ae87SScott Long if (bkgrdflag) {
1801660ae87SScott Long signal(SIGALRM, alarmhandler);
1811660ae87SScott Long itimerval.it_interval.tv_sec = 5;
1821660ae87SScott Long itimerval.it_interval.tv_usec = 0;
1831660ae87SScott Long itimerval.it_value.tv_sec = 5;
1841660ae87SScott Long itimerval.it_value.tv_usec = 0;
1851660ae87SScott Long setitimer(ITIMER_REAL, &itimerval, NULL);
1861660ae87SScott Long }
187d33e92f9SJulian Elischer /*
188d33e92f9SJulian Elischer * Push up our allowed memory limit so we can cope
189d33e92f9SJulian Elischer * with huge file systems.
190d33e92f9SJulian Elischer */
191d33e92f9SJulian Elischer if (getrlimit(RLIMIT_DATA, &rlimit) == 0) {
192d33e92f9SJulian Elischer rlimit.rlim_cur = rlimit.rlim_max;
193d33e92f9SJulian Elischer (void)setrlimit(RLIMIT_DATA, &rlimit);
194d33e92f9SJulian Elischer }
1957703a6ffSScott Long while (argc > 0) {
196469759f8SDavid Bright if ((fsret = checkfilesys(*argv)) == ERESTART)
1977703a6ffSScott Long continue;
198469759f8SDavid Bright ret |= fsret;
1997703a6ffSScott Long argc--;
2007703a6ffSScott Long argv++;
2017703a6ffSScott Long }
202d33e92f9SJulian Elischer
2038fae3551SRodney W. Grimes if (returntosingle)
2049ea6f4f0SAdrian Chadd ret = 2;
2058fae3551SRodney W. Grimes exit(ret);
2068fae3551SRodney W. Grimes }
2078fae3551SRodney W. Grimes
2086a5972dbSKirk McKusick static intmax_t
argtoimax(int flag,const char * req,const char * str,int base)2096a5972dbSKirk McKusick argtoimax(int flag, const char *req, const char *str, int base)
2108fae3551SRodney W. Grimes {
2118fae3551SRodney W. Grimes char *cp;
2126a5972dbSKirk McKusick intmax_t ret;
2138fae3551SRodney W. Grimes
2146a5972dbSKirk McKusick ret = strtoimax(str, &cp, base);
2158fae3551SRodney W. Grimes if (cp == str || *cp)
216780a5c1eSPeter Wemm errx(EEXIT, "-%c flag requires a %s", flag, req);
2178fae3551SRodney W. Grimes return (ret);
2188fae3551SRodney W. Grimes }
2198fae3551SRodney W. Grimes
2208fae3551SRodney W. Grimes /*
2218fae3551SRodney W. Grimes * Check the specified file system.
2228fae3551SRodney W. Grimes */
2238fae3551SRodney W. Grimes /* ARGSUSED */
224780a5c1eSPeter Wemm static int
checkfilesys(char * filesys)225b70cd7eeSWarner Losh checkfilesys(char *filesys)
2268fae3551SRodney W. Grimes {
2271c85e6a3SKirk McKusick ufs2_daddr_t n_ffree, n_bfree;
2288fae3551SRodney W. Grimes struct dups *dp;
2297578c6abSKirk McKusick struct statfs *mntp;
230a1c9ec3cSMatthew D Fleming intmax_t blks, files;
23184fc0d7eSMaxime Henrion size_t size;
232c0bfa109SKirk McKusick int sbreadfailed, ofsmodified;
2338fae3551SRodney W. Grimes
2347703a6ffSScott Long fsutilinit();
2357703a6ffSScott Long fsckinit();
23624adb851SCraig Rodrigues
2378fae3551SRodney W. Grimes cdevname = filesys;
238111a5220SDavid E. O'Brien if (debug && ckclean)
2398fae3551SRodney W. Grimes pwarn("starting\n");
24015fca934SKirk McKusick /*
24115fca934SKirk McKusick * Make best effort to get the disk name. Check first to see
24215fca934SKirk McKusick * if it is listed among the mounted file systems. Failing that
24315fca934SKirk McKusick * check to see if it is listed in /etc/fstab.
24415fca934SKirk McKusick */
245906c312bSKirk McKusick mntp = getmntpoint(filesys);
24615fca934SKirk McKusick if (mntp != NULL)
24715fca934SKirk McKusick filesys = mntp->f_mntfromname;
24815fca934SKirk McKusick else
24915fca934SKirk McKusick filesys = blockcheck(filesys);
25015fca934SKirk McKusick /*
25115fca934SKirk McKusick * If -F flag specified, check to see whether a background check
25215fca934SKirk McKusick * is possible and needed. If possible and needed, exit with
25315fca934SKirk McKusick * status zero. Otherwise exit with status non-zero. A non-zero
25415fca934SKirk McKusick * exit status will cause a foreground check to be run.
25515fca934SKirk McKusick */
25638375c40SKirk McKusick sblock_init();
257c0bfa109SKirk McKusick sbreadfailed = 0;
258e6886616SKirk McKusick if (openfilesys(filesys) == 0 || readsb() == 0)
259c0bfa109SKirk McKusick sbreadfailed = 1;
26015fca934SKirk McKusick if (bkgrdcheck) {
261c0bfa109SKirk McKusick if (sbreadfailed)
26215fca934SKirk McKusick exit(3); /* Cannot read superblock */
263344b5bf8SKirk McKusick if ((sblock.fs_flags & FS_NEEDSFSCK) == FS_NEEDSFSCK)
264344b5bf8SKirk McKusick exit(4); /* Earlier background failed */
265344b5bf8SKirk McKusick if ((sblock.fs_flags & FS_SUJ) == FS_SUJ) {
266344b5bf8SKirk McKusick maxino = sblock.fs_ncg * sblock.fs_ipg;
267344b5bf8SKirk McKusick maxfsblock = sblock.fs_size;
268344b5bf8SKirk McKusick bufinit();
269344b5bf8SKirk McKusick preen = 1;
270344b5bf8SKirk McKusick if (suj_check(filesys) == 0)
271344b5bf8SKirk McKusick exit(4); /* Journal good, run it now */
272344b5bf8SKirk McKusick }
27315fca934SKirk McKusick if ((sblock.fs_flags & FS_DOSOFTDEP) == 0)
27415fca934SKirk McKusick exit(5); /* Not running soft updates */
27515fca934SKirk McKusick size = MIBSIZE;
27615fca934SKirk McKusick if (sysctlnametomib("vfs.ffs.adjrefcnt", adjrefcnt, &size) < 0)
27715fca934SKirk McKusick exit(6); /* Lacks kernel support */
27815fca934SKirk McKusick if ((mntp == NULL && sblock.fs_clean == 1) ||
27915fca934SKirk McKusick (mntp != NULL && (sblock.fs_flags & FS_UNCLEAN) == 0))
28015fca934SKirk McKusick exit(7); /* Filesystem clean, report it now */
28115fca934SKirk McKusick exit(0);
28215fca934SKirk McKusick }
283111a5220SDavid E. O'Brien if (ckclean && skipclean) {
284aef8d244SPawel Jakub Dawidek /*
285aef8d244SPawel Jakub Dawidek * If file system is gjournaled, check it here.
286aef8d244SPawel Jakub Dawidek */
287c0bfa109SKirk McKusick if (sbreadfailed)
288aef8d244SPawel Jakub Dawidek exit(3); /* Cannot read superblock */
2890c5a5925SRobert Wing if (bkgrdflag == 0 &&
2900c5a5925SRobert Wing (nflag || (fswritefd = open(filesys, O_WRONLY)) < 0)) {
2915cc52631SKirk McKusick fswritefd = -1;
2925cc52631SKirk McKusick if (preen)
2935cc52631SKirk McKusick pfatal("NO WRITE ACCESS");
2945cc52631SKirk McKusick printf(" (NO WRITE)");
2955cc52631SKirk McKusick }
296aef8d244SPawel Jakub Dawidek if ((sblock.fs_flags & FS_GJOURNAL) != 0) {
297aef8d244SPawel Jakub Dawidek if (sblock.fs_clean == 1) {
298aef8d244SPawel Jakub Dawidek pwarn("FILE SYSTEM CLEAN; SKIPPING CHECKS\n");
299aef8d244SPawel Jakub Dawidek exit(0);
300aef8d244SPawel Jakub Dawidek }
301c0bfa109SKirk McKusick if ((sblock.fs_flags &
302c0bfa109SKirk McKusick (FS_UNCLEAN | FS_NEEDSFSCK)) == 0) {
303441e69e4SRobert Wing bufinit();
304aef8d244SPawel Jakub Dawidek gjournal_check(filesys);
305906c312bSKirk McKusick if (chkdoreload(mntp, pwarn) == 0)
306aef8d244SPawel Jakub Dawidek exit(0);
307db3f838dSPawel Jakub Dawidek exit(4);
308aef8d244SPawel Jakub Dawidek } else {
309c0bfa109SKirk McKusick pfatal("FULL FSCK NEEDED, CANNOT RUN FAST "
310c0bfa109SKirk McKusick "FSCK\n");
3110c5a5925SRobert Wing }
3120c5a5925SRobert Wing }
3135cc52631SKirk McKusick close(fswritefd);
314c0bfa109SKirk McKusick fswritefd = -1;
315aef8d244SPawel Jakub Dawidek }
3167578c6abSKirk McKusick if (bkgrdflag) {
317c0bfa109SKirk McKusick switch (setup_bkgrdchk(mntp, sbreadfailed, &filesys)) {
318c0bfa109SKirk McKusick case -1: /* filesystem clean */
31938375c40SKirk McKusick goto clean;
320c0bfa109SKirk McKusick case 0: /* cannot do background, give up */
321c0bfa109SKirk McKusick exit(EEXIT);
322c0bfa109SKirk McKusick case 1: /* doing background check, preen rules apply */
323c0bfa109SKirk McKusick preen = 1;
3247578c6abSKirk McKusick break;
3257578c6abSKirk McKusick }
3267578c6abSKirk McKusick }
3277578c6abSKirk McKusick
328780a5c1eSPeter Wemm switch (setup(filesys)) {
329780a5c1eSPeter Wemm case 0:
3308fae3551SRodney W. Grimes if (preen)
3318fae3551SRodney W. Grimes pfatal("CAN'T CHECK FILE SYSTEM.");
332e8337044SChuck Silvers return (EEXIT);
333780a5c1eSPeter Wemm case -1:
33438375c40SKirk McKusick clean:
335bf58d635SIan Dowse pwarn("clean, %ld free ", (long)(sblock.fs_cstotal.cs_nffree +
336bf58d635SIan Dowse sblock.fs_frag * sblock.fs_cstotal.cs_nbfree));
337a1c9ec3cSMatthew D Fleming printf("(%jd frags, %jd blocks, %.1f%% fragmentation)\n",
338a1c9ec3cSMatthew D Fleming (intmax_t)sblock.fs_cstotal.cs_nffree,
339a1c9ec3cSMatthew D Fleming (intmax_t)sblock.fs_cstotal.cs_nbfree,
3406b100474SJulian Elischer sblock.fs_cstotal.cs_nffree * 100.0 / sblock.fs_dsize);
34141cee58cSDavid Greenman return (0);
34241cee58cSDavid Greenman }
343113db2ddSJeff Roberson /*
344113db2ddSJeff Roberson * Determine if we can and should do journal recovery.
345113db2ddSJeff Roberson */
346344b5bf8SKirk McKusick if (bkgrdflag == 0 && (sblock.fs_flags & FS_SUJ) == FS_SUJ) {
347239597e0SKirk McKusick if ((sblock.fs_flags & FS_NEEDSFSCK) != FS_NEEDSFSCK &&
348239597e0SKirk McKusick skipclean) {
3495cc52631SKirk McKusick sujrecovery = 1;
350113db2ddSJeff Roberson if (suj_check(filesys) == 0) {
351239597e0SKirk McKusick pwarn("\n**** FILE SYSTEM MARKED CLEAN ****\n");
352906c312bSKirk McKusick if (chkdoreload(mntp, pwarn) == 0)
353113db2ddSJeff Roberson exit(0);
354113db2ddSJeff Roberson exit(4);
355113db2ddSJeff Roberson }
3565cc52631SKirk McKusick sujrecovery = 0;
357239597e0SKirk McKusick pwarn("Skipping journal, "
358239597e0SKirk McKusick "falling through to full fsck\n");
359edad6026SXin LI }
360ed1a156bSChuck Silvers if (fswritefd != -1) {
361113db2ddSJeff Roberson /*
362113db2ddSJeff Roberson * Write the superblock so we don't try to recover the
36391882068SKirk McKusick * journal on another pass. If this is the only change
36491882068SKirk McKusick * to the filesystem, we do not want it to be called
36591882068SKirk McKusick * out as modified.
366113db2ddSJeff Roberson */
367113db2ddSJeff Roberson sblock.fs_mtime = time(NULL);
368113db2ddSJeff Roberson sbdirty();
36991882068SKirk McKusick ofsmodified = fsmodified;
37091882068SKirk McKusick flush(fswritefd, &sblk);
37191882068SKirk McKusick fsmodified = ofsmodified;
372113db2ddSJeff Roberson }
373ed1a156bSChuck Silvers }
37431461aa2SKirk McKusick /*
37531461aa2SKirk McKusick * If the filesystem was run on an old kernel that did not
37631461aa2SKirk McKusick * support check hashes, clear the check-hash flags so that
37731461aa2SKirk McKusick * we do not try to verify them.
37831461aa2SKirk McKusick */
37931461aa2SKirk McKusick if ((sblock.fs_flags & FS_METACKHASH) == 0)
38031461aa2SKirk McKusick sblock.fs_metackhash = 0;
38131461aa2SKirk McKusick /*
38231461aa2SKirk McKusick * If we are running on a kernel that can provide check hashes
38331461aa2SKirk McKusick * that are not yet enabled for the filesystem and we are
38431461aa2SKirk McKusick * running manually without the -y flag, offer to add any
38531461aa2SKirk McKusick * supported check hashes that are not already enabled.
38631461aa2SKirk McKusick */
38731461aa2SKirk McKusick ckhashadd = 0;
38831461aa2SKirk McKusick if (preen == 0 && yflag == 0 && sblock.fs_magic != FS_UFS1_MAGIC &&
38931461aa2SKirk McKusick fswritefd != -1 && getosreldate() >= P_OSREL_CK_CYLGRP) {
39031461aa2SKirk McKusick if ((sblock.fs_metackhash & CK_CYLGRP) == 0 &&
3919fc5d538SKirk McKusick reply("ADD CYLINDER GROUP CHECK-HASH PROTECTION") != 0) {
39231461aa2SKirk McKusick ckhashadd |= CK_CYLGRP;
3939fc5d538SKirk McKusick sblock.fs_metackhash |= CK_CYLGRP;
3949fc5d538SKirk McKusick }
39531461aa2SKirk McKusick if ((sblock.fs_metackhash & CK_SUPERBLOCK) == 0 &&
39631461aa2SKirk McKusick getosreldate() >= P_OSREL_CK_SUPERBLOCK &&
397ec888383SKirk McKusick reply("ADD SUPERBLOCK CHECK-HASH PROTECTION") != 0) {
3989fc5d538SKirk McKusick ckhashadd |= CK_SUPERBLOCK;
399ec888383SKirk McKusick sblock.fs_metackhash |= CK_SUPERBLOCK;
400ec888383SKirk McKusick }
40131461aa2SKirk McKusick if ((sblock.fs_metackhash & CK_INODE) == 0 &&
40231461aa2SKirk McKusick getosreldate() >= P_OSREL_CK_INODE &&
4039fc5d538SKirk McKusick reply("ADD INODE CHECK-HASH PROTECTION") != 0) {
40431461aa2SKirk McKusick ckhashadd |= CK_INODE;
4059fc5d538SKirk McKusick sblock.fs_metackhash |= CK_INODE;
4069fc5d538SKirk McKusick }
4078f829a5cSKirk McKusick #ifdef notyet
40831461aa2SKirk McKusick if ((sblock.fs_metackhash & CK_INDIR) == 0 &&
40931461aa2SKirk McKusick getosreldate() >= P_OSREL_CK_INDIR &&
4109fc5d538SKirk McKusick reply("ADD INDIRECT BLOCK CHECK-HASH PROTECTION") != 0) {
41131461aa2SKirk McKusick ckhashadd |= CK_INDIR;
4129fc5d538SKirk McKusick sblock.fs_metackhash |= CK_INDIR;
4139fc5d538SKirk McKusick }
41431461aa2SKirk McKusick if ((sblock.fs_metackhash & CK_DIR) == 0 &&
41531461aa2SKirk McKusick getosreldate() >= P_OSREL_CK_DIR &&
4169fc5d538SKirk McKusick reply("ADD DIRECTORY CHECK-HASH PROTECTION") != 0) {
41731461aa2SKirk McKusick ckhashadd |= CK_DIR;
4189fc5d538SKirk McKusick sblock.fs_metackhash |= CK_DIR;
4199fc5d538SKirk McKusick }
42031461aa2SKirk McKusick #endif /* notyet */
4219fc5d538SKirk McKusick if (ckhashadd != 0) {
42231461aa2SKirk McKusick sblock.fs_flags |= FS_METACKHASH;
4239fc5d538SKirk McKusick sbdirty();
4249fc5d538SKirk McKusick }
42531461aa2SKirk McKusick }
4268fae3551SRodney W. Grimes /*
427b1897c19SJulian Elischer * Cleared if any questions answered no. Used to decide if
428b1897c19SJulian Elischer * the superblock should be marked clean.
429b1897c19SJulian Elischer */
430b1897c19SJulian Elischer resolved = 1;
431b1897c19SJulian Elischer /*
4328fae3551SRodney W. Grimes * 1: scan inodes tallying blocks used
4338fae3551SRodney W. Grimes */
4344d512b07SKirk McKusick if (preen == 0 || debug) {
4358fae3551SRodney W. Grimes printf("** Last Mounted on %s\n", sblock.fs_fsmnt);
4367578c6abSKirk McKusick if (mntp != NULL && mntp->f_flags & MNT_ROOTFS)
4378fae3551SRodney W. Grimes printf("** Root file system\n");
4388fae3551SRodney W. Grimes printf("** Phase 1 - Check Blocks and Sizes\n");
4398fae3551SRodney W. Grimes }
440ed75b5a1SKirk McKusick clock_gettime(CLOCK_REALTIME_PRECISE, &startprog);
4418fae3551SRodney W. Grimes pass1();
442ed75b5a1SKirk McKusick IOstats("Pass1");
4438fae3551SRodney W. Grimes
4448fae3551SRodney W. Grimes /*
4458fae3551SRodney W. Grimes * 1b: locate first references to duplicates, if any
4468fae3551SRodney W. Grimes */
4478fae3551SRodney W. Grimes if (duplist) {
448b1897c19SJulian Elischer if (preen || usedsoftdep)
449c82df0a0SKirk McKusick pfatal("INTERNAL ERROR: DUPS WITH %s%s%s",
45021be55ccSKirk McKusick preen ? "-p" : "",
451c82df0a0SKirk McKusick (preen && usedsoftdep) ? " AND " : "",
452c82df0a0SKirk McKusick usedsoftdep ? "SOFTUPDATES" : "");
4534d512b07SKirk McKusick if (preen == 0 || debug)
4548fae3551SRodney W. Grimes printf("** Phase 1b - Rescan For More DUPS\n");
4558fae3551SRodney W. Grimes pass1b();
456ed75b5a1SKirk McKusick IOstats("Pass1b");
4578fae3551SRodney W. Grimes }
4588fae3551SRodney W. Grimes
4598fae3551SRodney W. Grimes /*
4608fae3551SRodney W. Grimes * 2: traverse directories from root to mark all connected directories
4618fae3551SRodney W. Grimes */
4624d512b07SKirk McKusick if (preen == 0 || debug)
4638fae3551SRodney W. Grimes printf("** Phase 2 - Check Pathnames\n");
4648fae3551SRodney W. Grimes pass2();
465ed75b5a1SKirk McKusick IOstats("Pass2");
4668fae3551SRodney W. Grimes
4678fae3551SRodney W. Grimes /*
4688fae3551SRodney W. Grimes * 3: scan inodes looking for disconnected directories
4698fae3551SRodney W. Grimes */
4704d512b07SKirk McKusick if (preen == 0 || debug)
4718fae3551SRodney W. Grimes printf("** Phase 3 - Check Connectivity\n");
4728fae3551SRodney W. Grimes pass3();
473ed75b5a1SKirk McKusick IOstats("Pass3");
4748fae3551SRodney W. Grimes
4758fae3551SRodney W. Grimes /*
4768fae3551SRodney W. Grimes * 4: scan inodes looking for disconnected files; check reference counts
4778fae3551SRodney W. Grimes */
4784d512b07SKirk McKusick if (preen == 0 || debug)
4798fae3551SRodney W. Grimes printf("** Phase 4 - Check Reference Counts\n");
4808fae3551SRodney W. Grimes pass4();
481ed75b5a1SKirk McKusick IOstats("Pass4");
4828fae3551SRodney W. Grimes
4838fae3551SRodney W. Grimes /*
4848fae3551SRodney W. Grimes * 5: check and repair resource counts in cylinder groups
4858fae3551SRodney W. Grimes */
4864d512b07SKirk McKusick if (preen == 0 || debug)
4878fae3551SRodney W. Grimes printf("** Phase 5 - Check Cyl groups\n");
488460ed610SKirk McKusick snapflush(std_checkblkavail);
489da86e7a2SKirk McKusick if (cgheader_corrupt) {
490da86e7a2SKirk McKusick printf("PHASE 5 SKIPPED DUE TO CORRUPT CYLINDER GROUP "
49140647558SChuck Silvers "HEADER(S)\n\n");
492da86e7a2SKirk McKusick } else {
4938fae3551SRodney W. Grimes pass5();
494ed75b5a1SKirk McKusick IOstats("Pass5");
495da86e7a2SKirk McKusick }
4968fae3551SRodney W. Grimes
4978fae3551SRodney W. Grimes /*
4988fae3551SRodney W. Grimes * print out summary statistics
4998fae3551SRodney W. Grimes */
5008fae3551SRodney W. Grimes n_ffree = sblock.fs_cstotal.cs_nffree;
5018fae3551SRodney W. Grimes n_bfree = sblock.fs_cstotal.cs_nbfree;
5021dc349abSEd Maste files = maxino - UFS_ROOTINO - sblock.fs_cstotal.cs_nifree - n_files;
5037578c6abSKirk McKusick blks = n_blks +
5047578c6abSKirk McKusick sblock.fs_ncg * (cgdmin(&sblock, 0) - cgsblock(&sblock, 0));
5057578c6abSKirk McKusick blks += cgsblock(&sblock, 0) - cgbase(&sblock, 0);
5067578c6abSKirk McKusick blks += howmany(sblock.fs_cssize, sblock.fs_fsize);
5077578c6abSKirk McKusick blks = maxfsblock - (n_ffree + sblock.fs_frag * n_bfree) - blks;
5087578c6abSKirk McKusick if (bkgrdflag && (files > 0 || blks > 0)) {
5097578c6abSKirk McKusick countdirs = sblock.fs_cstotal.cs_ndir - countdirs;
510a1c9ec3cSMatthew D Fleming pwarn("Reclaimed: %ld directories, %jd files, %jd fragments\n",
511a1c9ec3cSMatthew D Fleming countdirs, files - countdirs, blks);
5127578c6abSKirk McKusick }
51384fc0d7eSMaxime Henrion pwarn("%ld files, %jd used, %ju free ",
51484fc0d7eSMaxime Henrion (long)n_files, (intmax_t)n_blks,
51584fc0d7eSMaxime Henrion (uintmax_t)n_ffree + sblock.fs_frag * n_bfree);
51684fc0d7eSMaxime Henrion printf("(%ju frags, %ju blocks, %.1f%% fragmentation)\n",
51784fc0d7eSMaxime Henrion (uintmax_t)n_ffree, (uintmax_t)n_bfree,
51884fc0d7eSMaxime Henrion n_ffree * 100.0 / sblock.fs_dsize);
5198fae3551SRodney W. Grimes if (debug) {
5207578c6abSKirk McKusick if (files < 0)
521a1c9ec3cSMatthew D Fleming printf("%jd inodes missing\n", -files);
5227578c6abSKirk McKusick if (blks < 0)
523a1c9ec3cSMatthew D Fleming printf("%jd blocks missing\n", -blks);
5248fae3551SRodney W. Grimes if (duplist != NULL) {
5258fae3551SRodney W. Grimes printf("The following duplicate blocks remain:");
5268fae3551SRodney W. Grimes for (dp = duplist; dp; dp = dp->next)
527a1c9ec3cSMatthew D Fleming printf(" %jd,", (intmax_t)dp->dup);
5288fae3551SRodney W. Grimes printf("\n");
5298fae3551SRodney W. Grimes }
5308fae3551SRodney W. Grimes }
5318fae3551SRodney W. Grimes duplist = (struct dups *)0;
5328fae3551SRodney W. Grimes muldup = (struct dups *)0;
5338fae3551SRodney W. Grimes inocleanup();
534802cd8e6SDavid Greenman if (fsmodified) {
535d33e92f9SJulian Elischer sblock.fs_time = time(NULL);
5368fae3551SRodney W. Grimes sbdirty();
5378fae3551SRodney W. Grimes }
5385cc52631SKirk McKusick if (cvtlevel && (sblk.b_flags & B_DIRTY) != 0) {
5398fae3551SRodney W. Grimes /*
5408fae3551SRodney W. Grimes * Write out the duplicate super blocks
5418fae3551SRodney W. Grimes */
542f644caadSKirk McKusick if (sbput(fswritefd, &sblock, sblock.fs_ncg) == 0)
543f644caadSKirk McKusick fsmodified = 1;
5448fae3551SRodney W. Grimes }
545b1897c19SJulian Elischer if (rerun)
546b1897c19SJulian Elischer resolved = 0;
547571b29eeSPeter Wemm
548d0e1503bSPeter Wemm /*
549aa5344b7SPeter Wemm * Check to see if the file system is mounted read-write.
550d0e1503bSPeter Wemm */
5517578c6abSKirk McKusick if (bkgrdflag == 0 && mntp != NULL && (mntp->f_flags & MNT_RDONLY) == 0)
552b1897c19SJulian Elischer resolved = 0;
553b1897c19SJulian Elischer ckfini(resolved);
554d33e92f9SJulian Elischer
555d33e92f9SJulian Elischer if (fsmodified && !preen)
5568fae3551SRodney W. Grimes printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
5577703a6ffSScott Long if (rerun) {
5587703a6ffSScott Long if (wantrestart && (restarts++ < 10) &&
5597703a6ffSScott Long (preen || reply("RESTART")))
5607703a6ffSScott Long return (ERESTART);
56147ceb636SGuido van Rooij printf("\n***** PLEASE RERUN FSCK *****\n");
5627703a6ffSScott Long }
563906c312bSKirk McKusick if (chkdoreload(mntp, pwarn) != 0) {
564d33e92f9SJulian Elischer if (!fsmodified)
565d33e92f9SJulian Elischer return (0);
5668fae3551SRodney W. Grimes if (!preen)
5678fae3551SRodney W. Grimes printf("\n***** REBOOT NOW *****\n");
5688fae3551SRodney W. Grimes sync();
5698fae3551SRodney W. Grimes return (4);
5708fae3551SRodney W. Grimes }
571469759f8SDavid Bright return (rerun ? ERERUN : 0);
5728fae3551SRodney W. Grimes }
573571b29eeSPeter Wemm
574c0bfa109SKirk McKusick /*
575c0bfa109SKirk McKusick * If we are to do a background check:
576c0bfa109SKirk McKusick * Get the mount point information of the file system
577c0bfa109SKirk McKusick * If already clean, return -1
578c0bfa109SKirk McKusick * Check that kernel supports background fsck
579c0bfa109SKirk McKusick * Find or create the snapshot directory
580c0bfa109SKirk McKusick * Create the snapshot file
581c0bfa109SKirk McKusick * Open snapshot
582c0bfa109SKirk McKusick * If anything fails print reason and return 0 which exits
583c0bfa109SKirk McKusick */
584c0bfa109SKirk McKusick static int
setup_bkgrdchk(struct statfs * mntp,int sbreadfailed,char ** filesys)585c0bfa109SKirk McKusick setup_bkgrdchk(struct statfs *mntp, int sbreadfailed, char **filesys)
586c0bfa109SKirk McKusick {
587c0bfa109SKirk McKusick struct stat snapdir;
588c0bfa109SKirk McKusick struct group *grp;
589c0bfa109SKirk McKusick struct iovec *iov;
590c0bfa109SKirk McKusick char errmsg[255];
591c0bfa109SKirk McKusick int iovlen;
5929583be04SKirk McKusick size_t size;
593c0bfa109SKirk McKusick
594c0bfa109SKirk McKusick /* Get the mount point information of the file system */
595c0bfa109SKirk McKusick if (mntp == NULL) {
596c0bfa109SKirk McKusick pwarn("NOT MOUNTED, CANNOT RUN IN BACKGROUND\n");
597c0bfa109SKirk McKusick return (0);
598c0bfa109SKirk McKusick }
599c0bfa109SKirk McKusick if ((mntp->f_flags & MNT_RDONLY) != 0) {
600c0bfa109SKirk McKusick pwarn("MOUNTED READ-ONLY, CANNOT RUN IN BACKGROUND\n");
601c0bfa109SKirk McKusick return (0);
602c0bfa109SKirk McKusick }
603c0bfa109SKirk McKusick if ((mntp->f_flags & MNT_SOFTDEP) == 0) {
604c0bfa109SKirk McKusick pwarn("NOT USING SOFT UPDATES, CANNOT RUN IN BACKGROUND\n");
605c0bfa109SKirk McKusick return (0);
606c0bfa109SKirk McKusick }
607c0bfa109SKirk McKusick if (sbreadfailed) {
608c0bfa109SKirk McKusick pwarn("SUPERBLOCK READ FAILED, CANNOT RUN IN BACKGROUND\n");
609c0bfa109SKirk McKusick return (0);
610c0bfa109SKirk McKusick }
611c0bfa109SKirk McKusick if ((sblock.fs_flags & FS_NEEDSFSCK) != 0) {
612c0bfa109SKirk McKusick pwarn("FULL FSCK NEEDED, CANNOT RUN IN BACKGROUND\n");
613c0bfa109SKirk McKusick return (0);
614c0bfa109SKirk McKusick }
615c0bfa109SKirk McKusick if (skipclean && ckclean &&
616c0bfa109SKirk McKusick (sblock.fs_flags & (FS_UNCLEAN|FS_NEEDSFSCK)) == 0) {
617c0bfa109SKirk McKusick /*
618c0bfa109SKirk McKusick * file system is clean;
619c0bfa109SKirk McKusick * skip snapshot and report it clean
620c0bfa109SKirk McKusick */
621c0bfa109SKirk McKusick pwarn("FILE SYSTEM CLEAN; SKIPPING CHECKS\n");
622c0bfa109SKirk McKusick return (-1);
623c0bfa109SKirk McKusick }
624c0bfa109SKirk McKusick /* Check that kernel supports background fsck */
625c0bfa109SKirk McKusick size = MIBSIZE;
626c0bfa109SKirk McKusick if (sysctlnametomib("vfs.ffs.adjrefcnt", adjrefcnt, &size) < 0||
627c0bfa109SKirk McKusick sysctlnametomib("vfs.ffs.adjblkcnt", adjblkcnt, &size) < 0||
628c0bfa109SKirk McKusick sysctlnametomib("vfs.ffs.setsize", setsize, &size) < 0 ||
629c0bfa109SKirk McKusick sysctlnametomib("vfs.ffs.freefiles", freefiles, &size) < 0||
630c0bfa109SKirk McKusick sysctlnametomib("vfs.ffs.freedirs", freedirs, &size) < 0 ||
631c0bfa109SKirk McKusick sysctlnametomib("vfs.ffs.freeblks", freeblks, &size) < 0) {
632c0bfa109SKirk McKusick pwarn("KERNEL LACKS BACKGROUND FSCK SUPPORT\n");
633c0bfa109SKirk McKusick return (0);
634c0bfa109SKirk McKusick }
635c0bfa109SKirk McKusick /*
636c0bfa109SKirk McKusick * When kernel lacks runtime bgfsck superblock summary
637c0bfa109SKirk McKusick * adjustment functionality, it does not mean we can not
638c0bfa109SKirk McKusick * continue, as old kernels will recompute the summary at
639c0bfa109SKirk McKusick * mount time. However, it will be an unexpected softupdates
640c0bfa109SKirk McKusick * inconsistency if it turns out that the summary is still
641c0bfa109SKirk McKusick * incorrect. Set a flag so subsequent operation can know this.
642c0bfa109SKirk McKusick */
643c0bfa109SKirk McKusick bkgrdsumadj = 1;
644c0bfa109SKirk McKusick if (sysctlnametomib("vfs.ffs.adjndir", adjndir, &size) < 0 ||
645c0bfa109SKirk McKusick sysctlnametomib("vfs.ffs.adjnbfree", adjnbfree, &size) < 0 ||
646c0bfa109SKirk McKusick sysctlnametomib("vfs.ffs.adjnifree", adjnifree, &size) < 0 ||
647c0bfa109SKirk McKusick sysctlnametomib("vfs.ffs.adjnffree", adjnffree, &size) < 0 ||
648c0bfa109SKirk McKusick sysctlnametomib("vfs.ffs.adjnumclusters", adjnumclusters,
649c0bfa109SKirk McKusick &size) < 0) {
650c0bfa109SKirk McKusick bkgrdsumadj = 0;
651c0bfa109SKirk McKusick pwarn("KERNEL LACKS RUNTIME SUPERBLOCK SUMMARY ADJUSTMENT "
652c0bfa109SKirk McKusick "SUPPORT\n");
653c0bfa109SKirk McKusick }
654c0bfa109SKirk McKusick /* Find or create the snapshot directory */
655*d3a36e4bSKirk McKusick snprintf(snapname, sizeof snapname, "%s/.snap", mntp->f_mntonname);
656c0bfa109SKirk McKusick if (stat(snapname, &snapdir) < 0) {
657c0bfa109SKirk McKusick if (errno != ENOENT) {
658c0bfa109SKirk McKusick pwarn("CANNOT FIND SNAPSHOT DIRECTORY %s: %s, CANNOT "
659c0bfa109SKirk McKusick "RUN IN BACKGROUND\n", snapname, strerror(errno));
660c0bfa109SKirk McKusick return (0);
661c0bfa109SKirk McKusick }
662c0bfa109SKirk McKusick if ((grp = getgrnam("operator")) == NULL ||
663c0bfa109SKirk McKusick mkdir(snapname, 0770) < 0 ||
664c0bfa109SKirk McKusick chown(snapname, -1, grp->gr_gid) < 0 ||
665c0bfa109SKirk McKusick chmod(snapname, 0770) < 0) {
666c0bfa109SKirk McKusick pwarn("CANNOT CREATE SNAPSHOT DIRECTORY %s: %s, "
667c0bfa109SKirk McKusick "CANNOT RUN IN BACKGROUND\n", snapname,
668c0bfa109SKirk McKusick strerror(errno));
669c0bfa109SKirk McKusick return (0);
670c0bfa109SKirk McKusick }
671c0bfa109SKirk McKusick } else if (!S_ISDIR(snapdir.st_mode)) {
672c0bfa109SKirk McKusick pwarn("%s IS NOT A DIRECTORY, CANNOT RUN IN BACKGROUND\n",
673c0bfa109SKirk McKusick snapname);
674c0bfa109SKirk McKusick return (0);
675c0bfa109SKirk McKusick }
676c0bfa109SKirk McKusick /* Create the snapshot file */
677c0bfa109SKirk McKusick iov = NULL;
678c0bfa109SKirk McKusick iovlen = 0;
679c0bfa109SKirk McKusick errmsg[0] = '\0';
680c0bfa109SKirk McKusick snprintf(snapname, sizeof snapname, "%s/.snap/fsck_snapshot",
681c0bfa109SKirk McKusick mntp->f_mntonname);
682c0bfa109SKirk McKusick build_iovec(&iov, &iovlen, "fstype", "ffs", 4);
683c0bfa109SKirk McKusick build_iovec(&iov, &iovlen, "from", snapname, (size_t)-1);
684c0bfa109SKirk McKusick build_iovec(&iov, &iovlen, "fspath", mntp->f_mntonname, (size_t)-1);
685c0bfa109SKirk McKusick build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg));
686c0bfa109SKirk McKusick build_iovec(&iov, &iovlen, "update", NULL, 0);
687c0bfa109SKirk McKusick build_iovec(&iov, &iovlen, "snapshot", NULL, 0);
688299fcf40SGordon Bergling /* Create snapshot, removing old snapshot if it exists */
689c0bfa109SKirk McKusick while (nmount(iov, iovlen, mntp->f_flags) < 0) {
690c0bfa109SKirk McKusick if (errno == EEXIST && unlink(snapname) == 0)
691c0bfa109SKirk McKusick continue;
692c0bfa109SKirk McKusick pwarn("CANNOT CREATE SNAPSHOT %s: %s %s\n", snapname,
693c0bfa109SKirk McKusick strerror(errno), errmsg);
694c0bfa109SKirk McKusick return (0);
695c0bfa109SKirk McKusick }
696c0bfa109SKirk McKusick /* Open snapshot */
697c0bfa109SKirk McKusick if (openfilesys(snapname) == 0) {
698c0bfa109SKirk McKusick unlink(snapname);
699c0bfa109SKirk McKusick pwarn("CANNOT OPEN SNAPSHOT %s: %s, CANNOT RUN IN "
700c0bfa109SKirk McKusick "BACKGROUND\n", snapname, strerror(errno));
701c0bfa109SKirk McKusick return (0);
702c0bfa109SKirk McKusick }
703*d3a36e4bSKirk McKusick /* Immediately unlink snapshot so that it will be deleted when closed */
704*d3a36e4bSKirk McKusick unlink(snapname);
705c0bfa109SKirk McKusick free(sblock.fs_csp);
706c0bfa109SKirk McKusick free(sblock.fs_si);
7074b08a62eSKirk McKusick if (readsb() == 0) {
7084b08a62eSKirk McKusick pwarn("CANNOT READ SNAPSHOT SUPERBLOCK\n");
7094b08a62eSKirk McKusick return (0);
7104b08a62eSKirk McKusick }
711c0bfa109SKirk McKusick *filesys = snapname;
712c0bfa109SKirk McKusick cmd.version = FFS_CMD_VERSION;
713c0bfa109SKirk McKusick cmd.handle = fsreadfd;
714c0bfa109SKirk McKusick return (1);
715c0bfa109SKirk McKusick }
716c0bfa109SKirk McKusick
7179ea6f4f0SAdrian Chadd static void
usage(void)718b70cd7eeSWarner Losh usage(void)
7199ea6f4f0SAdrian Chadd {
7209ea6f4f0SAdrian Chadd (void) fprintf(stderr,
721db83b143SRenato Botelho "usage: %s [-BCdEFfnpRrSyZ] [-b block] [-c level] [-m mode] filesystem ...\n",
7228e2e167cSMark Murray getprogname());
7239ea6f4f0SAdrian Chadd exit(1);
7249ea6f4f0SAdrian Chadd }
7257703a6ffSScott Long
7267703a6ffSScott Long void
infohandler(int sig __unused)7277703a6ffSScott Long infohandler(int sig __unused)
7287703a6ffSScott Long {
7297703a6ffSScott Long got_siginfo = 1;
7307703a6ffSScott Long }
7317703a6ffSScott Long
7327703a6ffSScott Long void
alarmhandler(int sig __unused)7337703a6ffSScott Long alarmhandler(int sig __unused)
7347703a6ffSScott Long {
7357703a6ffSScott Long got_sigalarm = 1;
7367703a6ffSScott Long }
737