Beispiel #1
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 );
}
Beispiel #2
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;
}