/* || Retrieve and validate a standard label */ int get_sl( SLLABEL *lab ) { int rc; /* || Read a block */ if ( opts.faketape ) rc = fet_read( opts.fetb, blkptr ); else rc = het_read( opts.hetb, blkptr ); if( rc >= 0 ) { /* || Does is look like a standard label? */ if( sl_islabel( lab, blkptr, rc ) == TRUE ) { return( 0 ); } } else { if ( opts.faketape ) WRMSG( HHC00075, "E", "fet_read()", fet_error( rc ) ); else WRMSG( HHC00075, "E", "het_read()", het_error( rc ) ); } return( -1 ); }
/* || Retrieves a block from the tape file and resets variables */ int getblock( ) { int rc; /* || Read a block from the tape */ if ( opts.faketape ) rc = fet_read( opts.fetb, blkptr ); else rc = het_read( opts.hetb, blkptr ); if( rc < 0 ) { return( rc ); } /* || Save the block length, and use BDW for RECFM=V to protect against minimum block sizes (which avoid tape noise). */ blklen = rc; if( (blklen > 4) && (opts.recfm & O_VARIABLE) ) { int bdw; bdw = bdw_length( blkptr ); if ( (bdw > 4) && (bdw < blklen) ) { blklen = bdw; } } rc = blklen; return( rc ); }
/* || Retrieves a block from the tape file and resets variables */ int getblock( ) { int rc; /* || Read a block from the tape */ if ( opts.faketape ) rc = fet_read( opts.fetb, blkptr ); else rc = het_read( opts.hetb, blkptr ); if( rc < 0 ) { return( rc ); } /* || Save the block length (should we use BDW for RECFM=V files???) */ blklen = rc; return( rc ); }
/* || Standard main */ int main( int argc, char *argv[] ) { HETB *hetb; FETB *fetb; char *i_filename; int i_faketape = FALSE; SInt32 rc; SInt32 fileno; SInt32 i; U32 uminsz; U32 umaxsz; U32 ubytes; U32 cminsz; U32 cmaxsz; U32 cbytes; U32 totblocks; U64 totubytes; U64 totcbytes; U32 opts = 0; SInt32 lResidue = max_bytes_dsply; /* amount of space left to print */ char *pgm; INITIALIZE_UTILITY( UTILITY_NAME, "Hercules AWS, HET and FakeTape tape map program", &pgm ); #define O_ALL 0xC0 #define O_FILES 0X80 #define O_LABELS 0X40 #define O_DATASETS 0X20 #define O_TAPEMAP_OUTPUT 0x10 #define O_TAPEMAP_INVOKED 0x08 #define O_SLANAL_OUT 0x04 if (! (opts & O_TAPEMAP_INVOKED) ) { opts = O_ALL; while( TRUE ) { rc = getopt( argc, argv, "ab:dfhlst" ); if( rc == -1 ) break; switch( rc ) { case 'a': opts = O_ALL; break; case 'b': max_bytes_dsply = atoi( optarg ); if ( max_bytes_dsply < 256 ) max_bytes_dsply = 256; else { int i; i = max_bytes_dsply % 4; max_bytes_dsply += (4-i); } opts = O_SLANAL_OUT; break; case 'd': opts = O_DATASETS; break; case 'f': opts = O_FILES; break; case 'h': Print_Usage( pgm ); return 1; case 'l': opts = O_LABELS; break; case 's': opts = O_SLANAL_OUT; break; case 't': opts = O_TAPEMAP_OUTPUT; break; default: Print_Usage( pgm ); return 1; } } } // end if (! (opts & O_TAPEMAP_INVOKED) ) argc -= optind; if( argc != 1 ) { Print_Usage( pgm ); exit( 1 ); } if( opts & O_ALL ) { printf( "%s", sep ); printf( "%-20.20s: %s\n", "Filename", argv[ optind ] ); } i_filename = argv[ optind ]; if ( ( rc = (int)strlen( i_filename ) ) > 4 && ( rc = strcasecmp( &i_filename[rc-4], ".fkt" ) ) == 0 ) { i_faketape = TRUE; } if ( i_faketape ) rc = fet_open( &fetb, i_filename, FETOPEN_READONLY ); else rc = het_open( &hetb, i_filename, HETOPEN_READONLY ); if( rc < 0 ) { if ( i_faketape ) { printf( "fet_open() returned %d\n", (int)rc ); fet_close( &fetb ); } else { printf( "het_open() returned %d\n", (int)rc ); het_close( &hetb ); } exit( 1 ); } BLANK_OUT ( gStdLblBuffer, sizeof ( gStdLblBuffer ) ); fileno = 0; gBlkCount = 0; uminsz = 0; umaxsz = 0; ubytes = 0; cminsz = 0; cmaxsz = 0; cbytes = 0; totblocks = 0; totubytes = 0; totcbytes = 0; while( TRUE ) { #ifdef EXTERNALGUI if( extgui ) { off_t curpos; /* Report progress every nnnK */ if ( i_faketape ) curpos = ftell( fetb->fh ); else curpos = ftell( hetb->fh ); if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) ) { prevpos = curpos; EXTGUIMSG( "IPOS=%"PRId64"\n", (U64)curpos ); } } #endif /*EXTERNALGUI*/ if ( i_faketape) { rc = fet_read( fetb, gBuffer ); } else rc = het_read( hetb, gBuffer ); if( rc == HETE_EOT ) // FETE and HETE enums are the same { if( opts & O_TAPEMAP_OUTPUT ) { printf ("End of tape.\n"); } break; } if( rc == HETE_TAPEMARK ) { fileno += 1; lResidue = max_bytes_dsply; if( opts & O_TAPEMAP_OUTPUT ) { printf ("File %d: Blocks=%d, block size min=%d, max=%d\n", (int)fileno, (int)gBlkCount, (int)uminsz, (int)umaxsz ); } if( opts & O_FILES ) { printf ( "%s", sep ); printf ( "%-20.20s: %d\n", "File #", (int)fileno ); printf ( "%-20.20s: %d\n", "Blocks", (int)gBlkCount ); printf ( "%-20.20s: %d\n", "Min Blocksize", (int)uminsz ); printf ( "%-20.20s: %d\n", "Max Blocksize", (int)umaxsz ); if ( !i_faketape ) { printf ( "%-20.20s: %d\n", "Uncompressed bytes", (int)ubytes ); printf ( "%-20.20s: %d\n", "Min Blocksize-Comp", (int)cminsz ); printf ( "%-20.20s: %d\n", "Max Blocksize-Comp", (int)cmaxsz ); printf ( "%-20.20s: %d\n", "Compressed bytes", (int)cbytes ); } } totblocks += gBlkCount; totubytes += ubytes; totcbytes += cbytes; gPrevBlkCnt = gBlkCount; gBlkCount = 0; uminsz = 0; umaxsz = 0; ubytes = 0; cminsz = 0; cmaxsz = 0; cbytes = 0; continue; } if( rc < 0 ) { if ( i_faketape ) printf ( "fet_read() returned %d\n", (int)rc ); else printf ( "het_read() returned %d\n", (int)rc ); break; } gBlkCount += 1; if ( !i_faketape ) { ubytes += hetb->ublksize; cbytes += hetb->cblksize; if( uminsz == 0 || hetb->ublksize < uminsz ) uminsz = hetb->ublksize; if( hetb->ublksize > umaxsz ) umaxsz = hetb->ublksize; if( cminsz == 0 || hetb->cblksize < cminsz ) cminsz = hetb->cblksize; if( hetb->cblksize > cmaxsz ) cmaxsz = hetb->cblksize; } if ( rc >= 80 ) { for (i=0; i < 80; i++) { gStdLblBuffer[i] = ebcdic_to_ascii[gBuffer[i]]; } gStdLblBuffer[i] = '\0'; } if( opts & O_LABELS ) { Print_Label( rc ); } if( opts & O_TAPEMAP_OUTPUT ) { Print_Label_Tapemap( rc ); } if( opts & O_DATASETS ) { Print_Dataset( rc, fileno ); } if( opts & O_SLANAL_OUT ) { gLength = rc; if ( gLength == 80 ) { if ( 0 || memcmp ( gStdLblBuffer, "HDR", 3 ) == 0 || memcmp ( gStdLblBuffer, "EOF", 3 ) == 0 || memcmp ( gStdLblBuffer, "VOL", 3 ) == 0 || memcmp ( gStdLblBuffer, "EOV", 3 ) == 0 || memcmp ( gStdLblBuffer, "UHL", 3 ) == 0 || memcmp ( gStdLblBuffer, "UTL", 3 ) == 0 ) { if ( !Print_Standard_Labels ( ) ) { if ( gBlkCount <= 10 && ( gBlkCount == 1 || ( gBlkCount > 1 && lResidue > bytes_per_line ) ) ) { gLenPrtd = ( gBlkCount == 1 ? ( gLength <= max_bytes_dsply ? gLength : max_bytes_dsply ) : ( gLength <= lResidue ? gLength : lResidue ) ); lResidue -= Print_Block_Data ( gLenPrtd ); } } } else { if ( gBlkCount <= 10 && ( gBlkCount == 1 || ( gBlkCount > 1 && lResidue > bytes_per_line ) ) ) { gLenPrtd = ( gBlkCount == 1 ? ( gLength <= max_bytes_dsply ? gLength : max_bytes_dsply ) : ( gLength <= lResidue ? gLength : lResidue ) ); lResidue -= Print_Block_Data ( gLenPrtd ); } } } else { if ( ( gBlkCount <= 10 ) && ( ( gBlkCount == 1 ) || ( ( gBlkCount > 1 ) && ( lResidue > bytes_per_line ) ) ) ) { gLenPrtd = ( gBlkCount == 1 ? ( gLength <= max_bytes_dsply ? gLength : max_bytes_dsply ) : ( gLength <= lResidue ? gLength : lResidue ) ); lResidue -= Print_Block_Data ( gLenPrtd ); } } } } if( opts & O_FILES ) { printf ( "%s", sep ); printf ( "%-20.20s:\n", "Summary" ); printf ( "%-20.20s: %d\n", "Files", (int)fileno ); printf ( "%-20.20s: %d\n", "Blocks", (int)totblocks ); if ( !i_faketape ) { printf ( "%-20.20s: %llu\n", "Uncompressed bytes", (unsigned long long)totubytes ); printf ( "%-20.20s: %llu\n", "Compressed bytes", (unsigned long long)totcbytes ); printf ( "%-20.20s: %llu\n", "Reduction", (unsigned long long)(totubytes - totcbytes) ); } } if ( i_faketape ) fet_close( &fetb ); else het_close( &hetb ); return 0; }
/* || Copy source to dest */ static int copytape( void ) { int rc; char buf[ HETMAX_BLOCKSIZE ]; while( TRUE ) { #ifdef EXTERNALGUI if( extgui ) { off_t curpos; /* Report progress every nnnK */ if ( i_faketape ) curpos = ftell( s_fetb->fd ); else curpos = ftell( s_hetb->fd ); if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) ) { prevpos = curpos; fprintf( stderr, "IPOS=%" I64_FMT "d\n", (U64)curpos ); } } #endif /*EXTERNALGUI*/ if ( i_faketape ) rc = fet_read( s_fetb, buf ); else rc = het_read( s_hetb, buf ); if( rc == HETE_EOT ) // FAKETAPE and HETTAPE share codes { rc = 0; break; } if( rc == HETE_TAPEMARK ) { if ( o_faketape ) rc = fet_tapemark( d_fetb ); else rc = het_tapemark( d_hetb ); if( rc < 0 ) { if ( o_faketape ) WRMSG( HHC00075, "E", "fet_tapemark()", fet_error( rc ) ); else WRMSG( HHC00075, "E", "het_tapemark()", het_error( rc ) ); break; } continue; } if( rc < 0 ) { if ( i_faketape ) WRMSG( HHC00075, "E", "fet_read()", fet_error( rc ) ); else WRMSG( HHC00075, "E", "het_read()", het_error( rc ) ); break; } if ( o_faketape ) rc = fet_write( d_fetb, buf, rc ); else rc = het_write( d_hetb, buf, rc ); if( rc < 0 ) { if ( o_faketape ) WRMSG( HHC00075, "E", "fet_write()", fet_error( rc ) ); else WRMSG( HHC00075, "E", "het_write()", het_error( rc ) ); break; } } return( rc ); }