kernel - Refactor Xinvltlb (3)
[dragonfly.git] / sbin / fsck_msdosfs / main.c
blob9d2e6f78e1aa70dd4efd15ab2d24fb2c96676f29
1 /*
2 * Copyright (C) 1995 Wolfgang Solfrank
3 * Copyright (c) 1995 Martin Husemann
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Martin Husemann
16 * and Wolfgang Solfrank.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * $NetBSD: main.c,v 1.10 1997/10/01 02:18:14 enami Exp $
33 * $FreeBSD: src/sbin/fsck_msdosfs/main.c,v 1.4.2.1 2001/08/01 05:47:56 obrien Exp $
36 #include <stdlib.h>
37 #include <string.h>
38 #include <ctype.h>
39 #include <stdio.h>
40 #include <unistd.h>
41 #include <errno.h>
42 #include <stdarg.h>
44 #include "fsutil.h"
45 #include "ext.h"
47 int alwaysno; /* assume "no" for all questions */
48 int alwaysyes; /* assume "yes" for all questions */
49 int preen; /* set when preening */
50 int rdonly; /* device is opened read only (supersedes above) */
52 static void usage(void);
54 static void
55 usage(void)
57 errexit("Usage: fsck_msdos [-fnpy] filesystem ... \n");
60 int
61 main(int argc, char **argv)
63 int ret = 0, erg;
64 int ch;
66 while ((ch = getopt(argc, argv, "fFnpy")) != -1) {
67 switch (ch) {
68 case 'f':
70 * We are always forced, since we don't
71 * have a clean flag
73 break;
74 case 'F':
75 /* We can never run in background */
76 exit(5);
77 break;
78 case 'n':
79 alwaysno = 1;
80 alwaysyes = preen = 0;
81 break;
82 case 'y':
83 alwaysyes = 1;
84 alwaysno = preen = 0;
85 break;
87 case 'p':
88 preen = 1;
89 alwaysyes = alwaysno = 0;
90 break;
92 default:
93 usage();
94 break;
97 argc -= optind;
98 argv += optind;
100 if (!argc)
101 usage();
103 while (--argc >= 0) {
104 setcdevname(*argv, preen);
105 erg = checkfilesys(*argv++);
106 if (erg > ret)
107 ret = erg;
110 return ret;
114 /*VARARGS*/
116 ask(int def, const char *fmt, ...)
118 va_list ap;
120 char prompt[256];
121 int c;
123 if (preen) {
124 if (rdonly)
125 def = 0;
126 if (def)
127 printf("FIXED\n");
128 return def;
131 va_start(ap, fmt);
132 vsnprintf(prompt, sizeof(prompt), fmt, ap);
133 if (alwaysyes || rdonly) {
134 printf("%s? %s\n", prompt, rdonly ? "no" : "yes");
135 return !rdonly;
137 do {
138 printf("%s? [yn] ", prompt);
139 fflush(stdout);
140 c = getchar();
141 while (c != '\n' && getchar() != '\n')
142 if (feof(stdin))
143 return 0;
144 } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
145 return c == 'y' || c == 'Y';