mirror of
https://github.com/SDL-Hercules-390/hyperion.git
synced 2026-04-13 07:25:22 +02:00
141 lines
5.1 KiB
C
141 lines
5.1 KiB
C
/* CCKDCOMP.C (c) Copyright Roger Bowler, 1999-2012 */
|
|
/* (c) Copyright Greg Smith, 2002-2012 */
|
|
/* Perform chkdsk for a Compressed CKD Direct Access Storage */
|
|
/* Device file. */
|
|
/* */
|
|
/* Released under "The Q Public License Version 1" */
|
|
/* (http://www.hercules-390.org/herclic.html) as modifications to */
|
|
/* Hercules. */
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
/* Remove all free space on a compressed ckd file */
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
#include "hstdinc.h"
|
|
|
|
#include "hercules.h"
|
|
|
|
int syntax ();
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
/* Main function for stand-alone compress */
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
int main (int argc, char *argv[])
|
|
{
|
|
int i; /* Index */
|
|
int rc; /* Return code */
|
|
int level=-1; /* Level for chkdsk */
|
|
int force=0; /* 1=Compress if OPENED set */
|
|
CCKDDASD_DEVHDR cdevhdr; /* Compressed CKD device hdr */
|
|
DEVBLK devblk; /* DEVBLK */
|
|
DEVBLK *dev=&devblk; /* -> DEVBLK */
|
|
|
|
INITIALIZE_UTILITY("cckdcomp");
|
|
|
|
/* 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 ();
|
|
level = (argv[0][1] & 0xf);
|
|
break;
|
|
case 'f': if (argv[0][2] != '\0') return syntax ();
|
|
force = 1;
|
|
break;
|
|
case 'v': if (argv[0][2] != '\0') return syntax ();
|
|
display_version
|
|
(stderr, "Hercules cckd compress 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, 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;
|
|
}
|
|
|
|
/* Check CCKD_OPENED bit if -f not specified */
|
|
if (!force)
|
|
{
|
|
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;
|
|
}
|
|
if (cdevhdr.options & CCKD_OPENED)
|
|
{
|
|
fprintf(stdout, MSG(HHC00352, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename));
|
|
close (dev->fd);
|
|
continue;
|
|
}
|
|
} /* if (!force) */
|
|
|
|
/* 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;
|
|
}
|
|
|
|
/* call compress */
|
|
rc = cckd_comp (dev);
|
|
|
|
close (dev->fd);
|
|
|
|
} /* for each arg */
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
/* print syntax */
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
int syntax()
|
|
{
|
|
fprintf (stderr, "\ncckdcomp [-v] [-f] [-level] file1 [file2 ... ]\n"
|
|
"\n"
|
|
" -v display version and exit\n"
|
|
"\n"
|
|
" -f force check even if OPENED bit is on\n"
|
|
"\n"
|
|
" chkdsk level is a digit 0 - 3:\n"
|
|
" -0 -- minimal checking\n"
|
|
" -1 -- normal checking\n"
|
|
" -2 -- intermediate checking\n"
|
|
" -3 -- maximal checking\n"
|
|
" default 0\n"
|
|
"\n");
|
|
return -1;
|
|
}
|