2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (C) 1995 Wolfgang Solfrank
5 * Copyright (c) 1995 Martin Husemann
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
31 __RCSID("$NetBSD: main.c,v 1.10 1997/10/01 02:18:14 enami Exp $");
32 static const char rcsid[] =
46 int alwaysno; /* assume "no" for all questions */
47 int alwaysyes; /* assume "yes" for all questions */
48 int preen; /* set when preening */
49 int rdonly; /* device is opened read only (supersedes above) */
50 int skipclean; /* skip clean file systems if preening */
51 int allow_mmap; /* Allow the use of mmap(), if possible */
53 static void usage(void) __dead2;
59 fprintf(stderr, "%s\n%s\n",
60 "usage: fsck_msdosfs -p [-f] filesystem ...",
61 " fsck_msdosfs [-ny] filesystem ...");
66 main(int argc, char **argv)
73 while ((ch = getopt(argc, argv, "CfFnpyM")) != -1) {
75 case 'C': /* for fsck_ffs compatibility */
82 * We can never run in the background. We must exit
83 * silently with a nonzero exit code so that fsck(8)
84 * can probe our support for -F. The exit code
85 * doesn't really matter, but we use an unusual one
86 * in case someone tries -F directly. The -F flag
87 * is intentionally left out of the usage message.
118 while (--argc >= 0) {
119 setcdevname(*argv, preen);
120 erg = checkfilesys(*argv++);
131 ask(int def, const char *fmt, ...)
138 if (alwaysyes || alwaysno || rdonly)
139 def = (alwaysyes && !rdonly && !alwaysno);
148 vsnprintf(prompt, sizeof(prompt), fmt, ap);
150 if (alwaysyes || alwaysno || rdonly) {
151 printf("%s? %s\n", prompt, def ? "yes" : "no");
155 printf("%s? [yn] ", prompt);
158 while (c != '\n' && getchar() != '\n')
161 } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
162 return c == 'y' || c == 'Y';