xref: /titanic_53/usr/src/cmd/stmfadm/stmfadm.c (revision 2f624233c43c1f4fe0d930648d6ece6fffe7aa49)
1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte  * CDDL HEADER START
3fcf3ce44SJohn Forte  *
4fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte  *
8fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte  * and limitations under the License.
12fcf3ce44SJohn Forte  *
13fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte  *
19fcf3ce44SJohn Forte  * CDDL HEADER END
20fcf3ce44SJohn Forte  */
21fcf3ce44SJohn Forte /*
22e17f3b22Stim szeto  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fcf3ce44SJohn Forte  * Use is subject to license terms.
24fcf3ce44SJohn Forte  */
25fcf3ce44SJohn Forte 
26fcf3ce44SJohn Forte #include <stdlib.h>
27fcf3ce44SJohn Forte #include <stdio.h>
28fcf3ce44SJohn Forte #include <strings.h>
29fcf3ce44SJohn Forte #include <sys/types.h>
30fcf3ce44SJohn Forte #include <unistd.h>
31fcf3ce44SJohn Forte #include <wchar.h>
32fcf3ce44SJohn Forte #include <libintl.h>
33fcf3ce44SJohn Forte #include <errno.h>
34fcf3ce44SJohn Forte #include <time.h>
35fcf3ce44SJohn Forte #include <string.h>
36fcf3ce44SJohn Forte #include <assert.h>
37fcf3ce44SJohn Forte #include <getopt.h>
38fcf3ce44SJohn Forte #include <cmdparse.h>
39fcf3ce44SJohn Forte #include <stmfadm.h>
40fcf3ce44SJohn Forte #include <libstmf.h>
41fcf3ce44SJohn Forte #include <signal.h>
42fcf3ce44SJohn Forte #include <pthread.h>
43fcf3ce44SJohn Forte #include <locale.h>
44fcf3ce44SJohn Forte 
45fcf3ce44SJohn Forte static int addHostGroupMemberFunc(int, char **, cmdOptions_t *, void *);
46fcf3ce44SJohn Forte static int addTargetGroupMemberFunc(int, char **, cmdOptions_t *, void *);
47fcf3ce44SJohn Forte static int addViewFunc(int, char **, cmdOptions_t *, void *);
48fcf3ce44SJohn Forte static int createHostGroupFunc(int, char **, cmdOptions_t *, void *);
498fe96085Stim szeto static int createLuFunc(int, char **, cmdOptions_t *, void *);
508fe96085Stim szeto static int modifyLuFunc(int, char **, cmdOptions_t *, void *);
518fe96085Stim szeto static int importLuFunc(int, char **, cmdOptions_t *, void *);
528fe96085Stim szeto static int deleteLuFunc(int, char **, cmdOptions_t *, void *);
53fcf3ce44SJohn Forte static int createTargetGroupFunc(int, char **, cmdOptions_t *, void *);
54fcf3ce44SJohn Forte static int deleteHostGroupFunc(int, char **, cmdOptions_t *, void *);
55fcf3ce44SJohn Forte static int deleteTargetGroupFunc(int, char **, cmdOptions_t *, void *);
56fcf3ce44SJohn Forte static int listLuFunc(int, char **, cmdOptions_t *, void *);
57fcf3ce44SJohn Forte static int listTargetFunc(int, char **, cmdOptions_t *, void *);
58fcf3ce44SJohn Forte static int listViewFunc(int, char **, cmdOptions_t *, void *);
59fcf3ce44SJohn Forte static int listHostGroupFunc(int, char **, cmdOptions_t *, void *);
60fcf3ce44SJohn Forte static int listStateFunc(int, char **, cmdOptions_t *, void *);
61fcf3ce44SJohn Forte static int listTargetGroupFunc(int, char **, cmdOptions_t *, void *);
62fcf3ce44SJohn Forte static int offlineTargetFunc(int, char **, cmdOptions_t *, void *);
63fcf3ce44SJohn Forte static int offlineLuFunc(int, char **, cmdOptions_t *, void *);
64fcf3ce44SJohn Forte static int onlineTargetFunc(int, char **, cmdOptions_t *, void *);
65fcf3ce44SJohn Forte static int onlineLuFunc(int, char **, cmdOptions_t *, void *);
66fcf3ce44SJohn Forte static int onlineOfflineTarget(char *, int);
67fcf3ce44SJohn Forte static int onlineOfflineLu(char *, int);
68fcf3ce44SJohn Forte static int removeHostGroupMemberFunc(int, char **, cmdOptions_t *, void *);
69fcf3ce44SJohn Forte static int removeTargetGroupMemberFunc(int, char **, cmdOptions_t *, void *);
708fe96085Stim szeto static int callModify(char *, stmfGuid *, uint32_t, const char *, const char *);
71fcf3ce44SJohn Forte static int removeViewFunc(int, char **, cmdOptions_t *, void *);
72fcf3ce44SJohn Forte static char *getExecBasename(char *);
73fcf3ce44SJohn Forte static int parseDevid(char *input, stmfDevid *devid);
74fcf3ce44SJohn Forte static void printGroupProps(stmfGroupProperties *groupProps);
75fcf3ce44SJohn Forte static int checkScsiNameString(wchar_t *, stmfDevid *);
76fcf3ce44SJohn Forte static int checkHexUpper(char *);
77fcf3ce44SJohn Forte static int checkIscsiName(wchar_t *);
78fcf3ce44SJohn Forte static void printLuProps(stmfLogicalUnitProperties *luProps);
798fe96085Stim szeto static int printExtLuProps(stmfGuid *guid);
80fcf3ce44SJohn Forte static void printGuid(stmfGuid *guid, FILE *printWhere);
81fcf3ce44SJohn Forte static void printTargetProps(stmfTargetProperties *);
82fcf3ce44SJohn Forte static void printSessionProps(stmfSessionList *);
838fe96085Stim szeto static int setLuPropFromInput(luResource, char *);
848fe96085Stim szeto static int convertCharToPropId(char *, uint32_t *);
85fcf3ce44SJohn Forte 
86fcf3ce44SJohn Forte 
87fcf3ce44SJohn Forte 
88fcf3ce44SJohn Forte /*
89fcf3ce44SJohn Forte  *  MAJOR - This should only change when there is an incompatible change made
90fcf3ce44SJohn Forte  *  to the interfaces or the output.
91fcf3ce44SJohn Forte  *
92fcf3ce44SJohn Forte  *  MINOR - This should change whenever there is a new command or new feature
93fcf3ce44SJohn Forte  *  with no incompatible change.
94fcf3ce44SJohn Forte  */
95fcf3ce44SJohn Forte #define	VERSION_STRING_MAJOR	    "1"
96fcf3ce44SJohn Forte #define	VERSION_STRING_MINOR	    "0"
97fcf3ce44SJohn Forte #define	MAX_DEVID_INPUT		    256
98fcf3ce44SJohn Forte #define	GUID_INPUT		    32
99fcf3ce44SJohn Forte #define	MAX_LU_NBR		    16383
100fcf3ce44SJohn Forte #define	ONLINE_LU		    0
101fcf3ce44SJohn Forte #define	OFFLINE_LU		    1
102fcf3ce44SJohn Forte #define	ONLINE_TARGET		    2
103fcf3ce44SJohn Forte #define	OFFLINE_TARGET		    3
104fcf3ce44SJohn Forte #define	PROPS_FORMAT		    "    %-18s: "
105fcf3ce44SJohn Forte #define	VIEW_FORMAT		    "    %-13s: "
106fcf3ce44SJohn Forte #define	LVL3_FORMAT		    "        %s"
107fcf3ce44SJohn Forte #define	LVL4_FORMAT		    "            %s"
108fcf3ce44SJohn Forte 
109fcf3ce44SJohn Forte /* SCSI Name String length definitions */
110fcf3ce44SJohn Forte #define	SNS_EUI_16		    16
111fcf3ce44SJohn Forte #define	SNS_EUI_24		    24
112fcf3ce44SJohn Forte #define	SNS_EUI_32		    32
113fcf3ce44SJohn Forte #define	SNS_NAA_16		    16
114fcf3ce44SJohn Forte #define	SNS_NAA_32		    32
115fcf3ce44SJohn Forte #define	SNS_WWN_16		    16
116fcf3ce44SJohn Forte #define	SNS_IQN_223		    223
117fcf3ce44SJohn Forte 
1188fe96085Stim szeto /* LU Property strings */
1198fe96085Stim szeto #define	GUID			    "GUID"
1208fe96085Stim szeto #define	ALIAS			    "ALIAS"
1218fe96085Stim szeto #define	VID			    "VID"
1228fe96085Stim szeto #define	PID			    "PID"
1238fe96085Stim szeto #define	META_FILE		    "META"
1248fe96085Stim szeto #define	WRITE_PROTECT		    "WP"
1258fe96085Stim szeto #define	WRITEBACK_CACHE_DISABLE	    "WCD"
1268fe96085Stim szeto #define	COMPANY_ID		    "OUI"
1278fe96085Stim szeto #define	BLOCK_SIZE		    "BLK"
1288fe96085Stim szeto #define	SERIAL_NUMBER		    "SERIAL"
129*2f624233SNattuvetty Bhavyan #define	MGMT_URL		    "MGMT-URL"
1308fe96085Stim szeto 
1318fe96085Stim szeto #define	MODIFY_HELP "\n"\
1328fe96085Stim szeto "Description: Modify properties of a logical unit. \n" \
1338fe96085Stim szeto "Valid properties for -p, --lu-prop are: \n" \
1348fe96085Stim szeto "     alias    - alias for logical unit (up to 255 chars)\n" \
135*2f624233SNattuvetty Bhavyan "     mgmt-url - Management URL address\n" \
1368fe96085Stim szeto "     wcd      - write cache disabled (true, false)\n" \
1378fe96085Stim szeto "     wp       - write protect (true, false)\n\n" \
1388fe96085Stim szeto "-f alters the meaning of the operand to be a file name\n" \
1398fe96085Stim szeto "rather than a LU name. This allows for modification\n" \
1408fe96085Stim szeto "of a logical unit that is not yet imported into stmf\n"
1418fe96085Stim szeto 
1428fe96085Stim szeto #define	CREATE_HELP "\n"\
1438fe96085Stim szeto "Description: Create a logical unit. \n" \
1448fe96085Stim szeto "Valid properties for -p, --lu-prop are: \n" \
1458fe96085Stim szeto "     alias    - alias for logical unit (up to 255 chars)\n" \
1468fe96085Stim szeto "     blk      - block size in bytes in 2^n\n" \
1478fe96085Stim szeto "     guid     - 32 ascii hex characters in NAA format \n" \
1488fe96085Stim szeto "     meta     - separate meta data file name\n" \
149*2f624233SNattuvetty Bhavyan "     mgmt-url - Management URL address\n" \
1508fe96085Stim szeto "     oui      - organizational unique identifier\n" \
1518fe96085Stim szeto "                6 ascii hex characters of valid format\n" \
1528fe96085Stim szeto "     pid      - product identifier (up to 16 chars)\n" \
1538fe96085Stim szeto "     serial   - serial number (up to 252 chars)\n" \
1548fe96085Stim szeto "     vid      - vendor identifier (up to 8 chars)\n" \
155*2f624233SNattuvetty Bhavyan "     wcd      - write cache disabled (true, false)\n" \
156*2f624233SNattuvetty Bhavyan "     wp       - write protect (true, false)\n"
1578fe96085Stim szeto #define	ADD_VIEW_HELP "\n"\
1588fe96085Stim szeto "Description: Add a view entry to a logical unit. \n" \
1598fe96085Stim szeto "A view entry is comprised of three elements; the \n" \
1608fe96085Stim szeto "logical unit number, the target group name and the\n" \
1618fe96085Stim szeto "host group name. These three elements combine together\n" \
1628fe96085Stim szeto "to form a view for a given COMSTAR logical unit.\n" \
1638fe96085Stim szeto "This view is realized by a client, a SCSI initiator,\n" \
1648fe96085Stim szeto "via a REPORT LUNS command. \n"
1658fe96085Stim szeto 
1668fe96085Stim szeto 
1678fe96085Stim szeto 
168fcf3ce44SJohn Forte /* tables set up based on cmdparse instructions */
169fcf3ce44SJohn Forte 
170fcf3ce44SJohn Forte /* add new options here */
171fcf3ce44SJohn Forte optionTbl_t longOptions[] = {
172fcf3ce44SJohn Forte 	{"all", no_arg, 'a', NULL},
173fcf3ce44SJohn Forte 	{"group-name", required_arg, 'g', "group-name"},
1748fe96085Stim szeto 	{"keep-views", no_arg, 'k', NULL},
175fcf3ce44SJohn Forte 	{"lu-name", required_arg, 'l', "LU-Name"},
176fcf3ce44SJohn Forte 	{"lun", required_arg, 'n', "logical-unit-number"},
1778fe96085Stim szeto 	{"lu-prop", required_arg, 'p', "logical-unit-property=value"},
1788fe96085Stim szeto 	{"file", no_arg, 'f', "filename"},
1798fe96085Stim szeto 	{"size", required_arg, 's', "size K/M/G/T/P"},
180fcf3ce44SJohn Forte 	{"target-group", required_arg, 't', "group-name"},
181fcf3ce44SJohn Forte 	{"host-group", required_arg, 'h', "group-name"},
1828fe96085Stim szeto 	{"verbose", no_arg, 'v', NULL},
183fcf3ce44SJohn Forte 	{NULL, 0, 0, 0}
184fcf3ce44SJohn Forte };
185fcf3ce44SJohn Forte 
186fcf3ce44SJohn Forte /*
187fcf3ce44SJohn Forte  * Add new subcommands here
188fcf3ce44SJohn Forte  */
189fcf3ce44SJohn Forte subCommandProps_t subcommands[] = {
190fcf3ce44SJohn Forte 	{"add-hg-member", addHostGroupMemberFunc, "g", "g", NULL,
1918fe96085Stim szeto 		OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL},
192fcf3ce44SJohn Forte 	{"add-tg-member", addTargetGroupMemberFunc, "g", "g", NULL,
1938fe96085Stim szeto 		OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL},
194fcf3ce44SJohn Forte 	{"add-view", addViewFunc, "nth", NULL, NULL,
1958fe96085Stim szeto 		OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, ADD_VIEW_HELP},
196fcf3ce44SJohn Forte 	{"create-hg", createHostGroupFunc, NULL, NULL, NULL,
1978fe96085Stim szeto 		OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL},
198fcf3ce44SJohn Forte 	{"create-tg", createTargetGroupFunc, NULL, NULL, NULL,
1998fe96085Stim szeto 		OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL},
2008fe96085Stim szeto 	{"create-lu", createLuFunc, "ps", NULL, NULL, OPERAND_MANDATORY_SINGLE,
2018fe96085Stim szeto 		"lu file", CREATE_HELP},
202fcf3ce44SJohn Forte 	{"delete-hg", deleteHostGroupFunc, NULL, NULL, NULL,
2038fe96085Stim szeto 		OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL},
2048fe96085Stim szeto 	{"modify-lu", modifyLuFunc, "psf", NULL, NULL, OPERAND_MANDATORY_SINGLE,
2058fe96085Stim szeto 		OPERANDSTRING_LU, MODIFY_HELP},
2068fe96085Stim szeto 	{"delete-lu", deleteLuFunc, "k", NULL, NULL,
2078fe96085Stim szeto 		OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_LU, NULL},
208fcf3ce44SJohn Forte 	{"delete-tg", deleteTargetGroupFunc, NULL, NULL, NULL,
2098fe96085Stim szeto 		OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL},
2108fe96085Stim szeto 	{"import-lu", importLuFunc, NULL, NULL, NULL,
2118fe96085Stim szeto 		OPERAND_MANDATORY_SINGLE, "file name", NULL},
212fcf3ce44SJohn Forte 	{"list-hg", listHostGroupFunc, "v", NULL, NULL,
2138fe96085Stim szeto 		OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_GROUP_NAME, NULL},
214fcf3ce44SJohn Forte 	{"list-lu", listLuFunc, "v", NULL, NULL, OPERAND_OPTIONAL_MULTIPLE,
2158fe96085Stim szeto 		OPERANDSTRING_LU, NULL},
216fcf3ce44SJohn Forte 	{"list-state", listStateFunc, NULL, NULL, NULL, OPERAND_NONE, NULL},
217fcf3ce44SJohn Forte 	{"list-target", listTargetFunc, "v", NULL, NULL,
2188fe96085Stim szeto 		OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_TARGET, NULL},
219fcf3ce44SJohn Forte 	{"list-tg", listTargetGroupFunc, "v", NULL, NULL,
2208fe96085Stim szeto 		OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_GROUP_NAME, NULL},
221fcf3ce44SJohn Forte 	{"list-view", listViewFunc, "l", "l", NULL,
2228fe96085Stim szeto 		OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_VIEW_ENTRY, NULL},
223fcf3ce44SJohn Forte 	{"online-lu", onlineLuFunc, NULL, NULL, NULL,
2248fe96085Stim szeto 		OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL},
225fcf3ce44SJohn Forte 	{"offline-lu", offlineLuFunc, NULL, NULL, NULL,
2268fe96085Stim szeto 		OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL},
227fcf3ce44SJohn Forte 	{"online-target", onlineTargetFunc, NULL, NULL, NULL,
2288fe96085Stim szeto 		OPERAND_MANDATORY_SINGLE, OPERANDSTRING_TARGET, NULL},
229fcf3ce44SJohn Forte 	{"offline-target", offlineTargetFunc, NULL, NULL, NULL,
2308fe96085Stim szeto 		OPERAND_MANDATORY_SINGLE, OPERANDSTRING_TARGET, NULL},
231fcf3ce44SJohn Forte 	{"remove-hg-member", removeHostGroupMemberFunc, "g", "g", NULL,
2328fe96085Stim szeto 		OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL},
233fcf3ce44SJohn Forte 	{"remove-tg-member", removeTargetGroupMemberFunc, "g", "g", NULL,
2348fe96085Stim szeto 		OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL},
235fcf3ce44SJohn Forte 	{"remove-view", removeViewFunc, "la", "l", NULL,
2368fe96085Stim szeto 		OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_VIEW_ENTRY, NULL},
2378fe96085Stim szeto 	{NULL, 0, NULL, NULL, 0, NULL, 0, NULL, NULL}
238fcf3ce44SJohn Forte };
239fcf3ce44SJohn Forte 
240fcf3ce44SJohn Forte /* globals */
241fcf3ce44SJohn Forte char *cmdName;
242fcf3ce44SJohn Forte 
243fcf3ce44SJohn Forte /*
244fcf3ce44SJohn Forte  * addHostGroupMemberFunc
245fcf3ce44SJohn Forte  *
246fcf3ce44SJohn Forte  * Add members to a host group
247fcf3ce44SJohn Forte  *
248fcf3ce44SJohn Forte  */
249fcf3ce44SJohn Forte /*ARGSUSED*/
250fcf3ce44SJohn Forte static int
251fcf3ce44SJohn Forte addHostGroupMemberFunc(int operandLen, char *operands[], cmdOptions_t *options,
252fcf3ce44SJohn Forte     void *args)
253fcf3ce44SJohn Forte {
254fcf3ce44SJohn Forte 	int i;
255fcf3ce44SJohn Forte 	int ret = 0;
256fcf3ce44SJohn Forte 	int stmfRet;
2573e7352aeSJohn Forte 	stmfGroupName groupName = {0};
2583e7352aeSJohn Forte 	wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
259fcf3ce44SJohn Forte 	stmfDevid devid;
260fcf3ce44SJohn Forte 
261fcf3ce44SJohn Forte 	for (; options->optval; options++) {
262fcf3ce44SJohn Forte 		switch (options->optval) {
263fcf3ce44SJohn Forte 			/* host group name */
264fcf3ce44SJohn Forte 			case 'g':
265fcf3ce44SJohn Forte 				(void) mbstowcs(groupNamePrint, options->optarg,
2663e7352aeSJohn Forte 				    sizeof (stmfGroupName) - 1);
267fcf3ce44SJohn Forte 				bcopy(options->optarg, groupName,
268fcf3ce44SJohn Forte 				    strlen(options->optarg));
269fcf3ce44SJohn Forte 				break;
270fcf3ce44SJohn Forte 			default:
271fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
272fcf3ce44SJohn Forte 				    cmdName, options->optval,
273fcf3ce44SJohn Forte 				    gettext("unknown option"));
274fcf3ce44SJohn Forte 				return (1);
275fcf3ce44SJohn Forte 		}
276fcf3ce44SJohn Forte 	}
277fcf3ce44SJohn Forte 
278fcf3ce44SJohn Forte 	for (i = 0; i < operandLen; i++) {
279fcf3ce44SJohn Forte 		if (parseDevid(operands[i], &devid) != 0) {
280fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n",
281fcf3ce44SJohn Forte 			    cmdName, operands[i],
282fcf3ce44SJohn Forte 			    gettext("unrecognized device id"));
283fcf3ce44SJohn Forte 			ret++;
284fcf3ce44SJohn Forte 			continue;
285fcf3ce44SJohn Forte 		}
286fcf3ce44SJohn Forte 		stmfRet = stmfAddToHostGroup(&groupName, &devid);
287fcf3ce44SJohn Forte 		switch (stmfRet) {
288fcf3ce44SJohn Forte 			case STMF_STATUS_SUCCESS:
289fcf3ce44SJohn Forte 				break;
290fcf3ce44SJohn Forte 			case STMF_ERROR_EXISTS:
291fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
292fcf3ce44SJohn Forte 				    operands[i], gettext("already exists"));
293fcf3ce44SJohn Forte 				ret++;
294fcf3ce44SJohn Forte 				break;
295fcf3ce44SJohn Forte 			case STMF_ERROR_GROUP_NOT_FOUND:
296fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
297fcf3ce44SJohn Forte 				    groupNamePrint, gettext("not found"));
298fcf3ce44SJohn Forte 				ret++;
299fcf3ce44SJohn Forte 				break;
300fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
301fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
302fcf3ce44SJohn Forte 				    gettext("permission denied"));
303fcf3ce44SJohn Forte 				break;
304fcf3ce44SJohn Forte 			case STMF_ERROR_BUSY:
305fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
306fcf3ce44SJohn Forte 				    operands[i], gettext("resource busy"));
307fcf3ce44SJohn Forte 				ret++;
308fcf3ce44SJohn Forte 				break;
309fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
310fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
311fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
312fcf3ce44SJohn Forte 				ret++;
313fcf3ce44SJohn Forte 				break;
314fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
315fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
316fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
317fcf3ce44SJohn Forte 				ret++;
318fcf3ce44SJohn Forte 				break;
319fcf3ce44SJohn Forte 			default:
320fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
321fcf3ce44SJohn Forte 				    operands[i], gettext("unknown error"));
322fcf3ce44SJohn Forte 				ret++;
323fcf3ce44SJohn Forte 				break;
324fcf3ce44SJohn Forte 		}
325fcf3ce44SJohn Forte 	}
326fcf3ce44SJohn Forte 
327fcf3ce44SJohn Forte 	return (ret);
328fcf3ce44SJohn Forte }
329fcf3ce44SJohn Forte 
330fcf3ce44SJohn Forte /*
331fcf3ce44SJohn Forte  * addTargetGroupMemberFunc
332fcf3ce44SJohn Forte  *
333fcf3ce44SJohn Forte  * Add members to a target group
334fcf3ce44SJohn Forte  *
335fcf3ce44SJohn Forte  */
336fcf3ce44SJohn Forte /*ARGSUSED*/
337fcf3ce44SJohn Forte static int
338fcf3ce44SJohn Forte addTargetGroupMemberFunc(int operandLen, char *operands[],
339fcf3ce44SJohn Forte     cmdOptions_t *options, void *args)
340fcf3ce44SJohn Forte {
341fcf3ce44SJohn Forte 	int i;
342fcf3ce44SJohn Forte 	int ret = 0;
343fcf3ce44SJohn Forte 	int stmfRet;
3443e7352aeSJohn Forte 	stmfGroupName groupName = {0};
3453e7352aeSJohn Forte 	wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
346fcf3ce44SJohn Forte 	stmfDevid devid;
347fcf3ce44SJohn Forte 
348fcf3ce44SJohn Forte 	for (; options->optval; options++) {
349fcf3ce44SJohn Forte 		switch (options->optval) {
350fcf3ce44SJohn Forte 			/* target group name */
351fcf3ce44SJohn Forte 			case 'g':
352fcf3ce44SJohn Forte 				(void) mbstowcs(groupNamePrint, options->optarg,
3533e7352aeSJohn Forte 				    sizeof (stmfGroupName) - 1);
354fcf3ce44SJohn Forte 				bcopy(options->optarg, groupName,
355fcf3ce44SJohn Forte 				    strlen(options->optarg));
356fcf3ce44SJohn Forte 				break;
357fcf3ce44SJohn Forte 			default:
358fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
359fcf3ce44SJohn Forte 				    cmdName, options->optval,
360fcf3ce44SJohn Forte 				    gettext("unknown option"));
361fcf3ce44SJohn Forte 				return (1);
362fcf3ce44SJohn Forte 		}
363fcf3ce44SJohn Forte 	}
364fcf3ce44SJohn Forte 
365fcf3ce44SJohn Forte 	for (i = 0; i < operandLen; i++) {
366fcf3ce44SJohn Forte 		if (parseDevid(operands[i], &devid) != 0) {
367fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n",
368fcf3ce44SJohn Forte 			    cmdName, operands[i],
369fcf3ce44SJohn Forte 			    gettext("unrecognized device id"));
370fcf3ce44SJohn Forte 			ret++;
371fcf3ce44SJohn Forte 			continue;
372fcf3ce44SJohn Forte 		}
373fcf3ce44SJohn Forte 		stmfRet = stmfAddToTargetGroup(&groupName, &devid);
374fcf3ce44SJohn Forte 		switch (stmfRet) {
375fcf3ce44SJohn Forte 			case STMF_STATUS_SUCCESS:
376fcf3ce44SJohn Forte 				break;
377fcf3ce44SJohn Forte 			case STMF_ERROR_EXISTS:
378fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
379fcf3ce44SJohn Forte 				    operands[i], gettext("already exists"));
380fcf3ce44SJohn Forte 				ret++;
381fcf3ce44SJohn Forte 				break;
382fcf3ce44SJohn Forte 			case STMF_ERROR_GROUP_NOT_FOUND:
383fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
384fcf3ce44SJohn Forte 				    groupNamePrint, gettext("not found"));
385fcf3ce44SJohn Forte 				ret++;
386fcf3ce44SJohn Forte 				break;
387fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
388fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
389fcf3ce44SJohn Forte 				    gettext("permission denied"));
390fcf3ce44SJohn Forte 				break;
391fcf3ce44SJohn Forte 			case STMF_ERROR_BUSY:
392fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
393fcf3ce44SJohn Forte 				    operands[i], gettext("resource busy"));
394fcf3ce44SJohn Forte 				ret++;
395fcf3ce44SJohn Forte 				break;
396fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
397fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
398fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
399fcf3ce44SJohn Forte 				ret++;
400fcf3ce44SJohn Forte 				break;
401fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_ONLINE:
402fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
403fcf3ce44SJohn Forte 				    gettext("STMF service must be offline"));
404fcf3ce44SJohn Forte 				ret++;
405fcf3ce44SJohn Forte 				break;
406fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
407fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
408fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
409fcf3ce44SJohn Forte 				ret++;
410fcf3ce44SJohn Forte 				break;
411fcf3ce44SJohn Forte 			default:
412fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
413fcf3ce44SJohn Forte 				    operands[i], gettext("unknown error"));
414fcf3ce44SJohn Forte 				ret++;
415fcf3ce44SJohn Forte 				break;
416fcf3ce44SJohn Forte 		}
417fcf3ce44SJohn Forte 	}
418fcf3ce44SJohn Forte 
419fcf3ce44SJohn Forte 	return (ret);
420fcf3ce44SJohn Forte }
421fcf3ce44SJohn Forte 
422fcf3ce44SJohn Forte /*
423fcf3ce44SJohn Forte  * parseDevid
424fcf3ce44SJohn Forte  *
425fcf3ce44SJohn Forte  * Converts char * input to a stmfDevid
426fcf3ce44SJohn Forte  *
427fcf3ce44SJohn Forte  * input - this should be in the following format with either a
428fcf3ce44SJohn Forte  * wwn. iqn. or eui. representation.
429fcf3ce44SJohn Forte  * A name string of the format:
430fcf3ce44SJohn Forte  *	wwn.<WWN> (FC/SAS address)
431fcf3ce44SJohn Forte  *	iqn.<iSCSI name> (iSCSI iqn)
432fcf3ce44SJohn Forte  *	eui.<WWN> (iSCSI eui name)
433fcf3ce44SJohn Forte  *
434fcf3ce44SJohn Forte  * devid - pointer to stmfDevid structure allocated by the caller.
435fcf3ce44SJohn Forte  *
436fcf3ce44SJohn Forte  * Returns:
437fcf3ce44SJohn Forte  *  0 on success
438fcf3ce44SJohn Forte  *  non-zero on failure
439fcf3ce44SJohn Forte  */
440fcf3ce44SJohn Forte static int
441fcf3ce44SJohn Forte parseDevid(char *input, stmfDevid *devid)
442fcf3ce44SJohn Forte {
4433e7352aeSJohn Forte 	wchar_t inputWc[MAX_DEVID_INPUT + 1] = {0};
444fcf3ce44SJohn Forte 
445fcf3ce44SJohn Forte 	/* convert to wcs */
4463e7352aeSJohn Forte 	(void) mbstowcs(inputWc, input, MAX_DEVID_INPUT);
447fcf3ce44SJohn Forte 
448fcf3ce44SJohn Forte 	/*
449fcf3ce44SJohn Forte 	 * Check for known scsi name string formats
450fcf3ce44SJohn Forte 	 * If one is found, we're done
451fcf3ce44SJohn Forte 	 * If not, then it's a failure to parse
452fcf3ce44SJohn Forte 	 */
453fcf3ce44SJohn Forte 	if (checkScsiNameString(inputWc, devid) == 0) {
454fcf3ce44SJohn Forte 		return (0);
455fcf3ce44SJohn Forte 	}
456fcf3ce44SJohn Forte 
457fcf3ce44SJohn Forte 	return (-1);
458fcf3ce44SJohn Forte }
459fcf3ce44SJohn Forte 
460fcf3ce44SJohn Forte /*
461fcf3ce44SJohn Forte  * checkScsiNameString
462fcf3ce44SJohn Forte  *
463fcf3ce44SJohn Forte  * Validates known SCSI name string formats and converts to stmfDevid
464fcf3ce44SJohn Forte  * format
465fcf3ce44SJohn Forte  *
466fcf3ce44SJohn Forte  * input - input SCSI name string
467fcf3ce44SJohn Forte  * devid - pointer to stmfDevid structure allocated by the caller
468fcf3ce44SJohn Forte  *         on successful return, contains the devid based on input
469fcf3ce44SJohn Forte  *
470fcf3ce44SJohn Forte  * returns:
471fcf3ce44SJohn Forte  *         0 on success
472fcf3ce44SJohn Forte  *         -1 on failure
473fcf3ce44SJohn Forte  */
474fcf3ce44SJohn Forte static int
475fcf3ce44SJohn Forte checkScsiNameString(wchar_t *input, stmfDevid *devid)
476fcf3ce44SJohn Forte {
477fcf3ce44SJohn Forte 	char *mbString = NULL;
478fcf3ce44SJohn Forte 	int mbStringLen;
479fcf3ce44SJohn Forte 	int len;
480fcf3ce44SJohn Forte 	int i;
481fcf3ce44SJohn Forte 
482fcf3ce44SJohn Forte 	/*
483fcf3ce44SJohn Forte 	 * Convert to multi-byte string
484fcf3ce44SJohn Forte 	 *
485fcf3ce44SJohn Forte 	 * This is used for either eui or naa formats
486fcf3ce44SJohn Forte 	 */
487fcf3ce44SJohn Forte 	mbString = calloc(1, (mbStringLen = wcstombs(mbString, input, 0)) + 1);
488fcf3ce44SJohn Forte 	if (mbString == NULL) {
489fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
490fcf3ce44SJohn Forte 		    cmdName, "Insufficient memory\n");
491fcf3ce44SJohn Forte 		return (-1);
492fcf3ce44SJohn Forte 	}
493fcf3ce44SJohn Forte 	if (wcstombs(mbString, input, mbStringLen) == (size_t)-1) {
494fcf3ce44SJohn Forte 		return (-1);
495fcf3ce44SJohn Forte 	}
496fcf3ce44SJohn Forte 
497fcf3ce44SJohn Forte 	/*
498fcf3ce44SJohn Forte 	 * check for iqn format
499fcf3ce44SJohn Forte 	 */
500fcf3ce44SJohn Forte 	if (strncmp(mbString, "iqn.", 4) == 0) {
501fcf3ce44SJohn Forte 		if ((len = strlen(mbString)) > (SNS_IQN_223)) {
502fcf3ce44SJohn Forte 			return (-1);
503fcf3ce44SJohn Forte 		}
504fcf3ce44SJohn Forte 		for (i = 0; i < len; i++) {
505fcf3ce44SJohn Forte 			mbString[i] = tolower(mbString[i]);
506fcf3ce44SJohn Forte 		}
507fcf3ce44SJohn Forte 		if (checkIscsiName(input + 4) != 0) {
508fcf3ce44SJohn Forte 			return (-1);
509fcf3ce44SJohn Forte 		}
510fcf3ce44SJohn Forte 	} else if (strncmp(mbString, "wwn.", 4) == 0) {
511fcf3ce44SJohn Forte 		if ((len = strlen(mbString + 4)) != SNS_WWN_16) {
512fcf3ce44SJohn Forte 			return (-1);
513fcf3ce44SJohn Forte 		} else if (checkHexUpper(mbString + 4) != 0) {
514fcf3ce44SJohn Forte 			return (-1);
515fcf3ce44SJohn Forte 		}
516fcf3ce44SJohn Forte 	} else if (strncmp(mbString, "eui.", 4) == 0) {
517fcf3ce44SJohn Forte 		if ((len = strlen(mbString + 4)) != SNS_EUI_16) {
518fcf3ce44SJohn Forte 			return (-1);
519fcf3ce44SJohn Forte 		} else if (checkHexUpper(mbString + 4) != 0) {
520fcf3ce44SJohn Forte 			return (-1);
521fcf3ce44SJohn Forte 		}
522fcf3ce44SJohn Forte 	} else {
523fcf3ce44SJohn Forte 		return (-1);
524fcf3ce44SJohn Forte 	}
525fcf3ce44SJohn Forte 
526fcf3ce44SJohn Forte 	/*
527fcf3ce44SJohn Forte 	 * We have a validated name string.
528fcf3ce44SJohn Forte 	 * Go ahead and set the length and copy it.
529fcf3ce44SJohn Forte 	 */
530fcf3ce44SJohn Forte 	devid->identLength = strlen(mbString);
531fcf3ce44SJohn Forte 	bzero(devid->ident, STMF_IDENT_LENGTH);
532fcf3ce44SJohn Forte 	bcopy(mbString, devid->ident, devid->identLength);
533fcf3ce44SJohn Forte 
534fcf3ce44SJohn Forte 	return (0);
535fcf3ce44SJohn Forte }
536fcf3ce44SJohn Forte 
537fcf3ce44SJohn Forte 
538fcf3ce44SJohn Forte /*
539fcf3ce44SJohn Forte  * Checks whether the entire string is in hex and converts to upper
540fcf3ce44SJohn Forte  */
541fcf3ce44SJohn Forte static int
542fcf3ce44SJohn Forte checkHexUpper(char *input)
543fcf3ce44SJohn Forte {
544fcf3ce44SJohn Forte 	int i;
545fcf3ce44SJohn Forte 
546fcf3ce44SJohn Forte 	for (i = 0; i < strlen(input); i++) {
547fcf3ce44SJohn Forte 		if (isxdigit(input[i])) {
548fcf3ce44SJohn Forte 			input[i] = toupper(input[i]);
549fcf3ce44SJohn Forte 			continue;
550fcf3ce44SJohn Forte 		}
551fcf3ce44SJohn Forte 		return (-1);
552fcf3ce44SJohn Forte 	}
553fcf3ce44SJohn Forte 
554fcf3ce44SJohn Forte 	return (0);
555fcf3ce44SJohn Forte }
556fcf3ce44SJohn Forte 
557fcf3ce44SJohn Forte /*
558fcf3ce44SJohn Forte  * checkIscsiName
559fcf3ce44SJohn Forte  *
560fcf3ce44SJohn Forte  * Purpose: Basic string checking on name
561fcf3ce44SJohn Forte  */
562fcf3ce44SJohn Forte static int
563fcf3ce44SJohn Forte checkIscsiName(wchar_t *input)
564fcf3ce44SJohn Forte {
565fcf3ce44SJohn Forte 	int i;
566fcf3ce44SJohn Forte 
567fcf3ce44SJohn Forte 	for (i = 0; input[i] != 0; i++) {
568fcf3ce44SJohn Forte 		if (!iswalnum(input[i]) && input[i] != '-' &&
569fcf3ce44SJohn Forte 		    input[i] != '.' && input[i] != ':') {
570fcf3ce44SJohn Forte 			return (-1);
571fcf3ce44SJohn Forte 		}
572fcf3ce44SJohn Forte 	}
573fcf3ce44SJohn Forte 
574fcf3ce44SJohn Forte 	return (0);
575fcf3ce44SJohn Forte }
576fcf3ce44SJohn Forte 
577fcf3ce44SJohn Forte 
578fcf3ce44SJohn Forte /*
579fcf3ce44SJohn Forte  * addViewFunc
580fcf3ce44SJohn Forte  *
581fcf3ce44SJohn Forte  * Adds a view entry to a logical unit
582fcf3ce44SJohn Forte  *
583fcf3ce44SJohn Forte  */
584fcf3ce44SJohn Forte /*ARGSUSED*/
585fcf3ce44SJohn Forte static int
586fcf3ce44SJohn Forte addViewFunc(int operandLen, char *operands[], cmdOptions_t *options,
587fcf3ce44SJohn Forte     void *args)
588fcf3ce44SJohn Forte {
589fcf3ce44SJohn Forte 	stmfViewEntry viewEntry;
590fcf3ce44SJohn Forte 	stmfGuid inGuid;
591fcf3ce44SJohn Forte 	unsigned int guid[sizeof (stmfGuid)];
592fcf3ce44SJohn Forte 	uint16_t inputLuNbr;
593fcf3ce44SJohn Forte 	int ret = 0;
594fcf3ce44SJohn Forte 	int stmfRet;
595fcf3ce44SJohn Forte 	int i;
596fcf3ce44SJohn Forte 	char sGuid[GUID_INPUT + 1];
597fcf3ce44SJohn Forte 
598fcf3ce44SJohn Forte 	bzero(&viewEntry, sizeof (viewEntry));
599fcf3ce44SJohn Forte 	/* init view entry structure */
600fcf3ce44SJohn Forte 	viewEntry.allHosts = B_TRUE;
601fcf3ce44SJohn Forte 	viewEntry.allTargets = B_TRUE;
602fcf3ce44SJohn Forte 	viewEntry.luNbrValid = B_FALSE;
603fcf3ce44SJohn Forte 
604fcf3ce44SJohn Forte 	/* check input length */
605fcf3ce44SJohn Forte 	if (strlen(operands[0]) != GUID_INPUT) {
606fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s: %s%d%s\n", cmdName, operands[0],
607fcf3ce44SJohn Forte 		    gettext("must be "), GUID_INPUT,
608fcf3ce44SJohn Forte 		    gettext(" hexadecimal digits"));
609fcf3ce44SJohn Forte 		return (1);
610fcf3ce44SJohn Forte 	}
611fcf3ce44SJohn Forte 
612fcf3ce44SJohn Forte 	for (; options->optval; options++) {
613fcf3ce44SJohn Forte 		switch (options->optval) {
614fcf3ce44SJohn Forte 			/* logical unit number */
615fcf3ce44SJohn Forte 			case 'n':
616fcf3ce44SJohn Forte 				viewEntry.luNbrValid = B_TRUE;
617fcf3ce44SJohn Forte 				inputLuNbr = atoi(options->optarg);
618fcf3ce44SJohn Forte 				if (inputLuNbr > MAX_LU_NBR) {
619fcf3ce44SJohn Forte 					(void) fprintf(stderr, "%s: %d: %s\n",
620fcf3ce44SJohn Forte 					    cmdName, inputLuNbr,
621fcf3ce44SJohn Forte 					    gettext("Logical unit number"
622fcf3ce44SJohn Forte 					    " must be less than 16384"));
623fcf3ce44SJohn Forte 					return (1);
624fcf3ce44SJohn Forte 				}
625fcf3ce44SJohn Forte 				viewEntry.luNbr[0] = inputLuNbr >> 8;
626fcf3ce44SJohn Forte 				viewEntry.luNbr[1] = inputLuNbr & 0xff;
627fcf3ce44SJohn Forte 				break;
628fcf3ce44SJohn Forte 			/* host group */
629fcf3ce44SJohn Forte 			case 'h':
630fcf3ce44SJohn Forte 				viewEntry.allHosts = B_FALSE;
631fcf3ce44SJohn Forte 				bcopy(options->optarg, viewEntry.hostGroup,
632fcf3ce44SJohn Forte 				    strlen(options->optarg));
633fcf3ce44SJohn Forte 				break;
634fcf3ce44SJohn Forte 			/* target group */
635fcf3ce44SJohn Forte 			case 't':
636fcf3ce44SJohn Forte 				viewEntry.allTargets = B_FALSE;
637fcf3ce44SJohn Forte 				bcopy(options->optarg, viewEntry.targetGroup,
638fcf3ce44SJohn Forte 				    strlen(options->optarg));
639fcf3ce44SJohn Forte 				break;
640fcf3ce44SJohn Forte 			default:
641fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
642fcf3ce44SJohn Forte 				    cmdName, options->optval,
643fcf3ce44SJohn Forte 				    gettext("unknown option"));
644fcf3ce44SJohn Forte 				return (1);
645fcf3ce44SJohn Forte 		}
646fcf3ce44SJohn Forte 	}
647fcf3ce44SJohn Forte 
648fcf3ce44SJohn Forte 	/* convert to lower case for scan */
649fcf3ce44SJohn Forte 	for (i = 0; i < 32; i++)
650fcf3ce44SJohn Forte 		sGuid[i] = tolower(operands[0][i]);
651fcf3ce44SJohn Forte 	sGuid[i] = 0;
652fcf3ce44SJohn Forte 
653fcf3ce44SJohn Forte 	(void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
654fcf3ce44SJohn Forte 	    &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
655fcf3ce44SJohn Forte 	    &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11],
656fcf3ce44SJohn Forte 	    &guid[12], &guid[13], &guid[14], &guid[15]);
657fcf3ce44SJohn Forte 
658fcf3ce44SJohn Forte 	for (i = 0; i < sizeof (stmfGuid); i++) {
659fcf3ce44SJohn Forte 		inGuid.guid[i] = guid[i];
660fcf3ce44SJohn Forte 	}
661fcf3ce44SJohn Forte 
662fcf3ce44SJohn Forte 	/* add the view entry */
663fcf3ce44SJohn Forte 	stmfRet = stmfAddViewEntry(&inGuid, &viewEntry);
664fcf3ce44SJohn Forte 	switch (stmfRet) {
665fcf3ce44SJohn Forte 		case STMF_STATUS_SUCCESS:
666fcf3ce44SJohn Forte 			break;
667fcf3ce44SJohn Forte 		case STMF_ERROR_EXISTS:
668fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
669fcf3ce44SJohn Forte 			    operands[0], gettext("already exists"));
670fcf3ce44SJohn Forte 			ret++;
671fcf3ce44SJohn Forte 			break;
672fcf3ce44SJohn Forte 		case STMF_ERROR_BUSY:
673fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
674fcf3ce44SJohn Forte 			    operands[0], gettext("resource busy"));
675fcf3ce44SJohn Forte 			ret++;
676fcf3ce44SJohn Forte 			break;
677fcf3ce44SJohn Forte 		case STMF_ERROR_SERVICE_NOT_FOUND:
678fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
679fcf3ce44SJohn Forte 			    gettext("STMF service not found"));
680fcf3ce44SJohn Forte 			ret++;
681fcf3ce44SJohn Forte 			break;
682fcf3ce44SJohn Forte 		case STMF_ERROR_PERM:
683fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
684fcf3ce44SJohn Forte 			    gettext("permission denied"));
685fcf3ce44SJohn Forte 			ret++;
686fcf3ce44SJohn Forte 			break;
687fcf3ce44SJohn Forte 		case STMF_ERROR_LUN_IN_USE:
688fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
689fcf3ce44SJohn Forte 			    gettext("LUN already in use"));
690fcf3ce44SJohn Forte 			ret++;
691fcf3ce44SJohn Forte 			break;
692fcf3ce44SJohn Forte 		case STMF_ERROR_VE_CONFLICT:
693fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
694fcf3ce44SJohn Forte 			    gettext("view entry exists"));
695fcf3ce44SJohn Forte 			ret++;
696fcf3ce44SJohn Forte 			break;
697fcf3ce44SJohn Forte 		case STMF_ERROR_CONFIG_NONE:
698fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
699fcf3ce44SJohn Forte 			    gettext("STMF service is not initialized"));
700fcf3ce44SJohn Forte 			ret++;
701fcf3ce44SJohn Forte 			break;
702fcf3ce44SJohn Forte 		case STMF_ERROR_SERVICE_DATA_VERSION:
703fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
704fcf3ce44SJohn Forte 			    gettext("STMF service version incorrect"));
705fcf3ce44SJohn Forte 			ret++;
706fcf3ce44SJohn Forte 			break;
707fcf3ce44SJohn Forte 		case STMF_ERROR_INVALID_HG:
708fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
709fcf3ce44SJohn Forte 			    gettext("invalid host group"));
710fcf3ce44SJohn Forte 			ret++;
711fcf3ce44SJohn Forte 			break;
712fcf3ce44SJohn Forte 		case STMF_ERROR_INVALID_TG:
713fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
714fcf3ce44SJohn Forte 			    gettext("invalid target group"));
715fcf3ce44SJohn Forte 			ret++;
716fcf3ce44SJohn Forte 			break;
717fcf3ce44SJohn Forte 		default:
718fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
719fcf3ce44SJohn Forte 			    operands[0], gettext("unknown error"));
720fcf3ce44SJohn Forte 			ret++;
721fcf3ce44SJohn Forte 			break;
722fcf3ce44SJohn Forte 	}
723fcf3ce44SJohn Forte 
724fcf3ce44SJohn Forte 	return (ret);
725fcf3ce44SJohn Forte }
726fcf3ce44SJohn Forte 
727fcf3ce44SJohn Forte /*
728fcf3ce44SJohn Forte  * createHostGroupFunc
729fcf3ce44SJohn Forte  *
730fcf3ce44SJohn Forte  * Create a host group
731fcf3ce44SJohn Forte  *
732fcf3ce44SJohn Forte  */
733fcf3ce44SJohn Forte /*ARGSUSED*/
734fcf3ce44SJohn Forte static int
735fcf3ce44SJohn Forte createHostGroupFunc(int operandLen, char *operands[],
736fcf3ce44SJohn Forte     cmdOptions_t *options, void *args)
737fcf3ce44SJohn Forte {
738fcf3ce44SJohn Forte 	int ret = 0;
739fcf3ce44SJohn Forte 	int stmfRet;
7403e7352aeSJohn Forte 	wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
7413e7352aeSJohn Forte 	stmfGroupName groupName = {0};
742fcf3ce44SJohn Forte 
743fcf3ce44SJohn Forte 	(void) strlcpy(groupName, operands[0], sizeof (groupName));
744fcf3ce44SJohn Forte 	(void) mbstowcs(groupNamePrint, (char *)groupName,
7453e7352aeSJohn Forte 	    sizeof (stmfGroupName) - 1);
746fcf3ce44SJohn Forte 	/* call create group */
747fcf3ce44SJohn Forte 	stmfRet = stmfCreateHostGroup(&groupName);
748fcf3ce44SJohn Forte 	switch (stmfRet) {
749fcf3ce44SJohn Forte 		case STMF_STATUS_SUCCESS:
750fcf3ce44SJohn Forte 			break;
751fcf3ce44SJohn Forte 		case STMF_ERROR_EXISTS:
752fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
753fcf3ce44SJohn Forte 			    operands[0], gettext("already exists"));
754fcf3ce44SJohn Forte 			ret++;
755fcf3ce44SJohn Forte 			break;
756fcf3ce44SJohn Forte 		case STMF_ERROR_BUSY:
757fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
758fcf3ce44SJohn Forte 			    operands[0], gettext("resource busy"));
759fcf3ce44SJohn Forte 			ret++;
760fcf3ce44SJohn Forte 			break;
761fcf3ce44SJohn Forte 		case STMF_ERROR_SERVICE_NOT_FOUND:
762fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
763fcf3ce44SJohn Forte 			    gettext("STMF service not found"));
764fcf3ce44SJohn Forte 			ret++;
765fcf3ce44SJohn Forte 			break;
766fcf3ce44SJohn Forte 		case STMF_ERROR_PERM:
767fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
768fcf3ce44SJohn Forte 			    gettext("permission denied"));
769fcf3ce44SJohn Forte 			ret++;
770fcf3ce44SJohn Forte 			break;
771fcf3ce44SJohn Forte 		case STMF_ERROR_SERVICE_DATA_VERSION:
772fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
773fcf3ce44SJohn Forte 			    gettext("STMF service version incorrect"));
774fcf3ce44SJohn Forte 			ret++;
775fcf3ce44SJohn Forte 			break;
776fcf3ce44SJohn Forte 		default:
777fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
778fcf3ce44SJohn Forte 			    operands[0], gettext("unknown error"));
779fcf3ce44SJohn Forte 			ret++;
780fcf3ce44SJohn Forte 			break;
781fcf3ce44SJohn Forte 	}
782fcf3ce44SJohn Forte 
783fcf3ce44SJohn Forte 	return (ret);
784fcf3ce44SJohn Forte }
785fcf3ce44SJohn Forte 
786fcf3ce44SJohn Forte /*
7878fe96085Stim szeto  * createLuFunc
7888fe96085Stim szeto  *
7898fe96085Stim szeto  * Create a logical unit
7908fe96085Stim szeto  *
7918fe96085Stim szeto  */
7928fe96085Stim szeto /*ARGSUSED*/
7938fe96085Stim szeto static int
7948fe96085Stim szeto createLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
7958fe96085Stim szeto     void *args)
7968fe96085Stim szeto {
7978fe96085Stim szeto 	luResource hdl = NULL;
7988fe96085Stim szeto 	int ret = 0;
7998fe96085Stim szeto 	int stmfRet = 0;
8008fe96085Stim szeto 	char guidAsciiBuf[33];
8018fe96085Stim szeto 	stmfGuid createdGuid;
8028fe96085Stim szeto 
8038fe96085Stim szeto 	stmfRet = stmfCreateLuResource(STMF_DISK, &hdl);
8048fe96085Stim szeto 
8058fe96085Stim szeto 	if (stmfRet != STMF_STATUS_SUCCESS) {
8068fe96085Stim szeto 		(void) fprintf(stderr, "%s: %s\n",
8078fe96085Stim szeto 		    cmdName, gettext("Failure to create lu resource\n"));
8088fe96085Stim szeto 		return (1);
8098fe96085Stim szeto 	}
8108fe96085Stim szeto 
8118fe96085Stim szeto 	for (; options->optval; options++) {
8128fe96085Stim szeto 		switch (options->optval) {
8138fe96085Stim szeto 			case 'p':
8148fe96085Stim szeto 				ret = setLuPropFromInput(hdl, options->optarg);
8158fe96085Stim szeto 				if (ret != 0) {
8168fe96085Stim szeto 					(void) stmfFreeLuResource(hdl);
8178fe96085Stim szeto 					return (1);
8188fe96085Stim szeto 				}
8198fe96085Stim szeto 				break;
8208fe96085Stim szeto 			case 's':
8218fe96085Stim szeto 				stmfRet = stmfSetLuProp(hdl, STMF_LU_PROP_SIZE,
8228fe96085Stim szeto 				    options->optarg);
8238fe96085Stim szeto 				if (stmfRet != STMF_STATUS_SUCCESS) {
8248fe96085Stim szeto 					(void) fprintf(stderr, "%s: %c: %s\n",
8258fe96085Stim szeto 					    cmdName, options->optval,
8268fe96085Stim szeto 					    gettext("size param invalid"));
8278fe96085Stim szeto 					(void) stmfFreeLuResource(hdl);
8288fe96085Stim szeto 					return (1);
8298fe96085Stim szeto 				}
8308fe96085Stim szeto 				break;
8318fe96085Stim szeto 			default:
8328fe96085Stim szeto 				(void) fprintf(stderr, "%s: %c: %s\n",
8338fe96085Stim szeto 				    cmdName, options->optval,
8348fe96085Stim szeto 				    gettext("unknown option"));
8358fe96085Stim szeto 				return (1);
8368fe96085Stim szeto 		}
8378fe96085Stim szeto 	}
8388fe96085Stim szeto 
8398fe96085Stim szeto 	stmfRet = stmfSetLuProp(hdl, STMF_LU_PROP_FILENAME, operands[0]);
8408fe96085Stim szeto 
8418fe96085Stim szeto 	if (stmfRet != STMF_STATUS_SUCCESS) {
8428fe96085Stim szeto 		(void) fprintf(stderr, "%s: %s\n",
8438fe96085Stim szeto 		    cmdName, gettext("could not set filename"));
8448fe96085Stim szeto 		return (1);
8458fe96085Stim szeto 	}
8468fe96085Stim szeto 
8478fe96085Stim szeto 	stmfRet = stmfCreateLu(hdl, &createdGuid);
8488fe96085Stim szeto 	switch (stmfRet) {
8498fe96085Stim szeto 		case STMF_STATUS_SUCCESS:
8508fe96085Stim szeto 			break;
8518fe96085Stim szeto 		case STMF_ERROR_BUSY:
8528fe96085Stim szeto 		case STMF_ERROR_LU_BUSY:
8538fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
8548fe96085Stim szeto 			    gettext("resource busy"));
8558fe96085Stim szeto 			ret++;
8568fe96085Stim szeto 			break;
8578fe96085Stim szeto 		case STMF_ERROR_PERM:
8588fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
8598fe96085Stim szeto 			    gettext("permission denied"));
8608fe96085Stim szeto 			ret++;
8618fe96085Stim szeto 			break;
8628fe96085Stim szeto 		case STMF_ERROR_FILE_IN_USE:
8638fe96085Stim szeto 			(void) fprintf(stderr, "%s: filename %s: %s\n", cmdName,
8648fe96085Stim szeto 			    operands[0], gettext("in use"));
8658fe96085Stim szeto 			ret++;
8668fe96085Stim szeto 			break;
8678fe96085Stim szeto 		case STMF_ERROR_INVALID_BLKSIZE:
8688fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
8698fe96085Stim szeto 			    gettext("invalid block size"));
8708fe96085Stim szeto 			ret++;
8718fe96085Stim szeto 			break;
8728fe96085Stim szeto 		case STMF_ERROR_GUID_IN_USE:
8738fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
8748fe96085Stim szeto 			    gettext("guid in use"));
8758fe96085Stim szeto 			ret++;
8768fe96085Stim szeto 			break;
8778fe96085Stim szeto 		case STMF_ERROR_META_FILE_NAME:
8788fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
8798fe96085Stim szeto 			    gettext("meta file error"));
8808fe96085Stim szeto 			ret++;
8818fe96085Stim szeto 			break;
8828fe96085Stim szeto 		case STMF_ERROR_DATA_FILE_NAME:
8838fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
8848fe96085Stim szeto 			    gettext("data file error"));
8858fe96085Stim szeto 			ret++;
8868fe96085Stim szeto 			break;
8878fe96085Stim szeto 		case STMF_ERROR_FILE_SIZE_INVALID:
8888fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
8898fe96085Stim szeto 			    gettext("file size invalid"));
8908fe96085Stim szeto 			ret++;
8918fe96085Stim szeto 			break;
8928fe96085Stim szeto 		case STMF_ERROR_SIZE_OUT_OF_RANGE:
8938fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
8948fe96085Stim szeto 			    gettext("invalid size"));
8958fe96085Stim szeto 			ret++;
8968fe96085Stim szeto 			break;
8978fe96085Stim szeto 		case STMF_ERROR_META_CREATION:
8988fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
8998fe96085Stim szeto 			    gettext("could not create meta file"));
9008fe96085Stim szeto 			ret++;
9018fe96085Stim szeto 			break;
9028fe96085Stim szeto 		case STMF_ERROR_WRITE_CACHE_SET:
9038fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
9048fe96085Stim szeto 			    gettext("could not set write cache"));
9058fe96085Stim szeto 			ret++;
9068fe96085Stim szeto 			break;
9078fe96085Stim szeto 		default:
9088fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
9098fe96085Stim szeto 			    gettext("unknown error"));
9108fe96085Stim szeto 			ret++;
9118fe96085Stim szeto 			break;
9128fe96085Stim szeto 	}
9138fe96085Stim szeto 
9148fe96085Stim szeto 	if (ret != 0) {
9158fe96085Stim szeto 		goto done;
9168fe96085Stim szeto 	}
9178fe96085Stim szeto 
9188fe96085Stim szeto 	(void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf),
9198fe96085Stim szeto 	    "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
9208fe96085Stim szeto 	    "%02X%02X%02X%02X%02X%02X",
9218fe96085Stim szeto 	    createdGuid.guid[0], createdGuid.guid[1], createdGuid.guid[2],
9228fe96085Stim szeto 	    createdGuid.guid[3], createdGuid.guid[4], createdGuid.guid[5],
9238fe96085Stim szeto 	    createdGuid.guid[6], createdGuid.guid[7], createdGuid.guid[8],
9248fe96085Stim szeto 	    createdGuid.guid[9], createdGuid.guid[10], createdGuid.guid[11],
9258fe96085Stim szeto 	    createdGuid.guid[12], createdGuid.guid[13], createdGuid.guid[14],
9268fe96085Stim szeto 	    createdGuid.guid[15]);
9278fe96085Stim szeto 	(void) printf("Logical unit created: %s\n", guidAsciiBuf);
9288fe96085Stim szeto 
9298fe96085Stim szeto done:
9308fe96085Stim szeto 	(void) stmfFreeLuResource(hdl);
9318fe96085Stim szeto 	return (ret);
9328fe96085Stim szeto }
9338fe96085Stim szeto 
9348fe96085Stim szeto /*
9358fe96085Stim szeto  * createLuFunc
9368fe96085Stim szeto  *
9378fe96085Stim szeto  * Create a logical unit
9388fe96085Stim szeto  *
9398fe96085Stim szeto  */
9408fe96085Stim szeto /*ARGSUSED*/
9418fe96085Stim szeto static int
9428fe96085Stim szeto modifyLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
9438fe96085Stim szeto     void *args)
9448fe96085Stim szeto {
9458fe96085Stim szeto 	stmfGuid inGuid;
9468fe96085Stim szeto 	unsigned int guid[sizeof (stmfGuid)];
9478fe96085Stim szeto 	int ret = 0;
9488fe96085Stim szeto 	int i;
9498fe96085Stim szeto 	char *fname = NULL;
9508fe96085Stim szeto 	char *lasts = NULL;
9518fe96085Stim szeto 	char sGuid[GUID_INPUT + 1];
9528fe96085Stim szeto 	char *prop = NULL;
9538fe96085Stim szeto 	char *propVal = NULL;
9548fe96085Stim szeto 	boolean_t fnameUsed = B_FALSE;
9558fe96085Stim szeto 	uint32_t propId;
9568fe96085Stim szeto 	cmdOptions_t *optionStart = options;
9578fe96085Stim szeto 
9588fe96085Stim szeto 
9598fe96085Stim szeto 	for (; options->optval; options++) {
9608fe96085Stim szeto 		switch (options->optval) {
9618fe96085Stim szeto 			case 'f':
9628fe96085Stim szeto 				fnameUsed = B_TRUE;
9638fe96085Stim szeto 				fname = operands[0];
9648fe96085Stim szeto 				break;
9658fe96085Stim szeto 		}
9668fe96085Stim szeto 	}
9678fe96085Stim szeto 	options = optionStart;
9688fe96085Stim szeto 
9698fe96085Stim szeto 	/* check input length */
9708fe96085Stim szeto 	if (!fnameUsed && strlen(operands[0]) != GUID_INPUT) {
9718fe96085Stim szeto 		(void) fprintf(stderr, "%s: %s: %s%d%s\n", cmdName, operands[0],
9728fe96085Stim szeto 		    gettext("must be "), GUID_INPUT,
9738fe96085Stim szeto 		    gettext(" hexadecimal digits"));
9748fe96085Stim szeto 		return (1);
9758fe96085Stim szeto 	}
9768fe96085Stim szeto 
9778fe96085Stim szeto 	if (!fnameUsed) {
9788fe96085Stim szeto 		/* convert to lower case for scan */
9798fe96085Stim szeto 		for (i = 0; i < 32; i++)
9808fe96085Stim szeto 			sGuid[i] = tolower(operands[0][i]);
9818fe96085Stim szeto 		sGuid[i] = 0;
9828fe96085Stim szeto 		(void) sscanf(sGuid,
9838fe96085Stim szeto 		    "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
9848fe96085Stim szeto 		    &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
9858fe96085Stim szeto 		    &guid[6], &guid[7], &guid[8], &guid[9], &guid[10],
9868fe96085Stim szeto 		    &guid[11], &guid[12], &guid[13], &guid[14], &guid[15]);
9878fe96085Stim szeto 
9888fe96085Stim szeto 		for (i = 0; i < sizeof (stmfGuid); i++) {
9898fe96085Stim szeto 			inGuid.guid[i] = guid[i];
9908fe96085Stim szeto 		}
9918fe96085Stim szeto 	}
9928fe96085Stim szeto 
9938fe96085Stim szeto 	for (; options->optval; options++) {
9948fe96085Stim szeto 		switch (options->optval) {
9958fe96085Stim szeto 			case 'p':
9968fe96085Stim szeto 				prop = strtok_r(options->optarg, "=", &lasts);
997*2f624233SNattuvetty Bhavyan 				propVal = strtok_r(NULL, "=", &lasts);
9988fe96085Stim szeto 				ret = convertCharToPropId(prop, &propId);
9998fe96085Stim szeto 				if (ret != 0) {
10008fe96085Stim szeto 					(void) fprintf(stderr, "%s: %s: %s\n",
10018fe96085Stim szeto 					    cmdName,
10028fe96085Stim szeto 					gettext("invalid property specified"),
10038fe96085Stim szeto 					    prop);
10048fe96085Stim szeto 					return (1);
10058fe96085Stim szeto 				}
1006*2f624233SNattuvetty Bhavyan 				if (propVal ==  NULL &&
1007*2f624233SNattuvetty Bhavyan 				    propId != STMF_LU_PROP_MGMT_URL) {
1008*2f624233SNattuvetty Bhavyan 					(void) fprintf(stderr, "%s: %s: %s\n",
1009*2f624233SNattuvetty Bhavyan 					    cmdName, options->optarg,
1010*2f624233SNattuvetty Bhavyan 					    gettext("invalid property specifier"
1011*2f624233SNattuvetty Bhavyan 					    "- prop=val\n"));
1012*2f624233SNattuvetty Bhavyan 					return (1);
1013*2f624233SNattuvetty Bhavyan 				}
1014*2f624233SNattuvetty Bhavyan 				if (propVal ==  NULL) {
1015*2f624233SNattuvetty Bhavyan 					ret = callModify(fname, &inGuid, propId,
1016*2f624233SNattuvetty Bhavyan 					    "", prop);
1017*2f624233SNattuvetty Bhavyan 				} else {
1018*2f624233SNattuvetty Bhavyan 					ret = callModify(fname, &inGuid, propId,
1019*2f624233SNattuvetty Bhavyan 					    propVal, prop);
1020*2f624233SNattuvetty Bhavyan 				}
1021*2f624233SNattuvetty Bhavyan 				if (ret != 0) {
10228fe96085Stim szeto 					return (1);
10238fe96085Stim szeto 				}
10248fe96085Stim szeto 				break;
10258fe96085Stim szeto 			case 's':
10268fe96085Stim szeto 				if (callModify(fname, &inGuid,
10278fe96085Stim szeto 				    STMF_LU_PROP_SIZE, options->optarg,
10288fe96085Stim szeto 				    "size") != 0) {
10298fe96085Stim szeto 					return (1);
10308fe96085Stim szeto 				}
10318fe96085Stim szeto 				break;
10328fe96085Stim szeto 			case 'f':
10338fe96085Stim szeto 				break;
10348fe96085Stim szeto 			default:
10358fe96085Stim szeto 				(void) fprintf(stderr, "%s: %c: %s\n",
10368fe96085Stim szeto 				    cmdName, options->optval,
10378fe96085Stim szeto 				    gettext("unknown option"));
10388fe96085Stim szeto 				return (1);
10398fe96085Stim szeto 		}
10408fe96085Stim szeto 	}
10418fe96085Stim szeto 	return (ret);
10428fe96085Stim szeto }
10438fe96085Stim szeto 
10448fe96085Stim szeto static int
10458fe96085Stim szeto callModify(char *fname, stmfGuid *luGuid, uint32_t prop, const char *propVal,
10468fe96085Stim szeto     const char *propString)
10478fe96085Stim szeto {
10488fe96085Stim szeto 	int ret = 0;
10498fe96085Stim szeto 	int stmfRet = 0;
10508fe96085Stim szeto 
10518fe96085Stim szeto 	if (!fname) {
10528fe96085Stim szeto 		stmfRet = stmfModifyLu(luGuid, prop, propVal);
10538fe96085Stim szeto 	} else {
10548fe96085Stim szeto 		stmfRet = stmfModifyLuByFname(STMF_DISK, fname, prop,
10558fe96085Stim szeto 		    propVal);
10568fe96085Stim szeto 	}
10578fe96085Stim szeto 	switch (stmfRet) {
10588fe96085Stim szeto 		case STMF_STATUS_SUCCESS:
10598fe96085Stim szeto 			break;
10608fe96085Stim szeto 		case STMF_ERROR_BUSY:
10618fe96085Stim szeto 		case STMF_ERROR_LU_BUSY:
10628fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
10638fe96085Stim szeto 			    gettext("resource busy"));
10648fe96085Stim szeto 			ret++;
10658fe96085Stim szeto 			break;
10668fe96085Stim szeto 		case STMF_ERROR_PERM:
10678fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
10688fe96085Stim szeto 			    gettext("permission denied"));
10698fe96085Stim szeto 			ret++;
10708fe96085Stim szeto 			break;
10718fe96085Stim szeto 		case STMF_ERROR_INVALID_BLKSIZE:
10728fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
10738fe96085Stim szeto 			    gettext("invalid block size"));
10748fe96085Stim szeto 			ret++;
10758fe96085Stim szeto 			break;
10768fe96085Stim szeto 		case STMF_ERROR_GUID_IN_USE:
10778fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
10788fe96085Stim szeto 			    gettext("guid in use"));
10798fe96085Stim szeto 			ret++;
10808fe96085Stim szeto 			break;
10818fe96085Stim szeto 		case STMF_ERROR_META_FILE_NAME:
10828fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
10838fe96085Stim szeto 			    gettext("meta file error"));
10848fe96085Stim szeto 			ret++;
10858fe96085Stim szeto 			break;
10868fe96085Stim szeto 		case STMF_ERROR_DATA_FILE_NAME:
10878fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
10888fe96085Stim szeto 			    gettext("data file error"));
10898fe96085Stim szeto 			ret++;
10908fe96085Stim szeto 			break;
10918fe96085Stim szeto 		case STMF_ERROR_FILE_SIZE_INVALID:
10928fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
10938fe96085Stim szeto 			    gettext("file size invalid"));
10948fe96085Stim szeto 			ret++;
10958fe96085Stim szeto 			break;
10968fe96085Stim szeto 		case STMF_ERROR_SIZE_OUT_OF_RANGE:
10978fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
10988fe96085Stim szeto 			    gettext("invalid size"));
10998fe96085Stim szeto 			ret++;
11008fe96085Stim szeto 			break;
11018fe96085Stim szeto 		case STMF_ERROR_META_CREATION:
11028fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
11038fe96085Stim szeto 			    gettext("could not create meta file"));
11048fe96085Stim szeto 			ret++;
11058fe96085Stim szeto 			break;
11068fe96085Stim szeto 		case STMF_ERROR_INVALID_PROP:
11078fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
11088fe96085Stim szeto 			    gettext("invalid property for modify"));
11098fe96085Stim szeto 			ret++;
11108fe96085Stim szeto 			break;
11118fe96085Stim szeto 		case STMF_ERROR_WRITE_CACHE_SET:
11128fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
11138fe96085Stim szeto 			    gettext("could not set write cache"));
11148fe96085Stim szeto 			ret++;
11158fe96085Stim szeto 			break;
11168fe96085Stim szeto 		default:
11178fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s: %s: %d\n", cmdName,
11188fe96085Stim szeto 			    gettext("could not set property"), propString,
11198fe96085Stim szeto 			    stmfRet);
11208fe96085Stim szeto 			ret++;
11218fe96085Stim szeto 			break;
11228fe96085Stim szeto 	}
11238fe96085Stim szeto 
11248fe96085Stim szeto 	return (ret);
11258fe96085Stim szeto }
11268fe96085Stim szeto 
11278fe96085Stim szeto 
11288fe96085Stim szeto /*
11298fe96085Stim szeto  * importLuFunc
11308fe96085Stim szeto  *
11318fe96085Stim szeto  * Create a logical unit
11328fe96085Stim szeto  *
11338fe96085Stim szeto  */
11348fe96085Stim szeto /*ARGSUSED*/
11358fe96085Stim szeto static int
11368fe96085Stim szeto importLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
11378fe96085Stim szeto     void *args)
11388fe96085Stim szeto {
11398fe96085Stim szeto 	int stmfRet = 0;
11408fe96085Stim szeto 	int ret = 0;
11418fe96085Stim szeto 	char guidAsciiBuf[33];
11428fe96085Stim szeto 	stmfGuid createdGuid;
11438fe96085Stim szeto 
11448fe96085Stim szeto 	stmfRet = stmfImportLu(STMF_DISK, operands[0], &createdGuid);
11458fe96085Stim szeto 	switch (stmfRet) {
11468fe96085Stim szeto 		case STMF_STATUS_SUCCESS:
11478fe96085Stim szeto 			break;
11488fe96085Stim szeto 		case STMF_ERROR_BUSY:
11498fe96085Stim szeto 		case STMF_ERROR_LU_BUSY:
11508fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
11518fe96085Stim szeto 			    gettext("resource busy"));
11528fe96085Stim szeto 			ret++;
11538fe96085Stim szeto 			break;
11548fe96085Stim szeto 		case STMF_ERROR_PERM:
11558fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
11568fe96085Stim szeto 			    gettext("permission denied"));
11578fe96085Stim szeto 			ret++;
11588fe96085Stim szeto 			break;
11598fe96085Stim szeto 		case STMF_ERROR_FILE_IN_USE:
11608fe96085Stim szeto 			(void) fprintf(stderr, "%s: filename %s: %s\n", cmdName,
11618fe96085Stim szeto 			    operands[0], gettext("in use"));
11628fe96085Stim szeto 			ret++;
11638fe96085Stim szeto 			break;
11648fe96085Stim szeto 		case STMF_ERROR_GUID_IN_USE:
11658fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
11668fe96085Stim szeto 			    gettext("guid in use"));
11678fe96085Stim szeto 			ret++;
11688fe96085Stim szeto 			break;
11698fe96085Stim szeto 		case STMF_ERROR_META_FILE_NAME:
11708fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
11718fe96085Stim szeto 			    gettext("meta file error"));
11728fe96085Stim szeto 			ret++;
11738fe96085Stim szeto 			break;
11748fe96085Stim szeto 		case STMF_ERROR_DATA_FILE_NAME:
11758fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
11768fe96085Stim szeto 			    gettext("data file error"));
11778fe96085Stim szeto 			ret++;
11788fe96085Stim szeto 			break;
11798fe96085Stim szeto 		case STMF_ERROR_META_CREATION:
11808fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
11818fe96085Stim szeto 			    gettext("could not create meta file"));
11828fe96085Stim szeto 			ret++;
11838fe96085Stim szeto 			break;
11848fe96085Stim szeto 		case STMF_ERROR_WRITE_CACHE_SET:
11858fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
11868fe96085Stim szeto 			    gettext("could not set write cache"));
11878fe96085Stim szeto 			ret++;
11888fe96085Stim szeto 			break;
11898fe96085Stim szeto 		default:
11908fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
11918fe96085Stim szeto 			    gettext("unknown error"));
11928fe96085Stim szeto 			ret++;
11938fe96085Stim szeto 			break;
11948fe96085Stim szeto 	}
11958fe96085Stim szeto 
11968fe96085Stim szeto 	if (ret != STMF_STATUS_SUCCESS) {
11978fe96085Stim szeto 		goto done;
11988fe96085Stim szeto 	}
11998fe96085Stim szeto 
12008fe96085Stim szeto 	(void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf),
12018fe96085Stim szeto 	    "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
12028fe96085Stim szeto 	    "%02X%02X%02X%02X%02X%02X",
12038fe96085Stim szeto 	    createdGuid.guid[0], createdGuid.guid[1], createdGuid.guid[2],
12048fe96085Stim szeto 	    createdGuid.guid[3], createdGuid.guid[4], createdGuid.guid[5],
12058fe96085Stim szeto 	    createdGuid.guid[6], createdGuid.guid[7], createdGuid.guid[8],
12068fe96085Stim szeto 	    createdGuid.guid[9], createdGuid.guid[10], createdGuid.guid[11],
12078fe96085Stim szeto 	    createdGuid.guid[12], createdGuid.guid[13], createdGuid.guid[14],
12088fe96085Stim szeto 	    createdGuid.guid[15]);
12098fe96085Stim szeto 	(void) printf("Logical unit imported: %s\n", guidAsciiBuf);
12108fe96085Stim szeto 
12118fe96085Stim szeto done:
12128fe96085Stim szeto 	return (ret);
12138fe96085Stim szeto }
12148fe96085Stim szeto 
12158fe96085Stim szeto static int
12168fe96085Stim szeto setLuPropFromInput(luResource hdl, char *optarg)
12178fe96085Stim szeto {
12188fe96085Stim szeto 	char *prop = NULL;
12198fe96085Stim szeto 	char *propVal = NULL;
12208fe96085Stim szeto 	char *lasts = NULL;
12218fe96085Stim szeto 	uint32_t propId;
12228fe96085Stim szeto 	int ret = 0;
12238fe96085Stim szeto 
12248fe96085Stim szeto 	prop = strtok_r(optarg, "=", &lasts);
12258fe96085Stim szeto 	if ((propVal = strtok_r(NULL, "=", &lasts)) == NULL) {
12268fe96085Stim szeto 		(void) fprintf(stderr, "%s: %s: %s\n",
12278fe96085Stim szeto 		    cmdName, optarg,
12288fe96085Stim szeto 		    gettext("invalid property specifier - prop=val\n"));
12298fe96085Stim szeto 		return (1);
12308fe96085Stim szeto 	}
12318fe96085Stim szeto 
12328fe96085Stim szeto 	ret = convertCharToPropId(prop, &propId);
12338fe96085Stim szeto 	if (ret != 0) {
12348fe96085Stim szeto 		(void) fprintf(stderr, "%s: %s: %s\n",
12358fe96085Stim szeto 		    cmdName, gettext("invalid property specified"), prop);
12368fe96085Stim szeto 		return (1);
12378fe96085Stim szeto 	}
12388fe96085Stim szeto 
12398fe96085Stim szeto 	ret = stmfSetLuProp(hdl, propId, propVal);
12408fe96085Stim szeto 	if (ret != STMF_STATUS_SUCCESS) {
12418fe96085Stim szeto 		(void) fprintf(stderr, "%s: %s %s: ",
12428fe96085Stim szeto 		    cmdName, gettext("unable to set"), prop);
12438fe96085Stim szeto 		switch (ret) {
12448fe96085Stim szeto 			case STMF_ERROR_INVALID_PROPSIZE:
12458fe96085Stim szeto 				(void) fprintf(stderr, "invalid length\n");
12468fe96085Stim szeto 				break;
12478fe96085Stim szeto 			case STMF_ERROR_INVALID_ARG:
12488fe96085Stim szeto 				(void) fprintf(stderr, "bad format\n");
12498fe96085Stim szeto 				break;
12508fe96085Stim szeto 			default:
12518fe96085Stim szeto 				(void) fprintf(stderr, "\n");
12528fe96085Stim szeto 				break;
12538fe96085Stim szeto 		}
12548fe96085Stim szeto 		return (1);
12558fe96085Stim szeto 	}
12568fe96085Stim szeto 
12578fe96085Stim szeto 	return (0);
12588fe96085Stim szeto }
12598fe96085Stim szeto 
12608fe96085Stim szeto static int
12618fe96085Stim szeto convertCharToPropId(char *prop, uint32_t *propId)
12628fe96085Stim szeto {
12638fe96085Stim szeto 	if (strcasecmp(prop, GUID) == 0) {
12648fe96085Stim szeto 		*propId = STMF_LU_PROP_GUID;
12658fe96085Stim szeto 	} else if (strcasecmp(prop, ALIAS) == 0) {
12668fe96085Stim szeto 		*propId = STMF_LU_PROP_ALIAS;
12678fe96085Stim szeto 	} else if (strcasecmp(prop, VID) == 0) {
12688fe96085Stim szeto 		*propId = STMF_LU_PROP_VID;
12698fe96085Stim szeto 	} else if (strcasecmp(prop, PID) == 0) {
12708fe96085Stim szeto 		*propId = STMF_LU_PROP_PID;
12718fe96085Stim szeto 	} else if (strcasecmp(prop, WRITE_PROTECT) == 0) {
12728fe96085Stim szeto 		*propId = STMF_LU_PROP_WRITE_PROTECT;
12738fe96085Stim szeto 	} else if (strcasecmp(prop, WRITEBACK_CACHE_DISABLE) == 0) {
12748fe96085Stim szeto 		*propId = STMF_LU_PROP_WRITE_CACHE_DISABLE;
12758fe96085Stim szeto 	} else if (strcasecmp(prop, BLOCK_SIZE) == 0) {
12768fe96085Stim szeto 		*propId = STMF_LU_PROP_BLOCK_SIZE;
12778fe96085Stim szeto 	} else if (strcasecmp(prop, SERIAL_NUMBER) == 0) {
12788fe96085Stim szeto 		*propId = STMF_LU_PROP_SERIAL_NUM;
12798fe96085Stim szeto 	} else if (strcasecmp(prop, COMPANY_ID) == 0) {
12808fe96085Stim szeto 		*propId = STMF_LU_PROP_COMPANY_ID;
12818fe96085Stim szeto 	} else if (strcasecmp(prop, META_FILE) == 0) {
12828fe96085Stim szeto 		*propId = STMF_LU_PROP_META_FILENAME;
1283*2f624233SNattuvetty Bhavyan 	} else if (strcasecmp(prop, MGMT_URL) == 0) {
1284*2f624233SNattuvetty Bhavyan 		*propId = STMF_LU_PROP_MGMT_URL;
12858fe96085Stim szeto 	} else {
12868fe96085Stim szeto 		return (1);
12878fe96085Stim szeto 	}
12888fe96085Stim szeto 	return (0);
12898fe96085Stim szeto }
12908fe96085Stim szeto 
12918fe96085Stim szeto /*
12928fe96085Stim szeto  * deleteLuFunc
12938fe96085Stim szeto  *
12948fe96085Stim szeto  * Delete a logical unit
12958fe96085Stim szeto  *
12968fe96085Stim szeto  */
12978fe96085Stim szeto /*ARGSUSED*/
12988fe96085Stim szeto static int
12998fe96085Stim szeto deleteLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
13008fe96085Stim szeto     void *args)
13018fe96085Stim szeto {
13028fe96085Stim szeto 	int i, j;
13038fe96085Stim szeto 	int ret = 0;
13048fe96085Stim szeto 	int stmfRet;
13058fe96085Stim szeto 	unsigned int inGuid[sizeof (stmfGuid)];
13068fe96085Stim szeto 	stmfGuid delGuid;
13078fe96085Stim szeto 	boolean_t keepViews = B_FALSE;
13088fe96085Stim szeto 	boolean_t viewEntriesRemoved = B_FALSE;
13098fe96085Stim szeto 	boolean_t noLunFound = B_FALSE;
13108fe96085Stim szeto 	boolean_t views = B_FALSE;
13118fe96085Stim szeto 	char sGuid[GUID_INPUT + 1];
13128fe96085Stim szeto 	stmfViewEntryList *viewEntryList = NULL;
13138fe96085Stim szeto 
13148fe96085Stim szeto 	for (; options->optval; options++) {
13158fe96085Stim szeto 		switch (options->optval) {
13168fe96085Stim szeto 			/* Keep views for logical unit */
13178fe96085Stim szeto 			case 'k':
13188fe96085Stim szeto 				keepViews = B_TRUE;
13198fe96085Stim szeto 				break;
13208fe96085Stim szeto 			default:
13218fe96085Stim szeto 				(void) fprintf(stderr, "%s: %c: %s\n",
13228fe96085Stim szeto 				    cmdName, options->optval,
13238fe96085Stim szeto 				    gettext("unknown option"));
13248fe96085Stim szeto 				return (1);
13258fe96085Stim szeto 		}
13268fe96085Stim szeto 	}
13278fe96085Stim szeto 
13288fe96085Stim szeto 
13298fe96085Stim szeto 	for (i = 0; i < operandLen; i++) {
13308fe96085Stim szeto 		for (j = 0; j < GUID_INPUT; j++) {
13318fe96085Stim szeto 			if (!isxdigit(operands[i][j])) {
13328fe96085Stim szeto 				break;
13338fe96085Stim szeto 			}
13348fe96085Stim szeto 			sGuid[j] = tolower(operands[i][j]);
13358fe96085Stim szeto 		}
13368fe96085Stim szeto 		if (j != GUID_INPUT) {
13378fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s: %s%d%s\n",
13388fe96085Stim szeto 			    cmdName, operands[i], gettext("must be "),
13398fe96085Stim szeto 			    GUID_INPUT,
13408fe96085Stim szeto 			    gettext(" hexadecimal digits long"));
13418fe96085Stim szeto 			continue;
13428fe96085Stim szeto 		}
13438fe96085Stim szeto 
13448fe96085Stim szeto 		sGuid[j] = 0;
13458fe96085Stim szeto 
13468fe96085Stim szeto 		(void) sscanf(sGuid,
13478fe96085Stim szeto 		    "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
13488fe96085Stim szeto 		    &inGuid[0], &inGuid[1], &inGuid[2], &inGuid[3],
13498fe96085Stim szeto 		    &inGuid[4], &inGuid[5], &inGuid[6], &inGuid[7],
13508fe96085Stim szeto 		    &inGuid[8], &inGuid[9], &inGuid[10], &inGuid[11],
13518fe96085Stim szeto 		    &inGuid[12], &inGuid[13], &inGuid[14], &inGuid[15]);
13528fe96085Stim szeto 
13538fe96085Stim szeto 		for (j = 0; j < sizeof (stmfGuid); j++) {
13548fe96085Stim szeto 			delGuid.guid[j] = inGuid[j];
13558fe96085Stim szeto 		}
13568fe96085Stim szeto 
13578fe96085Stim szeto 		stmfRet = stmfDeleteLu(&delGuid);
13588fe96085Stim szeto 		switch (stmfRet) {
13598fe96085Stim szeto 			case STMF_STATUS_SUCCESS:
13608fe96085Stim szeto 				break;
13618fe96085Stim szeto 			case STMF_ERROR_NOT_FOUND:
13628fe96085Stim szeto 				noLunFound = B_TRUE;
13638fe96085Stim szeto 				break;
13648fe96085Stim szeto 			case STMF_ERROR_BUSY:
13658fe96085Stim szeto 				(void) fprintf(stderr, "%s: %s\n", cmdName,
13668fe96085Stim szeto 				    gettext("resource busy"));
13678fe96085Stim szeto 				ret++;
13688fe96085Stim szeto 				break;
13698fe96085Stim szeto 			case STMF_ERROR_PERM:
13708fe96085Stim szeto 				(void) fprintf(stderr, "%s: %s\n", cmdName,
13718fe96085Stim szeto 				    gettext("permission denied"));
13728fe96085Stim szeto 				ret++;
13738fe96085Stim szeto 				break;
13748fe96085Stim szeto 			default:
13758fe96085Stim szeto 				(void) fprintf(stderr, "%s: %s\n", cmdName,
13768fe96085Stim szeto 				    gettext("unknown error"));
13778fe96085Stim szeto 				ret++;
13788fe96085Stim szeto 				break;
13798fe96085Stim szeto 		}
13808fe96085Stim szeto 
13818fe96085Stim szeto 		if (!keepViews) {
13828fe96085Stim szeto 			stmfRet = stmfGetViewEntryList(&delGuid,
13838fe96085Stim szeto 			    &viewEntryList);
13848fe96085Stim szeto 			if (stmfRet == STMF_STATUS_SUCCESS) {
13858fe96085Stim szeto 				for (j = 0; j < viewEntryList->cnt; j++) {
13868fe96085Stim szeto 					(void) stmfRemoveViewEntry(&delGuid,
13878fe96085Stim szeto 					    viewEntryList->ve[j].veIndex);
13888fe96085Stim szeto 				}
13898fe96085Stim szeto 				viewEntriesRemoved = B_TRUE;
13908fe96085Stim szeto 				stmfFreeMemory(viewEntryList);
13918fe96085Stim szeto 			} else if (stmfRet != STMF_ERROR_NOT_FOUND) {
13928fe96085Stim szeto 				(void) fprintf(stderr, "%s: %s\n", cmdName,
13938fe96085Stim szeto 				    gettext("unable to remove view entries\n"));
13948fe96085Stim szeto 				ret++;
13958fe96085Stim szeto 			} /* No view entries to remove */
13968fe96085Stim szeto 		}
13978fe96085Stim szeto 		if (keepViews) {
13988fe96085Stim szeto 			stmfRet = stmfGetViewEntryList(&delGuid,
13998fe96085Stim szeto 			    &viewEntryList);
14008fe96085Stim szeto 			if (stmfRet == STMF_STATUS_SUCCESS) {
14018fe96085Stim szeto 				views = B_TRUE;
14028fe96085Stim szeto 				stmfFreeMemory(viewEntryList);
14038fe96085Stim szeto 			}
14048fe96085Stim szeto 		}
14058fe96085Stim szeto 
14068fe96085Stim szeto 		if ((!viewEntriesRemoved && noLunFound && !views) ||
14078fe96085Stim szeto 		    (!views && keepViews && noLunFound)) {
14088fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s: %s\n",
14098fe96085Stim szeto 			    cmdName, sGuid,
14108fe96085Stim szeto 			    gettext("not found"));
14118fe96085Stim szeto 			ret++;
14128fe96085Stim szeto 		}
14138fe96085Stim szeto 		noLunFound = viewEntriesRemoved = views = B_FALSE;
14148fe96085Stim szeto 	}
14158fe96085Stim szeto 	return (ret);
14168fe96085Stim szeto }
14178fe96085Stim szeto 
14188fe96085Stim szeto 
14198fe96085Stim szeto /*
1420fcf3ce44SJohn Forte  * createTargetGroupFunc
1421fcf3ce44SJohn Forte  *
1422fcf3ce44SJohn Forte  * Create a target group
1423fcf3ce44SJohn Forte  *
1424fcf3ce44SJohn Forte  */
1425fcf3ce44SJohn Forte /*ARGSUSED*/
1426fcf3ce44SJohn Forte static int
1427fcf3ce44SJohn Forte createTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options,
1428fcf3ce44SJohn Forte     void *args)
1429fcf3ce44SJohn Forte {
1430fcf3ce44SJohn Forte 	int ret = 0;
1431fcf3ce44SJohn Forte 	int stmfRet;
14323e7352aeSJohn Forte 	wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
14333e7352aeSJohn Forte 	stmfGroupName groupName = {0};
1434fcf3ce44SJohn Forte 
1435fcf3ce44SJohn Forte 	(void) strlcpy(groupName, operands[0], sizeof (groupName));
1436fcf3ce44SJohn Forte 	(void) mbstowcs(groupNamePrint, (char *)groupName,
14373e7352aeSJohn Forte 	    sizeof (stmfGroupName) - 1);
1438fcf3ce44SJohn Forte 	/* call create group */
1439fcf3ce44SJohn Forte 	stmfRet = stmfCreateTargetGroup(&groupName);
1440fcf3ce44SJohn Forte 	switch (stmfRet) {
1441fcf3ce44SJohn Forte 		case STMF_STATUS_SUCCESS:
1442fcf3ce44SJohn Forte 			break;
1443fcf3ce44SJohn Forte 		case STMF_ERROR_EXISTS:
1444fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1445fcf3ce44SJohn Forte 			    groupNamePrint, gettext("already exists"));
1446fcf3ce44SJohn Forte 			ret++;
1447fcf3ce44SJohn Forte 			break;
1448fcf3ce44SJohn Forte 		case STMF_ERROR_BUSY:
1449fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1450fcf3ce44SJohn Forte 			    groupNamePrint, gettext("resource busy"));
1451fcf3ce44SJohn Forte 			ret++;
1452fcf3ce44SJohn Forte 			break;
1453fcf3ce44SJohn Forte 		case STMF_ERROR_PERM:
1454fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
1455fcf3ce44SJohn Forte 			    gettext("permission denied"));
1456fcf3ce44SJohn Forte 			ret++;
1457fcf3ce44SJohn Forte 			break;
1458fcf3ce44SJohn Forte 		case STMF_ERROR_SERVICE_NOT_FOUND:
1459fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
1460fcf3ce44SJohn Forte 			    gettext("STMF service not found"));
1461fcf3ce44SJohn Forte 			ret++;
1462fcf3ce44SJohn Forte 			break;
1463fcf3ce44SJohn Forte 		case STMF_ERROR_SERVICE_DATA_VERSION:
1464fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
1465fcf3ce44SJohn Forte 			    gettext("STMF service version incorrect"));
1466fcf3ce44SJohn Forte 			ret++;
1467fcf3ce44SJohn Forte 			break;
1468fcf3ce44SJohn Forte 		default:
1469fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1470fcf3ce44SJohn Forte 			    groupNamePrint, gettext("unknown error"));
1471fcf3ce44SJohn Forte 			ret++;
1472fcf3ce44SJohn Forte 			break;
1473fcf3ce44SJohn Forte 	}
1474fcf3ce44SJohn Forte 
1475fcf3ce44SJohn Forte 	return (ret);
1476fcf3ce44SJohn Forte }
1477fcf3ce44SJohn Forte 
1478fcf3ce44SJohn Forte /*
1479fcf3ce44SJohn Forte  * deleteHostGroupFunc
1480fcf3ce44SJohn Forte  *
1481fcf3ce44SJohn Forte  * Delete a host group
1482fcf3ce44SJohn Forte  *
1483fcf3ce44SJohn Forte  */
1484fcf3ce44SJohn Forte /*ARGSUSED*/
1485fcf3ce44SJohn Forte static int
1486fcf3ce44SJohn Forte deleteHostGroupFunc(int operandLen, char *operands[],
1487fcf3ce44SJohn Forte     cmdOptions_t *options, void *args)
1488fcf3ce44SJohn Forte {
1489fcf3ce44SJohn Forte 	int ret = 0;
1490fcf3ce44SJohn Forte 	int stmfRet;
14913e7352aeSJohn Forte 	wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
14923e7352aeSJohn Forte 	stmfGroupName groupName = {0};
1493fcf3ce44SJohn Forte 
1494fcf3ce44SJohn Forte 	(void) strlcpy(groupName, operands[0], sizeof (groupName));
1495fcf3ce44SJohn Forte 	(void) mbstowcs(groupNamePrint, (char *)groupName,
14963e7352aeSJohn Forte 	    sizeof (stmfGroupName) - 1);
1497fcf3ce44SJohn Forte 	/* call delete group */
1498fcf3ce44SJohn Forte 	stmfRet = stmfDeleteHostGroup(&groupName);
1499fcf3ce44SJohn Forte 	switch (stmfRet) {
1500fcf3ce44SJohn Forte 		case STMF_STATUS_SUCCESS:
1501fcf3ce44SJohn Forte 			break;
1502fcf3ce44SJohn Forte 		case STMF_ERROR_NOT_FOUND:
1503fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1504fcf3ce44SJohn Forte 			    groupNamePrint, gettext("not found"));
1505fcf3ce44SJohn Forte 			ret++;
1506fcf3ce44SJohn Forte 			break;
1507fcf3ce44SJohn Forte 		case STMF_ERROR_BUSY:
1508fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1509fcf3ce44SJohn Forte 			    groupNamePrint, gettext("resource busy"));
1510fcf3ce44SJohn Forte 			ret++;
1511fcf3ce44SJohn Forte 			break;
1512fcf3ce44SJohn Forte 		case STMF_ERROR_SERVICE_NOT_FOUND:
1513fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
1514fcf3ce44SJohn Forte 			    gettext("STMF service not found"));
1515fcf3ce44SJohn Forte 			ret++;
1516fcf3ce44SJohn Forte 			break;
1517fcf3ce44SJohn Forte 		case STMF_ERROR_PERM:
1518fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
1519fcf3ce44SJohn Forte 			    gettext("permission denied"));
1520fcf3ce44SJohn Forte 			ret++;
1521fcf3ce44SJohn Forte 			break;
1522fcf3ce44SJohn Forte 		case STMF_ERROR_GROUP_IN_USE:
1523fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1524fcf3ce44SJohn Forte 			    groupNamePrint,
1525fcf3ce44SJohn Forte 			    gettext("group is in use by existing view entry"));
1526fcf3ce44SJohn Forte 			ret++;
1527fcf3ce44SJohn Forte 			break;
1528fcf3ce44SJohn Forte 		case STMF_ERROR_SERVICE_DATA_VERSION:
1529fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
1530fcf3ce44SJohn Forte 			    gettext("STMF service version incorrect"));
1531fcf3ce44SJohn Forte 			ret++;
1532fcf3ce44SJohn Forte 			break;
1533fcf3ce44SJohn Forte 		default:
1534fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1535fcf3ce44SJohn Forte 			    groupNamePrint, gettext("unknown error"));
1536fcf3ce44SJohn Forte 			ret++;
1537fcf3ce44SJohn Forte 			break;
1538fcf3ce44SJohn Forte 	}
1539fcf3ce44SJohn Forte 
1540fcf3ce44SJohn Forte 	return (ret);
1541fcf3ce44SJohn Forte }
1542fcf3ce44SJohn Forte 
1543fcf3ce44SJohn Forte /*
1544fcf3ce44SJohn Forte  * deleteTargetGroupFunc
1545fcf3ce44SJohn Forte  *
1546fcf3ce44SJohn Forte  * Delete a target group
1547fcf3ce44SJohn Forte  *
1548fcf3ce44SJohn Forte  */
1549fcf3ce44SJohn Forte /*ARGSUSED*/
1550fcf3ce44SJohn Forte static int
1551fcf3ce44SJohn Forte deleteTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options,
1552fcf3ce44SJohn Forte     void *args)
1553fcf3ce44SJohn Forte {
1554fcf3ce44SJohn Forte 	int ret = 0;
1555fcf3ce44SJohn Forte 	int stmfRet;
15563e7352aeSJohn Forte 	wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
15573e7352aeSJohn Forte 	stmfGroupName groupName = {0};
1558fcf3ce44SJohn Forte 
1559fcf3ce44SJohn Forte 	(void) strlcpy(groupName, operands[0], sizeof (groupName));
1560fcf3ce44SJohn Forte 	(void) mbstowcs(groupNamePrint, (char *)groupName,
15613e7352aeSJohn Forte 	    sizeof (stmfGroupName) - 1);
1562fcf3ce44SJohn Forte 	/* call delete group */
1563fcf3ce44SJohn Forte 	stmfRet = stmfDeleteTargetGroup(&groupName);
1564fcf3ce44SJohn Forte 	switch (stmfRet) {
1565fcf3ce44SJohn Forte 		case STMF_STATUS_SUCCESS:
1566fcf3ce44SJohn Forte 			break;
1567fcf3ce44SJohn Forte 		case STMF_ERROR_NOT_FOUND:
1568fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1569fcf3ce44SJohn Forte 			    groupNamePrint, gettext("not found"));
1570fcf3ce44SJohn Forte 			ret++;
1571fcf3ce44SJohn Forte 			break;
1572fcf3ce44SJohn Forte 		case STMF_ERROR_BUSY:
1573fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1574fcf3ce44SJohn Forte 			    groupNamePrint, gettext("resource busy"));
1575fcf3ce44SJohn Forte 			ret++;
1576fcf3ce44SJohn Forte 			break;
1577fcf3ce44SJohn Forte 		case STMF_ERROR_SERVICE_NOT_FOUND:
1578fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
1579fcf3ce44SJohn Forte 			    gettext("STMF service not found"));
1580fcf3ce44SJohn Forte 			ret++;
1581fcf3ce44SJohn Forte 			break;
1582fcf3ce44SJohn Forte 		case STMF_ERROR_PERM:
1583fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
1584fcf3ce44SJohn Forte 			    gettext("permission denied"));
1585fcf3ce44SJohn Forte 			ret++;
1586fcf3ce44SJohn Forte 			break;
1587fcf3ce44SJohn Forte 		case STMF_ERROR_GROUP_IN_USE:
1588fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1589fcf3ce44SJohn Forte 			    groupNamePrint,
1590fcf3ce44SJohn Forte 			    gettext("group is in use by existing view entry"));
1591fcf3ce44SJohn Forte 			ret++;
1592fcf3ce44SJohn Forte 			break;
1593fcf3ce44SJohn Forte 		case STMF_ERROR_SERVICE_DATA_VERSION:
1594fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
1595fcf3ce44SJohn Forte 			    gettext("STMF service version incorrect"));
1596fcf3ce44SJohn Forte 			ret++;
1597fcf3ce44SJohn Forte 			break;
1598fcf3ce44SJohn Forte 		default:
1599fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1600fcf3ce44SJohn Forte 			    groupNamePrint, gettext("unknown error"));
1601fcf3ce44SJohn Forte 			ret++;
1602fcf3ce44SJohn Forte 			break;
1603fcf3ce44SJohn Forte 	}
1604fcf3ce44SJohn Forte 
1605fcf3ce44SJohn Forte 	return (ret);
1606fcf3ce44SJohn Forte }
1607fcf3ce44SJohn Forte 
1608fcf3ce44SJohn Forte /*
1609fcf3ce44SJohn Forte  * listHostGroupFunc
1610fcf3ce44SJohn Forte  *
1611fcf3ce44SJohn Forte  * Lists the specified host groups or all if none are specified
1612fcf3ce44SJohn Forte  *
1613fcf3ce44SJohn Forte  */
1614fcf3ce44SJohn Forte /*ARGSUSED*/
1615fcf3ce44SJohn Forte static int
1616fcf3ce44SJohn Forte listHostGroupFunc(int operandLen, char *operands[], cmdOptions_t *options,
1617fcf3ce44SJohn Forte     void *args)
1618fcf3ce44SJohn Forte {
1619fcf3ce44SJohn Forte 	int ret = 0;
1620fcf3ce44SJohn Forte 	int stmfRet;
1621fcf3ce44SJohn Forte 	int i, j, outerLoop;
1622fcf3ce44SJohn Forte 	boolean_t verbose = B_FALSE;
1623fcf3ce44SJohn Forte 	boolean_t found = B_TRUE;
1624fcf3ce44SJohn Forte 	boolean_t operandEntered;
1625fcf3ce44SJohn Forte 	stmfGroupList *groupList;
1626fcf3ce44SJohn Forte 	stmfGroupProperties *groupProps;
1627fcf3ce44SJohn Forte 	wchar_t operandName[sizeof (stmfGroupName)];
1628fcf3ce44SJohn Forte 	wchar_t groupNamePrint[sizeof (stmfGroupName)];
1629fcf3ce44SJohn Forte 
1630fcf3ce44SJohn Forte 	for (; options->optval; options++) {
1631fcf3ce44SJohn Forte 		switch (options->optval) {
1632fcf3ce44SJohn Forte 			case 'v':
1633fcf3ce44SJohn Forte 				verbose = B_TRUE;
1634fcf3ce44SJohn Forte 				break;
1635fcf3ce44SJohn Forte 			default:
1636fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
1637fcf3ce44SJohn Forte 				    cmdName, options->optval,
1638fcf3ce44SJohn Forte 				    gettext("unknown option"));
1639fcf3ce44SJohn Forte 				return (1);
1640fcf3ce44SJohn Forte 		}
1641fcf3ce44SJohn Forte 	}
1642fcf3ce44SJohn Forte 
1643fcf3ce44SJohn Forte 	if (operandLen > 0) {
1644fcf3ce44SJohn Forte 		outerLoop = operandLen;
1645fcf3ce44SJohn Forte 		operandEntered = B_TRUE;
1646fcf3ce44SJohn Forte 	} else {
1647fcf3ce44SJohn Forte 		outerLoop = 1;
1648fcf3ce44SJohn Forte 		operandEntered = B_FALSE;
1649fcf3ce44SJohn Forte 	}
1650fcf3ce44SJohn Forte 
1651fcf3ce44SJohn Forte 	stmfRet = stmfGetHostGroupList(&groupList);
1652fcf3ce44SJohn Forte 	if (stmfRet != STMF_STATUS_SUCCESS) {
1653fcf3ce44SJohn Forte 		switch (stmfRet) {
1654fcf3ce44SJohn Forte 			case STMF_ERROR_BUSY:
1655fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1656fcf3ce44SJohn Forte 				    gettext("resource busy"));
1657fcf3ce44SJohn Forte 				break;
1658fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
1659fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1660fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
1661fcf3ce44SJohn Forte 				break;
1662fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
1663fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1664fcf3ce44SJohn Forte 				    gettext("permission denied"));
1665fcf3ce44SJohn Forte 				break;
1666fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
1667fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1668fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
1669fcf3ce44SJohn Forte 				break;
1670fcf3ce44SJohn Forte 			default:
1671fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1672fcf3ce44SJohn Forte 				    gettext("unknown error"));
1673fcf3ce44SJohn Forte 				break;
1674fcf3ce44SJohn Forte 		}
1675fcf3ce44SJohn Forte 		return (1);
1676fcf3ce44SJohn Forte 	}
1677fcf3ce44SJohn Forte 
1678fcf3ce44SJohn Forte 	for (i = 0; i < outerLoop; i++) {
1679fcf3ce44SJohn Forte 		for (found = B_FALSE, j = 0; j < groupList->cnt; j++) {
1680fcf3ce44SJohn Forte 			(void) mbstowcs(groupNamePrint,
1681fcf3ce44SJohn Forte 			    (char *)groupList->name[j],
16823e7352aeSJohn Forte 			    sizeof (stmfGroupName) - 1);
16833e7352aeSJohn Forte 			groupNamePrint[sizeof (stmfGroupName) - 1] = 0;
1684fcf3ce44SJohn Forte 			if (operandEntered) {
1685fcf3ce44SJohn Forte 				(void) mbstowcs(operandName, operands[i],
16863e7352aeSJohn Forte 				    sizeof (stmfGroupName) - 1);
16873e7352aeSJohn Forte 				operandName[sizeof (stmfGroupName) - 1] = 0;
1688fcf3ce44SJohn Forte 				if (wcscmp(operandName, groupNamePrint)
1689fcf3ce44SJohn Forte 				    == 0) {
1690fcf3ce44SJohn Forte 					found = B_TRUE;
1691fcf3ce44SJohn Forte 				}
1692fcf3ce44SJohn Forte 			}
1693fcf3ce44SJohn Forte 			if ((found && operandEntered) || !operandEntered) {
1694fcf3ce44SJohn Forte 				(void) printf("Host Group: %ws\n",
1695fcf3ce44SJohn Forte 				    groupNamePrint);
1696fcf3ce44SJohn Forte 				if (verbose) {
1697fcf3ce44SJohn Forte 					stmfRet = stmfGetHostGroupMembers(
1698fcf3ce44SJohn Forte 					    &(groupList->name[j]), &groupProps);
1699fcf3ce44SJohn Forte 					if (stmfRet != STMF_STATUS_SUCCESS) {
1700fcf3ce44SJohn Forte 						return (1);
1701fcf3ce44SJohn Forte 					}
1702fcf3ce44SJohn Forte 					printGroupProps(groupProps);
1703fcf3ce44SJohn Forte 				}
1704fcf3ce44SJohn Forte 				if (found && operandEntered) {
1705fcf3ce44SJohn Forte 					break;
1706fcf3ce44SJohn Forte 				}
1707fcf3ce44SJohn Forte 			}
1708fcf3ce44SJohn Forte 
1709fcf3ce44SJohn Forte 		}
1710fcf3ce44SJohn Forte 		if (operandEntered && !found) {
1711fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
1712fcf3ce44SJohn Forte 			    operands[i], gettext("not found"));
1713fcf3ce44SJohn Forte 			ret = 1;
1714fcf3ce44SJohn Forte 		}
1715fcf3ce44SJohn Forte 	}
1716fcf3ce44SJohn Forte 	return (ret);
1717fcf3ce44SJohn Forte }
1718fcf3ce44SJohn Forte 
1719fcf3ce44SJohn Forte /*
1720fcf3ce44SJohn Forte  * printGroupProps
1721fcf3ce44SJohn Forte  *
1722fcf3ce44SJohn Forte  * Prints group members for target or host groups
1723fcf3ce44SJohn Forte  *
1724fcf3ce44SJohn Forte  */
1725fcf3ce44SJohn Forte static void
1726fcf3ce44SJohn Forte printGroupProps(stmfGroupProperties *groupProps)
1727fcf3ce44SJohn Forte {
1728fcf3ce44SJohn Forte 	int i;
17293e7352aeSJohn Forte 	wchar_t memberIdent[sizeof (groupProps->name[0].ident) + 1] = {0};
1730fcf3ce44SJohn Forte 
1731fcf3ce44SJohn Forte 
1732fcf3ce44SJohn Forte 	for (i = 0; i < groupProps->cnt; i++) {
1733fcf3ce44SJohn Forte 		(void) mbstowcs(memberIdent, (char *)groupProps->name[i].ident,
17343e7352aeSJohn Forte 		    sizeof (groupProps->name[0].ident));
1735fcf3ce44SJohn Forte 		(void) printf("\tMember: %ws\n", memberIdent);
1736fcf3ce44SJohn Forte 	}
1737fcf3ce44SJohn Forte }
1738fcf3ce44SJohn Forte 
1739fcf3ce44SJohn Forte /*
1740fcf3ce44SJohn Forte  * listTargetGroupFunc
1741fcf3ce44SJohn Forte  *
1742fcf3ce44SJohn Forte  * Lists the specified target groups or all if none are specified
1743fcf3ce44SJohn Forte  *
1744fcf3ce44SJohn Forte  */
1745fcf3ce44SJohn Forte /*ARGSUSED*/
1746fcf3ce44SJohn Forte static int
1747fcf3ce44SJohn Forte listTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options,
1748fcf3ce44SJohn Forte     void *args)
1749fcf3ce44SJohn Forte {
1750fcf3ce44SJohn Forte 	int ret = 0;
1751fcf3ce44SJohn Forte 	int stmfRet;
1752fcf3ce44SJohn Forte 	int i, j, outerLoop;
1753fcf3ce44SJohn Forte 	boolean_t verbose = B_FALSE;
1754fcf3ce44SJohn Forte 	boolean_t found = B_TRUE;
1755fcf3ce44SJohn Forte 	boolean_t operandEntered;
1756fcf3ce44SJohn Forte 	stmfGroupList *groupList;
1757fcf3ce44SJohn Forte 	stmfGroupProperties *groupProps;
1758fcf3ce44SJohn Forte 	wchar_t operandName[sizeof (stmfGroupName)];
1759fcf3ce44SJohn Forte 	wchar_t groupNamePrint[sizeof (stmfGroupName)];
1760fcf3ce44SJohn Forte 
1761fcf3ce44SJohn Forte 	for (; options->optval; options++) {
1762fcf3ce44SJohn Forte 		switch (options->optval) {
1763fcf3ce44SJohn Forte 			case 'v':
1764fcf3ce44SJohn Forte 				verbose = B_TRUE;
1765fcf3ce44SJohn Forte 				break;
1766fcf3ce44SJohn Forte 			default:
1767fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
1768fcf3ce44SJohn Forte 				    cmdName, options->optval,
1769fcf3ce44SJohn Forte 				    gettext("unknown option"));
1770fcf3ce44SJohn Forte 				return (1);
1771fcf3ce44SJohn Forte 		}
1772fcf3ce44SJohn Forte 	}
1773fcf3ce44SJohn Forte 
1774fcf3ce44SJohn Forte 	if (operandLen > 0) {
1775fcf3ce44SJohn Forte 		outerLoop = operandLen;
1776fcf3ce44SJohn Forte 		operandEntered = B_TRUE;
1777fcf3ce44SJohn Forte 	} else {
1778fcf3ce44SJohn Forte 		outerLoop = 1;
1779fcf3ce44SJohn Forte 		operandEntered = B_FALSE;
1780fcf3ce44SJohn Forte 	}
1781fcf3ce44SJohn Forte 
1782fcf3ce44SJohn Forte 	stmfRet = stmfGetTargetGroupList(&groupList);
1783fcf3ce44SJohn Forte 	if (stmfRet != STMF_STATUS_SUCCESS) {
1784fcf3ce44SJohn Forte 		switch (stmfRet) {
1785fcf3ce44SJohn Forte 			case STMF_ERROR_BUSY:
1786fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1787fcf3ce44SJohn Forte 				    gettext("resource busy"));
1788fcf3ce44SJohn Forte 				break;
1789fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
1790fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1791fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
1792fcf3ce44SJohn Forte 				break;
1793fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
1794fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1795fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
1796fcf3ce44SJohn Forte 				break;
1797fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
1798fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1799fcf3ce44SJohn Forte 				    gettext("permission denied"));
1800fcf3ce44SJohn Forte 				break;
1801fcf3ce44SJohn Forte 			default:
1802fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1803fcf3ce44SJohn Forte 				    gettext("unknown error"));
1804fcf3ce44SJohn Forte 				break;
1805fcf3ce44SJohn Forte 		}
1806fcf3ce44SJohn Forte 		return (1);
1807fcf3ce44SJohn Forte 	}
1808fcf3ce44SJohn Forte 
1809fcf3ce44SJohn Forte 	for (i = 0; i < outerLoop; i++) {
1810fcf3ce44SJohn Forte 		for (found = B_FALSE, j = 0; j < groupList->cnt; j++) {
1811fcf3ce44SJohn Forte 			(void) mbstowcs(groupNamePrint,
1812fcf3ce44SJohn Forte 			    (char *)groupList->name[j],
18133e7352aeSJohn Forte 			    sizeof (stmfGroupName) - 1);
18143e7352aeSJohn Forte 			groupNamePrint[sizeof (stmfGroupName) - 1] = 0;
1815fcf3ce44SJohn Forte 			if (operandEntered) {
1816fcf3ce44SJohn Forte 				(void) mbstowcs(operandName, operands[i],
18173e7352aeSJohn Forte 				    sizeof (stmfGroupName) - 1);
18183e7352aeSJohn Forte 				operandName[sizeof (stmfGroupName) - 1] = 0;
1819fcf3ce44SJohn Forte 				if (wcscmp(operandName, groupNamePrint)
1820fcf3ce44SJohn Forte 				    == 0) {
1821fcf3ce44SJohn Forte 					found = B_TRUE;
1822fcf3ce44SJohn Forte 				}
1823fcf3ce44SJohn Forte 			}
1824fcf3ce44SJohn Forte 			if ((found && operandEntered) || !operandEntered) {
1825fcf3ce44SJohn Forte 				(void) printf("Target Group: %ws\n",
1826fcf3ce44SJohn Forte 				    groupNamePrint);
1827fcf3ce44SJohn Forte 				if (verbose) {
1828fcf3ce44SJohn Forte 					stmfRet = stmfGetTargetGroupMembers(
1829fcf3ce44SJohn Forte 					    &(groupList->name[j]), &groupProps);
1830fcf3ce44SJohn Forte 					if (stmfRet != STMF_STATUS_SUCCESS) {
1831fcf3ce44SJohn Forte 						return (1);
1832fcf3ce44SJohn Forte 					}
1833fcf3ce44SJohn Forte 					printGroupProps(groupProps);
1834fcf3ce44SJohn Forte 				}
1835fcf3ce44SJohn Forte 				if (found && operandEntered) {
1836fcf3ce44SJohn Forte 					break;
1837fcf3ce44SJohn Forte 				}
1838fcf3ce44SJohn Forte 			}
1839fcf3ce44SJohn Forte 
1840fcf3ce44SJohn Forte 		}
1841fcf3ce44SJohn Forte 		if (operandEntered && !found) {
1842fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
1843fcf3ce44SJohn Forte 			    operands[i], gettext("not found"));
1844fcf3ce44SJohn Forte 			ret = 1;
1845fcf3ce44SJohn Forte 		}
1846fcf3ce44SJohn Forte 	}
1847fcf3ce44SJohn Forte 	return (ret);
1848fcf3ce44SJohn Forte }
1849fcf3ce44SJohn Forte 
1850fcf3ce44SJohn Forte /*
1851fcf3ce44SJohn Forte  * listLuFunc
1852fcf3ce44SJohn Forte  *
1853fcf3ce44SJohn Forte  * List the logical units and optionally the properties
1854fcf3ce44SJohn Forte  *
1855fcf3ce44SJohn Forte  */
1856fcf3ce44SJohn Forte /*ARGSUSED*/
1857fcf3ce44SJohn Forte static int
1858fcf3ce44SJohn Forte listLuFunc(int operandLen, char *operands[], cmdOptions_t *options, void *args)
1859fcf3ce44SJohn Forte {
1860fcf3ce44SJohn Forte 	cmdOptions_t *optionList = options;
1861fcf3ce44SJohn Forte 	boolean_t operandEntered;
1862fcf3ce44SJohn Forte 	int i, j;
1863fcf3ce44SJohn Forte 	int ret = 0;
1864fcf3ce44SJohn Forte 	int stmfRet;
1865fcf3ce44SJohn Forte 	int outerLoop;
1866fcf3ce44SJohn Forte 	unsigned int inGuid[sizeof (stmfGuid)];
1867fcf3ce44SJohn Forte 	stmfGuid cmpGuid;
1868fcf3ce44SJohn Forte 	boolean_t verbose = B_FALSE;
1869fcf3ce44SJohn Forte 	boolean_t found;
1870fcf3ce44SJohn Forte 	char sGuid[GUID_INPUT + 1];
1871fcf3ce44SJohn Forte 	stmfGuidList *luList;
1872fcf3ce44SJohn Forte 	stmfLogicalUnitProperties luProps;
1873fcf3ce44SJohn Forte 	boolean_t invalidInput = B_FALSE;
1874fcf3ce44SJohn Forte 	stmfViewEntryList *viewEntryList;
1875fcf3ce44SJohn Forte 
1876fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
1877fcf3ce44SJohn Forte 		switch (optionList->optval) {
1878fcf3ce44SJohn Forte 			case 'v':
1879fcf3ce44SJohn Forte 				verbose = B_TRUE;
1880fcf3ce44SJohn Forte 				break;
1881fcf3ce44SJohn Forte 		}
1882fcf3ce44SJohn Forte 	}
1883fcf3ce44SJohn Forte 
1884fcf3ce44SJohn Forte 	if ((stmfRet = stmfGetLogicalUnitList(&luList))
1885fcf3ce44SJohn Forte 	    != STMF_STATUS_SUCCESS) {
1886fcf3ce44SJohn Forte 		switch (stmfRet) {
1887fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
1888fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1889fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
1890fcf3ce44SJohn Forte 				break;
1891fcf3ce44SJohn Forte 			case STMF_ERROR_BUSY:
1892fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1893fcf3ce44SJohn Forte 				    gettext("resource busy"));
1894fcf3ce44SJohn Forte 				break;
1895fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
1896fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1897fcf3ce44SJohn Forte 				    gettext("permission denied"));
1898fcf3ce44SJohn Forte 				break;
1899fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
1900fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1901fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
1902fcf3ce44SJohn Forte 				break;
1903fcf3ce44SJohn Forte 			default:
1904fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
1905fcf3ce44SJohn Forte 				    gettext("list failed"));
1906fcf3ce44SJohn Forte 				break;
1907fcf3ce44SJohn Forte 		}
1908fcf3ce44SJohn Forte 		return (1);
1909fcf3ce44SJohn Forte 	}
1910fcf3ce44SJohn Forte 
1911fcf3ce44SJohn Forte 	if (operandLen > 0) {
1912fcf3ce44SJohn Forte 		operandEntered = B_TRUE;
1913fcf3ce44SJohn Forte 		outerLoop = operandLen;
1914fcf3ce44SJohn Forte 	} else {
1915fcf3ce44SJohn Forte 		operandEntered = B_FALSE;
1916fcf3ce44SJohn Forte 		outerLoop = 1;
1917fcf3ce44SJohn Forte 	}
1918fcf3ce44SJohn Forte 
1919fcf3ce44SJohn Forte 
1920fcf3ce44SJohn Forte 	for (invalidInput = B_FALSE, i = 0; i < outerLoop; i++) {
1921fcf3ce44SJohn Forte 		if (operandEntered) {
1922fcf3ce44SJohn Forte 			if (strlen(operands[i]) != GUID_INPUT) {
1923fcf3ce44SJohn Forte 				invalidInput = B_TRUE;
1924fcf3ce44SJohn Forte 			} else {
1925fcf3ce44SJohn Forte 				for (j = 0; j < GUID_INPUT; j++) {
1926fcf3ce44SJohn Forte 					if (!isxdigit(operands[i][j])) {
1927fcf3ce44SJohn Forte 						invalidInput = B_TRUE;
1928fcf3ce44SJohn Forte 						break;
1929fcf3ce44SJohn Forte 					}
1930fcf3ce44SJohn Forte 				}
1931fcf3ce44SJohn Forte 			}
1932fcf3ce44SJohn Forte 			if (invalidInput) {
1933fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s%d%s\n",
1934fcf3ce44SJohn Forte 				    cmdName, operands[i], gettext("must be "),
1935fcf3ce44SJohn Forte 				    GUID_INPUT,
1936fcf3ce44SJohn Forte 				    gettext(" hexadecimal digits long"));
19378fe96085Stim szeto 				invalidInput = B_FALSE;
1938fcf3ce44SJohn Forte 				continue;
1939fcf3ce44SJohn Forte 			}
1940fcf3ce44SJohn Forte 
1941fcf3ce44SJohn Forte 			for (j = 0; j < GUID_INPUT; j++) {
1942fcf3ce44SJohn Forte 				sGuid[j] = tolower(operands[i][j]);
1943fcf3ce44SJohn Forte 			}
1944fcf3ce44SJohn Forte 			sGuid[j] = 0;
1945fcf3ce44SJohn Forte 
1946fcf3ce44SJohn Forte 			(void) sscanf(sGuid,
1947fcf3ce44SJohn Forte 			    "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
1948fcf3ce44SJohn Forte 			    &inGuid[0], &inGuid[1], &inGuid[2], &inGuid[3],
1949fcf3ce44SJohn Forte 			    &inGuid[4], &inGuid[5], &inGuid[6], &inGuid[7],
1950fcf3ce44SJohn Forte 			    &inGuid[8], &inGuid[9], &inGuid[10], &inGuid[11],
1951fcf3ce44SJohn Forte 			    &inGuid[12], &inGuid[13], &inGuid[14], &inGuid[15]);
1952fcf3ce44SJohn Forte 
1953fcf3ce44SJohn Forte 			for (j = 0; j < sizeof (stmfGuid); j++) {
1954fcf3ce44SJohn Forte 				cmpGuid.guid[j] = inGuid[j];
1955fcf3ce44SJohn Forte 			}
1956fcf3ce44SJohn Forte 		}
1957fcf3ce44SJohn Forte 
1958fcf3ce44SJohn Forte 		for (found = B_FALSE, j = 0; j < luList->cnt; j++) {
1959fcf3ce44SJohn Forte 			if (operandEntered) {
1960fcf3ce44SJohn Forte 				if (bcmp(luList->guid[j].guid, cmpGuid.guid,
1961fcf3ce44SJohn Forte 				    sizeof (stmfGuid)) == 0) {
1962fcf3ce44SJohn Forte 					found = B_TRUE;
1963fcf3ce44SJohn Forte 				}
1964fcf3ce44SJohn Forte 			}
1965fcf3ce44SJohn Forte 			if ((found && operandEntered) || !operandEntered) {
1966fcf3ce44SJohn Forte 				(void) printf("LU Name: ");
1967fcf3ce44SJohn Forte 				printGuid(&luList->guid[j], stdout);
1968fcf3ce44SJohn Forte 				(void) printf("\n");
1969fcf3ce44SJohn Forte 
1970fcf3ce44SJohn Forte 				if (verbose) {
1971fcf3ce44SJohn Forte 					stmfRet = stmfGetLogicalUnitProperties(
1972fcf3ce44SJohn Forte 					    &(luList->guid[j]), &luProps);
1973fcf3ce44SJohn Forte 					if (stmfRet == STMF_STATUS_SUCCESS) {
1974fcf3ce44SJohn Forte 						printLuProps(&luProps);
1975fcf3ce44SJohn Forte 					} else {
1976fcf3ce44SJohn Forte 						(void) fprintf(stderr, "%s:",
1977fcf3ce44SJohn Forte 						    cmdName);
1978fcf3ce44SJohn Forte 						printGuid(&luList->guid[j],
1979fcf3ce44SJohn Forte 						    stderr);
1980fcf3ce44SJohn Forte 						(void) fprintf(stderr, "%s\n",
1981fcf3ce44SJohn Forte 						    gettext(" get properties "
1982fcf3ce44SJohn Forte 						    "failed"));
1983fcf3ce44SJohn Forte 					}
1984fcf3ce44SJohn Forte 					stmfRet = stmfGetViewEntryList(
1985fcf3ce44SJohn Forte 					    &(luList->guid[j]),
1986fcf3ce44SJohn Forte 					    &viewEntryList);
1987fcf3ce44SJohn Forte 					(void) printf(PROPS_FORMAT,
1988fcf3ce44SJohn Forte 					    "View Entry Count");
1989fcf3ce44SJohn Forte 					if (stmfRet == STMF_STATUS_SUCCESS) {
1990fcf3ce44SJohn Forte 						(void) printf("%d",
1991fcf3ce44SJohn Forte 						    viewEntryList->cnt);
1992fcf3ce44SJohn Forte 					} else if (stmfRet ==
1993fcf3ce44SJohn Forte 					    STMF_ERROR_NOT_FOUND) {
1994fcf3ce44SJohn Forte 						(void) printf("0");
1995fcf3ce44SJohn Forte 					} else {
1996fcf3ce44SJohn Forte 						(void) printf("unknown");
1997fcf3ce44SJohn Forte 					}
1998fcf3ce44SJohn Forte 					(void) printf("\n");
19998fe96085Stim szeto 					ret = printExtLuProps(
20008fe96085Stim szeto 					    &(luList->guid[j]));
2001fcf3ce44SJohn Forte 				}
2002fcf3ce44SJohn Forte 				if (found && operandEntered) {
2003fcf3ce44SJohn Forte 					break;
2004fcf3ce44SJohn Forte 				}
2005fcf3ce44SJohn Forte 			}
2006fcf3ce44SJohn Forte 
2007fcf3ce44SJohn Forte 		}
2008fcf3ce44SJohn Forte 		if (operandEntered && !found) {
2009fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2010fcf3ce44SJohn Forte 			    operands[i], gettext("not found"));
2011fcf3ce44SJohn Forte 			ret = 1;
2012fcf3ce44SJohn Forte 		}
2013fcf3ce44SJohn Forte 	}
2014fcf3ce44SJohn Forte 
2015fcf3ce44SJohn Forte 	return (ret);
2016fcf3ce44SJohn Forte }
2017fcf3ce44SJohn Forte 
2018fcf3ce44SJohn Forte static void
2019fcf3ce44SJohn Forte printGuid(stmfGuid *guid, FILE *stream)
2020fcf3ce44SJohn Forte {
2021fcf3ce44SJohn Forte 	int i;
2022fcf3ce44SJohn Forte 	for (i = 0; i < 16; i++) {
2023fcf3ce44SJohn Forte 		(void) fprintf(stream, "%02X", guid->guid[i]);
2024fcf3ce44SJohn Forte 	}
2025fcf3ce44SJohn Forte }
2026fcf3ce44SJohn Forte 
20278fe96085Stim szeto static int
20288fe96085Stim szeto printExtLuProps(stmfGuid *guid)
20298fe96085Stim szeto {
20308fe96085Stim szeto 	int stmfRet;
20318fe96085Stim szeto 	luResource hdl = NULL;
20328fe96085Stim szeto 	int ret = 0;
20338fe96085Stim szeto 	char propVal[MAXNAMELEN];
20348fe96085Stim szeto 	size_t propValSize = sizeof (propVal);
20358fe96085Stim szeto 
20368fe96085Stim szeto 	if ((stmfRet = stmfGetLuResource(guid, &hdl))
20378fe96085Stim szeto 	    != STMF_STATUS_SUCCESS) {
20388fe96085Stim szeto 		switch (stmfRet) {
20398fe96085Stim szeto 			case STMF_ERROR_BUSY:
20408fe96085Stim szeto 				(void) fprintf(stderr, "%s: %s\n", cmdName,
20418fe96085Stim szeto 				    gettext("resource busy"));
20428fe96085Stim szeto 				break;
20438fe96085Stim szeto 			case STMF_ERROR_PERM:
20448fe96085Stim szeto 				(void) fprintf(stderr, "%s: %s\n", cmdName,
20458fe96085Stim szeto 				    gettext("permission denied"));
20468fe96085Stim szeto 				break;
20478fe96085Stim szeto 			case STMF_ERROR_NOT_FOUND:
20488fe96085Stim szeto 				/* No error here */
20498fe96085Stim szeto 				return (0);
20508fe96085Stim szeto 				break;
20518fe96085Stim szeto 			default:
20528fe96085Stim szeto 				(void) fprintf(stderr, "%s: %s\n", cmdName,
20538fe96085Stim szeto 				    gettext("get extended properties failed"));
20548fe96085Stim szeto 				break;
20558fe96085Stim szeto 		}
20568fe96085Stim szeto 		return (1);
20578fe96085Stim szeto 	}
20588fe96085Stim szeto 
20598fe96085Stim szeto 	stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_FILENAME, propVal,
20608fe96085Stim szeto 	    &propValSize);
20618fe96085Stim szeto 	(void) printf(PROPS_FORMAT, "Data File");
20628fe96085Stim szeto 	if (stmfRet == STMF_STATUS_SUCCESS) {
20638fe96085Stim szeto 		(void) printf("%s\n", propVal);
20648fe96085Stim szeto 	} else if (stmfRet == STMF_ERROR_NO_PROP) {
20658fe96085Stim szeto 		(void) printf("not set\n");
20668fe96085Stim szeto 	} else {
20678fe96085Stim szeto 		(void) printf("<error retrieving property>\n");
20688fe96085Stim szeto 		ret++;
20698fe96085Stim szeto 	}
20708fe96085Stim szeto 
20718fe96085Stim szeto 	stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_META_FILENAME, propVal,
20728fe96085Stim szeto 	    &propValSize);
20738fe96085Stim szeto 	(void) printf(PROPS_FORMAT, "Meta File");
20748fe96085Stim szeto 	if (stmfRet == STMF_STATUS_SUCCESS) {
20758fe96085Stim szeto 		(void) printf("%s\n", propVal);
20768fe96085Stim szeto 	} else if (stmfRet == STMF_ERROR_NO_PROP) {
20778fe96085Stim szeto 		(void) printf("not set\n");
20788fe96085Stim szeto 	} else {
20798fe96085Stim szeto 		(void) printf("<error retrieving property>\n");
20808fe96085Stim szeto 		ret++;
20818fe96085Stim szeto 	}
20828fe96085Stim szeto 
20838fe96085Stim szeto 	stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_SIZE, propVal,
20848fe96085Stim szeto 	    &propValSize);
20858fe96085Stim szeto 	(void) printf(PROPS_FORMAT, "Size");
20868fe96085Stim szeto 	if (stmfRet == STMF_STATUS_SUCCESS) {
20878fe96085Stim szeto 		(void) printf("%s\n", propVal);
20888fe96085Stim szeto 	} else if (stmfRet == STMF_ERROR_NO_PROP) {
20898fe96085Stim szeto 		(void) printf("not set\n");
20908fe96085Stim szeto 	} else {
20918fe96085Stim szeto 		(void) printf("<error retrieving property>\n");
20928fe96085Stim szeto 		ret++;
20938fe96085Stim szeto 	}
20948fe96085Stim szeto 
20958fe96085Stim szeto 	stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_BLOCK_SIZE, propVal,
20968fe96085Stim szeto 	    &propValSize);
20978fe96085Stim szeto 	(void) printf(PROPS_FORMAT, "Block Size");
20988fe96085Stim szeto 	if (stmfRet == STMF_STATUS_SUCCESS) {
20998fe96085Stim szeto 		(void) printf("%s\n", propVal);
21008fe96085Stim szeto 	} else if (stmfRet == STMF_ERROR_NO_PROP) {
21018fe96085Stim szeto 		(void) printf("not set\n");
21028fe96085Stim szeto 	} else {
21038fe96085Stim szeto 		(void) printf("<error retrieving property>\n");
21048fe96085Stim szeto 		ret++;
21058fe96085Stim szeto 	}
21068fe96085Stim szeto 
2107*2f624233SNattuvetty Bhavyan 	stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_MGMT_URL, propVal,
2108*2f624233SNattuvetty Bhavyan 	    &propValSize);
2109*2f624233SNattuvetty Bhavyan 	(void) printf(PROPS_FORMAT, "Management URL");
2110*2f624233SNattuvetty Bhavyan 	if (stmfRet == STMF_STATUS_SUCCESS) {
2111*2f624233SNattuvetty Bhavyan 		(void) printf("%s\n", propVal);
2112*2f624233SNattuvetty Bhavyan 	} else if (stmfRet == STMF_ERROR_NO_PROP) {
2113*2f624233SNattuvetty Bhavyan 		(void) printf("not set\n");
2114*2f624233SNattuvetty Bhavyan 	} else {
2115*2f624233SNattuvetty Bhavyan 		(void) printf("<error retrieving property>\n");
2116*2f624233SNattuvetty Bhavyan 		ret++;
2117*2f624233SNattuvetty Bhavyan 	}
2118*2f624233SNattuvetty Bhavyan 
21198fe96085Stim szeto 	stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_VID, propVal,
21208fe96085Stim szeto 	    &propValSize);
21218fe96085Stim szeto 	(void) printf(PROPS_FORMAT, "Vendor ID");
21228fe96085Stim szeto 	if (stmfRet == STMF_STATUS_SUCCESS) {
21238fe96085Stim szeto 		(void) printf("%s\n", propVal);
21248fe96085Stim szeto 	} else if (stmfRet == STMF_ERROR_NO_PROP) {
21258fe96085Stim szeto 		(void) printf("not set\n");
21268fe96085Stim szeto 	} else {
21278fe96085Stim szeto 		(void) printf("<error retrieving property>\n");
21288fe96085Stim szeto 		ret++;
21298fe96085Stim szeto 	}
21308fe96085Stim szeto 
21318fe96085Stim szeto 	stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_PID, propVal,
21328fe96085Stim szeto 	    &propValSize);
21338fe96085Stim szeto 	(void) printf(PROPS_FORMAT, "Product ID");
21348fe96085Stim szeto 	if (stmfRet == STMF_STATUS_SUCCESS) {
21358fe96085Stim szeto 		(void) printf("%s\n", propVal);
21368fe96085Stim szeto 	} else if (stmfRet == STMF_ERROR_NO_PROP) {
21378fe96085Stim szeto 		(void) printf("not set\n");
21388fe96085Stim szeto 	} else {
21398fe96085Stim szeto 		(void) printf("<error retrieving property>\n");
21408fe96085Stim szeto 		ret++;
21418fe96085Stim szeto 	}
21428fe96085Stim szeto 
21438fe96085Stim szeto 	stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_SERIAL_NUM, propVal,
21448fe96085Stim szeto 	    &propValSize);
21458fe96085Stim szeto 	(void) printf(PROPS_FORMAT, "Serial Num");
21468fe96085Stim szeto 	if (stmfRet == STMF_STATUS_SUCCESS) {
21478fe96085Stim szeto 		(void) printf("%s\n", propVal);
21488fe96085Stim szeto 	} else if (stmfRet == STMF_ERROR_NO_PROP) {
21498fe96085Stim szeto 		(void) printf("not set\n");
21508fe96085Stim szeto 	} else {
21518fe96085Stim szeto 		(void) printf("<error retrieving property>\n");
21528fe96085Stim szeto 		ret++;
21538fe96085Stim szeto 	}
21548fe96085Stim szeto 
21558fe96085Stim szeto 	stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_WRITE_PROTECT, propVal,
21568fe96085Stim szeto 	    &propValSize);
21578fe96085Stim szeto 	(void) printf(PROPS_FORMAT, "Write Protect");
21588fe96085Stim szeto 	if (stmfRet == STMF_STATUS_SUCCESS) {
21598fe96085Stim szeto 		(void) printf("%s\n",
21608fe96085Stim szeto 		    strcasecmp(propVal, "true") ? "Disabled" : "Enabled");
21618fe96085Stim szeto 	} else if (stmfRet == STMF_ERROR_NO_PROP) {
21628fe96085Stim szeto 		(void) printf("not set\n");
21638fe96085Stim szeto 	} else {
21648fe96085Stim szeto 		(void) printf("<error retrieving property>\n");
21658fe96085Stim szeto 		ret++;
21668fe96085Stim szeto 	}
21678fe96085Stim szeto 
21688fe96085Stim szeto 	stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_WRITE_CACHE_DISABLE, propVal,
21698fe96085Stim szeto 	    &propValSize);
21708fe96085Stim szeto 	(void) printf(PROPS_FORMAT, "Writeback Cache");
21718fe96085Stim szeto 	if (stmfRet == STMF_STATUS_SUCCESS) {
21728fe96085Stim szeto 		(void) printf("%s\n",
21738fe96085Stim szeto 		    strcasecmp(propVal, "true") ? "Enabled" : "Disabled");
21748fe96085Stim szeto 	} else if (stmfRet == STMF_ERROR_NO_PROP) {
21758fe96085Stim szeto 		(void) printf("not set\n");
21768fe96085Stim szeto 	} else {
21778fe96085Stim szeto 		(void) printf("<error retrieving property>\n");
21788fe96085Stim szeto 		ret++;
21798fe96085Stim szeto 	}
21808fe96085Stim szeto 
21818fe96085Stim szeto 
21828fe96085Stim szeto 	(void) stmfFreeLuResource(hdl);
21838fe96085Stim szeto 	return (ret);
21848fe96085Stim szeto 
21858fe96085Stim szeto }
21868fe96085Stim szeto 
2187fcf3ce44SJohn Forte 
2188fcf3ce44SJohn Forte /*
2189fcf3ce44SJohn Forte  * printLuProps
2190fcf3ce44SJohn Forte  *
2191fcf3ce44SJohn Forte  * Prints the properties for a logical unit
2192fcf3ce44SJohn Forte  *
2193fcf3ce44SJohn Forte  */
2194fcf3ce44SJohn Forte static void
2195fcf3ce44SJohn Forte printLuProps(stmfLogicalUnitProperties *luProps)
2196fcf3ce44SJohn Forte {
2197fcf3ce44SJohn Forte 	(void) printf(PROPS_FORMAT, "Operational Status");
2198fcf3ce44SJohn Forte 	switch (luProps->status) {
2199fcf3ce44SJohn Forte 		case STMF_LOGICAL_UNIT_ONLINE:
2200fcf3ce44SJohn Forte 			(void) printf("Online");
2201fcf3ce44SJohn Forte 			break;
2202fcf3ce44SJohn Forte 		case STMF_LOGICAL_UNIT_OFFLINE:
2203fcf3ce44SJohn Forte 			(void) printf("Offline");
2204fcf3ce44SJohn Forte 			break;
2205fcf3ce44SJohn Forte 		case STMF_LOGICAL_UNIT_ONLINING:
2206fcf3ce44SJohn Forte 			(void) printf("Onlining");
2207fcf3ce44SJohn Forte 			break;
2208fcf3ce44SJohn Forte 		case STMF_LOGICAL_UNIT_OFFLINING:
2209fcf3ce44SJohn Forte 			(void) printf("Offlining");
2210fcf3ce44SJohn Forte 			break;
2211fcf3ce44SJohn Forte 		case STMF_LOGICAL_UNIT_UNREGISTERED:
2212fcf3ce44SJohn Forte 			(void) printf("unregistered");
2213fcf3ce44SJohn Forte 			(void) strncpy(luProps->providerName, "unregistered",
2214fcf3ce44SJohn Forte 			    sizeof (luProps->providerName));
2215fcf3ce44SJohn Forte 			break;
2216fcf3ce44SJohn Forte 		default:
2217fcf3ce44SJohn Forte 			(void) printf("unknown");
2218fcf3ce44SJohn Forte 			break;
2219fcf3ce44SJohn Forte 	}
2220fcf3ce44SJohn Forte 	(void) printf("\n");
2221fcf3ce44SJohn Forte 	(void) printf(PROPS_FORMAT, "Provider Name");
2222fcf3ce44SJohn Forte 	if (luProps->providerName[0] != 0) {
2223fcf3ce44SJohn Forte 		(void) printf("%s", luProps->providerName);
2224fcf3ce44SJohn Forte 	} else {
2225fcf3ce44SJohn Forte 		(void) printf("unknown");
2226fcf3ce44SJohn Forte 	}
2227fcf3ce44SJohn Forte 	(void) printf("\n");
2228fcf3ce44SJohn Forte 	(void) printf(PROPS_FORMAT, "Alias");
2229fcf3ce44SJohn Forte 	if (luProps->alias[0] != 0) {
2230fcf3ce44SJohn Forte 		(void) printf("%s", luProps->alias);
2231fcf3ce44SJohn Forte 	} else {
2232fcf3ce44SJohn Forte 		(void) printf("-");
2233fcf3ce44SJohn Forte 	}
2234fcf3ce44SJohn Forte 	(void) printf("\n");
2235fcf3ce44SJohn Forte }
2236fcf3ce44SJohn Forte 
2237fcf3ce44SJohn Forte /*
2238fcf3ce44SJohn Forte  * printTargetProps
2239fcf3ce44SJohn Forte  *
2240fcf3ce44SJohn Forte  * Prints the properties for a target
2241fcf3ce44SJohn Forte  *
2242fcf3ce44SJohn Forte  */
2243fcf3ce44SJohn Forte static void
2244fcf3ce44SJohn Forte printTargetProps(stmfTargetProperties *targetProps)
2245fcf3ce44SJohn Forte {
2246fcf3ce44SJohn Forte 	(void) printf(PROPS_FORMAT, "Operational Status");
2247fcf3ce44SJohn Forte 	switch (targetProps->status) {
2248fcf3ce44SJohn Forte 		case STMF_TARGET_PORT_ONLINE:
2249fcf3ce44SJohn Forte 			(void) printf("Online");
2250fcf3ce44SJohn Forte 			break;
2251fcf3ce44SJohn Forte 		case STMF_TARGET_PORT_OFFLINE:
2252fcf3ce44SJohn Forte 			(void) printf("Offline");
2253fcf3ce44SJohn Forte 			break;
2254fcf3ce44SJohn Forte 		case STMF_TARGET_PORT_ONLINING:
2255fcf3ce44SJohn Forte 			(void) printf("Onlining");
2256fcf3ce44SJohn Forte 			break;
2257fcf3ce44SJohn Forte 		case STMF_TARGET_PORT_OFFLINING:
2258fcf3ce44SJohn Forte 			(void) printf("Offlining");
2259fcf3ce44SJohn Forte 			break;
2260fcf3ce44SJohn Forte 		default:
2261fcf3ce44SJohn Forte 			(void) printf("unknown");
2262fcf3ce44SJohn Forte 			break;
2263fcf3ce44SJohn Forte 	}
2264fcf3ce44SJohn Forte 	(void) printf("\n");
2265fcf3ce44SJohn Forte 	(void) printf(PROPS_FORMAT, "Provider Name");
2266fcf3ce44SJohn Forte 	if (targetProps->providerName[0] != 0) {
2267fcf3ce44SJohn Forte 		(void) printf("%s", targetProps->providerName);
2268fcf3ce44SJohn Forte 	}
2269fcf3ce44SJohn Forte 	(void) printf("\n");
2270fcf3ce44SJohn Forte 	(void) printf(PROPS_FORMAT, "Alias");
2271fcf3ce44SJohn Forte 	if (targetProps->alias[0] != 0) {
2272fcf3ce44SJohn Forte 		(void) printf("%s", targetProps->alias);
2273fcf3ce44SJohn Forte 	} else {
2274fcf3ce44SJohn Forte 		(void) printf("-");
2275fcf3ce44SJohn Forte 	}
2276fcf3ce44SJohn Forte 	(void) printf("\n");
2277fcf3ce44SJohn Forte }
2278fcf3ce44SJohn Forte 
2279fcf3ce44SJohn Forte /*
2280fcf3ce44SJohn Forte  * printSessionProps
2281fcf3ce44SJohn Forte  *
2282fcf3ce44SJohn Forte  * Prints the session data
2283fcf3ce44SJohn Forte  *
2284fcf3ce44SJohn Forte  */
2285fcf3ce44SJohn Forte static void
2286fcf3ce44SJohn Forte printSessionProps(stmfSessionList *sessionList)
2287fcf3ce44SJohn Forte {
2288fcf3ce44SJohn Forte 	int i;
2289fcf3ce44SJohn Forte 	char *cTime;
2290fcf3ce44SJohn Forte 	wchar_t initiator[STMF_IDENT_LENGTH + 1];
2291fcf3ce44SJohn Forte 
2292fcf3ce44SJohn Forte 	(void) printf(PROPS_FORMAT, "Sessions");
2293fcf3ce44SJohn Forte 	(void) printf("%d\n", sessionList->cnt);
2294fcf3ce44SJohn Forte 	for (i = 0; i < sessionList->cnt; i++) {
2295fcf3ce44SJohn Forte 		(void) mbstowcs(initiator,
2296fcf3ce44SJohn Forte 		    (char *)sessionList->session[i].initiator.ident,
22973e7352aeSJohn Forte 		    STMF_IDENT_LENGTH);
22983e7352aeSJohn Forte 		initiator[STMF_IDENT_LENGTH] = 0;
2299fcf3ce44SJohn Forte 		(void) printf(LVL3_FORMAT, "Initiator: ");
2300fcf3ce44SJohn Forte 		(void) printf("%ws\n", initiator);
2301fcf3ce44SJohn Forte 		(void) printf(LVL4_FORMAT, "Alias: ");
2302fcf3ce44SJohn Forte 		if (sessionList->session[i].alias[0] != 0) {
2303fcf3ce44SJohn Forte 			(void) printf("%s", sessionList->session[i].alias);
2304fcf3ce44SJohn Forte 		} else {
2305fcf3ce44SJohn Forte 			(void) printf("-");
2306fcf3ce44SJohn Forte 		}
2307fcf3ce44SJohn Forte 		(void) printf("\n");
2308fcf3ce44SJohn Forte 		(void) printf(LVL4_FORMAT, "Logged in since: ");
2309fcf3ce44SJohn Forte 		cTime = ctime(&(sessionList->session[i].creationTime));
2310fcf3ce44SJohn Forte 		if (cTime != NULL) {
2311fcf3ce44SJohn Forte 			(void) printf("%s", cTime);
2312fcf3ce44SJohn Forte 		} else {
2313fcf3ce44SJohn Forte 			(void) printf("unknown\n");
2314fcf3ce44SJohn Forte 		}
2315fcf3ce44SJohn Forte 	}
2316fcf3ce44SJohn Forte }
2317fcf3ce44SJohn Forte 
2318e17f3b22Stim szeto static int
2319e17f3b22Stim szeto getStmfState(stmfState *state)
2320e17f3b22Stim szeto {
2321e17f3b22Stim szeto 	int ret;
2322e17f3b22Stim szeto 
2323e17f3b22Stim szeto 	ret = stmfGetState(state);
2324e17f3b22Stim szeto 	switch (ret) {
2325e17f3b22Stim szeto 		case STMF_STATUS_SUCCESS:
2326e17f3b22Stim szeto 			break;
2327e17f3b22Stim szeto 		case STMF_ERROR_PERM:
2328e17f3b22Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
2329e17f3b22Stim szeto 			    gettext("permission denied"));
2330e17f3b22Stim szeto 			break;
2331e17f3b22Stim szeto 		case STMF_ERROR_SERVICE_NOT_FOUND:
2332e17f3b22Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
2333e17f3b22Stim szeto 			    gettext("STMF service not found"));
2334e17f3b22Stim szeto 			break;
2335e17f3b22Stim szeto 		case STMF_ERROR_BUSY:
2336e17f3b22Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
2337e17f3b22Stim szeto 			    gettext("resource busy"));
2338e17f3b22Stim szeto 			break;
2339e17f3b22Stim szeto 		case STMF_ERROR_SERVICE_DATA_VERSION:
2340e17f3b22Stim szeto 			(void) fprintf(stderr, "%s: %s\n", cmdName,
2341e17f3b22Stim szeto 			    gettext("STMF service version incorrect"));
2342e17f3b22Stim szeto 			break;
2343e17f3b22Stim szeto 		default:
23448fe96085Stim szeto 			(void) fprintf(stderr, "%s: %s: %d\n", cmdName,
23458fe96085Stim szeto 			    gettext("unknown error"), ret);
2346e17f3b22Stim szeto 			break;
2347e17f3b22Stim szeto 	}
2348e17f3b22Stim szeto 	return (ret);
2349e17f3b22Stim szeto }
2350e17f3b22Stim szeto 
2351fcf3ce44SJohn Forte /*
2352fcf3ce44SJohn Forte  * listStateFunc
2353fcf3ce44SJohn Forte  *
2354fcf3ce44SJohn Forte  * List the operational and config state of the stmf service
2355fcf3ce44SJohn Forte  *
2356fcf3ce44SJohn Forte  */
2357fcf3ce44SJohn Forte /*ARGSUSED*/
2358fcf3ce44SJohn Forte static int
2359fcf3ce44SJohn Forte listStateFunc(int operandLen, char *operands[], cmdOptions_t *options,
2360fcf3ce44SJohn Forte     void *args)
2361fcf3ce44SJohn Forte {
2362fcf3ce44SJohn Forte 	int ret;
2363fcf3ce44SJohn Forte 	stmfState state;
2364fcf3ce44SJohn Forte 
2365e17f3b22Stim szeto 	if ((ret = getStmfState(&state)) != STMF_STATUS_SUCCESS)
2366e17f3b22Stim szeto 		return (ret);
2367fcf3ce44SJohn Forte 
2368fcf3ce44SJohn Forte 	(void) printf("%-18s: ", "Operational Status");
2369fcf3ce44SJohn Forte 	switch (state.operationalState) {
2370fcf3ce44SJohn Forte 		case STMF_SERVICE_STATE_ONLINE:
2371fcf3ce44SJohn Forte 			(void) printf("online");
2372fcf3ce44SJohn Forte 			break;
2373fcf3ce44SJohn Forte 		case STMF_SERVICE_STATE_OFFLINE:
2374fcf3ce44SJohn Forte 			(void) printf("offline");
2375fcf3ce44SJohn Forte 			break;
2376fcf3ce44SJohn Forte 		case STMF_SERVICE_STATE_ONLINING:
2377fcf3ce44SJohn Forte 			(void) printf("onlining");
2378fcf3ce44SJohn Forte 			break;
2379fcf3ce44SJohn Forte 		case STMF_SERVICE_STATE_OFFLINING:
2380fcf3ce44SJohn Forte 			(void) printf("offlining");
2381fcf3ce44SJohn Forte 			break;
2382fcf3ce44SJohn Forte 		default:
2383fcf3ce44SJohn Forte 			(void) printf("unknown");
2384fcf3ce44SJohn Forte 			break;
2385fcf3ce44SJohn Forte 	}
2386fcf3ce44SJohn Forte 	(void) printf("\n");
2387fcf3ce44SJohn Forte 	(void) printf("%-18s: ", "Config Status");
2388fcf3ce44SJohn Forte 	switch (state.configState) {
2389fcf3ce44SJohn Forte 		case STMF_CONFIG_STATE_NONE:
2390fcf3ce44SJohn Forte 			(void) printf("uninitialized");
2391fcf3ce44SJohn Forte 			break;
2392fcf3ce44SJohn Forte 		case STMF_CONFIG_STATE_INIT:
2393fcf3ce44SJohn Forte 			(void) printf("initializing");
2394fcf3ce44SJohn Forte 			break;
2395fcf3ce44SJohn Forte 		case STMF_CONFIG_STATE_INIT_DONE:
2396fcf3ce44SJohn Forte 			(void) printf("initialized");
2397fcf3ce44SJohn Forte 			break;
2398fcf3ce44SJohn Forte 		default:
2399fcf3ce44SJohn Forte 			(void) printf("unknown");
2400fcf3ce44SJohn Forte 			break;
2401fcf3ce44SJohn Forte 	}
2402fcf3ce44SJohn Forte 	(void) printf("\n");
2403fcf3ce44SJohn Forte 	return (0);
2404fcf3ce44SJohn Forte }
2405fcf3ce44SJohn Forte 
2406fcf3ce44SJohn Forte /*
2407fcf3ce44SJohn Forte  * listTargetFunc
2408fcf3ce44SJohn Forte  *
2409fcf3ce44SJohn Forte  * list the targets and optionally their properties
2410fcf3ce44SJohn Forte  *
2411fcf3ce44SJohn Forte  */
2412fcf3ce44SJohn Forte /*ARGSUSED*/
2413fcf3ce44SJohn Forte static int
2414fcf3ce44SJohn Forte listTargetFunc(int operandLen, char *operands[], cmdOptions_t *options,
2415fcf3ce44SJohn Forte     void *args)
2416fcf3ce44SJohn Forte {
2417fcf3ce44SJohn Forte 	cmdOptions_t *optionList = options;
2418fcf3ce44SJohn Forte 	int ret = 0;
2419fcf3ce44SJohn Forte 	int stmfRet;
2420fcf3ce44SJohn Forte 	int i, j;
2421fcf3ce44SJohn Forte 	int outerLoop;
2422fcf3ce44SJohn Forte 	stmfSessionList *sessionList;
2423fcf3ce44SJohn Forte 	stmfDevid devid;
2424fcf3ce44SJohn Forte 	boolean_t operandEntered, found, verbose = B_FALSE;
2425fcf3ce44SJohn Forte 	stmfDevidList *targetList;
2426fcf3ce44SJohn Forte 	wchar_t targetIdent[STMF_IDENT_LENGTH + 1];
2427fcf3ce44SJohn Forte 	stmfTargetProperties targetProps;
2428fcf3ce44SJohn Forte 
2429fcf3ce44SJohn Forte 	if ((stmfRet = stmfGetTargetList(&targetList)) != STMF_STATUS_SUCCESS) {
2430fcf3ce44SJohn Forte 		switch (stmfRet) {
2431fcf3ce44SJohn Forte 			case STMF_ERROR_NOT_FOUND:
2432fcf3ce44SJohn Forte 				ret = 0;
2433fcf3ce44SJohn Forte 				break;
2434fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_OFFLINE:
2435fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2436fcf3ce44SJohn Forte 				    gettext("STMF service offline"));
2437fcf3ce44SJohn Forte 				break;
2438fcf3ce44SJohn Forte 			case STMF_ERROR_BUSY:
2439fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2440fcf3ce44SJohn Forte 				    gettext("resource busy"));
2441fcf3ce44SJohn Forte 				break;
2442fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
2443fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2444fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
2445fcf3ce44SJohn Forte 				break;
2446fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
2447fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2448fcf3ce44SJohn Forte 				    gettext("permission denied"));
2449fcf3ce44SJohn Forte 				break;
2450fcf3ce44SJohn Forte 			default:
2451fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2452fcf3ce44SJohn Forte 				    gettext("unknown error"));
2453fcf3ce44SJohn Forte 				break;
2454fcf3ce44SJohn Forte 		}
2455fcf3ce44SJohn Forte 		return (1);
2456fcf3ce44SJohn Forte 	}
2457fcf3ce44SJohn Forte 
2458fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
2459fcf3ce44SJohn Forte 		switch (optionList->optval) {
2460fcf3ce44SJohn Forte 			case 'v':
2461fcf3ce44SJohn Forte 				verbose = B_TRUE;
2462fcf3ce44SJohn Forte 				break;
2463fcf3ce44SJohn Forte 		}
2464fcf3ce44SJohn Forte 	}
2465fcf3ce44SJohn Forte 
2466fcf3ce44SJohn Forte 	if (operandLen > 0) {
2467fcf3ce44SJohn Forte 		outerLoop = operandLen;
2468fcf3ce44SJohn Forte 		operandEntered = B_TRUE;
2469fcf3ce44SJohn Forte 	} else {
2470fcf3ce44SJohn Forte 		outerLoop = 1;
2471fcf3ce44SJohn Forte 		operandEntered = B_FALSE;
2472fcf3ce44SJohn Forte 	}
2473fcf3ce44SJohn Forte 
2474fcf3ce44SJohn Forte 	for (i = 0; i < outerLoop; i++) {
2475fcf3ce44SJohn Forte 		if (operandEntered) {
2476fcf3ce44SJohn Forte 			bzero(&devid, sizeof (devid));
2477fcf3ce44SJohn Forte 			(void) parseDevid(operands[i], &devid);
2478fcf3ce44SJohn Forte 		}
2479fcf3ce44SJohn Forte 		for (found = B_FALSE, j = 0; j < targetList->cnt; j++) {
2480fcf3ce44SJohn Forte 			if (operandEntered) {
2481fcf3ce44SJohn Forte 				if (bcmp(&devid, &(targetList->devid[j]),
2482fcf3ce44SJohn Forte 				    sizeof (devid)) == 0) {
2483fcf3ce44SJohn Forte 					found = B_TRUE;
2484fcf3ce44SJohn Forte 				}
2485fcf3ce44SJohn Forte 			}
2486fcf3ce44SJohn Forte 			if ((found && operandEntered) || !operandEntered) {
2487fcf3ce44SJohn Forte 				(void) mbstowcs(targetIdent,
2488fcf3ce44SJohn Forte 				    (char *)targetList->devid[j].ident,
24893e7352aeSJohn Forte 				    STMF_IDENT_LENGTH);
24903e7352aeSJohn Forte 				targetIdent[STMF_IDENT_LENGTH] = 0;
2491fcf3ce44SJohn Forte 				(void) printf("Target: %ws\n", targetIdent);
2492fcf3ce44SJohn Forte 				if (verbose) {
2493fcf3ce44SJohn Forte 					stmfRet = stmfGetTargetProperties(
2494fcf3ce44SJohn Forte 					    &(targetList->devid[j]),
2495fcf3ce44SJohn Forte 					    &targetProps);
2496fcf3ce44SJohn Forte 					if (stmfRet == STMF_STATUS_SUCCESS) {
2497fcf3ce44SJohn Forte 						printTargetProps(&targetProps);
2498fcf3ce44SJohn Forte 					} else {
2499fcf3ce44SJohn Forte 						(void) fprintf(stderr, "%s:",
2500fcf3ce44SJohn Forte 						    cmdName);
2501fcf3ce44SJohn Forte 						(void) fprintf(stderr, "%s\n",
2502fcf3ce44SJohn Forte 						    gettext(" get properties"
2503fcf3ce44SJohn Forte 						    " failed"));
2504fcf3ce44SJohn Forte 					}
2505fcf3ce44SJohn Forte 					stmfRet = stmfGetSessionList(
2506fcf3ce44SJohn Forte 					    &(targetList->devid[j]),
2507fcf3ce44SJohn Forte 					    &sessionList);
2508fcf3ce44SJohn Forte 					if (stmfRet == STMF_STATUS_SUCCESS) {
2509fcf3ce44SJohn Forte 						printSessionProps(sessionList);
2510fcf3ce44SJohn Forte 					} else {
2511fcf3ce44SJohn Forte 						(void) fprintf(stderr, "%s:",
2512fcf3ce44SJohn Forte 						    cmdName);
2513fcf3ce44SJohn Forte 						(void) fprintf(stderr, "%s\n",
2514fcf3ce44SJohn Forte 						    gettext(" get session info"
2515fcf3ce44SJohn Forte 						    " failed"));
2516fcf3ce44SJohn Forte 					}
2517fcf3ce44SJohn Forte 				}
2518fcf3ce44SJohn Forte 				if (found && operandEntered) {
2519fcf3ce44SJohn Forte 					break;
2520fcf3ce44SJohn Forte 				}
2521fcf3ce44SJohn Forte 			}
2522fcf3ce44SJohn Forte 
2523fcf3ce44SJohn Forte 		}
2524fcf3ce44SJohn Forte 		if (operandEntered && !found) {
2525fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2526fcf3ce44SJohn Forte 			    operands[i], "not found");
2527fcf3ce44SJohn Forte 			ret = 1;
2528fcf3ce44SJohn Forte 		}
2529fcf3ce44SJohn Forte 	}
2530fcf3ce44SJohn Forte 	return (ret);
2531fcf3ce44SJohn Forte }
2532fcf3ce44SJohn Forte 
2533fcf3ce44SJohn Forte /*
2534fcf3ce44SJohn Forte  * listViewFunc
2535fcf3ce44SJohn Forte  *
2536fcf3ce44SJohn Forte  * list the view entries for the specified logical unit
2537fcf3ce44SJohn Forte  *
2538fcf3ce44SJohn Forte  */
2539fcf3ce44SJohn Forte /*ARGSUSED*/
2540fcf3ce44SJohn Forte static int
2541fcf3ce44SJohn Forte listViewFunc(int operandLen, char *operands[], cmdOptions_t *options,
2542fcf3ce44SJohn Forte     void *args)
2543fcf3ce44SJohn Forte {
2544fcf3ce44SJohn Forte 	stmfViewEntryList *viewEntryList;
2545fcf3ce44SJohn Forte 	stmfGuid inGuid;
2546fcf3ce44SJohn Forte 	unsigned int guid[sizeof (stmfGuid)];
2547fcf3ce44SJohn Forte 	int ret = 0;
2548fcf3ce44SJohn Forte 	int stmfRet;
2549fcf3ce44SJohn Forte 	int i, j, outerLoop;
2550fcf3ce44SJohn Forte 	boolean_t found = B_TRUE;
2551fcf3ce44SJohn Forte 	boolean_t operandEntered;
2552fcf3ce44SJohn Forte 	uint16_t outputLuNbr;
2553fcf3ce44SJohn Forte 	wchar_t groupName[sizeof (stmfGroupName)];
2554fcf3ce44SJohn Forte 	char sGuid[GUID_INPUT + 1];
2555fcf3ce44SJohn Forte 
2556fcf3ce44SJohn Forte 
2557fcf3ce44SJohn Forte 	for (; options->optval; options++) {
2558fcf3ce44SJohn Forte 		switch (options->optval) {
2559fcf3ce44SJohn Forte 			case 'l':
2560fcf3ce44SJohn Forte 				if (strlen(options->optarg) != GUID_INPUT) {
2561fcf3ce44SJohn Forte 					(void) fprintf(stderr,
2562fcf3ce44SJohn Forte 					    "%s: %s: %s%d%s\n",
2563fcf3ce44SJohn Forte 					    cmdName, options->optarg,
2564fcf3ce44SJohn Forte 					    gettext("must be "), GUID_INPUT,
2565fcf3ce44SJohn Forte 					    gettext(" hexadecimal digits"
2566fcf3ce44SJohn Forte 					    " long"));
2567fcf3ce44SJohn Forte 					return (1);
2568fcf3ce44SJohn Forte 				}
2569fcf3ce44SJohn Forte 				bcopy(options->optarg, sGuid, GUID_INPUT);
2570fcf3ce44SJohn Forte 				break;
2571fcf3ce44SJohn Forte 			default:
2572fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
2573fcf3ce44SJohn Forte 				    cmdName, options->optval,
2574fcf3ce44SJohn Forte 				    gettext("unknown option"));
2575fcf3ce44SJohn Forte 				return (1);
2576fcf3ce44SJohn Forte 		}
2577fcf3ce44SJohn Forte 	}
2578fcf3ce44SJohn Forte 
2579fcf3ce44SJohn Forte 	if (operandLen > 0) {
2580fcf3ce44SJohn Forte 		outerLoop = operandLen;
2581fcf3ce44SJohn Forte 		operandEntered = B_TRUE;
2582fcf3ce44SJohn Forte 	} else {
2583fcf3ce44SJohn Forte 		outerLoop = 1;
2584fcf3ce44SJohn Forte 		operandEntered = B_FALSE;
2585fcf3ce44SJohn Forte 	}
2586fcf3ce44SJohn Forte 
2587fcf3ce44SJohn Forte 	for (i = 0; i < 32; i++)
2588fcf3ce44SJohn Forte 		sGuid[i] = tolower(sGuid[i]);
2589fcf3ce44SJohn Forte 	sGuid[i] = 0;
2590fcf3ce44SJohn Forte 
2591fcf3ce44SJohn Forte 	(void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
2592fcf3ce44SJohn Forte 	    &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
2593fcf3ce44SJohn Forte 	    &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11],
2594fcf3ce44SJohn Forte 	    &guid[12], &guid[13], &guid[14], &guid[15]);
2595fcf3ce44SJohn Forte 
2596fcf3ce44SJohn Forte 	for (i = 0; i < sizeof (stmfGuid); i++) {
2597fcf3ce44SJohn Forte 		inGuid.guid[i] = guid[i];
2598fcf3ce44SJohn Forte 	}
2599fcf3ce44SJohn Forte 
2600fcf3ce44SJohn Forte 	if ((stmfRet = stmfGetViewEntryList(&inGuid, &viewEntryList))
2601fcf3ce44SJohn Forte 	    != STMF_STATUS_SUCCESS) {
2602fcf3ce44SJohn Forte 
2603fcf3ce44SJohn Forte 		switch (stmfRet) {
2604fcf3ce44SJohn Forte 			case STMF_ERROR_BUSY:
2605fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2606fcf3ce44SJohn Forte 				    sGuid, gettext("resource busy"));
2607fcf3ce44SJohn Forte 				break;
2608fcf3ce44SJohn Forte 			case STMF_ERROR_NOT_FOUND:
2609fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2610fcf3ce44SJohn Forte 				    sGuid, gettext("no views found"));
2611fcf3ce44SJohn Forte 				break;
2612fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
2613fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2614fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
2615fcf3ce44SJohn Forte 				break;
2616fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
2617fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2618fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
2619fcf3ce44SJohn Forte 				break;
2620fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
2621fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2622fcf3ce44SJohn Forte 				    gettext("permission denied"));
2623fcf3ce44SJohn Forte 				break;
2624fcf3ce44SJohn Forte 			default:
2625fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2626fcf3ce44SJohn Forte 				    sGuid, gettext("unknown error"));
2627fcf3ce44SJohn Forte 				break;
2628fcf3ce44SJohn Forte 		}
2629fcf3ce44SJohn Forte 		return (1);
2630fcf3ce44SJohn Forte 	}
2631fcf3ce44SJohn Forte 
2632fcf3ce44SJohn Forte 	for (i = 0; i < outerLoop; i++) {
2633fcf3ce44SJohn Forte 		for (found = B_FALSE, j = 0; j < viewEntryList->cnt; j++) {
2634fcf3ce44SJohn Forte 			if (operandEntered) {
2635fcf3ce44SJohn Forte 				if (atoi(operands[i]) ==
2636fcf3ce44SJohn Forte 				    viewEntryList->ve[j].veIndex) {
2637fcf3ce44SJohn Forte 					found = B_TRUE;
2638fcf3ce44SJohn Forte 				}
2639fcf3ce44SJohn Forte 			}
2640fcf3ce44SJohn Forte 			if ((found && operandEntered) || !operandEntered) {
2641fcf3ce44SJohn Forte 				(void) printf("View Entry: %d\n",
2642fcf3ce44SJohn Forte 				    viewEntryList->ve[j].veIndex);
2643fcf3ce44SJohn Forte 				(void) printf(VIEW_FORMAT, "Host group");
2644fcf3ce44SJohn Forte 				if (viewEntryList->ve[j].allHosts) {
2645fcf3ce44SJohn Forte 					(void) printf("All\n");
2646fcf3ce44SJohn Forte 				} else {
2647fcf3ce44SJohn Forte 					(void) mbstowcs(groupName,
2648fcf3ce44SJohn Forte 					    viewEntryList->ve[j].hostGroup,
26493e7352aeSJohn Forte 					    sizeof (stmfGroupName) - 1);
26503e7352aeSJohn Forte 					groupName[sizeof (stmfGroupName) - 1]
26513e7352aeSJohn Forte 					    = 0;
2652fcf3ce44SJohn Forte 					(void) printf("%ws\n", groupName);
2653fcf3ce44SJohn Forte 				}
2654fcf3ce44SJohn Forte 				(void) printf(VIEW_FORMAT, "Target group");
2655fcf3ce44SJohn Forte 				if (viewEntryList->ve[j].allTargets) {
2656fcf3ce44SJohn Forte 					(void) printf("All\n");
2657fcf3ce44SJohn Forte 				} else {
2658fcf3ce44SJohn Forte 					(void) mbstowcs(groupName,
2659fcf3ce44SJohn Forte 					    viewEntryList->ve[j].targetGroup,
26603e7352aeSJohn Forte 					    sizeof (stmfGroupName) - 1);
26613e7352aeSJohn Forte 					groupName[sizeof (stmfGroupName) - 1]
26623e7352aeSJohn Forte 					    = 0;
2663fcf3ce44SJohn Forte 					(void) printf("%ws\n", groupName);
2664fcf3ce44SJohn Forte 				}
2665fcf3ce44SJohn Forte 				outputLuNbr = ((viewEntryList->ve[j].luNbr[0] &
2666fcf3ce44SJohn Forte 				    0x3F) << 8) | viewEntryList->ve[j].luNbr[1];
2667fcf3ce44SJohn Forte 				(void) printf(VIEW_FORMAT, "LUN");
2668fcf3ce44SJohn Forte 				(void) printf("%d\n", outputLuNbr);
2669fcf3ce44SJohn Forte 				if (found && operandEntered) {
2670fcf3ce44SJohn Forte 					break;
2671fcf3ce44SJohn Forte 				}
2672fcf3ce44SJohn Forte 			}
2673fcf3ce44SJohn Forte 		}
2674fcf3ce44SJohn Forte 		if (operandEntered && !found) {
2675fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s, %s: %s\n", cmdName,
2676fcf3ce44SJohn Forte 			    sGuid, operands[i], gettext("not found"));
2677fcf3ce44SJohn Forte 			ret = 1;
2678fcf3ce44SJohn Forte 		}
2679fcf3ce44SJohn Forte 	}
2680fcf3ce44SJohn Forte 
2681fcf3ce44SJohn Forte 	return (ret);
2682fcf3ce44SJohn Forte }
2683fcf3ce44SJohn Forte 
2684fcf3ce44SJohn Forte 
2685fcf3ce44SJohn Forte /*
2686fcf3ce44SJohn Forte  * onlineOfflineLu
2687fcf3ce44SJohn Forte  *
2688fcf3ce44SJohn Forte  * Purpose: Online or offline a logical unit
2689fcf3ce44SJohn Forte  *
2690fcf3ce44SJohn Forte  * lu - logical unit to online or offline
2691fcf3ce44SJohn Forte  *
2692fcf3ce44SJohn Forte  * state - ONLINE_LU
2693fcf3ce44SJohn Forte  *         OFFLINE_LU
2694fcf3ce44SJohn Forte  */
2695fcf3ce44SJohn Forte static int
2696fcf3ce44SJohn Forte onlineOfflineLu(char *lu, int state)
2697fcf3ce44SJohn Forte {
2698fcf3ce44SJohn Forte 	char sGuid[GUID_INPUT + 1];
2699fcf3ce44SJohn Forte 	stmfGuid inGuid;
2700fcf3ce44SJohn Forte 	unsigned int guid[sizeof (stmfGuid)];
2701fcf3ce44SJohn Forte 	int i;
2702fcf3ce44SJohn Forte 	int ret = 0;
2703fcf3ce44SJohn Forte 
2704fcf3ce44SJohn Forte 	if (strlen(lu) != GUID_INPUT) {
2705fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s: %s %d %s\n", cmdName, lu,
2706fcf3ce44SJohn Forte 		    gettext("must be"), GUID_INPUT,
2707fcf3ce44SJohn Forte 		    gettext("hexadecimal digits long"));
2708fcf3ce44SJohn Forte 		return (1);
2709fcf3ce44SJohn Forte 	}
2710fcf3ce44SJohn Forte 
2711fcf3ce44SJohn Forte 	bcopy(lu, sGuid, GUID_INPUT);
2712fcf3ce44SJohn Forte 
2713fcf3ce44SJohn Forte 	for (i = 0; i < 32; i++)
2714fcf3ce44SJohn Forte 		sGuid[i] = tolower(sGuid[i]);
2715fcf3ce44SJohn Forte 	sGuid[i] = 0;
2716fcf3ce44SJohn Forte 
2717fcf3ce44SJohn Forte 	(void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
2718fcf3ce44SJohn Forte 	    &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
2719fcf3ce44SJohn Forte 	    &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11],
2720fcf3ce44SJohn Forte 	    &guid[12], &guid[13], &guid[14], &guid[15]);
2721fcf3ce44SJohn Forte 
2722fcf3ce44SJohn Forte 	for (i = 0; i < sizeof (stmfGuid); i++) {
2723fcf3ce44SJohn Forte 		inGuid.guid[i] = guid[i];
2724fcf3ce44SJohn Forte 	}
2725fcf3ce44SJohn Forte 
2726fcf3ce44SJohn Forte 	if (state == ONLINE_LU) {
2727fcf3ce44SJohn Forte 		ret = stmfOnlineLogicalUnit(&inGuid);
2728fcf3ce44SJohn Forte 	} else if (state == OFFLINE_LU) {
2729fcf3ce44SJohn Forte 		ret = stmfOfflineLogicalUnit(&inGuid);
2730fcf3ce44SJohn Forte 	}
2731fcf3ce44SJohn Forte 	if (ret != STMF_STATUS_SUCCESS) {
2732fcf3ce44SJohn Forte 		switch (ret) {
2733fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
2734fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2735fcf3ce44SJohn Forte 				    gettext("permission denied"));
2736fcf3ce44SJohn Forte 				break;
2737fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
2738fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2739fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
2740fcf3ce44SJohn Forte 				break;
2741fcf3ce44SJohn Forte 			case STMF_ERROR_NOT_FOUND:
2742fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2743fcf3ce44SJohn Forte 				    lu, gettext("not found"));
2744fcf3ce44SJohn Forte 				break;
2745fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
2746fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2747fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
2748fcf3ce44SJohn Forte 				break;
2749fcf3ce44SJohn Forte 			default:
2750fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2751fcf3ce44SJohn Forte 				    gettext("unknown error"));
2752fcf3ce44SJohn Forte 				break;
2753fcf3ce44SJohn Forte 		}
2754fcf3ce44SJohn Forte 	}
2755fcf3ce44SJohn Forte 	return (ret);
2756fcf3ce44SJohn Forte }
2757fcf3ce44SJohn Forte 
2758fcf3ce44SJohn Forte /*
2759fcf3ce44SJohn Forte  * onlineLuFunc
2760fcf3ce44SJohn Forte  *
2761fcf3ce44SJohn Forte  * Purpose: Online a logical unit
2762fcf3ce44SJohn Forte  *
2763fcf3ce44SJohn Forte  */
2764fcf3ce44SJohn Forte /*ARGSUSED*/
2765fcf3ce44SJohn Forte static int
2766fcf3ce44SJohn Forte onlineLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
2767fcf3ce44SJohn Forte     void *args)
2768fcf3ce44SJohn Forte {
2769e17f3b22Stim szeto 	int ret;
2770e17f3b22Stim szeto 	stmfState state;
2771e17f3b22Stim szeto 
2772e17f3b22Stim szeto 	ret = getStmfState(&state);
2773e17f3b22Stim szeto 	if (ret != STMF_STATUS_SUCCESS)
2774e17f3b22Stim szeto 		return (ret);
2775e17f3b22Stim szeto 	if (state.operationalState == STMF_SERVICE_STATE_OFFLINE ||
2776e17f3b22Stim szeto 	    state.operationalState == STMF_SERVICE_STATE_OFFLINING) {
2777e17f3b22Stim szeto 		(void) fprintf(stderr, "%s: %s\n", cmdName,
2778e17f3b22Stim szeto 		    gettext("STMF service is offline"));
2779e17f3b22Stim szeto 		return (1);
2780e17f3b22Stim szeto 	}
2781fcf3ce44SJohn Forte 	return (onlineOfflineLu(operands[0], ONLINE_LU));
2782fcf3ce44SJohn Forte }
2783fcf3ce44SJohn Forte 
2784fcf3ce44SJohn Forte /*
2785fcf3ce44SJohn Forte  * offlineLuFunc
2786fcf3ce44SJohn Forte  *
2787fcf3ce44SJohn Forte  * Purpose: Offline a logical unit
2788fcf3ce44SJohn Forte  *
2789fcf3ce44SJohn Forte  */
2790fcf3ce44SJohn Forte /*ARGSUSED*/
2791fcf3ce44SJohn Forte static int
2792fcf3ce44SJohn Forte offlineLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
2793fcf3ce44SJohn Forte     void *args)
2794fcf3ce44SJohn Forte {
2795fcf3ce44SJohn Forte 	return (onlineOfflineLu(operands[0], OFFLINE_LU));
2796fcf3ce44SJohn Forte }
2797fcf3ce44SJohn Forte 
2798fcf3ce44SJohn Forte /*
2799fcf3ce44SJohn Forte  * onlineOfflineTarget
2800fcf3ce44SJohn Forte  *
2801fcf3ce44SJohn Forte  * Purpose: Online or offline a target
2802fcf3ce44SJohn Forte  *
2803fcf3ce44SJohn Forte  * target - target to online or offline
2804fcf3ce44SJohn Forte  *
2805fcf3ce44SJohn Forte  * state - ONLINE_TARGET
2806fcf3ce44SJohn Forte  *         OFFLINE_TARGET
2807fcf3ce44SJohn Forte  */
2808fcf3ce44SJohn Forte static int
2809fcf3ce44SJohn Forte onlineOfflineTarget(char *target, int state)
2810fcf3ce44SJohn Forte {
2811fcf3ce44SJohn Forte 	int ret = 0;
2812fcf3ce44SJohn Forte 	stmfDevid devid;
2813fcf3ce44SJohn Forte 
2814fcf3ce44SJohn Forte 	if (parseDevid(target, &devid) != 0) {
2815fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s: %s\n",
2816fcf3ce44SJohn Forte 		    cmdName, target, gettext("unrecognized device id"));
2817fcf3ce44SJohn Forte 		return (1);
2818fcf3ce44SJohn Forte 	}
2819fcf3ce44SJohn Forte 	if (state == ONLINE_TARGET) {
2820fcf3ce44SJohn Forte 		ret = stmfOnlineTarget(&devid);
2821fcf3ce44SJohn Forte 	} else if (state == OFFLINE_TARGET) {
2822fcf3ce44SJohn Forte 		ret = stmfOfflineTarget(&devid);
2823fcf3ce44SJohn Forte 	}
2824fcf3ce44SJohn Forte 	if (ret != STMF_STATUS_SUCCESS) {
2825fcf3ce44SJohn Forte 		switch (ret) {
2826fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
2827fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2828fcf3ce44SJohn Forte 				    gettext("permission denied"));
2829fcf3ce44SJohn Forte 				break;
2830fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
2831fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2832fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
2833fcf3ce44SJohn Forte 				break;
2834fcf3ce44SJohn Forte 			case STMF_ERROR_NOT_FOUND:
2835fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2836fcf3ce44SJohn Forte 				    target, gettext("not found"));
2837fcf3ce44SJohn Forte 				break;
2838fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
2839fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2840fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
2841fcf3ce44SJohn Forte 				break;
2842fcf3ce44SJohn Forte 			default:
2843fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2844fcf3ce44SJohn Forte 				    gettext("unknown error"));
2845fcf3ce44SJohn Forte 				break;
2846fcf3ce44SJohn Forte 		}
2847fcf3ce44SJohn Forte 	}
2848fcf3ce44SJohn Forte 	return (ret);
2849fcf3ce44SJohn Forte }
2850fcf3ce44SJohn Forte 
2851fcf3ce44SJohn Forte /*
2852fcf3ce44SJohn Forte  * onlineTargetFunc
2853fcf3ce44SJohn Forte  *
2854fcf3ce44SJohn Forte  * Purpose: Online a target
2855fcf3ce44SJohn Forte  *
2856fcf3ce44SJohn Forte  */
2857fcf3ce44SJohn Forte /*ARGSUSED*/
2858fcf3ce44SJohn Forte static int
2859fcf3ce44SJohn Forte onlineTargetFunc(int operandLen, char *operands[], cmdOptions_t *options,
2860fcf3ce44SJohn Forte     void *args)
2861fcf3ce44SJohn Forte {
2862e17f3b22Stim szeto 	int ret;
2863e17f3b22Stim szeto 	stmfState state;
2864e17f3b22Stim szeto 
2865e17f3b22Stim szeto 	ret = getStmfState(&state);
2866e17f3b22Stim szeto 	if (ret != STMF_STATUS_SUCCESS)
2867e17f3b22Stim szeto 		return (ret);
2868e17f3b22Stim szeto 	if (state.operationalState == STMF_SERVICE_STATE_OFFLINE ||
2869e17f3b22Stim szeto 	    state.operationalState == STMF_SERVICE_STATE_OFFLINING) {
2870e17f3b22Stim szeto 		(void) fprintf(stderr, "%s: %s\n", cmdName,
2871e17f3b22Stim szeto 		    gettext("STMF service is offline"));
2872e17f3b22Stim szeto 		return (1);
2873e17f3b22Stim szeto 	}
2874fcf3ce44SJohn Forte 	return (onlineOfflineTarget(operands[0], ONLINE_TARGET));
2875fcf3ce44SJohn Forte }
2876fcf3ce44SJohn Forte 
2877fcf3ce44SJohn Forte /*
2878fcf3ce44SJohn Forte  * offlineTargetFunc
2879fcf3ce44SJohn Forte  *
2880fcf3ce44SJohn Forte  * Purpose: Offline a target
2881fcf3ce44SJohn Forte  *
2882fcf3ce44SJohn Forte  */
2883fcf3ce44SJohn Forte /*ARGSUSED*/
2884fcf3ce44SJohn Forte static int
2885fcf3ce44SJohn Forte offlineTargetFunc(int operandLen, char *operands[], cmdOptions_t *options,
2886fcf3ce44SJohn Forte     void *args)
2887fcf3ce44SJohn Forte {
2888fcf3ce44SJohn Forte 	return (onlineOfflineTarget(operands[0], OFFLINE_TARGET));
2889fcf3ce44SJohn Forte }
2890fcf3ce44SJohn Forte 
2891fcf3ce44SJohn Forte 
2892fcf3ce44SJohn Forte /*ARGSUSED*/
2893fcf3ce44SJohn Forte static int
2894fcf3ce44SJohn Forte removeHostGroupMemberFunc(int operandLen, char *operands[],
2895fcf3ce44SJohn Forte     cmdOptions_t *options, void *args)
2896fcf3ce44SJohn Forte {
2897fcf3ce44SJohn Forte 	int i;
2898fcf3ce44SJohn Forte 	int ret = 0;
2899fcf3ce44SJohn Forte 	int stmfRet;
29003e7352aeSJohn Forte 	stmfGroupName groupName = {0};
2901fcf3ce44SJohn Forte 	stmfDevid devid;
29023e7352aeSJohn Forte 	wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
2903fcf3ce44SJohn Forte 
2904fcf3ce44SJohn Forte 	for (; options->optval; options++) {
2905fcf3ce44SJohn Forte 		switch (options->optval) {
2906fcf3ce44SJohn Forte 			case 'g':
2907fcf3ce44SJohn Forte 				(void) mbstowcs(groupNamePrint, options->optarg,
29083e7352aeSJohn Forte 				    sizeof (stmfGroupName) - 1);
2909fcf3ce44SJohn Forte 				bcopy(options->optarg, groupName,
2910fcf3ce44SJohn Forte 				    strlen(options->optarg));
2911fcf3ce44SJohn Forte 				break;
2912fcf3ce44SJohn Forte 			default:
2913fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
2914fcf3ce44SJohn Forte 				    cmdName, options->optval,
2915fcf3ce44SJohn Forte 				    gettext("unknown option"));
2916fcf3ce44SJohn Forte 				return (1);
2917fcf3ce44SJohn Forte 		}
2918fcf3ce44SJohn Forte 	}
2919fcf3ce44SJohn Forte 
2920fcf3ce44SJohn Forte 	for (i = 0; i < operandLen; i++) {
2921fcf3ce44SJohn Forte 		if (parseDevid(operands[i], &devid) != 0) {
2922fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n",
2923fcf3ce44SJohn Forte 			    cmdName, operands[i],
2924fcf3ce44SJohn Forte 			    gettext("unrecognized device id"));
2925fcf3ce44SJohn Forte 			ret++;
2926fcf3ce44SJohn Forte 			continue;
2927fcf3ce44SJohn Forte 		}
2928fcf3ce44SJohn Forte 		stmfRet = stmfRemoveFromHostGroup(&groupName, &devid);
2929fcf3ce44SJohn Forte 		switch (stmfRet) {
2930fcf3ce44SJohn Forte 			case STMF_STATUS_SUCCESS:
2931fcf3ce44SJohn Forte 				break;
2932fcf3ce44SJohn Forte 			case STMF_ERROR_MEMBER_NOT_FOUND:
2933fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2934fcf3ce44SJohn Forte 				    operands[i], gettext("not found"));
2935fcf3ce44SJohn Forte 				ret++;
2936fcf3ce44SJohn Forte 				break;
2937fcf3ce44SJohn Forte 			case STMF_ERROR_GROUP_NOT_FOUND:
2938fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
2939fcf3ce44SJohn Forte 				    groupNamePrint, gettext("not found"));
2940fcf3ce44SJohn Forte 				ret++;
2941fcf3ce44SJohn Forte 				break;
2942fcf3ce44SJohn Forte 			case STMF_ERROR_BUSY:
2943fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2944fcf3ce44SJohn Forte 				    operands[i], "resource busy");
2945fcf3ce44SJohn Forte 				ret++;
2946fcf3ce44SJohn Forte 				break;
2947fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
2948fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2949fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
2950fcf3ce44SJohn Forte 				ret++;
2951fcf3ce44SJohn Forte 				break;
2952fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
2953fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2954fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
2955fcf3ce44SJohn Forte 				ret++;
2956fcf3ce44SJohn Forte 				break;
2957fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
2958fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
2959fcf3ce44SJohn Forte 				    gettext("permission denied"));
2960fcf3ce44SJohn Forte 				ret++;
2961fcf3ce44SJohn Forte 				break;
2962fcf3ce44SJohn Forte 			default:
2963fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2964fcf3ce44SJohn Forte 				    operands[i], gettext("unknown error"));
2965fcf3ce44SJohn Forte 				ret++;
2966fcf3ce44SJohn Forte 				break;
2967fcf3ce44SJohn Forte 		}
2968fcf3ce44SJohn Forte 	}
2969fcf3ce44SJohn Forte 
2970fcf3ce44SJohn Forte 	return (ret);
2971fcf3ce44SJohn Forte }
2972fcf3ce44SJohn Forte 
2973fcf3ce44SJohn Forte /*
2974fcf3ce44SJohn Forte  * removeTargetGroupMemberFunc
2975fcf3ce44SJohn Forte  *
2976fcf3ce44SJohn Forte  * Removes one or more members from a target group
2977fcf3ce44SJohn Forte  *
2978fcf3ce44SJohn Forte  */
2979fcf3ce44SJohn Forte /*ARGSUSED*/
2980fcf3ce44SJohn Forte static int
2981fcf3ce44SJohn Forte removeTargetGroupMemberFunc(int operandLen, char *operands[],
2982fcf3ce44SJohn Forte     cmdOptions_t *options, void *args)
2983fcf3ce44SJohn Forte {
2984fcf3ce44SJohn Forte 	int i;
2985fcf3ce44SJohn Forte 	int ret = 0;
2986fcf3ce44SJohn Forte 	int stmfRet;
29873e7352aeSJohn Forte 	stmfGroupName groupName = {0};
2988fcf3ce44SJohn Forte 	stmfDevid devid;
29893e7352aeSJohn Forte 	wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
2990fcf3ce44SJohn Forte 
2991fcf3ce44SJohn Forte 	for (; options->optval; options++) {
2992fcf3ce44SJohn Forte 		switch (options->optval) {
2993fcf3ce44SJohn Forte 			case 'g':
2994fcf3ce44SJohn Forte 				(void) mbstowcs(groupNamePrint, options->optarg,
29953e7352aeSJohn Forte 				    sizeof (stmfGroupName) - 1);
2996fcf3ce44SJohn Forte 				bcopy(options->optarg, groupName,
2997fcf3ce44SJohn Forte 				    strlen(options->optarg));
2998fcf3ce44SJohn Forte 				break;
2999fcf3ce44SJohn Forte 			default:
3000fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
3001fcf3ce44SJohn Forte 				    cmdName, options->optval,
3002fcf3ce44SJohn Forte 				    gettext("unknown option"));
3003fcf3ce44SJohn Forte 				return (1);
3004fcf3ce44SJohn Forte 		}
3005fcf3ce44SJohn Forte 	}
3006fcf3ce44SJohn Forte 
3007fcf3ce44SJohn Forte 	for (i = 0; i < operandLen; i++) {
3008fcf3ce44SJohn Forte 		if (parseDevid(operands[i], &devid) != 0) {
3009fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n",
3010fcf3ce44SJohn Forte 			    cmdName, operands[i],
3011fcf3ce44SJohn Forte 			    gettext("unrecognized device id"));
3012fcf3ce44SJohn Forte 			ret++;
3013fcf3ce44SJohn Forte 			continue;
3014fcf3ce44SJohn Forte 		}
3015fcf3ce44SJohn Forte 		stmfRet = stmfRemoveFromTargetGroup(&groupName, &devid);
3016fcf3ce44SJohn Forte 		switch (stmfRet) {
3017fcf3ce44SJohn Forte 			case STMF_STATUS_SUCCESS:
3018fcf3ce44SJohn Forte 				break;
3019fcf3ce44SJohn Forte 			case STMF_ERROR_MEMBER_NOT_FOUND:
3020fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3021fcf3ce44SJohn Forte 				    operands[i], gettext("not found"));
3022fcf3ce44SJohn Forte 				ret++;
3023fcf3ce44SJohn Forte 				break;
3024fcf3ce44SJohn Forte 			case STMF_ERROR_GROUP_NOT_FOUND:
3025fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
3026fcf3ce44SJohn Forte 				    groupNamePrint, gettext("not found"));
3027fcf3ce44SJohn Forte 				ret++;
3028fcf3ce44SJohn Forte 				break;
3029fcf3ce44SJohn Forte 			case STMF_ERROR_BUSY:
3030fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3031fcf3ce44SJohn Forte 				    operands[i], gettext("resource busy"));
3032fcf3ce44SJohn Forte 				ret++;
3033fcf3ce44SJohn Forte 				break;
3034fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
3035fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
3036fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
3037fcf3ce44SJohn Forte 				ret++;
3038fcf3ce44SJohn Forte 				break;
3039fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
3040fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
3041fcf3ce44SJohn Forte 				    gettext("permission denied"));
3042fcf3ce44SJohn Forte 				ret++;
3043fcf3ce44SJohn Forte 				break;
3044fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
3045fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
3046fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
3047fcf3ce44SJohn Forte 				ret++;
3048fcf3ce44SJohn Forte 				break;
30495c8cac22Stim szeto 			case STMF_ERROR_TG_ONLINE:
30505c8cac22Stim szeto 				(void) fprintf(stderr, "%s: %s\n", cmdName,
30515c8cac22Stim szeto 				    gettext("STMF target must be offline"));
30525c8cac22Stim szeto 				ret++;
30535c8cac22Stim szeto 				break;
3054fcf3ce44SJohn Forte 			default:
3055fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3056fcf3ce44SJohn Forte 				    operands[i], gettext("unknown error"));
3057fcf3ce44SJohn Forte 				ret++;
3058fcf3ce44SJohn Forte 				break;
3059fcf3ce44SJohn Forte 		}
3060fcf3ce44SJohn Forte 	}
3061fcf3ce44SJohn Forte 
3062fcf3ce44SJohn Forte 	return (ret);
3063fcf3ce44SJohn Forte }
3064fcf3ce44SJohn Forte 
3065fcf3ce44SJohn Forte /*
3066fcf3ce44SJohn Forte  * removeViewFunc
3067fcf3ce44SJohn Forte  *
3068fcf3ce44SJohn Forte  * Removes one or more view entries from a logical unit
3069fcf3ce44SJohn Forte  *
3070fcf3ce44SJohn Forte  */
3071fcf3ce44SJohn Forte /*ARGSUSED*/
3072fcf3ce44SJohn Forte static int
3073fcf3ce44SJohn Forte removeViewFunc(int operandLen, char *operands[], cmdOptions_t *options,
3074fcf3ce44SJohn Forte     void *args)
3075fcf3ce44SJohn Forte {
3076fcf3ce44SJohn Forte 	char sGuid[GUID_INPUT + 1];
3077fcf3ce44SJohn Forte 	stmfViewEntryList *viewEntryList;
3078fcf3ce44SJohn Forte 	stmfGuid inGuid;
3079fcf3ce44SJohn Forte 	uint32_t count;
3080fcf3ce44SJohn Forte 	unsigned int guid[sizeof (stmfGuid)];
3081fcf3ce44SJohn Forte 	char *endPtr;
3082fcf3ce44SJohn Forte 	uint32_t veNbr;
3083fcf3ce44SJohn Forte 	int i;
3084fcf3ce44SJohn Forte 	boolean_t all = B_FALSE;
3085fcf3ce44SJohn Forte 	boolean_t luInput = B_FALSE;
3086fcf3ce44SJohn Forte 	int ret = 0;
3087fcf3ce44SJohn Forte 	int stmfRet;
3088fcf3ce44SJohn Forte 
3089fcf3ce44SJohn Forte 	/* Note: 'l' is required */
3090fcf3ce44SJohn Forte 	for (; options->optval; options++) {
3091fcf3ce44SJohn Forte 		switch (options->optval) {
3092fcf3ce44SJohn Forte 			case 'l':
3093fcf3ce44SJohn Forte 				if (strlen(options->optarg) != GUID_INPUT) {
3094fcf3ce44SJohn Forte 					(void) fprintf(stderr,
3095fcf3ce44SJohn Forte 					    "%s: %s: %s %d %s\n",
3096fcf3ce44SJohn Forte 					    cmdName, options->optarg,
3097fcf3ce44SJohn Forte 					    gettext("must be"), GUID_INPUT,
3098fcf3ce44SJohn Forte 					    gettext("hexadecimal digits long"));
3099fcf3ce44SJohn Forte 					return (1);
3100fcf3ce44SJohn Forte 				}
3101fcf3ce44SJohn Forte 				bcopy(options->optarg, sGuid, GUID_INPUT);
3102fcf3ce44SJohn Forte 				luInput = B_TRUE;
3103fcf3ce44SJohn Forte 				break;
3104fcf3ce44SJohn Forte 			case 'a':
3105fcf3ce44SJohn Forte 				/* removing all view entries for this GUID */
3106fcf3ce44SJohn Forte 				all = B_TRUE;
3107fcf3ce44SJohn Forte 				break;
3108fcf3ce44SJohn Forte 			default:
3109fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
3110fcf3ce44SJohn Forte 				    cmdName, options->optval,
3111fcf3ce44SJohn Forte 				    "unknown option");
3112fcf3ce44SJohn Forte 				return (1);
3113fcf3ce44SJohn Forte 		}
3114fcf3ce44SJohn Forte 	}
3115fcf3ce44SJohn Forte 
3116fcf3ce44SJohn Forte 	if (!all && operandLen == 0) {
3117fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n", cmdName,
3118fcf3ce44SJohn Forte 		    gettext("no view entries specified"));
3119fcf3ce44SJohn Forte 		return (1);
3120fcf3ce44SJohn Forte 	}
3121fcf3ce44SJohn Forte 
3122fcf3ce44SJohn Forte 	if (!luInput) {
3123fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n", cmdName,
3124fcf3ce44SJohn Forte 		    gettext("logical unit (-l) not specified"));
3125fcf3ce44SJohn Forte 		return (1);
3126fcf3ce44SJohn Forte 	}
3127fcf3ce44SJohn Forte 
3128fcf3ce44SJohn Forte 	for (i = 0; i < 32; i++)
3129fcf3ce44SJohn Forte 		sGuid[i] = tolower(sGuid[i]);
3130fcf3ce44SJohn Forte 	sGuid[i] = 0;
3131fcf3ce44SJohn Forte 
3132fcf3ce44SJohn Forte 	(void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
3133fcf3ce44SJohn Forte 	    &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
3134fcf3ce44SJohn Forte 	    &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11],
3135fcf3ce44SJohn Forte 	    &guid[12], &guid[13], &guid[14], &guid[15]);
3136fcf3ce44SJohn Forte 
3137fcf3ce44SJohn Forte 	for (i = 0; i < sizeof (stmfGuid); i++) {
3138fcf3ce44SJohn Forte 		inGuid.guid[i] = guid[i];
3139fcf3ce44SJohn Forte 	}
3140fcf3ce44SJohn Forte 
3141fcf3ce44SJohn Forte 	if ((stmfRet = stmfGetViewEntryList(&inGuid, &viewEntryList))
3142fcf3ce44SJohn Forte 	    != STMF_STATUS_SUCCESS) {
3143fcf3ce44SJohn Forte 
3144fcf3ce44SJohn Forte 		switch (stmfRet) {
3145fcf3ce44SJohn Forte 			case STMF_ERROR_BUSY:
3146fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3147fcf3ce44SJohn Forte 				    sGuid, gettext("resource busy"));
3148fcf3ce44SJohn Forte 				break;
3149fcf3ce44SJohn Forte 			case STMF_ERROR_NOT_FOUND:
3150fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3151fcf3ce44SJohn Forte 				    sGuid, gettext("no views found"));
3152fcf3ce44SJohn Forte 				break;
3153fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
3154fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
3155fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
3156fcf3ce44SJohn Forte 				break;
3157fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
3158fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
3159fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
3160fcf3ce44SJohn Forte 				break;
3161fcf3ce44SJohn Forte 			case STMF_ERROR_PERM:
3162fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
3163fcf3ce44SJohn Forte 				    gettext("permission denied"));
3164fcf3ce44SJohn Forte 				break;
3165fcf3ce44SJohn Forte 			default:
3166fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3167fcf3ce44SJohn Forte 				    sGuid, gettext("unknown error"));
3168fcf3ce44SJohn Forte 				break;
3169fcf3ce44SJohn Forte 		}
3170fcf3ce44SJohn Forte 		return (1);
3171fcf3ce44SJohn Forte 	}
3172fcf3ce44SJohn Forte 
3173fcf3ce44SJohn Forte 	if (all) {
3174fcf3ce44SJohn Forte 		count = viewEntryList->cnt;
3175fcf3ce44SJohn Forte 	} else {
3176fcf3ce44SJohn Forte 		count = operandLen;
3177fcf3ce44SJohn Forte 	}
3178fcf3ce44SJohn Forte 
3179fcf3ce44SJohn Forte 	for (i = 0; i < count; i++) {
3180fcf3ce44SJohn Forte 		if (all) {
3181fcf3ce44SJohn Forte 			veNbr = viewEntryList->ve[i].veIndex;
3182fcf3ce44SJohn Forte 		} else {
3183fcf3ce44SJohn Forte 			endPtr = NULL;
3184fcf3ce44SJohn Forte 			veNbr = strtol(operands[i], &endPtr, 10);
3185fcf3ce44SJohn Forte 			if (endPtr && *endPtr != 0) {
3186fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3187fcf3ce44SJohn Forte 				    operands[i], gettext("invalid input"));
3188fcf3ce44SJohn Forte 				continue;
3189fcf3ce44SJohn Forte 			}
3190fcf3ce44SJohn Forte 		}
3191fcf3ce44SJohn Forte 		stmfRet = stmfRemoveViewEntry(&inGuid, veNbr);
3192fcf3ce44SJohn Forte 		switch (stmfRet) {
3193fcf3ce44SJohn Forte 			case STMF_STATUS_SUCCESS:
3194fcf3ce44SJohn Forte 				break;
3195fcf3ce44SJohn Forte 			case STMF_ERROR_NOT_FOUND:
3196fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %d: %s\n",
3197fcf3ce44SJohn Forte 				    cmdName, sGuid, veNbr,
3198fcf3ce44SJohn Forte 				    gettext("not found"));
3199fcf3ce44SJohn Forte 				ret++;
3200fcf3ce44SJohn Forte 				break;
3201fcf3ce44SJohn Forte 			case STMF_ERROR_BUSY:
3202fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3203fcf3ce44SJohn Forte 				    sGuid, gettext("resource busy"));
3204fcf3ce44SJohn Forte 				ret++;
3205fcf3ce44SJohn Forte 				break;
3206fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_NOT_FOUND:
3207fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
3208fcf3ce44SJohn Forte 				    gettext("STMF service not found"));
3209fcf3ce44SJohn Forte 				ret++;
3210fcf3ce44SJohn Forte 				break;
3211fcf3ce44SJohn Forte 			case STMF_ERROR_CONFIG_NONE:
3212fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
3213fcf3ce44SJohn Forte 				    gettext("STMF service is not initialized"));
3214fcf3ce44SJohn Forte 				ret++;
3215fcf3ce44SJohn Forte 				break;
3216fcf3ce44SJohn Forte 			case STMF_ERROR_SERVICE_DATA_VERSION:
3217fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n", cmdName,
3218fcf3ce44SJohn Forte 				    gettext("STMF service version incorrect"));
3219fcf3ce44SJohn Forte 				ret++;
3220fcf3ce44SJohn Forte 				break;
3221fcf3ce44SJohn Forte 			default:
3222fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s, %d: %s",
3223fcf3ce44SJohn Forte 				    cmdName, sGuid, veNbr,
3224fcf3ce44SJohn Forte 				    gettext("unknown error"));
3225fcf3ce44SJohn Forte 				ret++;
3226fcf3ce44SJohn Forte 				break;
3227fcf3ce44SJohn Forte 		}
3228fcf3ce44SJohn Forte 	}
3229fcf3ce44SJohn Forte 
3230fcf3ce44SJohn Forte 	return (ret);
3231fcf3ce44SJohn Forte }
3232fcf3ce44SJohn Forte 
3233fcf3ce44SJohn Forte /*
3234fcf3ce44SJohn Forte  * input:
3235fcf3ce44SJohn Forte  *  execFullName - exec name of program (argv[0])
3236fcf3ce44SJohn Forte  *
3237fcf3ce44SJohn Forte  *  copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net
3238fcf3ce44SJohn Forte  *  (changed name to lowerCamelCase to keep consistent with this file)
3239fcf3ce44SJohn Forte  *
3240fcf3ce44SJohn Forte  * Returns:
3241fcf3ce44SJohn Forte  *  command name portion of execFullName
3242fcf3ce44SJohn Forte  */
3243fcf3ce44SJohn Forte static char *
3244fcf3ce44SJohn Forte getExecBasename(char *execFullname)
3245fcf3ce44SJohn Forte {
3246fcf3ce44SJohn Forte 	char *lastSlash, *execBasename;
3247fcf3ce44SJohn Forte 
3248fcf3ce44SJohn Forte 	/* guard against '/' at end of command invocation */
3249fcf3ce44SJohn Forte 	for (;;) {
3250fcf3ce44SJohn Forte 		lastSlash = strrchr(execFullname, '/');
3251fcf3ce44SJohn Forte 		if (lastSlash == NULL) {
3252fcf3ce44SJohn Forte 			execBasename = execFullname;
3253fcf3ce44SJohn Forte 			break;
3254fcf3ce44SJohn Forte 		} else {
3255fcf3ce44SJohn Forte 			execBasename = lastSlash + 1;
3256fcf3ce44SJohn Forte 			if (*execBasename == '\0') {
3257fcf3ce44SJohn Forte 				*lastSlash = '\0';
3258fcf3ce44SJohn Forte 				continue;
3259fcf3ce44SJohn Forte 			}
3260fcf3ce44SJohn Forte 			break;
3261fcf3ce44SJohn Forte 		}
3262fcf3ce44SJohn Forte 	}
3263fcf3ce44SJohn Forte 	return (execBasename);
3264fcf3ce44SJohn Forte }
3265fcf3ce44SJohn Forte 
3266fcf3ce44SJohn Forte int
3267fcf3ce44SJohn Forte main(int argc, char *argv[])
3268fcf3ce44SJohn Forte {
3269fcf3ce44SJohn Forte 	synTables_t synTables;
3270fcf3ce44SJohn Forte 	char versionString[VERSION_STRING_MAX_LEN];
3271fcf3ce44SJohn Forte 	int ret;
3272fcf3ce44SJohn Forte 	int funcRet;
3273fcf3ce44SJohn Forte 	void *subcommandArgs = NULL;
3274fcf3ce44SJohn Forte 
3275fcf3ce44SJohn Forte 	(void) setlocale(LC_ALL, "");
3276fcf3ce44SJohn Forte 	(void) textdomain(TEXT_DOMAIN);
3277fcf3ce44SJohn Forte 	/* set global command name */
3278fcf3ce44SJohn Forte 	cmdName = getExecBasename(argv[0]);
3279fcf3ce44SJohn Forte 
3280fcf3ce44SJohn Forte 	(void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s",
3281fcf3ce44SJohn Forte 	    VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
3282fcf3ce44SJohn Forte 	synTables.versionString = versionString;
3283fcf3ce44SJohn Forte 	synTables.longOptionTbl = &longOptions[0];
3284fcf3ce44SJohn Forte 	synTables.subCommandPropsTbl = &subcommands[0];
3285fcf3ce44SJohn Forte 
3286fcf3ce44SJohn Forte 	ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
3287fcf3ce44SJohn Forte 	if (ret != 0) {
3288fcf3ce44SJohn Forte 		return (ret);
3289fcf3ce44SJohn Forte 	}
3290fcf3ce44SJohn Forte 
3291fcf3ce44SJohn Forte 	return (funcRet);
3292fcf3ce44SJohn Forte } /* end main */
3293