2 * SPDX-License-Identifier: GPL-2.0-or-later
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * mkfs A simple generic frontend for the mkfs program
10 * under Linux. See the manual page for details.
12 * Copyright (C) David Engel, <david@ods.com>
13 * Copyright (C) Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
14 * Copyright (C) Ron Sommeling, <sommel@sci.kun.nl>
16 * Mon Jul 1 18:52:58 1996: janl@math.uio.no (Nicolai Langfeldt):
17 * Incorporated fix by Jonathan Kamens <jik@annex-1-slip-jik.cam.ov.com>
18 * 1999-02-22 Arkadiusz MiĆkiewicz <misiek@pld.ORG.PL>
19 * - added Native Language Support
24 * This command is deprecated. The utility is in maintenance mode,
25 * meaning we keep them in source tree for backward compatibility
26 * only. Do not waste time making this command better, unless the
27 * fix is about security or other very critical issue.
29 * See Documentation/deprecated.txt for more information.
40 #include "closestream.h"
44 #ifndef DEFAULT_FSTYPE
45 #define DEFAULT_FSTYPE "ext2"
48 static void __attribute__((__noreturn__
)) usage(void)
51 fputs(USAGE_HEADER
, out
);
52 fprintf(out
, _(" %s [options] [-t <type>] [fs-options] <device> [<size>]\n"),
53 program_invocation_short_name
);
55 fputs(USAGE_SEPARATOR
, out
);
56 fputs(_("Make a Linux filesystem.\n"), out
);
58 fputs(USAGE_OPTIONS
, out
);
59 fprintf(out
, _(" -t, --type=<type> filesystem type; when unspecified, ext2 is used\n"));
60 fprintf(out
, _(" fs-options parameters for the real filesystem builder\n"));
61 fprintf(out
, _(" <device> path to the device to be used\n"));
62 fprintf(out
, _(" <size> number of blocks to be used on the device\n"));
63 fprintf(out
, _(" -V, --verbose explain what is being done;\n"
64 " specifying -V more than once will cause a dry-run\n"));
65 fprintf(out
, USAGE_HELP_OPTIONS(20));
67 fprintf(out
, USAGE_MAN_TAIL("mkfs(8)"));
71 int main(int argc
, char **argv
)
73 char *progname
; /* name of executable to be called */
75 int i
, more
= 0, verbose
= 0;
77 enum { VERSION_OPTION
= CHAR_MAX
+ 1 };
79 static const struct option longopts
[] = {
80 {"type", required_argument
, NULL
, 't'},
81 {"version", no_argument
, NULL
, VERSION_OPTION
},
82 {"verbose", no_argument
, NULL
, 'V'},
83 {"help", no_argument
, NULL
, 'h'},
87 setlocale(LC_ALL
, "");
88 bindtextdomain(PACKAGE
, LOCALEDIR
);
90 close_stdout_atexit();
92 if (argc
== 2 && !strcmp(argv
[1], "-V"))
93 print_version(EXIT_SUCCESS
);
95 /* Check commandline options. */
98 && ((i
= getopt_long(argc
, argv
, "Vt:h", longopts
, NULL
))
110 print_version(EXIT_SUCCESS
);
114 break; /* start of specific arguments */
116 if (optind
== argc
) {
117 warnx(_("no device specified"));
118 errtryhelp(EXIT_FAILURE
);
121 /* If -t wasn't specified, use the default */
123 fstype
= DEFAULT_FSTYPE
;
125 xasprintf(&progname
, "mkfs.%s", fstype
);
126 argv
[--optind
] = progname
;
129 printf(UTIL_LINUX_VERSION
);
132 printf("%s ", argv
[i
++]);
138 /* Execute the program */
139 execvp(progname
, argv
+ optind
);
140 err(EXIT_FAILURE
, _("failed to execute %s"), progname
);