2006-12-06 17:25:32 -06:00
|
|
|
/*
|
2006-12-06 17:25:33 -06:00
|
|
|
* mkfs A simple generic frontend for the for the mkfs program
|
|
|
|
* under Linux. See the manual page for details.
|
2006-12-06 17:25:32 -06:00
|
|
|
*
|
|
|
|
* Authors: David Engel, <david@ods.com>
|
|
|
|
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
|
2006-12-06 17:25:33 -06:00
|
|
|
* Ron Sommeling, <sommel@sci.kun.nl>
|
2006-12-06 17:25:34 -06:00
|
|
|
*
|
|
|
|
* Mon Jul 1 18:52:58 1996: janl@math.uio.no (Nicolai Langfeldt):
|
|
|
|
* Incorporated fix by Jonathan Kamens <jik@annex-1-slip-jik.cam.ov.com>
|
2013-01-26 10:07:51 -06:00
|
|
|
* 1999-02-22 Arkadiusz Miśkiewicz <misiek@pld.ORG.PL>
|
2006-12-06 17:25:39 -06:00
|
|
|
* - added Native Language Support
|
|
|
|
*
|
2006-12-06 17:25:32 -06:00
|
|
|
*/
|
|
|
|
|
2014-09-28 14:51:35 -05:00
|
|
|
/*
|
|
|
|
* This command is deprecated. The utility is in maintenance mode,
|
|
|
|
* meaning we keep them in source tree for backward compatibility
|
|
|
|
* only. Do not waste time making this command better, unless the
|
|
|
|
* fix is about security or other very critical issue.
|
|
|
|
*
|
|
|
|
* See Documentation/deprecated.txt for more information.
|
|
|
|
*/
|
|
|
|
|
2011-06-28 16:22:47 -05:00
|
|
|
#include <getopt.h>
|
2011-06-28 17:23:01 -05:00
|
|
|
#include <limits.h>
|
2006-12-06 17:25:32 -06:00
|
|
|
#include <stdio.h>
|
2011-06-28 17:23:01 -05:00
|
|
|
#include <stdlib.h>
|
2006-12-06 17:25:35 -06:00
|
|
|
#include <string.h>
|
2011-06-28 17:23:01 -05:00
|
|
|
#include <unistd.h>
|
2006-12-06 17:25:33 -06:00
|
|
|
|
2011-06-28 17:23:01 -05:00
|
|
|
#include "c.h"
|
2012-04-04 13:04:39 -05:00
|
|
|
#include "closestream.h"
|
2011-06-28 17:23:01 -05:00
|
|
|
#include "nls.h"
|
2010-12-06 08:10:59 -06:00
|
|
|
#include "xalloc.h"
|
|
|
|
|
2006-12-06 17:25:32 -06:00
|
|
|
#ifndef DEFAULT_FSTYPE
|
2011-06-28 17:24:27 -05:00
|
|
|
#define DEFAULT_FSTYPE "ext2"
|
2006-12-06 17:25:32 -06:00
|
|
|
#endif
|
|
|
|
|
2010-01-24 21:36:55 -06:00
|
|
|
#define SEARCH_PATH "PATH=" FS_SEARCH_PATH
|
2006-12-06 17:25:33 -06:00
|
|
|
#define PROGNAME "mkfs.%s"
|
2006-12-06 17:25:32 -06:00
|
|
|
|
|
|
|
|
2011-06-28 16:22:47 -05:00
|
|
|
static void __attribute__ ((__noreturn__)) usage(FILE * out)
|
|
|
|
{
|
2014-09-28 14:51:41 -05:00
|
|
|
fputs(USAGE_HEADER, out);
|
2013-01-22 04:56:58 -06:00
|
|
|
fprintf(out, _(" %s [options] [-t <type>] [fs-options] <device> [<size>]\n"),
|
|
|
|
program_invocation_short_name);
|
2014-12-22 15:57:17 -06:00
|
|
|
|
|
|
|
fputs(USAGE_SEPARATOR, out);
|
|
|
|
fputs(_("Make a Linux filesystem.\n"), out);
|
|
|
|
|
2014-09-28 14:51:41 -05:00
|
|
|
fputs(USAGE_OPTIONS, out);
|
2013-01-22 04:56:58 -06:00
|
|
|
fprintf(out, _(" -t, --type=<type> filesystem type; when unspecified, ext2 is used\n"));
|
|
|
|
fprintf(out, _(" fs-options parameters for the real filesystem builder\n"));
|
|
|
|
fprintf(out, _(" <device> path to the device to be used\n"));
|
|
|
|
fprintf(out, _(" <size> number of blocks to be used on the device\n"));
|
|
|
|
fprintf(out, _(" -V, --verbose explain what is being done;\n"
|
|
|
|
" specifying -V more than once will cause a dry-run\n"));
|
|
|
|
fprintf(out, _(" -V, --version display version information and exit;\n"
|
|
|
|
" -V as --version must be the only option\n"));
|
|
|
|
fprintf(out, _(" -h, --help display this help text and exit\n"));
|
2011-06-28 16:22:47 -05:00
|
|
|
|
2014-09-28 14:51:40 -05:00
|
|
|
fprintf(out, USAGE_MAN_TAIL("mkfs(8)"));
|
2011-06-28 16:22:47 -05:00
|
|
|
|
|
|
|
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __attribute__ ((__noreturn__)) print_version(void)
|
|
|
|
{
|
2013-01-25 05:05:26 -06:00
|
|
|
printf(UTIL_LINUX_VERSION);
|
2011-06-28 16:22:47 -05:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2011-06-28 17:24:27 -05:00
|
|
|
int main(int argc, char **argv)
|
2006-12-06 17:25:32 -06:00
|
|
|
{
|
2011-06-28 17:24:27 -05:00
|
|
|
char *progname; /* name of executable to be called */
|
|
|
|
char *fstype = NULL;
|
|
|
|
int i, more = 0, verbose = 0;
|
|
|
|
char *oldpath, *newpath;
|
|
|
|
|
|
|
|
enum { VERSION_OPTION = CHAR_MAX + 1 };
|
|
|
|
|
|
|
|
static const struct option longopts[] = {
|
|
|
|
{"type", required_argument, NULL, 't'},
|
|
|
|
{"version", no_argument, NULL, VERSION_OPTION},
|
2014-02-07 16:01:20 -06:00
|
|
|
{"verbose", no_argument, NULL, 'V'},
|
2011-06-28 17:24:27 -05:00
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
2012-04-04 13:04:39 -05:00
|
|
|
atexit(close_stdout);
|
2011-06-28 17:24:27 -05:00
|
|
|
|
|
|
|
if (argc == 2 && !strcmp(argv[1], "-V"))
|
|
|
|
print_version();
|
|
|
|
|
|
|
|
/* Check commandline options. */
|
|
|
|
opterr = 0;
|
|
|
|
while ((more == 0)
|
|
|
|
&& ((i = getopt_long(argc, argv, "Vt:h", longopts, NULL))
|
|
|
|
!= -1))
|
|
|
|
switch (i) {
|
|
|
|
case 'V':
|
|
|
|
verbose++;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
fstype = optarg;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage(stdout);
|
|
|
|
case VERSION_OPTION:
|
|
|
|
print_version();
|
|
|
|
default:
|
|
|
|
optind--;
|
|
|
|
more = 1;
|
|
|
|
break; /* start of specific arguments */
|
|
|
|
}
|
|
|
|
if (optind == argc)
|
|
|
|
usage(stderr);
|
|
|
|
|
|
|
|
/* If -t wasn't specified, use the default */
|
|
|
|
if (fstype == NULL)
|
|
|
|
fstype = DEFAULT_FSTYPE;
|
|
|
|
|
|
|
|
/* Set PATH and program name */
|
|
|
|
oldpath = getenv("PATH");
|
|
|
|
if (!oldpath)
|
|
|
|
oldpath = "/bin";
|
|
|
|
|
|
|
|
newpath = xmalloc(strlen(oldpath) + sizeof(SEARCH_PATH) + 3);
|
|
|
|
sprintf(newpath, "%s:%s\n", SEARCH_PATH, oldpath);
|
|
|
|
putenv(newpath);
|
|
|
|
|
|
|
|
progname = xmalloc(sizeof(PROGNAME) + strlen(fstype) + 1);
|
|
|
|
sprintf(progname, PROGNAME, fstype);
|
|
|
|
argv[--optind] = progname;
|
|
|
|
|
|
|
|
if (verbose) {
|
2013-01-25 05:05:26 -06:00
|
|
|
printf(UTIL_LINUX_VERSION);
|
2011-06-28 17:24:27 -05:00
|
|
|
i = optind;
|
|
|
|
while (argv[i])
|
|
|
|
printf("%s ", argv[i++]);
|
|
|
|
printf("\n");
|
|
|
|
if (verbose > 1)
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute the program */
|
|
|
|
execvp(progname, argv + optind);
|
2014-12-07 04:13:03 -06:00
|
|
|
err(EXIT_FAILURE, _("failed to execute %s"), progname);
|
2006-12-06 17:25:32 -06:00
|
|
|
}
|