/*
* This shows how the utility routines are used. For
* mrd_scsi_decode(3mrd), a selected SCSI-2 error will
* be filled into the key, asc and ascq fields of a
* dev_status_t structure and the resulting MRD status
* message printed. For mrd_map_os_error(3mrd) the
* will be done for a selected operating system error.
*
* Usage:
*
* mrd_utility
*/
#ifndef lint
static char SccsId[] = "@(#)mrd_utility.c 1.2 3/5/97" ;
#endif
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <mrd_common.h>
#include <mrd_message.h>
#ifdef vms
# include <ssdef.h>
#endif
main(int argc, char *argv[])
{
dev_status_t dev_status ; /* Device status */
int status ;
char log_info[MRD_MAX_LOG_STRING+1] ;
/*
* Clear this for later.
*/
log_info[0] = '\0' ;
/*
* First, try mrd_scsi_decode(3mrd). SCSI-2 happens to
* have ASC/ASCQ codes for a cleaning cartridge being
* installed somewhere, presumably a drive. We'll
* see what MRD does with it.
*/
dev_status.valid = SCSI_REQ_SENSE_VALID ;
dev_status.key = 1 ; /* Recovered Error */
dev_status.asc = 0x30 ;
dev_status.ascq = 3 ;
status = mrd_scsi_decode(&dev_status) ;
/*
* Now print the result. As it happens we map this
* code to MRD_STATUS_AUTOCLEAN, which is nearly
* right.
*/
printf("Cleaning Cartridge Installed: (%d,%x,%x): %s\n",
dev_status.key, dev_status.asc,
dev_status.ascq, mrd_strstatus(status)) ;
/*
* Now do one of completely random values. Seed the
* random number generator just so most get a different
* answer. Most of these are likely to end up as
* Vendor Unique errors.
*/
srand(time(NULL)) ;
dev_status.key = rand() % 16 ; /* 0 - 15 */
dev_status.asc = rand() % 256 ; /* 0 - 255 */
dev_status.ascq = rand() % 256 ; /* 0 - 255 */
status = mrd_scsi_decode(&dev_status) ;
/*
* Now print the result.
*/
printf("Random SCSI Decode: (%d,%x,%x): %s\n",
dev_status.key, dev_status.asc,
dev_status.ascq, mrd_strstatus(status)) ;
/*
* Now an OS error. If #ifdef is handle the two example
* operating systems.
*/
dev_status.valid = 0 ;
#if defined(VMS)
dev_status.os_status = SS$_UNASEFC ;
#elif defined(unix)
dev_status.os_status = EINTR ;
#else
dev_status.os_status = rand() % 100 ;
#endif
status = mrd_map_os_error(dev_status.os_status, log_info) ;
if( log_info[0] )
printf("Map OS Error: %d: %s: %s\n", dev_status.os_status,
mrd_strstatus(status), log_info) ;
else
printf("Map OS Error: %d: %s\n", dev_status.os_status,
mrd_strstatus(status)) ;
return 0 ;
}