10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 23*644Sakaplan * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate /*LINTLIBRARY*/ 300Sstevel@tonic-gate 310Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <stdio.h> 340Sstevel@tonic-gate #include <stdlib.h> 350Sstevel@tonic-gate #include <string.h> 360Sstevel@tonic-gate #include <errno.h> 370Sstevel@tonic-gate #include <signal.h> 380Sstevel@tonic-gate #include <sys/types.h> 390Sstevel@tonic-gate #include <devmgmt.h> 400Sstevel@tonic-gate 410Sstevel@tonic-gate extern char *optarg; 420Sstevel@tonic-gate extern int optind, 430Sstevel@tonic-gate ckquit, 440Sstevel@tonic-gate ckwidth; 450Sstevel@tonic-gate 460Sstevel@tonic-gate char *prog; 470Sstevel@tonic-gate char *label, *fsname; 480Sstevel@tonic-gate char *prompt; 490Sstevel@tonic-gate int options = 0; 500Sstevel@tonic-gate int kpid = (-2); 510Sstevel@tonic-gate int signo = SIGKILL; 520Sstevel@tonic-gate 530Sstevel@tonic-gate static void usage(void); 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* 560Sstevel@tonic-gate * Given argv[0], return a pointer to the basename of the program. 570Sstevel@tonic-gate */ 580Sstevel@tonic-gate static char * 590Sstevel@tonic-gate prog_name(char *arg0) 600Sstevel@tonic-gate { 610Sstevel@tonic-gate char *str; 620Sstevel@tonic-gate 630Sstevel@tonic-gate /* first strip trailing '/' characters (exec() allows these!) */ 640Sstevel@tonic-gate str = arg0 + strlen(arg0); 650Sstevel@tonic-gate while (str > arg0 && *--str == '/') 660Sstevel@tonic-gate *str = '\0'; 670Sstevel@tonic-gate if ((str = strrchr(arg0, '/')) != NULL) 680Sstevel@tonic-gate return (str + 1); 690Sstevel@tonic-gate return (arg0); 700Sstevel@tonic-gate } 710Sstevel@tonic-gate 72*644Sakaplan int 730Sstevel@tonic-gate main(int argc, char **argv) 740Sstevel@tonic-gate { 750Sstevel@tonic-gate int c, n; 760Sstevel@tonic-gate 770Sstevel@tonic-gate prog = prog_name(argv[0]); 780Sstevel@tonic-gate 790Sstevel@tonic-gate while ((c = getopt(argc, argv, "fFownx:l:p:k:s:?QW:")) != EOF) { 800Sstevel@tonic-gate switch (c) { 810Sstevel@tonic-gate case 'Q': 820Sstevel@tonic-gate ckquit = 0; 830Sstevel@tonic-gate break; 840Sstevel@tonic-gate 850Sstevel@tonic-gate case 'W': 860Sstevel@tonic-gate ckwidth = atol(optarg); 870Sstevel@tonic-gate break; 880Sstevel@tonic-gate 890Sstevel@tonic-gate case 'f': 900Sstevel@tonic-gate options |= DM_FORMAT; 910Sstevel@tonic-gate break; 920Sstevel@tonic-gate 930Sstevel@tonic-gate case 'F': 940Sstevel@tonic-gate options |= DM_FORMFS; 950Sstevel@tonic-gate break; 960Sstevel@tonic-gate 970Sstevel@tonic-gate case 'o': 980Sstevel@tonic-gate options |= DM_OLABEL; 990Sstevel@tonic-gate break; 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate case 'n': 1020Sstevel@tonic-gate options |= DM_BATCH; 1030Sstevel@tonic-gate break; 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate case 'w': 1060Sstevel@tonic-gate options |= DM_WLABEL; 1070Sstevel@tonic-gate break; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate case 'l': 1100Sstevel@tonic-gate if (label) 1110Sstevel@tonic-gate usage(); 1120Sstevel@tonic-gate label = optarg; 1130Sstevel@tonic-gate break; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate case 'p': 1160Sstevel@tonic-gate prompt = optarg; 1170Sstevel@tonic-gate break; 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate case 'x': 1200Sstevel@tonic-gate if (label) 1210Sstevel@tonic-gate usage(); 1220Sstevel@tonic-gate label = optarg; 1230Sstevel@tonic-gate options |= DM_ELABEL; 1240Sstevel@tonic-gate break; 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate case 'k': 1270Sstevel@tonic-gate kpid = atol(optarg); 1280Sstevel@tonic-gate break; 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate case 's': 1310Sstevel@tonic-gate signo = atol(optarg); 1320Sstevel@tonic-gate break; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate default: 1350Sstevel@tonic-gate usage(); 1360Sstevel@tonic-gate } 1370Sstevel@tonic-gate } 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate if ((optind+1) != argc) 1400Sstevel@tonic-gate usage(); 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate switch (n = getvol(argv[optind], label, options, prompt)) { 1430Sstevel@tonic-gate case 0: 1440Sstevel@tonic-gate break; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate case 1: 1470Sstevel@tonic-gate (void) fprintf(stderr, 1480Sstevel@tonic-gate "%s: ERROR: unable to access device <%s>\n", 1490Sstevel@tonic-gate prog, argv[optind]); 1500Sstevel@tonic-gate break; 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate case 2: 1530Sstevel@tonic-gate (void) fprintf(stderr, "%s: ERROR: unknown device <%s>\n", 1540Sstevel@tonic-gate prog, argv[optind]); 1550Sstevel@tonic-gate break; 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate case 3: 1580Sstevel@tonic-gate if (kpid > -2) 1590Sstevel@tonic-gate (void) kill(kpid, signo); 1600Sstevel@tonic-gate break; 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate case 4: 1630Sstevel@tonic-gate (void) fprintf(stderr, "%s: ERROR: bad label on <%s>\n", 1640Sstevel@tonic-gate prog, argv[optind]); 1650Sstevel@tonic-gate break; 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate default: 1680Sstevel@tonic-gate (void) fprintf(stderr, "%s: ERROR: unknown device error\n", 1690Sstevel@tonic-gate prog); 1700Sstevel@tonic-gate break; 1710Sstevel@tonic-gate } 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate return (n); 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate static void 1770Sstevel@tonic-gate usage() 1780Sstevel@tonic-gate { 1790Sstevel@tonic-gate fprintf(stderr, 1800Sstevel@tonic-gate "usage: %s [-owfF] [-x extlabel] [-l [fsname],volname] device\n", 1810Sstevel@tonic-gate prog); 1820Sstevel@tonic-gate fprintf(stderr, 1830Sstevel@tonic-gate "usage: %s [-n] [-x extlabel] [-l [fsname],volname] device\n", 1840Sstevel@tonic-gate prog); 1850Sstevel@tonic-gate exit(1); 1860Sstevel@tonic-gate } 187