/* || List files in the tape "archive" (ie think "unzip -v") Only works on SL tapes. */ int listfiles( ) { SLFMT fmt; SLLABEL lab; int rc; /* || First block should be a VOL1 record */ rc = get_sl( &lab ); if( rc < 0 || !sl_isvol( &lab, 1 ) ) { logmsg( "Expected VOL1 label\n" ); return( -1 ); } /* process all files on tape */ while (rc >= 0) { /* || Get the HDR1 label. */ rc = get_sl( &lab ); if( rc < 0 || !sl_ishdr( &lab, 1 ) ) { /* quietly return when no more files */ return( 0 ); } /* || Make the label more managable */ sl_fmtlab( &fmt, &lab ); logmsg("%-17.17s", fmt.slds1.dsid ); /* || Get the HDR2 label. */ rc = get_sl( &lab ); if( rc < 0 || !sl_ishdr( &lab, 2 ) ) { logmsg( "Expected HDR2 label\n" ); return( -1 ); } /* || Merge the DCB information */ merge( &lab, 1 ); /* || Hop over the tapemark */ if ( opts.faketape ) rc = fet_fsf( opts.fetb ); else rc = het_fsf( opts.hetb ); if( rc < 0 ) { logmsg( "%s while spacing to start of data\n", het_error( rc ) ); return( rc ); } /* || skip data file, if any */ if ( opts.faketape ) rc = fet_fsf( opts.fetb ); else rc = het_fsf( opts.hetb ); if( rc < 0 ) { return( 0 ); } /* || skip EOF file, if any */ if ( opts.faketape ) rc = fet_fsf( opts.fetb ); else rc = het_fsf( opts.hetb ); if( rc < 0 ) { return( 0 ); } } /* while */ return (0); }
/* || Extract files from the tape "archive" (ie think "unzip") Only works on SL tapes. */ int extractfiles( ) { SLFMT fmt; SLLABEL lab; unsigned char *ptr; int rc; FILE *outf; /* || First block should be a VOL1 record */ rc = get_sl( &lab ); if( rc < 0 || !sl_isvol( &lab, 1 ) ) { logmsg( "Expected VOL1 label\n" ); return( -1 ); } /* process all files on tape */ while (rc >= 0) { /* || Get the HDR1 label. */ rc = get_sl( &lab ); if( rc < 0 || !sl_ishdr( &lab, 1 ) ) { /* quietly return when no more files */ return( 0 ); } /* || Make the label more managable */ sl_fmtlab( &fmt, &lab ); logmsg("%-17.17s", fmt.slds1.dsid ); /* || Get the HDR2 label. */ rc = get_sl( &lab ); if( rc < 0 || !sl_ishdr( &lab, 2 ) ) { logmsg( "Expected HDR2 label\n" ); return( -1 ); } /* || Merge the DCB information */ merge( &lab, 1 ); /* || Hop over the tapemark */ if ( opts.faketape ) rc = fet_fsf( opts.fetb ); else rc = het_fsf( opts.hetb ); if( rc < 0 ) { logmsg( "%s while spacing to start of data\n", het_error( rc ) ); return( rc ); } /* || process the current file */ { /* || Open the output file */ char pathname[MAX_PATH]; opts.ofile = fmt.slds1.dsid; hostpath(pathname, opts.ofile, sizeof(pathname)); outf = fopen( pathname, (opts.flags & O_ASCII) ? "w" : "wb" ); if( outf == NULL ) { logmsg("unable to open %s\n", opts.ofile); return( -1 ); } } /* this should be in a common block, or at least indented */ /* || Different processing when converting to ASCII */ if( opts.flags & ( O_ASCII | O_UNBLOCK | O_RDW ) ) { /* || Get a record */ while( ( rc = getrecord( ) ) >= 0 ) { #ifdef EXTERNALGUI if( extgui ) { off_t curpos; /* Report progress every nnnK */ if ( opts.faketape ) curpos = ftell( opts.fetb->fd ); else curpos = ftell( opts.hetb->fd ); if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) ) { prevpos = curpos; fprintf( stderr, "IPOS=%" I64_FMT "d\n", (U64)curpos ); } } #endif /*EXTERNALGUI*/ /* || Get working copy of record ptr */ ptr = recptr; /* || Only want data portion for RECFM=V records */ if( opts.recfm & O_VARIABLE ) { ptr += 4; rc -= 4; } /* || Convert record to ASCII */ if( opts.flags & O_ASCII ) { sl_etoa( NULL, ptr, rc ); } /* || Strip trailing blanks */ if( opts.flags & O_STRIP || ((opts.flags & O_HRCTXT) && (opts.recfm & O_FIXED) ) ) { while( rc > 0 && ptr[ rc - 1 ] == ' ' ) { rc--; } /* if a text file has been copied, in binary mode, into a fixed dataset, it will have NUL-padding. Since we don't want NULs in a text file, we clean them up too */ if (opts.recfm & O_FIXED) { while( rc > 0 && ptr[ rc - 1 ] == '\0' ) { rc--; } } } /* || Write the record out */ if ( (opts.flags & O_ASCII) && rc == 1 && ptr[0] == ' ' && !(opts.flags & O_RDW) && ( ((opts.recfm & O_UNDEFINED) && !(opts.flags & O_NO_NEW) ) || (opts.recfm & O_VARIABLE) ) ) { /* if the dataset is undefined or variable and has a single space, then don't write out that space, because the space most likely exists because it was artificially inserted to prevent empty records or blocks rather than because the user really wants a space. Also, if they are taking care of newlines themselves for RECFM=U, then any single space in the last block would be genuine albeit extremely unlikely. */ rc = 0; } /* write out an artificial RDW */ if ((opts.flags & O_RDW) || ((opts.flags & O_HRCBIN) && (opts.recfm & O_VARIABLE) ) ) { int havenl = 0; /* take into account newline */ if( opts.flags & O_ASCII && (!(opts.flags & O_NO_NEW) || !(opts.recfm & O_UNDEFINED) ) ) { havenl = 1; rc++; } rc += 4; fputc( (((unsigned int)rc >> 8) & 0xff), outf ); fputc( ((unsigned int)rc & 0xff), outf ); fputc( 0x00, outf ); fputc( 0x00, outf ); rc -= 4; if (havenl) { rc--; } } fwrite( ptr, rc, 1, outf ); /* || Put out a linefeed when converting */ if( opts.flags & O_ASCII && (!(opts.flags & O_NO_NEW) || !(opts.recfm & O_UNDEFINED) ) ) { fwrite( "\n", 1, 1, outf ); } } } else { /* || Get a record */ while( ( rc = getblock( ) ) >= 0 )
/* || Extract the file from the tape */ int getfile( FILE *outf ) { SLFMT fmt; SLLABEL lab; unsigned char *ptr; int fileno; int rc; /* || Skip to the desired file */ if( opts.flags & O_NL ) { /* || For NL tapes, just use the specified file number */ fileno = opts.fileno; /* || Start skipping */ while( --fileno ) { /* || Forward space to beginning of next file */ if ( opts.faketape ) rc = fet_fsf ( opts.fetb ); else rc = het_fsf( opts.hetb ); if( rc < 0 ) { char msgbuf[128]; MSGBUF( msgbuf, "%set_fsf() while positioning to file '%d'", opts.faketape ? "f" : "h", opts.fileno ); WRMSG( HHC00075, "E", msgbuf, het_error( rc ) ); return( rc ); } } } else { /* || First block should be a VOL1 record */ rc = get_sl( &lab ); if( rc < 0 || !sl_isvol( &lab, 1 ) ) { WRMSG( HHC02753, "E", "VOL1" ); return( -1 ); } /* || For SL, adjust the file # so we end up on the label before the data */ fileno = ( opts.fileno * 3 ) - 2; /* || Start skipping */ while( --fileno ) { /* || Forward space to beginning of next file */ if ( opts.faketape ) rc = fet_fsf ( opts.fetb ); else rc = het_fsf( opts.hetb ); if( rc < 0 ) { char msgbuf[128]; MSGBUF( msgbuf, "%set_fsf() while positioning to file '%d'", opts.faketape ? "f" : "h", opts.fileno ); WRMSG( HHC00075, "E", msgbuf, het_error( rc ) ); return( rc ); } } /* || Get the HDR1 label. */ rc = get_sl( &lab ); if( rc < 0 || !sl_ishdr( &lab, 1 ) ) { WRMSG( HHC02753, "E", "HDR1" ); return( -1 ); } /* || Make the label more managable */ sl_fmtlab( &fmt, &lab ); WRMSG( HHC02754, "E", fmt.slds1.dsid ); /* || Get the HDR2 label. */ rc = get_sl( &lab ); if( rc < 0 || !sl_ishdr( &lab, 2 ) ) { WRMSG( HHC02753, "E", "HDR2" ); return( -1 ); } /* || Merge the DCB information */ merge( &lab ); /* || Hop over the tapemark */ if ( opts.faketape ) rc = fet_fsf( opts.fetb ); else rc = het_fsf( opts.hetb ); if( rc < 0 ) { if ( opts.faketape ) WRMSG( HHC00075, "E", "fet_fsf()", fet_error( rc ) ); else WRMSG( HHC00075, "E", "het_fsf()", het_error( rc ) ); return( rc ); } } /* || Different processing when converting to ASCII */ if( opts.flags & ( O_ASCII | O_UNBLOCK ) ) { /* || Get a record */ while( ( rc = getrecord( ) ) >= 0 ) { #ifdef EXTERNALGUI if( extgui ) { off_t curpos; /* Report progress every nnnK */ if ( opts.faketape ) curpos = ftell( opts.fetb->fd ); else curpos = ftell( opts.hetb->fd ); if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) ) { prevpos = curpos; fprintf( stderr, "IPOS=%" I64_FMT "d\n", (U64)curpos ); } } #endif /*EXTERNALGUI*/ /* || Get working copy of record ptr */ ptr = recptr; /* || Only want data portion for RECFM=V records */ if( opts.recfm & O_VARIABLE ) { ptr += 4; rc -= 4; } /* || Convert record to ASCII */ if( opts.flags & O_ASCII ) { sl_etoa( NULL, ptr, rc ); } /* || Strip trailing blanks */ if( opts.flags & O_STRIP ) { while( rc > 0 && ptr[ rc - 1 ] == ' ' ) { rc--; } } /* || Write the record out */ fwrite( ptr, rc, 1, outf ); /* || Put out a linefeed when converting */ if( opts.flags & O_ASCII ) { fwrite( "\n", 1, 1, outf ); } } } else { /* || Get a record */ while( ( rc = getblock( ) ) >= 0 ) { #ifdef EXTERNALGUI if( extgui ) { off_t curpos; /* Report progress every nnnK */ if ( opts.faketape ) curpos = ftell( opts.fetb->fd ); else curpos = ftell( opts.hetb->fd ); if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) ) { prevpos = curpos; fprintf( stderr, "IPOS=%" I64_FMT "d\n", (U64)curpos ); } } #endif /*EXTERNALGUI*/ /* || Write the record out */ fwrite( blkptr, blklen, 1, outf ); } } return( rc ); }