xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/segments.c (revision 11734:d29dc9c2b6c5)
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
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211618Srie 
220Sstevel@tonic-gate /*
23*11734SAli.Bahrami@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate  * String conversion routine for segment flags.
290Sstevel@tonic-gate  */
300Sstevel@tonic-gate #include	<string.h>
311618Srie #include	<libld.h>
321618Srie #include	"_conv.h"
330Sstevel@tonic-gate #include	"segments_msg.h"
340Sstevel@tonic-gate 
352352Sab196087 #define	SEGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
36*11734SAli.Bahrami@Sun.COM 		MSG_FLG_SG_P_VADDR_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
37*11734SAli.Bahrami@Sun.COM 		MSG_FLG_SG_P_PADDR_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
382352Sab196087 		MSG_FLG_SG_LENGTH_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
39*11734SAli.Bahrami@Sun.COM 		MSG_FLG_SG_P_ALIGN_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
402352Sab196087 		MSG_FLG_SG_ROUND_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
41*11734SAli.Bahrami@Sun.COM 		MSG_FLG_SG_P_FLAGS_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
42*11734SAli.Bahrami@Sun.COM 		MSG_FLG_SG_P_TYPE_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
43*11734SAli.Bahrami@Sun.COM 		MSG_FLG_SG_IS_ORDER_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
442352Sab196087 		MSG_FLG_SG_NOHDR_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
452352Sab196087 		MSG_FLG_SG_EMPTY_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
462352Sab196087 		MSG_FLG_SG_KEY_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
47*11734SAli.Bahrami@Sun.COM 		MSG_FLG_SG_NODISABLE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
482352Sab196087 		MSG_FLG_SG_DISABLED_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
492352Sab196087 		MSG_FLG_SG_PHREQ_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
50*11734SAli.Bahrami@Sun.COM 		MSG_FLG_SG_ORDERED_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
514734Sab196087 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
524734Sab196087 
534734Sab196087 /*
544734Sab196087  * Ensure that Conv_seg_flags_buf_t is large enough:
554734Sab196087  *
564734Sab196087  * SEGSZ is the real minimum size of the buffer required by conv_seg_flags().
574734Sab196087  * However, Conv_seg_flags_buf_t uses CONV_SEG_FLAGS_BUFSIZE to set the
584734Sab196087  * buffer size. We do things this way because the definition of SEGSZ uses
594734Sab196087  * information that is not available in the environment of other programs
604734Sab196087  * that include the conv.h header file.
614734Sab196087  */
625152Sab196087 #if (CONV_SEG_FLAGS_BUFSIZE != SEGSZ) && !defined(__lint)
635152Sab196087 #define	REPORT_BUFSIZE SEGSZ
645152Sab196087 #include "report_bufsize.h"
655152Sab196087 #error "CONV_SEG_FLAGS_BUFSIZE does not match SEGSZ"
664734Sab196087 #endif
670Sstevel@tonic-gate 
680Sstevel@tonic-gate const char *
conv_seg_flags(sg_flags_t flags,Conv_seg_flags_buf_t * seg_flags_buf)69*11734SAli.Bahrami@Sun.COM conv_seg_flags(sg_flags_t flags, Conv_seg_flags_buf_t *seg_flags_buf)
700Sstevel@tonic-gate {
711618Srie 	static Val_desc vda[] = {
72*11734SAli.Bahrami@Sun.COM 		{ FLG_SG_P_VADDR,	MSG_FLG_SG_P_VADDR },
73*11734SAli.Bahrami@Sun.COM 		{ FLG_SG_P_PADDR,	MSG_FLG_SG_P_PADDR },
749273SAli.Bahrami@Sun.COM 		{ FLG_SG_LENGTH,	MSG_FLG_SG_LENGTH },
75*11734SAli.Bahrami@Sun.COM 		{ FLG_SG_P_ALIGN,	MSG_FLG_SG_P_ALIGN },
769273SAli.Bahrami@Sun.COM 		{ FLG_SG_ROUND,		MSG_FLG_SG_ROUND },
77*11734SAli.Bahrami@Sun.COM 		{ FLG_SG_P_FLAGS,	MSG_FLG_SG_P_FLAGS },
78*11734SAli.Bahrami@Sun.COM 		{ FLG_SG_P_TYPE,	MSG_FLG_SG_P_TYPE },
79*11734SAli.Bahrami@Sun.COM 		{ FLG_SG_IS_ORDER,	MSG_FLG_SG_IS_ORDER },
809273SAli.Bahrami@Sun.COM 		{ FLG_SG_NOHDR,		MSG_FLG_SG_NOHDR },
819273SAli.Bahrami@Sun.COM 		{ FLG_SG_EMPTY,		MSG_FLG_SG_EMPTY },
829273SAli.Bahrami@Sun.COM 		{ FLG_SG_KEY,		MSG_FLG_SG_KEY },
83*11734SAli.Bahrami@Sun.COM 		{ FLG_SG_NODISABLE,	MSG_FLG_SG_NODISABLE },
849273SAli.Bahrami@Sun.COM 		{ FLG_SG_DISABLED,	MSG_FLG_SG_DISABLED },
859273SAli.Bahrami@Sun.COM 		{ FLG_SG_PHREQ,		MSG_FLG_SG_PHREQ },
86*11734SAli.Bahrami@Sun.COM 		{ FLG_SG_ORDERED,	MSG_FLG_SG_ORDERED },
871618Srie 		{ 0,			0 }
881618Srie 	};
894734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
909273SAli.Bahrami@Sun.COM 	    NULL, sizeof (seg_flags_buf->buf) };
910Sstevel@tonic-gate 
920Sstevel@tonic-gate 	if (flags == 0)
930Sstevel@tonic-gate 		return (MSG_ORIG(MSG_GBL_ZERO));
940Sstevel@tonic-gate 
954734Sab196087 	conv_arg.buf = seg_flags_buf->buf;
962352Sab196087 	conv_arg.oflags = conv_arg.rflags = flags;
979273SAli.Bahrami@Sun.COM 	(void) conv_expn_field(&conv_arg, vda, 0);
981618Srie 
994734Sab196087 	return ((const char *)seg_flags_buf->buf);
1000Sstevel@tonic-gate }
101