1219019Sgabor/*
2219019Sgabor * Copyright (c) 1980, 1986, 1993
3219019Sgabor *	The Regents of the University of California.  All rights reserved.
4219019Sgabor *
5219019Sgabor * Redistribution and use in source and binary forms, with or without
6219019Sgabor * modification, are permitted provided that the following conditions
7219019Sgabor * are met:
8219019Sgabor * 1. Redistributions of source code must retain the above copyright
9219019Sgabor *    notice, this list of conditions and the following disclaimer.
10219019Sgabor * 2. Redistributions in binary form must reproduce the above copyright
11219019Sgabor *    notice, this list of conditions and the following disclaimer in the
12219019Sgabor *    documentation and/or other materials provided with the distribution.
13219019Sgabor * 4. Neither the name of the University nor the names of its contributors
14219019Sgabor *    may be used to endorse or promote products derived from this software
15219019Sgabor *    without specific prior written permission.
16219019Sgabor *
17219019Sgabor * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18219019Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19219019Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20219019Sgabor * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21219019Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22219019Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23219019Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24219019Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25219019Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26219019Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27219019Sgabor * SUCH DAMAGE.
28219019Sgabor */
29219019Sgabor
30219019Sgabor#if 0
31219019Sgabor#ifndef lint
32219019Sgaborstatic const char copyright[] =
33219019Sgabor"@(#) Copyright (c) 1980, 1986, 1993\n\
34219019Sgabor	The Regents of the University of California.  All rights reserved.\n";
35219019Sgabor#endif /* not lint */
36219019Sgabor
37219019Sgabor#ifndef lint
38219019Sgaborstatic char sccsid[] = "@(#)main.c	8.6 (Berkeley) 5/14/95";
39219019Sgabor#endif /* not lint */
40219019Sgabor#endif
41219019Sgabor#include <sys/cdefs.h>
42219019Sgabor__FBSDID("$FreeBSD: stable/10/sbin/fsck_ffs/globs.c 307536 2016-10-17 22:34:41Z mckusick $");
43219019Sgabor
44219019Sgabor#include <sys/param.h>
45219019Sgabor#include <ufs/ufs/dinode.h>
46219019Sgabor#include <ufs/ffs/fs.h>
47219019Sgabor#include <string.h>
48219019Sgabor#include "fsck.h"
49219019Sgabor
50219019Sgaborlong readcnt[BT_NUMBUFTYPES];
51219019Sgaborlong totalreadcnt[BT_NUMBUFTYPES];
52219019Sgaborstruct timespec readtime[BT_NUMBUFTYPES];
53219019Sgaborstruct timespec totalreadtime[BT_NUMBUFTYPES];
54219019Sgaborstruct timespec startprog;
55219019Sgaborstruct bufarea sblk;		/* file system superblock */
56219019Sgaborstruct bufarea *pdirbp;		/* current directory contents */
57219019Sgaborstruct bufarea *pbp;		/* current inode block */
58219019Sgaborino_t cursnapshot;
59219019Sgaborlong numdirs, dirhash, listmax, inplast;
60219019Sgaborlong countdirs;		/* number of directories we actually found */
61219019Sgaborint	adjrefcnt[MIBSIZE];	/* MIB command to adjust inode reference cnt */
62219019Sgaborint	adjblkcnt[MIBSIZE];	/* MIB command to adjust inode block count */
63219019Sgaborint	adjndir[MIBSIZE];	/* MIB command to adjust number of directories */
64219019Sgaborint	adjnbfree[MIBSIZE];	/* MIB command to adjust number of free blocks */
65219019Sgaborint	adjnifree[MIBSIZE];	/* MIB command to adjust number of free inodes */
66219019Sgaborint	adjnffree[MIBSIZE];	/* MIB command to adjust number of free frags */
67219019Sgaborint	adjnumclusters[MIBSIZE];	/* MIB command to adjust number of free clusters */
68219019Sgaborint	freefiles[MIBSIZE];	/* MIB command to free a set of files */
69219019Sgaborint	freedirs[MIBSIZE];	/* MIB command to free a set of directories */
70219019Sgaborint	freeblks[MIBSIZE];	/* MIB command to free a set of data blocks */
71219019Sgaborstruct	fsck_cmd cmd;		/* sysctl file system update commands */
72219019Sgaborchar	snapname[BUFSIZ];	/* when doing snapshots, the name of the file */
73219019Sgaborchar	*cdevname;		/* name of device being checked */
74219019Sgaborlong	dev_bsize;		/* computed value of DEV_BSIZE */
75219019Sgaborlong	secsize;		/* actual disk sector size */
76219019Sgaboru_int	real_dev_bsize;		/* actual disk sector size, not overridden */
77219019Sgaborchar	nflag;			/* assume a no response */
78219019Sgaborchar	yflag;			/* assume a yes response */
79219019Sgaborint	bkgrdflag;		/* use a snapshot to run on an active system */
80219019Sgaborufs2_daddr_t bflag;		/* location of alternate super block */
81219019Sgaborint	debug;			/* output debugging info */
82219019Sgaborint	Eflag;			/* delete empty data blocks */
83219019Sgaborint	Zflag;			/* zero empty data blocks */
84219019Sgaborint	inoopt;			/* trim out unused inodes */
85219019Sgaborchar	ckclean;		/* only do work if not cleanly unmounted */
86219019Sgaborint	cvtlevel;		/* convert to newer file system format */
87219019Sgaborint	bkgrdcheck;		/* determine if background check is possible */
88219019Sgaborint	bkgrdsumadj;		/* whether the kernel have ability to adjust superblock summary */
89219019Sgaborchar	usedsoftdep;		/* just fix soft dependency inconsistencies */
90219019Sgaborchar	preen;			/* just fix normal inconsistencies */
91219019Sgaborchar	rerun;			/* rerun fsck. Only used in non-preen mode */
92219019Sgaborint	returntosingle;		/* 1 => return to single user mode on exit */
93219019Sgaborchar	resolved;		/* cleared if unresolved changes => not clean */
94219019Sgaborchar	havesb;			/* superblock has been read */
95219019Sgaborchar	skipclean;		/* skip clean file systems if preening */
96219019Sgaborint	fsmodified;		/* 1 => write done to file system */
97219019Sgaborint	fsreadfd;		/* file descriptor for reading file system */
98219019Sgaborint	fswritefd;		/* file descriptor for writing file system */
99219019Sgaborint	surrender;		/* Give up if reads fail */
100219019Sgaborint	wantrestart;		/* Restart fsck on early termination */
101219019Sgaborufs2_daddr_t maxfsblock;	/* number of blocks in the file system */
102219019Sgaborchar	*blockmap;		/* ptr to primary blk allocation map */
103219019Sgaborino_t	maxino;			/* number of inodes in file system */
104219019Sgaborino_t	lfdir;			/* lost & found directory inode number */
105219019Sgaborconst char *lfname;		/* lost & found directory name */
106219019Sgaborint	lfmode;			/* lost & found directory creation mode */
107219019Sgaborufs2_daddr_t n_blks;		/* number of blocks in use */
108219019Sgaborino_t n_files;			/* number of files in use */
109219019Sgaborvolatile sig_atomic_t	got_siginfo;	/* received a SIGINFO */
110219019Sgaborvolatile sig_atomic_t	got_sigalarm;	/* received a SIGALRM */
111219019Sgaborstruct	ufs1_dinode ufs1_zino;
112219019Sgaborstruct	ufs2_dinode ufs2_zino;
113219019Sgabor
114219019Sgaborvoid
115219019Sgaborfsckinit(void)
116219019Sgabor{
117219019Sgabor	bzero(readcnt, sizeof(long) * BT_NUMBUFTYPES);
118219019Sgabor	bzero(totalreadcnt, sizeof(long) * BT_NUMBUFTYPES);
119219019Sgabor	bzero(readtime, sizeof(struct timespec) * BT_NUMBUFTYPES);
120219019Sgabor	bzero(totalreadtime, sizeof(struct timespec) * BT_NUMBUFTYPES);
121219019Sgabor	bzero(&startprog, sizeof(struct timespec));;
122219019Sgabor	bzero(&sblk, sizeof(struct bufarea));
123219019Sgabor	pdirbp = NULL;
124219019Sgabor	pbp = NULL;
125219019Sgabor	cursnapshot = 0;
126219019Sgabor	numdirs = dirhash = listmax = inplast = 0;
127219019Sgabor	countdirs = 0;
128219019Sgabor	bzero(adjrefcnt, sizeof(int) * MIBSIZE);
129219019Sgabor	bzero(adjblkcnt, sizeof(int) * MIBSIZE);
130219019Sgabor	bzero(adjndir, sizeof(int) * MIBSIZE);
131219019Sgabor	bzero(adjnbfree, sizeof(int) * MIBSIZE);
132219019Sgabor	bzero(adjnifree, sizeof(int) * MIBSIZE);
133219019Sgabor	bzero(adjnffree, sizeof(int) * MIBSIZE);
134219019Sgabor	bzero(adjnumclusters, sizeof(int) * MIBSIZE);
135219019Sgabor	bzero(freefiles, sizeof(int) * MIBSIZE);
136219019Sgabor	bzero(freedirs, sizeof(int) * MIBSIZE);
137219019Sgabor	bzero(freeblks, sizeof(int) * MIBSIZE);
138219019Sgabor	bzero(&cmd, sizeof(struct fsck_cmd));
139219019Sgabor	bzero(snapname, sizeof(char) * BUFSIZ);
140219019Sgabor	cdevname = NULL;
141219019Sgabor	dev_bsize = 0;
142219019Sgabor	secsize = 0;
143219019Sgabor	real_dev_bsize = 0;
144219019Sgabor	bkgrdsumadj = 0;
145219019Sgabor	usedsoftdep = 0;
146219019Sgabor	rerun = 0;
147219019Sgabor	returntosingle = 0;
148219019Sgabor	resolved = 0;
149219019Sgabor	havesb = 0;
150219019Sgabor	fsmodified = 0;
151219019Sgabor	fsreadfd = 0;
152219019Sgabor	fswritefd = 0;
153219019Sgabor	maxfsblock = 0;
154219019Sgabor	blockmap = NULL;
155219019Sgabor	maxino = 0;
156219019Sgabor	lfdir = 0;
157219019Sgabor	lfname = "lost+found";
158219019Sgabor	lfmode = 0700;
159260264Sdim	n_blks = 0;
160219019Sgabor	n_files = 0;
161219019Sgabor	got_siginfo = 0;
162219019Sgabor	got_sigalarm = 0;
163219019Sgabor	bzero(&ufs1_zino, sizeof(struct ufs1_dinode));
164219019Sgabor	bzero(&ufs2_zino, sizeof(struct ufs2_dinode));
165219019Sgabor}
166219019Sgabor