1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/*
* dasdls
*
* Copyright 2000-2009 by Malcolm Beattie
* Based on code copyright by Roger Bowler, 1999-2009
*
* $Id: dasdls.c 5125 2009-01-23 12:01:44Z bernard $
*
* $Log$
* Revision 1.27 2008/11/04 04:50:46 fish
* Ensure consistent utility startup
*
* Revision 1.26 2007/06/23 00:04:08 ivan
* Update copyright notices to include current year (2007)
*
* Revision 1.25 2006/12/08 09:43:19 jj
* Add CVS message log
*
*/
#include "hstdinc.h"
#include "hercules.h"
#include "dasdblks.h"
static int needsep = 0; /* Write newline separator next time */
int end_of_track(BYTE *p)
{
return p[0] == 0xff && p[1] == 0xff && p[2] == 0xff && p[3] == 0xff
&& p[4] == 0xff && p[5] == 0xff && p[6] == 0xff && p[7] == 0xff;
}
/* list_contents partly based on dasdutil.c:search_key_equal */
int list_contents(CIFBLK *cif, char *volser, DSXTENT *extent)
{
int cext = 0;
int ccyl = (extent[cext].xtbcyl[0] << 8) | extent[cext].xtbcyl[1];
int chead = (extent[cext].xtbtrk[0] << 8) | extent[cext].xtbtrk[1];
int ecyl = (extent[cext].xtecyl[0] << 8) | extent[cext].xtecyl[1];
int ehead = (extent[cext].xtetrk[0] << 8) | extent[cext].xtetrk[1];
#ifdef EXTERNALGUI
if (extgui) fprintf(stderr,"ETRK=%d\n",((ecyl*(cif->heads))+ehead));
#endif /*EXTERNALGUI*/
printf("%s%s: VOLSER=%s\n", needsep ? "\n" : "", cif->fname, volser);
needsep = 1;
do {
BYTE *ptr;
int rc = read_track(cif, ccyl, chead);
#ifdef EXTERNALGUI
if (extgui) fprintf(stderr,"CTRK=%d\n",((ccyl*(cif->heads))+chead));
#endif /*EXTERNALGUI*/
if (rc < 0)
return -1;
ptr = cif->trkbuf + CKDDASD_TRKHDR_SIZE;
while (!end_of_track(ptr)) {
char dsname[45];
CKDDASD_RECHDR *rechdr = (CKDDASD_RECHDR*)ptr;
int kl = rechdr->klen;
int dl = (rechdr->dlen[0] << 8) | rechdr->dlen[1];
make_asciiz(dsname, sizeof(dsname), ptr + CKDDASD_RECHDR_SIZE, kl);
/* XXXX Is this a suitable sanity check for a legal dsname? */
if (isalnum(*dsname))
printf("%s\n", dsname);
ptr += CKDDASD_RECHDR_SIZE + kl + dl;
}
chead++;
if (chead >= cif->heads) {
ccyl++;
chead = 0;
}
} while (ccyl < ecyl || (ccyl == ecyl && chead <= ehead));
return 0;
}
/* do_ls_cif based on dasdutil.c:build_extent_array */
int do_ls_cif(CIFBLK *cif)
{
int rc, cyl, head, rec, len;
unsigned char *vol1data;
FORMAT4_DSCB *f4dscb;
char volser[7];
rc = read_block(cif, 0, 0, 3, 0, 0, &vol1data, &len);
if (rc < 0)
return -1;
if (rc > 0) {
fprintf(stderr, "VOL1 record not found\n");
return -1;
}
make_asciiz(volser, sizeof(volser), vol1data+4, 6);
cyl = (vol1data[11] << 8) | vol1data[12];
head = (vol1data[13] << 8) | vol1data[14];
rec = vol1data[15];
rc = read_block(cif, cyl, head, rec, (void *)&f4dscb, &len, 0, 0);
if (rc < 0)
return -1;
if (rc > 0) {
fprintf(stderr, "F4DSCB record not found\n");
return -1;
}
return list_contents(cif, volser, &f4dscb->ds4vtoce);
}
int do_ls(char *file, char *sfile)
{
CIFBLK *cif = open_ckd_image(file, sfile, O_RDONLY|O_BINARY, 0);
if (!cif || do_ls_cif(cif) || close_ckd_image(cif))
return -1;
return 0;
}
int main(int argc, char **argv)
{
int rc = 0;
char *fn, *sfn;
INITIALIZE_UTILITY("dasdls");
/* Display program info message */
display_version (stderr, "Hercules DASD list program ", FALSE);
if (argc < 2) {
fprintf(stderr, "Usage: dasdls dasd_image [sf=shadow-file-name]...\n");
exit(2);
}
/*
* If your version of Hercules doesn't have support in its
* dasdutil.c for turning off verbose messages, then remove
* the following line but you'll have to live with chatty
* progress output on stdout.
*/
set_verbose_util(0);
while (*++argv)
{
fn = *argv;
if (*(argv+1) && strlen (*(argv+1)) > 3 && !memcmp(*(argv+1), "sf=", 3))
sfn = *++argv;
else sfn = NULL;
if (do_ls(fn, sfn))
rc = 1;
}
return rc;
}
|