xref: /freebsd/sbin/fsck_ffs/globs.c (revision 3416500aef140042c64bc149cb1ec6620483bc44)
1 /*
2  * Copyright (c) 1980, 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #if 0
31 #ifndef lint
32 static const char copyright[] =
33 "@(#) Copyright (c) 1980, 1986, 1993\n\
34 	The Regents of the University of California.  All rights reserved.\n";
35 #endif /* not lint */
36 
37 #ifndef lint
38 static char sccsid[] = "@(#)main.c	8.6 (Berkeley) 5/14/95";
39 #endif /* not lint */
40 #endif
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
43 
44 #include <sys/param.h>
45 #include <ufs/ufs/dinode.h>
46 #include <ufs/ffs/fs.h>
47 #include <string.h>
48 #include "fsck.h"
49 
50 long readcnt[BT_NUMBUFTYPES];
51 long totalreadcnt[BT_NUMBUFTYPES];
52 struct timespec readtime[BT_NUMBUFTYPES];
53 struct timespec totalreadtime[BT_NUMBUFTYPES];
54 struct timespec startprog;
55 struct bufarea sblk;		/* file system superblock */
56 struct bufarea *pdirbp;		/* current directory contents */
57 struct bufarea *pbp;		/* current inode block */
58 ino_t cursnapshot;
59 long  dirhash, inplast;
60 unsigned long  numdirs, listmax;
61 long countdirs;		/* number of directories we actually found */
62 int	adjrefcnt[MIBSIZE];	/* MIB command to adjust inode reference cnt */
63 int	adjblkcnt[MIBSIZE];	/* MIB command to adjust inode block count */
64 int	adjndir[MIBSIZE];	/* MIB command to adjust number of directories */
65 int	adjnbfree[MIBSIZE];	/* MIB command to adjust number of free blocks */
66 int	adjnifree[MIBSIZE];	/* MIB command to adjust number of free inodes */
67 int	adjnffree[MIBSIZE];	/* MIB command to adjust number of free frags */
68 int	adjnumclusters[MIBSIZE];	/* MIB command to adjust number of free clusters */
69 int	freefiles[MIBSIZE];	/* MIB command to free a set of files */
70 int	freedirs[MIBSIZE];	/* MIB command to free a set of directories */
71 int	freeblks[MIBSIZE];	/* MIB command to free a set of data blocks */
72 struct	fsck_cmd cmd;		/* sysctl file system update commands */
73 char	snapname[BUFSIZ];	/* when doing snapshots, the name of the file */
74 char	*cdevname;		/* name of device being checked */
75 long	dev_bsize;		/* computed value of DEV_BSIZE */
76 long	secsize;		/* actual disk sector size */
77 u_int	real_dev_bsize;		/* actual disk sector size, not overridden */
78 char	nflag;			/* assume a no response */
79 char	yflag;			/* assume a yes response */
80 int	bkgrdflag;		/* use a snapshot to run on an active system */
81 ufs2_daddr_t bflag;		/* location of alternate super block */
82 int	debug;			/* output debugging info */
83 int	Eflag;			/* delete empty data blocks */
84 int	Zflag;			/* zero empty data blocks */
85 int	inoopt;			/* trim out unused inodes */
86 char	ckclean;		/* only do work if not cleanly unmounted */
87 int	cvtlevel;		/* convert to newer file system format */
88 int	bkgrdcheck;		/* determine if background check is possible */
89 int	bkgrdsumadj;		/* whether the kernel have ability to adjust superblock summary */
90 char	usedsoftdep;		/* just fix soft dependency inconsistencies */
91 char	preen;			/* just fix normal inconsistencies */
92 char	rerun;			/* rerun fsck. Only used in non-preen mode */
93 int	returntosingle;		/* 1 => return to single user mode on exit */
94 char	resolved;		/* cleared if unresolved changes => not clean */
95 char	havesb;			/* superblock has been read */
96 char	skipclean;		/* skip clean file systems if preening */
97 int	fsmodified;		/* 1 => write done to file system */
98 int	fsreadfd;		/* file descriptor for reading file system */
99 int	fswritefd;		/* file descriptor for writing file system */
100 int	surrender;		/* Give up if reads fail */
101 int	wantrestart;		/* Restart fsck on early termination */
102 ufs2_daddr_t maxfsblock;	/* number of blocks in the file system */
103 char	*blockmap;		/* ptr to primary blk allocation map */
104 ino_t	maxino;			/* number of inodes in file system */
105 ino_t	lfdir;			/* lost & found directory inode number */
106 const char *lfname;		/* lost & found directory name */
107 int	lfmode;			/* lost & found directory creation mode */
108 ufs2_daddr_t n_blks;		/* number of blocks in use */
109 ino_t n_files;			/* number of files in use */
110 volatile sig_atomic_t	got_siginfo;	/* received a SIGINFO */
111 volatile sig_atomic_t	got_sigalarm;	/* received a SIGALRM */
112 struct	ufs1_dinode ufs1_zino;
113 struct	ufs2_dinode ufs2_zino;
114 
115 void
116 fsckinit(void)
117 {
118 	bzero(readcnt, sizeof(long) * BT_NUMBUFTYPES);
119 	bzero(totalreadcnt, sizeof(long) * BT_NUMBUFTYPES);
120 	bzero(readtime, sizeof(struct timespec) * BT_NUMBUFTYPES);
121 	bzero(totalreadtime, sizeof(struct timespec) * BT_NUMBUFTYPES);
122 	bzero(&startprog, sizeof(struct timespec));
123 	bzero(&sblk, sizeof(struct bufarea));
124 	pdirbp = NULL;
125 	pbp = NULL;
126 	cursnapshot = 0;
127 	listmax = numdirs = dirhash = inplast = 0;
128 	countdirs = 0;
129 	bzero(adjrefcnt, sizeof(int) * MIBSIZE);
130 	bzero(adjblkcnt, sizeof(int) * MIBSIZE);
131 	bzero(adjndir, sizeof(int) * MIBSIZE);
132 	bzero(adjnbfree, sizeof(int) * MIBSIZE);
133 	bzero(adjnifree, sizeof(int) * MIBSIZE);
134 	bzero(adjnffree, sizeof(int) * MIBSIZE);
135 	bzero(adjnumclusters, sizeof(int) * MIBSIZE);
136 	bzero(freefiles, sizeof(int) * MIBSIZE);
137 	bzero(freedirs, sizeof(int) * MIBSIZE);
138 	bzero(freeblks, sizeof(int) * MIBSIZE);
139 	bzero(&cmd, sizeof(struct fsck_cmd));
140 	bzero(snapname, sizeof(char) * BUFSIZ);
141 	cdevname = NULL;
142 	dev_bsize = 0;
143 	secsize = 0;
144 	real_dev_bsize = 0;
145 	bkgrdsumadj = 0;
146 	usedsoftdep = 0;
147 	rerun = 0;
148 	returntosingle = 0;
149 	resolved = 0;
150 	havesb = 0;
151 	fsmodified = 0;
152 	fsreadfd = 0;
153 	fswritefd = 0;
154 	maxfsblock = 0;
155 	blockmap = NULL;
156 	maxino = 0;
157 	lfdir = 0;
158 	lfname = "lost+found";
159 	lfmode = 0700;
160 	n_blks = 0;
161 	n_files = 0;
162 	got_siginfo = 0;
163 	got_sigalarm = 0;
164 	bzero(&ufs1_zino, sizeof(struct ufs1_dinode));
165 	bzero(&ufs2_zino, sizeof(struct ufs2_dinode));
166 }
167