17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
237c478bd9Sstevel@tonic-gate /* All Rights Reserved */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * Copyright (c) 1997, by Sun Microsystems, Inc.
287c478bd9Sstevel@tonic-gate * All rights reserved.
297c478bd9Sstevel@tonic-gate */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <devmgmt.h>
377c478bd9Sstevel@tonic-gate #include "libadm.h"
387c478bd9Sstevel@tonic-gate #include <stdlib.h>
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #define LABELSIZ 6
417c478bd9Sstevel@tonic-gate #define BELL "\007"
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate #define FORMFS_MSG ",\\n\\ \\ or [f] to format %s and place a filesystem on it"
447c478bd9Sstevel@tonic-gate #define FORMAT_MSG ",\\n\\ \\ or [f] to format the %s"
457c478bd9Sstevel@tonic-gate #define MAKEFS_MSG ",\\n\\ \\ or [m] to place a filesystem on %s"
467c478bd9Sstevel@tonic-gate #define EJECT_MSG ",\\n\\ \\ or [e] to eject the %s"
477c478bd9Sstevel@tonic-gate #define UNLOAD_MSG ",\\n\\ \\ or [u] to unload/offline the %s"
487c478bd9Sstevel@tonic-gate #define WLABEL_MSG ",\\n\\ \\ or [w] to write a new label on the %s"
497c478bd9Sstevel@tonic-gate #define OLABEL_MSG ",\\n\\ \\ or [o] to use the current label anyway"
507c478bd9Sstevel@tonic-gate #define QUIT_MSG ",\\n\\ \\ or [q] to quit"
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate #define ERR_ACCESS "\n%s (%s) cannot be accessed.\n"
537c478bd9Sstevel@tonic-gate #define ERR_FMT "\nAttempt to format %s failed.\n"
547c478bd9Sstevel@tonic-gate #define ERR_MKFS "\nAttempt to place filesystem on %s failed.\n"
557c478bd9Sstevel@tonic-gate #define ERR_REMOVE "\nExecution of \"removecmd\"[%s] failed.\n"
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate static void elabel(void);
587c478bd9Sstevel@tonic-gate static void doformat(char *, char *, char *);
597c478bd9Sstevel@tonic-gate static void labelerr(char *, char *);
607c478bd9Sstevel@tonic-gate static int ckilabel(char *, int);
617c478bd9Sstevel@tonic-gate static int insert(char *, char *, int, char *);
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate static char *cdevice; /* character device name */
647c478bd9Sstevel@tonic-gate static char *pname; /* device presentation name */
657c478bd9Sstevel@tonic-gate static char *volume; /* volume name */
667c478bd9Sstevel@tonic-gate static char origfsname[LABELSIZ+1];
677c478bd9Sstevel@tonic-gate static char origvolname[LABELSIZ+1];
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate * Return:
717c478bd9Sstevel@tonic-gate * 0 - okay, label matches
727c478bd9Sstevel@tonic-gate * 1 - device not accessable
737c478bd9Sstevel@tonic-gate * 2 - unknown device (devattr failed)
747c478bd9Sstevel@tonic-gate * 3 - user selected quit
757c478bd9Sstevel@tonic-gate * 4 - label does not match
767c478bd9Sstevel@tonic-gate */
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate * macros from labelit to behave correctly for tape
807c478bd9Sstevel@tonic-gate * is a kludge, should use devmgmt
817c478bd9Sstevel@tonic-gate */
827c478bd9Sstevel@tonic-gate #ifdef RT
837c478bd9Sstevel@tonic-gate #define IFTAPE(s) ((strncmp(s, "/dev/mt", 7) == 0) || \
847c478bd9Sstevel@tonic-gate (strncmp(s, "mt", 2) == 0))
857c478bd9Sstevel@tonic-gate #define TAPENAMES "'/dev/mt'"
867c478bd9Sstevel@tonic-gate #else
877c478bd9Sstevel@tonic-gate #define IFTAPE(s) ((strncmp(s, "/dev/rmt", 8) == 0) || \
887c478bd9Sstevel@tonic-gate (strncmp(s, "rmt", 3) == 0) || (strncmp(s, "/dev/rtp", 8) == 0) || \
897c478bd9Sstevel@tonic-gate (strncmp(s, "rtp", 3) == 0))
907c478bd9Sstevel@tonic-gate #define TAPENAMES "'/dev/rmt' or '/dev/rtp'"
917c478bd9Sstevel@tonic-gate #endif
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate int
getvol(char * device,char * label,int options,char * prompt)947c478bd9Sstevel@tonic-gate getvol(char *device, char *label, int options, char *prompt)
957c478bd9Sstevel@tonic-gate {
967c478bd9Sstevel@tonic-gate return (_getvol(device, label, options, prompt, NULL));
977c478bd9Sstevel@tonic-gate }
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate int
_getvol(char * device,char * label,int options,char * prompt,char * norewind)1007c478bd9Sstevel@tonic-gate _getvol(char *device, char *label, int options, char *prompt, char *norewind)
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate FILE *tmp;
1037c478bd9Sstevel@tonic-gate char *advice, *pt;
1047c478bd9Sstevel@tonic-gate int n, override;
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate cdevice = devattr(device, "cdevice");
1077c478bd9Sstevel@tonic-gate if ((cdevice == NULL) || !cdevice[0]) {
1087c478bd9Sstevel@tonic-gate cdevice = devattr(device, "pathname");
1097c478bd9Sstevel@tonic-gate if ((cdevice == NULL) || !cdevice)
1107c478bd9Sstevel@tonic-gate return (2); /* bad device */
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate pname = devattr(device, "desc");
1147c478bd9Sstevel@tonic-gate if (pname == NULL) {
1157c478bd9Sstevel@tonic-gate pname = devattr(device, "alias");
1167c478bd9Sstevel@tonic-gate if (!pname)
1177c478bd9Sstevel@tonic-gate pname = device;
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate volume = devattr(device, "volume");
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate if (label) {
1237c478bd9Sstevel@tonic-gate (void) strncpy(origfsname, label, LABELSIZ);
1247c478bd9Sstevel@tonic-gate origfsname[LABELSIZ] = '\0';
1257c478bd9Sstevel@tonic-gate if (pt = strchr(origfsname, ',')) {
1267c478bd9Sstevel@tonic-gate *pt = '\0';
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate if (pt = strchr(label, ',')) {
1297c478bd9Sstevel@tonic-gate (void) strncpy(origvolname, pt+1, LABELSIZ);
1307c478bd9Sstevel@tonic-gate origvolname[LABELSIZ] = '\0';
1317c478bd9Sstevel@tonic-gate } else
1327c478bd9Sstevel@tonic-gate origvolname[0] = '\0';
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate override = 0;
1367c478bd9Sstevel@tonic-gate for (;;) {
1377c478bd9Sstevel@tonic-gate if (!(options & DM_BATCH) && volume) {
1387c478bd9Sstevel@tonic-gate n = insert(device, label, options, prompt);
1397c478bd9Sstevel@tonic-gate if (n < 0)
1407c478bd9Sstevel@tonic-gate override++;
1417c478bd9Sstevel@tonic-gate else if (n)
1427c478bd9Sstevel@tonic-gate return (n); /* input function failed */
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate if ((tmp = fopen(norewind ? norewind : cdevice, "r")) == NULL) {
1467c478bd9Sstevel@tonic-gate /* device was not accessible */
1477c478bd9Sstevel@tonic-gate if (options & DM_BATCH)
1487c478bd9Sstevel@tonic-gate return (1);
1497c478bd9Sstevel@tonic-gate (void) fprintf(stderr, ERR_ACCESS, pname, cdevice);
1507c478bd9Sstevel@tonic-gate if ((options & DM_BATCH) || (volume == NULL))
1517c478bd9Sstevel@tonic-gate return (1);
1527c478bd9Sstevel@tonic-gate /* display advice on how to ready device */
1537c478bd9Sstevel@tonic-gate if (advice = devattr(device, "advice"))
1547c478bd9Sstevel@tonic-gate (void) puttext(stderr, advice, 0, 0);
1557c478bd9Sstevel@tonic-gate continue;
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate (void) fclose(tmp);
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate /* check label on device */
1607c478bd9Sstevel@tonic-gate if (label) {
1617c478bd9Sstevel@tonic-gate if (options & DM_ELABEL)
1627c478bd9Sstevel@tonic-gate elabel();
1637c478bd9Sstevel@tonic-gate else {
1647c478bd9Sstevel@tonic-gate /* check internal label using /etc/labelit */
1657c478bd9Sstevel@tonic-gate if (ckilabel(label, override)) {
1667c478bd9Sstevel@tonic-gate if ((options & DM_BATCH) ||
1677c478bd9Sstevel@tonic-gate volume == NULL)
1687c478bd9Sstevel@tonic-gate return (4);
1697c478bd9Sstevel@tonic-gate continue;
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate break;
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate return (0);
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate static int
ckilabel(char * label,int flag)1797c478bd9Sstevel@tonic-gate ckilabel(char *label, int flag)
1807c478bd9Sstevel@tonic-gate {
1817c478bd9Sstevel@tonic-gate FILE *pp;
1827c478bd9Sstevel@tonic-gate char *pt, *look, buffer[512];
1837c478bd9Sstevel@tonic-gate char fsname[LABELSIZ+1], volname[LABELSIZ+1];
1847c478bd9Sstevel@tonic-gate char *pvolname, *pfsname;
1857c478bd9Sstevel@tonic-gate int n, c;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate (void) strncpy(fsname, label, LABELSIZ);
1887c478bd9Sstevel@tonic-gate fsname[LABELSIZ] = '\0';
1897c478bd9Sstevel@tonic-gate if (pt = strchr(fsname, ',')) {
1907c478bd9Sstevel@tonic-gate *pt = '\0';
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate if (pt = strchr(label, ',')) {
1937c478bd9Sstevel@tonic-gate (void) strncpy(volname, pt+1, LABELSIZ);
1947c478bd9Sstevel@tonic-gate volname[LABELSIZ] = '\0';
1957c478bd9Sstevel@tonic-gate } else
1967c478bd9Sstevel@tonic-gate volname[0] = '\0';
1977c478bd9Sstevel@tonic-gate
198*4656d474SGarrett D'Amore (void) snprintf(buffer, sizeof (buffer), "/etc/labelit %s", cdevice);
1997c478bd9Sstevel@tonic-gate pp = popen(buffer, "r");
2007c478bd9Sstevel@tonic-gate pt = buffer;
2017c478bd9Sstevel@tonic-gate while ((c = getc(pp)) != EOF)
2027c478bd9Sstevel@tonic-gate *pt++ = (char)c;
2037c478bd9Sstevel@tonic-gate *pt = '\0';
2047c478bd9Sstevel@tonic-gate (void) pclose(pp);
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate pt = buffer;
2077c478bd9Sstevel@tonic-gate pfsname = pvolname = NULL;
2087c478bd9Sstevel@tonic-gate look = "Current fsname: ";
2097c478bd9Sstevel@tonic-gate n = (int)strlen(look);
2107c478bd9Sstevel@tonic-gate while (*pt) {
2117c478bd9Sstevel@tonic-gate if (strncmp(pt, look, n) == 0) {
2127c478bd9Sstevel@tonic-gate *pt = '\0';
2137c478bd9Sstevel@tonic-gate pt += strlen(look);
2147c478bd9Sstevel@tonic-gate if (pfsname == NULL) {
2157c478bd9Sstevel@tonic-gate pfsname = pt;
2167c478bd9Sstevel@tonic-gate look = ", Current volname: ";
2177c478bd9Sstevel@tonic-gate n = (int)strlen(look);
2187c478bd9Sstevel@tonic-gate } else if (pvolname == NULL) {
2197c478bd9Sstevel@tonic-gate pvolname = pt;
2207c478bd9Sstevel@tonic-gate look = ", Blocks: ";
2217c478bd9Sstevel@tonic-gate n = (int)strlen(look);
2227c478bd9Sstevel@tonic-gate } else
2237c478bd9Sstevel@tonic-gate break;
2247c478bd9Sstevel@tonic-gate } else
2257c478bd9Sstevel@tonic-gate pt++;
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate if (strcmp(fsname, pfsname) || strcmp(volname, pvolname)) {
2297c478bd9Sstevel@tonic-gate /* mismatched label */
2307c478bd9Sstevel@tonic-gate if (flag) {
231*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
2327c478bd9Sstevel@tonic-gate (void) sprintf(label, "%s,%s", pfsname, pvolname);
2337c478bd9Sstevel@tonic-gate } else {
2347c478bd9Sstevel@tonic-gate labelerr(pfsname, pvolname);
2357c478bd9Sstevel@tonic-gate return (1);
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate return (0);
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate static int
wilabel(char * label)2427c478bd9Sstevel@tonic-gate wilabel(char *label)
2437c478bd9Sstevel@tonic-gate {
2447c478bd9Sstevel@tonic-gate char buffer[512];
2457c478bd9Sstevel@tonic-gate char fsname[LABELSIZ+1];
2467c478bd9Sstevel@tonic-gate char volname[LABELSIZ+1];
2477c478bd9Sstevel@tonic-gate int n;
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate if (!label || !strlen(origfsname)) {
2507c478bd9Sstevel@tonic-gate if (n = ckstr(fsname, NULL, LABELSIZ, NULL, NULL, NULL,
2517c478bd9Sstevel@tonic-gate "Enter text for fsname label:"))
2527c478bd9Sstevel@tonic-gate return (n);
2537c478bd9Sstevel@tonic-gate } else
2547c478bd9Sstevel@tonic-gate (void) strcpy(fsname, origfsname);
2557c478bd9Sstevel@tonic-gate if (!label || !strlen(origvolname)) {
2567c478bd9Sstevel@tonic-gate if (n = ckstr(volname, NULL, LABELSIZ, NULL, NULL, NULL,
2577c478bd9Sstevel@tonic-gate "Enter text for volume label:"))
2587c478bd9Sstevel@tonic-gate return (n);
2597c478bd9Sstevel@tonic-gate } else
2607c478bd9Sstevel@tonic-gate (void) strcpy(volname, origvolname);
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate if (IFTAPE(cdevice)) {
263*4656d474SGarrett D'Amore (void) snprintf(buffer, sizeof (buffer),
264*4656d474SGarrett D'Amore "/etc/labelit %s \"%s\" \"%s\" -n 1>&2",
2657c478bd9Sstevel@tonic-gate cdevice, fsname, volname);
2667c478bd9Sstevel@tonic-gate } else {
267*4656d474SGarrett D'Amore (void) snprintf(buffer, sizeof (buffer),
268*4656d474SGarrett D'Amore "/etc/labelit %s \"%s\" \"%s\" 1>&2",
2697c478bd9Sstevel@tonic-gate cdevice, fsname, volname);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate if (system(buffer)) {
2727c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\nWrite of label to %s failed.", pname);
2737c478bd9Sstevel@tonic-gate return (1);
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate if (label)
276*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
2777c478bd9Sstevel@tonic-gate (void) sprintf(label, "%s,%s", fsname, volname);
2787c478bd9Sstevel@tonic-gate return (0);
2797c478bd9Sstevel@tonic-gate }
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate static void
elabel(void)2827c478bd9Sstevel@tonic-gate elabel(void)
2837c478bd9Sstevel@tonic-gate {
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate
2867c478bd9Sstevel@tonic-gate static int
insert(char * device,char * label,int options,char * prompt)2877c478bd9Sstevel@tonic-gate insert(char *device, char *label, int options, char *prompt)
2887c478bd9Sstevel@tonic-gate {
2897c478bd9Sstevel@tonic-gate int n;
2907c478bd9Sstevel@tonic-gate char strval[16], prmpt[BUFSIZ];
2917c478bd9Sstevel@tonic-gate char *pt, *keyword[10];
2927c478bd9Sstevel@tonic-gate char *fmtcmd;
2937c478bd9Sstevel@tonic-gate char *mkfscmd;
2947c478bd9Sstevel@tonic-gate char *voltxt;
2957c478bd9Sstevel@tonic-gate char *removecmd;
2967c478bd9Sstevel@tonic-gate char *dev_type;
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate voltxt = (volume ? volume : "volume");
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate fmtcmd = devattr(device, "fmtcmd");
3017c478bd9Sstevel@tonic-gate mkfscmd = devattr(device, "mkfscmd");
3027c478bd9Sstevel@tonic-gate removecmd = devattr(device, "removecmd");
3037c478bd9Sstevel@tonic-gate dev_type = devattr(device, "type");
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate if (prompt) {
306*4656d474SGarrett D'Amore (void) strlcpy(prmpt, prompt, sizeof (prmpt));
3077c478bd9Sstevel@tonic-gate for (pt = prmpt; *prompt; ) {
3087c478bd9Sstevel@tonic-gate if ((*prompt == '\\') && (prompt[1] == '%'))
3097c478bd9Sstevel@tonic-gate prompt++;
3107c478bd9Sstevel@tonic-gate else if (*prompt == '%') {
3117c478bd9Sstevel@tonic-gate switch (prompt[1]) {
3127c478bd9Sstevel@tonic-gate case 'v':
3137c478bd9Sstevel@tonic-gate (void) strcpy(pt, voltxt);
3147c478bd9Sstevel@tonic-gate break;
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate case 'p':
3177c478bd9Sstevel@tonic-gate (void) strcpy(pt, pname);
3187c478bd9Sstevel@tonic-gate break;
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate default:
3217c478bd9Sstevel@tonic-gate *pt = '\0';
3227c478bd9Sstevel@tonic-gate break;
3237c478bd9Sstevel@tonic-gate }
3247c478bd9Sstevel@tonic-gate pt = pt + strlen(pt);
3257c478bd9Sstevel@tonic-gate prompt += 2;
3267c478bd9Sstevel@tonic-gate continue;
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate *pt++ = *prompt++;
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate *pt = '\0';
3317c478bd9Sstevel@tonic-gate } else {
332*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
3337c478bd9Sstevel@tonic-gate (void) sprintf(prmpt, "Insert a %s into %s.", voltxt, pname);
3347c478bd9Sstevel@tonic-gate if (label && (options & DM_ELABEL)) {
3357c478bd9Sstevel@tonic-gate (void) strcat(prmpt, " The following external label ");
336*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
3377c478bd9Sstevel@tonic-gate (void) sprintf(prmpt+strlen(prmpt),
3387c478bd9Sstevel@tonic-gate " should appear on the %s:\\n\\t%s",
3397c478bd9Sstevel@tonic-gate voltxt, label);
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate if (label && !(options & DM_ELABEL)) {
342*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
3437c478bd9Sstevel@tonic-gate (void) sprintf(prmpt+strlen(prmpt),
3447c478bd9Sstevel@tonic-gate " The %s should be internally labeled as follows:",
3457c478bd9Sstevel@tonic-gate voltxt);
346*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
3477c478bd9Sstevel@tonic-gate (void) sprintf(prmpt+strlen(prmpt),
3487c478bd9Sstevel@tonic-gate "\\n\\t%s\\n", label);
3497c478bd9Sstevel@tonic-gate }
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate pt = prompt = prmpt + strlen(prmpt);
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate n = 0;
3557c478bd9Sstevel@tonic-gate pt += sprintf(pt, "\\nType [go] when ready");
3567c478bd9Sstevel@tonic-gate keyword[n++] = "go";
3577c478bd9Sstevel@tonic-gate
3587c478bd9Sstevel@tonic-gate if (options & DM_FORMFS) {
3597c478bd9Sstevel@tonic-gate if (fmtcmd && *fmtcmd && mkfscmd && *mkfscmd) {
360*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
3617c478bd9Sstevel@tonic-gate pt += sprintf(pt, FORMFS_MSG, voltxt);
3627c478bd9Sstevel@tonic-gate keyword[n++] = "f";
3637c478bd9Sstevel@tonic-gate } else if (fmtcmd && *fmtcmd) {
364*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
3657c478bd9Sstevel@tonic-gate pt += sprintf(pt, FORMAT_MSG, voltxt);
3667c478bd9Sstevel@tonic-gate keyword[n++] = "f";
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate if (mkfscmd && *mkfscmd) {
369*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
3707c478bd9Sstevel@tonic-gate pt += sprintf(pt, MAKEFS_MSG, voltxt);
3717c478bd9Sstevel@tonic-gate keyword[n++] = "m";
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate } else if (options & DM_FORMAT) {
3747c478bd9Sstevel@tonic-gate if (fmtcmd && *fmtcmd) {
375*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
3767c478bd9Sstevel@tonic-gate pt += sprintf(pt, FORMAT_MSG, voltxt);
3777c478bd9Sstevel@tonic-gate keyword[n++] = "f";
3787c478bd9Sstevel@tonic-gate }
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate if (options & DM_WLABEL) {
381*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
3827c478bd9Sstevel@tonic-gate pt += sprintf(pt, WLABEL_MSG, voltxt);
3837c478bd9Sstevel@tonic-gate keyword[n++] = "w";
3847c478bd9Sstevel@tonic-gate }
3857c478bd9Sstevel@tonic-gate if (options & DM_OLABEL) {
3867c478bd9Sstevel@tonic-gate pt += sprintf(pt, OLABEL_MSG);
3877c478bd9Sstevel@tonic-gate keyword[n++] = "o";
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate if (removecmd && *removecmd && dev_type && *dev_type) {
3907c478bd9Sstevel@tonic-gate if (strcmp(dev_type, "diskette") == 0) {
391*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
3927c478bd9Sstevel@tonic-gate pt += sprintf(pt, EJECT_MSG, voltxt);
3937c478bd9Sstevel@tonic-gate keyword[n++] = "e";
3947c478bd9Sstevel@tonic-gate } else {
395*4656d474SGarrett D'Amore /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */
3967c478bd9Sstevel@tonic-gate pt += sprintf(pt, UNLOAD_MSG, voltxt);
3977c478bd9Sstevel@tonic-gate keyword[n++] = "u";
3987c478bd9Sstevel@tonic-gate }
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate keyword[n] = NULL;
4017c478bd9Sstevel@tonic-gate if (ckquit)
4027c478bd9Sstevel@tonic-gate pt += sprintf(pt, QUIT_MSG);
4037c478bd9Sstevel@tonic-gate *pt++ = ':';
4047c478bd9Sstevel@tonic-gate *pt = '\0';
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate pt = prmpt;
4077c478bd9Sstevel@tonic-gate (void) fprintf(stderr, BELL);
4087c478bd9Sstevel@tonic-gate for (;;) {
4097c478bd9Sstevel@tonic-gate if (n = ckkeywd(strval, keyword, NULL, NULL, NULL, pt))
4107c478bd9Sstevel@tonic-gate return (n);
4117c478bd9Sstevel@tonic-gate
4127c478bd9Sstevel@tonic-gate pt = prompt; /* next prompt is only partial */
4137c478bd9Sstevel@tonic-gate if (*strval == 'f') {
4147c478bd9Sstevel@tonic-gate if (options & DM_FORMFS)
4157c478bd9Sstevel@tonic-gate doformat(voltxt, fmtcmd, mkfscmd);
4167c478bd9Sstevel@tonic-gate else
4177c478bd9Sstevel@tonic-gate doformat(voltxt, fmtcmd, NULL);
4187c478bd9Sstevel@tonic-gate continue;
4197c478bd9Sstevel@tonic-gate } else if (*strval == 'm') {
4207c478bd9Sstevel@tonic-gate doformat(voltxt, NULL, mkfscmd);
4217c478bd9Sstevel@tonic-gate continue;
4227c478bd9Sstevel@tonic-gate } else if (*strval == 'e' || *strval == 'u') {
4237c478bd9Sstevel@tonic-gate (void) doremovecmd(device, 1);
4247c478bd9Sstevel@tonic-gate continue;
4257c478bd9Sstevel@tonic-gate } else if (*strval == 'w') {
4267c478bd9Sstevel@tonic-gate (void) wilabel(label);
4277c478bd9Sstevel@tonic-gate continue;
4287c478bd9Sstevel@tonic-gate } else if (*strval == 'o')
4297c478bd9Sstevel@tonic-gate return (-1);
4307c478bd9Sstevel@tonic-gate break;
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate return (0);
4337c478bd9Sstevel@tonic-gate }
4347c478bd9Sstevel@tonic-gate
4357c478bd9Sstevel@tonic-gate static void
doformat(char * voltxt,char * fmtcmd,char * mkfscmd)4367c478bd9Sstevel@tonic-gate doformat(char *voltxt, char *fmtcmd, char *mkfscmd)
4377c478bd9Sstevel@tonic-gate {
4387c478bd9Sstevel@tonic-gate char buffer[512];
4397c478bd9Sstevel@tonic-gate
4407c478bd9Sstevel@tonic-gate if (fmtcmd && *fmtcmd) {
4417c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\t[%s]\n", fmtcmd);
442*4656d474SGarrett D'Amore (void) snprintf(buffer, sizeof (buffer), "(%s) 1>&2", fmtcmd);
4437c478bd9Sstevel@tonic-gate if (system(buffer)) {
4447c478bd9Sstevel@tonic-gate (void) fprintf(stderr, ERR_FMT, voltxt);
4457c478bd9Sstevel@tonic-gate return;
4467c478bd9Sstevel@tonic-gate }
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate if (mkfscmd && *mkfscmd) {
4497c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\t[%s]\n", mkfscmd);
450*4656d474SGarrett D'Amore (void) snprintf(buffer, sizeof (buffer), "(%s) 1>&2", mkfscmd);
4517c478bd9Sstevel@tonic-gate if (system(buffer)) {
4527c478bd9Sstevel@tonic-gate (void) fprintf(stderr, ERR_MKFS, voltxt);
4537c478bd9Sstevel@tonic-gate return;
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate }
4567c478bd9Sstevel@tonic-gate }
4577c478bd9Sstevel@tonic-gate
4587c478bd9Sstevel@tonic-gate void
doremovecmd(char * device,int echo)4597c478bd9Sstevel@tonic-gate doremovecmd(char *device, int echo)
4607c478bd9Sstevel@tonic-gate {
4617c478bd9Sstevel@tonic-gate char *removecmd;
4627c478bd9Sstevel@tonic-gate char buffer[512];
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate if (device && *device) {
4657c478bd9Sstevel@tonic-gate removecmd = devattr(device, "removecmd");
4667c478bd9Sstevel@tonic-gate if (removecmd && *removecmd) {
4677c478bd9Sstevel@tonic-gate if (echo)
4687c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\t[%s]\n", removecmd);
469*4656d474SGarrett D'Amore (void) snprintf(buffer, sizeof (buffer),
470*4656d474SGarrett D'Amore "(%s) 1>&2", removecmd);
4717c478bd9Sstevel@tonic-gate if (system(buffer)) {
4727c478bd9Sstevel@tonic-gate if (echo)
4737c478bd9Sstevel@tonic-gate (void) fprintf(stderr, ERR_REMOVE,
4747c478bd9Sstevel@tonic-gate removecmd);
4757c478bd9Sstevel@tonic-gate return;
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate }
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate }
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate static void
labelerr(char * fsname,char * volname)4827c478bd9Sstevel@tonic-gate labelerr(char *fsname, char *volname)
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\nLabel incorrect.\n");
4857c478bd9Sstevel@tonic-gate if (volume)
4867c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
4877c478bd9Sstevel@tonic-gate "The internal label on the inserted %s is\n", volume);
4887c478bd9Sstevel@tonic-gate else
4897c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "The internal label for %s is", pname);
4907c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\t%s,%s\n", fsname, volname);
4917c478bd9Sstevel@tonic-gate }
492