1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*0Sstevel@tonic-gate /* All Rights Reserved */ 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate /* 27*0Sstevel@tonic-gate * Copyright (c) 1997, by Sun Microsystems, Inc. 28*0Sstevel@tonic-gate * All rights reserved. 29*0Sstevel@tonic-gate */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*0Sstevel@tonic-gate /*LINTLIBRARY*/ 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #include <stdio.h> 35*0Sstevel@tonic-gate #include <string.h> 36*0Sstevel@tonic-gate #include <sys/types.h> 37*0Sstevel@tonic-gate #include <devmgmt.h> 38*0Sstevel@tonic-gate #include "libadm.h" 39*0Sstevel@tonic-gate #include <stdlib.h> 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate #define LABELSIZ 6 42*0Sstevel@tonic-gate #define BELL "\007" 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate #define FORMFS_MSG ",\\n\\ \\ or [f] to format %s and place a filesystem on it" 45*0Sstevel@tonic-gate #define FORMAT_MSG ",\\n\\ \\ or [f] to format the %s" 46*0Sstevel@tonic-gate #define MAKEFS_MSG ",\\n\\ \\ or [m] to place a filesystem on %s" 47*0Sstevel@tonic-gate #define EJECT_MSG ",\\n\\ \\ or [e] to eject the %s" 48*0Sstevel@tonic-gate #define UNLOAD_MSG ",\\n\\ \\ or [u] to unload/offline the %s" 49*0Sstevel@tonic-gate #define WLABEL_MSG ",\\n\\ \\ or [w] to write a new label on the %s" 50*0Sstevel@tonic-gate #define OLABEL_MSG ",\\n\\ \\ or [o] to use the current label anyway" 51*0Sstevel@tonic-gate #define QUIT_MSG ",\\n\\ \\ or [q] to quit" 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate #define ERR_ACCESS "\n%s (%s) cannot be accessed.\n" 54*0Sstevel@tonic-gate #define ERR_FMT "\nAttempt to format %s failed.\n" 55*0Sstevel@tonic-gate #define ERR_MKFS "\nAttempt to place filesystem on %s failed.\n" 56*0Sstevel@tonic-gate #define ERR_REMOVE "\nExecution of \"removecmd\"[%s] failed.\n" 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate static void elabel(void); 59*0Sstevel@tonic-gate static void doformat(char *, char *, char *); 60*0Sstevel@tonic-gate static void labelerr(char *, char *); 61*0Sstevel@tonic-gate static int ckilabel(char *, int); 62*0Sstevel@tonic-gate static int insert(char *, char *, int, char *); 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate static char *cdevice; /* character device name */ 65*0Sstevel@tonic-gate static char *pname; /* device presentation name */ 66*0Sstevel@tonic-gate static char *volume; /* volume name */ 67*0Sstevel@tonic-gate static char origfsname[LABELSIZ+1]; 68*0Sstevel@tonic-gate static char origvolname[LABELSIZ+1]; 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate /* 71*0Sstevel@tonic-gate * Return: 72*0Sstevel@tonic-gate * 0 - okay, label matches 73*0Sstevel@tonic-gate * 1 - device not accessable 74*0Sstevel@tonic-gate * 2 - unknown device (devattr failed) 75*0Sstevel@tonic-gate * 3 - user selected quit 76*0Sstevel@tonic-gate * 4 - label does not match 77*0Sstevel@tonic-gate */ 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate /* 80*0Sstevel@tonic-gate * macros from labelit to behave correctly for tape 81*0Sstevel@tonic-gate * is a kludge, should use devmgmt 82*0Sstevel@tonic-gate */ 83*0Sstevel@tonic-gate #ifdef RT 84*0Sstevel@tonic-gate #define IFTAPE(s) ((strncmp(s, "/dev/mt", 7) == 0) || \ 85*0Sstevel@tonic-gate (strncmp(s, "mt", 2) == 0)) 86*0Sstevel@tonic-gate #define TAPENAMES "'/dev/mt'" 87*0Sstevel@tonic-gate #else 88*0Sstevel@tonic-gate #define IFTAPE(s) ((strncmp(s, "/dev/rmt", 8) == 0) || \ 89*0Sstevel@tonic-gate (strncmp(s, "rmt", 3) == 0) || (strncmp(s, "/dev/rtp", 8) == 0) || \ 90*0Sstevel@tonic-gate (strncmp(s, "rtp", 3) == 0)) 91*0Sstevel@tonic-gate #define TAPENAMES "'/dev/rmt' or '/dev/rtp'" 92*0Sstevel@tonic-gate #endif 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate int 95*0Sstevel@tonic-gate getvol(char *device, char *label, int options, char *prompt) 96*0Sstevel@tonic-gate { 97*0Sstevel@tonic-gate return (_getvol(device, label, options, prompt, NULL)); 98*0Sstevel@tonic-gate } 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate int 101*0Sstevel@tonic-gate _getvol(char *device, char *label, int options, char *prompt, char *norewind) 102*0Sstevel@tonic-gate { 103*0Sstevel@tonic-gate FILE *tmp; 104*0Sstevel@tonic-gate char *advice, *pt; 105*0Sstevel@tonic-gate int n, override; 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate cdevice = devattr(device, "cdevice"); 108*0Sstevel@tonic-gate if ((cdevice == NULL) || !cdevice[0]) { 109*0Sstevel@tonic-gate cdevice = devattr(device, "pathname"); 110*0Sstevel@tonic-gate if ((cdevice == NULL) || !cdevice) 111*0Sstevel@tonic-gate return (2); /* bad device */ 112*0Sstevel@tonic-gate } 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate pname = devattr(device, "desc"); 115*0Sstevel@tonic-gate if (pname == NULL) { 116*0Sstevel@tonic-gate pname = devattr(device, "alias"); 117*0Sstevel@tonic-gate if (!pname) 118*0Sstevel@tonic-gate pname = device; 119*0Sstevel@tonic-gate } 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate volume = devattr(device, "volume"); 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate if (label) { 124*0Sstevel@tonic-gate (void) strncpy(origfsname, label, LABELSIZ); 125*0Sstevel@tonic-gate origfsname[LABELSIZ] = '\0'; 126*0Sstevel@tonic-gate if (pt = strchr(origfsname, ',')) { 127*0Sstevel@tonic-gate *pt = '\0'; 128*0Sstevel@tonic-gate } 129*0Sstevel@tonic-gate if (pt = strchr(label, ',')) { 130*0Sstevel@tonic-gate (void) strncpy(origvolname, pt+1, LABELSIZ); 131*0Sstevel@tonic-gate origvolname[LABELSIZ] = '\0'; 132*0Sstevel@tonic-gate } else 133*0Sstevel@tonic-gate origvolname[0] = '\0'; 134*0Sstevel@tonic-gate } 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate override = 0; 137*0Sstevel@tonic-gate for (;;) { 138*0Sstevel@tonic-gate if (!(options & DM_BATCH) && volume) { 139*0Sstevel@tonic-gate n = insert(device, label, options, prompt); 140*0Sstevel@tonic-gate if (n < 0) 141*0Sstevel@tonic-gate override++; 142*0Sstevel@tonic-gate else if (n) 143*0Sstevel@tonic-gate return (n); /* input function failed */ 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate if ((tmp = fopen(norewind ? norewind : cdevice, "r")) == NULL) { 147*0Sstevel@tonic-gate /* device was not accessible */ 148*0Sstevel@tonic-gate if (options & DM_BATCH) 149*0Sstevel@tonic-gate return (1); 150*0Sstevel@tonic-gate (void) fprintf(stderr, ERR_ACCESS, pname, cdevice); 151*0Sstevel@tonic-gate if ((options & DM_BATCH) || (volume == NULL)) 152*0Sstevel@tonic-gate return (1); 153*0Sstevel@tonic-gate /* display advice on how to ready device */ 154*0Sstevel@tonic-gate if (advice = devattr(device, "advice")) 155*0Sstevel@tonic-gate (void) puttext(stderr, advice, 0, 0); 156*0Sstevel@tonic-gate continue; 157*0Sstevel@tonic-gate } 158*0Sstevel@tonic-gate (void) fclose(tmp); 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate /* check label on device */ 161*0Sstevel@tonic-gate if (label) { 162*0Sstevel@tonic-gate if (options & DM_ELABEL) 163*0Sstevel@tonic-gate elabel(); 164*0Sstevel@tonic-gate else { 165*0Sstevel@tonic-gate /* check internal label using /etc/labelit */ 166*0Sstevel@tonic-gate if (ckilabel(label, override)) { 167*0Sstevel@tonic-gate if ((options & DM_BATCH) || 168*0Sstevel@tonic-gate volume == NULL) 169*0Sstevel@tonic-gate return (4); 170*0Sstevel@tonic-gate continue; 171*0Sstevel@tonic-gate } 172*0Sstevel@tonic-gate } 173*0Sstevel@tonic-gate } 174*0Sstevel@tonic-gate break; 175*0Sstevel@tonic-gate } 176*0Sstevel@tonic-gate return (0); 177*0Sstevel@tonic-gate } 178*0Sstevel@tonic-gate 179*0Sstevel@tonic-gate static int 180*0Sstevel@tonic-gate ckilabel(char *label, int flag) 181*0Sstevel@tonic-gate { 182*0Sstevel@tonic-gate FILE *pp; 183*0Sstevel@tonic-gate char *pt, *look, buffer[512]; 184*0Sstevel@tonic-gate char fsname[LABELSIZ+1], volname[LABELSIZ+1]; 185*0Sstevel@tonic-gate char *pvolname, *pfsname; 186*0Sstevel@tonic-gate int n, c; 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate (void) strncpy(fsname, label, LABELSIZ); 189*0Sstevel@tonic-gate fsname[LABELSIZ] = '\0'; 190*0Sstevel@tonic-gate if (pt = strchr(fsname, ',')) { 191*0Sstevel@tonic-gate *pt = '\0'; 192*0Sstevel@tonic-gate } 193*0Sstevel@tonic-gate if (pt = strchr(label, ',')) { 194*0Sstevel@tonic-gate (void) strncpy(volname, pt+1, LABELSIZ); 195*0Sstevel@tonic-gate volname[LABELSIZ] = '\0'; 196*0Sstevel@tonic-gate } else 197*0Sstevel@tonic-gate volname[0] = '\0'; 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate (void) sprintf(buffer, "/etc/labelit %s", cdevice); 200*0Sstevel@tonic-gate pp = popen(buffer, "r"); 201*0Sstevel@tonic-gate pt = buffer; 202*0Sstevel@tonic-gate while ((c = getc(pp)) != EOF) 203*0Sstevel@tonic-gate *pt++ = (char)c; 204*0Sstevel@tonic-gate *pt = '\0'; 205*0Sstevel@tonic-gate (void) pclose(pp); 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate pt = buffer; 208*0Sstevel@tonic-gate pfsname = pvolname = NULL; 209*0Sstevel@tonic-gate look = "Current fsname: "; 210*0Sstevel@tonic-gate n = (int)strlen(look); 211*0Sstevel@tonic-gate while (*pt) { 212*0Sstevel@tonic-gate if (strncmp(pt, look, n) == 0) { 213*0Sstevel@tonic-gate *pt = '\0'; 214*0Sstevel@tonic-gate pt += strlen(look); 215*0Sstevel@tonic-gate if (pfsname == NULL) { 216*0Sstevel@tonic-gate pfsname = pt; 217*0Sstevel@tonic-gate look = ", Current volname: "; 218*0Sstevel@tonic-gate n = (int)strlen(look); 219*0Sstevel@tonic-gate } else if (pvolname == NULL) { 220*0Sstevel@tonic-gate pvolname = pt; 221*0Sstevel@tonic-gate look = ", Blocks: "; 222*0Sstevel@tonic-gate n = (int)strlen(look); 223*0Sstevel@tonic-gate } else 224*0Sstevel@tonic-gate break; 225*0Sstevel@tonic-gate } else 226*0Sstevel@tonic-gate pt++; 227*0Sstevel@tonic-gate } 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate if (strcmp(fsname, pfsname) || strcmp(volname, pvolname)) { 230*0Sstevel@tonic-gate /* mismatched label */ 231*0Sstevel@tonic-gate if (flag) { 232*0Sstevel@tonic-gate (void) sprintf(label, "%s,%s", pfsname, pvolname); 233*0Sstevel@tonic-gate } else { 234*0Sstevel@tonic-gate labelerr(pfsname, pvolname); 235*0Sstevel@tonic-gate return (1); 236*0Sstevel@tonic-gate } 237*0Sstevel@tonic-gate } 238*0Sstevel@tonic-gate return (0); 239*0Sstevel@tonic-gate } 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gate static int 242*0Sstevel@tonic-gate wilabel(char *label) 243*0Sstevel@tonic-gate { 244*0Sstevel@tonic-gate char buffer[512]; 245*0Sstevel@tonic-gate char fsname[LABELSIZ+1]; 246*0Sstevel@tonic-gate char volname[LABELSIZ+1]; 247*0Sstevel@tonic-gate int n; 248*0Sstevel@tonic-gate 249*0Sstevel@tonic-gate if (!label || !strlen(origfsname)) { 250*0Sstevel@tonic-gate if (n = ckstr(fsname, NULL, LABELSIZ, NULL, NULL, NULL, 251*0Sstevel@tonic-gate "Enter text for fsname label:")) 252*0Sstevel@tonic-gate return (n); 253*0Sstevel@tonic-gate } else 254*0Sstevel@tonic-gate (void) strcpy(fsname, origfsname); 255*0Sstevel@tonic-gate if (!label || !strlen(origvolname)) { 256*0Sstevel@tonic-gate if (n = ckstr(volname, NULL, LABELSIZ, NULL, NULL, NULL, 257*0Sstevel@tonic-gate "Enter text for volume label:")) 258*0Sstevel@tonic-gate return (n); 259*0Sstevel@tonic-gate } else 260*0Sstevel@tonic-gate (void) strcpy(volname, origvolname); 261*0Sstevel@tonic-gate 262*0Sstevel@tonic-gate if (IFTAPE(cdevice)) { 263*0Sstevel@tonic-gate (void) sprintf(buffer, "/etc/labelit %s \"%s\" \"%s\" -n 1>&2", 264*0Sstevel@tonic-gate cdevice, fsname, volname); 265*0Sstevel@tonic-gate } else { 266*0Sstevel@tonic-gate (void) sprintf(buffer, "/etc/labelit %s \"%s\" \"%s\" 1>&2", 267*0Sstevel@tonic-gate cdevice, fsname, volname); 268*0Sstevel@tonic-gate } 269*0Sstevel@tonic-gate if (system(buffer)) { 270*0Sstevel@tonic-gate (void) fprintf(stderr, "\nWrite of label to %s failed.", pname); 271*0Sstevel@tonic-gate return (1); 272*0Sstevel@tonic-gate } 273*0Sstevel@tonic-gate if (label) 274*0Sstevel@tonic-gate (void) sprintf(label, "%s,%s", fsname, volname); 275*0Sstevel@tonic-gate return (0); 276*0Sstevel@tonic-gate } 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate static void 279*0Sstevel@tonic-gate elabel(void) 280*0Sstevel@tonic-gate { 281*0Sstevel@tonic-gate } 282*0Sstevel@tonic-gate 283*0Sstevel@tonic-gate static int 284*0Sstevel@tonic-gate insert(char *device, char *label, int options, char *prompt) 285*0Sstevel@tonic-gate { 286*0Sstevel@tonic-gate int n; 287*0Sstevel@tonic-gate char strval[16], prmpt[BUFSIZ]; 288*0Sstevel@tonic-gate char *pt, *keyword[10]; 289*0Sstevel@tonic-gate char *fmtcmd; 290*0Sstevel@tonic-gate char *mkfscmd; 291*0Sstevel@tonic-gate char *voltxt; 292*0Sstevel@tonic-gate char *removecmd; 293*0Sstevel@tonic-gate char *dev_type; 294*0Sstevel@tonic-gate 295*0Sstevel@tonic-gate voltxt = (volume ? volume : "volume"); 296*0Sstevel@tonic-gate 297*0Sstevel@tonic-gate fmtcmd = devattr(device, "fmtcmd"); 298*0Sstevel@tonic-gate mkfscmd = devattr(device, "mkfscmd"); 299*0Sstevel@tonic-gate removecmd = devattr(device, "removecmd"); 300*0Sstevel@tonic-gate dev_type = devattr(device, "type"); 301*0Sstevel@tonic-gate 302*0Sstevel@tonic-gate if (prompt) { 303*0Sstevel@tonic-gate (void) strcpy(prmpt, prompt); 304*0Sstevel@tonic-gate for (pt = prmpt; *prompt; ) { 305*0Sstevel@tonic-gate if ((*prompt == '\\') && (prompt[1] == '%')) 306*0Sstevel@tonic-gate prompt++; 307*0Sstevel@tonic-gate else if (*prompt == '%') { 308*0Sstevel@tonic-gate switch (prompt[1]) { 309*0Sstevel@tonic-gate case 'v': 310*0Sstevel@tonic-gate (void) strcpy(pt, voltxt); 311*0Sstevel@tonic-gate break; 312*0Sstevel@tonic-gate 313*0Sstevel@tonic-gate case 'p': 314*0Sstevel@tonic-gate (void) strcpy(pt, pname); 315*0Sstevel@tonic-gate break; 316*0Sstevel@tonic-gate 317*0Sstevel@tonic-gate default: 318*0Sstevel@tonic-gate *pt = '\0'; 319*0Sstevel@tonic-gate break; 320*0Sstevel@tonic-gate } 321*0Sstevel@tonic-gate pt = pt + strlen(pt); 322*0Sstevel@tonic-gate prompt += 2; 323*0Sstevel@tonic-gate continue; 324*0Sstevel@tonic-gate } 325*0Sstevel@tonic-gate *pt++ = *prompt++; 326*0Sstevel@tonic-gate } 327*0Sstevel@tonic-gate *pt = '\0'; 328*0Sstevel@tonic-gate } else { 329*0Sstevel@tonic-gate (void) sprintf(prmpt, "Insert a %s into %s.", voltxt, pname); 330*0Sstevel@tonic-gate if (label && (options & DM_ELABEL)) { 331*0Sstevel@tonic-gate (void) strcat(prmpt, " The following external label "); 332*0Sstevel@tonic-gate (void) sprintf(prmpt+strlen(prmpt), 333*0Sstevel@tonic-gate " should appear on the %s:\\n\\t%s", 334*0Sstevel@tonic-gate voltxt, label); 335*0Sstevel@tonic-gate } 336*0Sstevel@tonic-gate if (label && !(options & DM_ELABEL)) { 337*0Sstevel@tonic-gate (void) sprintf(prmpt+strlen(prmpt), 338*0Sstevel@tonic-gate " The %s should be internally labeled as follows:", 339*0Sstevel@tonic-gate voltxt); 340*0Sstevel@tonic-gate (void) sprintf(prmpt+strlen(prmpt), 341*0Sstevel@tonic-gate "\\n\\t%s\\n", label); 342*0Sstevel@tonic-gate } 343*0Sstevel@tonic-gate } 344*0Sstevel@tonic-gate 345*0Sstevel@tonic-gate pt = prompt = prmpt + strlen(prmpt); 346*0Sstevel@tonic-gate 347*0Sstevel@tonic-gate n = 0; 348*0Sstevel@tonic-gate pt += sprintf(pt, "\\nType [go] when ready"); 349*0Sstevel@tonic-gate keyword[n++] = "go"; 350*0Sstevel@tonic-gate 351*0Sstevel@tonic-gate if (options & DM_FORMFS) { 352*0Sstevel@tonic-gate if (fmtcmd && *fmtcmd && mkfscmd && *mkfscmd) { 353*0Sstevel@tonic-gate pt += sprintf(pt, FORMFS_MSG, voltxt); 354*0Sstevel@tonic-gate keyword[n++] = "f"; 355*0Sstevel@tonic-gate } else if (fmtcmd && *fmtcmd) { 356*0Sstevel@tonic-gate pt += sprintf(pt, FORMAT_MSG, voltxt); 357*0Sstevel@tonic-gate keyword[n++] = "f"; 358*0Sstevel@tonic-gate } 359*0Sstevel@tonic-gate if (mkfscmd && *mkfscmd) { 360*0Sstevel@tonic-gate pt += sprintf(pt, MAKEFS_MSG, voltxt); 361*0Sstevel@tonic-gate keyword[n++] = "m"; 362*0Sstevel@tonic-gate } 363*0Sstevel@tonic-gate } else if (options & DM_FORMAT) { 364*0Sstevel@tonic-gate if (fmtcmd && *fmtcmd) { 365*0Sstevel@tonic-gate pt += sprintf(pt, FORMAT_MSG, voltxt); 366*0Sstevel@tonic-gate keyword[n++] = "f"; 367*0Sstevel@tonic-gate } 368*0Sstevel@tonic-gate } 369*0Sstevel@tonic-gate if (options & DM_WLABEL) { 370*0Sstevel@tonic-gate pt += sprintf(pt, WLABEL_MSG, voltxt); 371*0Sstevel@tonic-gate keyword[n++] = "w"; 372*0Sstevel@tonic-gate } 373*0Sstevel@tonic-gate if (options & DM_OLABEL) { 374*0Sstevel@tonic-gate pt += sprintf(pt, OLABEL_MSG); 375*0Sstevel@tonic-gate keyword[n++] = "o"; 376*0Sstevel@tonic-gate } 377*0Sstevel@tonic-gate if (removecmd && *removecmd && dev_type && *dev_type) { 378*0Sstevel@tonic-gate if (strcmp(dev_type, "diskette") == 0) { 379*0Sstevel@tonic-gate pt += sprintf(pt, EJECT_MSG, voltxt); 380*0Sstevel@tonic-gate keyword[n++] = "e"; 381*0Sstevel@tonic-gate } else { 382*0Sstevel@tonic-gate pt += sprintf(pt, UNLOAD_MSG, voltxt); 383*0Sstevel@tonic-gate keyword[n++] = "u"; 384*0Sstevel@tonic-gate } 385*0Sstevel@tonic-gate } 386*0Sstevel@tonic-gate keyword[n] = NULL; 387*0Sstevel@tonic-gate if (ckquit) 388*0Sstevel@tonic-gate pt += sprintf(pt, QUIT_MSG); 389*0Sstevel@tonic-gate *pt++ = ':'; 390*0Sstevel@tonic-gate *pt = '\0'; 391*0Sstevel@tonic-gate 392*0Sstevel@tonic-gate pt = prmpt; 393*0Sstevel@tonic-gate (void) fprintf(stderr, BELL); 394*0Sstevel@tonic-gate for (;;) { 395*0Sstevel@tonic-gate if (n = ckkeywd(strval, keyword, NULL, NULL, NULL, pt)) 396*0Sstevel@tonic-gate return (n); 397*0Sstevel@tonic-gate 398*0Sstevel@tonic-gate pt = prompt; /* next prompt is only partial */ 399*0Sstevel@tonic-gate if (*strval == 'f') { 400*0Sstevel@tonic-gate if (options & DM_FORMFS) 401*0Sstevel@tonic-gate doformat(voltxt, fmtcmd, mkfscmd); 402*0Sstevel@tonic-gate else 403*0Sstevel@tonic-gate doformat(voltxt, fmtcmd, NULL); 404*0Sstevel@tonic-gate continue; 405*0Sstevel@tonic-gate } else if (*strval == 'm') { 406*0Sstevel@tonic-gate doformat(voltxt, NULL, mkfscmd); 407*0Sstevel@tonic-gate continue; 408*0Sstevel@tonic-gate } else if (*strval == 'e' || *strval == 'u') { 409*0Sstevel@tonic-gate (void) doremovecmd(device, 1); 410*0Sstevel@tonic-gate continue; 411*0Sstevel@tonic-gate } else if (*strval == 'w') { 412*0Sstevel@tonic-gate (void) wilabel(label); 413*0Sstevel@tonic-gate continue; 414*0Sstevel@tonic-gate } else if (*strval == 'o') 415*0Sstevel@tonic-gate return (-1); 416*0Sstevel@tonic-gate break; 417*0Sstevel@tonic-gate } 418*0Sstevel@tonic-gate return (0); 419*0Sstevel@tonic-gate } 420*0Sstevel@tonic-gate 421*0Sstevel@tonic-gate static void 422*0Sstevel@tonic-gate doformat(char *voltxt, char *fmtcmd, char *mkfscmd) 423*0Sstevel@tonic-gate { 424*0Sstevel@tonic-gate char buffer[512]; 425*0Sstevel@tonic-gate 426*0Sstevel@tonic-gate if (fmtcmd && *fmtcmd) { 427*0Sstevel@tonic-gate (void) fprintf(stderr, "\t[%s]\n", fmtcmd); 428*0Sstevel@tonic-gate (void) sprintf(buffer, "(%s) 1>&2", fmtcmd); 429*0Sstevel@tonic-gate if (system(buffer)) { 430*0Sstevel@tonic-gate (void) fprintf(stderr, ERR_FMT, voltxt); 431*0Sstevel@tonic-gate return; 432*0Sstevel@tonic-gate } 433*0Sstevel@tonic-gate } 434*0Sstevel@tonic-gate if (mkfscmd && *mkfscmd) { 435*0Sstevel@tonic-gate (void) fprintf(stderr, "\t[%s]\n", mkfscmd); 436*0Sstevel@tonic-gate (void) sprintf(buffer, "(%s) 1>&2", mkfscmd); 437*0Sstevel@tonic-gate if (system(buffer)) { 438*0Sstevel@tonic-gate (void) fprintf(stderr, ERR_MKFS, voltxt); 439*0Sstevel@tonic-gate return; 440*0Sstevel@tonic-gate } 441*0Sstevel@tonic-gate } 442*0Sstevel@tonic-gate } 443*0Sstevel@tonic-gate 444*0Sstevel@tonic-gate void 445*0Sstevel@tonic-gate doremovecmd(char *device, int echo) 446*0Sstevel@tonic-gate { 447*0Sstevel@tonic-gate char *removecmd; 448*0Sstevel@tonic-gate char buffer[512]; 449*0Sstevel@tonic-gate 450*0Sstevel@tonic-gate if (device && *device) { 451*0Sstevel@tonic-gate removecmd = devattr(device, "removecmd"); 452*0Sstevel@tonic-gate if (removecmd && *removecmd) { 453*0Sstevel@tonic-gate if (echo) 454*0Sstevel@tonic-gate (void) fprintf(stderr, "\t[%s]\n", removecmd); 455*0Sstevel@tonic-gate (void) sprintf(buffer, "(%s) 1>&2", removecmd); 456*0Sstevel@tonic-gate if (system(buffer)) { 457*0Sstevel@tonic-gate if (echo) 458*0Sstevel@tonic-gate (void) fprintf(stderr, ERR_REMOVE, 459*0Sstevel@tonic-gate removecmd); 460*0Sstevel@tonic-gate return; 461*0Sstevel@tonic-gate } 462*0Sstevel@tonic-gate } 463*0Sstevel@tonic-gate } 464*0Sstevel@tonic-gate } 465*0Sstevel@tonic-gate 466*0Sstevel@tonic-gate static void 467*0Sstevel@tonic-gate labelerr(char *fsname, char *volname) 468*0Sstevel@tonic-gate { 469*0Sstevel@tonic-gate (void) fprintf(stderr, "\nLabel incorrect.\n"); 470*0Sstevel@tonic-gate if (volume) 471*0Sstevel@tonic-gate (void) fprintf(stderr, 472*0Sstevel@tonic-gate "The internal label on the inserted %s is\n", volume); 473*0Sstevel@tonic-gate else 474*0Sstevel@tonic-gate (void) fprintf(stderr, "The internal label for %s is", pname); 475*0Sstevel@tonic-gate (void) fprintf(stderr, "\t%s,%s\n", fsname, volname); 476*0Sstevel@tonic-gate } 477