xref: /onnv-gate/usr/src/cmd/fm/fminject/common/inj_util.c (revision 1414:b4126407ac5b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*1414Scindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <inj.h>
300Sstevel@tonic-gate #include <inj_err.h>
310Sstevel@tonic-gate #include <assert.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate const char *
inj_item2str(inj_itemtype_t item)340Sstevel@tonic-gate inj_item2str(inj_itemtype_t item)
350Sstevel@tonic-gate {
36*1414Scindi 	static const char *const names[] = { "event", "fmri", "auth", "list" };
370Sstevel@tonic-gate 
380Sstevel@tonic-gate 	return (item >= 0 &&
390Sstevel@tonic-gate 	    item < sizeof (names) / sizeof (char *) ? names[item] : "???");
400Sstevel@tonic-gate }
410Sstevel@tonic-gate 
420Sstevel@tonic-gate inj_memtype_t
inj_item2mem(inj_itemtype_t item)430Sstevel@tonic-gate inj_item2mem(inj_itemtype_t item)
440Sstevel@tonic-gate {
450Sstevel@tonic-gate 	static const inj_memtype_t mems[] = {
46*1414Scindi 		MEMTYPE_EVENT, MEMTYPE_FMRI, MEMTYPE_AUTH, MEMTYPE_LIST
470Sstevel@tonic-gate 	};
480Sstevel@tonic-gate 
490Sstevel@tonic-gate 	assert(item >= 0 && item < sizeof (mems) / sizeof (inj_memtype_t));
500Sstevel@tonic-gate 	return (mems[item]);
510Sstevel@tonic-gate }
520Sstevel@tonic-gate 
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate  * Convert a *subset* of inj_memtype_t's to inj_itemtype_t's.
550Sstevel@tonic-gate  */
560Sstevel@tonic-gate inj_itemtype_t
inj_mem2item(inj_memtype_t mem)570Sstevel@tonic-gate inj_mem2item(inj_memtype_t mem)
580Sstevel@tonic-gate {
590Sstevel@tonic-gate 	switch (mem) {
600Sstevel@tonic-gate 	case MEMTYPE_EVENT:
610Sstevel@tonic-gate 		return (ITEMTYPE_EVENT);
620Sstevel@tonic-gate 	case MEMTYPE_FMRI:
630Sstevel@tonic-gate 		return (ITEMTYPE_FMRI);
640Sstevel@tonic-gate 	case MEMTYPE_AUTH:
650Sstevel@tonic-gate 		return (ITEMTYPE_AUTH);
66*1414Scindi 	case MEMTYPE_LIST:
67*1414Scindi 		return (ITEMTYPE_LIST);
680Sstevel@tonic-gate 	default:
690Sstevel@tonic-gate 		return (-1);
700Sstevel@tonic-gate 	}
710Sstevel@tonic-gate }
720Sstevel@tonic-gate 
730Sstevel@tonic-gate const char *
inj_mem2str(inj_memtype_t mem)740Sstevel@tonic-gate inj_mem2str(inj_memtype_t mem)
750Sstevel@tonic-gate {
760Sstevel@tonic-gate 	static const char *names[] = {
770Sstevel@tonic-gate 		"UNKNOWN",
780Sstevel@tonic-gate 		"int8", "int16", "int32", "int64",
790Sstevel@tonic-gate 		"uint8", "uint16", "uint32", "uint64",
800Sstevel@tonic-gate 		"bool", "string", "enum",
810Sstevel@tonic-gate 		"event", "fmri", "auth"
820Sstevel@tonic-gate 	};
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	return (mem >= 0 &&
850Sstevel@tonic-gate 	    mem < sizeof (names) / sizeof (char *) ? names[mem] : "???");
860Sstevel@tonic-gate }
87