2 * mkfs A simple generic frontend for the for the mkfs program
3 * under Linux. See the manual page for details.
5 * Authors: David Engel, <david@ods.com>
6 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
7 * Ron Sommeling, <sommel@sci.kun.nl>
9 * Mon Jul 1 18:52:58 1996: janl@math.uio.no (Nicolai Langfeldt):
10 * Incorporated fix by Jonathan Kamens <jik@annex-1-slip-jik.cam.ov.com>
11 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
12 * - added Native Language Support
27 #ifndef DEFAULT_FSTYPE
28 #define DEFAULT_FSTYPE "ext2"
31 #define SEARCH_PATH "PATH=" FS_SEARCH_PATH
32 #define PROGNAME "mkfs.%s"
35 static void __attribute__ ((__noreturn__
)) usage(FILE * out
)
38 _("Usage: %s [options] [-t type fs-options] device [size]\n"),
39 program_invocation_short_name
);
41 fprintf(out
, _("\nOptions:\n"
42 " -t, --type=TYPE file system type, when undefined ext2 is used\n"
43 " fs-options parameters to real file system builder\n"
44 " device path to a device\n"
45 " size number of blocks on the device\n"
46 " -V, --verbose explain what is done\n"
47 " defining -V more than once will cause a dry-run\n"
48 " -V, --version output version information and exit\n"
49 " -V as version must be only option\n"
50 " -h, --help display this help and exit\n"));
52 fprintf(out
, _("\nFor more information see mkfs(8).\n"));
54 exit(out
== stderr
? EXIT_FAILURE
: EXIT_SUCCESS
);
57 static void __attribute__ ((__noreturn__
)) print_version(void)
59 printf(_("%s (%s)\n"),
60 program_invocation_short_name
, PACKAGE_STRING
);
64 int main(int argc
, char **argv
)
66 char *progname
; /* name of executable to be called */
68 int i
, more
= 0, verbose
= 0;
69 char *oldpath
, *newpath
;
71 enum { VERSION_OPTION
= CHAR_MAX
+ 1 };
73 static const struct option longopts
[] = {
74 {"type", required_argument
, NULL
, 't'},
75 {"version", no_argument
, NULL
, VERSION_OPTION
},
76 {"help", no_argument
, NULL
, 'h'},
80 setlocale(LC_ALL
, "");
81 bindtextdomain(PACKAGE
, LOCALEDIR
);
84 if (argc
== 2 && !strcmp(argv
[1], "-V"))
87 /* Check commandline options. */
90 && ((i
= getopt_long(argc
, argv
, "Vt:h", longopts
, NULL
))
106 break; /* start of specific arguments */
111 /* If -t wasn't specified, use the default */
113 fstype
= DEFAULT_FSTYPE
;
115 /* Set PATH and program name */
116 oldpath
= getenv("PATH");
120 newpath
= xmalloc(strlen(oldpath
) + sizeof(SEARCH_PATH
) + 3);
121 sprintf(newpath
, "%s:%s\n", SEARCH_PATH
, oldpath
);
124 progname
= xmalloc(sizeof(PROGNAME
) + strlen(fstype
) + 1);
125 sprintf(progname
, PROGNAME
, fstype
);
126 argv
[--optind
] = progname
;
129 printf(_("mkfs (%s)\n"), PACKAGE_STRING
);
132 printf("%s ", argv
[i
++]);
138 /* Execute the program */
139 execvp(progname
, argv
+ optind
);