util-linux/disk-utils/mkfs.c

84 lines
1.8 KiB
C
Raw Normal View History

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
*
2006-12-06 17:25:33 -06:00
* Usage: mkfs [-V] [-t fstype] [fs-options] device [size]
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>
*
* 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>
2006-12-06 17:25:32 -06:00
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
2006-12-06 17:25:33 -06:00
#include <limits.h>
2006-12-06 17:25:32 -06:00
#define VERSION "1.10"
2006-12-06 17:25:33 -06:00
2006-12-06 17:25:32 -06:00
#ifndef DEFAULT_FSTYPE
# define DEFAULT_FSTYPE "ext2"
2006-12-06 17:25:32 -06:00
#endif
2006-12-06 17:25:33 -06:00
#define SEARCH_PATH "PATH=/sbin:/sbin/fs.d:/sbin/fs:/etc/fs:/etc"
#define PROGNAME "mkfs.%s"
2006-12-06 17:25:32 -06:00
2006-12-06 17:25:33 -06:00
int main(int argc, char *argv[])
2006-12-06 17:25:32 -06:00
{
2006-12-06 17:25:33 -06:00
char progname[NAME_MAX];
char *fstype = NULL;
int i, more = 0, verbose = 0;
/* Check commandline options. */
opterr = 0;
while ((more == 0) && ((i = getopt(argc, argv, "Vt:")) != EOF))
switch (i) {
case 'V':
verbose++;
break;
case 't':
fstype = optarg;
break;
default:
optind--;
2006-12-06 17:25:33 -06:00
more = 1;
break; /* start of specific arguments */
2006-12-06 17:25:32 -06:00
}
2006-12-06 17:25:33 -06:00
if (optind == argc) {
fprintf(stderr,
"Usage: mkfs [-V] [-t fstype] [fs-options] device [size]\n");
return -1;
}
/* If -t wasn't specified, use the default */
if (fstype == NULL)
fstype = DEFAULT_FSTYPE;
/* Set PATH and program name */
putenv(SEARCH_PATH);
sprintf(progname, PROGNAME, fstype);
argv[--optind] = progname;
if (verbose) {
puts("mkfs version " VERSION " (" __DATE__ ")");
i = optind;
while (argv[i])
printf("%s ", argv[i++]);
printf("\n");
if (verbose > 1)
return 0;
}
/* Execute the program */
execvp(progname, argv+optind);
perror(progname);
return 1;
2006-12-06 17:25:32 -06:00
}