Esempio n. 1
0
static char *check_sce_filepath(const char *path, char *fullpath)
{
char temppath[MAX_PATH];
char tempreal[MAX_PATH];

    /* Return file access error if no basedir has been set */
    if(!sce_basedir)
    {
        strlcpy(fullpath,path,sizeof(temppath));
        errno = EACCES;
        return NULL;
    }

    /* Establish the full path of the file we are trying to access */
    strlcpy(temppath,sce_basedir,sizeof(temppath));
    strlcat(temppath,path,sizeof(temppath));

    if(!realpath(temppath,tempreal))
    {
        hostpath(fullpath, tempreal, sizeof(temppath));
        if(strncmp( sce_basedir, fullpath, strlen(sce_basedir)))
            errno = EACCES;
        return NULL;
    }

    hostpath(fullpath, tempreal, sizeof(temppath));
    if(strncmp( sce_basedir, fullpath, strlen(sce_basedir)))
    {
        errno = EACCES;
        return NULL;
    }

    return fullpath;
}
Esempio n. 2
0
static void http_verify_path(WEBBLK *webblk, char *path)
{
    char resolved_path[HTTP_PATH_LENGTH];
    char pathname[HTTP_PATH_LENGTH];

#if 0
    int i;

    for (i = 0; path[i]; i++)
        if (!isalnum((int)path[i]) && !strchr("/.-_", path[i]))
            http_error(webblk, "404 File Not Found","",
                               "Illegal character in filename");
#endif
    if (!realpath( path, resolved_path ))
        http_error(webblk, "404 File Not Found","",
                           "Invalid pathname");

    hostpath(pathname, resolved_path, sizeof(pathname));

    // The following verifies the specified file does not lie
    // outside the specified httproot (Note: http_serv.httproot
    // was previously resolved to an absolute path by config.c)

    if (strncmp( http_serv.httproot, pathname, strlen(http_serv.httproot)))
        http_error(webblk, "404 File Not Found","",
                           "Invalid pathname");
}
Esempio n. 3
0
/*-------------------------------------------------------------------*/
static int clear_cardrdr ( DEVBLK *dev )
{
    /* Close the card image file */
    if (cardrdr_close_device(dev) != 0) return -1;

    if (dev->bs) return 0;

    /* Clear the file name */
    dev->filename[0] = '\0';

    /* If next file is available, open it */
    if (dev->current_file && *(dev->current_file))
    {
        hostpath(dev->filename, *(dev->current_file++), sizeof(dev->filename));
    }
    else
    {
        /* Reset the device dependent flags */
        dev->multifile = 0;
        dev->ascii = 0;
        dev->ebcdic = 0;
//      dev->rdreof = 0;
        dev->trunc = 0;
        dev->autopad = 0;
    }

    return 0;
} /* end function clear_cardrdr */
Esempio n. 4
0
void set_sce_dir(char *path)
{
char realdir[MAX_PATH];
char tempdir[MAX_PATH];

    if(sce_basedir)
    {
        free(sce_basedir);
        sce_basedir = NULL;
    }

    if(!path)
        sce_basedir = NULL;
    else
        if(!realpath(path,tempdir))
        {
            WRMSG(HHC00600, "E", path, "realpath()", strerror(errno));
            sce_basedir = NULL;
        }
        else
        {
            hostpath(realdir, tempdir, sizeof(realdir));
            strlcat(realdir,PATHSEPS,sizeof(realdir));
            sce_basedir = strdup(realdir);
        }
}
Esempio n. 5
0
static char *set_sce_basedir(char *path)
{
char *basedir;
char realdir[MAX_PATH];
char tempdir[MAX_PATH];

    if(sce_basedir)
    {
        free(sce_basedir);
        sce_basedir = NULL;
    }

    if(!realpath(path,tempdir))
    {
        WRMSG(HHC00600,"E",path,"realpath()",strerror(errno));
        sce_basedir = NULL;
        return NULL;
    }
    hostpath(realdir, tempdir, sizeof(realdir));

    if((basedir = strrchr(realdir,PATHSEPC)))
    {
        *(++basedir) = '\0';
        sce_basedir = strdup(realdir);
        return (basedir = strrchr(path,PATHSEPC)) ? ++basedir : path;
    }
    else
    {
        sce_basedir = NULL;
        return path;
    }
}
Esempio n. 6
0
/* hdl_setpath - set path for module load
 * If path is NULL, then return the current path
 * If path length is greater than MAX_PATH, send message and return NULL
 *     indicating an error has occurred.
 * If flag is TRUE, then only set new path if not already defined
 * If flag is FALSE, then always set the new path.
 */
DLL_EXPORT char *hdl_setpath(char *path, int flag)
{
    char    pathname[MAX_PATH];         /* pathname conversion */

    if (path == NULL)
        return hdl_modpath;             /* return module path to caller */

    if ( strlen(path) > MAX_PATH )
    {
        WRMSG( HHC01505, "E", (int)strlen(path), MAX_PATH );
        return NULL;
    }

    hostpath(pathname, path, sizeof(pathname));

    if (flag)
    {
        if (hdl_modpath)
        {
            if (!hdl_arg_p)
            {
                free(hdl_modpath);
            }
            else
            {
                WRMSG( HHC01506, "W", pathname );
                WRMSG( HHC01507, "W", hdl_modpath );
                return hdl_modpath;
            }
        }
    }
    else
    {
        hdl_arg_p = TRUE;
        if(hdl_modpath)
            free(hdl_modpath);
    }

    hdl_modpath = strdup(pathname);

    if (MLVL(VERBOSE))
        WRMSG( HHC01508, "I", hdl_modpath );

    return hdl_modpath;
}
Esempio n. 7
0
/*-------------------------------------------------------------------*/
int open_awstape (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc = -1;                /* 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 AWSTAPE file */
    hostpath(pathname, dev->filename, sizeof(pathname));
    if(!dev->tdparms.logical_readonly)
    {
        rc = hopen(pathname, O_RDWR | O_BINARY);
    }

    /* If file is read-only, attempt to open again */
    if (dev->tdparms.logical_readonly || (rc < 0 && (EROFS == errno || EACCES == errno)))
    {
        dev->readonly = 1;
        rc = hopen(pathname, O_RDONLY | O_BINARY);
    }

    /* Check for successful open */
    if (rc < 0)
    {
        logmsg (_("HHCTA102E %4.4X: Error opening %s: %s\n"),
                dev->devnum, dev->filename, strerror(errno));

        strcpy(dev->filename, TAPE_UNLOADED);
        build_senseX(TAPE_BSENSE_TAPELOADFAIL,dev,unitstat,code);
        return -1;
    }

    /* Store the file descriptor in the device block */
    dev->fd = rc;
    rc=rewind_awstape(dev,unitstat,code);
    return rc;

} /* end function open_awstape */
Esempio n. 8
0
/*-------------------------------------------------------------------*/
static char *rcname = NULL;             /* hercules.rc name pointer  */
static void* process_rc_file (void* dummy)
{
int     is_default_rc  = 0;             /* 1 == default name used    */
char    pathname[MAX_PATH];             /* (work)                    */

    UNREFERENCED(dummy);

    /* Obtain the name of the hercules.rc file or default */

    if (!rcname)
    {
        if (!(rcname = getenv("HERCULES_RC")))
        {
            rcname = "hercules.rc";
            is_default_rc = 1;
        }
    }

    if(!strcasecmp(rcname,"None"))
        return NULL;

    hostpath(pathname, rcname, sizeof(pathname));

    /* Wait for panel thread to engage */
// ZZ FIXME:THIS NEED TO GO
    while (!sysblk.panel_init)
        usleep( 10 * 1000 );

    /* Run the script processor for this file */

    if (process_script_file(pathname,1) != 0)
        if (ENOENT == errno)
            if (!is_default_rc)
                WRMSG(HHC01405, "E", pathname);
        // (else error message already issued)

    return NULL;
}
Esempio n. 9
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   */
CKDDASD_DEVHDR  devhdr;                 /* CKD device header         */
CCKDDASD_DEVHDR cdevhdr;                /* Compressed CKD device hdr */
int             level = 0;              /* Chkdsk level              */
int             force = 0;              /* 1=swap if OPENED bit on   */
int             rc;                     /* Return code               */
int             i;                      /* Index                     */
int             bigend;                 /* 1=big-endian file         */
DEVBLK          devblk;                 /* DEVBLK                    */
DEVBLK         *dev=&devblk;            /* -> DEVBLK                 */
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, "Swap 'endianess' of a cckd file" ) );
    display_version (stderr, msgbuf+10, FALSE);

    /* parse the arguments */
    for (argc--, argv++ ; argc > 0 ; argc--, argv++)
    {
        if(**argv != '-') break;

        switch(argv[0][1])
        {
            case '0':
            case '1':
            case '2':
            case '3':  if (argv[0][2] != '\0') return syntax (pgm);
                       level = (argv[0][1] & 0xf);
                       break;
            case 'f':  if (argv[0][2] != '\0') return syntax (pgm);
                       force = 1;
                       break;
            case 'v':  if (argv[0][2] != '\0') return syntax (pgm);
                       return 0;
            default:   return syntax (pgm);
        }
    }

    if (argc < 1) return syntax (pgm);

    for (i = 0; i < argc; i++)
    {
        memset (dev, 0, sizeof (DEVBLK));
        dev->batch = 1;

        /* open the input file */
        hostpath(dev->filename, argv[i], sizeof(dev->filename));
        dev->fd = HOPEN (dev->filename, O_RDWR|O_BINARY);
        if (dev->fd < 0)
        {
            fprintf(stdout, MSG(HHC00354, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename,
                    "open()", strerror(errno)));
            continue;
        }

        /* read the CKD device header */
        if ((rc = read (dev->fd, &devhdr, CKDDASD_DEVHDR_SIZE)) < CKDDASD_DEVHDR_SIZE)
        {
            fprintf(stdout, MSG(HHC00355, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename,
                    "read()", (U64)0, rc < 0 ? strerror(errno) : "incomplete"));
            close (dev->fd);
            continue;
        }
        if (memcmp(devhdr.devid, "CKD_C370", 8) != 0
         && memcmp(devhdr.devid, "CKD_S370", 8) != 0
         && memcmp(devhdr.devid, "FBA_C370", 8) != 0
         && memcmp(devhdr.devid, "FBA_S370", 8) != 0)
        {
            fprintf(stdout, MSG(HHC00356, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename));
            close (dev->fd);
            continue;
        }

        /* read the compressed CKD device header */
        if ((rc = read (dev->fd, &cdevhdr, CCKD_DEVHDR_SIZE)) < CCKD_DEVHDR_SIZE)
        {
            fprintf(stdout, MSG(HHC00355, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename,
                    "read()", (U64)CCKD_DEVHDR_POS, rc < 0 ? strerror(errno) : "incomplete"));
            close (dev->fd);
            continue;
        }

        /* Check the OPENED bit */
        if (!force && (cdevhdr.options & CCKD_OPENED))
        {
            fprintf(stdout, MSG(HHC00352, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename));
            close (dev->fd);
            continue;
        }

        /* get the byte order of the file */
        bigend = (cdevhdr.options & CCKD_BIGENDIAN);

        /* call chkdsk */
        if (cckd_chkdsk (dev, level) < 0)
        {
            fprintf(stdout, MSG(HHC00353, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename));
            close (dev->fd);
            continue;
        }

        /* re-read the compressed CKD device header */
        if (lseek (dev->fd, CCKD_DEVHDR_POS, SEEK_SET) < 0)
        {
            fprintf(stdout, MSG(HHC00355, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename,
                    "lseek()", (U64)CCKD_DEVHDR_POS, strerror(errno)));
            close (dev->fd);
            continue;
        }
        if ((rc = read (dev->fd, &cdevhdr, CCKD_DEVHDR_SIZE)) < CCKD_DEVHDR_SIZE)
        {
            fprintf(stdout, MSG(HHC00355, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename,
                    "read()", (U64)CCKD_DEVHDR_POS, rc < 0 ? strerror(errno) : "incomplete"));
            close (dev->fd);
            continue;
        }

        /* swap the byte order of the file if chkdsk didn't do it for us */
        if (bigend == (cdevhdr.options & CCKD_BIGENDIAN))
        {
            fprintf(stdout, MSG(HHC00357, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename,
                    cckd_endian() ? "big-endian" : "little-endian"));
            if (cckd_swapend (dev) < 0)
                fprintf(stdout, MSG(HHC00378, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename));

        }

        close (dev->fd);
    } /* for each arg */

    return 0;
} /* end main */
Esempio n. 10
0
/*-------------------------------------------------------------------*/
static int printer_init_handler (DEVBLK *dev, int argc, char *argv[])
{
int   iarg,i,j;                        /* some Array subscripts      */
char *ptr;
char *nxt;
int   sockdev = 0;                     /* 1 == is socket device     */

    /* For re-initialisation, close the existing file, if any, and raise attention */
    if (dev->fd >= 0)
    {
        (dev->hnd->close)(dev);

        release_lock (&dev->lock);
        device_attention (dev, CSW_DE);
        obtain_lock (&dev->lock);
    }

    dev->excps = 0;

    /* Forcibly disconnect anyone already currently connected */
    if (dev->bs && !unbind_device_ex(dev,1))
        return -1; // (error msg already issued)

    /* The first argument is the file name */
    if (argc == 0 || strlen(argv[0]) >= sizeof(dev->filename))
    {
        WRMSG (HHC01101, "E", SSID_TO_LCSS(dev->ssid), dev->devnum);
        return -1;
    }

    /* Save the file name in the device block */
    hostpath(dev->filename, argv[0], sizeof(dev->filename));

    if(!sscanf(dev->typname,"%hx",&(dev->devtype)))
        dev->devtype = 0x3211;

    /* Initialize device dependent fields */
    dev->fd = -1;
    dev->diaggate = 0;
    dev->fold = 0;
    dev->crlf = 0;
    dev->stopdev = FALSE;
    dev->notrunc = 0;
    dev->ispiped = (dev->filename[0] == '|');


    /* initialize the new fields for FCB+ support */
    dev->fcbsupp = 1;
    dev->cc = 0;
    dev->rawcc = 0;
    dev->fcbcheck = 1;
    dev->nofcbcheck = 0;
    dev->ccpend = 0;
    dev->chskip = 0;

    dev->prevline = 1;
    dev->currline = 1;
    dev->destline = 1;

    dev->print = 1;
    dev->browse = 0;

    dev->lpi = 6;
    dev->index = 0;
    dev->ffchan = 1;
    for (i = 0; i < FCBSIZE; i++)  dev->fcb[i] = 0;
    for (i = 1; i <= 12; i++ )
    {
        if ( FCBMASK[i] != 0 )
            dev->fcb[FCBMASK[i]] = i;
    }
    dev->lpp = FCBMASK[0];
    dev->fcbisdef = 0;

    /* Process the driver arguments */
    for (iarg = 1; iarg < argc; iarg++)
    {
        if (strcasecmp(argv[iarg], "crlf") == 0)
        {
            dev->crlf = 1;
            continue;
        }

        /* sockdev means the device file is actually
           a connected socket instead of a disk file.
           The file name is the socket_spec (host:port)
           to listen for connections on.
        */
        if (!dev->ispiped && strcasecmp(argv[iarg], "sockdev") == 0)
        {
            sockdev = 1;
            continue;
        }

        if (strcasecmp(argv[iarg], "noclear") == 0)
        {
            dev->notrunc = 1;
            continue;
        }

        if (strcasecmp(argv[iarg], "cc") == 0)
        {
            dev->cc = 1;
            dev->rawcc = 0;
            continue;
        }
        if (strcasecmp(argv[iarg], "rawcc") == 0)
        {
            dev->cc = 0;
            dev->rawcc = 1;
            continue;
        }

        if (strcasecmp(argv[iarg], "nofcbcheck") == 0)
        {
            dev->fcbcheck = 0;
            dev->nofcbcheck = 1;
            continue;
        }

        if (strcasecmp(argv[iarg], "fcbcheck") == 0)
        {
            dev->fcbcheck = 1;
            dev->nofcbcheck = 0;
            continue;
        }

        if ( (strcasecmp(argv[iarg], "browse") == 0) ||
             (strcasecmp(argv[iarg], "optbrowse") == 0 ) )
        {
            dev->print = 0;
            dev->browse = 1;
            continue;
        }

        if ( (strcasecmp(argv[iarg], "print") == 0 ) ||
             (strcasecmp(argv[iarg], "optprint") == 0) )
        {
            dev->print = 1;
            dev->browse = 0;
            continue;
        }

        if (strncasecmp("lpi=", argv[iarg], 4) == 0)
        {
            ptr = argv[iarg]+4;
            errno = 0;
            dev->lpi = (int) strtoul(ptr,&nxt,10);
            if (errno != 0 || nxt == ptr || *nxt != 0 || ( dev->lpi != 6 && dev->lpi != 8 ) )
            {
                j = ptr - argv[iarg];
                WRMSG (HHC01103, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, iarg + 1, argv[iarg], j);
                return -1;
            }
            continue;
        }

        if (strncasecmp("index=", argv[iarg], 6) == 0)
        {
            if (dev->devtype != 0x3211 )
            {
                WRMSG (HHC01103, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, iarg + 1, argv[iarg], 1);
                return -1;
            }
            ptr = argv[iarg]+6;
            errno = 0;
            dev->index = (int) strtoul(ptr,&nxt,10);
            if (errno != 0 || nxt == ptr || *nxt != 0 || ( dev->index < 0 || dev->index > 15) )
            {
                j = ptr - argv[iarg];
                WRMSG (HHC01103, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, iarg + 1, argv[iarg], j);
                return -1;
            }
            continue;
        }

        if (strncasecmp("lpp=", argv[iarg], 4) == 0)
        {
            ptr = argv[iarg]+4;
            errno = 0;
            dev->lpp = (int) strtoul(ptr,&nxt,10);
            if (errno != 0 || nxt == ptr || *nxt != 0 ||dev->lpp > FCBSIZE)
            {
                j = ptr - argv[iarg];
                WRMSG (HHC01103, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, iarg + 1, argv[iarg], j);
                return -1;
            }
            continue;
        }
#if 0
        if (strncasecmp("ffchan=", argv[iarg], 7) == 0)
        {
            ptr = argv[iarg]+7;
            errno = 0;
            dev->ffchan = (int) strtoul(ptr,&nxt,10);
            if (errno != 0 || nxt == ptr || *nxt != 0 ||  dev->ffchan < 1 || dev->ffchan > 12)
            {
                j = ptr - argv[iarg];
                WRMSG (HHC01103, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, iarg + 1, argv[iarg], j);
                return -1;
            }
            continue;
        }
#endif

        if (strncasecmp("fcb=", argv[iarg], 4) == 0)
        {
            for (line = 0; line <= FCBSIZE; line++)  dev->fcb[line] = 0;
            /* check for simple mode */
            if ( strstr(argv[iarg],":") )
            {
                /* ':" found  ==> new mode */
                ptr = argv[iarg]+4;
                while (*ptr)
                {
                    errno = 0;
                    line = (int) strtoul(ptr,&nxt,10);
                    if (errno != 0 || *nxt != ':' || nxt == ptr || line > dev->lpp || dev->fcb[line] != 0 )
                    {
                        j = ptr - argv[iarg];
                        WRMSG (HHC01103, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, iarg + 1, argv[iarg], j);
                        return -1;
                    }

                    ptr = nxt + 1;
                    errno = 0;
                    chan = (int) strtoul(ptr,&nxt,10);
                    if (errno != 0 || (*nxt != ',' && *nxt != 0) || nxt == ptr || chan < 1 || chan > 12 )
                    {
                        j = ptr - argv[iarg];
                        WRMSG (HHC01103, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, iarg + 1, argv[iarg], j);
                        return -1;
                    }
                    dev->fcb[line] = chan;
                    if ( *nxt == 0 )
                        break;
                    ptr = nxt + 1;
                }

            }
            else
            {
                /* ':" NOT found  ==> old mode */
                ptr = argv[iarg]+4;
                chan = 0;
                while (*ptr)
                {
                    errno = 0;
                    line = (int) strtoul(ptr,&nxt,10);
                    if (errno != 0 || (*nxt != ',' && *nxt != 0) || nxt == ptr || line > dev->lpp || dev->fcb[line] != 0 )
                    {
                        j = ptr - argv[iarg];
                        WRMSG (HHC01103, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, iarg + 1, argv[iarg], j);
                        return -1;
                    }
                    chan += 1;
                    if ( chan > 12 )
                    {
                        j = ptr - argv[iarg];
                        WRMSG (HHC01103, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, iarg + 1, argv[iarg], j);
                        return -1;
                    }
                    dev->fcb[line] = chan;
                    if ( *nxt == 0 )
                        break;
                    ptr = nxt + 1;
                }
                if ( chan != 12 )
                {
                    j = 5;
                    WRMSG (HHC01103, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, iarg + 1, argv[iarg], j);
                    return -1;
                }
            }

            continue;
        }

        WRMSG (HHC01102, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, iarg + 1, argv[iarg]);
        return -1;
    }

    /* Check for incompatible options */
    if (dev->rawcc && dev->browse)
    {
        WRMSG (HHC01104, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "rawcc/browse");
        return -1;
    }

    if (sockdev && dev->crlf)
    {
        WRMSG (HHC01104, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "sockdev/crlf");
        return -1;
    }

    if (sockdev && dev->notrunc)
    {
        WRMSG (HHC01104, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "sockdev/noclear");
        return -1;
    }

    /* If socket device, create a listening socket
       to accept connections on.
    */
    if (sockdev && !bind_device_ex( dev,
        dev->filename, onconnect_callback, dev ))
    {
        return -1;  // (error msg already issued)
    }

    /* Set length of print buffer */
//  dev->bufsize = LINE_LENGTH + 8;
    dev->bufsize = BUFF_SIZE + BUFF_OVFL;
    dev->bufres = BUFF_SIZE;
    dev->bufoff = 0;

    /* Set number of sense bytes */
    dev->numsense = 1;

    /* Initialize the device identifier bytes */
    dev->devid[0] = 0xFF;
    dev->devid[1] = 0x28; /* Control unit type is 2821-1 */
    dev->devid[2] = 0x21;
    dev->devid[3] = 0x01;
    dev->devid[4] = dev->devtype >> 8;
    dev->devid[5] = dev->devtype & 0xFF;
    dev->devid[6] = 0x01;
    dev->numdevid = 7;

    /* Activate I/O tracing */
//  dev->ccwtrace = 1;

    return 0;
} /* end function printer_init_handler */
Esempio n. 11
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int
fet_open ( FETB **fetb, char *filename, int flags )
{
int             rc = -1;                /* Return code               */
char            pathname[MAX_PATH];     /* file path in host format  */
FETB           *tfetb;
char           *omode;
int             oflags;


    /* Open the FAKETAPE file */
    *fetb = NULL;

    hostpath(pathname, filename, sizeof(pathname));

    /*
    || Allocate a new FETB
    */
    tfetb = calloc( 1, sizeof( FETB ) );
    if( tfetb == NULL )
    {
        return( FETE_NOMEM );
    }

    /* Initialize FETB */
    tfetb->fd = -1;

    /*
    || clear FETOPEN_CREATE if FETOPEN_READONLY is specified
    */
    if(flags & FETOPEN_READONLY)
    {
        flags&=~FETOPEN_CREATE;
    }
    /*
    || Translate HET create flag to filesystem flag
    */
    oflags = ( ( flags & FETOPEN_CREATE ) ? O_CREAT : 0 );

    omode = "r+b";
    if( !( flags & FETOPEN_READONLY ) )
    {
        tfetb->fd = HOPEN( pathname, O_RDWR | O_BINARY | oflags, S_IRUSR | S_IWUSR | S_IRGRP );
    }

    /* If file is read-only, attempt to open again */
    if ( ( flags & FETOPEN_READONLY ) || (tfetb->fd < 0 && (EROFS == errno || EACCES == errno)))
    {
        omode = "rb";
        tfetb->writeprotect = TRUE;
        tfetb->fd = HOPEN( pathname, O_RDONLY | O_BINARY, S_IRUSR | S_IRGRP );
    }

    /*
    || Error out if both opens failed
    */
    if( tfetb->fd == -1 )
    {
        free( tfetb );
        return( FETE_ERROR );
    }

    /*
    || Associate stream with file descriptor
    */
    tfetb->fh = fdopen( tfetb->fd, omode );

    if( tfetb->fh == NULL )
    {
        rc = errno;
        close( tfetb->fd );
        errno = rc;
        free( tfetb );
        return( FETE_ERROR );
    }

    /*
    || If uninitialized tape, write 2 tapemarks to make it a valid NL tape
    */
    rc = fet_read_header( tfetb, 0L, NULL, NULL );
    if( rc < 0 && rc != FETE_TAPEMARK )
    {
        if( rc != FETE_EOT )
        {
            return( rc );
        }

        rc = fet_tapemark( tfetb );
        if( rc < 0 )
        {
            return( rc );
        }

        rc = fet_tapemark( tfetb );
        if( rc < 0 )
        {
            return( rc );
        }

        tfetb->created = TRUE;
    }
    else
        tfetb->created = FALSE;

    /*
    || Reposition tape to load point
    */
    rc = fet_rewind( tfetb );
    if( rc < 0 )
    {
        return( rc );
    }

    /*
    || Give the caller the new FETB
    */
    *fetb = tfetb;

    return( 0 );

} /* end function fet_open */
Esempio n. 12
0
DLL_EXPORT void log_sethrdcpy(char *filename)
{
    FILE *temp_hrdcpy = logger_hrdcpy;
    FILE *new_hrdcpy;
    int   new_hrdcpyfd = -1;

    if(!filename)
    {
        memset(logger_filename, 0, sizeof(logger_filename));

        if(!logger_hrdcpy)
        {
            WRMSG(HHC02100, "E");
            return;
        }
        else
        {
            obtain_lock(&logger_lock);
            logger_hrdcpy = 0;
            logger_hrdcpyfd = 0;
            release_lock(&logger_lock);
            if ( sysblk.emsg & EMSG_TS )
            {
                struct timeval  now;
                time_t          tt;
                char            hhmmss[10];

                gettimeofday( &now, NULL );
                tt = now.tv_sec;
                strlcpy( hhmmss, ctime(&tt)+11, sizeof(hhmmss) );
                hhmmss[8] = '\0';
                fprintf(temp_hrdcpy, "%s ", hhmmss);
            }
            fprintf(temp_hrdcpy,MSG(HHC02101, "I"));
            fclose(temp_hrdcpy);
            WRMSG(HHC02101, "I");
            return;
        }
    }
    else
    {
        char pathname[MAX_PATH];
        hostpath(pathname, filename, sizeof(pathname));

        memset(logger_filename, 0, sizeof(logger_filename));

        new_hrdcpyfd = HOPEN(pathname,
                             O_WRONLY | O_CREAT | O_TRUNC /* O_SYNC */,
                             S_IRUSR  | S_IWUSR | S_IRGRP);
        if(new_hrdcpyfd < 0)
        {
            WRMSG(HHC02102, "E","open()",strerror(errno));
            return;
        }
        else
        {
            if(!(new_hrdcpy = fdopen(new_hrdcpyfd,"w")))
            {
                WRMSG(HHC02102,"E", "fdopen()", strerror(errno));
                return;
            }
            else
            {
                setvbuf(new_hrdcpy, NULL, _IONBF, 0);

                obtain_lock(&logger_lock);
                logger_hrdcpy = new_hrdcpy;
                logger_hrdcpyfd = new_hrdcpyfd;
                strlcpy(logger_filename, filename, sizeof(logger_filename));
                release_lock(&logger_lock);

                if(temp_hrdcpy)
                {
                    char buf[MAX_PATH+2];
                    char *pzbuf = buf;

                    if ( strchr(filename,SPACE) == NULL )
                        pzbuf = filename;
                    else
                        MSGBUF(buf,"'%s'",filename);

                    if ( sysblk.emsg & EMSG_TS )
                    {
                        struct timeval  now;
                        time_t          tt;
                        char            hhmmss[10];

                        gettimeofday( &now, NULL );
                        tt = now.tv_sec;
                        strlcpy( hhmmss, ctime(&tt)+11, sizeof(hhmmss) );
                        hhmmss[8] = '\0';
                        fprintf(temp_hrdcpy, "%s ", hhmmss);
                    }
                    fprintf(temp_hrdcpy, MSG(HHC02104, "I", pzbuf));
                    fclose(temp_hrdcpy);
                }
            }
        }
    }
}
Esempio n. 13
0
/*-------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
int             i;                      /* Array subscript           */
int             len;                    /* Length of actual read     */
char           *filename;               /* -> Input file name        */
int             infd = -1;              /* Input file descriptor     */
DEVMAP_CTLR     controller;             /* Controller record         */
DEVMAP_DEV      device;                 /* Device record             */
char            output_type[5];         /* Device type to print      */
char           *output_filename;        /* -> filename to print      */
int             more_devices;           /* More devices this ctlr?   */
char            pathname[MAX_PATH];     /* file path in host format  */

    INITIALIZE_UTILITY("dmap2hrc");

    /* Display the program identification message */
    display_version (stderr,
                     "P/390 DEVMAP to Hercules conversion program\n", FALSE);

    /* The only argument is the DEVMAP file name */
    if (argc == 2 && argv[1] != NULL)
    {
        filename = argv[1];
    }
    else
    {
        fprintf (stderr,"Usage: dmap2hrc filename\n");
        exit (1);
    }

    /* Open the devmap file */
    hostpath(pathname, filename, sizeof(pathname));
    infd = hopen(pathname, O_RDONLY | O_BINARY);
    if (infd < 0)
    {
        fprintf (stderr,"dmap2hrc: Error opening %s: %s\n",
                 filename, strerror(errno));
        exit (2);
    }

    /* Skip the file header */
    for (i = 0; i < 9; i++)
    {
        len = read (infd, (void *)&controller, sizeof(DEVMAP_CTLR));
        if (len < 0)
        {
            fprintf (stderr,
                     "dmap2hrc: error reading header records from %s: %s\n",
                     filename, strerror(errno));
            exit (3);
        }
    }

    /* Read records from the input file and convert them */
    while (1)
    {
        /* Read a controller record. */
        len = read (infd, (void *)&controller, sizeof(DEVMAP_CTLR));
        if (len < 0)
        {
            fprintf (stderr,
                     "dmap2hrc: error reading controller record from %s:"
                     " %s\n",
                     filename, strerror(errno));
            exit (4);
        }

        /* Did we finish too soon? */
        if ((len > 0) && (len < (int)sizeof(DEVMAP_CTLR)))
        {
            fprintf (stderr,
                     "dmap2hrc: incomplete controller record on %s\n",
                     filename);
            exit(5);
        }
        
        /* Check for end of file. */
        if (len == 0)
        {
            fprintf(stderr, "End of input file.\n");
            break;
        }
        
        /* Read devices on this controller. */
        more_devices = 1;
        while (more_devices)
        {

            /* Read a device record. */
            len = read (infd, (void *)&device, sizeof(DEVMAP_DEV));
            if (len < 0)
            {
                fprintf (stderr,
                         "dmap2hrc: error reading device record from %s:"
                         " %s\n",
                         filename, strerror(errno));
                exit (6);
            }

            /* Did we finish too soon? */
            if ((len > 0) && (len < (int)sizeof(DEVMAP_DEV)))
            {
                fprintf (stderr,
                         "dmap2hrc: incomplete device record on %s\n",
                         filename);
                exit(7);
            }
        
            /* Check for end of file. */
            if (len == 0)
            {
                fprintf (stderr,"dmap2hrc: premature end of input file\n");
                exit(8);
            }

        /* Is this the dummy device record at the end of the controller's
           set of devices? */
        if (strncmp(device.type,"    ",4) == 0)
        {
            more_devices = 0;
            break;
        }
        
        /* It's a real device. Fix the type so Hercules can use it and
           locate the output filename. */
        strncpy(output_type, device.type, 4);
        output_type[4] = '\0';
        if (isprint(device.parms.disk.volser[0]))
            output_filename = device.parms.disk.filename;
        else output_filename = device.parms.other.filename;
        
        if (strncmp(device.type, "3278", 4) == 0)
        {
            strcpy(output_type, "3270");
            output_filename = "";
        }
        if (strncmp(device.type, "2540", 4) == 0)
            strcpy(output_type, "3505");
        
        /* Emit the Hercules config file entry. */
        printf("%02X%02X    %s",
               device.highaddr, device.lowaddr,
               output_type);
        if (strlen(output_filename) > 0)
            printf("    %s", output_filename);
        puts("");   /* newline */

        } /* end while more_devices) */

    } /* end while (1) */

    /* Close files and exit */
    close (infd);

    return 0;

} /* end function main */
Esempio n. 14
0
/*-------------------------------------------------------------------*/
int ARCH_DEP(load_hmc) (char *fname, int cpu, int clear)
{
REGS   *regs;                           /* -> Regs                   */
FILE   *fp;
char    inputbuff[MAX_PATH];
char   *inputline;
char    filename[MAX_PATH];             /* filename of image file    */
char    pathname[MAX_PATH];             /* pathname of image file    */
U32     fileaddr;
int     rc = 0;                         /* Return codes (work)       */

    /* Get started */
    if (ARCH_DEP(common_load_begin) (cpu, clear) != 0)
        return -1;

    /* The actual IPL proper starts here... */

    regs = sysblk.regs[cpu];    /* Point to IPL CPU's registers */

    if(fname == NULL)                   /* Default ipl from DASD     */
        fname = "HERCULES.ins";         /*   from HERCULES.ins       */

    hostpath(pathname, fname, sizeof(pathname));

    if(!(fname = set_sce_basedir(pathname)))
        return -1;

    /* Construct and check full pathname */
    if(!check_sce_filepath(fname,filename))
    {
        WRMSG(HHC00601,"E",fname,strerror(errno));
        return -1;
    }

    fp = fopen(filename, "r");
    if(fp == NULL)
    {
        WRMSG(HHC00600,"E", fname,"fopen()",strerror(errno));
        return -1;
    }

    do
    {
        inputline = fgets(inputbuff,sizeof(inputbuff),fp);

#if !defined(_MSVC_)
        if(inputline && *inputline == 0x1a)
            inputline = NULL;
#endif /*!defined(_MSVC_)*/

        if(inputline)
        {
            rc = sscanf(inputline,"%" QSTR(MAX_PATH) "s %i",filename,&fileaddr);
        }

        /* If no load address was found load to location zero */
        if(inputline && rc < 2)
            fileaddr = 0;

        if(inputline && rc > 0 && *filename != '*' && *filename != '#')
        {
            hostpath(pathname, filename, sizeof(pathname));

            /* Construct and check full pathname */
            if(!check_sce_filepath(pathname,filename))
            {
                WRMSG(HHC00602,"E",pathname,strerror(errno));
                return -1;
            }

            if( ARCH_DEP(load_main) (filename, fileaddr, 0) < 0 )
            {
                fclose(fp);
                HDC1(debug_cpu_state, regs);
                return -1;
            }
            sysblk.main_clear = sysblk.xpnd_clear = 0;
        }
    } while(inputline);
    fclose(fp);

    /* Finish up... */
    return ARCH_DEP(common_load_finish) (regs);

} /* end function load_hmc */
Esempio n. 15
0
/*-------------------------------------------------------------------*/
static int
process_member (CIFBLK *cif, int noext, DSXTENT extent[],
                char *memname, BYTE *ttr)
{
int             rc;                     /* Return code               */
U16             len;                    /* Record length             */
u_int           trk;                    /* Relative track number     */
U32             cyl;                    /* Cylinder number           */
U8              head;                   /* Head number               */
U8              rec;                    /* Record number             */
BYTE           *buf;                    /* -> Data block             */
FILE           *ofp;                    /* Output file pointer       */
char            ofname[256];            /* Output file name          */
int             offset;                 /* Offset of record in buffer*/
char            card[81];               /* Logical record (ASCIIZ)   */
char            pathname[MAX_PATH];     /* ofname in host format     */

    /* Build the output file name */
    memset (ofname, 0, sizeof(ofname));
    strncpy (ofname, memname, 8);
    string_to_lower (ofname);
    strlcat (ofname, ".mac", sizeof(ofname));

    /* Open the output file */
    hostpath(pathname, ofname, sizeof(pathname));
    ofp = fopen (pathname, (asciiflag? "w" : "wb"));
    if (ofp == NULL)
    {
        FWRMSG( stderr, HHC02468, "E", ofname, "fopen", strerror( errno ));
        return -1;
    }

    /* Point to the start of the member */
    trk = (ttr[0] << 8) | ttr[1];
    rec = ttr[2];

    WRMSG( HHC02469, "I", memname, trk, rec );

    /* Read the member */
    while (1)
    {
        /* Convert relative track to cylinder and head */
        rc = convert_tt (trk, noext, extent, cif->heads, &cyl, &head);
        if (rc < 0) return -1;

//      fprintf (stderr,
//              "CCHHR=%4.4X%4.4X%2.2X\n",
//              cyl, head, rec);

        /* Read a data block */
        rc = read_block (cif, cyl, head, rec, NULL, NULL, &buf, &len);
        if (rc < 0) return -1;

        /* Move to next track if record not found */
        if (rc > 0)
        {
            trk++;
            rec = 1;
            continue;
        }

        /* Exit at end of member */
        if (len == 0) break;

        /* Check length of data block */
        if (len % 80 != 0)
        {
            FWRMSG( stderr, HHC02470, "E", len, cyl, head, rec );
            return -1;
        }

        /* Process each record in the data block */
        for (offset = 0; offset < len; offset += 80)
        {
            if (asciiflag)
            {
                make_asciiz (card, sizeof(card), buf + offset, 72);
                fprintf (ofp, "%s\n", card);
            }
            else
            {
                fwrite (buf+offset, 80, 1, ofp);
            }

            if (ferror(ofp))
            {
                FWRMSG( stderr, HHC02468, "E",
                    ofname, "fwrite", strerror( errno ));
                return -1;
            }
        } /* end for(offset) */

        /* Point to the next data block */
        rec++;

    } /* end while */

    /* Close the output file and exit */
    fclose (ofp);
    return 0;

} /* end function process_member */
Esempio n. 16
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 )
Esempio n. 17
0
/* tab can be pressed anywhere in the command line, so I have to split
   command line
   for example: attach 0a00 3390 volu_ sf=volume1.shadow
   will be divided
   part1 = "attach 0a00 "
   part2 = "volu"
   part3 = " sf=volume1.shadow"
   only part2 can be changed and it must be divided into path and filename
*/
int tab_pressed(char *cmdlinefull, size_t cmdlinelen, int *cmdoffset) {
  struct dirent **namelist;
  int   n, i, j, len, len1, len2;
  int   cmdoff = *(cmdoffset); /* for easy reading of source code */
  char *part1, *part2, *part3;
  char *buff;
  char *filename, *path, *tmp;
  char  result[1024];
  char  pathname[MAX_PATH];
  size_t    bl, pl;
#ifdef _MSVC_
  int within_quoted_string = 0;
  int quote_pos;
#endif

  /* part3 goes from cursor position to the end of line */
  part3 = cmdlinefull + cmdoff;
  /* looking for ' ','@' or '=' backward, starting from cursor offset
     I am not aware of any other delimiters which can be used in hercules */
  /* (except for '"' (double quote) for the MSVC version of herc - Fish) */
#ifdef _MSVC_
  /* determine if tab was pressed within a quoted string */
  for (i=0; i < cmdoff; i++)
      if ('\"' == cmdlinefull[i])
      {
          within_quoted_string = !within_quoted_string;
          quote_pos = i; /* (save position of quote
                         immediately preceding cmdoff) */
      }
  if (within_quoted_string)
    i = quote_pos; /* (the quote is our delimiter) */
  else
#endif
  for (i = cmdoff-1; i>=0; i--)
    if (cmdlinefull[i] == ' '
       || cmdlinefull[i] == '@'
       || cmdlinefull[i] == '=')
      break;
  /* part1 is from beginning to found delimiter (including delimiter itself) */
  part1 = (char*) malloc(i+2);
  strncpy(part1, cmdlinefull, i+1);
  part1[i+1]= '\0';

  /* part2 is the interesting one */
  part2 = (char*)malloc(cmdoff - i);
  strncpy(part2, cmdlinefull + i + 1, cmdoff - i - 1);
  part2[cmdoff - i - 1] = '\0';

  len = (int)strlen(part2);
  /* 3 characters minimum needed, for ./\0 in path. */
  /* (or 4 chars for MSVC if within quoted string, for \"./\0 - Fish) */
#ifdef _MSVC_
  if (within_quoted_string)
  {
    if (len < 3)
      len = 3;
  }
  else
#endif
  if (len < 2)
    len = 2;
  pl = len + 1;
  path = (char*)malloc(pl);
  *path = '\0';
  filename = part2;
  /* is it pure filename or is there whole path ? */
#ifdef _MSVC_
  tmp = strrchr(part2, '\\');
#else
  tmp = strrchr(part2, '/');
#endif
#ifdef _MSVC_
  if (!tmp) tmp = strrchr(part2, '\\');
#endif
  if (tmp != NULL) {
    filename = tmp + 1;
    strncpy(path, part2, strlen(part2)-strlen(filename));
    path[strlen(part2)-strlen(filename)] = '\0';
    tmp[0] = '\0';
  }
  else {
#ifdef _MSVC_
    if (within_quoted_string)
        strlcpy(path,"\".\\",pl);
    else
        strlcpy(path,".\\",pl);
#else
        strlcpy(path,"./",pl);
#endif

  }
  /* this is used in filter function to include only relevant filenames */
  filterarray = filename;

  n = scandir(path, &namelist, filter, alphasort);
  if (n > 0) {
    for (i=0; i<n; i++) {
      struct stat buf;
      char fullfilename[1+MAX_PATH+1];
      /* namelist[i]->d_name contains filtered filenames, check if they are
         directories with stat(), before that create whole path */
      if (tmp != NULL)
         sprintf(fullfilename, "%s%s", path, namelist[i]->d_name);
      else
         sprintf(fullfilename, "%s", namelist[i]->d_name);
#ifdef _MSVC_
      if (within_quoted_string)
        strlcat(fullfilename,"\"",sizeof(fullfilename));
#endif
      /* if it is a directory, add '/' to the end so it can be seen on screen*/
      hostpath(pathname, fullfilename, sizeof(pathname));
      if (stat(pathname,&buf) == 0)
         if (buf.st_mode & S_IFDIR) {
//          strlcat(namelist[i]->d_name,"/",sizeof(namelist[i]->d_name));
// Don't write past end of d_name
// Problem debugged by bb5ch39t
            namelist[i] = realloc(namelist[i], sizeof(struct dirent)
                                + strlen(namelist[i]->d_name) + 2);
            if (namelist[i])
#ifdef _MSVC_
               strlcat(namelist[i]->d_name,"\\",sizeof(namelist[i]->d_name));
#else
               strlcat(namelist[i]->d_name,"/",sizeof(namelist[i]->d_name));
#endif
         }
    }
    /* now check, if filenames have something in common, after a cycle buff
       contains maximal intersection of names */
    bl = (size_t)(strlen(namelist[0]->d_name) + 1);
    buff = (char*)malloc(bl); /* first one */
    strlcpy(buff, namelist[0]->d_name,bl);
    for (i = 1; i < n; i++) {
      len1 = (int)strlen(buff);
      len2 = (int)strlen(namelist[i]->d_name);
      /* check number of characters in shorter one */
      len = len1 > len2 ? len2 : len1;
      for (j = 0; j < len; j++)
      if (buff[j] != namelist[i]->d_name[j]) {
        buff[j] = '\0'; /* end the string where characters are not equal */
        break;
      }
    }
    /* if maximal intersection of filenames is longer then original filename */
    if (strlen(buff) > strlen(filename)) {
      char *fullfilename;
      
      bl = (size_t)(strlen(path) + strlen(buff) + 2);
      fullfilename = (char*)calloc(1,bl);

      /* this test is not useless as path contains './' if there was no path
         in original filename. it is because of scandir function, which
         needs path portion */
      if (tmp != NULL)
         snprintf(fullfilename, bl-1, "%s%s", path, buff);
      else
         snprintf(fullfilename, bl-1, "%s", buff);
      /* construct command line */
      snprintf(result, sizeof(result)-1, "%s%s%s", part1, fullfilename, part3);
      /* move cursor */
      *(cmdoffset) = (int)(strlen(part1) + strlen(fullfilename));
      strlcpy(cmdlinefull, result, cmdlinelen);
      free(fullfilename);
    }
    else 
    {
      /* display all alternatives */
      for (i = 0; i< n; i++)
         logmsg("%s\n", namelist[i]->d_name);
    }
    /* free everything */
    free(buff);
    for (i = 0; i< n; i++)
      free(namelist[i]);
    free(namelist);

  }
  free(part1);
  free(part2);
  free(path);
  return(0);
}
Esempio n. 18
0
/*-------------------------------------------------------------------*/
int open_omatape (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             fd;                     /* File descriptor integer   */
int             rc;                     /* Return code               */
OMATAPE_DESC   *omadesc;                /* -> OMA descriptor entry   */
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;
     }

    /* Read the OMA descriptor file if necessary */
    if (dev->omadesc == NULL)
    {
        rc = read_omadesc (dev);
        if (rc < 0)
        {
            build_senseX(TAPE_BSENSE_TAPELOADFAIL,dev,unitstat,code);
            return -1;
        }
        dev->blockid = 0;
    }

    dev->fenced = 0;

    /* Unit exception if beyond end of tape */
    /* ISW: CHANGED PROCESSING - RETURN UNDEFINITE Tape Marks  */
    /*       NOTE: The last entry in the TDF table is ALWAYS   */
    /*              an EOT Condition                           */
    /*              This is ensured by the TDF reading routine */
#if 0
    if (dev->curfilen >= dev->omafiles)
    {
        logmsg (_("HHCTA250E %4.4X: Attempt to access beyond end of tape %s\n"),
                dev->devnum, dev->filename);

        build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
        return -1;
    }
#else
    if(dev->curfilen>dev->omafiles)
    {
        dev->curfilen=dev->omafiles;
        return(0);
    }
#endif

    /* Point to the current file entry in the OMA descriptor table */
    omadesc = (OMATAPE_DESC*)(dev->omadesc);
    omadesc += (dev->curfilen-1);
    if(omadesc->format=='X')
    {
        return 0;
    }
    if(omadesc->format=='E')
    {
        return 0;
    }

    /* Open the OMATAPE file */
    hostpath(pathname, omadesc->filename, sizeof(pathname));
    fd = hopen(pathname, O_RDONLY | O_BINARY);

    /* Check for successful open */
    if (fd < 0 || lseek (fd, 0, SEEK_END) > LONG_MAX)
    {
        if (fd >= 0)            /* (if open was successful, then it) */
            errno = EOVERFLOW;  /* (must have been a lseek overflow) */

        logmsg (_("HHCTA251E %4.4X: Error opening %s: %s\n"),
                dev->devnum, omadesc->filename, strerror(errno));

        if (fd >= 0)
            close(fd);          /* (close the file if it was opened) */

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

    /* OMA tapes are always read-only */
    dev->readonly = 1;

    /* Store the file descriptor in the device block */
    dev->fd = fd;
    return 0;

} /* end function open_omatape */
Esempio n. 19
0
int main ( int argc, char *argv[])
{
int             fd;
CKDDASD_DEVHDR  devhdr;
CCKDDASD_DEVHDR cdevhdr;
int             heads, cyls, devt;
char            pathname[MAX_PATH];

        hostpath(pathname, argv[1], sizeof(pathname));

        fd = hopen(pathname, O_RDWR|O_BINARY);
        if (fd < 0) return 1;

        read (fd, &devhdr, CKDDASD_DEVHDR_SIZE);
        read (fd, &cdevhdr, CCKDDASD_DEVHDR_SIZE);

        /* --------------------------------------- */
        /* Device header updates                   */
        /* --------------------------------------- */

        /* device identifier */

//      memcpy (devhdr.devid, "CKD_C370", 8);

        /* number of heads per cylinder
           must be in little-endian byte order */

//      devhdr.heads[3] = (heads >> 24) & 0xFF;
//      devhdr.heads[2] = (heads >> 16) & 0xFF;
//      devhdr.heads[1] = (heads >>  8) & 0xFF;
//      devhdr.heads[0] = heads & 0xFF;

        /* device type -- last two digits */

//      devhdr.devtype = devt;      /* eg 0x90 for 3390 */

        /* file sequence number; must be zero for
           compressed ckd dasd emulation */

//      devhdr.fileseq = 0;

        /* highest cylinder on this file; must be zero for
           compressed ckd dasd emulation */

//      devhdr.highcyl[0] = 0;
//      devhdr.highcyl[1] = 0;

//      memset (&devhdr.resv, 0, 492);


        /* --------------------------------------- */
        /* Compressed device header updates        */
        /* --------------------------------------- */

        /* version-release-modification level */

//      cdevhdr.vrm[0] = CCKD_VERSION;
//      cdevhdr.vrm[0] = CCKD_RELEASE;
//      cdevhdr.vrm[0] = CCKD_MODLVL;

        /* options byte */

//      cdevhdr.options = 0;
//      cdevhdr.options |= CCKD_NOFUDGE;
//      cdevhdr.options |= CCKD_BIGENDIAN;
//      cdevhdr.options |= CCKD_OPENED;

        /* lookup table sizes*/

//      cdevhdr.numl1tab = (cyls * heads) >> 8;
//      if ((cyls * heads) & 0xff != 0)
//         cdevhdr.numl1tab++;
//      cdevhdr.numl2tab = 256;

        /* free space header -- set to zeroes to force
           cckdcdsk to rebuild the free space */

//      cdevhdr.size = cdevhdr.used = cdevhdr.free =
//      cdevhdr.free_total = cdevhdr.free_largest =
//      cdevhdr.free_number = cdevhdr.free_imbed = 0;


        /* number of cylinders on the emulated device
           must be in little-endian byte order */

//      cdevhdr.cyls[3] = (cyls >> 24) & 0xFF;
//      cdevhdr.cyls[2] = (cyls >> 16) & 0xFF;
//      cdevhdr.cyls[1] = (cyls >>    8) & 0xFF;
//      cdevhdr.cyls[0] = cyls & 0xFF;

//      cdevhdr.resv1 = 0;

        /* compression algorithm and parameter */

//      cdevhdr.compress = CCKD_COMPRESS_NONE;
//      cdevhdr.compress_parm = 0;

//      cdevhdr.compress = CCKD_COMPRESS_ZLIB;
//      cdevhdr.compress_parm = Z_DEFAULT_COMPRESSION;

//      cdevhdr.compress = CCKD_COMPRESS_BZIP2;
//      cdevhdr.compress_parm = 5;

//      memset (&cdevhdr.resv2, 0, 464);

        lseek (fd, 0, SEEK_SET);
        write (fd, &devhdr, CKDDASD_DEVHDR_SIZE);
        write (fd, &cdevhdr, CCKDDASD_DEVHDR_SIZE);

        close (fd);
        return 0;
}
Esempio n. 20
0
/*-------------------------------------------------------------------*/
int read_omadesc (DEVBLK *dev)
{
int             rc;                     /* Return code               */
int             i;                      /* Array subscript           */
int             pathlen;                /* Length of TDF path name   */
int             tdfsize;                /* Size of TDF file in bytes */
int             filecount;              /* Number of files           */
int             stmt;                   /* TDF file statement number */
int             fd;                     /* TDF file descriptor       */
struct stat     statbuf;                /* TDF file information      */
U32             blklen;                 /* Fixed block length        */
int             tdfpos;                 /* Position in TDF buffer    */
char           *tdfbuf;                 /* -> TDF file buffer        */
char           *tdfrec;                 /* -> TDF record             */
char           *tdffilenm;              /* -> Filename in TDF record */
char           *tdfformat;              /* -> Format in TDF record   */
char           *tdfreckwd;              /* -> Keyword in TDF record  */
char           *tdfblklen;              /* -> Length in TDF record   */
OMATAPE_DESC   *tdftab;                 /* -> Tape descriptor array  */
BYTE            c;                      /* Work area for sscanf      */
char            pathname[MAX_PATH];     /* file path in host format  */

    /* Isolate the base path name of the TDF file */
    for (pathlen = strlen(dev->filename); pathlen > 0; )
    {
        pathlen--;
        if (dev->filename[pathlen-1] == '/') break;
    }
#if 0
    // JCS thinks this is bad
    if (pathlen < 7
        || strncasecmp(dev->filename+pathlen-7, "/tapes/", 7) != 0)
    {
        logmsg (_("HHCTA232I %4.4X: Invalid filename %s: "
                "TDF files must be in the TAPES subdirectory\n"),
                dev->devnum, dev->filename+pathlen);
        return -1;
    }
    pathlen -= 7;
#endif

    /* Open the tape descriptor file */
    hostpath(pathname, dev->filename, sizeof(pathname));
    fd = hopen(pathname, O_RDONLY | O_BINARY);
    if (fd < 0)
    {
        logmsg (_("HHCTA239E %4.4X: Error opening TDF file %s: %s\n"),
                dev->devnum, dev->filename, strerror(errno));
        return -1;
    }

    /* Determine the size of the tape descriptor file */
    rc = fstat (fd, &statbuf);
    if (rc < 0)
    {
        logmsg (_("HHCTA240E %4.4X: File %s fstat error: %s\n"),
                dev->devnum, dev->filename, strerror(errno));
        close (fd);
        return -1;
    }
    tdfsize = statbuf.st_size;

    /* Obtain a buffer for the tape descriptor file */
    tdfbuf = malloc (tdfsize);
    if (tdfbuf == NULL)
    {
        logmsg (_("HHCTA241E %4.4X: Cannot obtain buffer for TDF file %s: %s\n"),
                dev->devnum, dev->filename, strerror(errno));
        close (fd);
        return -1;
    }

    /* Read the tape descriptor file into the buffer */
    rc = read (fd, tdfbuf, tdfsize);
    if (rc < tdfsize)
    {
        logmsg (_("HHCTA242E %4.4X: Error reading TDF file %s: %s\n"),
                dev->devnum, dev->filename, strerror(errno));
        free (tdfbuf);
        close (fd);
        return -1;
    }

    /* Close the tape descriptor file */
    close (fd); fd = -1;

    /* Check that the first record is a TDF header */
    if (memcmp(tdfbuf, "@TDF", 4) != 0)
    {
        logmsg (_("HHCTA243E %4.4X: %s is not a valid TDF file\n"),
                dev->devnum, dev->filename);
        free (tdfbuf);
        return -1;
    }

    /* Count the number of linefeeds in the tape descriptor file
       to determine the size of the descriptor array required */
    for (i = 0, filecount = 0; i < tdfsize; i++)
    {
        if (tdfbuf[i] == '\n') filecount++;
    } /* end for(i) */
    /* ISW Add 1 to filecount to add an extra EOT marker */
    filecount++;

    /* Obtain storage for the tape descriptor array */
    tdftab = (OMATAPE_DESC*)malloc (filecount * sizeof(OMATAPE_DESC));
    if (tdftab == NULL)
    {
        logmsg (_("HHCTA244E %4.4X: Cannot obtain buffer for TDF array: %s\n"),
                dev->devnum, strerror(errno));
        free (tdfbuf);
        return -1;
    }

    /* Build the tape descriptor array */
    for (filecount = 0, tdfpos = 0, stmt = 1; ; filecount++)
    {
        /* Clear the tape descriptor array entry */
        memset (&(tdftab[filecount]), 0, sizeof(OMATAPE_DESC));

        /* Point past the next linefeed in the TDF file */
        while (tdfpos < tdfsize && tdfbuf[tdfpos++] != '\n');
        stmt++;

        /* Exit at end of TDF file */
        if (tdfpos >= tdfsize) break;

        /* Mark the end of the TDF record with a null terminator */
        tdfrec = tdfbuf + tdfpos;
        while (tdfpos < tdfsize && tdfbuf[tdfpos]!='\r'
            && tdfbuf[tdfpos]!='\n') tdfpos++;
        c = tdfbuf[tdfpos];
        if (tdfpos >= tdfsize) break;
        tdfbuf[tdfpos] = '\0';

        /* Exit if TM or EOT record */
        if (strcasecmp(tdfrec, "TM") == 0)
        {
            tdftab[filecount].format='X';
            tdfbuf[tdfpos] = c;
            continue;
        }
        if(strcasecmp(tdfrec, "EOT") == 0)
        {
            tdftab[filecount].format='E';
            break;
        }

        /* Parse the TDF record */
        tdffilenm = strtok (tdfrec, " \t");
        tdfformat = strtok (NULL, " \t");
        tdfreckwd = strtok (NULL, " \t");
        tdfblklen = strtok (NULL, " \t");

        /* Check for missing fields */
        if (tdffilenm == NULL || tdfformat == NULL)
        {
            logmsg (_("HHCTA245E %4.4X: Filename or format missing in "
                    "line %d of file %s\n"),
                    dev->devnum, stmt, dev->filename);
            free (tdftab);
            free (tdfbuf);
            return -1;
        }

        /* Check that the file name is not too long */
        if (pathlen + 1 + strlen(tdffilenm)
                > sizeof(tdftab[filecount].filename) - 1)
        {
            logmsg (_("HHCTA246E %4.4X: Filename %s too long in "
                    "line %d of file %s\n"),
                    dev->devnum, tdffilenm, stmt, dev->filename);
            free (tdftab);
            free (tdfbuf);
            return -1;
        }

        /* Convert the file name to Unix format */
        for (i = 0; i < (int)strlen(tdffilenm); i++)
        {
            if (tdffilenm[i] == '\\')
                tdffilenm[i] = '/';
/* JCS */
//            else
//                tdffilenm[i] = tolower(tdffilenm[i]);
        } /* end for(i) */

        /* Prefix the file name with the base path name and
           save it in the tape descriptor array */
        /* but only if the filename lacks a leading slash - JCS  */
/*
        strncpy (tdftab[filecount].filename, dev->filename, pathlen);
        if (tdffilenm[0] != '/')
            stlrcat ( tdftab[filecount].filename, "/", sizeof(tdftab[filecount].filename) );
        strlcat ( tdftab[filecount].filename, tdffilenm, sizeof(tdftab[filecount].filename) );
*/
        tdftab[filecount].filename[0] = 0;

        if ((tdffilenm[0] != '/') && (tdffilenm[1] != ':'))
        {
            strncpy (tdftab[filecount].filename, dev->filename, pathlen);
            strlcat (tdftab[filecount].filename, "/", sizeof(tdftab[filecount].filename) );
        }

        strlcat (tdftab[filecount].filename, tdffilenm, sizeof(tdftab[filecount].filename) );

        /* Check for valid file format code */
        if (strcasecmp(tdfformat, "HEADERS") == 0)
        {
            tdftab[filecount].format = 'H';
        }
        else if (strcasecmp(tdfformat, "TEXT") == 0)
        {
            tdftab[filecount].format = 'T';
        }
        else if (strcasecmp(tdfformat, "FIXED") == 0)
        {
            /* Check for RECSIZE keyword */
            if (tdfreckwd == NULL
                || strcasecmp(tdfreckwd, "RECSIZE") != 0)
            {
                logmsg (_("HHCTA247E %4.4X: RECSIZE keyword missing in "
                        "line %d of file %s\n"),
                        dev->devnum, stmt, dev->filename);
                free (tdftab);
                free (tdfbuf);
                return -1;
            }

            /* Check for valid fixed block length */
            if (tdfblklen == NULL
                || sscanf(tdfblklen, "%u%c", &blklen, &c) != 1
                || blklen < 1 || blklen > MAX_BLKLEN)
            {
                logmsg (_("HHCTA248E %4.4X: Invalid record size %s in "
                        "line %d of file %s\n"),
                        dev->devnum, tdfblklen, stmt, dev->filename);
                free (tdftab);
                free (tdfbuf);
                return -1;
            }

            /* Set format and block length in descriptor array */
            tdftab[filecount].format = 'F';
            tdftab[filecount].blklen = blklen;
        }
        else
        {
            logmsg (_("HHCTA249E %4.4X: Invalid record format %s in "
                    "line %d of file %s\n"),
                    dev->devnum, tdfformat, stmt, dev->filename);
            free (tdftab);
            free (tdfbuf);
            return -1;
        }
        tdfbuf[tdfpos] = c;
    } /* end for(filecount) */
    /* Force an EOT as last entry (filecount is correctly adjusted here) */
    tdftab[filecount].format='E';

    /* Save the file count and TDF array pointer in the device block */
    dev->omafiles = filecount+1;
    dev->omadesc = tdftab;

    /* Release the TDF file buffer and exit */
    free (tdfbuf);
    return 0;

} /* end function read_omadesc */
Esempio n. 21
0
/*-------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
char           *pgm;                    /* -> Program name           */
int             ckddasd=-1;             /* 1=CKD  0=FBA              */
int             rc;                     /* Return code               */
int             quiet=0;                /* 1=Don't display status    */
int             comp=255;               /* Compression algorithm     */
int             cyls=-1, blks=-1;       /* Size of output file       */
int             lfs=0;                  /* 1=Create 1 large file     */
int             alt=0;                  /* 1=Create alt cyls         */
int             r=0;                    /* 1=Replace output file     */
int             in=0, out=0;            /* Input/Output file types   */
int             fd;                     /* Input file descriptor     */
char           *ifile, *ofile;          /* -> Input/Output file names*/
char           *sfile=NULL;             /* -> Input shadow file name */
CIFBLK         *icif, *ocif;            /* -> Input/Output CIFBLK    */
DEVBLK         *idev, *odev;            /* -> Input/Output DEVBLK    */

CKDDEV         *ckd=NULL;               /* -> CKD device table entry */
FBADEV         *fba=NULL;               /* -> FBA device table entry */
int             i, n, max;              /* Loop index, limits        */
BYTE            unitstat;               /* Device unit status        */
char            msgbuf[512];            /* Message buffer            */
size_t          fba_bytes_remaining=0;  /* FBA bytes to be copied    */
int             nullfmt = CKDDASD_NULLTRK_FMT0; /* Null track format */
char            pathname[MAX_PATH];     /* file path in host format  */
char            pgmpath[MAX_PATH];      /* prog path in host format  */

    INITIALIZE_UTILITY("dasdcopy");

    /* 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, "ckd2cckd") == 0)
    {
        in = CKD;
        out = CCKD;
    }
    else if (strcmp(pgm, "cckd2ckd") == 0)
    {
        in = CCKD;
        out = CKD;
    }
    else if (strcmp(pgm, "fba2cfba") == 0)
    {
        in = FBA;
        out = CFBA;
    }
    else if (strcmp(pgm, "cfba2fba") == 0)
    {
        in = CFBA;
        out = FBA;
    }

    /* Process the arguments */
    for (argc--, argv++ ; argc > 0 ; argc--, argv++)
    {
        if (argv[0][0] != '-') break;
        if (strcmp(argv[0], "-v") == 0)
        {
             snprintf (msgbuf, 512, _("Hercules %s copy program "), pgm);
             display_version (stderr, msgbuf, FALSE);
             return 0;
        }
        else if (strcmp(argv[0], "-h") == 0)
        {
            syntax(pgm);
            return 0;
        }
        else if (strcmp(argv[0], "-q") == 0
              || strcmp(argv[0], "-quiet") == 0)
            quiet = 1;
        else if (strcmp(argv[0], "-r") == 0)
            r = 1;
#ifdef CCKD_COMPRESS_ZLIB
        else if (strcmp(argv[0], "-z") == 0)
            comp = CCKD_COMPRESS_ZLIB;
#endif
#ifdef CCKD_COMPRESS_BZIP2
        else if (strcmp(argv[0], "-bz2") == 0)
            comp = CCKD_COMPRESS_BZIP2;
#endif
        else if (strcmp(argv[0], "-0") == 0)
            comp = CCKD_COMPRESS_NONE;
        else if ((strcmp(argv[0], "-cyl") == 0
               || strcmp(argv[0], "-cyls") == 0) && cyls < 0)
        {
            if (argc < 2 || (cyls = atoi(argv[1])) < 0)
                return syntax(pgm);
            argc--; argv++;
        }
        else if ((strcmp(argv[0], "-blk") == 0
               || strcmp(argv[0], "-blks") == 0) && blks < 0)
        {
            if (argc < 2 || (blks = atoi(argv[1])) < 0)
                return syntax(pgm);
            argc--; argv++;
        }
        else if (strcmp(argv[0], "-a") == 0
              || strcmp(argv[0], "-alt") == 0
              || strcmp(argv[0], "-alts") == 0)
            alt = 1;
        else if (strcmp(argv[0], "-lfs") == 0)
            lfs = 1;
        else if (out == 0 && strcmp(argv[0], "-o") == 0)
        {
            if (argc < 2 || out != 0) return syntax(pgm);
            if (strcasecmp(argv[1], "ckd") == 0)
                out = CKD;
            else if (strcasecmp(argv[1], "cckd") == 0)
                out = CCKD;
            else if (strcasecmp(argv[1], "fba") == 0)
                out = FBA;
            else if (strcasecmp(argv[1], "cfba") == 0)
                out = CFBA;
            else
                return syntax(pgm);
            argc--; argv++;
        }
        else
            return syntax(pgm);
    }

    /* Get the file names:
       input-file [sf=shadow-file] output-file   */
    if (argc < 2 || argc > 3) return syntax(pgm);
    ifile = argv[0];
    if (argc < 3)
        ofile = argv[1];
    else
    {
        if (strlen(argv[1]) < 4 || memcmp(argv[1], "sf=", 3))
            return syntax(pgm);
        sfile = argv[1];
        ofile = argv[2];
    }

    /* If we don't know what the input file is then find out */
    if (in == 0)
    {
        BYTE buf[8];
        hostpath(pathname, ifile, sizeof(pathname));
        fd = hopen(pathname, O_RDONLY|O_BINARY);
        if (fd < 0)
        {
            fprintf (stderr, _("HHCDC001E %s: %s open error: %s\n"),
                     pgm, ifile, strerror(errno));
            return -1;
        }
        rc = read (fd, buf, 8);
        if (rc < 8)
        {
            fprintf (stderr, _("HHCDC002E %s: %s read error: %s\n"),
                     pgm, ifile, strerror(errno));
            return -1;
        }
        if (memcmp(buf, "CKD_P370", 8) == 0)
            in = CKD;
        else if (memcmp(buf, "CKD_C370", 8) == 0)
            in = CCKD;
        else if (memcmp(buf, "FBA_C370", 8) == 0)
            in = CFBA;
        else
            in = FBA;
        close (fd);
    }

    /* If we don't know what the output file type is
       then derive it from the input file type */
    if (out == 0)
    {
        switch (in) {
        case CKD:  if (!lfs) out = CCKD;
                   else out = CKD;
                   break;
        case CCKD: if (comp == 255) out = CKD;
                   else out = CCKD;
                   break;
        case FBA:  if (!lfs) out = CFBA;
                   else out = FBA;
                   break;
        case CFBA: if (comp == 255) out = FBA;
                   else out = CFBA;
                   break;
        }
    }

    /* Set default compression if out file is to be compressed */
    if (comp == 255 && (out & COMPMASK))
#ifdef CCKD_COMPRESS_ZLIB
        comp = CCKD_COMPRESS_ZLIB;
#else
        comp = CCKD_COMPRESS_NONE;
#endif

    /* Perform sanity checks on the options */
    if ((in & CKDMASK) && !(out & CKDMASK)) return syntax(pgm);
    if ((in & FBAMASK) && !(out & FBAMASK)) return syntax(pgm);
    if (sfile && !(in & COMPMASK)) return syntax(pgm);
    if (comp != 255 && !(out & COMPMASK)) return syntax(pgm);
    if (lfs && (out & COMPMASK)) return syntax(pgm);
    if (cyls >= 0 && !(in & CKDMASK)) return syntax(pgm);
    if (blks >= 0 && !(in & FBAMASK)) return syntax(pgm);
    if (!(in & CKDMASK) && alt) return syntax(pgm);

    /* Set the type of processing (ckd or fba) */
    ckddasd = (in & CKDMASK);

    /* Open the input file */
    if (ckddasd)
        icif = open_ckd_image (ifile, sfile, O_RDONLY|O_BINARY, 0);
    else
        icif = open_fba_image (ifile, sfile, O_RDONLY|O_BINARY, 0);
    if (icif == NULL)
    {
        fprintf (stderr, _("HHCDC003E %s: %s open failed\n"), pgm, ifile);
        return -1;
    }
    idev = &icif->devblk;
    if (idev->oslinux) nullfmt = CKDDASD_NULLTRK_FMT2;

    /* Calculate the number of tracks or blocks to copy */
    if (ckddasd)
    {
        if (cyls < 0) cyls = idev->ckdcyls;
        else if (cyls == 0) cyls = (idev->hnd->used)(idev);
        ckd = dasd_lookup (DASD_CKDDEV, NULL, idev->devtype, cyls);
        if (ckd == NULL)
        {
            fprintf (stderr, _("HHCDC004E %s: ckd lookup failed for %4.4X "
                     "cyls %d\n"),
                     pgm, idev->devtype, cyls);
            close_image_file (icif);
            return -1;
        }
        if (out == CCKD) cyls = ckd->cyls;
        if (cyls <= ckd->cyls && alt) cyls = ckd->cyls + ckd->altcyls;
        n = cyls * idev->ckdheads;
        max = idev->ckdtrks;
        if (max < n && out == CCKD) n = max;
    }
    else
    {
        fba_bytes_remaining = idev->fbanumblk * idev->fbablksiz;
        if (blks < 0) blks = idev->fbanumblk;
        else if (blks == 0) blks = (idev->hnd->used)(idev);
        fba = dasd_lookup (DASD_FBADEV, NULL, idev->devtype, blks);
        if (fba == NULL)
        {
            fprintf (stderr, _("HHCDC005E %s: fba lookup failed, blks %d\n"),
                     pgm, blks);
            close_image_file (icif);
            return -1;
        }
        n = blks;
        max = idev->fbanumblk;
        if (max < n && out == CFBA) n = max;
        n = (n + FBA_BLKS_PER_GRP - 1) / FBA_BLKS_PER_GRP;
        max = (max + FBA_BLKS_PER_GRP - 1) / FBA_BLKS_PER_GRP;
    }

    /* Create the output file */
    if (ckddasd)
        rc = create_ckd(ofile, idev->devtype, idev->ckdheads,
                        ckd->r1, cyls, "", comp, lfs, 1+r, nullfmt, 0);
    else
        rc = create_fba(ofile, idev->devtype, fba->size,
                        blks, "", comp, lfs, 1+r, 0);
    if (rc < 0)
    {
        fprintf (stderr, _("HHCDC006E %s: %s create failed\n"), pgm, ofile);
        close_image_file (icif);
        return -1;
    }

    /* Open the output file */
    if (ckddasd)
        ocif = open_ckd_image (ofile, NULL, O_RDWR|O_BINARY, 1);
    else
        ocif = open_fba_image (ofile, NULL, O_RDWR|O_BINARY, 1);
    if (ocif == NULL)
    {
        fprintf (stderr, _("HHCDC007E %s: %s open failed\n"), pgm, ofile);
        close_image_file (icif);
        return -1;
    }
    odev = &ocif->devblk;

    /* Copy the files */
#ifdef EXTERNALGUI
    if (extgui)
        /* Notify GUI of total #of tracks or blocks being copied... */
        fprintf (stderr, "TRKS=%d\n", n);
    else
#endif /*EXTERNALGUI*/
    if (!quiet) printf ("  %3d%% %7d of %d", 0, 0, n);
    for (i = 0; i < n; i++)
    {
        /* Read a track or block */
        if (ckddasd)
        {
            if (i < max)
                rc = (idev->hnd->read)(idev, i, &unitstat);
            else
            {
                memset (idev->buf, 0, idev->ckdtrksz);
                rc = nulltrk(idev->buf, i, idev->ckdheads, nullfmt);
            }
        }
        else
        {
            if (i < max)
                rc = (idev->hnd->read)(idev, i, &unitstat);
            else
                memset (idev->buf, 0, FBA_BLKGRP_SIZE);
                rc = 0;
        }
        if (rc < 0)
        {
            fprintf (stderr, _("HHCDC008E %s: %s read error %s %d "
                               "stat=%2.2X, null %s substituted\n"),
                     pgm, ifile, ckddasd ? "track" : "block", i, unitstat,
                     ckddasd ? "track" : "block");
            if (ckddasd)
                nulltrk(idev->buf, i, idev->ckdheads, nullfmt);
            else
                memset (idev->buf, 0, FBA_BLKGRP_SIZE);
            if (!quiet)
            {
                printf (_("  %3d%% %7d of %d"), 0, 0, n);
                status (i, n);
            }
        }

        /* Write the track or block just read */
        if (ckddasd)
        {
            rc = (odev->hnd->write)(odev, i, 0, idev->buf,
                      idev->ckdtrksz, &unitstat);
        }
        else
        {
            if (fba_bytes_remaining >= (size_t)idev->buflen)
            {
                rc = (odev->hnd->write)(odev,  i, 0, idev->buf,
                          idev->buflen, &unitstat);
                fba_bytes_remaining -= (size_t)idev->buflen;
            }
            else
            {
                ASSERT(fba_bytes_remaining > 0 && (i+1) >= n);
                rc = (odev->hnd->write)(odev,  i, 0, idev->buf,
                          (int)fba_bytes_remaining, &unitstat);
                fba_bytes_remaining = 0;
            }
        }
        if (rc < 0)
        {
            fprintf (stderr, _("HHCDC009E %s: %s write error %s %d "
                               "stat=%2.2X\n"),
                     pgm, ofile, ckddasd ? "track" : "block", i, unitstat);
            close_image_file(icif); close_image_file(ocif);
            return -1;
        }

        /* Update the status indicator */
        if (!quiet) status (i+1, n);
    }

    close_image_file(icif); close_image_file(ocif);
    if (!quiet) printf (_("\r"));
    printf (_("HHCDC010I %s successfully completed.\n"), pgm);
    return 0;
}
Esempio n. 22
0
/*-------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
    int             i;                      /* Index                     */
    int             rc;                     /* Return code               */
    int             level=1;                /* Chkdsk level checking     */
    int             ro=0;                   /* 1=Open readonly           */
    int             force=0;                /* 1=Check if OPENED bit on  */
    CCKDDASD_DEVHDR cdevhdr;                /* Compressed CKD device hdr */
    DEVBLK          devblk;                 /* DEVBLK                    */
    DEVBLK         *dev=&devblk;            /* -> DEVBLK                 */

    INITIALIZE_UTILITY("cckdcdsk");

    /* parse the arguments */
    for (argc--, argv++ ; argc > 0 ; argc--, argv++)
    {
        if(**argv != '-') break;

        switch(argv[0][1])
        {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
            if (argv[0][2] != '\0') return syntax ();
            level = (argv[0][1] & 0xf);
            break;
        case 'f':
            if (argv[0][2] != '\0') return syntax ();
            force = 1;
            break;
        case 'r':
            if (argv[0][2] == 'o' && argv[0][3] == '\0')
                ro = 1;
            else return syntax ();
            break;
        case 'v':
            if (argv[0][2] != '\0') return syntax ();
            display_version
            (stderr, "Hercules cckd chkdsk program ", FALSE);
            return 0;
        default:
            return syntax ();
        }
    }

    if (argc < 1) return syntax ();

    for (i = 0; i < argc; i++)
    {
        memset (dev, 0, sizeof(DEVBLK));
        dev->batch = 1;

        /* open the file */
        hostpath(dev->filename, argv[i], sizeof(dev->filename));
        dev->fd = hopen(dev->filename, ro ? O_RDONLY|O_BINARY : O_RDWR|O_BINARY);
        if (dev->fd < 0)
        {
            cckdumsg (dev, 700, "open error: %s\n", strerror(errno));
            continue;
        }

        /* Check CCKD_OPENED bit if -f not specified */
        if (!force)
        {
            if (lseek (dev->fd, CCKD_DEVHDR_POS, SEEK_SET) < 0)
            {
                cckdumsg (dev, 702, "lseek error offset 0x%" I64_FMT "x: %s\n",
                          (long long)CCKD_DEVHDR_POS, strerror(errno));
                close (dev->fd);
                continue;
            }
            if ((rc = read (dev->fd, &cdevhdr, CCKD_DEVHDR_SIZE)) < CCKD_DEVHDR_SIZE)
            {
                cckdumsg (dev, 703, "read error rc=%d offset 0x%" I64_FMT "x len %d: %s\n",
                          rc, (long long)CCKD_DEVHDR_POS, CCKD_DEVHDR_SIZE,
                          rc < 0 ? strerror(errno) : "incomplete");
                close (dev->fd);
                continue;
            }
            if (cdevhdr.options & CCKD_OPENED)
            {
                cckdumsg (dev, 707, "OPENED bit is on, use -f\n");
                close (dev->fd);
                continue;
            }
        } /* if (!force) */

        rc = cckd_chkdsk (dev, level);

        close (dev->fd);
    } /* for each arg */

    return 0;
}
Esempio n. 23
0
int main(int argc, char **argv) {

    DADSM    dadsm;                  // DADSM workarea
    FILE    *fout = NULL;           // output file
    CIFBLK  *cif;
    int      dsn_recs_written = 0, bail, dsorg, rc;
    char     pathname[MAX_PATH];

    fprintf(stderr, "dasdseq %s (C) Copyright 1999-2010 Roger Bowler\n"
        "Portions (C) Copyright 2001-2010 James M. Morrison\n", VERSION);
    if (debug) fprintf(stderr, "DEBUG enabled\n");

//  Parse command line

    memset(&dadsm, 0, sizeof(dadsm));           // init DADSM workarea
    rc = parsecmd(argc, argv, &dadsm);
    if (rc) exit(rc);

//  Open CKD image

    cif = open_ckd_image(din, sfn, O_RDONLY | O_BINARY, 0);
    if (!cif) {
        fprintf(stderr, "dasdseq unable to open image file %s\n", din);
        exit(20);
    }

//  Unless -abs specified (in which case trust the expert user):
//  Retrieve extent information for the dataset
//  Display dataset attributes
//  Verify dataset has acceptable attributes

    if (!absvalid) {
        rc = dadsm_setup(cif, &argdsn, &dadsm, local_verbose);
        if (rc) {
            close_ckd_image(cif);
            exit(rc);
        }
        if (local_verbose) {
            fprintf(stderr, "\n"); 
            showf1(stderr, &dadsm.f1buf, dadsm.f1ext, copy_verbose);
            fprintf(stderr, "\n");
        }
        bail = 1;
        dsorg = (dadsm.f1buf.ds1dsorg[0] << 8) | (dadsm.f1buf.ds1dsorg[1]); 
        if (dsorg & (DSORG_PS * 256)) {
            if ((dadsm.f1buf.ds1recfm & RECFM_FORMAT) == RECFM_FORMAT_F) 
                bail = 0;
            if ((dadsm.f1buf.ds1recfm & RECFM_FORMAT) == RECFM_FORMAT_V) {
                bail = 1;               // not yet
                fprintf(stderr, "dasdseq only supports RECFM=F[B]\n");
            }
        } else 
            fprintf(stderr, "dasdseq only supports DSORG=PS datasets\n");
        if (bail) {
            close_ckd_image(cif);
            exit(21);
        }
    }

//  Open output dataset (EBCDIC requires binary open)

    hostpath(pathname, argdsn, sizeof(pathname));

    fout = fopen(pathname, (tran_ascii) ? "wb" : "w");
    if (fout == NULL) {
        fprintf(stderr, "dasdseq unable to open output file %s, %s\n",
                argdsn, strerror(errno));
        close_ckd_image(cif);
        exit(22);
    }
    if (local_verbose)
        fprintf(stderr, "dasdseq writing %s\n", argdsn);

//  Write dasd data to output dataset

    dsn_recs_written = fbcopy(fout, cif, &dadsm, tran_ascii, copy_verbose);
    if (dsn_recs_written == -1)
        fprintf(stderr, "dasdseq error processing %s\n", argdsn);
    else
        fprintf(stderr, "dasdseq wrote %d records to %s\n", 
                dsn_recs_written, argdsn);

//  Close output dataset, dasd image and return to caller

    fclose(fout);
    if (local_verbose > 2) fprintf(stderr, "CLOSED %s\n", argdsn);
    if (local_verbose > 3) {
        fprintf(stderr, "CIFBLK\n");
        data_dump((void *) cif, sizeof(CIFBLK));
    }
    close_ckd_image(cif);
    if (local_verbose > 2) fprintf(stderr, "CLOSED image\n");
    return rc;

} /* main */
Esempio n. 24
0
/*-------------------------------------------------------------------*/
static IFD 
open_input_image (char *ifname, U16 *devt, U32 *vcyls,
                U32 *itrkl, BYTE **itrkb, BYTE *volser)
{
int             rc;                     /* Return code               */
H30CKD_TRKHDR   h30trkhdr;              /* Input track header        */
IFD             ifd;                    /* Input file descriptor     */
int             len;                    /* Length of input           */
U16             code;                   /* Device type code          */
U16             dt;                     /* Device type               */
U32             cyls;                   /* Device size (pri+alt cyls)*/
U32             alts;                   /* Number of alternate cyls  */
BYTE           *itrkbuf;                /* -> Input track buffer     */
U32             itrklen;                /* Input track length        */
BYTE           *pbuf;                   /* Current byte in input buf */
BYTE            klen;                   /* Key length                */
U16             dlen;                   /* Data length               */
BYTE           *kptr;                   /* -> Key in input buffer    */
BYTE           *dptr;                   /* -> Data in input buffer   */
U32             cyl;                    /* Cylinder number           */
U32             head;                   /* Head number               */
BYTE            rec;                    /* Record number             */
char            pathname[MAX_PATH];     /* file path in host format  */

    hostpath(pathname, (char *)ifname, sizeof(pathname));

    /* Open the HDR-30 CKD image file */
  #if defined(HAVE_LIBZ)
    if (strcmp(ifname, "-") == 0)
        ifd = gzdopen (STDIN_FILENO, "rb");
    else
        ifd = gzopen (pathname, "rb");

    if (ifd == NULL)
    {
        fprintf (stderr,
                "Cannot open %s: %s\n",
                ifname,
                errno == 0 ? "gzopen error" : strerror(errno));
        EXIT(3);
    }
  #else /*!defined(HAVE_LIBZ)*/
    if (strcmp(ifname, "-") == 0)
        ifd = STDIN_FILENO;
    else
    {
        ifd = hopen(pathname, O_RDONLY | O_BINARY);

        if (ifd < 0)
        {
            fprintf (stderr,
                    "Cannot open %s: %s\n",
                    ifname, strerror(errno));
            EXIT(3);
        }
    }
  #endif /*!defined(HAVE_LIBZ)*/

    /* Read the first track header */
    read_input_data (ifd, ifname, (BYTE*)&h30trkhdr,
                    H30CKD_TRKHDR_SIZE, 0);

  #if !defined(HAVE_LIBZ)
    /* Reject input if compressed and we lack gzip support */
    if (memcmp(h30trkhdr.devcode, gz_magic_id, sizeof(gz_magic_id)) == 0) 
    {
        fprintf (stderr,
                "Input file %s appears to be a .gz file\n"
                "but this program was compiled without compression support\n",
                ifname);
        EXIT(3);
    }
  #endif /*!defined(HAVE_LIBZ)*/

    /* Reject input if it is already in CKD or CCKD format */
    if (memcmp((BYTE*)&h30trkhdr, ckd_ident, sizeof(ckd_ident)) == 0)
    {
        fprintf (stderr,
                "Input file %s is already in CKD format, use dasdcopy\n",
                ifname);
        EXIT(3);
    }

    /* Extract the device type code from the track header */
    FETCH_HW (code, h30trkhdr.devcode);

    /* Determine the input device type and size from the device code */
    switch (code) {
    case 0x01: dt=0x3330; cyls=411; alts=7; break;      /* 3330      */
    case 0x02: dt=0x3330; cyls=815; alts=7; break;      /* 3330-11   */
    case 0x03: dt=0x3340; cyls=351; alts=1; break;      /* 3340-35   */
    case 0x04: dt=0x3340; cyls=701; alts=1; break;      /* 3340-70   */
    case 0x05: dt=0x3350; cyls=562; alts=7; break;      /* 3350      */
    case 0x06: dt=0x3375; cyls=962; alts=3; break;      /* 3375      */
    case 0x08: dt=0x3380; cyls=888; alts=3; break;      /* 3380-A,D,J*/
    case 0x09: dt=0x3380; cyls=1774; alts=4; break;     /* 3380-E    */
    case 0x0A: dt=0x3380; cyls=2660; alts=5; break;     /* 3380-K    */
    case 0x0B: dt=0x3390; cyls=1117; alts=4; break;     /* 3390-1    */
    case 0x0C: dt=0x3390; cyls=2230; alts=4; break;     /* 3390-2    */
    case 0x0D: dt=0x3390; cyls=3343; alts=4; break;     /* 3390-3    */
    case 0x12: dt=0x2314; cyls=203; alts=3; break;      /* 2314      */
    case 0x13: dt=0x3390; cyls=10038; alts=21; break;   /* 3390-9    */
    case 0x14: dt=0x9345; cyls=1454; alts=14; break;    /* 9345-1    */
    case 0x15: dt=0x9345; cyls=2170; alts=14; break;    /* 9345-2    */
    default:
        fprintf (stderr,
                "Unknown device code %4.4X" \
                " at offset 00000000 in input file %s\n",
                code, ifname);
        EXIT(3);
    } /* end switch(code) */

    /* Use the device type to determine the input image track size */
    switch (dt) {
    case 0x2314: itrklen = 0x2000; break;
    case 0x3330: itrklen = 0x3400; break;
    case 0x3340: itrklen = 0x2400; break;
    case 0x3350: itrklen = 0x4C00; break;
    case 0x3375: itrklen = 0x9000; break;
    case 0x3380: itrklen = 0xBC00; break;
    case 0x3390: itrklen = 0xE400; break;
    case 0x9345: itrklen = 0xBC00; break;
    default:
        fprintf (stderr, "Unknown device type: %4.4X\n", dt);
        EXIT(3);
    } /* end switch(dt) */

    /* Obtain the input track buffer */
    itrkbuf = malloc (itrklen);
    if (itrkbuf == NULL)
    {
        fprintf (stderr,
                "Cannot obtain storage for input track buffer: %s\n",
                strerror(errno));
        EXIT(3);
    }

    /* Copy the first track header to the input track buffer */
    memcpy (itrkbuf, &h30trkhdr, H30CKD_TRKHDR_SIZE);

    /* Read the remainder of the first track into the buffer */
    read_input_data (ifd, ifname,
                     itrkbuf + H30CKD_TRKHDR_SIZE,
                     itrklen - H30CKD_TRKHDR_SIZE,
                     H30CKD_TRKHDR_SIZE);

    /* Initialize the volume serial number */
    strcpy ((char *)volser, "(NONE)");

    /* Search for volume label in record 3 of first track */
    pbuf = itrkbuf + H30CKD_TRKHDR_SIZE;
    len = itrklen - H30CKD_TRKHDR_SIZE;
    while (1)
    {
        /* Find next input record */
        rc = find_input_record (itrkbuf, &pbuf, &len,
                &klen, &kptr, &dlen, &dptr,
                &cyl, &head, &rec);
     
        /* Give up if error or end of track */
        if (rc != 0) break;

        /* Process when record 3 is found */
        if (cyl == 0 && head == 0 && rec == 3)
        {
            /* Extract volser if it is a volume label */
            if (klen == 4 && memcmp(kptr, ebcdicvol1, 4) == 0
            && dlen == 80 && memcmp(dptr, ebcdicvol1, 4) == 0)
                make_asciiz ((char *)volser, 7, dptr+4, 6);
            break;
        }
    } /* end while */

    /* Set output variables and return the input file descriptor */
    *devt = dt;
    *vcyls = cyls - alts;
    *itrkl = itrklen;
    *itrkb = itrkbuf;
    return ifd;

} /* end function open_input_image */
Esempio n. 25
0
/*-------------------------------------------------------------------*/
int http_command(int argc, char *argv[])
{
    int rc = 0;

    if ( !http_struct_init )
    {
        memset(&http_serv,0,sizeof(HTTP_SERV));
        initialize_condition( &http_serv.http_wait_shutdown );
        initialize_lock( &http_serv.http_lock_shutdown );
        initialize_lock( &http_lock_root );
        http_struct_init = TRUE;
    }

    http_serv.httpstmtold = FALSE;

    if ( argc == 2 && CMD(argv[0],rootx,4) &&
         ( ( strlen(argv[0]) == 5 && argv[2] != NULL && strcmp(argv[2],"httproot") == 0 ) ||
           ( strlen(argv[0]) == 4 ) ) )
    {
        if ( strlen(argv[0]) == 5 )
        {
            http_serv.httpstmtold = TRUE;
        }

        obtain_lock( &http_lock_root );
        if (http_serv.httproot)
        {
            free(http_serv.httproot);
            http_serv.httproot = NULL;
        }

        if ( strlen(argv[1]) > 0 )
        {
            char    pathname[MAX_PATH];

            hostpath(pathname, argv[1], sizeof(pathname));

            if ( pathname[strlen(pathname)-1] != PATHSEPC )
                strlcat( pathname, PATHSEPS, sizeof(pathname) );

            http_serv.httproot = strdup(pathname);
        }
        release_lock( &http_lock_root );

        http_root();

        if ( MLVL(VERBOSE) )
            WRMSG(HHC02204, "I", http_serv.httpstmtold ? "httproot": "root",
                        http_serv.httproot ? http_serv.httproot : "<not specified>");

        if ( http_serv.httpstmtold )
            http_startup(TRUE);

        rc = 0;
    }
    else if ( (argc == 2 || argc == 3 || argc == 5) && CMD(argv[0],portx,4) &&
              ( ( strlen(argv[0]) == 5 && argv[5] != NULL && strcmp(argv[5],"httpport") == 0 ) ||
                ( strlen(argv[0]) == 4 ) ) )
    {
        if ( strlen(argv[0]) == 5 )
        {
            http_serv.httpstmtold = TRUE;
        }

        if ( sysblk.httptid != 0 )
        {
            WRMSG( HHC01812, "E" );
            rc = -1;
        }
        else
        {
            char c;

            if (sscanf(argv[1], "%hu%c", &http_serv.httpport, &c) != 1
                    || http_serv.httpport == 0
                    || (http_serv.httpport < 1024 && http_serv.httpport != 80) )
            {
                rc = -1;
            }
            if ( rc >= 0 && argc == 3 && CMD(argv[2],noauth,6) )
            {
                http_serv.httpauth = 0;
            }
            else if ( rc >=0 && argc == 5 && CMD(argv[2],auth,4) )
            {
                if ( strlen( argv[3] ) < 1 || strlen( argv[4] ) < 1 )
                {
                    WRMSG( HHC01814, "E" );
                    rc = -1;
                }
                else
                {
                    if (http_serv.httpuser)
                        free(http_serv.httpuser);
                    http_serv.httpuser = strdup(argv[3]);

                    if (http_serv.httppass)
                        free(http_serv.httppass);
                    http_serv.httppass = strdup(argv[4]);

                    http_serv.httpauth = 1;
                }
            }
            else if ( argc != 2 || rc < 0 )
            {
                WRMSG( HHC02299, "E", "http" );
                rc = -1;
            }

            if ( rc >= 0 && MLVL(VERBOSE) )
            {
                char msgbuf[128];
                if ( http_serv.httpauth == 1 )
                {
                    MSGBUF( msgbuf, "port=%hu auth userid<%s> password<%s>",
                            http_serv.httpport,
                          ( http_serv.httpuser == NULL || strlen(http_serv.httpuser) == 0 ) ?
                                "" : http_serv.httpuser,
                          ( http_serv.httppass == NULL || strlen(http_serv.httppass) == 0 ) ?
                                "" : http_serv.httppass );
                }
                else
                    MSGBUF( msgbuf, "port=%hu noauth", http_serv.httpport );

                WRMSG( HHC02204, "I", http_serv.httpstmtold ? "httpport":"port", msgbuf );

                if ( http_serv.httpstmtold )
                    http_startup(TRUE);

            }   /* VERBOSE */
        }
    }
    else if ( argc == 1 && CMD(argv[0],start,3) )
    {
        if ( http_serv.httpport == 0 )
        {
            WRMSG( HHC01815, "E", "not valid");
            rc = -1;
        }
        else
            rc = http_startup(FALSE);
    }
    else if (argc == 1 && CMD(argv[0],stop,4))
    {
        if ( sysblk.httptid != 0 )
        {
            http_shutdown(NULL);
            WRMSG( HHC01805, "I" );
            rc = 1;
        }
        else
        {
            http_serv.httpshutdown = TRUE;
            WRMSG( HHC01806, "W", "already stopped" );
            rc = 1;
        }
    }
    else if ( argc == 0 )
    {
        if ( sysblk.httptid != 0 )
        {
            if ( http_serv.httpbinddone )
            {
                WRMSG( HHC01809, "I" );
                rc = 0;
            }
            else
            {
                WRMSG( HHC01813, "I" );
                rc = 1;
            }
        }
        else
        {
            WRMSG( HHC01810, "I" );
            rc = 1;
        }

        WRMSG(HHC01811, "I", http_get_root());

        WRMSG(HHC01808, "I", http_get_port(), http_get_portauth());
    }
    else
    {
        WRMSG( HHC02299, "E", "http" );
        rc = -1;
    }
    return rc;
}
Esempio n. 26
0
/*-------------------------------------------------------------------*/
static void
convert_ckd_file (IFD ifd, char *ifname, int itrklen, BYTE *itrkbuf,
                int repl, int quiet,
                char *ofname, int fseqn, U16 devtype, U32 heads,
                U32 trksize, BYTE *obuf, U32 start, U32 end,
                U32 volcyls, BYTE *volser)
{
int             rc;                     /* Return code               */
int             ofd;                    /* Output file descriptor    */
CKDDASD_DEVHDR  devhdr;                 /* Output device header      */
CKDDASD_TRKHDR *trkhdr;                 /* -> Output track header    */
CKDDASD_RECHDR *rechdr;                 /* -> Output record header   */
U32             cyl;                    /* Cylinder number           */
U32             head;                   /* Head number               */
int             fileseq;                /* CKD header sequence number*/
int             highcyl;                /* CKD header high cyl number*/
BYTE           *opos;                   /* -> Byte in output buffer  */
BYTE            klen;                   /* Key length                */
U16             dlen;                   /* Data length               */
BYTE            rec;                    /* Record number             */
BYTE           *iptr;                   /* -> Byte in input buffer   */
BYTE           *kptr;                   /* -> Key in input buffer    */
BYTE           *dptr;                   /* -> Data in input buffer   */
int             ilen;                   /* Bytes left in input buffer*/
H30CKD_TRKHDR  *ith;                    /* -> Input track header     */
U32             ihc, ihh;               /* Input trk header cyl,head */
U32             offset;                 /* Current input file offset */
char            pathname[MAX_PATH];     /* file path in host format  */

    UNREFERENCED(volser);

    /* Set file sequence number to zero if this is the only file */
    if (fseqn == 1 && end + 1 == volcyls)
        fileseq = 0;
    else
        fileseq = fseqn;

    /* Set high cylinder number to zero if this is the last file */
    if (end + 1 == volcyls)
        highcyl = 0;
    else
        highcyl = end;

    /* Create the AWSCKD image file */
    hostpath(pathname, (char *)ofname, sizeof(pathname));
    ofd = hopen(pathname,
                O_WRONLY | O_CREAT | O_BINARY | (repl ? 0 : O_EXCL),
                S_IRUSR | S_IWUSR | S_IRGRP);

    if (ofd < 0)
    {
        fprintf (stderr, "%s open error: %s\n",
                ofname, strerror(errno));
        EXIT(8);
    }

    /* Create the device header */
    memset(&devhdr, 0, CKDDASD_DEVHDR_SIZE);
    memcpy(devhdr.devid, "CKD_P370", 8);
    devhdr.heads[3] = (heads >> 24) & 0xFF;
    devhdr.heads[2] = (heads >> 16) & 0xFF;
    devhdr.heads[1] = (heads >> 8) & 0xFF;
    devhdr.heads[0] = heads & 0xFF;
    devhdr.trksize[3] = (trksize >> 24) & 0xFF;
    devhdr.trksize[2] = (trksize >> 16) & 0xFF;
    devhdr.trksize[1] = (trksize >> 8) & 0xFF;
    devhdr.trksize[0] = trksize & 0xFF;
    devhdr.devtype = devtype & 0xFF;
    devhdr.fileseq = fileseq;
    devhdr.highcyl[1] = (highcyl >> 8) & 0xFF;
    devhdr.highcyl[0] = highcyl & 0xFF;

    /* Write the device header */
    rc = write (ofd, &devhdr, CKDDASD_DEVHDR_SIZE);
    if (rc < CKDDASD_DEVHDR_SIZE)
    {
        fprintf (stderr, "%s device header write error: %s\n",
                ofname, errno ? strerror(errno) : "incomplete");
        EXIT(1);
    }

    /* Write each cylinder */
    for (cyl = start; cyl <= end; cyl++)
    {
        /* Display progress message every 10 cylinders */
        if ((cyl % 10) == 0)
        {
#ifdef EXTERNALGUI
            if (extgui)
                fprintf (stderr, "CYL=%u\n", cyl);
            else
#endif /*EXTERNALGUI*/
            if (quiet == 0)
                fprintf (stderr, "Writing cylinder %u\r", cyl);
        }

        for (head = 0; head < heads; head++)
        {
            /* Calculate the current offset in the file */
            offset = ((cyl*heads)+head)*itrklen;

            /* Read the input track image (except cyl 0 head 0 
               already read by the open_input_image procedure) */
            if (cyl > 0 || head > 0)
            {
                read_input_data (ifd, ifname,
                                 itrkbuf, itrklen,
                                 offset);
            } /* end if(cyl>0||head>0) */

            /* Validate the track header */
            ith = (H30CKD_TRKHDR*)itrkbuf;
            FETCH_HW (ihc, ith->cyl);
            FETCH_HW (ihh, ith->head);
            if (ihc != cyl || ihh != head)
            {
                fprintf (stderr,
                        "Invalid track header found at offset %8.8X\n"
                        "in input file %s\n"
                        "Expected cyl=%4.4X head=%4.4X\n"
                        "   Found cyl=%4.4X head=%4.4X\n",
                        offset, ifname,
                        cyl, head, ihc, ihh);
                EXIT(8);
            }
             
            /* Clear the output track image to zeroes */
            memset (obuf, 0, trksize);

            /* Build the output track header */
            trkhdr = (CKDDASD_TRKHDR*)obuf;
            trkhdr->bin = 0;
            STORE_HW (trkhdr->cyl, cyl);
            STORE_HW (trkhdr->head, head);
            opos = obuf + CKDDASD_TRKHDR_SIZE;

            /* Copy each record from the input buffer */
            iptr = itrkbuf + H30CKD_TRKHDR_SIZE;
            ilen = itrklen - H30CKD_TRKHDR_SIZE;
            while (1)
            {
                /* Locate the next input record */
                rc = find_input_record (itrkbuf, &iptr, &ilen,
                        &klen, &kptr, &dlen, &dptr,
                        &ihc, &ihh, &rec);

                /* Exit at end of track */
                if (rc == 1) break;

                /* Error if invalid record header detected */
                if (rc > 1)
                {
                    fprintf (stderr,
                            "Invalid record header (reason %d)\n"
                            "at offset %4.4X"
                            " in track at cyl %4.4X head %4.4X\n"
                            "at offset %8.8X in input file %s\n",
                            rc, (unsigned int)(iptr-itrkbuf), cyl, head,
                            offset, ifname);
                    EXIT(9);
                }

                /* Build AWSCKD record header in output buffer */
                rechdr = (CKDDASD_RECHDR*)opos;
                opos += CKDDASD_RECHDR_SIZE;
                STORE_HW (rechdr->cyl, ihc);
                STORE_HW (rechdr->head, ihh);
                rechdr->rec = rec;
                rechdr->klen = klen;
                STORE_HW (rechdr->dlen, dlen);

                /* Copy key and data to output buffer */
                if (klen != 0)
                {
                    memcpy (opos, kptr, klen);
                    opos += klen;
                }
                if (dlen != 0)
                {
                    memcpy (opos, dptr, dlen);
                    opos += dlen;
                }

            } /* end while */

            /* Build the end of track marker */
            memcpy (opos, eighthexFF, 8);

            /* Write the track to the file */
            rc = write (ofd, obuf, trksize);
            if (rc < 0 || (U32)rc < trksize)
            {
                fprintf (stderr,
                        "%s cylinder %u head %u write error: %s\n",
                        ofname, cyl, head,
                        errno ? strerror(errno) : "incomplete");
                EXIT(1);
            }

        } /* end for(head) */

    } /* end for(cyl) */

    /* Close the AWSCKD image file */
    rc = close (ofd);
    if (rc < 0)
    {
        fprintf (stderr, "%s close error: %s\n",
                ofname, strerror(errno));
        EXIT(10);
    }

    /* Display completion message */
    fprintf (stderr,
            "%u cylinders successfully written to file %s\n",
            cyl - start, ofname);

} /* end function convert_ckd_file */
Esempio n. 27
0
/*-------------------------------------------------------------------*/
char *http_root()
{
    obtain_lock( &http_lock_root );

    /* If the HTTP root directory is not specified,
       use a reasonable default */
    if (!http_serv.httproot)
    {
#if defined(_MSVC_)
        char process_dir[HTTP_PATH_LENGTH];
        if (get_process_directory(process_dir,HTTP_PATH_LENGTH) > 0)
        {
            strlcat(process_dir,"\\html",HTTP_PATH_LENGTH);
            http_serv.httproot = strdup(process_dir);
        }
        else
#endif /*defined(WIN32)*/
        http_serv.httproot = strdup(HTTP_ROOT);
    }

    /* Convert the specified HTTPROOT value to an absolute path
       ending with a '/' and save in http_serv.httproot. */
    {
        char absolute_httproot_path[HTTP_PATH_LENGTH];
        int  rc;
#if defined(_MSVC_)
        /* Expand any embedded %var% environ vars */
        rc = expand_environ_vars( http_serv.httproot, absolute_httproot_path,
            sizeof(absolute_httproot_path) );
        if (rc == 0)
        {
            char *p = strdup(absolute_httproot_path);;
            if ( http_serv.httproot != NULL )
                free(http_serv.httproot);

            http_serv.httproot = p;
        }
#endif /* defined(_MSVC_) */
        /* Convert to absolute path */
        if (!realpath(http_serv.httproot, absolute_httproot_path))
        {
            char msgbuf[MAX_PATH+3] = { 0 };
            char *p = msgbuf;

            if ( strchr( http_serv.httproot, SPACE ) == NULL )
                p = http_serv.httproot;
            else
                MSGBUF(msgbuf, "'%s'", http_serv.httproot);

            WRMSG(HHC01801, "E", p, strerror(errno));

            release_lock( &http_lock_root );

            return NULL;
        }
        /* Verify that the absolute path is valid */
        // mode: 0 = exist only, 2 = write, 4 = read, 6 = read/write
        // rc: 0 = success, -1 = error (errno = cause)
        // ENOENT = File name or path not found.
        if (access( absolute_httproot_path, R_OK ) != 0)
        {
            char msgbuf[MAX_PATH+3];
            char *p = absolute_httproot_path;

            if ( strchr( absolute_httproot_path, SPACE ) != NULL )
            {
                MSGBUF(msgbuf, "'%s'", absolute_httproot_path);
                p = msgbuf;
            }

            WRMSG(HHC01801, "E", p, strerror(errno));

            release_lock( &http_lock_root );

            return p;
        }
        /* Append trailing [back]slash, but only if needed */
        rc = (int)strlen(absolute_httproot_path);

        if (absolute_httproot_path[rc-1] != *HTTP_PS)
            strlcat(absolute_httproot_path,HTTP_PS,sizeof(absolute_httproot_path));

        /* Save the absolute path */
        free(http_serv.httproot);

        if (strlen(absolute_httproot_path) > MAX_PATH )
        {
            char msgbuf[MAX_PATH+3] = { 0 };
            char *p = msgbuf;

            if ( strchr( absolute_httproot_path, SPACE ) == NULL )
                p = absolute_httproot_path;
            else
                MSGBUF(msgbuf, "'%s'", absolute_httproot_path);

            WRMSG(HHC01801, "E", p, "path length too long");

            release_lock( &http_lock_root );

            return NULL;
        }
        else
        {
            char    pathname[MAX_PATH];     /* working pathname          */
            char msgbuf[MAX_PATH+3];
            char *p = msgbuf;

            memset(msgbuf,0,sizeof(msgbuf));

            hostpath(pathname, absolute_httproot_path, sizeof(pathname));
            http_serv.httproot = strdup(pathname);

            if ( strchr( http_serv.httproot, SPACE ) == NULL )
                p = http_serv.httproot;
            else
                MSGBUF(msgbuf, "'%s'", http_serv.httproot);

            WRMSG(HHC01802, "I", p);
        }
    }

    release_lock( &http_lock_root );

    return http_serv.httproot;
}
Esempio n. 28
0
/*-------------------------------------------------------------------*/
static int cardrdr_init_handler ( DEVBLK *dev, int argc, char *argv[] )
{
int     i;                              /* Array subscript           */
int     fc;                             /* File counter              */
char    pathname[MAX_PATH];             /* file path in host format  */
int     sockdev = 0;
int     attn = 0;


    /* Raise attention for re-init */
    if(dev->devtype)
        attn = 1;

    /* For re-initialisarion close the existing file */
    if (dev->fd >= 0)
        (dev->hnd->close)(dev);

    if (dev->bs)
    {
        if (!unbind_device(dev))
        {
            // (error message already issued)
            return -1;
        }
    }

    /* Initialize device dependent fields */

    dev->fd = -1;
    dev->fh = NULL;
    dev->multifile = 0;
    dev->ebcdic = 0;
    dev->ascii = 0;
    dev->trunc = 0;
    dev->cardpos = 0;
    dev->cardrem = 0;
    dev->autopad = 0;

    dev->excps = 0;

    if(!sscanf(dev->typname,"%hx",&(dev->devtype)))
        dev->devtype = 0x2501;

    fc = 0;

    if (dev->more_files) free (dev->more_files);

    dev->more_files = malloc(sizeof(char*) * (fc + 1));

    if (!dev->more_files)
    {
        char buf[40];
        MSGBUF(buf, "malloc(%d)", (int)(sizeof(char) * (fc + 1)) );
        WRMSG (HHC01200, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, buf, strerror(errno));
        return -1;
    }

    dev->more_files[fc] = NULL;

    /* Process the driver arguments starting with the SECOND
       argument. (The FIRST argument is the filename and is
       checked later further below.) */

    for (i = 1; i < argc; i++)
    {
        /* sockdev means the device file is actually
           a connected socket instead of a disk file.
           The file name is the socket_spec (host:port)
           to listen for connections on. */

        if (strcasecmp(argv[i], "sockdev") == 0)
        {
            sockdev = 1;
            continue;
        }

        /* multifile means to automatically open the next
           i/p file if multiple i/p files are defined.   */

        if (strcasecmp(argv[i], "multifile") == 0)
        {
            dev->multifile = 1;
            continue;
        }

        /* eof means that unit exception will be returned at
           end of file, instead of intervention required */

        if (strcasecmp(argv[i], "eof") == 0)
        {
            dev->rdreof = 1;
            continue;
        }

        /* intrq means that intervention required will be returned at
           end of file, instead of unit exception */

        if (strcasecmp(argv[i], "intrq") == 0)
        {
            dev->rdreof = 0;
            continue;
        }

        /* ebcdic means that the card image file consists of
           fixed length 80-byte EBCDIC card images with no
           line-end delimiters */

        if (strcasecmp(argv[i], "ebcdic") == 0)
        {
            dev->ebcdic = 1;
            continue;
        }

        /* ascii means that the card image file consists of
           variable length ASCII records delimited by either
           line-feed or carriage-return line-feed sequences */

        if (strcasecmp(argv[i], "ascii") == 0)
        {
            dev->ascii = 1;
            continue;
        }

        /* trunc means that records longer than 80 bytes will
           be silently truncated to 80 bytes when processing a
           variable length ASCII file.  The default behaviour
           is to present a data check if an overlength record
           is encountered.  The trunc option is ignored except
           when processing an ASCII card image file. */

        if (strcasecmp(argv[i], "trunc") == 0)
        {
            dev->trunc = 1;
            continue;
        }

        /* autopad means that if reading fixed sized records
         * (ebcdic) and end of file is reached in the middle of
         * a record, the record is automatically padded to 80 bytes.
         */

        if (strcasecmp(argv[i], "autopad") == 0)
        {
            dev->autopad = 1;
            continue;
        }

        // add additional file arguments

        if (strlen(argv[i]) >= sizeof(dev->filename))
        {
            WRMSG (HHC01201, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, argv[i], (unsigned int)sizeof(dev->filename)-1);
            return -1;
        }

        if (access(argv[i], R_OK | F_OK) != 0)
        {
            WRMSG (HHC01200, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "access()", strerror(errno));
            return -1;
        }
        hostpath(pathname, argv[i], sizeof(pathname));
        dev->more_files[fc++] = strdup(pathname);
        dev->more_files = realloc(dev->more_files, sizeof(char*) * (fc + 1));

        if (!dev->more_files)
        {
            WRMSG (HHC01200, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "strdup()", strerror(errno));
            return -1;
        }

        dev->more_files[fc] = NULL;
    }

    dev->current_file = dev->more_files;

    /* Check for conflicting arguments */

    if (dev->ebcdic && dev->ascii)
    {
        WRMSG (HHC01202, "E", SSID_TO_LCSS(dev->ssid), dev->devnum);
        return -1;
    }

    if (sockdev)
    {
        if (fc)
        {
            WRMSG (HHC01203, "E", SSID_TO_LCSS(dev->ssid), dev->devnum);
            return -1;
        }

        // If neither ascii nor ebcdic is specified, default to ascii.
        // This is required for socket devices because the open logic,
        // if neither is specified, attempts to determine whether the data
        // is actually ascii or ebcdic by reading the 1st 160 bytes of
        // data and then rewinding to the beginning of the file afterwards.
        //  Since you can't "rewind" a socket, we must therefore default
        // to one of them.

        if (!dev->ebcdic && !dev->ascii)
        {
            WRMSG (HHC01204, "I", SSID_TO_LCSS(dev->ssid), dev->devnum);
            dev->ascii = 1;
        }
    }

    if (dev->multifile && !fc)
    {
        WRMSG (HHC01205, "W", SSID_TO_LCSS(dev->ssid), dev->devnum);
        dev->multifile = 0;
    }

    /* The first argument is the file name */

    if (argc > 0)
    {
        /* Check for valid file name */

        if (strlen(argv[0]) >= sizeof(dev->filename))
        {
            WRMSG (HHC01201, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, argv[0], (unsigned int)sizeof(dev->filename)-1);
            return -1;
        }

        if (!sockdev)
        {
            /* Check for specification of no file mounted on reader */
            if (argv[0][0] == '*')
            {
                dev->filename[0] = '\0';
            }
            else if (access(argv[0], R_OK | F_OK) != 0)
            {
                WRMSG (HHC01200, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "access()", strerror(errno));
                return -1;
            }
        }

        /* Save the file name in the device block */
        hostpath(dev->filename, argv[0], sizeof(dev->filename));
    }
    else
    {
        dev->filename[0] = '\0';
    }

    /* Set size of i/o buffer */
    dev->bufsize = CARD_SIZE;

    if (sockdev && dev->ascii)
    {
        /* Allocate extra room for socket i/o buffer */
        dev->bufsize += (TRAY_CARDS * CARD_SIZE);
        dev->buflen = dev->bufsize;
        dev->bufoff = dev->buflen;
    }

    /* Set number of sense bytes */

    /* ISW 20030307 : Empirical knowledge : DOS/VS R34 Erep */
    /*                indicates 4 bytes in 3505 sense       */
    dev->numsense = 4;

    /* Initialize the device identifier bytes */

    dev->devid[0] = 0xFF;
    if (0x3505 == dev->devtype || 0x2501 == dev->devtype)
    {
        dev->devid[1] = dev->devtype >> 8;
        dev->devid[2] = dev->devtype;
    }
Esempio n. 29
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   */
int             cckd_diag_rc = 0;       /* Program return code       */
char           *fn;                     /* File name                 */

CKDDASD_DEVHDR  devhdr;                 /* [C]CKD device hdr         */
CCKDDASD_DEVHDR cdevhdr;                /* Compressed CKD device hdr */
CKDDEV         *ckd=0;                  /* CKD DASD table entry      */
FBADEV         *fba=0;                  /* FBA DASD table entry      */

int             cmd_devhdr = 0;         /* display DEVHDR            */
int             cmd_cdevhdr = 0;        /* display CDEVHDR           */
int             cmd_l1tab = 0;          /* display L1TAB             */
int             cmd_l2tab = 0;          /* display L2TAB             */
int             cmd_trkdata = 0;        /* display track data        */
int             cmd_hexdump = 0;        /* display track data (hex)  */

int             cmd_offset = 0;         /* 1 = display data at       */
int             op_offset = 0;          /* op_offset of length       */
int             op_length = 0;          /* op_length                 */

int             cmd_cchh = 0;           /* 1 = display CCHH data     */
int             op_cc = 0;              /* CC = cylinder             */
int             op_hh = 0;              /* HH = head                 */

int             cmd_tt = 0;             /* 1 = display TT data       */
int             op_tt = 0;              /* relative track #          */

int             swapend;                /* 1 = New endianess doesn't
                                             match machine endianess */
int             n, trk=0, l1ndx=0, l2ndx=0;
off_t           l2taboff=0;             /* offset to assoc. L2 table */
int             ckddasd;                /* 1=CKD dasd  0=FBA dasd    */
int             heads=0;                /* Heads per cylinder        */
off_t           trkhdroff=0;            /* offset to assoc. trk hdr  */
int             imglen=0;               /* track length              */
char            pathname[MAX_PATH];     /* file path in host format  */
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, "CCKD diagnostic program" ) );
    display_version (stderr, msgbuf+10, FALSE);

    /* parse the arguments */
    argc--;
    argv++ ;
    while (argc > 0) {
        if(**argv != '-') break;

        switch(argv[0][1]) {
            case 'v':  if (argv[0][2] != '\0') return syntax (pgm);
                       return 0;
            case 'd':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_devhdr = 1;
                       break;
            case 'c':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_cdevhdr = 1;
                       break;
            case '1':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_l1tab = 1;
                       break;
            case '2':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_l2tab = 1;
                       break;
            case 'a':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_cchh = 1;
                       argc--; argv++;
                       op_cc = offtify(*argv);
                       argc--; argv++;
                       op_hh = offtify(*argv);
                       break;
            case 'r':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_tt = 1;
                       argc--; argv++;
                       op_tt = offtify(*argv);
                       break;
            case 'o':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_offset = 1;
                       argc--;
                       argv++;
                       op_offset = offtify(*argv);
                       argc--;
                       argv++;
                       op_length = offtify(*argv);
                       break;
            case 't':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_trkdata = 1;
                       break;
            case 'x':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_hexdump = 1;
                       cmd_trkdata = 1;
                       break;
            case 'g':  if (argv[0][2] != '\0') return syntax (pgm);
                       debug = 1;
                       break;
            default:   return syntax (pgm);
        }
        argc--;
        argv++;
    }
    if (argc != 1) return syntax (pgm);
    fn = argv[0];

    /* open the file */
    hostpath(pathname, fn, sizeof(pathname));
    fd = HOPEN(pathname, O_RDONLY | O_BINARY);
    if (fd < 0) {
        fprintf(stderr,
                _("cckddiag: error opening file %s: %s\n"),
                fn, strerror(errno));
        return -1;
    }

    /*---------------------------------------------------------------*/
    /* display DEVHDR - first 512 bytes of dasd image                */
    /*---------------------------------------------------------------*/
    readpos(fd, &devhdr, 0, sizeof(devhdr));
    if (cmd_devhdr) {
        fprintf(stderr, "\nDEVHDR - %d (decimal) bytes:\n",
                (int)sizeof(devhdr));
        data_dump(&devhdr, sizeof(devhdr));
    }

    /*---------------------------------------------------------------*/
    /* Determine CKD or FBA device type                              */
    /*---------------------------------------------------------------*/
    if (memcmp(devhdr.devid, "CKD_C370", 8) == 0
       || memcmp(devhdr.devid, "CKD_S370", 8) == 0) {
        ckddasd = 1;
        ckd = dasd_lookup(DASD_CKDDEV, NULL, devhdr.devtype, 0);
        if (ckd == NULL) {
            fprintf(stderr,
                    "DASD table entry not found for devtype 0x%2.2X\n",
                    devhdr.devtype);
            clean();
            exit(5);
        }
    }
    else
        if (memcmp(devhdr.devid, "FBA_C370", 8) == 0
           || memcmp(devhdr.devid, "FBA_S370", 8) == 0) {
        ckddasd = 0;
        fba = dasd_lookup(DASD_FBADEV, NULL, devhdr.devtype, 0);
        if (fba == NULL) {
            fprintf(stderr,
                    "DASD table entry not found for "
                    "devtype 0x%2.2X\n",
                    DEFAULT_FBA_TYPE);
            clean();
            exit(6);
        }
    }
    else {
        fprintf(stderr, "incorrect header id\n");
        clean();
        return -1;
    }

    /*---------------------------------------------------------------*/
    /* Set up device characteristics                                 */
    /*---------------------------------------------------------------*/
    if (ckddasd) {
        heads = ((U32)(devhdr.heads[3]) << 24)
              | ((U32)(devhdr.heads[2]) << 16)
              | ((U32)(devhdr.heads[1]) << 8)
              | (U32)(devhdr.heads[0]);
        if (debug)
            fprintf(stderr,
                "\nHHC90000D DBG: %s device has %d heads/cylinder\n",
                ckd->name, heads);
    } 


    /*---------------------------------------------------------------*/
    /* display CDEVHDR - follows DEVHDR                              */
    /*---------------------------------------------------------------*/
    readpos(fd, &cdevhdr, CKDDASD_DEVHDR_SIZE, sizeof(cdevhdr));
    if (cmd_cdevhdr) {
        fprintf(stderr, "\nCDEVHDR - %d (decimal) bytes:\n",
                (int)sizeof(cdevhdr));
        data_dump(&cdevhdr, sizeof(cdevhdr));
    }

    /*---------------------------------------------------------------*/
    /* Find machine endian-ness                                      */
    /*---------------------------------------------------------------*/
    /* cckd_endian() returns 1 for big-endian machines               */
    swapend = (cckd_endian() !=
               ((cdevhdr.options & CCKD_BIGENDIAN) != 0));

    /*---------------------------------------------------------------*/
    /* display L1TAB - follows CDEVHDR                               */
    /*---------------------------------------------------------------*/
    /* swap numl1tab if needed */
    n = cdevhdr.numl1tab;
    if (swapend) cckd_swapend4((char *)&n);

    l1 = makbuf(n * CCKD_L1ENT_SIZE, "L1TAB");
    readpos(fd, l1, CCKD_L1TAB_POS, n * CCKD_L1ENT_SIZE);
    /* L1TAB itself is not adjusted for endian-ness                  */
    if (cmd_l1tab) {
        fprintf(stderr, "\nL1TAB - %d (0x%X) bytes:\n",
                (int)(n * CCKD_L1ENT_SIZE), (unsigned int)(n * CCKD_L1ENT_SIZE));
        data_dump(l1, n * CCKD_L1ENT_SIZE);
    }

    /*---------------------------------------------------------------*/
    /* display OFFSET, LENGTH data                                   */
    /*---------------------------------------------------------------*/
    if (cmd_offset) {
        bulk = makbuf(op_length, "BULK");
        readpos(fd, bulk, op_offset, op_length);
        fprintf(stderr,
            "\nIMAGE OFFSET %d (0x%8.8X) "
            "of length %d (0x%8.8X) bytes:\n",
            op_offset, op_offset, op_length, op_length);
        data_dump(bulk, op_length);
        free(bulk);
        bulk = NULL;
    }

    /*---------------------------------------------------------------*/
    /* FBA isn't supported here because I don't know much about FBA  */
    /*---------------------------------------------------------------*/
    if ( (!ckddasd) && ((cmd_cchh) || (cmd_tt)) ) {
        fprintf(stderr, "CCHH/reltrk not supported for FBA\n");
        clean();
        exit(3);
    }

    /*---------------------------------------------------------------*/
    /* Setup CCHH or relative track request                          */
    /*---------------------------------------------------------------*/
    if (ckddasd) {
        if (cmd_tt) {
            trk = op_tt;
            op_cc = trk / heads;
            op_hh = trk % heads;
        } else {
            trk = (op_cc * heads) + op_hh;
        }
        l1ndx = trk / cdevhdr.numl2tab;
        l2ndx = trk % cdevhdr.numl2tab;
        l2taboff = l1[l1ndx];
        if (swapend) cckd_swapend4((char *)&l2taboff);
    }

    /*---------------------------------------------------------------*/
    /* display CKD CCHH or relative track data                       */
    /*---------------------------------------------------------------*/
    if ((cmd_cchh) || (cmd_tt)) {
        fprintf(stderr,
                "CC %d HH %d = reltrk %d; "
                "L1 index = %d, L2 index = %d\n"
                "L1 index %d = L2TAB offset %d (0x%8.8X)\n",
                op_cc, op_hh, trk,
                l1ndx, l2ndx,
                l1ndx, (int)l2taboff, (int)l2taboff);
        l2 = makbuf(cdevhdr.numl2tab * sizeof(CCKD_L2ENT), "L2TAB");
        readpos(fd, l2, l2taboff,
                cdevhdr.numl2tab * sizeof(CCKD_L2ENT));
        if (cmd_l2tab) {
            fprintf(stderr,
                   "\nL2TAB - %d (decimal) bytes\n",
                   (int)(cdevhdr.numl2tab * sizeof(CCKD_L2ENT)));
            data_dump(l2, (cdevhdr.numl2tab * sizeof(CCKD_L2ENT)) );
        }
        fprintf(stderr, "\nL2 index %d = L2TAB entry %d bytes\n",
               l2ndx, (int)sizeof(CCKD_L2ENT) );
        data_dump(&l2[l2ndx], sizeof(CCKD_L2ENT) );
        trkhdroff = l2[l2ndx].pos;
        imglen = l2[l2ndx].len;
        if (swapend) {
            cckd_swapend4((char *)&trkhdroff);
            cckd_swapend4((char *)&imglen);
        }
        fprintf(stderr, "\nTRKHDR offset %d (0x%8.8X); "
                "length %d (0x%4.4X)\n",
                (int)trkhdroff, (int)trkhdroff, imglen, imglen);
        tbuf = makbuf(imglen, "TRKHDR+DATA");
        readpos(fd, tbuf, trkhdroff, imglen);
        fprintf(stderr, "\nTRKHDR track %d\n", trk);
        data_dump(tbuf, sizeof(CKDDASD_TRKHDR) );
        if (cmd_trkdata) showtrk(tbuf, imglen, trk, cmd_hexdump);
        free(l2); free(tbuf);
        l2 = NULL; tbuf = NULL;
    }

    /* Close file, exit */
    fprintf(stderr, "\n");
    clean();
    return cckd_diag_rc;
}
Esempio n. 30
0
/*-------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
int             i;                      /* Array subscript           */
int             len;                    /* Block length              */
int             prevlen;                /* Previous block length     */
char           *filename;               /* -> Input file name        */
int             infd = -1;              /* Input file descriptor     */
int             fileno;                 /* Tape file number          */
int             blkcount;               /* Block count               */
int             curblkl;                /* Current block length      */
int             minblksz;               /* Minimum block size        */
int             maxblksz;               /* Maximum block size        */
BYTE            labelrec[81];           /* Standard label (ASCIIZ)   */
AWSTAPE_BLKHDR  awshdr;                 /* AWSTAPE block header      */
char            pathname[MAX_PATH];     /* file path in host format  */

    INITIALIZE_UTILITY("tapemap");

    /* Display the program identification message */
    display_version (stderr, "Hercules tape map program ", FALSE);

    /* The only argument is the tape image file name */
    if (argc == 2 && argv[1] != NULL)
    {
        filename = argv[1];
    }
    else
    {
        printf ("Usage: tapemap filename\n");
        exit (1);
    }

    /* Open the tape device */
    hostpath(pathname, filename, sizeof(pathname));
    infd = hopen(pathname, O_RDONLY | O_BINARY);
    if (infd < 0)
    {
        printf ("tapemap: Error opening %s: %s\n",
                filename, strerror(errno));
        exit (2);
    }

    /* Read blocks from the input file and report on them */
    fileno = 1;
    blkcount = 0;
    minblksz = 0;
    maxblksz = 0;
    len = 0;

    while (1)
    {
#ifdef EXTERNALGUI
        if (extgui)
        {
            /* Report progress every nnnK */
            if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) )
            {
                prevpos = curpos;
                fprintf( stderr, "IPOS=%ld\n", curpos );
            }
        }
#endif /*EXTERNALGUI*/
        /* Save previous block length */
        prevlen = len;

        /* Read a block from the tape */
        len = read (infd, buf, sizeof(AWSTAPE_BLKHDR));
#ifdef EXTERNALGUI
        if (extgui) curpos += len;
#endif /*EXTERNALGUI*/
        if (len < 0)
        {
            printf ("tapemap: error reading header block from %s: %s\n",
                    filename, strerror(errno));
            exit (3);
        }

        /* Did we finish too soon? */
        if ((len > 0) && (len < (int)sizeof(AWSTAPE_BLKHDR)))
        {
            printf ("tapemap: incomplete block header on %s\n",
                    filename);
            exit(4);
        }
        
        /* Check for end of tape. */
        if (len == 0)
        {
            printf ("End of tape.\n");
            break;
        }
        
        /* Parse the block header */
        memcpy(&awshdr, buf, sizeof(AWSTAPE_BLKHDR));
        
        /* Tapemark? */
        if ((awshdr.flags1 & AWSTAPE_FLAG1_TAPEMARK) != 0)
        {
            /* Print summary of current file */
            printf ("File %u: Blocks=%u, block size min=%u, max=%u\n",
                    fileno, blkcount, minblksz, maxblksz);

            /* Reset counters for next file */
            fileno++;
            minblksz = 0;
            maxblksz = 0;
            blkcount = 0;

        }
        else /* if(tapemark) */
        {
            /* Count blocks and block sizes */
            blkcount++;
            curblkl = awshdr.curblkl[0] + (awshdr.curblkl[1] << 8);
            if (curblkl > maxblksz) maxblksz = curblkl;
            if (minblksz == 0 || curblkl < minblksz) minblksz = curblkl;

            /* Read the data block. */
            len = read (infd, buf, curblkl);
#ifdef EXTERNALGUI
            if (extgui) curpos += len;
#endif /*EXTERNALGUI*/
            if (len < 0)
            {
                printf ("tapemap: error reading data block from %s: %s\n",
                        filename, strerror(errno));
                exit (5);
            }

            /* Did we finish too soon? */
            if ((len > 0) && (len < curblkl))
            {
                printf ("tapemap: incomplete final data block on %s, "
                        "expected %d bytes, got %d\n",
                        filename, curblkl, len);
                exit(6);
            }
        
            /* Check for end of tape */
            if (len == 0)
            {
                printf ("tapemap: header block with no data on %s\n",
                        filename);
                exit(7);
            }
        
            /* Print standard labels */
            if (len == 80 && blkcount < 4
                && (memcmp(buf, vollbl, 3) == 0
                    || memcmp(buf, hdrlbl, 3) == 0
                    || memcmp(buf, eoflbl, 3) == 0
                    || memcmp(buf, eovlbl, 3) == 0))
            {
                for (i=0; i < 80; i++)
                    labelrec[i] = guest_to_host(buf[i]);
                labelrec[i] = '\0';
                printf ("%s\n", labelrec);
            }
            
        } /* end if(tapemark) */

    } /* end while */

    /* Close files and exit */
    close (infd);

    return 0;

} /* end function main */