| /*
* This is an example of using mrd_test_unit_ready(3mrd)
* to see if a media changer will accept commands. On
* Digital UNIX this particular example will always
* succeed whether the robot is ready or not. See the
* Restrictions section of the manual page for more
* information.
*
* Usage:
*
* mrd_test_unit_ready robot [ more-robots... ]
*/
#ifndef lint
static char SccsId[] = "@(#)mrd_test_unit_ready.c 1.1 (mrd-example) 4/16/97" ;
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <mrd_common.h>
#include <mrd_message.h>
/*
* Message string.
*/
char *tur_failed_dev = "Test unit ready failed on %s: %s (%d,0x%x,0x%x).\n" ;
char *tur_failed_os = "Test unit ready failed on %s: %s (%d).\n" ;
char *tur_failed = "Test unit ready failed on %s: %s.\n" ;
/*
* The MRD can report three types of errors:
*
* o Device errors - When the "valid" field is set, at least one
* of the key, asc and ascq field should have values set from
* a SCSI Request Sense data or equivalent.
*
* o Operating System errors - When the valid field is zero, but
* the os_status field is set. Where possible an MRD error
* will be set if one corresponds to the error. If not, the
* MRD status will be MRD_STATUS_OS_ERROR. The os_status
* is the error specific to the operating system. On Digital
* UNIX it is an errno value. On OpenVMS it is a system service
* return value.
*
* o MRD Errors - The MRD error code is set explicitly.
*/
print_error(char *robot, int mrd_status, dev_status_t *dp)
{
/*
* Print the Key/ASC/ASCQ data for device errors.
*/
if( dp->valid )
printf(tur_failed_dev, robot, mrd_strstatus(mrd_status),
dp->key, dp->asc, dp->ascq) ;
/*
* Try to decode the os_status according to the operating
* system type.
*/
else if( dp->os_status == MRD_STATUS_OS_ERROR )
printf(tur_failed_os, robot, mrd_strstatus(mrd_status),
#ifdef unix
strerror(dp->os_status)) ;
#endif
#ifdef vms
strerror(EVMSERR, dp->os_status)) ;
#endif
/*
* Just print the message on others.
*/
else
printf(tur_failed, robot, mrd_strstatus(mrd_status)) ;
}
main(int argc, char *argv[])
{
int rc ; /* counter */
int status ; /* return status */
char *robot ; /* Robot to open */
robot_info_t robot_info ; /* Robot data */
dev_status_t dev_status ; /* Device status */
char log_info[MRD_MAX_LOG_STRING+1] ;
/*
* Check that there are enough arguments.
*/
if( argc < 2 ) {
printf("usage: %s robot [ robot... ]\n", argv[0]) ;
exit(1) ;
}
/*
* Initialize the channel field of the robot_info, so
* mrd_startup(3mrd) will actually open the robot.
*/
robot_info.channel = BAD_CHANNEL ;
for(rc = 1; rc < argc; rc++) {
/*
* The robot for this command.
*/
robot = argv[rc] ;
status = mrd_startup(robot, &robot_info, log_info) ;
if( status != MRD_STATUS_SUCCESS ) {
printf("Startup failed on %s: %s.\n", robot,
mrd_strstatus(status)) ;
continue ;
}
memset((void *)&dev_status, 0, sizeof(dev_status)) ;
status = mrd_test_unit_ready(&robot_info, &dev_status) ;
/*
* Do some fancy error printing.
*/
if( status != MRD_STATUS_SUCCESS )
print_error(robot, status, &dev_status) ;
else
printf("%s is ready.\n", robot) ;
(void)mrd_shutdown(&robot_info) ;
}
return 0 ;
}
|
| /*
* This is an example of using mrd_request_sense(3mrd)
* to see what state a medium changer is in. The MRD
* implementation of Request Sense only collects the
* Sense Key, Additional Sense Code and Additional Sense
* Code Qualifier.
*
* Usage:
*
* mrd_request_sense robot [ more-robots... ]
*/
#ifndef lint
static char SccsId[] = "@(#)mrd_request_sense.c 1.1 (mrd-example) 4/16/97" ;
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <mrd_common.h>
#include <mrd_message.h>
char *device_sense = "Sense data for %s: %s (%d,0x%x,0x%x).\n" ;
char *sense_failed = "Request Sense failed on %s: %s.\n" ;
main(int argc, char *argv[])
{
int rc ; /* counter */
int status ; /* return status */
char *robot ; /* Robot to open */
robot_info_t robot_info ; /* Robot data */
dev_status_t dev_status ; /* Device status */
char log_info[MRD_MAX_LOG_STRING+1] ;
/*
* Check that there are enough arguments.
*/
if( argc < 2 ) {
printf("usage: %s robot [ robot... ]\n", argv[0]) ;
exit(1) ;
}
/*
* Initialize the channel field of the robot_info, so
* mrd_startup(3mrd) will actually open the robot.
*/
robot_info.channel = BAD_CHANNEL ;
for(rc = 1; rc < argc; rc++) {
/*
* The robot for this command.
*/
robot = argv[rc] ;
status = mrd_startup(robot, &robot_info, log_info) ;
if( status != MRD_STATUS_SUCCESS ) {
printf("Startup failed on %s: %s.\n", robot,
mrd_strstatus(status)) ;
continue ;
}
memset((void *)&dev_status, 0, sizeof(dev_status)) ;
/*
* mrd_request_sense(3mrd) will never return
* MRD_STATUS_SUCCESS. If no Request Sense data
* is available, it will return MRD_STATUS_NO_SENSE.
*/
status = mrd_request_sense(&robot_info, &dev_status,
MRD_CHECK_SENSE) ;
/*
* Print the Key/ASC/ASCQ data for device errors.
*/
if( dev_status.valid )
printf(device_sense, robot, mrd_strstatus(status),
dev_status.key, dev_status.asc,
dev_status.ascq) ;
/*
* Just print the MRD error.
*/
else
printf(sense_failed, robot, mrd_strstatus(status)) ;
(void)mrd_shutdown(&robot_info) ;
}
return 0 ;
}
|