Home | History | Annotate | Download | only in common
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  *
     21  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     22  * Use is subject to license terms.
     23  */
     24 
     25 
     26 /*
     27  * A collection of functions to ask operator questions
     28  *
     29  * These functions must be reworked when the operator interface is available
     30  */
     31 
     32 #include <sys/types.h>
     33 #include <sys/siginfo.h>
     34 #include <sys/scsi/impl/uscsi.h>
     35 #include <stdlib.h>
     36 #include <ctype.h>
     37 #include <sys/varargs.h>
     38 #include <string.h>
     39 #include <dm_msg.h>
     40 #include <dm_impl.h>
     41 #include <dm_proto.h>
     42 #include <mms_trace.h>
     43 
     44 static	char *_SrcFile = __FILE__;
     45 
     46 
     47 /*
     48  * Function name
     49  *	dm_ask_reply(char *reply)
     50  *
     51  * Parameters:
     52  *	reply	address of reply buffer
     53  *
     54  * Description:
     55  *	check standard replies from operator
     56  *
     57  * Return code:
     58  *	DM_REP_YES
     59  *	DM_REP_NO
     60  *	DM_REP_UNATTENDED
     61  *	DM_REP_ABORT
     62  *	DM_REP_RETRY
     63  *	DM_REP_STRING	reply is none above.
     64  *
     65  * Note:
     66  *
     67  *
     68  */
     69 
     70 int
     71 dm_ask_reply(char *reply)
     72 {
     73 	int		rc;
     74 
     75 	if (strcmp(reply, "yes") == 0) {
     76 		rc = DM_REP_YES;
     77 	} else if (strcmp(reply, "no") == 0) {
     78 		rc = DM_REP_NO;
     79 	} else if (strcmp(reply, "unattended") == 0) {
     80 		rc = DM_REP_UNATTENDED;
     81 	} else if (strcmp(reply, "abort") == 0) {
     82 		rc = DM_REP_ABORT;
     83 	} else if (strcmp(reply, "retry") == 0) {
     84 		rc = DM_REP_RETRY;
     85 	} else {
     86 		rc = DM_REP_STRING;
     87 	}
     88 
     89 	return (rc);
     90 }
     91 
     92 /*
     93  * Function name
     94  *	dm_ask_preempt(void)
     95  *
     96  * Parameters:
     97  *	none
     98  *
     99  * Description:
    100  *	Ask operator if reservation should be preempted
    101  *
    102  * Return code:
    103  *	return code from dm_ask_reply()
    104  *	DM_REP_ERROR	error
    105  *
    106  * Note:
    107  *
    108  *
    109  */
    110 
    111 int
    112 dm_ask_preempt(void)
    113 {
    114 	char		*reply = NULL;
    115 	int		rc;
    116 
    117 	dm_send_request(&reply, DM_6502_MSG, DM_MSG_REASON);
    118 	if (reply == NULL) {
    119 		return (DM_REP_ERROR);
    120 	}
    121 	rc = dm_ask_reply(reply);
    122 	free(reply);
    123 	return (rc);
    124 }
    125 
    126 /*
    127  * Function name
    128  *	dm_ask_freserve(void)
    129  *
    130  * Parameters:
    131  *	none
    132  *
    133  * Description:
    134  *	Ask operator if DM should reserve  the  tape  unit  by   breaking
    135  *	reservation held by another host
    136  *
    137  * Return code:
    138  *	return code from dm_ask_reply()
    139  *	DM_REP_ERROR	error
    140  *
    141  * Note:
    142  *
    143  *
    144  */
    145 
    146 int
    147 dm_ask_freserve(void)
    148 {
    149 	char		*reply = NULL;
    150 	int		rc;
    151 
    152 	dm_send_request(&reply, DM_6502_MSG, DM_MSG_REASON);
    153 	if (reply == NULL) {
    154 		return (DM_REP_ERROR);
    155 	}
    156 	rc = dm_ask_reply(reply);
    157 	free(reply);
    158 	return (rc);
    159 }
    160 
    161 /*
    162  * Function name
    163  *	dm_ask_write_lbl(char *from, char *to, char *pcl)
    164  *
    165  * Parameters:
    166  *	from	from label type
    167  *	to	to label type
    168  *	pcl	cartridge PCL of new label
    169  *
    170  * Description:
    171  *	ask for permission to write a new VOL1 label
    172  *
    173  * Return code:
    174  *	0	success
    175  *	-1	operator replied no or error
    176  *
    177  * Note:
    178  *
    179  *
    180  */
    181 
    182 int
    183 dm_ask_write_lbl(char *from, char *to, char *pcl)
    184 {
    185 	int		rc;
    186 	int		ask_lsw = 0;
    187 	int		ask_wo = 0;
    188 	char		*reply = NULL;
    189 
    190 	if ((drv->drv_flags & (DRV_SWITCH_LBL | DRV_ASK_SWITCH_LBL)) == 0) {
    191 		/* No switch labels */
    192 		return (-1);
    193 	}
    194 	if ((drv->drv_flags & DRV_ASK_SWITCH_LBL) != 0) {
    195 		ask_lsw = 1;
    196 	}
    197 
    198 	if ((drv->drv_flags & DRV_BLANK) == 0) {
    199 		/* Not a blank tape */
    200 		if (drv->drv_flags & (DRV_SWITCH_LBL | DRV_ASK_SWITCH_LBL)) {
    201 			if ((drv->drv_flags & DRV_ASK_WRITEOVER) != 0) {
    202 				ask_wo = 1;
    203 			}
    204 		} else {
    205 			/* No writeover */
    206 			return (-1);
    207 		}
    208 	}
    209 
    210 	if (ask_lsw == 0 && ask_wo == 0) {
    211 		/* Write label without asking */
    212 		return (0);
    213 	}
    214 
    215 	if (ask_lsw == 1 && ask_wo == 1) {
    216 		dm_send_request(&reply, DM_6520_MSG,
    217 		    "from", from, "to", to, "pcl", pcl, DM_MSG_REASON);
    218 	} else if (ask_lsw == 1) {
    219 		dm_send_request(&reply, DM_6519_MSG, "from", from,
    220 		    "to", to, DM_MSG_REASON);
    221 	} else {
    222 		dm_send_request(&reply, DM_6518_MSG, "pcl", pcl,
    223 		    DM_MSG_REASON);
    224 	}
    225 	if (reply == NULL) {
    226 		/* Can't get reply - means "no" */
    227 		return (-1);
    228 	}
    229 	rc = dm_ask_reply(reply);
    230 	free(reply);
    231 	if (rc == DM_REP_ERROR) {
    232 		/* Ask got an error, assume "no" */
    233 		return (-1);
    234 	}
    235 	if (rc == DM_REP_NO) {
    236 		DM_MSG_ADD((MMS_INTERNAL, MMS_DM_E_INTERNAL,
    237 		    "write label denied by operator"));
    238 		return (-1);
    239 	}
    240 
    241 	/*
    242 	 * Can write label
    243 	 */
    244 	return (0);
    245 }
    246