/** * @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 #include #include /** @brief Longest data set name. */ constexpr unsigned 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). */ constexpr unsigned CSI_FIELD_LEN = 162; /** @brief Smallest work area worth passing. */ constexpr unsigned 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. */ constexpr unsigned 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