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

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

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95";
43#endif
44static const char rcsid[] =
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

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

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95";
43#endif
44static const char rcsid[] =
45 "$FreeBSD: head/sbin/fsck_ffs/main.c 55773 2000-01-10 14:20:53Z peter $";
45 "$FreeBSD: head/sbin/fsck_ffs/main.c 66861 2000-10-09 08:26:35Z adrian $";
46#endif /* not lint */
47
48#include <sys/param.h>
49#include <sys/stat.h>
50#include <sys/time.h>
51#include <sys/mount.h>
52#include <sys/resource.h>
53
54#include <ufs/ufs/dinode.h>
55#include <ufs/ufs/ufsmount.h>
56#include <ufs/ffs/fs.h>
57
58#include <err.h>
59#include <errno.h>
60#include <fstab.h>
61#include <paths.h>
62
63#include "fsck.h"
64
46#endif /* not lint */
47
48#include <sys/param.h>
49#include <sys/stat.h>
50#include <sys/time.h>
51#include <sys/mount.h>
52#include <sys/resource.h>
53
54#include <ufs/ufs/dinode.h>
55#include <ufs/ufs/ufsmount.h>
56#include <ufs/ffs/fs.h>
57
58#include <err.h>
59#include <errno.h>
60#include <fstab.h>
61#include <paths.h>
62
63#include "fsck.h"
64
65int returntosingle;
66
67static void usage __P((void));
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));
69static struct statfs *getmntpt __P((const char *));
70int main __P((int argc, char *argv[]));
71
72int
73main(argc, argv)
74 int argc;
75 char *argv[];
76{
77 int ch;
68static int argtoi __P((int flag, char *req, char *str, int base));
69static int docheck __P((struct fstab *fsp));
70static int checkfilesys __P((char *filesys, char *mntpt, long auxdata,
71 int child));
72static struct statfs *getmntpt __P((const char *));
73int main __P((int argc, char *argv[]));
74
75int
76main(argc, argv)
77 int argc;
78 char *argv[];
79{
80 int ch;
78 int ret, maxrun = 0;
79 struct rlimit rlimit;
81 struct rlimit rlimit;
82 int ret = 0;
80
81 sync();
83
84 sync();
82 while ((ch = getopt(argc, argv, "dfpnNyYb:c:l:m:")) != -1) {
85 skipclean = 1;
86 markclean = 1;
87 while ((ch = getopt(argc, argv, "b:c:dfm:npy")) != -1) {
83 switch (ch) {
88 switch (ch) {
84 case 'p':
85 preen++;
86 break;
87
88 case 'b':
89 case 'b':
90 skipclean = 0;
89 bflag = argtoi('b', "number", optarg, 10);
90 printf("Alternate super block location: %d\n", bflag);
91 break;
92
93 case 'c':
91 bflag = argtoi('b', "number", optarg, 10);
92 printf("Alternate super block location: %d\n", bflag);
93 break;
94
95 case 'c':
96 skipclean = 0;
94 cvtlevel = argtoi('c', "conversion level", optarg, 10);
95 break;
96
97 case 'd':
98 debug++;
99 break;
100
101 case 'f':
97 cvtlevel = argtoi('c', "conversion level", optarg, 10);
98 break;
99
100 case 'd':
101 debug++;
102 break;
103
104 case 'f':
102 fflag++;
105 skipclean = 0;
103 break;
104
106 break;
107
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)
112 errx(EEXIT, "bad mode to -m: %o", lfmode);
113 printf("** lost+found creation mode %o\n", lfmode);
114 break;
115
116 case 'n':
108 case 'm':
109 lfmode = argtoi('m', "mode", optarg, 8);
110 if (lfmode &~ 07777)
111 errx(EEXIT, "bad mode to -m: %o", lfmode);
112 printf("** lost+found creation mode %o\n", lfmode);
113 break;
114
115 case 'n':
117 case 'N':
118 nflag++;
119 yflag = 0;
120 break;
121
116 nflag++;
117 yflag = 0;
118 break;
119
120 case 'p':
121 preen++;
122 break;
123
122 case 'y':
124 case 'y':
123 case 'Y':
124 yflag++;
125 nflag = 0;
126 break;
127
128 default:
125 yflag++;
126 nflag = 0;
127 break;
128
129 default:
129 errx(EEXIT, "%c option?", ch);
130 usage();
130 }
131 }
132 argc -= optind;
133 argv += optind;
131 }
132 }
133 argc -= optind;
134 argv += optind;
135
136 if (!argc)
137 usage();
138
134 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
135 (void)signal(SIGINT, catch);
136 if (preen)
137 (void)signal(SIGQUIT, catchquit);
138 /*
139 * Push up our allowed memory limit so we can cope
140 * with huge filesystems.
141 */
142 if (getrlimit(RLIMIT_DATA, &rlimit) == 0) {
143 rlimit.rlim_cur = rlimit.rlim_max;
144 (void)setrlimit(RLIMIT_DATA, &rlimit);
145 }
139 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
140 (void)signal(SIGINT, catch);
141 if (preen)
142 (void)signal(SIGQUIT, catchquit);
143 /*
144 * Push up our allowed memory limit so we can cope
145 * with huge filesystems.
146 */
147 if (getrlimit(RLIMIT_DATA, &rlimit) == 0) {
148 rlimit.rlim_cur = rlimit.rlim_max;
149 (void)setrlimit(RLIMIT_DATA, &rlimit);
150 }
146 if (argc) {
147 while (argc-- > 0) {
148 char *path = blockcheck(*argv);
151 while (argc-- > 0)
152 (void)checkfilesys(blockcheck(*argv++), 0, 0L, 0);
149
153
150 if (path == NULL)
151 pfatal("Can't check %s\n", *argv);
152 else
153 (void)checkfilesys(path, 0, 0L, 0);
154 ++argv;
155 }
156 exit(0);
157 }
158 ret = checkfstab(preen, maxrun, docheck, checkfilesys);
159 if (returntosingle)
154 if (returntosingle)
160 exit(2);
155 ret = 2;
161 exit(ret);
162}
163
164static int
165argtoi(flag, req, str, base)
166 int flag;
167 char *req, *str;
168 int base;
169{
170 char *cp;
171 int ret;
172
173 ret = (int)strtol(str, &cp, base);
174 if (cp == str || *cp)
175 errx(EEXIT, "-%c flag requires a %s", flag, req);
176 return (ret);
177}
178
179/*
156 exit(ret);
157}
158
159static int
160argtoi(flag, req, str, base)
161 int flag;
162 char *req, *str;
163 int base;
164{
165 char *cp;
166 int ret;
167
168 ret = (int)strtol(str, &cp, base);
169 if (cp == str || *cp)
170 errx(EEXIT, "-%c flag requires a %s", flag, req);
171 return (ret);
172}
173
174/*
180 * Determine whether a filesystem should be checked.
181 */
182static int
183docheck(fsp)
184 register struct fstab *fsp;
185{
186
187 if (strcmp(fsp->fs_vfstype, "ufs") ||
188 (strcmp(fsp->fs_type, FSTAB_RW) &&
189 strcmp(fsp->fs_type, FSTAB_RO)) ||
190 fsp->fs_passno == 0)
191 return (0);
192 return (1);
193}
194
195/*
196 * Check the specified filesystem.
197 */
198/* ARGSUSED */
199static int
200checkfilesys(filesys, mntpt, auxdata, child)
201 char *filesys, *mntpt;
202 long auxdata;
203 int child;

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

410 devname = device;
411 }
412 if (stat(devname, &mntdevstat) == 0 &&
413 mntdevstat.st_rdev == devstat.st_rdev)
414 return (&mntbuf[i]);
415 }
416 return (NULL);
417}
175 * Check the specified filesystem.
176 */
177/* ARGSUSED */
178static int
179checkfilesys(filesys, mntpt, auxdata, child)
180 char *filesys, *mntpt;
181 long auxdata;
182 int child;

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

389 devname = device;
390 }
391 if (stat(devname, &mntdevstat) == 0 &&
392 mntdevstat.st_rdev == devstat.st_rdev)
393 return (&mntbuf[i]);
394 }
395 return (NULL);
396}
397
398static void
399usage()
400{
401 extern char *__progname;
402
403 (void) fprintf(stderr,
404 "Usage: %s [-dfnpy] [-B be|le] [-b block] [-c level] [-m mode] "
405 "filesystem ...\n",
406 __progname);
407 exit(1);
408}