2023-07-04 23:40:53 +03:00
|
|
|
/* $NetBSD: main.c,v 1.92 2023/07/04 20:40:53 riastradh Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 22:57:30 +04:00
|
|
|
* Copyright (c) 1980, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 14:04:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-09-14 18:36:29 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
2008-07-20 05:20:21 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1993\
|
|
|
|
The Regents of the University of California. All rights reserved.");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-03-18 17:54:19 +03:00
|
|
|
#if 0
|
1997-09-16 20:44:43 +04:00
|
|
|
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95";
|
1995-03-18 17:54:19 +03:00
|
|
|
#else
|
2023-07-04 23:40:53 +03:00
|
|
|
__RCSID("$NetBSD: main.c,v 1.92 2023/07/04 20:40:53 riastradh Exp $");
|
1995-03-18 17:54:19 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1994-04-25 22:23:19 +04:00
|
|
|
#include <sys/time.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <sys/mount.h>
|
1997-11-02 04:42:44 +03:00
|
|
|
#include <sys/resource.h>
|
1997-09-16 20:44:43 +04:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <ufs/ufs/dinode.h>
|
1998-03-01 05:20:01 +03:00
|
|
|
#include <ufs/ufs/ufsmount.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <ufs/ffs/fs.h>
|
1998-03-18 20:01:23 +03:00
|
|
|
#include <ufs/ffs/ffs_extern.h>
|
1997-09-16 20:44:43 +04:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
2008-08-30 18:07:32 +04:00
|
|
|
#include <errno.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <fstab.h>
|
|
|
|
#include <string.h>
|
1998-04-01 19:55:43 +04:00
|
|
|
#include <time.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <stdio.h>
|
1997-09-20 10:16:23 +04:00
|
|
|
#include <stdlib.h>
|
1994-12-05 23:15:31 +03:00
|
|
|
#include <unistd.h>
|
2007-02-09 00:36:58 +03:00
|
|
|
#include <signal.h>
|
1994-12-05 23:15:31 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "fsck.h"
|
1994-12-05 23:15:31 +03:00
|
|
|
#include "extern.h"
|
1996-09-28 02:45:10 +04:00
|
|
|
#include "fsutil.h"
|
2008-02-24 00:41:47 +03:00
|
|
|
#include "exitvalues.h"
|
2008-08-30 14:46:16 +04:00
|
|
|
#include "snapshot.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-04-05 18:25:39 +03:00
|
|
|
struct bufarea bufhead;
|
|
|
|
struct bufarea sblk;
|
|
|
|
struct bufarea asblk;
|
|
|
|
struct bufarea cgblk;
|
|
|
|
struct bufarea appleufsblk;
|
|
|
|
struct bufarea *pdirbp;
|
|
|
|
struct bufarea *pbp;
|
|
|
|
struct fs *sblock;
|
|
|
|
struct fs *altsblock;
|
|
|
|
struct cg *cgrp;
|
|
|
|
struct fs *sblocksave;
|
|
|
|
struct dups *duplist;
|
|
|
|
struct dups *muldup;
|
|
|
|
struct zlncnt *zlnhead;
|
|
|
|
struct inoinfo **inphead, **inpsort;
|
|
|
|
long numdirs, dirhash, listmax, inplast;
|
|
|
|
struct uquot_hash *uquot_user_hash;
|
|
|
|
struct uquot_hash *uquot_group_hash;
|
|
|
|
uint8_t q2h_hash_shift;
|
|
|
|
uint16_t q2h_hash_mask;
|
|
|
|
struct inostatlist *inostathead;
|
|
|
|
long dev_bsize;
|
|
|
|
long secsize;
|
|
|
|
char nflag;
|
|
|
|
char yflag;
|
|
|
|
int Uflag;
|
|
|
|
int bflag;
|
|
|
|
int debug;
|
|
|
|
int zflag;
|
|
|
|
int cvtlevel;
|
|
|
|
int doinglevel1;
|
|
|
|
int doinglevel2;
|
2022-11-17 09:40:38 +03:00
|
|
|
int doing2ea;
|
|
|
|
int doing2noea;
|
2020-04-05 18:25:39 +03:00
|
|
|
int newinofmt;
|
|
|
|
char usedsoftdep;
|
|
|
|
int preen;
|
|
|
|
int forceimage;
|
|
|
|
int is_ufs2;
|
2022-11-17 09:40:38 +03:00
|
|
|
int is_ufs2ea;
|
2020-04-05 18:25:39 +03:00
|
|
|
int markclean;
|
|
|
|
char havesb;
|
|
|
|
char skipclean;
|
|
|
|
int fsmodified;
|
|
|
|
int fsreadfd;
|
|
|
|
int fswritefd;
|
|
|
|
int rerun;
|
|
|
|
char resolved;
|
2020-04-06 09:41:34 +03:00
|
|
|
#ifndef NO_FFS_EI
|
2020-04-05 18:25:39 +03:00
|
|
|
int endian;
|
|
|
|
int doswap;
|
|
|
|
int needswap;
|
|
|
|
int do_blkswap;
|
|
|
|
int do_dirswap;
|
2020-04-06 12:54:24 +03:00
|
|
|
#endif
|
|
|
|
#ifndef NO_APPLE_UFS
|
2020-04-05 18:25:39 +03:00
|
|
|
int isappleufs;
|
2020-04-06 12:54:24 +03:00
|
|
|
#endif
|
2020-04-05 18:25:39 +03:00
|
|
|
daddr_t maxfsblock;
|
|
|
|
char *blockmap;
|
|
|
|
ino_t maxino;
|
|
|
|
int dirblksiz;
|
|
|
|
daddr_t n_blks;
|
|
|
|
ino_t n_files;
|
|
|
|
long countdirs;
|
|
|
|
int got_siginfo;
|
|
|
|
struct ufs1_dinode ufs1_zino;
|
|
|
|
struct ufs2_dinode ufs2_zino;
|
|
|
|
|
2005-01-13 18:22:35 +03:00
|
|
|
int progress = 0;
|
1996-10-22 20:35:04 +04:00
|
|
|
|
2005-06-27 05:25:35 +04:00
|
|
|
static int argtoi(int, const char *, const char *, int);
|
2008-08-30 14:46:16 +04:00
|
|
|
static int checkfilesys(const char *, const char *, int);
|
2011-08-29 18:34:58 +04:00
|
|
|
__dead static void usage(void);
|
1996-10-22 20:35:04 +04:00
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
int
|
2005-01-19 20:33:58 +03:00
|
|
|
main(int argc, char *argv[])
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-11-02 04:42:44 +03:00
|
|
|
struct rlimit r;
|
1993-03-21 12:45:37 +03:00
|
|
|
int ch;
|
2008-02-24 00:41:47 +03:00
|
|
|
int ret = FSCK_EXIT_OK;
|
2008-08-30 14:46:16 +04:00
|
|
|
char *snap_backup = NULL;
|
|
|
|
int snap_internal = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2011-06-09 23:57:50 +04:00
|
|
|
ckfinish = ckfini;
|
|
|
|
|
1997-11-02 04:42:44 +03:00
|
|
|
if (getrlimit(RLIMIT_DATA, &r) == 0) {
|
|
|
|
r.rlim_cur = r.rlim_max;
|
|
|
|
(void) setrlimit(RLIMIT_DATA, &r);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
sync();
|
1995-04-13 01:24:07 +04:00
|
|
|
skipclean = 1;
|
1998-03-18 20:01:23 +03:00
|
|
|
markclean = 1;
|
2001-08-15 07:54:53 +04:00
|
|
|
forceimage = 0;
|
2017-02-08 19:11:39 +03:00
|
|
|
#ifndef NO_FFS_EI
|
1998-03-18 20:01:23 +03:00
|
|
|
endian = 0;
|
2017-02-08 19:11:39 +03:00
|
|
|
#endif
|
|
|
|
#ifndef NO_APPLE_UFS
|
2002-09-29 00:11:05 +04:00
|
|
|
isappleufs = 0;
|
2017-02-08 19:11:39 +03:00
|
|
|
#endif
|
2019-05-05 17:59:06 +03:00
|
|
|
while ((ch = getopt(argc, argv, "aB:b:c:dFfm:npPqUyx:Xz")) != -1) {
|
1993-03-21 12:45:37 +03:00
|
|
|
switch (ch) {
|
2017-02-08 19:11:39 +03:00
|
|
|
#ifndef NO_APPLE_UFS
|
2002-09-29 00:11:05 +04:00
|
|
|
case 'a':
|
|
|
|
isappleufs = 1;
|
|
|
|
break;
|
2017-02-08 19:11:39 +03:00
|
|
|
#endif
|
2002-09-29 00:11:05 +04:00
|
|
|
|
2017-02-08 19:11:39 +03:00
|
|
|
#ifndef NO_FFS_EI
|
1998-03-18 20:01:23 +03:00
|
|
|
case 'B':
|
|
|
|
if (strcmp(optarg, "be") == 0)
|
|
|
|
endian = BIG_ENDIAN;
|
|
|
|
else if (strcmp(optarg, "le") == 0)
|
|
|
|
endian = LITTLE_ENDIAN;
|
2017-02-08 19:11:39 +03:00
|
|
|
else
|
|
|
|
usage();
|
1998-03-18 20:01:23 +03:00
|
|
|
break;
|
2017-02-08 19:11:39 +03:00
|
|
|
#endif
|
1998-03-18 20:01:23 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'b':
|
1995-04-13 01:24:07 +04:00
|
|
|
skipclean = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
bflag = argtoi('b', "number", optarg, 10);
|
|
|
|
printf("Alternate super block location: %d\n", bflag);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
1995-04-13 01:24:07 +04:00
|
|
|
skipclean = 0;
|
2022-11-17 09:40:38 +03:00
|
|
|
if (strcmp(optarg, "ea") == 0) {
|
|
|
|
doing2ea = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strcmp(optarg, "no-ea") == 0) {
|
|
|
|
doing2noea = 1;
|
|
|
|
break;
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
cvtlevel = argtoi('c', "conversion level", optarg, 10);
|
2004-01-18 01:17:07 +03:00
|
|
|
if (cvtlevel > 4) {
|
|
|
|
cvtlevel = 4;
|
2015-06-17 02:58:30 +03:00
|
|
|
warnx("Using maximum conversion level of %d",
|
2008-02-24 00:41:47 +03:00
|
|
|
cvtlevel);
|
2004-01-18 01:17:07 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
2022-11-17 09:40:38 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'd':
|
|
|
|
debug++;
|
|
|
|
break;
|
|
|
|
|
2001-08-15 07:54:53 +04:00
|
|
|
case 'F':
|
|
|
|
forceimage = 1;
|
|
|
|
break;
|
|
|
|
|
implement a 'force check' flag, '-f'. I used the SunOS name, but the Digital
semantics. now:
(1) dirty file systems will always be checked; nothing new there.
(2) if not '-f' clean file systems will _NEVER_ be checked,
i.e. they won't be checked even if -p isn't specified. This
allows one to 'fsck -p ; fsck' to preen, then clean up
anything that 'fsck -p' barfs on, without waiting for the
clean file systems to be checked again.
(3) if '-f' clean file systems will ALWAYS be checked. This
allows people to put 'fsck -fp' into /etc/rc on systems
where they're leery of the FS clean flag state, need
the extra reliability, and can afford time 'wasted'
in checks.
The assumption made here is that if a file system is marked clean, it
_IS CLEAN_, really, and shouldn't be checked unless fsck is explicitly
told to (with -f). This should be a valid assumption, but may not be in
the presence of file system bugs. Documentation updated to note '-f'.
1995-07-12 05:49:16 +04:00
|
|
|
case 'f':
|
|
|
|
skipclean = 0;
|
|
|
|
break;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'm':
|
|
|
|
lfmode = argtoi('m', "mode", optarg, 8);
|
|
|
|
if (lfmode &~ 07777)
|
2008-02-24 00:41:47 +03:00
|
|
|
errx(FSCK_EXIT_USAGE, "bad mode to -m: %o",
|
|
|
|
lfmode);
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("** lost+found creation mode %o\n", lfmode);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
nflag++;
|
|
|
|
yflag = 0;
|
|
|
|
break;
|
|
|
|
|
1996-10-22 20:35:04 +04:00
|
|
|
case 'p':
|
|
|
|
preen++;
|
|
|
|
break;
|
|
|
|
|
2005-01-13 18:22:35 +03:00
|
|
|
case 'P':
|
|
|
|
progress = 1;
|
|
|
|
break;
|
|
|
|
|
2003-10-20 16:04:38 +04:00
|
|
|
case 'q':
|
|
|
|
quiet++;
|
|
|
|
break;
|
2008-10-09 20:56:23 +04:00
|
|
|
#ifndef SMALL
|
|
|
|
case 'U':
|
|
|
|
Uflag++;
|
|
|
|
break;
|
|
|
|
#endif
|
2003-10-20 16:04:38 +04:00
|
|
|
|
2008-08-30 14:46:16 +04:00
|
|
|
case 'x':
|
|
|
|
snap_backup = optarg;
|
|
|
|
break;
|
2019-05-05 17:59:06 +03:00
|
|
|
|
2008-08-30 14:46:16 +04:00
|
|
|
case 'X':
|
|
|
|
snap_internal = 1;
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2019-05-05 17:59:06 +03:00
|
|
|
case 'y':
|
|
|
|
yflag++;
|
|
|
|
nflag = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'z':
|
|
|
|
zflag++;
|
|
|
|
break;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
1996-10-22 20:35:04 +04:00
|
|
|
usage();
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1996-10-22 20:35:04 +04:00
|
|
|
|
2008-08-30 14:46:16 +04:00
|
|
|
if (snap_backup || snap_internal) {
|
|
|
|
if (!nflag || yflag) {
|
2015-06-17 02:18:54 +03:00
|
|
|
warnx("Cannot use -x or -X without -n");
|
2008-08-30 14:46:16 +04:00
|
|
|
snap_backup = NULL;
|
|
|
|
snap_internal = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
1996-10-22 20:35:04 +04:00
|
|
|
|
|
|
|
if (!argc)
|
|
|
|
usage();
|
|
|
|
|
2005-01-13 18:22:35 +03:00
|
|
|
if (debug)
|
|
|
|
progress = 0;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
|
|
|
|
(void)signal(SIGINT, catch);
|
|
|
|
if (preen)
|
|
|
|
(void)signal(SIGQUIT, catchquit);
|
2005-01-13 22:56:02 +03:00
|
|
|
#ifdef PROGRESS
|
2005-01-13 18:22:35 +03:00
|
|
|
if (progress) {
|
|
|
|
progress_ttywidth(0);
|
|
|
|
(void)signal(SIGWINCH, progress_ttywidth);
|
|
|
|
}
|
2005-01-13 22:56:02 +03:00
|
|
|
#endif /* ! PROGRESS */
|
2002-05-06 07:17:43 +04:00
|
|
|
signal(SIGINFO, infohandler);
|
1996-09-23 20:18:31 +04:00
|
|
|
|
2003-04-02 14:39:19 +04:00
|
|
|
while (argc-- > 0) {
|
2008-08-30 14:46:16 +04:00
|
|
|
int nret;
|
2011-02-06 15:02:59 +03:00
|
|
|
char *path;
|
|
|
|
|
|
|
|
if (!forceimage)
|
|
|
|
path = strdup(blockcheck(*argv));
|
|
|
|
else
|
|
|
|
path = strdup(*argv);
|
2003-04-02 14:39:19 +04:00
|
|
|
|
|
|
|
if (path == NULL)
|
|
|
|
pfatal("Can't check %s\n", *argv);
|
2023-07-04 23:40:53 +03:00
|
|
|
|
2008-08-30 14:46:16 +04:00
|
|
|
if (snap_backup || snap_internal) {
|
|
|
|
char *snap_dev;
|
|
|
|
int snapfd;
|
|
|
|
|
2010-04-11 12:23:51 +04:00
|
|
|
snapfd = snap_open(*argv, snap_backup, NULL, &snap_dev);
|
2008-08-30 14:46:16 +04:00
|
|
|
if (snapfd < 0) {
|
2010-04-11 12:23:51 +04:00
|
|
|
warn("can't take snapshot of %s", *argv);
|
2008-08-30 14:46:16 +04:00
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
nret = checkfilesys(blockcheck(snap_dev), path, 0);
|
2008-02-24 00:41:47 +03:00
|
|
|
if (ret < nret)
|
|
|
|
ret = nret;
|
2008-08-30 14:46:16 +04:00
|
|
|
close(snapfd);
|
|
|
|
} else {
|
|
|
|
nret = checkfilesys(path, path, 0);
|
|
|
|
if (ret < nret)
|
|
|
|
ret = nret;
|
|
|
|
}
|
|
|
|
next:
|
|
|
|
free(path);
|
2003-04-02 14:39:19 +04:00
|
|
|
argv++;
|
|
|
|
}
|
1996-09-23 20:18:31 +04:00
|
|
|
|
2008-02-24 00:41:47 +03:00
|
|
|
return returntosingle ? FSCK_EXIT_UNRESOLVED : ret;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-10-22 20:35:04 +04:00
|
|
|
static int
|
2005-06-27 05:25:35 +04:00
|
|
|
argtoi(int flag, const char *req, const char *str, int base)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = (int)strtol(str, &cp, base);
|
|
|
|
if (cp == str || *cp)
|
2008-02-24 00:41:47 +03:00
|
|
|
errx(FSCK_EXIT_USAGE, "-%c flag requires a %s",
|
|
|
|
flag, req);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the specified filesystem.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
1996-10-22 20:35:04 +04:00
|
|
|
static int
|
2008-08-30 14:46:16 +04:00
|
|
|
checkfilesys(const char *filesys, const char *origfs, int child)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-25 00:55:02 +03:00
|
|
|
daddr_t n_ffree, n_bfree;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct dups *dp;
|
|
|
|
struct zlncnt *zlnp;
|
2023-01-07 22:41:29 +03:00
|
|
|
uint32_t cylno;
|
1997-09-24 13:24:21 +04:00
|
|
|
#ifdef LITE2BORKEN
|
2001-01-26 20:37:16 +03:00
|
|
|
int flags;
|
1997-09-24 13:24:21 +04:00
|
|
|
#endif
|
2005-01-13 22:56:02 +03:00
|
|
|
#ifdef PROGRESS
|
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
2006-11-15 00:01:46 +03:00
|
|
|
/*
|
|
|
|
* In prune mode, how far does the progress bar travel during
|
|
|
|
* each pass? (In non-prune mode, each pass has a separate
|
|
|
|
* progress bar that travels from 0 to 100%.)
|
|
|
|
*
|
|
|
|
* The numbers below are percentages, intended to correspond
|
|
|
|
* roughly to the cumulative time up to the end of each pass.
|
|
|
|
* They don't have to be accurate. In reality, on a large
|
|
|
|
* file system, Pass 1 and Pass 2 together are likely to use
|
|
|
|
* significantly more than the 95% reflected below, so users
|
|
|
|
* will get a pleasant surprise when the last 5% of the progress
|
|
|
|
* bar runs more quickly than they had expected.
|
|
|
|
*/
|
|
|
|
static int progress_limits[] = {0, 20, 95, 96, 97, 100};
|
2005-01-13 22:56:02 +03:00
|
|
|
#endif /* PROGRESS */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (preen && child)
|
|
|
|
(void)signal(SIGQUIT, voidquit);
|
1996-09-23 20:18:31 +04:00
|
|
|
setcdevname(filesys, preen);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (debug && preen)
|
|
|
|
pwarn("starting\n");
|
2008-08-30 14:46:16 +04:00
|
|
|
switch (setup(filesys, origfs)) {
|
1995-04-13 01:24:07 +04:00
|
|
|
case 0:
|
1993-03-21 12:45:37 +03:00
|
|
|
if (preen)
|
|
|
|
pfatal("CAN'T CHECK FILE SYSTEM.");
|
1997-09-16 20:44:43 +04:00
|
|
|
/* fall through */
|
1995-04-13 01:24:07 +04:00
|
|
|
case -1:
|
2008-02-24 00:41:47 +03:00
|
|
|
return FSCK_EXIT_OK;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1999-11-15 22:18:24 +03:00
|
|
|
/*
|
|
|
|
* Cleared if any questions answered no. Used to decide if
|
|
|
|
* the superblock should be marked clean.
|
|
|
|
*/
|
|
|
|
resolved = 1;
|
2005-01-13 18:22:35 +03:00
|
|
|
|
2005-01-13 22:56:02 +03:00
|
|
|
#ifdef PROGRESS
|
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
2006-11-15 00:01:46 +03:00
|
|
|
progress_switch(progress);
|
|
|
|
progress_init();
|
2005-01-13 22:56:02 +03:00
|
|
|
#endif /* PROGRESS */
|
2005-01-13 18:22:35 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 22:57:30 +04:00
|
|
|
* 1: scan inodes tallying blocks used
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-06-08 22:57:30 +04:00
|
|
|
if (preen == 0) {
|
2003-10-20 16:04:38 +04:00
|
|
|
pwarn("** Last Mounted on %s\n", sblock->fs_fsmnt);
|
1996-09-23 20:18:31 +04:00
|
|
|
if (hotroot())
|
2003-10-20 16:04:38 +04:00
|
|
|
pwarn("** Root file system\n");
|
|
|
|
pwarn("** Phase 1 - Check Blocks and Sizes\n");
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
2005-01-13 22:56:02 +03:00
|
|
|
#ifdef PROGRESS
|
2005-01-13 18:22:35 +03:00
|
|
|
if (preen)
|
2006-11-15 01:51:11 +03:00
|
|
|
progress_setrange(0, progress_limits[1]);
|
2005-01-13 22:56:02 +03:00
|
|
|
#endif /* PROGRESS */
|
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
2006-11-15 00:01:46 +03:00
|
|
|
pass1();
|
2005-01-13 18:22:35 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
/*
|
|
|
|
* 1b: locate first references to duplicates, if any
|
|
|
|
*/
|
|
|
|
if (duplist) {
|
2000-12-13 06:04:51 +03:00
|
|
|
if (preen)
|
|
|
|
pfatal("INTERNAL ERROR: dups with -p\n");
|
|
|
|
if (usedsoftdep)
|
|
|
|
pfatal("INTERNAL ERROR: dups with softdep\n");
|
2003-10-20 16:04:38 +04:00
|
|
|
pwarn("** Phase 1b - Rescan For More DUPS\n");
|
1994-06-08 22:57:30 +04:00
|
|
|
pass1b();
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
/*
|
|
|
|
* 2: traverse directories from root to mark all connected directories
|
|
|
|
*/
|
|
|
|
if (preen == 0)
|
2003-10-20 16:04:38 +04:00
|
|
|
pwarn("** Phase 2 - Check Pathnames\n");
|
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
2006-11-15 00:01:46 +03:00
|
|
|
#ifdef PROGRESS
|
|
|
|
if (preen)
|
|
|
|
progress_sethighlim(progress_limits[2]);
|
|
|
|
#endif /* PROGRESS */
|
1994-06-08 22:57:30 +04:00
|
|
|
pass2();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
/*
|
|
|
|
* 3: scan inodes looking for disconnected directories
|
|
|
|
*/
|
|
|
|
if (preen == 0)
|
2003-10-20 16:04:38 +04:00
|
|
|
pwarn("** Phase 3 - Check Connectivity\n");
|
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
2006-11-15 00:01:46 +03:00
|
|
|
#ifdef PROGRESS
|
|
|
|
if (preen)
|
|
|
|
progress_sethighlim(progress_limits[3]);
|
|
|
|
#endif /* PROGRESS */
|
1994-06-08 22:57:30 +04:00
|
|
|
pass3();
|
1993-10-01 04:45:30 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
/*
|
|
|
|
* 4: scan inodes looking for disconnected files; check reference counts
|
|
|
|
*/
|
|
|
|
if (preen == 0)
|
2003-10-20 16:04:38 +04:00
|
|
|
pwarn("** Phase 4 - Check Reference Counts\n");
|
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
2006-11-15 00:01:46 +03:00
|
|
|
#ifdef PROGRESS
|
|
|
|
if (preen)
|
|
|
|
progress_sethighlim(progress_limits[4]);
|
|
|
|
#endif /* PROGRESS */
|
1994-06-08 22:57:30 +04:00
|
|
|
pass4();
|
1993-10-01 04:45:30 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
/*
|
|
|
|
* 5: check and repair resource counts in cylinder groups
|
|
|
|
*/
|
|
|
|
if (preen == 0)
|
2003-10-20 16:04:38 +04:00
|
|
|
pwarn("** Phase 5 - Check Cyl groups\n");
|
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
2006-11-15 00:01:46 +03:00
|
|
|
#ifdef PROGRESS
|
|
|
|
if (preen)
|
|
|
|
progress_sethighlim(progress_limits[5]);
|
|
|
|
#endif /* PROGRESS */
|
1994-06-08 22:57:30 +04:00
|
|
|
pass5();
|
2011-03-06 20:08:10 +03:00
|
|
|
if (uquot_user_hash != NULL) {
|
|
|
|
if (preen == 0)
|
|
|
|
pwarn("** Phase 6 - Check Quotas\n");
|
|
|
|
pass6();
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* print out summary statistics
|
|
|
|
*/
|
1998-03-18 20:01:23 +03:00
|
|
|
n_ffree = sblock->fs_cstotal.cs_nffree;
|
|
|
|
n_bfree = sblock->fs_cstotal.cs_nbfree;
|
2005-08-19 06:07:18 +04:00
|
|
|
pwarn("%llu files, %lld used, %lld free ",
|
|
|
|
(unsigned long long)n_files, (long long)n_blks,
|
2003-01-28 08:17:12 +03:00
|
|
|
(long long)(n_ffree + sblock->fs_frag * n_bfree));
|
2003-01-25 00:55:02 +03:00
|
|
|
printf("(%lld frags, %lld blocks, %lld.%lld%% fragmentation)\n",
|
|
|
|
(long long)n_ffree, (long long)n_bfree,
|
2003-01-28 08:17:12 +03:00
|
|
|
(long long)(n_ffree * 100 / (daddr_t)sblock->fs_dsize),
|
|
|
|
(long long)(((n_ffree * 1000 + (daddr_t)sblock->fs_dsize / 2)
|
|
|
|
/ (daddr_t)sblock->fs_dsize) % 10));
|
1993-03-21 12:45:37 +03:00
|
|
|
if (debug &&
|
2013-01-22 13:39:11 +04:00
|
|
|
(n_files -= maxino - UFS_ROOTINO - sblock->fs_cstotal.cs_nifree))
|
2005-08-19 06:07:18 +04:00
|
|
|
printf("%llu files missing\n", (unsigned long long)n_files);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (debug) {
|
1998-03-18 20:01:23 +03:00
|
|
|
n_blks += sblock->fs_ncg *
|
|
|
|
(cgdmin(sblock, 0) - cgsblock(sblock, 0));
|
|
|
|
n_blks += cgsblock(sblock, 0) - cgbase(sblock, 0);
|
|
|
|
n_blks += howmany(sblock->fs_cssize, sblock->fs_fsize);
|
|
|
|
if (n_blks -= maxfsblock - (n_ffree + sblock->fs_frag * n_bfree))
|
2003-01-25 00:55:02 +03:00
|
|
|
printf("%lld blocks missing\n", (long long)n_blks);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (duplist != NULL) {
|
|
|
|
printf("The following duplicate blocks remain:");
|
|
|
|
for (dp = duplist; dp; dp = dp->next)
|
2003-01-25 00:55:02 +03:00
|
|
|
printf(" %lld,", (long long)dp->dup);
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
if (zlnhead != NULL) {
|
|
|
|
printf("The following zero link count inodes remain:");
|
|
|
|
for (zlnp = zlnhead; zlnp; zlnp = zlnp->next)
|
2005-08-19 06:07:18 +04:00
|
|
|
printf(" %llu,",
|
|
|
|
(unsigned long long)zlnp->zlncnt);
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zlnhead = (struct zlncnt *)0;
|
|
|
|
duplist = (struct dups *)0;
|
1994-06-08 22:57:30 +04:00
|
|
|
muldup = (struct dups *)0;
|
1993-03-21 12:45:37 +03:00
|
|
|
inocleanup();
|
|
|
|
if (fsmodified) {
|
2003-04-02 14:39:19 +04:00
|
|
|
sblock->fs_time = time(NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
sbdirty();
|
|
|
|
}
|
1999-11-15 22:18:24 +03:00
|
|
|
if (rerun)
|
|
|
|
markclean = 0;
|
1997-09-24 13:24:21 +04:00
|
|
|
#if LITE2BORKEN
|
1997-09-16 20:44:43 +04:00
|
|
|
if (!hotroot()) {
|
2011-06-09 23:57:50 +04:00
|
|
|
ckfini(1);
|
1997-09-16 20:44:43 +04:00
|
|
|
} else {
|
2004-04-21 05:05:31 +04:00
|
|
|
struct statvfs stfs_buf;
|
1997-09-16 20:44:43 +04:00
|
|
|
/*
|
|
|
|
* Check to see if root is mounted read-write.
|
|
|
|
*/
|
2004-04-21 05:05:31 +04:00
|
|
|
if (statvfs("/", &stfs_buf) == 0)
|
|
|
|
flags = stfs_buf.f_flag;
|
1997-09-16 20:44:43 +04:00
|
|
|
else
|
|
|
|
flags = 0;
|
1998-03-18 20:01:23 +03:00
|
|
|
if (markclean)
|
|
|
|
markclean = flags & MNT_RDONLY;
|
2011-06-09 23:57:50 +04:00
|
|
|
ckfini(1);
|
1997-09-16 20:44:43 +04:00
|
|
|
}
|
1997-09-24 13:24:21 +04:00
|
|
|
#else
|
2011-06-09 23:57:50 +04:00
|
|
|
ckfini(1);
|
1997-09-24 13:24:21 +04:00
|
|
|
#endif
|
2003-04-02 14:39:19 +04:00
|
|
|
for (cylno = 0; cylno < sblock->fs_ncg; cylno++)
|
|
|
|
if (inostathead[cylno].il_stat != NULL)
|
|
|
|
free(inostathead[cylno].il_stat);
|
|
|
|
free(inostathead);
|
|
|
|
inostathead = NULL;
|
|
|
|
|
2004-10-11 19:24:09 +04:00
|
|
|
if (!resolved || rerun) {
|
|
|
|
pwarn("\n***** UNRESOLVED INCONSISTENCIES REMAIN *****\n");
|
|
|
|
returntosingle = 1;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!fsmodified)
|
2008-02-24 00:41:47 +03:00
|
|
|
return FSCK_EXIT_OK;
|
1994-06-08 22:57:30 +04:00
|
|
|
if (!preen)
|
2003-10-20 16:04:38 +04:00
|
|
|
pwarn("\n***** FILE SYSTEM WAS MODIFIED *****\n");
|
1996-10-12 00:15:46 +04:00
|
|
|
if (rerun)
|
2003-10-20 16:04:38 +04:00
|
|
|
pwarn("\n***** PLEASE RERUN FSCK *****\n");
|
1996-09-23 20:18:31 +04:00
|
|
|
if (hotroot()) {
|
2004-04-21 05:05:31 +04:00
|
|
|
struct statvfs stfs_buf;
|
1994-06-08 22:57:30 +04:00
|
|
|
/*
|
|
|
|
* We modified the root. Do a mount update on
|
|
|
|
* it, unless it is read-write, so we can continue.
|
|
|
|
*/
|
2004-04-21 05:05:31 +04:00
|
|
|
if (statvfs("/", &stfs_buf) == 0) {
|
|
|
|
long flags = stfs_buf.f_flag;
|
1994-06-08 22:57:30 +04:00
|
|
|
struct ufs_args args;
|
|
|
|
|
|
|
|
if (flags & MNT_RDONLY) {
|
|
|
|
args.fspec = 0;
|
|
|
|
flags |= MNT_UPDATE | MNT_RELOAD;
|
2008-02-24 00:41:47 +03:00
|
|
|
if (mount(MOUNT_FFS, "/", flags,
|
|
|
|
&args, sizeof args) == 0)
|
|
|
|
return FSCK_EXIT_OK;
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!preen)
|
2003-10-20 16:04:38 +04:00
|
|
|
pwarn("\n***** REBOOT NOW *****\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
sync();
|
2008-02-24 00:41:47 +03:00
|
|
|
return FSCK_EXIT_ROOT_CHANGED;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2008-02-24 00:41:47 +03:00
|
|
|
return FSCK_EXIT_OK;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-10-22 20:35:04 +04:00
|
|
|
|
|
|
|
static void
|
2005-01-19 20:33:58 +03:00
|
|
|
usage(void)
|
1996-10-22 20:35:04 +04:00
|
|
|
{
|
2001-02-20 01:48:57 +03:00
|
|
|
|
1996-10-22 20:35:04 +04:00
|
|
|
(void) fprintf(stderr,
|
2017-02-08 19:11:39 +03:00
|
|
|
"usage: %s [-"
|
|
|
|
#ifndef NO_APPLE_UFS
|
|
|
|
"a"
|
|
|
|
#endif
|
|
|
|
"dFfPpqUX] "
|
|
|
|
#ifndef NO_FFS_EI
|
|
|
|
"[-B byteorder] "
|
|
|
|
#endif
|
|
|
|
"[-b block] [-c level] [-m mode]\n"
|
2008-10-13 00:49:43 +04:00
|
|
|
"\t[-x snap-backup] [-y | -n] filesystem ...\n",
|
2001-02-20 01:48:57 +03:00
|
|
|
getprogname());
|
2008-02-24 00:41:47 +03:00
|
|
|
exit(FSCK_EXIT_USAGE);
|
1996-10-22 20:35:04 +04:00
|
|
|
}
|