1 /* DASDBLKS.H   (c) Copyright Roger Bowler, 1999-2009                */
2 /*              DASD control block structures                        */
3 
4 /*-------------------------------------------------------------------*/
5 /* This header file contains definitions of OS Data Management       */
6 /* control block structures for use by the Hercules DASD utilities.  */
7 /* It also contains function prototypes for the DASD utilities.      */
8 /*-------------------------------------------------------------------*/
9 
10 #include "hercules.h"
11 
12 #ifndef _DASDUTIL_C_
13 #ifndef _HDASD_DLL_
14 #define DUT_DLL_IMPORT DLL_IMPORT
15 #else   /* _HDASD_DLL_ */
16 #define DUT_DLL_IMPORT extern
17 #endif  /* _HDASD_DLL_ */
18 #else
19 #define DUT_DLL_IMPORT DLL_EXPORT
20 #endif
21 //  Forward references...
22 
23 typedef  struct  FORMAT1_DSCB   FORMAT1_DSCB;   // DSCB1: Dataset descriptor
24 typedef  struct  FORMAT3_DSCB   FORMAT3_DSCB;   // DSCB3: Additional extents
25 typedef  struct  FORMAT4_DSCB   FORMAT4_DSCB;   // DSCB4: VTOC descriptor
26 typedef  struct  FORMAT5_DSCB   FORMAT5_DSCB;   // DSCB5: Free space map
27 
28 typedef  struct  F5AVEXT        F5AVEXT;        // Available extent in DSCB5
29 typedef  struct  DSXTENT        DSXTENT;        // Dataset extent descriptor
30 
31 typedef  struct  PDSDIR         PDSDIR;         // PDS directory entry
32 typedef  struct  CIFBLK         CIFBLK;         // CKD image file descriptor
33 
34 typedef  struct  COPYR1         COPYR1;         // IEBCOPY header record 1
35 typedef  struct  COPYR2         COPYR2;         // IEBCOPY header record 2
36 typedef  struct  DATABLK        DATABLK;        // IEBCOPY unload data rec
37 
38 #define  MAX_TRACKS   32767
39 
40 /*-------------------------------------------------------------------*/
41 /* Definition of DSCB records in VTOC                                */
42 /*-------------------------------------------------------------------*/
43 struct DSXTENT {                        /* Dataset extent descriptor */
44         BYTE    xttype;                 /* Extent type               */
45         BYTE    xtseqn;                 /* Extent sequence number    */
46         HWORD   xtbcyl;                 /* Extent begin cylinder     */
47         HWORD   xtbtrk;                 /* Extent begin track        */
48         HWORD   xtecyl;                 /* Extent end cylinder       */
49         HWORD   xtetrk;                 /* Extent end track          */
50 };
51 
52 /* Bit definitions for extent type */
53 #define XTTYPE_UNUSED           0x00    /* Unused extent descriptor  */
54 #define XTTYPE_DATA             0x01    /* Data extent               */
55 #define XTTYPE_OVERFLOW         0x02    /* Overflow extent           */
56 #define XTTYPE_INDEX            0x04    /* Index extent              */
57 #define XTTYPE_USERLBL          0x40    /* User label extent         */
58 #define XTTYPE_SHARCYL          0x80    /* Shared cylinders          */
59 #define XTTYPE_CYLBOUND         0x81    /* Extent on cyl boundary    */
60 
61 struct FORMAT1_DSCB {                   /* DSCB1: Dataset descriptor */
62         BYTE    ds1dsnam[44];           /* Key (44 byte dataset name)*/
63         BYTE    ds1fmtid;               /* Format identifier (0xF1)  */
64         BYTE    ds1dssn[6];             /* Volume serial number      */
65         HWORD   ds1volsq;               /* Volume sequence number    */
66         BYTE    ds1credt[3];            /* Dataset creation date...
67                                            ...byte 0: Binary year-1900
68                                            ...bytes 1-2: Binary day  */
69         BYTE    ds1expdt[3];            /* Dataset expiry date       */
70         BYTE    ds1noepv;               /* Number of extents         */
71         BYTE    ds1bodbd;               /* #bytes used in last dirblk*/
72         BYTE    resv1;                  /* Reserved                  */
73         BYTE    ds1syscd[13];           /* System code (IBMOSVS2)    */
74         BYTE    resv2[7];               /* Reserved                  */
75         BYTE    ds1dsorg[2];            /* Dataset organization      */
76         BYTE    ds1recfm;               /* Record format             */
77         BYTE    ds1optcd;               /* Option codes              */
78         HWORD   ds1blkl;                /* Block length              */
79         HWORD   ds1lrecl;               /* Logical record length     */
80         BYTE    ds1keyl;                /* Key length                */
81         HWORD   ds1rkp;                 /* Relative key position     */
82         BYTE    ds1dsind;               /* Dataset indicators        */
83         FWORD   ds1scalo;               /* Secondary allocation...
84                                            ...byte 0: Allocation units
85                                            ...bytes 1-3: Quantity    */
86         BYTE    ds1lstar[3];            /* Last used TTR             */
87         HWORD   ds1trbal;               /* Bytes unused on last trk  */
88         BYTE    resv3[2];               /* Reserved                  */
89         DSXTENT ds1ext1;                /* First extent descriptor   */
90         DSXTENT ds1ext2;                /* Second extent descriptor  */
91         DSXTENT ds1ext3;                /* Third extent descriptor   */
92         BYTE    ds1ptrds[5];            /* CCHHR of F2 or F3 DSCB    */
93 };
94 
95 /* Bit definitions for ds1dsind */
96 #define DS1DSIND_LASTVOL        0x80    /* Last volume of dataset    */
97 #define DS1DSIND_RACFIND        0x40    /* RACF indicated            */
98 #define DS1DSIND_BLKSIZ8        0x20    /* Blocksize multiple of 8   */
99 #define DS1DSIND_PASSWD         0x10    /* Password protected        */
100 #define DS1DSIND_WRTPROT        0x04    /* Write protected           */
101 #define DS1DSIND_UPDATED        0x02    /* Updated since last backup */
102 #define DS1DSIND_SECCKPT        0x01    /* Secure checkpoint dataset */
103 
104 /* Bit definitions for ds1optcd */
105 #define DS1OPTCD_ICFDSET        0x80    /* Dataset in ICF catalog    */
106 #define DS1OPTCD_ICFCTLG        0x40    /* ICF catalog               */
107 
108 /* Bit definitions for ds1scalo byte 0 */
109 #define DS1SCALO_UNITS          0xC0    /* Allocation units...       */
110 #define DS1SCALO_UNITS_ABSTR    0x00    /* ...absolute tracks        */
111 #define DS1SCALO_UNITS_BLK      0x40    /* ...blocks                 */
112 #define DS1SCALO_UNITS_TRK      0x80    /* ...tracks                 */
113 #define DS1SCALO_UNITS_CYL      0xC0    /* ...cylinders              */
114 #define DS1SCALO_CONTIG         0x08    /* Contiguous space          */
115 #define DS1SCALO_MXIG           0x04    /* Maximum contiguous extent */
116 #define DS1SCALO_ALX            0x02    /* Up to 5 largest extents   */
117 #define DS1SCALO_ROUND          0x01    /* Round to cylinders        */
118 
119 struct FORMAT3_DSCB {                   /* DSCB3: Additional extents */
120         BYTE    ds3keyid[4];            /* Key (4 bytes of 0x03)     */
121         DSXTENT ds3extnt[4];            /* Four extent descriptors   */
122         BYTE    ds3fmtid;               /* Format identifier (0xF3)  */
123         DSXTENT ds3adext[9];            /* Nine extent descriptors   */
124         BYTE    ds3ptrds[5];            /* CCHHR of next F3 DSCB     */
125 };
126 
127 struct FORMAT4_DSCB {                   /* DSCB4: VTOC descriptor    */
128         BYTE    ds4keyid[44];           /* Key (44 bytes of 0x04)    */
129         BYTE    ds4fmtid;               /* Format identifier (0xF4)  */
130         BYTE    ds4hpchr[5];            /* CCHHR of highest F1 DSCB  */
131         HWORD   ds4dsrec;               /* Number of format 0 DSCBs  */
132         BYTE    ds4hcchh[4];            /* CCHH of next avail alt trk*/
133         HWORD   ds4noatk;               /* Number of avail alt tracks*/
134         BYTE    ds4vtoci;               /* VTOC indicators           */
135         BYTE    ds4noext;               /* Number of extents in VTOC */
136         BYTE    resv1[2];               /* Reserved                  */
137         FWORD   ds4devsz;               /* Device size (CCHH)        */
138         HWORD   ds4devtk;               /* Device track length       */
139         BYTE    ds4devi;                /* Non-last keyed blk overhd */
140         BYTE    ds4devl;                /* Last keyed block overhead */
141         BYTE    ds4devk;                /* Non-keyed block difference*/
142         BYTE    ds4devfg;               /* Device flags              */
143         HWORD   ds4devtl;               /* Device tolerance          */
144         BYTE    ds4devdt;               /* Number of DSCBs per track */
145         BYTE    ds4devdb;               /* Number of dirblks/track   */
146         DBLWRD  ds4amtim;               /* VSAM timestamp            */
147         BYTE    ds4vsind;               /* VSAM indicators           */
148         HWORD   ds4vscra;               /* CRA track location        */
149         DBLWRD  ds4r2tim;               /* VSAM vol/cat timestamp    */
150         BYTE    resv2[5];               /* Reserved                  */
151         BYTE    ds4f6ptr[5];            /* CCHHR of first F6 DSCB    */
152         DSXTENT ds4vtoce;               /* VTOC extent descriptor    */
153         BYTE    resv3[25];              /* Reserved                  */
154 };
155 
156 /* Bit definitions for ds4vtoci */
157 #define DS4VTOCI_DOS            0x80    /* Format 5 DSCBs not valid  */
158 #define DS4VTOCI_IXDISAB        0x40    /* VTOC index disabled       */
159 #define DS4VTOCI_DOSSTCK        0x10    /* DOS stacked pack          */
160 #define DS4VTOCI_DOSCNVT        0x08    /* DOS converted pack        */
161 #define DS4VTOCI_DIRF           0x04    /* VTOC contains errors      */
162 #define DS4VTOCI_DIRFCVT        0x02    /* DIRF reclaimed            */
163 #define DS4VTOCI_IXVTOC         0x01    /* Indexed VTOC              */
164 
165 /* Bit definitions for ds4devfg */
166 #define DS4DEVFG_TOL            0x01    /* Tolerance factor applies to
167                                            all but last block of trk */
168 
169 struct F5AVEXT {                       /* Available extent in DSCB5 */
170         HWORD   btrk;                   /* Extent begin track address*/
171         HWORD   ncyl;                   /* Number of full cylinders  */
172         BYTE    ntrk;                   /* Number of odd tracks      */
173 };
174 
175 struct FORMAT5_DSCB {                   /* DSCB5: Free space map     */
176         BYTE    ds5keyid[4];            /* Key (4 bytes of 0x05)     */
177         F5AVEXT ds5avext[8];            /* First 8 available extents */
178         BYTE    ds5fmtid;               /* Format identifier (0xF5)  */
179         F5AVEXT ds5mavet[18];           /* 18 more available extents */
180         BYTE    ds5ptrds[5];            /* CCHHR of next F5 DSCB     */
181 };
182 
183 /*-------------------------------------------------------------------*/
184 /* Definitions of DSORG and RECFM fields                             */
185 /*-------------------------------------------------------------------*/
186 /* Bit settings for dataset organization byte 0 */
187 #define DSORG_IS                0x80    /* Indexed sequential        */
188 #define DSORG_PS                0x40    /* Physically sequential     */
189 #define DSORG_DA                0x20    /* Direct access             */
190 #define DSORG_PO                0x02    /* Partitioned organization  */
191 #define DSORG_U                 0x01    /* Unmovable                 */
192 
193 /* Bit settings for dataset organization byte 1 */
194 #define DSORG_AM                0x08    /* VSAM dataset              */
195 
196 /* Bit settings for record format */
197 #define RECFM_FORMAT            0xC0    /* Bits 0-1=Record format    */
198 #define RECFM_FORMAT_V          0x40    /* ...variable length        */
199 #define RECFM_FORMAT_F          0x80    /* ...fixed length           */
200 #define RECFM_FORMAT_U          0xC0    /* ...undefined length       */
201 #define RECFM_TRKOFLOW          0x20    /* Bit 2=Track overflow      */
202 #define RECFM_BLOCKED           0x10    /* Bit 3=Blocked             */
203 #define RECFM_SPANNED           0x08    /* Bit 4=Spanned or standard */
204 #define RECFM_CTLCHAR           0x06    /* Bits 5-6=Carriage control */
205 #define RECFM_CTLCHAR_A         0x04    /* ...ANSI carriage control  */
206 #define RECFM_CTLCHAR_M         0x02    /* ...Machine carriage ctl.  */
207 
208 /*-------------------------------------------------------------------*/
209 /* Definition of PDS directory entry                                 */
210 /*-------------------------------------------------------------------*/
211 struct PDSDIR {                         /* PDS directory entry       */
212         BYTE    pds2name[8];            /* Member name               */
213         BYTE    pds2ttrp[3];            /* TTR of first block        */
214         BYTE    pds2indc;               /* Indicator byte            */
215         BYTE    pds2usrd[62];           /* User data (0-31 halfwords)*/
216 };
217 
218 /* Bit definitions for PDS directory indicator byte */
219 #define PDS2INDC_ALIAS          0x80    /* Bit 0: Name is an alias   */
220 #define PDS2INDC_NTTR           0x60    /* Bits 1-2: User TTR count  */
221 #define PDS2INDC_NTTR_SHIFT     5       /* Shift count for NTTR      */
222 #define PDS2INDC_LUSR           0x1F    /* Bits 3-7: User halfwords  */
223 
224 /*-------------------------------------------------------------------*/
225 /* Text unit keys for transmit/receive                               */
226 /*-------------------------------------------------------------------*/
227 #define INMDDNAM        0x0001          /* DDNAME for the file       */
228 #define INMDSNAM        0x0002          /* Name of the file          */
229 #define INMMEMBR        0x0003          /* Member name list          */
230 #define INMSECND        0x000B          /* Secondary space quantity  */
231 #define INMDIR          0x000C          /* Directory space quantity  */
232 #define INMEXPDT        0x0022          /* Expiration date           */
233 #define INMTERM         0x0028          /* Data transmitted as msg   */
234 #define INMBLKSZ        0x0030          /* Block size                */
235 #define INMDSORG        0x003C          /* File organization         */
236 #define INMLRECL        0x0042          /* Logical record length     */
237 #define INMRECFM        0x0049          /* Record format             */
238 #define INMTNODE        0x1001          /* Target node name/number   */
239 #define INMTUID         0x1002          /* Target user ID            */
240 #define INMFNODE        0x1011          /* Origin node name/number   */
241 #define INMFUID         0x1012          /* Origin user ID            */
242 #define INMLREF         0x1020          /* Date last referenced      */
243 #define INMLCHG         0x1021          /* Date last changed         */
244 #define INMCREAT        0x1022          /* Creation date             */
245 #define INMFVERS        0x1023          /* Origin vers# of data fmt  */
246 #define INMFTIME        0x1024          /* Origin timestamp          */
247 #define INMTTIME        0x1025          /* Destination timestamp     */
248 #define INMFACK         0x1026          /* Originator request notify */
249 #define INMERRCD        0x1027          /* RECEIVE command error code*/
250 #define INMUTILN        0x1028          /* Name of utility program   */
251 #define INMUSERP        0x1029          /* User parameter string     */
252 #define INMRECCT        0x102A          /* Transmitted record count  */
253 #define INMSIZE         0x102C          /* File size in bytes        */
254 #define INMFFM          0x102D          /* Filemode number           */
255 #define INMNUMF         0x102F          /* #of files transmitted     */
256 #define INMTYPE         0x8012          /* Dataset type              */
257 
258 /*-------------------------------------------------------------------*/
259 /* Definitions of IEBCOPY header records                             */
260 /*-------------------------------------------------------------------*/
261 struct COPYR1 {                         /* IEBCOPY header record 1   */
262         BYTE    uldfmt;                 /* Unload format             */
263         BYTE    hdrid[3];               /* Header identifier         */
264         HWORD   ds1dsorg;               /* Dataset organization      */
265         HWORD   ds1blkl;                /* Block size                */
266         HWORD   ds1lrecl;               /* Logical record length     */
267         BYTE    ds1recfm;               /* Record format             */
268         BYTE    ds1keyl;                /* Key length                */
269         BYTE    ds1optcd;               /* Option codes              */
270         BYTE    ds1smsfg;               /* SMS indicators            */
271         HWORD   uldblksz;               /* Block size of container   */
272                                         /* Start of DEVTYPE fields   */
273         FWORD   ucbtype;                /* Original device type      */
274         FWORD   maxblksz;               /* Maximum block size        */
275         HWORD   cyls;                   /* Number of cylinders       */
276         HWORD   heads;                  /* Number of tracks/cylinder */
277         HWORD   tracklen;               /* Track length              */
278         HWORD   overhead;               /* Block overhead            */
279         BYTE    keyovhead;              /* Keyed block overhead      */
280         BYTE    devflags;               /* Flags                     */
281         HWORD   tolerance;              /* Tolerance factor          */
282                                         /* End of DEVTYPE fields     */
283         HWORD   hdrcount;               /* Number of header records
284                                            (if zero, then 2 headers) */
285         BYTE    resv1;                  /* Reserved                  */
286         BYTE    ds1refd[3];             /* Last reference date       */
287         BYTE    ds1scext[3];            /* Secondary space extension */
288         BYTE    ds1scalo[4];            /* Secondary allocation      */
289         BYTE    ds1lstar[3];            /* Last track used TTR       */
290         HWORD   ds1trbal;               /* Last track balance        */
291         HWORD   resv2;                  /* Reserved                  */
292 };
293 
294 /* Bit settings for unload format byte */
295 #define COPYR1_ULD_FORMAT       0xC0    /* Bits 0-1=unload format... */
296 #define COPYR1_ULD_FORMAT_OLD   0x00    /* ...old format             */
297 #define COPYR1_ULD_FORMAT_PDSE  0x40    /* ...PDSE format            */
298 #define COPYR1_ULD_FORMAT_ERROR 0x80    /* ...error during unload    */
299 #define COPYR1_ULD_FORMAT_XFER  0xC0    /* ...transfer format        */
300 #define COPYR1_ULD_PROGRAM      0x10    /* Bit 3=Contains programs   */
301 #define COPYR1_ULD_PDSE         0x01    /* Bit 7=Contains PDSE       */
302 
303 /* Bit settings for header identifier */
304 #define COPYR1_HDRID    "\xCA\x6D\x0F"  /* Constant value for hdrid  */
305 
306 struct COPYR2 {                         /* IEBCOPY header record 2   */
307         BYTE    debbasic[16];           /* Last 16 bytes of basic
308                                            section of original DEB   */
309         BYTE    debxtent[16][16];       /* First 16 extent descriptors
310                                            from original DEB         */
311         FWORD   resv;                   /* Reserved                  */
312 };
313 
314 /*-------------------------------------------------------------------*/
315 /* Definition of data record block in IEBCOPY unload file            */
316 /*-------------------------------------------------------------------*/
317 struct DATABLK {                        /* IEBCOPY unload data rec   */
318         FWORD   header;                 /* Reserved                  */
319         HWORD   cyl;                    /* Cylinder number           */
320         HWORD   head;                   /* Head number               */
321         BYTE    rec;                    /* Record number             */
322         BYTE    klen;                   /* Key length                */
323         HWORD   dlen;                   /* Data length               */
324 #define MAX_DATALEN      32767
325         BYTE    kdarea[MAX_DATALEN];    /* Key and data area         */
326 };
327 
328 /*-------------------------------------------------------------------*/
329 /* Internal structures used by DASD utility functions                */
330 /*-------------------------------------------------------------------*/
331 struct CIFBLK {                         /* CKD image file descriptor */
332         char   *fname;                  /* -> CKD image file name    */
333         int     fd;                     /* CKD image file descriptor */
334         int     trksz;                  /* CKD image track size      */
335         BYTE   *trkbuf;                 /* -> Track buffer           */
336         int     curcyl;                 /* Cylinder number of track
337                                            currently in track buffer */
338         int     curhead;                /* Head number of track
339                                            currently in track buffer */
340         int     trkmodif;               /* 1=Track has been modified */
341         int     heads;                  /* Tracks per cylinder       */
342         DEVBLK  devblk;                 /* Device Block              */
343 };
344 
345 /*-------------------------------------------------------------------*/
346 /* Macro definitions                                                 */
347 /*-------------------------------------------------------------------*/
348 #define ROUND_UP(x,y)   (((x)+(y)-1)/(y)*(y))
349 
350 /*-------------------------------------------------------------------*/
351 /* Function prototypes                                               */
352 /*-------------------------------------------------------------------*/
353 
354 /* Functions in module dasdutil.c */
355 DUT_DLL_IMPORT void string_to_upper (char *source);
356 DUT_DLL_IMPORT void string_to_lower (char *source);
357 DUT_DLL_IMPORT void convert_to_ebcdic (BYTE *dest, int len, char *source);
358 DUT_DLL_IMPORT int  make_asciiz (char *dest, int destlen, BYTE *src, int srclen);
359 DUT_DLL_IMPORT void data_dump (void *addr, int len);
360 DUT_DLL_IMPORT int  read_track (CIFBLK *cif, int cyl, int head);
361 int  rewrite_track (CIFBLK *cif);
362 DUT_DLL_IMPORT int  read_block (CIFBLK *cif, int cyl, int head, int rec,
363         BYTE **keyptr, int *keylen, BYTE **dataptr, int *datalen);
364 DUT_DLL_IMPORT int  search_key_equal (CIFBLK *cif, BYTE *key, int keylen, int noext,
365         DSXTENT extent[], int *cyl, int *head, int *rec);
366 DUT_DLL_IMPORT int  convert_tt (int tt, int noext, DSXTENT extent[], int heads,
367         int *cyl, int *head);
368 DUT_DLL_IMPORT CIFBLK* open_ckd_image (char *fname, char *sfname, int omode,
369         int dasdcopy);
370 DUT_DLL_IMPORT CIFBLK* open_fba_image (char *fname, char *sfname, int omode,
371         int dasdcopy);
372 DUT_DLL_IMPORT int  close_ckd_image (CIFBLK *cif);
373 #define close_image_file(cif) close_ckd_image((cif))
374 DUT_DLL_IMPORT int  build_extent_array (CIFBLK *cif, char *dsnama, DSXTENT extent[],
375         int *noext);
376 DUT_DLL_IMPORT int  capacity_calc (CIFBLK *cif, int used, int keylen, int datalen,
377         int *newused, int *trkbaln, int *physlen, int *kbconst,
378         int *lbconst, int *nkconst, BYTE*devflag, int *tolfact,
379         int *maxdlen, int *numrecs, int *numhead, int *numcyls);
380 DUT_DLL_IMPORT int create_ckd (char *fname, U16 devtype, U32 heads, U32 maxdlen,
381         U32 volcyls, char *volser, BYTE comp, int lfs, int dasdcopy,
382         int nullfmt, int rawflag);
383 DUT_DLL_IMPORT int create_fba (char *fname, U16 devtype, U32 sectsz, U32 sectors,
384         char *volser, BYTE comp, int lfs, int dasdcopy, int rawflag);
385 int create_compressed_fba (char *fname, U16 devtype, U32 sectsz,
386         U32 sectors, char *volser, BYTE comp, int lfs, int dasdcopy,
387         int rawflag);
388 int get_verbose_util(void);
389 DUT_DLL_IMPORT void set_verbose_util(int v);
390 
391 DUT_DLL_IMPORT int valid_dsname( const char *pszdsname );
392 #define DEFAULT_FBA_TYPE 0x3370
393