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
smc_elem_type_code_to_str(int code)43 char* smc_elem_type_code_to_str(int code)
44 {
45 switch (code) {
46 case SMC_ELEM_TYPE_ALL:
47 return "ALL";
48 case SMC_ELEM_TYPE_MTE:
49 return "ARM";
50 case SMC_ELEM_TYPE_SE:
51 return "SLOT";
52 case SMC_ELEM_TYPE_IEE:
53 return "IEE";
54 case SMC_ELEM_TYPE_DTE:
55 return "TAPE";
56 default:
57 return "???";
58 }
59 }
60
smc_pp_element_address_assignments(struct smc_element_address_assignment * eaa,int lineno,char * buf)61 int smc_pp_element_address_assignments(
62 struct smc_element_address_assignment* eaa,
63 int lineno,
64 char* buf)
65 {
66 sprintf(buf, "slots %d@%d drive %d@%d arm %d@%d i/e %d@%d", eaa->se_count,
67 eaa->se_addr, eaa->dte_count, eaa->dte_addr, eaa->mte_count,
68 eaa->mte_addr, eaa->iee_count, eaa->iee_addr);
69
70 return 1;
71 }
72
smc_pp_element_descriptor(struct smc_element_descriptor * edp,int lineno,char * ret_buf)73 int smc_pp_element_descriptor(struct smc_element_descriptor* edp,
74 int lineno,
75 char* ret_buf)
76 {
77 int nline = 0;
78 char buf[100];
79
80 *ret_buf = 0;
81 *buf = 0;
82
83 sprintf(buf, "@%-3d %-4s", edp->element_address,
84 smc_elem_type_code_to_str(edp->element_type_code));
85
86 if (edp->Full)
87 strcat(buf, " Full ");
88 else
89 strcat(buf, " Empty");
90
91 if (edp->element_type_code == SMC_ELEM_TYPE_MTE) {
92 if (edp->Access) {
93 /* unusual for MTE */
94 /* actually not defined */
95 strcat(buf, " ?access=granted?");
96 }
97 } else {
98 if (!edp->Access) {
99 /* unusual for all non-MTE elements */
100 strcat(buf, " ?access=denied?");
101 }
102 }
103
104 if (edp->PVolTag && edp->Full) {
105 sprintf(strend(buf), " PVolTag(%s,#%d)", edp->primary_vol_tag->volume_id,
106 edp->primary_vol_tag->volume_seq);
107 }
108
109 if (edp->Except) {
110 sprintf(strend(buf), " Except(asc=%02x,ascq=%02x)", 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)", edp->src_se_addr,
129 edp->Invert ? "" : "!");
130 }
131
132 if (*buf && nline++ == lineno) strcpy(ret_buf, buf);
133 *buf = 0;
134
135 if (edp->element_type_code == SMC_ELEM_TYPE_DTE) {
136 strcpy(buf, INDENT_SPACES);
137 if (edp->ID_valid) {
138 sprintf(strend(buf), "ID sid=%d", edp->scsi_sid);
139 } else {
140 strcat(buf, "no-sid-data");
141 }
142 if (edp->LU_valid) {
143 sprintf(strend(buf), " lun=%d", edp->scsi_lun);
144 } else {
145 strcat(buf, " no-lun-data");
146 }
147
148 if (edp->ID_valid && edp->Not_bus) { strcat(buf, " not-same-bus"); }
149 }
150
151 if (*buf && nline++ == lineno) strcpy(ret_buf, buf);
152 *buf = 0;
153
154 if (edp->element_type_code == SMC_ELEM_TYPE_IEE) {
155 strcpy(buf, INDENT_SPACES);
156
157 if (edp->InEnab)
158 strcat(buf, " can-import");
159 else
160 strcat(buf, " can-not-import");
161
162 if (edp->ExEnab)
163 strcat(buf, " can-export");
164 else
165 strcat(buf, " can-not-export");
166
167 if (edp->ImpExp)
168 strcat(buf, " by-oper");
169 else
170 strcat(buf, " by-mte");
171 }
172
173 if (*buf && nline++ == lineno) strcpy(ret_buf, buf);
174 *buf = 0;
175
176 return nline;
177 }
178
strend(char * s)179 static char* strend(char* s)
180 {
181 while (*s) s++;
182 return s;
183 }
184