Beispiel #1
0
int
proc_rule(struct htx_data *phtx_info, struct ruleinfo *prule_info,
          char *wbuf, char *rbuf, struct blk_num_typ *pblk_num)
{
  int            dlen, loop, rc;                   
  char           msg[220], path[100];
  unsigned short seed[3];

  rc = 0;
  init_seed(seed);            /* initialize seed for random number generator */
  dlen = prule_info->num_blks * BLK_SIZE;       /* initialize length of data */
                                           /*-------------------------------*/
                                           /* initialize the write buffer   */
                                           /*-------------------------------*/
  if ( (prule_info->pattern_id[0] != '#') && 
       (prule_info->pattern_id[0] != 0) ) {
	 path[0] ='\0';	  
     if ( (int) htx_strlen((char *) htx_strcpy(path, getenv("HTXPATTERNS"))) == 0 )
        htx_strcpy(path, "../pattern/");         /* default ONLY */
     htx_strcat (path, prule_info->pattern_id);
     rc = hxfpat(path, wbuf, dlen);
     if ( rc == 1 ) {
        sprintf(msg, "cannot open pattern file - %s\n", path);
        hxfmsg(phtx_info, 0, SYSERR, msg);
        return(1);
     } 
     if ( rc == 2 ) {
        sprintf(msg, "cannot read pattern file - %s\n", path);
        hxfmsg(phtx_info, 0, SYSERR, msg);
        return(1);
     } 
  } else if ( prule_info->pattern_id[0] == '#' )
     bldbuf((unsigned short*)wbuf, dlen, prule_info->pattern_id, pblk_num);
  pblk_num->in_rule = 0;      /* initialize block number within current rule */
  rc = 0;
  tape_error_code = 0;
  for ( loop = 1; loop <= prule_info->num_oper; loop++ ) {
     if ( strcmp(prule_info->oper, "R") == 0 ) {     
        rc = read_tape(phtx_info, prule_info, loop, pblk_num, rbuf);
     } else if ( strcmp(prule_info->oper, "W") == 0 ) {
        rc = write_tape(phtx_info, prule_info, loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "RC") == 0 ) {   
        rc = read_tape(phtx_info, prule_info, loop, pblk_num, rbuf);
        if ( rc >= 0 )     
           rc = cmpbuf(phtx_info, prule_info, loop, pblk_num, wbuf, rbuf);
     } else if ( strcmp(prule_info->oper, "RW") == 0 ) {
        rc = rewind_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "WEOF") == 0 ) { 
        rc = weof_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "SF") == 0 ) {  
        rc = search_file(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "SR") == 0 ) {  
        rc = search_rec(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "D") == 0 ) { 
        rc = diag_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "E") == 0 ) { 
        rc = erase_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "S") == 0 ) { 
        rc = do_sleep(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "CO") == 0 ) { 
        rc = close_open(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "C") == 0 ) { 
        rc = tclose(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "O") == 0 ) {  
        rc = topen(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "WEOT") == 0 ) {
        rc = write_eot(phtx_info, prule_info,loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "RCEOT") == 0 ) {
        rc = read_eot(phtx_info, prule_info, loop,pblk_num, wbuf, rbuf);
     } else if ( strcmp(prule_info->oper, "REOT") == 0 ) {  
        rc = read_teot(phtx_info, prule_info, loop, pblk_num, wbuf, rbuf);
     } else if ( strcmp(prule_info->oper, "RS") == 0 ) {  
        rc = prt_req_sense(phtx_info, prule_info, loop, pblk_num);
	 }
#ifndef __HTX_LINUX__		
     else if ( strcmp(prule_info->oper, "ML") == 0 ) { 
        rc = medium_load(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "MUL") == 0 ) {   
        rc = medium_unload(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "RES") == 0 ) {   
        rc = read_status(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "IE") == 0 ) {   
        rc = init_element(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "RP") == 0 ) {  
        rc = read_posit(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "LB") == 0 ) {   
        rc = loc_block(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "ASF") == 0 ) { 
        rc = asearch_file(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "ASR") == 0 ) { 
        rc = asearch_rec(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "ADUL") == 0 ) {  
        rc = write_unload(phtx_info, prule_info, loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "TWIE") == 0 ) {  
        rc = twin_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "TWPE") == 0 ) {   
        rc = twps_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "TWRE") == 0 ) {  
        rc = twrd_stat(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "TWMM") == 0 ) { 
        rc = twmv_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "TWUL") == 0 ) {  
        rc = unload_write(phtx_info, prule_info, loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "WUL") == 0 ) {   
        rc = tape_unload(phtx_info, prule_info, loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "CDRE") == 0 ) {
        rc = cdrd_stat(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "CDMM") == 0 ) {  
        rc = cdmv_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "HUNL") == 0 ) {
        rc = himove(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "HINI") == 0 ) {
        rc = hiinit(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "HREL") == 0 ) {
        rc = hielem(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "HWUN") == 0 ) {
        rc = hidal_unload(phtx_info, prule_info, loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "DBUG") == 0 ) {  
       rc = set_dbug(phtx_info, prule_info, pblk_num);
     } 
#endif
	 else if ( strcmp(prule_info->oper, "XCMD") == 0 ) {
       rc = do_cmd(phtx_info, prule_info, pblk_num);
     } else {
        ;
     }
     hxfupdate(UPDATE, phtx_info);
     if ( phtx_info->run_type[0] == 'O' ) {
        info_msg(phtx_info, prule_info, loop, pblk_num, msg);
        hxfmsg(phtx_info, 0, INFO, msg);
     } 
     if ( rc != 0 )
        break;
  } 
  return(rc);
} 
Beispiel #2
0
int proc_rule(struct htx_data *ps, struct ruleinfo *pr, char *wbuf, char *rbuf, unsigned int *last_lba, unsigned int *pblk_size)
{
  int            blkno[3], blkno_save[3]; /* block # ptrs 0-curr,1-up,2-dwn */
  int            rc, i, rc_ptr, save_dlen, loop;
  unsigned short seed[3];
  char           path[100], msg[221], *tbuf, *tbuf_malloc;

  int read_res = -1;

  tbuf_malloc = malloc(TMP_BUF_SIZE + PAGE_SIZE);
  if(tbuf_malloc == NULL) { /* Out of memory? */
     sprintf(msg, "Cannot allocate memory for tbuf: %d bytes\n", TMP_BUF_SIZE + PAGE_SIZE);
     hxfmsg(ps, 0, SYSERR, msg);
     return(1);
  }

#ifndef __HTX_LINUX__     /* AIX */
  tbuf = tbuf_malloc;
#else                     /* Linux */
  /* Page align the tmp buffer for linux raw IO */
  tbuf = (char *)HTX_PAGE_ALIGN(tbuf_malloc);
#endif

  init_seed(seed);                /* init seed for random number generator */
  if ( strcmp(pr->addr_type, "SEQ") == 0 ||         /* init length of data */
       strcmp(pr->type_length, "FIXED") == 0)       /* to be transmitted   */
     pr->dlen = pr->num_blks * pr->bytpsec;
  else
     pr->dlen = random_dlen(pr->bytpsec, pr->tot_blks, seed);
  if ( strcmp(pr->oper, "RC") == 0 ) {      /* init write buff for oper RC */
                                   /* get HTXPATTERNS environment variable */
     strcpy(path, ""); /* Linux will need this initialization */
     if ((char *) getenv("HTXPATTERNS") != NULL) {
                 strcpy(path, (char *) getenv("HTXPATTERNS"));
     } else {
         strcpy(path, "../pattern/");                       /* default ONLY */
     }
     strcat (path, pr->pattern_id);
     rc = hxfpat(path, wbuf, pr->dlen);
     if ( rc == 1 ) {
        sprintf(msg, "Cannot open pattern file - %s\n", path);
        hxfmsg(ps, 0, SYSERR, msg);
        return(1);
     }
     if ( rc == 2 ) {
        sprintf(msg, "Cannot read pattern file - %s\n", path);
        hxfmsg(ps, 0, SYSERR, msg);
        return(1);
     }
  }
  if ( strcmp(pr->addr_type, "SEQ") == 0 )    /* init current block number */
     init_blkno(pr, blkno);
  else
     random_blkno(blkno, pr->dlen, pr->bytpsec, pr->max_blkno, seed,
                  pr->min_blkno);
  for ( i = 0; i < 3; i++ )
      blkno_save[i] = blkno[i];

  for ( loop = 1 ; loop <= pr->num_oper ; loop++ ) {
     if ( strcmp(pr->oper, "MS") == 0 ) {
        ms_get(pr, ps, last_lba, pblk_size);
    } else if ( strcmp(pr->oper, "R") == 0 ) {
        read_cdrom(ps, pr, loop, blkno, rbuf);
    } else if ( strcmp(pr->oper, "RWP") == 0 ) {
        read_write_pattern(ps, pr, loop, blkno, rbuf);
    } else if ( strcmp(pr->oper, "RRC") == 0 ) {
        /*read_cdrom(ps, pr, loop, blkno, wbuf);
        read_cdrom(ps, pr, loop, blkno, rbuf);*/

        if( (read_res = read_cdrom(ps, pr, loop, blkno, wbuf) ) == 0 ) {/* read success */
        	if( (read_res = read_cdrom(ps, pr, loop, blkno, rbuf) ) == 0 ) {/* read success, again */
        		cmpbuf(ps, pr, loop, blkno, wbuf, rbuf); /* safe to compare */
			} else { /* second read fail */
				 sprintf(msg, "read_cdrom() failed in Re-Read sequence of RRC oper\n"
				              "Skipping compare operation\n");
				 prt_msg(ps, pr, loop, blkno, 0, SOFT, msg);
			}
		} else { /* first read fail */
			 sprintf(msg, "read_cdrom() failed in Read sequence of RRC oper\n"
						  "Skipping compare operation\n");
			 prt_msg(ps, pr, loop, blkno, 0, SOFT, msg);
		}

    } else if ( strcmp(pr->oper, "RC") == 0 ) {
        for ( i = 0; i < 3; i++ )
           blkno[i] = blkno_save[i];      /* RC = always start at same blkno */
                       /******************************************************/
                       /*- First, read the successive data blocks into rbuf  -*/
                       /******************************************************/
        save_dlen = pr->dlen;
        rc_ptr = 0;                          /*- init read/compare pointer --*/
        pr->dlen = pr->bytpsec;      /*-- read 1 block at a time into rbuf --*/
        while ( rc_ptr <= pr->num_blks ) {
           /*read_cdrom(ps, pr, loop, blkno, tbuf);*/
           if( ( read_res = read_cdrom(ps, pr, loop, blkno, tbuf) ) != 0 ) /* read un-succesfull ?*/
           		break;

           for ( i = 0; i <= pr->dlen; i++ )
               rbuf[(pr->dlen*rc_ptr)+i] = tbuf[i];
           set_blkno(blkno, pr->direction, pr->increment, 1);
           rc_ptr++;
        }
        if( read_res == 0 ) {/* only if all reads are successful ... */
			pr->dlen = save_dlen;
			cmpbuf(ps, pr, loop, blkno_save, wbuf, rbuf);
		} else { /* read fail */
			 sprintf(msg, "read_cdrom() failed in Read sequence of RC oper\n"
						  "Skipping compare operation\n");
			 prt_msg(ps, pr, loop, blkno, 0, SOFT, msg);
		}

    } else if ( strcmp(pr->oper, "D") == 0 ) {
        diag_cdrom(ps, pr, loop, blkno);
    } else if ( strcmp(pr->oper, "A") == 0 ) {
      #ifndef __HTX_LINUX__
        audio_cdrom(ps, pr, loop, blkno);
      #endif
    } else if ( strcmp(pr->oper, "AMM") == 0 ) {
		if ( (0 != strncmp(device_subclass, "sata", 16)) && (0 != strncmp(device_subclass, "usbif", 16)) ) {
			/* PLAYUDIO MSF is not supported for SATA drives */
        	audio_mm(ps, pr, loop, blkno);
		}
		else {
			sprintf(msg, "Skipping AMM stanza for SATA/USB drive, rule_id = %s\n", pr->rule_id);
       		hxfmsg(ps, 0, INFO, msg);
		}
    } else if ( strcmp(pr->oper, "RS") == 0 ) {
        prt_req_sense(ps, pr, loop, blkno);
    } else if ( strcmp(pr->oper, "S") == 0 ) {
        do_sleep(ps, pr, loop, blkno);
    } else if ( strcmp(pr->oper, "XCMD") == 0 ) {
        rc = do_cmd(ps, pr);
    } else {
        ;
    }

    hxfupdate(UPDATE, ps);
    if ( ps->run_type[0] == 'O' ) {
       info_msg(ps, pr, loop, blkno, msg);
       hxfmsg(ps, 0, INFO, msg);
    }
    if ( strcmp(pr->type_length, "RANDOM") == 0 && /* set lgth of data trans */
         strcmp(pr->addr_type, "RANDOM") == 0 )    /* if random is specified */
       pr->dlen = random_dlen(pr->bytpsec, pr->tot_blks, seed);
    if ( strcmp(pr->addr_type, "RANDOM") == 0 ) /* set block # for next oper */
       random_blkno(blkno, pr->dlen, pr->bytpsec, pr->max_blkno, seed,
                    pr->min_blkno);
    else if ( (strcmp(pr->oper, "RC") != 0 ) /* set blkno if not RC or RWP */
		      && ( strcmp(pr->oper, "RWP") != 0 ))
       set_blkno(blkno, pr->direction, pr->increment, pr->num_blks);
    if ( strcmp(pr->addr_type, "SEQ") == 0 ) {
       rc = wrap(pr, blkno);
       if ( rc == 1 )
          init_blkno(pr,blkno);
    }
  }
  free(tbuf_malloc);
  return(0);
}