1 /*
2  * Copyright (c) 1998,1999,2000
3  *	Traakan, Inc., Los Altos, CA
4  *	All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice unmodified, this list of conditions, and the following
11  *    disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 /*
30  * Project:  NDMJOB
31  * Ident:    $Id: $
32  *
33  * Description:
34  *
35  */
36 
37 
38 #include "smc_priv.h"
39 
40 static char *strend(char *s);
41 
42 
43 
44 char *
smc_elem_type_code_to_str(int code)45 smc_elem_type_code_to_str(int code)
46 {
47 	switch (code) {
48 	case SMC_ELEM_TYPE_ALL:		return "ALL";
49 	case SMC_ELEM_TYPE_MTE:		return "ARM";
50 	case SMC_ELEM_TYPE_SE:		return "SLOT";
51 	case SMC_ELEM_TYPE_IEE:		return "IEE";
52 	case SMC_ELEM_TYPE_DTE:		return "TAPE";
53 	default:			return "???";
54 	}
55 }
56 
57 int
smc_pp_element_address_assignments(struct smc_element_address_assignment * eaa,int lineno,char * buf)58 smc_pp_element_address_assignments (struct smc_element_address_assignment *eaa,
59   int lineno, char *buf)
60 {
61 	sprintf (buf, "slots %d@%d  drive %d@%d  arm %d@%d  i/e %d@%d",
62 		eaa->se_count,  eaa->se_addr,
63 		eaa->dte_count, eaa->dte_addr,
64 		eaa->mte_count, eaa->mte_addr,
65 		eaa->iee_count, eaa->iee_addr);
66 
67 	return 1;
68 }
69 
70 int
smc_pp_element_descriptor(struct smc_element_descriptor * edp,int lineno,char * ret_buf)71 smc_pp_element_descriptor (struct smc_element_descriptor *edp,
72   int lineno, char *ret_buf)
73 {
74 	int		nline = 0;
75 	char		buf[100];
76 
77 	*ret_buf = 0;
78 	*buf = 0;
79 
80 	sprintf (buf, "@%-3d %-4s",
81 		edp->element_address,
82 		smc_elem_type_code_to_str(edp->element_type_code));
83 
84 	if (edp->Full)
85 		strcat (buf, " Full ");
86 	else
87 		strcat (buf, " Empty");
88 
89 	if (edp->element_type_code == SMC_ELEM_TYPE_MTE) {
90 		if (edp->Access) {
91 			/* unusual for MTE */
92 			/* actually not defined */
93 			strcat (buf, " ?access=granted?");
94 		}
95 	} else {
96 		if (!edp->Access) {
97 			/* unusual for all non-MTE elements */
98 			strcat (buf, " ?access=denied?");
99 		}
100 	}
101 
102 	if (edp->PVolTag && edp->Full) {
103 		sprintf (strend(buf), " PVolTag(%s,#%d)",
104 			edp->primary_vol_tag->volume_id,
105 			edp->primary_vol_tag->volume_seq);
106 	}
107 
108 	if (edp->Except) {
109 		sprintf (strend(buf), " Except(asc=%02x,ascq=%02x)",
110 			edp->asc, edp->ascq);
111 	}
112 
113 	if (*buf && nline++ == lineno) strcpy (ret_buf, buf);
114 	*buf = 0;
115 
116 #define INDENT_SPACES "          "	/* 10 spaces */
117 
118 	if (edp->AVolTag) {
119 		sprintf (buf, INDENT_SPACES "AVolTag(%s,#%d)",
120 			edp->alternate_vol_tag->volume_id,
121 			edp->alternate_vol_tag->volume_seq);
122 	}
123 
124 	if (*buf && nline++ == lineno) strcpy (ret_buf, buf);
125 	*buf = 0;
126 
127 	if (edp->SValid) {
128 		sprintf (buf, INDENT_SPACES "SValid(src=%d,%sinvert)",
129 			edp->src_se_addr,
130 			edp->Invert ? "" : "!");
131 	}
132 
133 	if (*buf && nline++ == lineno) strcpy (ret_buf, buf);
134 	*buf = 0;
135 
136 	if (edp->element_type_code == SMC_ELEM_TYPE_DTE) {
137 		strcpy (buf, INDENT_SPACES);
138 		if (edp->ID_valid) {
139 			sprintf (strend(buf), "ID sid=%d", edp->scsi_sid);
140 		} else {
141 			strcat (buf, "no-sid-data");
142 		}
143 		if (edp->LU_valid) {
144 			sprintf (strend(buf), " lun=%d", edp->scsi_lun);
145 		} else {
146 			strcat (buf, " no-lun-data");
147 		}
148 
149 		if (edp->ID_valid && edp->Not_bus) {
150 			strcat (buf, " not-same-bus");
151 		}
152 	}
153 
154 	if (*buf && nline++ == lineno) strcpy (ret_buf, buf);
155 	*buf = 0;
156 
157 	if (edp->element_type_code == SMC_ELEM_TYPE_IEE) {
158 		strcpy (buf, INDENT_SPACES);
159 
160 		if (edp->InEnab)
161 			strcat (buf, " can-import");
162 		else
163 			strcat (buf, " can-not-import");
164 
165 		if (edp->ExEnab)
166 			strcat (buf, " can-export");
167 		else
168 			strcat (buf, " can-not-export");
169 
170 		if (edp->ImpExp)
171 			strcat (buf, " by-oper");
172 		else
173 			strcat (buf, " by-mte");
174 	}
175 
176 	if (*buf && nline++ == lineno) strcpy (ret_buf, buf);
177 	*buf = 0;
178 
179 	return nline;
180 }
181 
182 static char *
strend(char * s)183 strend (char *s)
184 {
185 	while (*s) s++;
186 	return s;
187 }
188