#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <sys/types.h>
#include <devmgmt.h>
extern char *optarg;
extern int optind,
ckquit,
ckwidth;
char *prog;
char *label, *fsname;
char *prompt;
int options = 0;
int kpid = (-2);
int signo = SIGKILL;
static void usage(void);
static char *
prog_name(char *arg0)
{
char *str;
str = arg0 + strlen(arg0);
while (str > arg0 && *--str == '/')
*str = '\0';
if ((str = strrchr(arg0, '/')) != NULL)
return (str + 1);
return (arg0);
}
int
main(int argc, char **argv)
{
int c, n;
prog = prog_name(argv[0]);
while ((c = getopt(argc, argv, "fFownx:l:p:k:s:?QW:")) != EOF) {
switch (c) {
case 'Q':
ckquit = 0;
break;
case 'W':
ckwidth = atol(optarg);
break;
case 'f':
options |= DM_FORMAT;
break;
case 'F':
options |= DM_FORMFS;
break;
case 'o':
options |= DM_OLABEL;
break;
case 'n':
options |= DM_BATCH;
break;
case 'w':
options |= DM_WLABEL;
break;
case 'l':
if (label)
usage();
label = optarg;
break;
case 'p':
prompt = optarg;
break;
case 'x':
if (label)
usage();
label = optarg;
options |= DM_ELABEL;
break;
case 'k':
kpid = atol(optarg);
break;
case 's':
signo = atol(optarg);
break;
default:
usage();
}
}
if ((optind+1) != argc)
usage();
switch (n = getvol(argv[optind], label, options, prompt)) {
case 0:
break;
case 1:
(void) fprintf(stderr,
"%s: ERROR: unable to access device <%s>\n",
prog, argv[optind]);
break;
case 2:
(void) fprintf(stderr, "%s: ERROR: unknown device <%s>\n",
prog, argv[optind]);
break;
case 3:
if (kpid > -2)
(void) kill(kpid, signo);
break;
case 4:
(void) fprintf(stderr, "%s: ERROR: bad label on <%s>\n",
prog, argv[optind]);
break;
default:
(void) fprintf(stderr, "%s: ERROR: unknown device error\n",
prog);
break;
}
return (n);
}
static void
usage()
{
fprintf(stderr,
"usage: %s [-owfF] [-x extlabel] [-l [fsname],volname] device\n",
prog);
fprintf(stderr,
"usage: %s [-n] [-x extlabel] [-l [fsname],volname] device\n",
prog);
exit(1);
}