2017-11-27 15:37:16 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*
|
2001-07-09 10:35:18 +00:00
|
|
|
* Copyright (C) 1995 Wolfgang Solfrank
|
|
|
|
* Copyright (c) 1995 Martin Husemann
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
|
|
|
__RCSID("$NetBSD: main.c,v 1.10 1997/10/01 02:18:14 enami Exp $");
|
|
|
|
static const char rcsid[] =
|
|
|
|
"$FreeBSD$";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "fsutil.h"
|
|
|
|
#include "ext.h"
|
|
|
|
|
|
|
|
int alwaysno; /* assume "no" for all questions */
|
|
|
|
int alwaysyes; /* assume "yes" for all questions */
|
|
|
|
int preen; /* set when preening */
|
|
|
|
int rdonly; /* device is opened read only (supersedes above) */
|
2004-02-05 15:47:46 +00:00
|
|
|
int skipclean; /* skip clean file systems if preening */
|
2001-07-09 10:35:18 +00:00
|
|
|
|
2002-03-20 22:57:10 +00:00
|
|
|
static void usage(void) __dead2;
|
2001-07-09 10:35:18 +00:00
|
|
|
|
|
|
|
static void
|
2003-12-27 13:08:55 +00:00
|
|
|
usage(void)
|
2001-07-09 10:35:18 +00:00
|
|
|
{
|
2003-12-27 13:08:55 +00:00
|
|
|
|
2005-02-10 09:39:51 +00:00
|
|
|
fprintf(stderr, "%s\n%s\n",
|
|
|
|
"usage: fsck_msdosfs -p [-f] filesystem ...",
|
|
|
|
" fsck_msdosfs [-ny] filesystem ...");
|
2003-12-27 13:08:55 +00:00
|
|
|
exit(1);
|
2001-07-09 10:35:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-03-20 22:57:10 +00:00
|
|
|
main(int argc, char **argv)
|
2001-07-09 10:35:18 +00:00
|
|
|
{
|
|
|
|
int ret = 0, erg;
|
|
|
|
int ch;
|
2003-12-27 05:57:20 +00:00
|
|
|
|
2004-02-05 15:47:46 +00:00
|
|
|
skipclean = 1;
|
2009-06-10 19:02:54 +00:00
|
|
|
while ((ch = getopt(argc, argv, "CfFnpy")) != -1) {
|
2001-07-09 10:35:18 +00:00
|
|
|
switch (ch) {
|
2009-06-10 19:02:54 +00:00
|
|
|
case 'C': /* for fsck_ffs compatibility */
|
|
|
|
break;
|
2001-07-09 10:35:18 +00:00
|
|
|
case 'f':
|
2004-02-05 15:47:46 +00:00
|
|
|
skipclean = 0;
|
2001-07-09 10:35:18 +00:00
|
|
|
break;
|
2001-07-19 16:45:45 +00:00
|
|
|
case 'F':
|
2003-12-27 14:02:52 +00:00
|
|
|
/*
|
|
|
|
* We can never run in the background. We must exit
|
|
|
|
* silently with a nonzero exit code so that fsck(8)
|
|
|
|
* can probe our support for -F. The exit code
|
|
|
|
* doesn't really matter, but we use an unusual one
|
|
|
|
* in case someone tries -F directly. The -F flag
|
|
|
|
* is intentionally left out of the usage message.
|
|
|
|
*/
|
2001-07-19 17:06:08 +00:00
|
|
|
exit(5);
|
2001-07-09 10:35:18 +00:00
|
|
|
case 'n':
|
|
|
|
alwaysno = 1;
|
2019-06-07 01:38:51 +00:00
|
|
|
alwaysyes = 0;
|
2001-07-09 10:35:18 +00:00
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
alwaysyes = 1;
|
2019-06-07 01:38:51 +00:00
|
|
|
alwaysno = 0;
|
2001-07-09 10:35:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
preen = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (!argc)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
while (--argc >= 0) {
|
|
|
|
setcdevname(*argv, preen);
|
|
|
|
erg = checkfilesys(*argv++);
|
|
|
|
if (erg > ret)
|
|
|
|
ret = erg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*VARARGS*/
|
|
|
|
int
|
|
|
|
ask(int def, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
char prompt[256];
|
|
|
|
int c;
|
|
|
|
|
2019-06-15 07:23:06 +00:00
|
|
|
if (alwaysyes || alwaysno || rdonly)
|
|
|
|
def = (alwaysyes && !rdonly && !alwaysno);
|
|
|
|
|
2001-07-09 10:35:18 +00:00
|
|
|
if (preen) {
|
|
|
|
if (def)
|
|
|
|
printf("FIXED\n");
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(prompt, sizeof(prompt), fmt, ap);
|
2012-05-29 01:48:06 +00:00
|
|
|
va_end(ap);
|
2019-06-15 07:23:06 +00:00
|
|
|
if (alwaysyes || alwaysno || rdonly) {
|
|
|
|
printf("%s? %s\n", prompt, def ? "yes" : "no");
|
|
|
|
return def;
|
2001-07-09 10:35:18 +00:00
|
|
|
}
|
|
|
|
do {
|
|
|
|
printf("%s? [yn] ", prompt);
|
|
|
|
fflush(stdout);
|
|
|
|
c = getchar();
|
|
|
|
while (c != '\n' && getchar() != '\n')
|
|
|
|
if (feof(stdin))
|
|
|
|
return 0;
|
|
|
|
} while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
|
|
|
|
return c == 'y' || c == 'Y';
|
|
|
|
}
|