Beispiel #1
0
/*
|| 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 );
}
Beispiel #2
0
/*-------------------------------------------------------------------*/
int bsf_het (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    /* Exit if already at BOT */
    if (dev->curfilen==1 && dev->nxtblkpos == 0)
    {
        build_senseX(TAPE_BSENSE_LOADPTERR,dev,unitstat,code);
        return -1;
    }

    rc = het_bsf (dev->hetb);
    if (rc < 0)
    {
        logmsg (_("HHCTA421E %4.4X: Error back spacing to previous file "
                "at block %8.8X in file %s:\n %s(%s)\n"),
                dev->devnum, dev->hetb->cblk, dev->filename,
                het_error(rc), strerror(errno));

        build_senseX(TAPE_BSENSE_LOCATEERR,dev,unitstat,code);
        return -1;
    }

    /* Maintain position */
    dev->blockid = rc;
    dev->curfilen--;

    /* Return success */
    return 0;

} /* end function bsf_het */
Beispiel #3
0
/*
|| Retrieve and validate a standard label
*/
int
get_sl( HETB *hetb, SLLABEL *lab )
{
    int rc;
    
    /*
    || Read a block
    */
    rc = het_read( hetb, blkptr );
    if( rc >= 0 )
    {
        /*
        || Does is look like a standard label?
        */
        if( sl_islabel( lab, blkptr, rc ) == TRUE )
        {
            return( 0 );
        }
    }
    else
    {
        printf( "%s while reading block\n", het_error( rc ) );
    }

    return( -1 );
}
Beispiel #4
0
/*-------------------------------------------------------------------*/
int bsf_het (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    /* Exit if already at BOT */
    if (dev->curfilen==1 && dev->nxtblkpos == 0)
    {
        build_senseX(TAPE_BSENSE_LOADPTERR,dev,unitstat,code);
        return -1;
    }

    rc = het_bsf (dev->hetb);
    if (rc < 0)
    {
        char msgbuf[128];
        MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_bsf()", (off_t)dev->hetb->cblk, msgbuf);

        build_senseX(TAPE_BSENSE_LOCATEERR,dev,unitstat,code);
        return -1;
    }

    /* Maintain position */
    dev->blockid = rc;
    dev->curfilen--;

    /* Return success */
    return 0;

} /* end function bsf_het */
Beispiel #5
0
/*-------------------------------------------------------------------*/
int fsf_het (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    /* Forward space to start of next file */
    rc = het_fsf (dev->hetb);
    if (rc < 0)
    {
        char msgbuf[128];
        MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_fsf()", (off_t)dev->hetb->cblk, msgbuf);

        if(rc==HETE_EOT)
        {
            build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
        }
        else
        {
            build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        }
        return -1;
    }

    /* Maintain position */
    dev->blockid = rc;
    dev->curfilen++;

    /* Return success */
    return 0;

} /* end function fsf_het */
Beispiel #6
0
/*-------------------------------------------------------------------*/
int write_hetmark (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    /* Write the tape mark */
    rc = het_tapemark (dev->hetb);
    if (rc < 0)
    {
        /* Handle error condition */
        logmsg (_("HHCTA417E %4.4X: Error writing tape mark "
                "at block %8.8X in file %s: %s(%s)\n"),
                dev->devnum, dev->hetb->cblk, dev->filename,
                het_error(rc), strerror(errno));

        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_WRITEFAIL,dev,unitstat,code);
        return -1;
    }

    /* Return normal status */
    dev->blockid++;

    return 0;

} /* end function write_hetmark */
Beispiel #7
0
/*-------------------------------------------------------------------*/
int write_hetmark( DEVBLK *dev, BYTE *unitstat, BYTE code )
{
int             rc;                     /* Return code               */

    if ( dev->hetb->writeprotect )
    {
        build_senseX(TAPE_BSENSE_WRITEPROTECT,dev,unitstat,code);
        return -1;
    }

    /* Write the tape mark */
    rc = het_tapemark (dev->hetb);
    if (rc < 0)
    {
        /* Handle error condition */
        char msgbuf[128];
        MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_tapemark()", (off_t)dev->hetb->cblk, msgbuf);

        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_WRITEFAIL,dev,unitstat,code);
        return -1;
    }

    /* Return normal status */
    dev->blockid++;

    return 0;

} /* end function write_hetmark */
Beispiel #8
0
/*-------------------------------------------------------------------*/
int fsf_het (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    /* Forward space to start of next file */
    rc = het_fsf (dev->hetb);
    if (rc < 0)
    {
        logmsg (_("HHCTA420E %4.4X: Error forward spacing to next file "
                "at block %8.8X in file %s: %s(%s)\n"),
                dev->devnum, dev->hetb->cblk, dev->filename,
                het_error(rc), strerror(errno));

        if(rc==HETE_EOT)
        {
            build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
        }
        else
        {
            build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        }
        return -1;
    }

    /* Maintain position */
    dev->blockid = rc;
    dev->curfilen++;

    /* Return success */
    return 0;

} /* end function fsf_het */
Beispiel #9
0
/*-------------------------------------------------------------------*/
int write_het (DEVBLK *dev, BYTE *buf, U16 blklen,
                      BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */
off_t           cursize;                /* Current size for size chk */

    /* Check if we have already violated the size limit */
    if(dev->tdparms.maxsize>0)
    {
        cursize=het_tell(dev->hetb);
        if(cursize>=dev->tdparms.maxsize)
        {
            build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
            return -1;
        }
    }
    /* Write the data block */
    rc = het_write (dev->hetb, buf, blklen);
    if (rc < 0)
    {
        /* Handle write error condition */
        logmsg (_("HHCTA416E %4.4X: Error writing data block "
                "at block %8.8X in file %s: %s(%s)\n"),
                dev->devnum, dev->hetb->cblk, dev->filename,
                het_error(rc), strerror(errno));

        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_WRITEFAIL,dev,unitstat,code);
        return -1;
    }
    /* Check if we have violated the maxsize limit */
    /* Also check if we are passed EOT marker */
    if(dev->tdparms.maxsize>0)
    {
        cursize=het_tell(dev->hetb);
        if(cursize>dev->tdparms.maxsize)
        {
            logmsg (_("HHCTA430I %4.4X: max tape capacity exceeded\n"),
                    dev->devnum);
            if(dev->tdparms.strictsize)
            {
                logmsg (_("HHCTA431I %4.4X: max tape capacity enforced\n"),
                        dev->devnum);
                het_bsb(dev->hetb);
                cursize=het_tell(dev->hetb);
                ftruncate( fileno(dev->hetb->fd),cursize);
                dev->hetb->truncated=TRUE; /* SHOULD BE IN HETLIB */
            }
            build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
            return -1;
        }
    }

    /* Return normal status */
    dev->blockid++;

    return 0;

} /* end function write_het */
Beispiel #10
0
/*-------------------------------------------------------------------*/
int rewind_het(DEVBLK *dev,BYTE *unitstat,BYTE code)
{
int rc;
    rc = het_rewind (dev->hetb);
    if (rc < 0)
    {
        /* Handle seek error condition */
        logmsg (_("HHCTA402E %4.4X: Error seeking to start of %s: %s(%s)\n"),
                dev->devnum, dev->filename, het_error(rc), strerror(errno));

        build_senseX(TAPE_BSENSE_REWINDFAILED,dev,unitstat,code);
        return -1;
    }
    dev->nxtblkpos=0;
    dev->prvblkpos=-1;
    dev->curfilen=1;
    dev->blockid=0;
    dev->fenced = 0;
    return 0;
}
Beispiel #11
0
/*-------------------------------------------------------------------*/
int read_het (DEVBLK *dev, BYTE *buf, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    rc = het_read (dev->hetb, buf);
    if (rc < 0)
    {
        /* Increment file number and return zero if tapemark was read */
        if (rc == HETE_TAPEMARK)
        {
            dev->curfilen++;
            dev->blockid++;
            return 0;
        }

        /* Handle end of file (uninitialized tape) condition */
        if (rc == HETE_EOT)
        {
            logmsg (_("HHCTA414E %4.4X: End of file (end of tape) "
                    "at block %8.8X in file %s\n"),
                    dev->devnum, dev->hetb->cblk, dev->filename);

            /* Set unit exception with tape indicate (end of tape) */
            build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
            return -1;
        }

        logmsg (_("HHCTA415E %4.4X: Error reading data block "
                "at block %8.8X in file %s: %s(%s)\n"),
                dev->devnum, dev->hetb->cblk, dev->filename,
                het_error(rc), strerror(errno));

        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        return -1;
    }
    dev->blockid++;
    /* Return block length */
    return rc;

} /* end function read_het */
Beispiel #12
0
/*-------------------------------------------------------------------*/
int rewind_het(DEVBLK *dev,BYTE *unitstat,BYTE code)
{
int rc;
    rc = het_rewind (dev->hetb);
    if (rc < 0)
    {
        /* Handle seek error condition */
        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_rewind()", msgbuf);

        build_senseX(TAPE_BSENSE_REWINDFAILED,dev,unitstat,code);
        return -1;
    }
    dev->nxtblkpos=0;
    dev->prvblkpos=-1;
    dev->curfilen=1;
    dev->blockid=0;
    dev->fenced = 0;
    return 0;
}
Beispiel #13
0
/*-------------------------------------------------------------------*/
int fsb_het (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    /* Forward space one block */
    rc = het_fsb (dev->hetb);

    if (rc < 0)
    {
        /* Increment file number and return zero if tapemark was read */
        if (rc == HETE_TAPEMARK)
        {
            dev->blockid++;
            dev->curfilen++;
            return 0;
        }

        logmsg (_("HHCTA418E %4.4X: Error forward spacing "
                "at block %8.8X in file %s: %s(%s)\n"),
                dev->devnum, dev->hetb->cblk, dev->filename,
                het_error(rc), strerror(errno));

        /* Set unit check with equipment check */
        if(rc==HETE_EOT)
        {
            build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
        }
        else
        {
            build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        }
        return -1;
    }

    dev->blockid++;

    /* Return +1 to indicate forward space successful */
    return +1;

} /* end function fsb_het */
Beispiel #14
0
/*-------------------------------------------------------------------*/
int bsb_het (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    /* Back space one block */
    rc = het_bsb (dev->hetb);
    if (rc < 0)
    {
        /* Increment file number and return zero if tapemark was read */
        if (rc == HETE_TAPEMARK)
        {
            dev->blockid--;
            dev->curfilen--;
            return 0;
        }

        /* Unit check if already at start of tape */
        if (rc == HETE_BOT)
        {
            build_senseX(TAPE_BSENSE_LOADPTERR,dev,unitstat,code);
            return -1;
        }

        logmsg (_("HHCTA419E %4.4X: Error reading data block "
                "at block %8.8X in file %s: %s(%s)\n"),
                dev->devnum, dev->hetb->cblk, dev->filename,
                het_error(rc), strerror(errno));

        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        return -1;
    }

    dev->blockid--;

    /* Return +1 to indicate back space successful */
    return +1;

} /* end function bsb_het */
Beispiel #15
0
/*-------------------------------------------------------------------*/
int bsb_het (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    /* Back space one block */
    rc = het_bsb (dev->hetb);
    if (rc < 0)
    {
        /* Increment file number and return zero if tapemark was read */
        if (rc == HETE_TAPEMARK)
        {
            dev->blockid--;
            dev->curfilen--;
            return 0;
        }

        /* Unit check if already at start of tape */
        if (rc == HETE_BOT)
        {
            build_senseX(TAPE_BSENSE_LOADPTERR,dev,unitstat,code);
            return -1;
        }
        {
            char msgbuf[128];
            MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
            WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename,
                   "het", "het_bsb()", (off_t)dev->hetb->cblk, msgbuf);
        }
        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        return -1;
    }

    dev->blockid--;

    /* Return +1 to indicate back space successful */
    return +1;

} /* end function bsb_het */
Beispiel #16
0
/*-------------------------------------------------------------------*/
int read_het (DEVBLK *dev, BYTE *buf, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    rc = het_read (dev->hetb, buf);
    if (rc < 0)
    {
        /* Increment file number and return zero if tapemark was read */
        if (rc == HETE_TAPEMARK)
        {
            dev->curfilen++;
            dev->blockid++;
            return 0;
        }

        /* Handle end of file (uninitialized tape) condition */
        if (rc == HETE_EOT)
        {
            WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_read()", (off_t)dev->hetb->cblk, "end of file (uninitialized tape)");

            /* Set unit exception with tape indicate (end of tape) */
            build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
            return -1;
        }
        {
            char msgbuf[128];
            MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
            WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_read()", (off_t)dev->hetb->cblk, msgbuf);
        }
        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        return -1;
    }
    dev->blockid++;
    /* Return block length */
    return rc;

} /* end function read_het */
Beispiel #17
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 */
Beispiel #18
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;
}
Beispiel #19
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;
}
Beispiel #20
0
/*
|| Open HET tapes and set options
*/
static int
opentapes( void )
{
    int rc;

    if ( ( rc = (int)strlen( o_sname ) ) > 4 && 
        ( rc = strcasecmp( &o_sname[rc-4], ".fkt" ) ) == 0 )
    {
        i_faketape = TRUE;
    }

    if ( i_faketape )
        rc = fet_open( &s_fetb, o_sname, FETOPEN_READONLY );
    else
        rc = het_open( &s_hetb, o_sname, HETOPEN_READONLY );
    if( rc < 0 )
    {
        if ( o_verbose )
            WRMSG( HHC02720, "E", o_sname, rc, het_error( rc ) );
        goto exit;
    }

    if ( ( rc = (int)strlen( o_dname ) ) > 4 && 
        ( rc = strcasecmp( &o_dname[rc-4], ".fkt" ) ) == 0 )
    {
        o_faketape = TRUE;
    }
    
    if ( o_faketape )
        rc = fet_open( &d_fetb, o_dname, FETOPEN_CREATE );
    else
        rc = het_open( &d_hetb, o_dname, HETOPEN_CREATE );
    if( rc < 0 )
    {
        if ( o_verbose )
            WRMSG( HHC02720, "E", o_dname, rc, het_error( rc ) );
        goto exit;
    }

    if ( !i_faketape )
    {
        if ( o_verbose )
            WRMSG( HHC02755, "I", "decompress", yesno( o_decompress ) );

        rc = het_cntl( s_hetb, HETCNTL_SET | HETCNTL_DECOMPRESS, o_decompress );
        if( rc < 0 )
        {
            if ( o_verbose )
                WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) );
            goto exit;
        }
    }

    if ( !o_faketape )
    {
        if ( o_verbose )
            WRMSG( HHC02755, "I", "compress", yesno( o_compress ) );

        rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_COMPRESS, o_compress );
        if( rc < 0 )
        {
            if ( o_verbose )
                WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) );
            goto exit;
        }

        if ( o_verbose )
        {
            char msgbuf[16];
            MSGBUF( msgbuf, "%d", o_method );
            WRMSG( HHC02755, "I", "method", msgbuf );
        }

        rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_METHOD, o_method );
        if( rc < 0 )
        {
            if ( o_verbose )
                WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) );
            goto exit;
        }

        if ( o_verbose )
        {
            char msgbuf[16];
            MSGBUF( msgbuf, "%d", o_level );
            WRMSG( HHC02755, "I", "level", msgbuf );
        }

        rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_LEVEL, o_level );
        if( rc < 0 )
        {
            if ( o_verbose )
                WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) );
            goto exit;
        }

        if ( o_verbose )
        {
            char msgbuf[16];
            MSGBUF( msgbuf, "%d", o_chunksize );
            WRMSG( HHC02755, "I", "chunksize", msgbuf );
        }

        rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_CHUNKSIZE, o_chunksize );
        if( rc < 0 )
        {
            if ( o_verbose )
                WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) );
            goto exit;
        }
    }

    if( o_verbose )
    {
        char msgbuf[128];

        MSGBUF( msgbuf, "Source             : %s", o_sname );
        WRMSG( HHC02757, "I", msgbuf );
        MSGBUF( msgbuf, "Destination        : %s", o_dname );
        WRMSG( HHC02757, "I", msgbuf );
        if ( !i_faketape )
        {
            MSGBUF( msgbuf, "Decompress source  : %s", yesno( het_cntl( s_hetb, HETCNTL_DECOMPRESS, 0 ) ) );
            WRMSG( HHC02757, "I", msgbuf );
        }
        if ( !o_faketape )
        {
            MSGBUF( msgbuf, "Compress dest      : %s", yesno( het_cntl( d_hetb, HETCNTL_COMPRESS, 0 ) ) );
            WRMSG( HHC02757, "I", msgbuf );
            MSGBUF( msgbuf, "Compression method : %d", het_cntl( d_hetb, HETCNTL_METHOD, 0 ) );
            WRMSG( HHC02757, "I", msgbuf );
            MSGBUF( msgbuf, "Compression level  : %d", het_cntl( d_hetb, HETCNTL_LEVEL, 0 ) );
            WRMSG( HHC02757, "I", msgbuf );
        }
    }

exit:

    return( rc );
}
Beispiel #21
0
/*
|| 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   */
    char            toname[ MAX_PATH ];
    int             rc;
    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 Copy/Update" ) );
    display_version (stderr, msgbuf+10, FALSE);

    while( TRUE )
    {
#if defined( HET_BZIP2 )
        rc = getopt( argc, argv, "bc:dhrsvz0123456789" );
#else
        rc = getopt( argc, argv, "c:dhrsvz0123456789" );
#endif /* defined( HET_BZIP2 ) */
        if( rc == -1 )
        {
            break;
        }

        switch( rc )
        {
            case '1': case '2': case '3': case '4': /* Compression level     */
            case '5': case '6': case '7': case '8':
            case '9':
                o_level = ( rc - '0' );
            break;

#if defined( HET_BZIP2 )
            case 'b':                               /* Use BZLIB compression */
                o_method = HETMETH_BZLIB;
                o_compress = TRUE;
                o_decompress = TRUE;
            break;
#endif /* defined( HET_BZIP2 ) */

            case 'c':                               /* Chunk size           */
                o_chunksize = atoi( optarg );
            break;

            case 'd':                               /* Decompress           */
                o_compress = FALSE;
                o_decompress = TRUE;
            break;

            case 'h':                               /* Print usage          */
                usage( pgm );
                exit( 1 );
            break;

            case 'r':                               /* Rechunk              */
                o_compress = FALSE;
                o_decompress = FALSE;
            break;

            case 's':                               /* Strict HET spec      */
                o_chunksize = 4096;
                o_compress = FALSE;
                o_decompress = TRUE;
            break;

            case 'v':                               /* Be chatty            */
                o_verbose = TRUE;
            break;

            case 'z':                               /* Use ZLIB compression */
                o_method = HETMETH_ZLIB;
                o_compress = TRUE;
                o_decompress = TRUE;
            break;

            default:                                /* Print usage          */
                usage( pgm );
                exit( 1 );
            break;
        }
    }

    argc -= optind;

    switch( argc )
    {
        case 1:
            sprintf( toname, "%s.%010d", argv[ optind ], rand() );
            o_dname = toname;
            dorename = TRUE;
        break;

        case 2:
            o_dname = argv[ optind + 1 ];
        break;

        default:
            usage( pgm );
            exit( 1 );
        break;
    }
    o_sname = argv[ optind ] ;

    rc = opentapes();
    if( rc < 0 )
    {
        WRMSG( HHC02756, "E", "opening", het_error( rc ) );
    }
    else
    {
        rc = copytape();
        if( rc < 0 )
        {
            WRMSG( HHC02756, "E", "copying", het_error( rc ) );
        }
    }

    closetapes( rc );

    return 0;
}
Beispiel #22
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 )
Beispiel #23
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 #24
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 );
}
Beispiel #25
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 */
Beispiel #26
0
/*
|| 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 );
}
Beispiel #27
0
/*
|| Standard main
*/
int
main( int argc, char *argv[] )
{
    char toname[ PATH_MAX ];
    HETB *s_hetb;
    HETB *d_hetb;
    int rc;

    INITIALIZE_UTILITY("hetupd");

    s_hetb = NULL;
    d_hetb = NULL;

    /* Display the program identification message */
    display_version (stderr, "Hercules HET copy/update program ", FALSE);

    while( TRUE )
    {
#if defined( HET_BZIP2 )
        rc = getopt( argc, argv, "bc:dhrsvz0123456789" );
#else
        rc = getopt( argc, argv, "c:dhrsvz0123456789" );
#endif /* defined( HET_BZIP2 ) */
        if( rc == -1 )
        {
            break;
        }

        switch( rc )
        {
            case '1': case '2': case '3': case '4': /* Compression level     */
            case '5': case '6': case '7': case '8':
            case '9':
                o_level = ( rc - '0' );
            break;

#if defined( HET_BZIP2 )
            case 'b':                               /* Use BZLIB compression */
                o_method = HETMETH_BZLIB;
                o_compress = TRUE;
                o_decompress = TRUE;
            break;
#endif /* defined( HET_BZIP2 ) */

            case 'c':                               /* Chunk size           */
                o_chunksize = atoi( optarg );
            break;

            case 'd':                               /* Decompress           */
                o_compress = FALSE;
                o_decompress = TRUE;
            break;

            case 'h':                               /* Print usage          */
                usage( argv[ 0 ] );
                exit( 1 );
            break;

            case 'r':                               /* Rechunk              */
                o_compress = FALSE;
                o_decompress = FALSE;
            break;

            case 's':                               /* Strict HET spec      */
                o_chunksize = 4096;
                o_compress = FALSE;
                o_decompress = TRUE;
            break;

            case 'v':                               /* Be chatty            */
                o_verbose = TRUE;
            break;

            case 'z':                               /* Use ZLIB compression */
                o_method = HETMETH_ZLIB;
                o_compress = TRUE;
                o_decompress = TRUE;
            break;

            default:                                /* Print usage          */
                usage( argv[ 0 ] );
                exit( 1 );
            break;
        }
    }

    argc -= optind;

    switch( argc )
    {
        case 1:
            sprintf( toname, "%s.%010d", argv[ optind ], rand() );
            o_dname = toname;
            dorename = TRUE;
        break;

        case 2:
            o_dname = argv[ optind + 1 ];
        break;

        default:
            usage( argv[ 0 ] );
            exit( 1 );
        break;
    }
    o_sname = argv[ optind ] ;

    rc = opentapes();
    if( rc < 0 )
    {
        printf( "Error opening files - HETLIB rc: %d\n%s\n",
            rc,
            het_error( rc ) );
        exit( 1 );
    }

    rc = copytape();
    if( rc < 0 )
    {
        printf( "Error copying files - HETLIB rc: %d\n%s\n",
            rc,
            het_error( rc ) );
        exit( 1 );
    }

    closetapes( rc );

    return 0;
}
Beispiel #28
0
/*
|| 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;
}
Beispiel #29
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);
}
Beispiel #30
0
/*-------------------------------------------------------------------*/
int write_het (DEVBLK *dev, BYTE *buf, U32 blklen,
                      BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */
off_t           cursize;                /* Current size for size chk */

    if ( dev->hetb->writeprotect )
    {
        build_senseX(TAPE_BSENSE_WRITEPROTECT,dev,unitstat,code);
            return -1;
    }

    /* Check if we have already violated the size limit */
    if(dev->tdparms.maxsize>0)
    {
        cursize=het_tell(dev->hetb);
        if(cursize>=dev->tdparms.maxsize)
        {
            build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
            return -1;
        }
    }
    /* Write the data block */
    rc = het_write (dev->hetb, buf, blklen);
    if (rc < 0)
    {
        /* Handle write error condition */
        char msgbuf[128];
        MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_write()", (off_t)dev->hetb->cblk, msgbuf);

        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_WRITEFAIL,dev,unitstat,code);
        return -1;
    }
    /* Check if we have violated the maxsize limit */
    /* Also check if we are passed EOT marker */
    if(dev->tdparms.maxsize>0)
    {
        cursize=het_tell(dev->hetb);
        if(cursize>dev->tdparms.maxsize)
        {
            WRMSG (HHC00208, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het");
            if(dev->tdparms.strictsize)
            {
                WRMSG (HHC00209, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het");
                het_bsb(dev->hetb);
                cursize=het_tell(dev->hetb);
                VERIFY(!ftruncate(dev->hetb->fd, cursize));
                dev->hetb->truncated=TRUE; /* SHOULD BE IN HETLIB */
            }
            build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
            return -1;
        }
    }

    /* Return normal status */
    dev->blockid++;

    return 0;

} /* end function write_het */