Esempio n. 1
0
/*-------------------------------------------------------------------*/
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   */
IFD             ifd;                    /* Input file descriptor     */
int             repl = 0;               /* 1=replace existing file   */
int             quiet = 0;              /* 1=suppress progress msgs  */
BYTE           *itrkbuf;                /* -> Input track buffer     */
U32             itrklen;                /* Input track length        */
U32             volcyls;                /* Total cylinders on volume */
U32             heads = 0;              /* Number of tracks/cylinder */
U32             maxdlen = 0;            /* Maximum R1 data length    */
U16             devtype;                /* Device type               */
char            ifname[256];            /* Input file name           */
char            ofname[256];            /* Output file name          */
BYTE            volser[7];              /* Volume serial (ASCIIZ)    */
int             lfs = 0;                /* 1 = Build large file      */
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( pgm );

    /* Display the program identification message */
    MSGBUF( msgbuf, MSG_C( HHC02499, "I", pgm, "DASD CKD image conversion" ) );
    display_version (stderr, msgbuf+10, FALSE);

    /* Process the options in the argument list */
    for (; argc > 1; argc--, argv++)
    {
        if (strcmp(argv[1], "-") == 0) break;
        if (argv[1][0] != '-') break;
        if (strcmp(argv[1], "-r") == 0)
            repl = 1;
        else if (strcmp(argv[1], "-q") == 0)
            quiet = 1;
        else
        if (sizeof(off_t) > 4 && strcmp(argv[1], "-lfs") == 0)
            lfs = 1;
        else
            argexit(5, pgm);
    }
    if (argc != 3)
        argexit(5, pgm);

    /* The first argument is the input file name */
    if (argv[1] == NULL || strlen(argv[1]) == 0
        || strlen(argv[1]) > sizeof(ifname)-1)
        argexit(1, pgm);
    strcpy (ifname, argv[1]);

    /* The second argument is the output file name */
    if (argv[2] == NULL || strlen(argv[2]) == 0
        || strlen(argv[2]) > sizeof(ofname)-1)
        argexit(2, pgm);
    strcpy (ofname, argv[2]);

    /* Read the first track of the input file, and determine
       the device type and size from the track header */
    ifd = open_input_image (ifname, &devtype, &volcyls,
                &itrklen, &itrkbuf, volser);

    /* Use the device type to determine track characteristics */
    switch (devtype) {
    case 0x2314: heads = 20; maxdlen = 7294; break;
    case 0x3330: heads = 19; maxdlen = 13030; break;
    case 0x3340: heads = 12; maxdlen = 8368; break;
    case 0x3350: heads = 30; maxdlen = 19069; break;
    case 0x3375: heads = 12; maxdlen = 35616; break;
    case 0x3380: heads = 15; maxdlen = 47476; break;
    case 0x3390: heads = 15; maxdlen = 56664; break;
    case 0x9345: heads = 15; maxdlen = 46456; break;
    default:
        fprintf (stderr, MSG(HHC02416, "E", devtype));
        EXIT(3);
    } /* end switch(devtype) */

    /* Create the device */
    convert_ckd (lfs, ifd, ifname, itrklen, itrkbuf, repl, quiet,
                ofname, devtype, heads, maxdlen, volcyls, volser);

    /* Release the input buffer and close the input file */
    free (itrkbuf);
    IFCLOS (ifd);

    /* Display completion message */
    fprintf (stderr, MSG(HHC02423, "I"));

    return 0;

} /* end function main */
Esempio n. 2
0
/*-------------------------------------------------------------------*/
int main ( int argc, char *argv[] )
{
IFD             ifd;                    /* Input file descriptor     */
int             repl = 0;               /* 1=replace existing file   */
int             quiet = 0;              /* 1=suppress progress msgs  */
BYTE           *itrkbuf;                /* -> Input track buffer     */
U32             itrklen;                /* Input track length        */
U32             volcyls;                /* Total cylinders on volume */
U32             heads = 0;              /* Number of tracks/cylinder */
U32             maxdlen = 0;            /* Maximum R1 data length    */
U16             devtype;                /* Device type               */
char            ifname[256];            /* Input file name           */
char            ofname[256];            /* Output file name          */
BYTE            volser[7];              /* Volume serial (ASCIIZ)    */
int             lfs = 0;                /* 1 = Build large file      */

    INITIALIZE_UTILITY("dasdconv");

    /* Display the program identification message */
    display_version (stderr,
                     "Hercules DASD CKD image conversion program\n",
                     FALSE);

    /* Process the options in the argument list */
    for (; argc > 1; argc--, argv++)
    {
        if (strcmp(argv[1], "-") == 0) break;
        if (argv[1][0] != '-') break;
        if (strcmp(argv[1], "-r") == 0)
            repl = 1;
        else if (strcmp(argv[1], "-q") == 0)
            quiet = 1;
        else
        if (sizeof(off_t) > 4 && strcmp(argv[1], "-lfs") == 0)
            lfs = 1;
        else
            argexit(5);
    }
    if (argc != 3)
        argexit(5);

    /* The first argument is the input file name */
    if (argv[1] == NULL || strlen(argv[1]) == 0
        || strlen(argv[1]) > sizeof(ifname)-1)
        argexit(1);
    strcpy (ifname, argv[1]);

    /* The second argument is the output file name */
    if (argv[2] == NULL || strlen(argv[2]) == 0
        || strlen(argv[2]) > sizeof(ofname)-1)
        argexit(2);
    strcpy (ofname, argv[2]);

    /* Read the first track of the input file, and determine
       the device type and size from the track header */
    ifd = open_input_image (ifname, &devtype, &volcyls,
                &itrklen, &itrkbuf, volser);

    /* Use the device type to determine track characteristics */
    switch (devtype) {
    case 0x2314: heads = 20; maxdlen = 7294; break;
    case 0x3330: heads = 19; maxdlen = 13030; break;
    case 0x3340: heads = 12; maxdlen = 8368; break;
    case 0x3350: heads = 30; maxdlen = 19069; break;
    case 0x3375: heads = 12; maxdlen = 35616; break;
    case 0x3380: heads = 15; maxdlen = 47476; break;
    case 0x3390: heads = 15; maxdlen = 56664; break;
    case 0x9345: heads = 15; maxdlen = 46456; break;
    default:
        fprintf (stderr, "Unknown device type: %4.4X\n", devtype);
        EXIT(3);
    } /* end switch(devtype) */

    /* Create the device */
    convert_ckd (lfs, ifd, ifname, itrklen, itrkbuf, repl, quiet,
                ofname, devtype, heads, maxdlen, volcyls, volser);

    /* Release the input buffer and close the input file */
    free (itrkbuf);
    IFCLOS (ifd);
     
    /* Display completion message */
    fprintf (stderr, "DASD conversion successfully completed.\n");

    return 0;

} /* end function main */
Esempio n. 3
0
/*-------------------------------------------------------------------*/
int main ( int argc, char *argv[] )
{
int     altcylflag = 0;                 /* Alternate cylinders flag  */
int     rawflag = 0;                    /* Raw format flag           */
int     volsize_argnum = 4;             /* argc value of size option */
U32     size = 0;                       /* Volume size               */
U32     altsize = 0;                    /* Alternate cylinders       */
U32     heads = 0;                      /* Number of tracks/cylinder */
U32     maxdlen = 0;                    /* Maximum R1 data length    */
U32     sectsize = 0;                   /* Sector size               */
U16     devtype = 0;                    /* Device type               */
BYTE    comp = 0xff;                    /* Compression algoritm      */
BYTE    type = 0;                       /* C=CKD, F=FBA              */
char    fname[1024];                    /* File name                 */
char    volser[7];                      /* Volume serial number      */
BYTE    c;                              /* Character work area       */
CKDDEV *ckd;                            /* -> CKD device table entry */
FBADEV *fba;                            /* -> FBA device table entry */
int     lfs = 0;                        /* 1 = Build large file      */
int     nullfmt = CKDDASD_NULLTRK_FMT1; /* Null track format type    */
int     rc;                             /* Return code               */

    INITIALIZE_UTILITY("dasdinit");

    /* Display program identification and help */
    if (argc <= 1 || (argc == 2 && !strcmp(argv[1], "-v")))
        argexit(-1, NULL);

    /* Process optional arguments */
    for ( ; argc > 1 && argv[1][0] == '-'; argv++, argc--)
    {
        if (strcmp("0", &argv[1][1]) == 0)
            comp = CCKD_COMPRESS_NONE;
#ifdef HAVE_LIBZ
        else if (strcmp("z", &argv[1][1]) == 0)
            comp = CCKD_COMPRESS_ZLIB;
#endif
#ifdef CCKD_BZIP2
        else if (strcmp("bz2", &argv[1][1]) == 0)
            comp = CCKD_COMPRESS_BZIP2;
#endif
        else if (strcmp("a", &argv[1][1]) == 0)
            altcylflag = 1;
        else if (strcmp("r", &argv[1][1]) == 0)
            rawflag = 1;
        else if (strcmp("lfs", &argv[1][1]) == 0 && sizeof(off_t) > 4)
            lfs = 1;
        else if (strcmp("linux", &argv[1][1]) == 0)
            nullfmt = CKDDASD_NULLTRK_FMT2;
        else argexit(0, argv[1]);
    }

    /* Check remaining number of arguments */
    if (argc < (rawflag ? 3 : 4) || argc > (rawflag ? 4 : 5))
        argexit(5, NULL);

    /* The first argument is the file name */
    if (argv[1] == NULL || strlen(argv[1]) == 0
        || strlen(argv[1]) > sizeof(fname)-1)
        argexit(1, argv[1]);

    strcpy (fname, argv[1]);

    /* The second argument is the device type.
       Model number may also be specified */
    if (argv[2] == NULL)
        argexit(2, argv[2]);
    ckd = dasd_lookup (DASD_CKDDEV, argv[2], 0, 0);
    if (ckd != NULL)
    {
        type = 'C';
        devtype = ckd->devt;
        size = ckd->cyls;
        altsize = ckd->altcyls;
        heads = ckd->heads;
        maxdlen = ckd->r1;
    }
    else
    {
        fba = dasd_lookup (DASD_FBADEV, argv[2], 0, 0);
        if (fba != NULL)
        {
            type = 'F';
            devtype = fba->devt;
            size = fba->blks;
            altsize = 0;
            sectsize = fba->size;
        }
    }

    if (!type)
        /* Specified model not found */
        argexit(2, argv[2]);

    /* If -r option specified, then there is not volume serial
       argument and volume size argument is actually argument
       number 3 and not argument number 4 as otherwise */
    if (rawflag)
        volsize_argnum = 3;
    else
    {
        volsize_argnum = 4;

        /* The third argument is the volume serial number */
        if (argv[3] == NULL || strlen(argv[3]) == 0
            || strlen(argv[3]) > sizeof(volser)-1)
            argexit(3, argv[3]);

        strcpy (volser, argv[3]);
        string_to_upper (volser);
    }

    /* The fourth argument (or third for -r) is the volume size */
    if (argc > volsize_argnum)
    {
        if (argc > (volsize_argnum+1))
            argexit(5, NULL);

        if (!argv[volsize_argnum] || strlen(argv[volsize_argnum]) == 0
            || sscanf(argv[volsize_argnum], "%u%c", &size, &c) != 1)
            argexit(4, argv[volsize_argnum]);

        altcylflag = 0;
    }

    /* `-linux' only supported for 3390 device type */
    if (nullfmt == CKDDASD_NULLTRK_FMT2 && devtype != 0x3390)
        argexit(6, NULL);

    if (altcylflag)
        size += altsize;

    /* Create the device */
    if (type == 'C')
        rc = create_ckd (fname, devtype, heads, maxdlen, size, volser,
                        comp, lfs, 0, nullfmt, rawflag);
    else
        rc = create_fba (fname, devtype, sectsize, size, volser, comp,
                        lfs, 0, rawflag);

    /* Display completion message */
    if (rc == 0)
    {
        fprintf (stderr, _("HHCDI001I DASD initialization successfully "
                "completed.\n"));
    } else {
        fprintf (stderr, _("HHCDI002I DASD initialization unsuccessful"
                "\n"));
    }

    return rc;

} /* end function main */