Example #1
0
/*
|| Print terse dataset information (from VOL1/EOF1/EOF2)
*/
void
printdataset( char *buf, int len, int fileno )
{
    SLLABEL lab;
    SLFMT fmt;
    char crtdt[ 9 ];
    char expdt[ 9 ];
    char recfm[ 4 ];

    if( sl_islabel( &lab, buf, len ) == FALSE )
    {
        return;
    }

    sl_fmtlab( &fmt, &lab );

    if( sl_isvol( buf, 1 ) )
    {
        printf( "vol=%-17.17s  owner=%s\n\n",
                fmt.slvol.volser,
                fmt.slvol.owner);
    }
    else if( sl_iseof( buf, 1 ) )
    {
        printf( "seq=%-17d  file#=%d\n",
                atoi( fmt.slds1.dsseq ),
                fileno );
        printf( "dsn=%-17.17s  crtdt=%-8.8s  expdt=%-8.8s  blocks=%d\n",
                fmt.slds1.dsid,
                sl_fmtdate( crtdt, fmt.slds1.crtdt, TRUE ),
                sl_fmtdate( expdt, fmt.slds1.expdt, TRUE ),
                atoi( fmt.slds1.blkhi ) * 1000000 + atoi( fmt.slds1.blklo ) );
    }
    else if( sl_iseof( buf, 2 ) )
    {
        recfm[ 0 ] = '\0';
        strcat( strcat( strcat( recfm,
                                fmt.slds2.recfm ),
                        fmt.slds2.blkattr ),
                fmt.slds2.ctrl );
        printf( "job=%17.17s  recfm=%-3.3s       lrecl=%-5d     blksize=%-5d\n\n",
                fmt.slds2.jobid,
                recfm,
                atoi( fmt.slds2.lrecl ),
                atoi( fmt.slds2.blksize ) );
    }

    return;
}
Example #2
0
/*
 || Print all label fields
 */
void
Print_Label( SInt32 len )
{
    SLLABEL lab;
    SLFMT fmt;
    SInt32 i;

    if( sl_islabel( &lab, gBuffer, len ) == FALSE )
    {
        return;
    }

    sl_fmtlab( &fmt, &lab );

    printf ( "%s", sep );

    for( i = 0; fmt.key[ i ] != NULL; i++ )
    {
        printf ("%-20.20s: '%s'\n", fmt.key[ i ] , fmt.val[ i ] );
    }

    return;
}
Example #3
0
/*
|| Print all label fields
*/
void
printlabel( char *buf, int len )
{
    SLLABEL lab;
    SLFMT fmt;
    int i;

    if( sl_islabel( &lab, buf, len ) == FALSE )
    {
        return;
    }

    sl_fmtlab( &fmt, &lab );

    printf( sep );

    for( i = 0; fmt.key[ i ] != NULL; i++ )
    {
        printf("%-20.20s: '%s'\n", fmt.key[ i ] , fmt.val[ i ] );
    }

    return;
}
Example #4
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 )
Example #5
0
/*
|| 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);
}
Example #6
0
/*
|| Merge DCB information from HDR2 label
*/
void
merge( SLLABEL *lab, int disp_out )
{
    SLFMT fmt;
    int i;

    UNREFERENCED(disp_out);
    /*
    || Make the label more managable
    */
    sl_fmtlab( &fmt, lab );

    /*
    || Merge the record format;
    */
    if( opts.recfm == 0 )
    {
        opts.recfm = O_UNDEFINED;
        for( i = 0 ; i < (int)VALFMCNT ; i++ )
        {
            if( strcasecmp( fmt.slds2.recfm, valfm[ i ].recfm ) == 0 )
            {
                opts.recfm = valfm[ i ].fmt;
                break;
            }
        }
    }

    /*
    || Merge in the record length
    */
    if( opts.lrecl == 0 )
    {
        opts.lrecl = atoi( fmt.slds2.lrecl );
    }

    /*
    || Merge in the block size
    */
    if( opts.blksize == 0 )
    {
        /*
        || Try the blksize field first
        */
        opts.blksize = atoi( fmt.slds2.blksize );
        if( opts.blksize == 0 )
        {
            /*
            || Still zero, so try the lblkln field
            */
            opts.blksize = atoi( fmt.slds2.lblkln );
        }
    }

    /*
    || Locate final RECFM string
    */
    for( i = 0 ; i < (int)VALFMCNT ; i++ )
    {
        if( strcasecmp( fmt.slds2.recfm, valfm[ i ].recfm ) == 0 )
        {
            break;
        }
    }

// some of these functions are duplicated in hetmap.c
#if 0
    /*
    || Print DCB attributes
    */
    if ( disp_opt == 0 )
    {
        logmsg( "DCB Attributes used:\n" );
        logmsg( "  RECFM=%-4.4s  LRECL=%-5.5d  BLKSIZE=%d\n",
                valfm[ i ].recfm,
                opts.lrecl,
                opts.blksize );
    }
    else if ( disp_opt == 1 )
    {
        logmsg( " %-4.4s %5d %5d\n", valfm[ i ].recfm, opts.lrecl, opts.blksize );
    }
#endif

    return;
}
Example #7
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 );
}
Example #8
0
/*
|| Merge DCB information from HDR2 label
*/
void
merge( SLLABEL *lab )
{
    SLFMT fmt;
    int i;

    /*
    || Make the label more managable
    */
    sl_fmtlab( &fmt, lab );

    /*
    || Merge the record format;
    */
    if( opts.recfm == 0 )
    {
        opts.recfm = O_UNDEFINED;
        for( i = 0 ; i < (int)VALFMCNT ; i++ )
        {
            if( strcasecmp( fmt.slds2.recfm, valfm[ i ].recfm ) == 0 )
            {
                opts.recfm = valfm[ i ].fmt;
                break;
            }
        }
    }

    /*
    || Merge in the record length
    */
    if( opts.lrecl == 0 )
    {
        opts.lrecl = atoi( fmt.slds2.lrecl );
    }

    /*
    || Merge in the block size
    */
    if( opts.blksize == 0 )
    {
        /*
        || Try the blksize field first
        */
        opts.blksize = atoi( fmt.slds2.blksize );
        if( opts.blksize == 0 )
        {
            /*
            || Still zero, so try the lblkln field
            */
            opts.blksize = atoi( fmt.slds2.lblkln );
        }
    }

    /*
    || Locate final RECFM string
    */
    for( i = 0 ; i < (int)VALFMCNT ; i++ )
    {
        if( strcasecmp( fmt.slds2.recfm, valfm[ i ].recfm ) == 0 )
        {
            break;
        }
    }

    /*
    || Print DCB attributes
    */
    printf( "DCB Attributes used:\n" );
    printf( "  RECFM=%-4.4s  LRECL=%-5.5d  BLKSIZE=%d\n",
        valfm[ i ].recfm,
        opts.lrecl,
        opts.blksize );

    return;
}