Deleted Added
full compact
main.c (18808) main.c (23675)
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

--- 24 unchanged lines hidden (view full) ---

33
34#ifndef lint
35static const char copyright[] =
36"@(#) Copyright (c) 1980, 1986, 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
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

--- 24 unchanged lines hidden (view full) ---

33
34#ifndef lint
35static const char copyright[] =
36"@(#) Copyright (c) 1980, 1986, 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41static const char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94";
41static const char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95";
42#endif /* not lint */
43
44#include <sys/param.h>
45#include <sys/time.h>
46#include <sys/proc.h>
47#include <sys/mount.h>
42#endif /* not lint */
43
44#include <sys/param.h>
45#include <sys/time.h>
46#include <sys/proc.h>
47#include <sys/mount.h>
48
48#include <ufs/ufs/dinode.h>
49#include <ufs/ufs/dinode.h>
50#include <ufs/ufs/ufsmount.h>
49#include <ufs/ffs/fs.h>
51#include <ufs/ffs/fs.h>
52
53#include <ctype.h>
54#include <err.h>
50#include <fstab.h>
51#include <stdlib.h>
52#include <unistd.h>
53#include <string.h>
54#include <stdio.h>
55#include <fstab.h>
56#include <stdlib.h>
57#include <unistd.h>
58#include <string.h>
59#include <stdio.h>
60
55#include "fsck.h"
61#include "fsck.h"
56static int argtoi __P((int flag, char *req, char *str, int base));
57static int docheck __P((struct fstab *fsp));
58static int checkfilesys __P((char *filesys, char *mntpt, long auxdata,
59 int child));
60
62
63int returntosingle;
64
65static int argtoi __P((int flag, char *req, char *str, int base));
66static int docheck __P((struct fstab *fsp));
67static int checkfilesys __P((char *filesys, char *mntpt, long auxdata,
68 int child));
69int main __P((int argc, char *argv[]));
70
61int
62main(argc, argv)
63 int argc;
64 char *argv[];
65{
66 int ch;
67 int ret, maxrun = 0;
68 extern char *optarg;

--- 25 unchanged lines hidden (view full) ---

94
95 case 'l':
96 maxrun = argtoi('l', "number", optarg, 10);
97 break;
98
99 case 'm':
100 lfmode = argtoi('m', "mode", optarg, 8);
101 if (lfmode &~ 07777)
71int
72main(argc, argv)
73 int argc;
74 char *argv[];
75{
76 int ch;
77 int ret, maxrun = 0;
78 extern char *optarg;

--- 25 unchanged lines hidden (view full) ---

104
105 case 'l':
106 maxrun = argtoi('l', "number", optarg, 10);
107 break;
108
109 case 'm':
110 lfmode = argtoi('m', "mode", optarg, 8);
111 if (lfmode &~ 07777)
102 errexit("bad mode to -m: %o\n", lfmode);
112 errx(EEXIT, "bad mode to -m: %o", lfmode);
103 printf("** lost+found creation mode %o\n", lfmode);
104 break;
105
106 case 'n':
107 case 'N':
108 nflag++;
109 yflag = 0;
110 break;
111
112 case 'y':
113 case 'Y':
114 yflag++;
115 nflag = 0;
116 break;
117
118 default:
113 printf("** lost+found creation mode %o\n", lfmode);
114 break;
115
116 case 'n':
117 case 'N':
118 nflag++;
119 yflag = 0;
120 break;
121
122 case 'y':
123 case 'Y':
124 yflag++;
125 nflag = 0;
126 break;
127
128 default:
119 errexit("%c option?\n", ch);
129 errx(EEXIT, "%c option?", ch);
120 }
121 }
122 argc -= optind;
123 argv += optind;
124 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
125 (void)signal(SIGINT, catch);
126 if (preen)
127 (void)signal(SIGQUIT, catchquit);
128 if (argc) {
129 while (argc-- > 0)
130 (void)checkfilesys(blockcheck(*argv++), 0, 0L, 0);
131 exit(0);
132 }
133 ret = checkfstab(preen, maxrun, docheck, checkfilesys);
134 if (returntosingle)
135 exit(2);
136 exit(ret);
137}
138
130 }
131 }
132 argc -= optind;
133 argv += optind;
134 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
135 (void)signal(SIGINT, catch);
136 if (preen)
137 (void)signal(SIGQUIT, catchquit);
138 if (argc) {
139 while (argc-- > 0)
140 (void)checkfilesys(blockcheck(*argv++), 0, 0L, 0);
141 exit(0);
142 }
143 ret = checkfstab(preen, maxrun, docheck, checkfilesys);
144 if (returntosingle)
145 exit(2);
146 exit(ret);
147}
148
139int
149static int
140argtoi(flag, req, str, base)
141 int flag;
142 char *req, *str;
143 int base;
144{
145 char *cp;
146 int ret;
147
148 ret = (int)strtol(str, &cp, base);
149 if (cp == str || *cp)
150argtoi(flag, req, str, base)
151 int flag;
152 char *req, *str;
153 int base;
154{
155 char *cp;
156 int ret;
157
158 ret = (int)strtol(str, &cp, base);
159 if (cp == str || *cp)
150 errexit("-%c flag requires a %s\n", flag, req);
160 errx(EEXIT, "-%c flag requires a %s", flag, req);
151 return (ret);
152}
153
154/*
155 * Determine whether a filesystem should be checked.
156 */
161 return (ret);
162}
163
164/*
165 * Determine whether a filesystem should be checked.
166 */
157int
167static int
158docheck(fsp)
159 register struct fstab *fsp;
160{
161
162 if (strcmp(fsp->fs_vfstype, "ufs") ||
163 (strcmp(fsp->fs_type, FSTAB_RW) &&
164 strcmp(fsp->fs_type, FSTAB_RO)) ||
165 fsp->fs_passno == 0)
166 return (0);
167 return (1);
168}
169
170/*
171 * Check the specified filesystem.
172 */
173/* ARGSUSED */
168docheck(fsp)
169 register struct fstab *fsp;
170{
171
172 if (strcmp(fsp->fs_vfstype, "ufs") ||
173 (strcmp(fsp->fs_type, FSTAB_RW) &&
174 strcmp(fsp->fs_type, FSTAB_RO)) ||
175 fsp->fs_passno == 0)
176 return (0);
177 return (1);
178}
179
180/*
181 * Check the specified filesystem.
182 */
183/* ARGSUSED */
174int
184static int
175checkfilesys(filesys, mntpt, auxdata, child)
176 char *filesys, *mntpt;
177 long auxdata;
178 int child;
179{
185checkfilesys(filesys, mntpt, auxdata, child)
186 char *filesys, *mntpt;
187 long auxdata;
188 int child;
189{
180 daddr_t n_ffree, n_bfree;
190 ufs_daddr_t n_ffree, n_bfree;
181 struct dups *dp;
182 struct zlncnt *zlnp;
191 struct dups *dp;
192 struct zlncnt *zlnp;
183 int cylno;
193 int cylno, flags;
184
185 if (preen && child)
186 (void)signal(SIGQUIT, voidquit);
187 cdevname = filesys;
188 if (debug && preen)
189 pwarn("starting\n");
194
195 if (preen && child)
196 (void)signal(SIGQUIT, voidquit);
197 cdevname = filesys;
198 if (debug && preen)
199 pwarn("starting\n");
190 if (setup(filesys) == 0) {
200 switch (setup(filesys)) {
201 case 0:
191 if (preen)
192 pfatal("CAN'T CHECK FILE SYSTEM.");
202 if (preen)
203 pfatal("CAN'T CHECK FILE SYSTEM.");
204 /* fall through */
205 case -1:
193 return (0);
194 }
195
196 if (preen && sblock.fs_clean && !fflag) {
197 pwarn("clean, %ld free ", sblock.fs_cstotal.cs_nffree +
198 sblock.fs_frag * sblock.fs_cstotal.cs_nbfree);
199 printf("(%ld frags, %ld blocks, %.1f%% fragmentation)\n",
200 sblock.fs_cstotal.cs_nffree,

--- 96 unchanged lines hidden (view full) ---

297 if (cvtlevel && sblk.b_dirty) {
298 /*
299 * Write out the duplicate super blocks
300 */
301 for (cylno = 0; cylno < sblock.fs_ncg; cylno++)
302 bwrite(fswritefd, (char *)&sblock,
303 fsbtodb(&sblock, cgsblock(&sblock, cylno)), SBSIZE);
304 }
206 return (0);
207 }
208
209 if (preen && sblock.fs_clean && !fflag) {
210 pwarn("clean, %ld free ", sblock.fs_cstotal.cs_nffree +
211 sblock.fs_frag * sblock.fs_cstotal.cs_nbfree);
212 printf("(%ld frags, %ld blocks, %.1f%% fragmentation)\n",
213 sblock.fs_cstotal.cs_nffree,

--- 96 unchanged lines hidden (view full) ---

310 if (cvtlevel && sblk.b_dirty) {
311 /*
312 * Write out the duplicate super blocks
313 */
314 for (cylno = 0; cylno < sblock.fs_ncg; cylno++)
315 bwrite(fswritefd, (char *)&sblock,
316 fsbtodb(&sblock, cgsblock(&sblock, cylno)), SBSIZE);
317 }
305 ckfini();
318 if (!hotroot) {
319 ckfini(1);
320 } else {
321 struct statfs stfs_buf;
322 /*
323 * Check to see if root is mounted read-write.
324 */
325 if (statfs("/", &stfs_buf) == 0)
326 flags = stfs_buf.f_flags;
327 else
328 flags = 0;
329 ckfini(flags & MNT_RDONLY);
330 }
306 free(blockmap);
307 free(statemap);
308 free((char *)lncntp);
309 if (!fsmodified)
310 return (0);
311 if (!preen)
312 printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
313 if (rerun)
314 printf("\n***** PLEASE RERUN FSCK *****\n");
315 if (hotroot) {
331 free(blockmap);
332 free(statemap);
333 free((char *)lncntp);
334 if (!fsmodified)
335 return (0);
336 if (!preen)
337 printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
338 if (rerun)
339 printf("\n***** PLEASE RERUN FSCK *****\n");
340 if (hotroot) {
316 struct statfs stfs_buf;
341 struct ufs_args args;
342 int ret;
317 /*
318 * We modified the root. Do a mount update on
319 * it, unless it is read-write, so we can continue.
320 */
343 /*
344 * We modified the root. Do a mount update on
345 * it, unless it is read-write, so we can continue.
346 */
321 if (statfs("/", &stfs_buf) == 0) {
322 long flags = stfs_buf.f_flags;
323 struct ufs_args args;
324 int ret;
325
326 if (flags & MNT_RDONLY) {
327 args.fspec = 0;
328 args.export.ex_flags = 0;
329 args.export.ex_root = 0;
330 flags |= MNT_UPDATE | MNT_RELOAD;
331 ret = mount(MOUNT_UFS, "/", flags, &args);
332 if (ret == 0)
333 return(0);
334 }
347 if (flags & MNT_RDONLY) {
348 args.fspec = 0;
349 args.export.ex_flags = 0;
350 args.export.ex_root = 0;
351 flags |= MNT_UPDATE | MNT_RELOAD;
352 ret = mount("ufs", "/", flags, &args);
353 if (ret == 0)
354 return (0);
335 }
336 if (!preen)
337 printf("\n***** REBOOT NOW *****\n");
338 sync();
339 return (4);
340 }
341 return (0);
342}
355 }
356 if (!preen)
357 printf("\n***** REBOOT NOW *****\n");
358 sync();
359 return (4);
360 }
361 return (0);
362}