HELPLIB.HLB  —  MRD Library, mrd_home, Example
    /*
     *   Example to do slot to slot moves.  The command usage is:
     *
     *      mrd_home robot_name type address [ volume-tag ]
     *
     *   Type can be one of:
     *
     *      slot, port, drive or transport
     *
     *   The optional transport argument can be a transport address
     *   number, the word "default" or an empty string.
     */
    #ifndef   lint
    static   char   SccsId[] = "@(#)mrd_home.c   1.2 3/5/97" ;
    #endif

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <mrd_common.h>
    #include <mrd_message.h>

    /*
     *   Given a string, resembling one of the element types,
     *   return the SCSI type code for it.
     */
    struct {
       int   code ;
       char   *string ;
    } etypes[] = {
       TRANSPORT,   "transport",
       SLOT,      "slot",
       DRIVE,      "drive",
       PORT,      "port",
    } ;

    convert_type(char *etype)
    {
       register i ;

       /*
        *   For each entry in the array.
        */
       for(i = 0; i < sizeof(etypes)/sizeof(etypes[0]); i++)
          /*
           *   Do a case insensitive comparison, allowing
           *   abbreviations.  Return as soon as a match is
           *   found.  Return -1 if one isn't found.
           */
    #ifdef   vms
          if( strncmp(etypes[i].string, etype, strlen(etype)) == 0)
    #else
          if( strncasecmp(etypes[i].string,etype,strlen(etype)) == 0)
    #endif
             return etypes[i].code ;

       return -1 ;
    }

    main(int argc, char *argv[])
    {
       int   status ;      /* Status from mrd_home(3mrd) */
       char   *robot ;      /* Robot to use */
       char   *element ;      /* Element address */
       char   *volume_tag = NULL ;   /* Optional volume tag */
       int   type ;         /* Element type */
       char   home[MRD_NAME_SIZE+1] ;   /* space for return address */
       int   home_type ;      /* return element type */
       char   log_info[MRD_MAX_LOG_STRING+1] ;   /* error string */

       /*
        *   Three required arguments; robot, element type and address.
        */
       if( argc < 4 ) {
          printf("usage: %s robot type address [ volume_tag ]\n",
             argv[0]) ;

          exit(1) ;
       }

       robot   = argv[1] ;
       type    = convert_type(argv[2]) ;
       element = argv[3] ;

       /*
        *   Optional volume tag.
        */
       if( argc > 4 )
          volume_tag = argv[4] ;

       /*
        *   Do the operation.
        */
       status = mrd_home(robot, volume_tag, element, type,
             home, &home_type, log_info) ;

       if( status != MRD_STATUS_SUCCESS )
          printf("Home failed: %s: %s.\n", mrd_strstatus(status),
             log_info[0] ? log_info : "none") ;
       else
          printf("The cartridge in %s %s was returned to %s %s.\n",
             mrd_strelement(type), element,
             mrd_strelement(home_type), home) ;

       return 0 ;
    }
Close Help