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
|
/**
* @file mvsfmt.h
* @brief Formats of MVS data that zash reads: Catalog Search Interface
* work areas, PDS directory blocks and the TIOT.
*
* The decoders are plain C over byte buffers, compiled on every platform.
* On z/OS they read what IGGCSI00, the directory and the TIOT really
* hold. Elsewhere sys_posix.c builds the same bytes from a test catalog,
* so the decoding (and its bounds checks) runs under ASan, UBSan,
* Valgrind and a fuzzer long before it runs on z/OS.
*
* All multi-byte integers are big-endian and are read a byte at a time,
* so nothing here depends on the host's byte order or alignment.
*/
#ifndef ZASH_MVSFMT_H
#define ZASH_MVSFMT_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/** @brief Longest data set name. */
#define MVS_DSN_MAX 44
/** @brief IBM-1047 to ISO8859-1, with z/OS's NL/LF assignment. */
extern const unsigned char mvs_e2a[256];
/** @brief ISO8859-1 to IBM-1047, the inverse of #mvs_e2a. */
extern const unsigned char mvs_a2e[256];
void mvs_from_ebcdic(char *s, size_t n);
void mvs_to_ebcdic(char *s, size_t n);
void mvs_name(const unsigned char *field, size_t n, char *dst);
/**
* @brief Called with each name a listing finds.
* @param name The name, in the program's character set.
* @param type For catalog entries the CSI entry type as an ASCII letter
* ('A' non-VSAM, 'X' alias, ...). 0 for members and DD names.
* @param arg Caller's context.
*/
typedef void mvs_name_fn(const char *name, char type, void *arg);
/* ---- Catalog Search Interface ----------------------------------------- */
/** @brief Selection criteria with one field name (CSIFIELD). */
#define CSI_FIELD_LEN 162
/** @brief Smallest work area worth passing. */
#define CSI_WORK_MIN 1024
/**
* @brief The three areas of a CSI call, as IGGCSI00 sees them.
*
* On z/OS all three must be 31-bit addresses (below 2 GB), because
* IGGCSI00 is AMODE 31.
*/
typedef struct csi_area {
unsigned char *reason; /**< 4 bytes: module ID, reason, return code */
unsigned char *field; /**< CSI_FIELD_LEN bytes of selection criteria */
unsigned char *work; /**< return work area */
uint32_t worklen; /**< its size */
} csi_area;
/**
* @brief Performs one IGGCSI00 call on an area.
* @return The return code in register 15 (0 OK, 4 some entries in
* error, 8 and up the request failed).
*/
typedef int csi_call_fn(csi_area *a, void *ctx);
bool csi_filter_ok(const char *filter);
bool mvs_dsn_ok(const char *dsn);
void csi_build(unsigned char *field, const char *filter);
bool csi_parse(const unsigned char *work, size_t worklen, mvs_name_fn *fn,
void *arg);
bool csi_search(const char *filter, csi_area *a, csi_call_fn *call, void *ctx,
mvs_name_fn *fn, void *arg);
/* ---- PDS directories and the TIOT -------------------------------------- */
/** @brief Size of a PDS directory block. */
#define PDS_DIRBLK 256
bool pds_parse_block(const unsigned char *blk, mvs_name_fn *fn, void *arg,
bool *end);
bool tiot_parse(const unsigned char *entries, size_t maxlen, mvs_name_fn *fn,
void *arg);
#endif
|