/* || Close tapes and cleanup */ static void closetapes( int rc ) { het_close( &d_hetb ); het_close( &s_hetb ); if( dorename ) { if( rc >= 0 ) { rc = rename( o_dname, o_sname ); } else { rc = remove( o_dname ); } if( rc == -1 ) { printf( "Error renaming files - manual checks required\n"); } } return; }
/*-------------------------------------------------------------------*/ void close_het (DEVBLK *dev) { /* Close the HET file */ het_close (&dev->hetb); /* Reinitialize the DEV fields */ dev->fd = -1; strcpy (dev->filename, TAPE_UNLOADED); dev->blockid = 0; dev->fenced = 0; return; } /* end function close_het */
/* || Close tapes and cleanup */ static void closetapes( int rc ) { if ( d_hetb != NULL ) het_close( &d_hetb ); if ( s_hetb != NULL ) het_close( &s_hetb ); if ( d_fetb != NULL ) fet_close( &d_fetb ); if ( s_fetb != NULL ) fet_close( &s_fetb ); if( dorename ) { if( rc >= 0 ) { rc = remove( o_sname ); if ( rc < 0 ) { WRMSG( HHC02745, "I", o_sname ); } else { rc = rename( o_dname, o_sname ); if ( rc < 0 ) WRMSG( HHC02744, "I", o_dname, o_sname ); } } else { rc = remove( o_dname ); if ( rc < 0 ) WRMSG( HHC02745, "I", o_dname ); } } return; }
/*-------------------------------------------------------------------*/ void close_het (DEVBLK *dev) { /* BHE 03/04/2010: This was the statement?? */ /* if(dev->hetb->fd >= 0) */ /* Caught it after a warning message */ if(dev->fd >= 0) { WRMSG (HHC00201, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het"); } /* Close the HET file */ het_close (&dev->hetb); /* Reinitialize the DEV fields */ dev->fd = -1; dev->fh = NULL; strlcpy( dev->filename, TAPE_UNLOADED, sizeof(dev->filename) ); dev->blockid = 0; dev->fenced = 0; return; } /* end function close_het */
/* || 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; }
/*-------------------------------------------------------------------*/ int open_het (DEVBLK *dev, BYTE *unitstat,BYTE code) { int rc; /* Return code */ /* Check for no tape in drive */ if (!strcmp (dev->filename, TAPE_UNLOADED)) { build_senseX(TAPE_BSENSE_TAPEUNLOADED,dev,unitstat,code); return -1; } /* Open the HET file */ rc = het_open (&dev->hetb, dev->filename, dev->tdparms.logical_readonly ? HETOPEN_READONLY : HETOPEN_CREATE ); if (rc >= 0) { if(dev->hetb->writeprotect) { dev->readonly=1; } rc = het_cntl (dev->hetb, HETCNTL_SET | HETCNTL_COMPRESS, dev->tdparms.compress); if (rc >= 0) { rc = het_cntl (dev->hetb, HETCNTL_SET | HETCNTL_METHOD, dev->tdparms.method); if (rc >= 0) { rc = het_cntl (dev->hetb, HETCNTL_SET | HETCNTL_LEVEL, dev->tdparms.level); if (rc >= 0) { rc = het_cntl (dev->hetb, HETCNTL_SET | HETCNTL_CHUNKSIZE, dev->tdparms.chksize); } } } } /* Check for successful open */ if (rc < 0) { int save_errno = errno; het_close (&dev->hetb); errno = save_errno; logmsg (_("HHCTA401E %4.4X: Error opening %s: %s(%s)\n"), dev->devnum, dev->filename, het_error(rc), strerror(errno)); strcpy(dev->filename, TAPE_UNLOADED); build_senseX(TAPE_BSENSE_TAPELOADFAIL,dev,unitstat,code); return -1; } /* Indicate file opened */ dev->fd = 1; return 0; } /* end function open_het */
/* || Standard main() function */ int main( int argc, char *argv[] ) { char *pgmname; /* prog name in host format */ char *pgm; /* less any extension (.ext) */ char msgbuf[512]; /* message build work area */ int rc; SLLABEL lab; HETB *hetb; /* used for aws and het tapes*/ FETB *fetb; /* used for faketapes */ int o_iehinitt; int o_nl; int o_compress; int o_faketape; char *o_filename; char *o_owner; char *o_volser; char *strtok_str = NULL; /* Set program name */ if ( argc > 0 ) { if ( strlen(argv[0]) == 0 ) { pgmname = strdup( UTILITY_NAME ); } else { char path[MAX_PATH]; #if defined( _MSVC_ ) GetModuleFileName( NULL, path, MAX_PATH ); #else strncpy( path, argv[0], sizeof( path ) ); #endif pgmname = strdup(basename(path)); #if !defined( _MSVC_ ) strncpy( path, argv[0], sizeof(path) ); #endif } } else { pgmname = strdup( UTILITY_NAME ); } pgm = strtok_r( strdup(pgmname), ".", &strtok_str); INITIALIZE_UTILITY( pgmname ); /* Display the program identification message */ MSGBUF( msgbuf, MSG_C( HHC02499, "I", pgm, "HET IEHINITT " ) ); display_version (stderr, msgbuf+10, FALSE); hetb = NULL; fetb = NULL; o_filename = NULL; o_faketape = FALSE; o_iehinitt = TRUE; o_nl = FALSE; o_compress = TRUE; o_owner = NULL; o_volser = NULL; while( TRUE ) { rc = getopt( argc, argv, "dhin" ); if( rc == -1 ) { break; } switch( rc ) { case 'd': o_compress = FALSE; break; case 'h': usage( pgm ); goto exit; break; case 'i': o_iehinitt = TRUE; o_nl = FALSE; break; case 'n': o_iehinitt = FALSE; o_nl = TRUE; break; default: usage( pgm ); goto exit; break; } } argc -= optind; if( argc < 1 ) { usage( pgm ); goto exit; } o_filename = argv[ optind ]; if ( ( rc = (int)strlen( o_filename ) ) > 4 && ( rc = strcasecmp( &o_filename[rc-4], ".fkt" ) ) == 0 ) { o_faketape = TRUE; } if( o_iehinitt ) { if( argc == 2 ) { o_volser = argv[ optind + 1 ]; } else if( argc == 3 ) { o_volser = argv[ optind + 1 ]; o_owner = argv[ optind + 2 ]; } else { usage( pgm ); goto exit; } } if( o_nl ) { if( argc != 1 ) { usage( pgm ); goto exit; } } if( o_volser ) het_string_to_upper( o_volser ); if( o_owner ) het_string_to_upper( o_owner ); if ( o_faketape ) { rc = fet_open( &fetb, o_filename, FETOPEN_CREATE ); if ( rc < 0 ) { WRMSG( HHC00075, "E", "fet_open()", fet_error( rc ) ); goto exit; } } else { rc = het_open( &hetb, o_filename, HETOPEN_CREATE ); if( rc < 0 ) { WRMSG( HHC00075, "E", "het_open()", het_error( rc ) ); goto exit; } rc = het_cntl( hetb, HETCNTL_SET | HETCNTL_COMPRESS, o_compress ); if( rc < 0 ) { WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) ); goto exit; } } if( o_iehinitt ) { rc = sl_vol1( &lab, o_volser, o_owner ); if( rc < 0 ) { WRMSG( HHC00075, "E", "sl_vol1()", sl_error( rc ) ); goto exit; } if ( o_faketape ) rc = fet_write( fetb, &lab, (U16)sizeof( lab ) ); else rc = het_write( hetb, &lab, sizeof( lab ) ); if( rc < 0 ) { if ( o_faketape ) WRMSG( HHC00075, "E", "fet_write() for VOL1", fet_error( rc ) ); else WRMSG( HHC00075, "E", "het_write() for VOL1", het_error( rc ) ); goto exit; } rc = sl_hdr1( &lab, SL_INITDSN, NULL, 0, 0, NULL, 0 ); if( rc < 0 ) { WRMSG( HHC00075, "E", "sl_hdr1()", sl_error( rc ) ); goto exit; } if ( o_faketape ) rc = fet_write( fetb, &lab, (U16)sizeof(lab) ); else rc = het_write( hetb, &lab, sizeof( lab ) ); if( rc < 0 ) { if ( o_faketape ) WRMSG( HHC00075, "E", "fet_write() for HDR1", fet_error( rc ) ); else WRMSG( HHC00075, "E", "het_write() for HDR1", het_error( rc ) ); goto exit; } } else if( o_nl ) { if ( o_faketape ) rc = fet_tapemark( fetb ); else rc = het_tapemark( hetb ); if( rc < 0 ) { if ( o_faketape ) WRMSG( HHC00075, "E", "fet_tapemark()", fet_error( rc ) ); else WRMSG( HHC00075, "E", "het_tapemark()", het_error( rc ) ); goto exit; } } if ( o_faketape ) rc = fet_tapemark( fetb ); else rc = het_tapemark( hetb ); if( rc < 0 ) { if ( o_faketape ) WRMSG( HHC00075, "E", "fet_tapemark()", fet_error( rc ) ); else WRMSG( HHC00075, "E", "het_tapemark()", het_error( rc ) ); goto exit; } exit: if ( o_faketape) fet_close( &fetb ); else het_close( &hetb ); return( rc < 0 ); }
/* || Standard main */ int main( int argc, char *argv[] ) { char buf[ HETMAX_BLOCKSIZE ]; HETB *hetb; int rc; int fileno; U32 blocks; U32 uminsz; U32 umaxsz; U32 ubytes; U32 cminsz; U32 cmaxsz; U32 cbytes; U32 totblocks; U32 totubytes; U32 totcbytes; U32 opts = 0; char pgmpath[MAX_PATH]; char *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 /* Figure out processing based on the program name */ hostpath(pgmpath, argv[0], sizeof(pgmpath)); pgm = strrchr(pgmpath, '/'); if (pgm) { pgm++; } else { pgm = argv[0]; } strtok (pgm, "."); if ((strcmp(pgm, "tapemap") == 0) || (strcmp(pgm, "TAPEMAP") == 0)) { opts = O_TAPEMAP_OUTPUT+O_TAPEMAP_INVOKED; } INITIALIZE_UTILITY(pgm); /* Display the program identification message */ display_version (stderr, "Hercules HET and AWS tape map program ", FALSE); if (! (opts & O_TAPEMAP_INVOKED) ) { opts = O_ALL; while( TRUE ) { rc = getopt( argc, argv, "adfhlt" ); if( rc == -1 ) { break; } switch( rc ) { case 'a': opts = O_ALL; break; case 'd': opts = O_DATASETS; break; case 'f': opts = O_FILES; break; case 'h': usage( pgm ); exit( 1 ); break; case 'l': opts = O_LABELS; break; case 't': opts = O_TAPEMAP_OUTPUT; break; default: usage( pgm ); exit( 1 ); break; } } } // end if (! (opts & O_TAPEMAP_INVOKED) ) argc -= optind; if( argc != 1 ) { usage( pgm ); exit( 1 ); } if( opts & O_ALL ) { printf( sep ); printf( "%-20.20s: %s\n", "Filename", argv[ optind ] ); } rc = het_open( &hetb, argv[ optind ], 0 ); if( rc < 0 ) { printf( "het_open() returned %d\n", rc ); het_close( &hetb ); exit( 1 ); } fileno = 0; blocks = 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 ) { /* Report progress every nnnK */ off_t curpos = ftell( hetb->fd ); if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) ) { prevpos = curpos; fprintf( stderr, "IPOS=%" I64_FMT "d\n", (U64)curpos ); } } #endif /*EXTERNALGUI*/ rc = het_read( hetb, buf ); if( rc == HETE_EOT ) { if( opts & O_TAPEMAP_OUTPUT ) { printf ("End of tape.\n"); } break; } if( rc == HETE_TAPEMARK ) { fileno += 1; if( opts & O_TAPEMAP_OUTPUT ) { printf ("File %u: Blocks=%u, block size min=%u, max=%u\n", fileno, blocks, uminsz, umaxsz ); } if( opts & O_FILES ) { printf( sep ); printf( "%-20.20s: %d\n", "File #", fileno ); printf( "%-20.20s: %d\n", "Blocks", blocks ); printf( "%-20.20s: %d\n", "Min Blocksize", uminsz ); printf( "%-20.20s: %d\n", "Max Blocksize", umaxsz ); printf( "%-20.20s: %d\n", "Uncompressed bytes", ubytes ); printf( "%-20.20s: %d\n", "Min Blocksize-Comp", cminsz ); printf( "%-20.20s: %d\n", "Max Blocksize-Comp", cmaxsz ); printf( "%-20.20s: %d\n", "Compressed bytes", cbytes ); } totblocks += blocks; totubytes += ubytes; totcbytes += cbytes; blocks = 0; uminsz = 0; umaxsz = 0; ubytes = 0; cminsz = 0; cmaxsz = 0; cbytes = 0; continue; } if( rc < 0 ) { printf( "het_read() returned %d\n", rc ); break; } blocks += 1; 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( opts & O_LABELS ) { printlabel( buf, rc ); } if( opts & O_TAPEMAP_OUTPUT ) { printlabeltapemap( buf, rc ); } if( opts & O_DATASETS ) { printdataset( buf, rc, fileno ); } } if( opts & O_FILES ) { printf( sep ); printf( "%-20.20s:\n", "Summary" ); printf( "%-20.20s: %d\n", "Files", fileno ); printf( "%-20.20s: %d\n", "Blocks", totblocks ); printf( "%-20.20s: %d\n", "Uncompressed bytes", totubytes ); printf( "%-20.20s: %d\n", "Compressed bytes", totcbytes ); printf( "%-20.20s: %d\n", "Reduction", totubytes - totcbytes ); } het_close( &hetb ); return 0; }
/* || Open HET tapes and set options */ static int opentapes( void ) { int rc; rc = het_open( &s_hetb, o_sname, 0 ); if( rc < 0 ) { goto exit; } rc = het_open( &d_hetb, o_dname, HETOPEN_CREATE ); if( rc < 0 ) { goto exit; } rc = het_cntl( s_hetb, HETCNTL_SET | HETCNTL_DECOMPRESS, o_decompress ); if( rc < 0 ) { goto exit; } rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_COMPRESS, o_compress ); if( rc < 0 ) { goto exit; } rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_METHOD, o_method ); if( rc < 0 ) { goto exit; } rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_LEVEL, o_level ); if( rc < 0 ) { goto exit; } rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_CHUNKSIZE, o_chunksize ); if( rc < 0 ) { goto exit; } if( o_verbose ) { printf( "Source : %s\n", o_sname ); printf( "Destination : %s\n", o_dname ); printf( "Decompress source : %s\n", yesno( het_cntl( s_hetb, HETCNTL_DECOMPRESS, 0 ) ) ); printf( "Compress dest : %s\n", yesno( het_cntl( d_hetb, HETCNTL_COMPRESS, 0 ) ) ); printf( "Compression method : %d\n", het_cntl( d_hetb, HETCNTL_METHOD, 0 ) ); printf( "Compression level : %d\n", het_cntl( d_hetb, HETCNTL_LEVEL, 0 ) ); } exit: if( rc < 0 ) { het_close( &d_hetb ); het_close( &s_hetb ); } return( rc ); }
/* || Standard main */ int main( int argc, char *argv[] ) { char *pgmname; /* prog name in host format */ char *pgm; /* less any extension (.ext) */ char msgbuf[512]; /* message build work area */ FILE *outf; int rc; int i; char pathname[MAX_PATH]; char *strtok_str = NULL; /* Set program name */ if ( argc > 0 ) { if ( strlen(argv[0]) == 0 ) { pgmname = strdup( UTILITY_NAME ); } else { char path[MAX_PATH]; #if defined( _MSVC_ ) GetModuleFileName( NULL, path, MAX_PATH ); #else strncpy( path, argv[0], sizeof( path ) ); #endif pgmname = strdup(basename(path)); #if !defined( _MSVC_ ) strncpy( path, argv[0], sizeof(path) ); #endif } } else { pgmname = strdup( UTILITY_NAME ); } pgm = strtok_r( strdup(pgmname), ".", &strtok_str); INITIALIZE_UTILITY( pgmname ); /* Display the program identification message */ MSGBUF( msgbuf, MSG_C( HHC02499, "I", pgm, "Extract Files from AWS, HET or FAKETAPE" ) ); display_version (stderr, msgbuf+10, FALSE); /* || Process option switches */ while( TRUE ) { rc = getopt( argc, argv, "abhnsu" ); if( rc == -1 ) { break; } switch( rc ) { case 'a': opts.flags |= O_ASCII; set_codepage(NULL); break; case 'h': usage( pgm ); exit( 1 ); break; case 'n': opts.flags |= O_NL; break; case 's': opts.flags |= O_STRIP; break; case 'u': opts.flags |= O_UNBLOCK; break; default: usage( pgm ); exit( 1 ); break; } } /* || Calc number of non-switch arguments */ argc -= optind; /* || We must have at least the first 3 parms */ if(argc < 3) { if ( argc > 1 ) WRMSG( HHC02446, "E" ); usage( pgm ); exit( 1 ); } hostpath( pathname, argv[ optind ], sizeof(pathname) ); opts.ifile = strdup( pathname ); if ( ( rc = (int)strlen( opts.ifile ) ) > 4 && ( rc = strcasecmp( &opts.ifile[rc-4], ".fkt" ) ) == 0 ) { opts.faketape = TRUE; } hostpath( pathname, argv[ optind + 1 ], sizeof(pathname) ); opts.ofile = strdup( pathname ); opts.fileno = atoi( argv[ optind + 2 ] ); if( opts.fileno == 0 || opts.fileno > 9999 ) { char msgbuf[20]; MSGBUF( msgbuf, "%d", opts.fileno ); WRMSG( HHC02205, "E", msgbuf, "; file number must be within the range of 1 to 9999" ); exit( 1 ); } /* || If NL tape, then we require the DCB attributes */ if( opts.flags & O_NL ) { if( argc != 6 ) { WRMSG( HHC02750, "E" ); exit( 1 ); } } /* || If specified, get the DCB attributes */ if( argc > 3 ) { /* || Must have only three */ if( argc != 6 ) { usage( pgm ); exit( 1 ); } /* || Lookup the specified RECFM in our table */ opts.recfm = 0; for( i = 0 ; i < (int)VALFMCNT ; i++ ) { if( strcasecmp( argv[ optind + 3 ], valfm[ i ].recfm ) == 0 ) { opts.recfm = valfm[ i ].fmt; break; } } /* || If we didn't find a match, show the user what the valid ones are */ if( opts.recfm == 0) { char msgbuf[512] = ""; char msgbuf2[64] = ""; char msgbuf3[16] = ""; char msgbuf4[128] = ""; /* || Dump out the valid RECFMs */ MSGBUF( msgbuf, MSG( HHC02751, "I" ) ); for( i = 0 ; i < (int)VALFMCNT ; i++ ) { MSGBUF( msgbuf3, " %-4.4s", valfm[ i ].recfm ); if( ( ( i + 1 ) % 3 ) == 0 ) { strcat( msgbuf2, msgbuf3 ); MSGBUF( msgbuf4, MSG( HHC02752, "I", msgbuf2 ) ); strcat( msgbuf, msgbuf4 ); msgbuf2[0] = 0; } else { strcat( msgbuf2, msgbuf3 ); } } printf( "%s", msgbuf ); exit( 1 ); } /* || Get the record length */ opts.lrecl = atoi( argv[ optind + 4 ] ); /* || Get and validate the blksize */ opts.blksize = atoi( argv[ optind + 5 ] ); if( opts.blksize == 0 ) { WRMSG( HHC02205, "E", "0", "; block size can't be zero" ); exit( 1 ); } } /* || Open the tape file */ if ( opts.faketape ) rc = fet_open( &opts.fetb, opts.ifile, FETOPEN_READONLY ); else rc = het_open( &opts.hetb, opts.ifile, HETOPEN_READONLY ); if( rc >= 0 ) { /* || Get memory for the tape buffer */ blkptr = malloc( HETMAX_BLOCKSIZE ); if( blkptr != NULL ) { /* || Open the output file */ outf = fopen( opts.ofile, "wb" ); if( outf != NULL ) { /* || Go extract the file from the tape */ rc = getfile( outf ); /* || Close the output file */ fclose( outf ); } /* || Free the buffer memory */ free( blkptr ); } } else { if ( opts.faketape ) WRMSG( HHC00075, "E", "fet_open()", fet_error( rc ) ); else WRMSG( HHC00075, "E", "het_open()", het_error( rc ) ); } /* || Close the tape file */ if ( opts.faketape ) fet_close( &opts.fetb ); else het_close( &opts.hetb ); return 0; }
/* || Standard main */ int main( int argc, char *argv[] ) { HETB *hetb; FILE *outf; int rc; int i; INITIALIZE_UTILITY("hetget"); /* Display the program identification message */ display_version (stderr, "Hercules HET extract files program ", FALSE); /* || Process option switches */ while( TRUE ) { rc = getopt( argc, argv, "abhnsu" ); if( rc == -1 ) { break; } switch( rc ) { case 'a': opts.flags |= O_ASCII; break; case 'h': usage( argv[ 0 ] ); exit( 1 ); break; case 'n': opts.flags |= O_NL; break; case 's': opts.flags |= O_STRIP; break; case 'u': opts.flags |= O_UNBLOCK; break; default: usage( argv[ 0 ] ); exit( 1 ); break; } } /* || Calc number of non-switch arguments */ argc -= optind; /* || We must have at least the first 3 parms */ if( argc < 3 ) { printf( "Must specify input tape, output file, and file #\n" ); printf( "Use -h option for more help\n" ); exit( 1 ); } opts.ifile = argv[ optind ]; opts.ofile = argv[ optind + 1 ]; opts.fileno = atoi( argv[ optind + 2 ] ); if( opts.fileno == 0 || opts.fileno > 9999 ) { printf( "File number must be within 1-9999\n" ); exit( 1 ); } /* || If NL tape, then we require the DCB attributes */ if( opts.flags & O_NL ) { if( argc != 6 ) { printf( "DCB attributes required for NL tapes\n" ); exit( 1 ); } } /* || If specified, get the DCB attributes */ if( argc > 3 ) { /* || Must have only three */ if( argc != 6 ) { usage( argv[ 0 ] ); exit( 1 ); } /* || Lookup the specified RECFM in our table */ opts.recfm = 0; for( i = 0 ; i < (int)VALFMCNT ; i++ ) { if( strcasecmp( argv[ optind + 3 ], valfm[ i ].recfm ) == 0 ) { opts.recfm = valfm[ i ].fmt; break; } } /* || If we didn't find a match, show the user what the valid ones are */ if( opts.recfm == 0) { /* || Dump out the valid RECFMs */ printf( "Valid record formats are:\n" ); for( i = 0 ; i < (int)VALFMCNT ; i++ ) { printf( " %-4.4s", valfm[ i ].recfm ); if( ( ( i + 1 ) % 3 ) == 0 ) { printf( "\n" ); } } exit( 1 ); } /* || Get the record length */ opts.lrecl = atoi( argv[ optind + 4 ] ); /* || Get and validate the blksize */ opts.blksize = atoi( argv[ optind + 5 ] ); if( opts.blksize == 0 ) { printf( "Block size can't be zero\n" ); exit( 1 ); } } /* || Open the tape file */ rc = het_open( &hetb, opts.ifile, 0 ); if( rc >= 0 ) { /* || Get memory for the tape buffer */ blkptr = malloc( HETMAX_BLOCKSIZE ); if( blkptr != NULL ) { /* || Open the output file */ char pathname[MAX_PATH]; hostpath(pathname, opts.ofile, sizeof(pathname)); outf = fopen( pathname, "wb" ); if( outf != NULL ) { /* || Go extract the file from the tape */ rc = getfile( hetb, outf ); /* || Close the output file */ fclose( outf ); } /* || Free the buffer memory */ free( blkptr ); } } else { printf( "het_open() returned %s\n", het_error( rc ) ); } /* || Close the tape file */ het_close( &hetb ); return 0; }
/* || Standard main */ int main( int argc, char *argv[] ) { char *pgm; /* less any extension (.ext) */ FILE *outf; int rc; int i; char pathname[MAX_PATH]; INITIALIZE_UTILITY( UTILITY_NAME, "Extract Files from AWS, HET or FAKETAPE", &pgm ); /* || Process option switches */ while( TRUE ) { rc = getopt( argc, argv, "abhnsu" ); if( rc == -1 ) { break; } switch( rc ) { case 'a': opts.flags |= O_ASCII; set_codepage(NULL); break; case 'h': usage( pgm ); exit( 1 ); UNREACHABLE_CODE(); case 'n': opts.flags |= O_NL; break; case 's': opts.flags |= O_STRIP; break; case 'u': opts.flags |= O_UNBLOCK; break; default: usage( pgm ); exit( 1 ); UNREACHABLE_CODE(); } } /* || Calc number of non-switch arguments */ argc -= optind; /* || We must have at least the first 3 parms */ if(argc < 3) { if ( argc > 1 ) // "Invalid number of arguments" FWRMSG( stderr, HHC02446, "E" ); usage( pgm ); exit( 1 ); } hostpath( pathname, argv[ optind ], sizeof(pathname) ); opts.ifile = strdup( pathname ); if ( ( rc = (int)strlen( opts.ifile ) ) > 4 && ( rc = strcasecmp( &opts.ifile[rc-4], ".fkt" ) ) == 0 ) { opts.faketape = TRUE; } hostpath( pathname, argv[ optind + 1 ], sizeof(pathname) ); opts.ofile = strdup( pathname ); opts.fileno = atoi( argv[ optind + 2 ] ); if( opts.fileno == 0 || opts.fileno > 9999 ) { char msgbuf[20]; MSGBUF( msgbuf, "%d", opts.fileno ); // "Invalid argument %s%s" FWRMSG( stderr, HHC02205, "S", msgbuf, "; file number must be within the range of 1 to 9999" ); exit( 1 ); } /* || If NL tape, then we require the DCB attributes */ if( opts.flags & O_NL ) { if( argc != 6 ) { // "DCB attributes required for NL tape" FWRMSG( stderr, HHC02750, "S" ); exit( 1 ); } } /* || If specified, get the DCB attributes */ if( argc > 3 ) { /* || Must have only three */ if( argc != 6 ) { usage( pgm ); exit( 1 ); } /* || Lookup the specified RECFM in our table */ opts.recfm = 0; for( i = 0 ; i < (int)VALFMCNT ; i++ ) { if( strcasecmp( argv[ optind + 3 ], valfm[ i ].recfm ) == 0 ) { opts.recfm = valfm[ i ].fmt; break; } } /* || If we didn't find a match, show the user what the valid ones are */ if( opts.recfm == 0) { char msgbuf[512] = ""; char msgbuf2[64] = ""; char msgbuf3[16] = ""; char msgbuf4[128] = ""; /* || Dump out the valid RECFMs */ // "Valid record formats are:" MSGBUF( msgbuf, MSG( HHC02751, "I" ) ); for( i = 0 ; i < (int)VALFMCNT ; i++ ) { MSGBUF( msgbuf3, " %-4.4s", valfm[ i ].recfm ); if( ( ( i + 1 ) % 3 ) == 0 ) { strlcat( msgbuf2, msgbuf3, sizeof(msgbuf2) ); // "%s" MSGBUF( msgbuf4, MSG( HHC02752, "I", msgbuf2 ) ); strlcat( msgbuf, msgbuf4, sizeof(msgbuf) ); msgbuf2[0] = 0; } else { strlcat( msgbuf2, msgbuf3, sizeof(msgbuf2) ); } } printf( "%s", msgbuf ); exit( 1 ); } /* || Get the record length */ opts.lrecl = atoi( argv[ optind + 4 ] ); /* || Get and validate the blksize */ opts.blksize = atoi( argv[ optind + 5 ] ); if( opts.blksize == 0 ) { // "Invalid argument %s%s" FWRMSG( stderr, HHC02205, "S", "0", "; block size can't be zero" ); exit( 1 ); } } /* || Open the tape file */ if ( opts.faketape ) rc = fet_open( &opts.fetb, opts.ifile, FETOPEN_READONLY ); else rc = het_open( &opts.hetb, opts.ifile, HETOPEN_READONLY ); if( rc >= 0 ) { /* || Get memory for the tape buffer */ blkptr = malloc( HETMAX_BLOCKSIZE ); if( blkptr != NULL ) { /* || Open the output file */ outf = fopen( opts.ofile, "wb" ); if( outf != NULL ) { /* || Go extract the file from the tape */ rc = getfile( outf ); /* || Close the output file */ fclose( outf ); } /* || Free the buffer memory */ free( blkptr ); } } else { // "Error in function %s: %s" if ( opts.faketape ) FWRMSG( stderr, HHC00075, "E", "fet_open()", fet_error( rc ) ); else FWRMSG( stderr, HHC00075, "E", "het_open()", het_error( rc ) ); } /* || Close the tape file */ if ( opts.faketape ) fet_close( &opts.fetb ); else het_close( &opts.hetb ); return 0; }
/*-------------------------------------------------------------------*/ int open_het (DEVBLK *dev, BYTE *unitstat,BYTE code) { int rc; /* Return code */ char pathname[MAX_PATH]; /* file path in host format */ /* Check for no tape in drive */ if (!strcmp (dev->filename, TAPE_UNLOADED)) { build_senseX(TAPE_BSENSE_TAPEUNLOADED,dev,unitstat,code); return -1; } /* Open the HET file */ hostpath(pathname, dev->filename, sizeof(pathname)); rc = het_open (&dev->hetb, pathname, dev->tdparms.logical_readonly ? HETOPEN_READONLY : sysblk.noautoinit ? 0 : HETOPEN_CREATE ); if (rc >= 0) { /* Keep file descriptor and handle synchronized */ dev->fd = dev->hetb->fd; dev->fh = dev->hetb->fh; if(dev->hetb->writeprotect) { dev->readonly=1; } rc = het_cntl (dev->hetb, HETCNTL_SET | HETCNTL_COMPRESS, dev->tdparms.compress); if (rc >= 0) { rc = het_cntl (dev->hetb, HETCNTL_SET | HETCNTL_METHOD, dev->tdparms.method); if (rc >= 0) { rc = het_cntl (dev->hetb, HETCNTL_SET | HETCNTL_LEVEL, dev->tdparms.level); if (rc >= 0) { rc = het_cntl (dev->hetb, HETCNTL_SET | HETCNTL_CHUNKSIZE, dev->tdparms.chksize); } } } } /* Check for successful open */ if (rc < 0) { int save_errno = errno; het_close (&dev->hetb); dev->fd = -1; dev->fh = NULL; errno = save_errno; { char msgbuf[128]; MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno)); WRMSG( HHC00205, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_open()", msgbuf ); } strlcpy( dev->filename, TAPE_UNLOADED, sizeof(dev->filename) );; build_senseX(TAPE_BSENSE_TAPELOADFAIL,dev,unitstat,code); return -1; } if ( !sysblk.noautoinit && dev->hetb->created ) { WRMSG( HHC00235, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het" ); } return 0; } /* end function open_het */