/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (C) 1995 Wolfgang Solfrank4* Copyright (c) 1995 Martin Husemann5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR16* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES17* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.18* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT20* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,21* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF24* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/262728#include <sys/cdefs.h>29#ifndef lint30__RCSID("$NetBSD: main.c,v 1.10 1997/10/01 02:18:14 enami Exp $");31#endif /* not lint */3233#include <stdlib.h>34#include <string.h>35#include <stdio.h>36#include <unistd.h>37#include <errno.h>38#include <stdarg.h>3940#include "fsutil.h"41#include "ext.h"4243int alwaysno; /* assume "no" for all questions */44int alwaysyes; /* assume "yes" for all questions */45int preen; /* set when preening */46int rdonly; /* device is opened read only (supersedes above) */47int skipclean; /* skip clean file systems if preening */48int allow_mmap; /* Allow the use of mmap(), if possible */4950static void usage(void) __dead2;5152static void53usage(void)54{5556fprintf(stderr, "%s\n%s\n",57"usage: fsck_msdosfs -p [-f] filesystem ...",58" fsck_msdosfs [-ny] filesystem ...");59exit(1);60}6162int63main(int argc, char **argv)64{65int ret = 0, erg;66int ch;6768skipclean = 1;69allow_mmap = 1;70while ((ch = getopt(argc, argv, "BCfFnpyM")) != -1) {71switch (ch) {72case 'B': /* for fsck_ffs compatibility */73case 'C':74break;75case 'f':76skipclean = 0;77break;78case 'F':79/*80* We can never run in the background. We must exit81* silently with a nonzero exit code so that fsck(8)82* can probe our support for -F. The exit code83* doesn't really matter, but we use an unusual one84* in case someone tries -F directly. The -F flag85* is intentionally left out of the usage message.86*/87exit(5);88case 'n':89alwaysno = 1;90alwaysyes = 0;91break;92case 'y':93alwaysyes = 1;94alwaysno = 0;95break;9697case 'p':98preen = 1;99break;100101case 'M':102allow_mmap = 0;103break;104105default:106usage();107break;108}109}110argc -= optind;111argv += optind;112113if (!argc)114usage();115116while (--argc >= 0) {117setcdevname(*argv, preen);118erg = checkfilesys(*argv++);119if (erg > ret)120ret = erg;121}122123return ret;124}125126127/*VARARGS*/128int129ask(int def, const char *fmt, ...)130{131va_list ap;132133char prompt[256];134int c;135136if (alwaysyes || alwaysno || rdonly)137def = (alwaysyes && !rdonly && !alwaysno);138139if (preen) {140if (def)141printf("FIXED\n");142return def;143}144145va_start(ap, fmt);146vsnprintf(prompt, sizeof(prompt), fmt, ap);147va_end(ap);148if (alwaysyes || alwaysno || rdonly) {149printf("%s? %s\n", prompt, def ? "yes" : "no");150return def;151}152do {153printf("%s? [yn] ", prompt);154fflush(stdout);155c = getchar();156while (c != '\n' && getchar() != '\n')157if (feof(stdin))158return 0;159} while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');160return c == 'y' || c == 'Y';161}162163164