Skip to content

Commit

Permalink
25 Feb 2006 cckd 0.3.1 - Greg Smith
Browse files Browse the repository at this point in the history
git-svn-id: file:///home/jj/hercules.svn/trunk@3699 956126f8-22a0-4046-8f4a-272fa8102e63
  • Loading branch information
Greg Smith committed Feb 25, 2006
1 parent b670856 commit 09c9200
Show file tree
Hide file tree
Showing 9 changed files with 2,615 additions and 2,307 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#### Don't forget to change the version number in configure.ac! ####

25 Feb 2006 cckd 0.3.1 - Greg Smith
24 Feb 2006 Skeletal last floating point instructions - Bernard van der Helm
21 Feb 2006 Fix string overrun when hitting tab at the wrong time - Bjoern
Zeeb
Expand Down
118 changes: 48 additions & 70 deletions cckdcdsk.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ int syntax ();
/*-------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
int cckd_chkdsk_rc = 0; /* Program return code */
char *fn; /* File name */
int fd; /* File descriptor */
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 */
char pathname[MAX_PATH]; /* file path in host format */
DEVBLK devblk; /* DEVBLK */
DEVBLK *dev=&devblk; /* -> DEVBLK */

#if defined(ENABLE_NLS)
setlocale(LC_ALL, "");
Expand Down Expand Up @@ -52,7 +52,8 @@ char pathname[MAX_PATH]; /* file path in host format */
case '0':
case '1':
case '2':
case '3': if (argv[0][2] != '\0') return syntax ();
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 ();
Expand All @@ -70,85 +71,62 @@ char pathname[MAX_PATH]; /* file path in host format */
}
}

if (argc != 1) return syntax ();
if (argc < 1) return syntax ();

fn = argv[0];

/* open the file */
hostpath(pathname, fn, sizeof(pathname));
if (ro)
fd = open (pathname, O_RDONLY|O_BINARY);
else
fd = open (pathname, O_RDWR|O_BINARY);
if (fd < 0)
for (i = 0; i < argc; i++)
{
fprintf (stderr,
_("cckdcdsk: error opening file %s: %s\n"),
fn, strerror(errno));
return -1;
}
memset (dev, 0, sizeof(DEVBLK));
dev->batch = 1;

/* Check CCKD_OPENED bit if -f not specified */
if (!force)
{
if (LSEEK (fd, CKDDASD_DEVHDR_SIZE, SEEK_SET) < 0)
{
fprintf (stderr, _("cckdcdsk: lseek error: %s\n"),strerror(errno));
close (fd);
return -1;
}
if (read (fd, &cdevhdr, CCKDDASD_DEVHDR_SIZE) < CCKDDASD_DEVHDR_SIZE)
/* open the file */
hostpath(dev->filename, argv[i], sizeof(dev->filename));
dev->fd = open (dev->filename, ro ? O_RDONLY|O_BINARY : O_RDWR|O_BINARY);
if (dev->fd < 0)
{
fprintf (stderr, _("cckdcdsk: read error: %s\n"),strerror(errno));
close (fd);
return -1;
cckdumsg (dev, 700, "open error: %s\n", strerror(errno));
continue;
}
if (cdevhdr.options & CCKD_OPENED)
{
fprintf (stderr, _("cckdcdsk: OPENED bit is on, use `-f'\n"));
close (fd);
return -1;
}
}

/* call the actual chkdsk function */
cckd_chkdsk_rc = cckd_chkdsk (fd, stderr, level);

/* print some statistics */
if (LSEEK (fd, CKDDASD_DEVHDR_SIZE, SEEK_SET) < 0)
{
fprintf (stderr, _("lseek error: %s\n"),strerror(errno));
if (!cckd_chkdsk_rc) cckd_chkdsk_rc = 1;
}
else
{
if (read (fd, &cdevhdr, CCKDDASD_DEVHDR_SIZE) < 0)
/* Check CCKD_OPENED bit if -f not specified */
if (!force)
{
fprintf (stderr, _("read error: %s\n"),strerror(errno));
if (!cckd_chkdsk_rc) cckd_chkdsk_rc = 1;
}
else
{
if (cckd_endian() != ((cdevhdr.options & CCKD_BIGENDIAN) != 0))
cckd_swapend_chdr (&cdevhdr);

fprintf (stdout, _("size %d used %d free %d imbed %d first 0x%x number %d\n"),
cdevhdr.size, cdevhdr.used, cdevhdr.free_total,
cdevhdr.free_imbed, cdevhdr.free, cdevhdr.free_number);
}
}

close (fd);

return cckd_chkdsk_rc;
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;
}

/*-------------------------------------------------------------------*/
/* print syntax */
/*-------------------------------------------------------------------*/
int syntax()
{
fprintf (stderr, _("\ncckdcdsk [-v] [-f] [-level] [-ro] file-name\n"
fprintf (stderr, _("\ncckdcdsk [-v] [-f] [-level] [-ro] file1 [file2 ...]\n"
"\n"
" -v display version and exit\n"
"\n"
Expand Down
104 changes: 54 additions & 50 deletions cckdcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ int syntax ();

int main (int argc, char *argv[])
{
int i; /* Index */
int rc; /* Return code */
char *fn; /* File name */
int fd; /* File descriptor */
int level=-1; /* Level for chkdsk */
int force=0; /* 1=Compress if OPENED set */
CCKDDASD_DEVHDR cdevhdr; /* Compressed CKD device hdr */
char pathname[MAX_PATH]; /* file path in host format */
DEVBLK devblk; /* DEVBLK */
DEVBLK *dev=&devblk; /* -> DEVBLK */

#ifdef EXTERNALGUI
if (argc >= 1 && strncmp(argv[argc-1],"EXTERNALGUI",11) == 0)
Expand All @@ -51,69 +51,72 @@ char pathname[MAX_PATH]; /* file path in host format */
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 ();
fn = argv[0];

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

/* Check CCKD_OPENED bit if -f not specified */
if (!force)
for (i = 0; i < argc; i++)
{
if (LSEEK (fd, CKDDASD_DEVHDR_SIZE, SEEK_SET) < 0)
{
fprintf (stderr, _("cckdcomp: lseek error: %s\n"),strerror(errno));
close (fd);
return -1;
}
if (read (fd, &cdevhdr, CCKDDASD_DEVHDR_SIZE) < CCKDDASD_DEVHDR_SIZE)
{
fprintf (stderr, _("cckdcomp: read error: %s\n"),strerror(errno));
close (fd);
return -1;
}
if (cdevhdr.options & CCKD_OPENED)
memset (dev, 0, sizeof(DEVBLK));

/* open the file */
hostpath(dev->filename, argv[i], sizeof(dev->filename));
dev->fd = open (dev->filename, O_RDWR|O_BINARY);
if (dev->fd < 0)
{
fprintf (stderr, _("cckdcomp: OPENED bit is on, use `-f'\n"));
close (fd);
return -1;
cckdumsg (dev, 700, "open error: %s\n", strerror(errno));
continue;
}
}

/* call chkdsk() if level was specified */
if (level >= 0)
{
rc = cckd_chkdsk (fd, stderr, level);
if (rc < 0)
/* Check CCKD_OPENED bit if -f not specified */
if (!force)
{
fprintf (stderr,
"cckdcomp: terminating due to chkdsk errors%s\n", "");
return -1;
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) */

/* call chkdsk */
if (cckd_chkdsk (dev, level) < 0)
{
cckdumsg (dev, 708, "chkdsk errors\n");
close (dev->fd);
continue;
}
}

/* call the actual compress function */
rc = cckd_comp (fd, stderr);

/* call compress */
rc = cckd_comp (dev);

close (fd);
close (dev->fd);

return rc;
} /* for each arg */

return 0;
}

/*-------------------------------------------------------------------*/
Expand All @@ -122,7 +125,7 @@ char pathname[MAX_PATH]; /* file path in host format */

int syntax()
{
fprintf (stderr, "\ncckdcomp [-v] [-f] [-level] file-name\n"
fprintf (stderr, "\ncckdcomp [-v] [-f] [-level] file1 [file2 ... ]\n"
"\n"
" -v display version and exit\n"
"\n"
Expand All @@ -131,8 +134,9 @@ int syntax()
" 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 don't check\n"
" default 0\n"
"\n");
return -1;
}
Loading

0 comments on commit 09c9200

Please sign in to comment.