Initial s390-tools-2.0.0 import

This commit is based on the s390-tools-1.39.0 version.

Changes on top of s390-tools-1.39.0:

 - Add MIT license to all source files
 - Add LICENSE file
 - Transform REAMDE to README.md (markdown)
 - Add AUTHORS.md file
 - Add CONTRIBUTING.md file
 - Move changelog from README to CHANGELOG.md file

Reviewed-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
This commit is contained in:
Michael Holzheu
2017-08-07 16:13:17 +02:00
commit b627b8d8e1
647 changed files with 168974 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
/*
* ccw - Channel Command Word library (traditional I/O)
*
* Copyright 2017 IBM Corp.
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_CCW_H
#define LIB_CCW_H
#include <stdbool.h>
#include "lib/zt_common.h"
/**
* ccw_devid - CCW device ID
*/
struct ccw_devid {
/** Channel Subsystem ID */
unsigned int cssid:8;
/** Subchannel set ID */
unsigned int ssid:8;
/** Device number */
unsigned int devno:16;
} __packed;
/**
* Initialize ccw_devid structure
*
* @param[in,out] devid Pointer to ccw_devid structure to be initialized
* @param[in] cssid Channel Subsystem ID
* @param[in] ssid Subchannel set ID
* @param[in] devno Device number
*/
static inline void ccw_devid_init(struct ccw_devid *devid,
unsigned int cssid, unsigned int ssid,
unsigned int devno)
{
devid->cssid = cssid;
devid->ssid = ssid;
devid->devno = devno;
}
bool ccw_parse_str(struct ccw_devid *devid, const char *id);
#endif
+21
View File
@@ -0,0 +1,21 @@
/*
* dasd - Library for DASD related functions
*
* DASD related helper functions for accessing device information via sysfs
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_DASD_SYS_H
#define LIB_DASD_SYS_H
#include <stdio.h>
#include "u2s.h"
int dasd_sys_raw_track_access(char *);
int dasd_reset_chpid(char *, char *);
#endif /* LIB_DASD_SYS_H */
+816
View File
@@ -0,0 +1,816 @@
/**
* \file libzds.h
* This is the main header file for the internal library libzds.
* Please note that this library should currently only be used
* by programs in the s390-tools package. It is not yet meant
* for external use as interfaces and definitions may change
* without further notice.
*
* Copyright IBM Corp. 2013, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
/**
* @mainpage
* The libzds is a s390-tools internal library for use with DASD
* devices in raw_track_access mode.
*
* The regular operation mode of the DASD device driver allows only to
* access ECKD DASDs that were formatted with a specific record
* layout. The raw access mode of the DASD device driver allows to
* access any kind of ECKD DASD, but requires the correct use of
* the DIRECT_IO interface and leaves the interpretation of the data
* format on these devices to the user.
*
* This library supports the use of raw DASD devices by providing
* functions that
* @li access the device with DIRECT_IO and the correct buffer alignment
* @li provide access to label and VTOC data on the device
* @li provide access to simple z/OS data set formats
* (physical sequential (PS) and partitioned data sets (PDS))
*
*
* @section interface_groups Library Interface
*
* @subsection interface_structures Data Structures
*
* The data structures provided by this library can be divided into
* two types: Structures that represent external hardware and software
* interfaces, and structures that are defined by libzds itself:
*
* @ref external_interfaces
*
* @ref libzds_data
*
*
* @subsection interface_functions Functions
*
* The functions provided by this library are divided into 5 categories:
* base, low, mid, and highlevel functions and helper functions.
*
* The lower the level, the less dependent are the functions on the data
* that is stored on the DASDs. The higher the level the more abstract
* are the implemented concepts.
*
* The base level functions are needed to setup the internal data
* structures which the other functions work on. Otherwise, he use of higher
* level functions does not require the use of low level functions.
* For example: To simply read data from a data set, you just need the
* base and high level functions and can ignore the low and mid level
* functions.
*
* \ref libzds_functions_base
*
* \ref libzds_functions_low
*
* \ref libzds_functions_mid
*
* \ref libzds_functions_high
*
* \ref libzds_functions_helper
*
*
* @section naming_scheme Naming Scheme
*
* All interface functions start with lzds_ for libzds (could be changed later
* but libzds_ is quite long). Next is the entity the function works on,
* for example
* @li @c lzds_zdsroot_...
* @li @c lzds_dasd_...
*
* So if you know what entity you want to work on, you know where to look.
*
* Then follows the operation (add, get, read, alloc, ...).
* There are several verbs that can mean 'access data'.
* As a guideline we define the following meaning for use in this library:
* @li read: Will result in data being read from a device
* @li get: Get a value from one of the internal structures
* @li extract: Use the internal data to create higher level data,
* e.g. use the VTOC information of a DASD to create data
* set structures
* @li alloc: Create and return a libzds data structure
*
* @note For every alloc function there shall be a matching free function to
* release the memory. However, often the structure is created in the
* context of a another structure, but when it is freed, that is done in
* its own context. For example:
* lzds_zdsroot_alloc_dasditerator is matched by lzds_dasditerator_free
*
* Finally the object of the operation, what you want to get or achieve,
* e.g lzds_ds_get_is_PDS
*
* For the parmeter list, the general rule is:
* The subject comes first, the object last, further parameters in between.
*/
#ifndef LIB_LIBZDS_H
/**
* @brief Watchdog for libzds.h inclusion.
*/
#define LIB_LIBZDS_H
#include "vtoc.h"
/**
* \defgroup external_interfaces External constants and structures.
* @{
* @brief These constants and structures are related to
* hardware and software interfaces that are specified outside of
* libzds.
*
* @li For a description of ECKD data formats see
* 'IBM 3990/9390 Storage Control Reference', Document Number GA32-0274-05
* @li For a description of VTOC entries see
* 'z/OS DFSMSdfp Advanced Services', Document Number SC26-7400-11
* @li For a description of physical sequential and partitioned data sets see
* 'z/OS DFSMS Using Data Sets', Document Number SC26-7410-11
* @li For a description of the Linux on System z DASD device driver see
* 'Device Drivers, Features, and Commands (kernel 3.7)',
* Document Number SC33-8411-18
*/
/**
* @brief The size of one raw track when read via the DASD device driver
* with raw_track_access.
*
* When reading from a DASD in raw_track_access mode, you need to
* align your I/O to multiples of this size.
*/
#define RAWTRACKSIZE 65536
/**
* @brief Maximum size of one record on a track
*
* This is the maximum size of a single record on a track. If a track contains
* multiple records, the additional overhead will cause the sum of these
* multiple records to be smaller than the biggest single record, so MAXRECSIZE
* is also the upper limit for user data that a single track can hold.
*/
#define MAXRECSIZE 56664
/**
* @brief Maximum number of extents a data set can hold.
*
* We do not handle extended format data sets so we can have a total of 16
* extents per dataset (3 in the f1 and 13 in the f3 label).
*/
#define MAXEXTENTS 16
/**
* @brief Maximum size of a data set name string (including one byte for
* 0-termination)
*/
#define MAXDSNAMELENGTH 45
/**
* @brief Maximum size of a partitioned data set member name string
* (including one byte for 0-termination)
*/
#define MEMBERNAMELENGTH 9
/**
* @brief The maximum number of volumes (devices) that a multi volume data
* set can span.
*/
#define MAXVOLUMESPERDS 59
/**
* @brief Eight bytes of 0xFF are used in several cases to designate the end of data.
*
*/
#define ENDTOKEN 0xFFFFFFFFFFFFFFFFULL
/**
* @brief This structure represents the count field in an ECKD record.
*/
struct eckd_count {
/** @brief record ID
*
* In general the record ID is defined as just a 5 byte field.
* The interpretation of these 5 bytes as a struct cchhb_t is a common
* convention, which we assume here as well.
*/
cchhb_t recid;
/** @brief key length */
unsigned char kl;
/** @brief data length */
unsigned short dl;
} __attribute__ ((packed));
/**
* @brief A generic structure to describe a data set control block (DSCB)
*
* The elements of the VTOC are called DSCBs. All DSCBs have in common that
* they have a size of 140 bytes, and byte 44 is the identifier that
* determines the type of DSCB.
*/
struct dscb {
/** @brief key area
*
* This part of the DSCB is usually stored in the key part of an
* ECKD record in the VTOC. The contents depends on the format.
*/
char key[44];
/** @brief Format identifier
*
* This identifier determines the data layout of the rest of the
* DSCB. In a format-x DSCB this field is called DSxFMTID.
* The identifiers for format-1 to format-9 are the respective
* EBCDIC characters '1' to '9' (0xf1 to 0xf9).
* An empty DSCB record (format-0 DSCB) contains 140 zeros, so
* here the format id is 0x00.
*/
char fmtid;
/** @brief The residual data part of the DSCB
*
* The contents depends on the format.
*/
char data[95];
} __attribute__ ((packed));
/**
* @brief This structure represents a segment descriptor word (SDW),
* record descriptor word (RDW) or block descriptor word (BDW).
*
* These are used to describe data set blocks and records.
* (see z/OS DFSMS Using Data Sets)
*/
struct segment_header {
/** @brief Is this an empty segment (valid for SDW) */
unsigned short nullsegment:1;
/** @brief Length of the segment */
unsigned short length:15;
/** @brief reserved */
unsigned char reserved1:6;
/** @brief Segment control code (valid for SDW)
*
* 0: logical record consists of just this segment,
* 1: first segment in the logical record,
* 2: last segment in the logical record,
* 3: intermediate in the logical record
*/
unsigned char position:2;
/** @brief reserved */
unsigned char reserved3:8;
} __attribute__ ((packed));
/**
* @brief The key length of a PDS directory member record.
*/
#define PDS_DIR_KL 8
/**
* @brief The data length of a PDS directory member record.
*/
#define PDS_DIR_DL 256
/**
* @brief This structure represents and entry in the PDS directory and
* describes a member of the data set.
*
* This structure represents only the fixed part of the member
* entry. The variable size of the user data part is determined
* by the entry user_data_count.
* (see z/OS DFSMS Using Data Sets)
*/
struct pds_member_entry {
/** @brief Member name */
char name[8];
/** @brief Start track of the member (relative to start of the PDS) */
unsigned short track;
/** @brief Start record of the member */
unsigned char record;
/** @brief Is this entry an alias for another entry? */
unsigned char is_alias:1;
/** @brief How many TTRN note lists are contained in the user data. */
unsigned char ttrn_count:2;
/** @brief The user_data_count value counts 'half words' i.e. shorts! */
unsigned char user_data_count:5;
} __attribute__ ((packed));
/** @} */ /* end of group hardware */
/**
* @defgroup libzds_data libzds data structures
* @{
* @brief These are the data structures used by the libzds API.
*
* For users of libzds these are opaque data structures and they have
* no dependency on the implementation details of these structures.
* All libzds interface functions work on pointers to these structures,
* so programs that use the library do not need to know them either.
* This prevents users from accessing the data in unsupported ways
* allows us to change the implementation without changing the
* interface.
*/
/**
* @struct zdsroot
* @brief The root of all device and data set information.
*
* Note that data sets do not belong to DASDs, as they
* may span over more than one DASD.
*/
struct zdsroot;
/**
* @struct dasd
* @brief Represents one physical device, may have a vtoc
*/
struct dasd;
/**
* @struct dasditerator
* @brief Allows to iterate over all dasds in the zdsroot
*/
struct dasditerator;
/**
* @struct dasdhandle
* @brief Represents the state of a DASD device while it is in use.
*
* For applications that need to read data directly from a DASD device.
* The idea is to have an abstract handle for a DASD that is in
* use, similar to a FILE pointer
*/
struct dasdhandle;
/**
* @struct raw_vtoc
* @brief The VTOC is a directory of data sets on one dasd
*/
struct raw_vtoc;
/**
* @struct dscbiterator
* @brief allows to iterate over all DSCBs in a vtoc
*/
struct dscbiterator;
/**
* @struct dataset
* @brief The whole of one data set
*
* May refer to one or more dataset parts
* and may have a list of partitioned dataset members.
*/
struct dataset;
/**
* @struct dsiterator
* @brief Allows to iterate over all data sets in the zdsroot
*/
struct dsiterator;
/**
* @struct pdsmember
* @brief If a data set is a partitioned data set (PDS) it
* may have zero or more PDS members
*/
struct pdsmember;
/**
* @struct memberiterator
* @brief Allows to iterate over all members in the dataset
*/
struct memberiterator;
/**
* @struct dshandle
* @brief Represents the state of a data set while it is in use
*
* This state includes the I/O buffers used for reading,
* the position within the data set, options used for processing the data,
* etc. The idea is to have an abstract handle for a data set that is in
* use, similar to a FILE pointer.
*/
struct dshandle;
/**
* @struct error_log
* @brief A stack of error messages that are related to the last error
*/
struct errorlog;
/** @} */ /* end of group libzds_data */
/**
* @defgroup libzds_functions_base Base functions
* @{
* @brief These functions are basic setup functions which need to
* be used before any of the low, mid or high level functions
* can be used. These functions concern the allocation and
* initialization of the zdsroot and the basic handling of devices.
*/
/**
* @brief Allocate a new zdsroot structure.
*/
int lzds_zdsroot_alloc(struct zdsroot **root);
/**
* @brief Free the memory of the given zdsroot structure.
*/
void lzds_zdsroot_free(struct zdsroot *root);
/**
* @brief Add a DASD device to the zdsroot.
*/
int lzds_zdsroot_add_device(struct zdsroot *root, const char *devnode,
struct dasd **dasd);
/**
* @brief Get the errorlog.
*/
void lzds_dasd_get_errorlog(struct dasd *dasd, struct errorlog **log);
/**
* @brief Allocate index that allows to iterate through all DASDs
* stored in the root.
*/
int lzds_zdsroot_alloc_dasditerator(struct zdsroot *root,
struct dasditerator **it);
/**
* @brief Free the dasditerator structure.
*/
void lzds_dasditerator_free(struct dasditerator *it);
/**
* @brief Get the next dasd structure.
*/
int lzds_dasditerator_get_next_dasd(struct dasditerator *it,
struct dasd **dasd);
/**
* @brief Return the device node name that was used for this dasd.
*/
void lzds_dasd_get_device(struct dasd *dasd, char **device);
/**
* @brief Get the dasd structure that belongs to the given device.
*/
int lzds_zdsroot_get_dasd_by_node_name(struct zdsroot *root, const char *device,
struct dasd **dasd);
/**
* @brief Get the errorlog.
*/
void lzds_zdsroot_get_errorlog(struct zdsroot *root, struct errorlog **log);
int lzds_errorlog_fprint(struct errorlog *log, FILE *stream);
/** @} */ /* end of group libzds_functions_base */
/**
* @defgroup libzds_functions_low Low level interface functions.
* @{
* @brief Very basic functions, should all work on every kind DASD.
*
* These functions give access to the data on a DASD on a very
* low abstraction level. They do not dependent on the data on the
* device itself.
*
*/
/**
* @brief Based on the dasd device geometry, compute a track number from a
* given cchh_t (cylinder, head) address value.
*/
void lzds_dasd_cchh2trk(struct dasd *dasd, cchh_t *p, unsigned int *track);
/**
* @brief Get the number of cylinders that this DASD has.
*/
void lzds_dasd_get_cylinders(struct dasd *dasd, unsigned int *cylinders);
/**
* @brief Get the number of heads, that a cylinder of this DASD has.
*/
void lzds_dasd_get_heads(struct dasd *dasd, unsigned int *heads);
/**
* @brief Allocate a new dasd context structure for given data set.
*/
int lzds_dasd_alloc_dasdhandle(struct dasd *dasd, struct dasdhandle **dasdh);
/**
* @brief Free memory that was allocated for a dasdhandle.
*/
void lzds_dasdhandle_free(struct dasdhandle *dasdh);
/**
* @brief This makes the dasd context ready for read operations.
*/
int lzds_dasdhandle_open(struct dasdhandle *dasdh);
/**
* @brief This closes the file descriptor connected with the dasdhandle.
*/
int lzds_dasdhandle_close(struct dasdhandle *dasdh);
/**
* @brief Read raw tracks from the dasdhandle.
*/
int lzds_dasdhandle_read_tracks_to_buffer(struct dasdhandle *dasdh,
unsigned int starttrck,
unsigned int endtrck,
char *trackdata);
/** @} */ /* end of group libzds_functions_low */
/**
* @defgroup libzds_functions_mid Mid level interface functions
* @{
* @brief Functions that give access to low level structures like VTOC
* records.
*
* These functions give access to and rely on the meta data stored on
* the DASD, in particular the VTOC.
* These functions take the structure of the data on the
* device into account, so they may fail if this data is not
* correct (e.g. if the VTOC is broken).
*
* @todo The interface of the mid level functions is not properly structured yet.
*
*/
/**
* @brief Read the volume label from device. The data as stored as
* part of the struct dasd.
*/
int lzds_dasd_read_vlabel(struct dasd *dasd);
/**
* @brief Get the previously read volume label data..
*/
int lzds_dasd_get_vlabel(struct dasd *dasd, struct volume_label **vlabel);
/**
* @brief Read the vtoc data from device. The data as stored as part
* of the struct dasd.
*/
int lzds_dasd_read_rawvtoc(struct dasd *dasd);
/**
* @brief Get the previously read raw_vtoc data.
*/
int lzds_dasd_get_rawvtoc(struct dasd *dasd, struct raw_vtoc **vtoc);
/**
* @brief Allocate index that allows to iterate through all DSCB
* records stored in the raw_vtoc.
*/
int lzds_raw_vtoc_alloc_dscbiterator(struct raw_vtoc *rawvtoc,
struct dscbiterator **it);
/**
* @brief Free the iterators memory
*/
void lzds_dscbiterator_free(struct dscbiterator *it);
/**
* @brief Get the next DSCB in the VTOC.
*/
int lzds_dscbiterator_get_next_dscb(struct dscbiterator *it,
struct dscb **dscb);
/**
* @brief Find and get a specific DSCB record by its cylinder, head
* and record address (cchhb_t)
*/
int lzds_raw_vtoc_get_dscb_from_cchhb(struct raw_vtoc *rv, cchhb_t *p,
struct dscb **dscb);
/** @} */ /* end of group libzds_functions_mid */
/**
* @defgroup libzds_functions_high High level interface functions
* @{
* @brief These functions give access to the data on a DASD on a
* high abstraction level.
*
* These functions abstract away most of the low level details.
* They give access to the user data stored on the DASD using abstract
* concepts like 'data set' without requiring the user
* to do any low level analysis.
*/
/**
* @brief Search zdsroot for a specific data set.
*/
int lzds_zdsroot_find_dataset(struct zdsroot *root, const char *name,
struct dataset **ds);
/**
* @brief Allocate an iterator that will allow to iterate through all
* datasets on the index.
*/
int lzds_zdsroot_alloc_dsiterator(struct zdsroot *zdsroot,
struct dsiterator **it);
/**
* @brief Free memory of the given data set iterator.
*/
void lzds_dsiterator_free(struct dsiterator *it);
/**
* @brief Return the next data set the iterator points to.
*/
int lzds_dsiterator_get_next_dataset(struct dsiterator *it,
struct dataset **ds);
/**
* @brief Get the 'partitioned data set' status of a data set?
*/
void lzds_dataset_get_is_PDS(struct dataset *ds, int *ispds);
/**
* @brief Are all parts of a multi volume data set available?
*/
void lzds_dataset_get_is_complete(struct dataset *ds, int *iscomplete);
/**
* @brief Can the data set be opened and read with this library?
*/
void lzds_dataset_get_is_supported(struct dataset *ds, int *issupported);
/**
* @brief Get the name of a dataset as ASCII string.
*/
void lzds_dataset_get_name(struct dataset *ds, char **name);
/**
* @brief Get the format 1 DSCB for a data set. In case of a multi volume
* data set it returns the DSCB of the first volume.
*/
void lzds_dataset_get_format1_dscb(struct dataset *ds, format1_label_t **f1);
/**
* @brief Search the data set for a given member name and if a matching
* member is found return a struct pdsmember.
*/
int lzds_dataset_get_member_by_name(struct dataset *ds, char *membername,
struct pdsmember **member);
/**
* @brief Allocate an iterator that will allow to iterate through all members
* on a datasets.
*/
int lzds_dataset_alloc_memberiterator(struct dataset *ds,
struct memberiterator **it);
/**
* @brief Free memory of the given member iterator.
*/
void lzds_memberiterator_free(struct memberiterator *it);
/**
* @brief Return the next data set member the iterator points to.
*/
int lzds_memberiterator_get_next_member(struct memberiterator *it,
struct pdsmember **member);
/**
* @brief Allocate a new data set context structure for given data set.
*/
int lzds_dataset_alloc_dshandle(struct dataset *ds,
unsigned int tracks_per_frame,
struct dshandle **dsh);
/**
* @brief Free the memory of the given dshandle structure.
*/
void lzds_dshandle_free(struct dshandle *dsh);
/**
* @brief If the dsh points to a partitioned data set, this function will
* set which member of that PDS is read via the dsh.
*/
int lzds_dshandle_set_member(struct dshandle *dsh, char *membername);
/**
* @brief Read out the member pointer that has been set on this dshandle.
*/
void lzds_dshandle_get_member(struct dshandle *dsh,
struct pdsmember **member);
/**
* @brief Set the flag that causes the library to keep the record descriptor
* word (RDW) of variable records in the data stream.
*/
int lzds_dshandle_set_keepRDW(struct dshandle *dsh, int keepRDW);
/**
* @brief Read out the current setting of the RDW flag.
*/
void lzds_dshandle_get_keepRDW(struct dshandle *dsh, int *keepRDW);
/**
* @brief Prepares the dsh and the related devices for read operations.
*/
int lzds_dshandle_open(struct dshandle *dsh);
/**
* @brief Matching close operation for the data set context.
*/
void lzds_dshandle_close(struct dshandle *dsh);
/**
* @brief Read data from the data set to which the dsh points.
*/
int lzds_dshandle_read(struct dshandle *dsh, char *buf,
size_t size, ssize_t *rcsize);
/**
* @brief Move buffer position of dsh to offset.
*/
int lzds_dshandle_lseek(struct dshandle *dsh, long long offset,
long long *rcoffset);
/**
* @brief Get the current buffer position.
*/
void lzds_dshandle_get_offset(struct dshandle *dsh, long long *offset);
/**
* @brief Get the errorlog.
*/
void lzds_dshandle_get_errorlog(struct dshandle *dsh, struct errorlog **log);
/**
* @brief Set an upper limit for the seek buffer.
*/
int lzds_dshandle_set_seekbuffer(struct dshandle *dsh,
unsigned long long seek_buffer_size);
/**
* @brief Get the size of the data set in number of tracks (sum of all extents).
*/
void lzds_dataset_get_size_in_tracks(struct dataset *ds,
unsigned long long *tracks);
/**
* @brief Get the name of a partitioned dataset member.
*/
void lzds_pdsmember_get_name(struct pdsmember *member, char **name);
/**
* @brief Extract the data set information from the rawvtoc stored in the
* dasd and add it to the list of data sets stored in the zdsroot.
*/
int lzds_zdsroot_extract_datasets_from_dasd(struct zdsroot *root,
struct dasd *dasd);
/** @} */ /* end of group libzds_functions_high */
/**
* @defgroup libzds_functions_helper Helper functions
* @{
*
* @brief These functions do not fit in the hierarchy of the other
* libzds functions, but are useful helpers.
*/
/**
* @brief Translates a DS1RECFM byte to a recfm format string.
*/
void lzds_DS1RECFM_to_recfm(char DS1RECFM, char *buffer);
int lzds_analyse_open_count(struct zdsroot *root, int warn);
/** @} */ /* end of group libzds_functions_helper */
#endif /* LIB_LIBZDS_H */
+21
View File
@@ -0,0 +1,21 @@
/*
*
* Copyright IBM Corp. 2004, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*
* History of changes (starts July 2004)
* 2004-07-02 initial
*/
#ifndef LIB_U2S_H
#define LIB_U2S_H
#define U2S_BUS_ID_SIZE 32
int u2s_getbusid(char *, char *);
int u2s_read_attribute(char *, char *, char *, size_t);
int u2s_get_host_access_count(char *);
#endif /* LIB_U2S_H */
+19
View File
@@ -0,0 +1,19 @@
/*
* util - Utility function library
*
* Library helper functions
*
* Copyright IBM Corp. 2013, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef UTIL_H
#define UTIL_H
#include "util_base.h"
#include "util_list.h"
#include "util_part.h"
#endif /* UTIL_H */
+50
View File
@@ -0,0 +1,50 @@
/*
* util - Utility function library
*
* General helper functions
*
* Copyright IBM Corp. 2013, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_BASE_H
#define LIB_UTIL_BASE_H
#include <stdio.h>
#include <stdlib.h>
void util_hexdump(FILE *fh, const char *tag, const void *data, int cnt);
void util_hexdump_grp(FILE *fh, const char *tag, const void *data, int group,
int cnt, int indent);
void util_print_indented(const char *str, int indent);
#define UTIL_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#define MIN(x, y) \
({ \
__typeof__(x) _x = (x); \
__typeof__(y) _y = (y); \
\
_x < _y ? _x : _y; \
})
#define MAX(x, y) \
({ \
__typeof__(x) _x = (x); \
__typeof__(y) _y = (y); \
\
_x > _y ? _x : _y; \
})
static inline void util_ptr_vec_free(void **ptr_vec, int count)
{
int i;
for (i = 0; i < count; i++)
free(ptr_vec[i]);
free(ptr_vec);
}
#endif /* LIB_UTIL_BASE_H */
+26
View File
@@ -0,0 +1,26 @@
/**
* @defgroup util_file_h util_file: File read/write interface
* @{
* @brief Read and write files
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_FILE_H
#define LIB_UITL_FILE_H
int util_file_read_line(char *str, size_t size, const char *fmt, ...);
int util_file_read_l(long *val, int base, const char *fmt, ...);
int util_file_read_ll(long long *val, int base, const char *fmt, ...);
int util_file_read_ul(unsigned long *val, int base, const char *fmt, ...);
int util_file_read_ull(unsigned long long *val, int base, const char *fmt, ...);
int util_file_write_s(const char *str, const char *fmt, ...);
int util_file_write_l(long val, int base, const char *fmt, ...);
int util_file_write_ll(long long val, int base, const char *fmt, ...);
int util_file_write_ul(unsigned long val, int base, const char *fmt, ...);
int util_file_write_ull(unsigned long long val, int base, const char *fmt, ...);
#endif /** LIB_UTIL_FILE_H @} */
+128
View File
@@ -0,0 +1,128 @@
/**
* @defgroup util_libc_h util_libc: Libc wrapper interface
* @{
* @brief Handle standard errors for libc functions
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_LIBC_H
#define LIB_UTIL_LIBC_H
#include <stdio.h>
/**
* Allocate memory or panic in case of failure
*
* @param[in] size Number of bytes to be allocated
*
* @returns Pointer to memory buffer created with malloc()
*/
#define util_malloc(size) \
__util_malloc(__func__, __FILE__, __LINE__, size)
void *__util_malloc(const char *func, const char *file, int line, size_t size);
/**
* Allocate zero-initialized memory or panic in case of failure
*
* @param[in] size Number of bytes to be allocated
*
* @returns Pointer to memory buffer created with calloc()
*/
#define util_zalloc(size) \
__util_zalloc(__func__, __FILE__, __LINE__, size)
void *__util_zalloc(const char *func, const char *file, int line, size_t size);
/**
* Re-allocate memory or exit in case of failure
*
* @param[in] ptr Pointer ot old memory buffer
* @param[in] size Number of bytes to be allocated
*
* @returns Pointer to memory buffer created with realloc()
*/
#define util_realloc(ptr, size) \
__util_realloc(__func__, __FILE__, __LINE__, ptr, size)
void *__util_realloc(const char *func, const char *file, int line,
void *ptr, size_t size);
/**
* Duplicate a string buffer or exit in case of failure
*
* @param[in] str String to be duplicated
*
* @returns Pointer to copied string allocated with malloc()
*/
#define util_strdup(str) \
__util_strdup(__func__, __FILE__, __LINE__, str)
void *__util_strdup(const char *func, const char *file, int line,
const char *str);
/**
* Print to allocated string or exit in case of failure
*
* @param[in,out] strp Pointer for returned string allocated with malloc()
* @param[in] fmt Format string for generation of string
* @param[in] ap Parameters for format string
*
* @returns num Number of formatted characters
*/
#define util_vasprintf(strp, fmt, ap) \
__util_vasprintf(__func__, __FILE__, __LINE__, strp, fmt, ap)
#define UTIL_VASPRINTF(strp, fmt, ap) \
do { \
va_start(ap, fmt); \
util_vasprintf(strp, fmt, ap); \
va_end(ap); \
} while (0)
int __util_vasprintf(const char *func, const char *file, int line,
char **strp, const char *fmt, va_list ap);
/**
* Print to newly allocated string or exit in case of failure
*
* @param[in,out] strp Pointer for returned string allocated with malloc()
* @param[in] ... Format string and parameters for format string
*
* @returns num Number of formatted characters
*/
#define util_asprintf(strp, ...) \
__util_asprintf(__func__, __FILE__, __LINE__, strp, ##__VA_ARGS__)
int __util_asprintf(const char *func, const char *file, int line,
char **strp, const char *fmt, ...);
/**
* Print to string buffer or exit in case of failure
*
* @param[in] str String buffer
* @param[in] fmt Format string for generation of string
* @param[in] ap Parameters for format string
*
* @returns num Number of formatted characters
*/
#define util_vsprintf(str, fmt, ap) \
__util_vsprintf(__func__, __FILE__, __LINE__, str, fmt, ap)
#define UTIL_VSPRINTF(str, fmt, ap) \
do { \
va_start(ap, fmt); \
util_vsprintf(str, fmt, ap); \
va_end(ap); \
} while (0)
int __util_vsprintf(const char *func, const char *file, int line,
char *str, const char *fmt, va_list ap);
char *util_strcat_realloc(char *str1, const char *str2);
void util_str_toupper(char *str);
#endif /** LIB_UTIL_LIBC_H @} */
+65
View File
@@ -0,0 +1,65 @@
/*
* util - Utility function library
*
* Linked lists
*
* Copyright IBM Corp. 2013, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_LIST_H
#define LIB_UTIL_LIST_H
#include <stddef.h>
struct util_list {
unsigned long offset; /* Offset of struct util_list_node */
struct util_list_node *start; /* First element */
struct util_list_node *end; /* Last element */
};
struct util_list_node {
struct util_list_node *next;
struct util_list_node *prev;
};
#define util_list_new(type, member) util_list_new_offset(offsetof(type, member))
#define util_list_init(list, type, member) \
util_list_init_offset(list, offsetof(type, member))
void util_list_free(struct util_list *list);
struct util_list *util_list_new_offset(unsigned long offset);
void util_list_init_offset(struct util_list *list, unsigned long offset);
void util_list_add_tail(struct util_list *list, void *entry);
void util_list_add_head(struct util_list *list, void *entry);
void util_list_add_next(struct util_list *list, void *entry, void *list_entry);
void util_list_add_prev(struct util_list *list, void *entry, void *list_entry);
void util_list_remove(struct util_list *list, void *entry);
void *util_list_next(struct util_list *list, void *entry);
void *util_list_prev(struct util_list *list, void *entry);
void *util_list_start(struct util_list *list);
void *util_list_end(struct util_list *list);
int util_list_is_empty(struct util_list *list);
unsigned long util_list_len(struct util_list *list);
/*
* The compare function should return the following:
* a < b --> < 0
* a > b --> > 0
* a = b --> = 0
*/
typedef int (*util_list_cmp_fn)(void *a, void *b, void *data);
void util_list_sort(struct util_list *list, util_list_cmp_fn fn, void *data);
#define util_list_iterate(list, i) \
for (i = util_list_start(list); \
i != NULL; \
i = util_list_next(list, i)) \
#define util_list_iterate_safe(list, i, n) \
for (i = util_list_start(list), n = util_list_next(list, i); \
i != NULL; \
i = n, n = util_list_next(list, i)) \
#endif /* LIB_UTIL_LIST_H */
+88
View File
@@ -0,0 +1,88 @@
/**
* @defgroup util_opt_h util_opt: Command line options interface
* @{
* @brief Parse the command line options
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_OPT_H
#define LIB_UTIL_OPT_H
#include <getopt.h>
#include <unistd.h>
/* Flag indicating that an option does not have a short form */
#define UTIL_OPT_FLAG_NOSHORT 1
/* Flag indicating that an option does not have a long form */
#define UTIL_OPT_FLAG_NOLONG 2
/* Flag indicating that this is a section heading */
#define UTIL_OPT_FLAG_SECTION 4
/**
* Command line option
*/
struct util_opt {
/** Defined by getopt.h, see "man getopt_long" */
struct option option;
/** For options with arguments: Argument name */
char *argument;
/** Description displayed for --help */
char *desc;
/** Flags for this option */
int flags;
/** Command to which this option belongs. NULL means all commands */
char *command;
};
/**
* Standard option: --help
*/
#define UTIL_OPT_HELP \
{ \
.option = { "help", 0, NULL, 'h' }, \
.desc = "Print this help, then exit", \
}
/**
* Standard option: --version
*/
#define UTIL_OPT_VERSION \
{ \
.option = { "version", 0, NULL, 'v' }, \
.desc = "Print version information, then exit", \
}
/**
* End-marker for the option pointer vector
*/
#define UTIL_OPT_END \
{ \
.option = { NULL, 0, NULL, 0 }, \
}
/**
* Section header
*/
#define UTIL_OPT_SECTION(title) \
{ \
.desc = (title), \
.flags = UTIL_OPT_FLAG_SECTION, \
}
/*
* Option functions
*/
void util_opt_init(struct util_opt *opt_vec, const char *opt_prefix);
void util_opt_set_command(const char *command);
int util_opt_getopt_long(int argc, char *argv[]);
void util_opt_print_help(void);
void util_opt_print_indented(const char *opt, const char *desc);
void util_opt_print_parse_error(char opt, char *argv[]);
#endif /** LIB_UTIL_OPT_H @} */
+44
View File
@@ -0,0 +1,44 @@
/**
* @defgroup util_panic_h util_panic: Panic interface
* @{
* @brief Collect FFDC data for unexpected errors
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_PANIC_H
#define LIB_UTIL_PANIC_H
#include "zt_common.h"
/**
* Write message, print backtrace and then call the abort() function
*
* @param[in] ... Format string and parameters describing the panic reason
*/
#define util_panic(...) \
__util_panic(__func__, __FILE__, __LINE__, ##__VA_ARGS__)
void __noreturn __util_panic(const char *func, const char *file, int line,
const char *fmt, ...);
/**
* Ensure that assumption is not true, otherwise panic
*
* Example: util_assert(ptr == NULL, "The ptr must be NULL, but is %p", ptr)
*
* @param[in] assumption This assumption has to be true
* @param[in] ... Format string and parameters describing the assumption
*/
#define util_assert(assumption, ...) \
__util_assert(#assumption, __func__, __FILE__, __LINE__, \
assumption, ##__VA_ARGS__)
void __util_assert(const char *assertion_string,
const char *func, const char *file, int line,
int assumption, const char *fmt, ...);
#endif /** LIB_UTIL_PANIC_H @} */
+20
View File
@@ -0,0 +1,20 @@
/*
* util - Utility function library
*
* Partition detection functions
*
* Copyright IBM Corp. 2013, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_PART_H
#define LIB_UTIL_PART_H
int util_part_search(const char *dev, size_t blk_start, size_t blk_cnt,
size_t blk_size, int *ext_part);
int util_part_search_fh(int fh, size_t blk_start, size_t blk_cnt,
size_t blk_size, int *ext_part);
#endif /* LIB_UTIL_PART_H */
+24
View File
@@ -0,0 +1,24 @@
/**
* @defgroup util_path_h util_path: Path interface
* @{
* @brief Work with paths
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_PATH_H
#define LIB_UTIL_PATH_H
#include <stdbool.h>
char *util_path_sysfs(const char *fmt, ...);
bool util_path_is_readable(const char *fmt, ...);
bool util_path_is_writable(const char *fmt, ...);
bool util_path_is_dir(const char *fmt, ...);
bool util_path_is_reg_file(const char *fmt, ...);
#endif /** LIB_UTIL_PATH_H @} */
+64
View File
@@ -0,0 +1,64 @@
/**
* @defgroup util_prg_h util_prg: Program interface
* @{
* @brief Print standard program messages
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_PRG_H
#define LIB_UTIL_PRG_H
#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
struct util_prg_copyright {
/** Name of the copyright owner, e.g. IBM */
const char *owner;
/** Year of first publishing */
int pub_first;
/** Year of last major changes */
int pub_last;
};
/**
* @brief Coypright end marker
*/
#define UTIL_PRG_COPYRIGHT_END {NULL, 0, 0}
/**
* Program description
*/
struct util_prg {
/** Description for help */
const char *desc;
/** Command arguments in front of other options */
const char *command_args;
/** Positional arguments */
const char *args;
/** Copyright list */
struct util_prg_copyright copyright_vec[];
};
void util_prg_init(const struct util_prg *prg);
void util_prg_set_command(const char *command);
void util_prg_print_parse_error(void);
void util_prg_print_required_arg(const char *option);
void util_prg_print_invalid_option(const char *option);
void util_prg_print_arg_error(const char *arg_name);
void util_prg_print_version(void);
void util_prg_print_help(void);
#endif /** LIB_UTIL_PRG_H @} */
+51
View File
@@ -0,0 +1,51 @@
/*
* Scanner for the /proc files
*
* Copyright IBM Corp. 2001, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*
*/
#ifndef LIB_UTIL_PROC_H
#define LIB_UTIL_PROC_H
#include <ctype.h>
#include <sys/types.h>
struct util_proc_part_entry {
dev_t device;
size_t blockcount;
char *name;
};
struct util_proc_dev_entry {
int blockdev;
dev_t device;
char *name;
};
/**
* Container for the fields of the output of /proc/mounts (man fstab)
*/
struct util_proc_mnt_entry {
char *spec;
char *file;
char *vfstype;
char *mntOpts;
char *dump;
char *passno;
};
int util_proc_part_get_entry(dev_t device, struct util_proc_part_entry *entry);
void util_proc_part_free_entry(struct util_proc_part_entry *entry);
int util_proc_dev_get_entry(dev_t dev, int blockdev,
struct util_proc_dev_entry *entry);
void util_proc_dev_free_entry(struct util_proc_dev_entry *entry);
int util_proc_mnt_get_entry(const char *file_name, const char *spec,
struct util_proc_mnt_entry *entry);
void util_proc_mnt_free_entry(struct util_proc_mnt_entry *entry);
#endif /* LIB_UTIL_PROC_H */
+72
View File
@@ -0,0 +1,72 @@
/**
* @defgroup util_rec_h util_rec: Record interface
* @{
* @brief Print records in different output formats
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_REC_H
#define LIB_UTIL_REC_H
#include "lib/util_list.h"
#define PAGE_SIZE 4096
/**
* Opaque handle for a record
*
* The util_rec structure describes:
*
* - A set of fields
* - An output format with the required formatting attributes (e.g. character
* for header separator)
*/
struct util_rec;
/**
* Opaque handle for a record field (used for util_rec_iterate)
*
* The util_rec_fld structure describes:
*
* - Field value
* - Field key name
* - A set of attributes (e.g. width, alignment etc.)
*/
struct util_rec_fld;
/**
* Alignment in util_rec tables
*/
enum util_rec_align {
/** Align field left */
UTIL_REC_ALIGN_LEFT,
/** Align field right */
UTIL_REC_ALIGN_RIGHT,
};
struct util_list *__util_rec_get_list(struct util_rec *rec);
const char *util_rec_fld_get_key(struct util_rec_fld *fld);
#define util_rec_iterate(rec, fld) \
util_list_iterate(__util_rec_get_list(rec), fld)
struct util_rec *util_rec_new_wide(const char *hdr_sep);
struct util_rec *util_rec_new_csv(const char *col_sep);
struct util_rec *util_rec_new_long(const char *hdr_sep, const char *col_sep,
const char *key, int key_size, int val_size);
void util_rec_free(struct util_rec *rec);
void util_rec_def(struct util_rec *rec, const char *key,
enum util_rec_align align, int width, const char *hdr);
void util_rec_set(struct util_rec *rec, const char *key, const char *fmt, ...);
void util_rec_set_argz(struct util_rec *rec, const char *key, const char *argz,
size_t len);
const char *util_rec_get(struct util_rec *rec, const char *key);
void util_rec_print_hdr(struct util_rec *rec);
void util_rec_print(struct util_rec *rec);
#endif /** LIB_UTIL_REC_H @} */
+25
View File
@@ -0,0 +1,25 @@
/**
* @defgroup util_scandir_h util_scandir: Scandir interface
* @{
* @brief Scan a directory for matching entries
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_UTIL_SCANDIR_H
#define LIB_UTIL_SCANDIR_H
#include <dirent.h>
int util_scandir_hexsort(const struct dirent **de1, const struct dirent **de2);
int util_scandir(struct dirent ***namelist,
int compar_fn(const struct dirent **,
const struct dirent **),
const char *path,
const char *pattern, ...);
void util_scandir_free(struct dirent **de_vec, int count);
#endif /** LIB_UTIL_SCANDIR_H @} */
+16
View File
@@ -0,0 +1,16 @@
/*
* vmdump - VMDUMP conversion library
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_VMDUMP_H
#define LIB_VMDUMP_H
int vmdump_convert(const char* inputFileName, const char* outputFileName,
const char* progName);
#endif /* LIB_VMDUMP_H */
+420
View File
@@ -0,0 +1,420 @@
/*
* Copyright IBM Corp. 2002, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_VTOC_H
#define LIB_VTOC_H
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#define LINE_LENGTH 80
#define VTOC_START_CC 0x0
#define VTOC_START_HH 0x1
#define FIRST_USABLE_CYL 1
#define FIRST_USABLE_TRK 2
#define DASD_3380_TYPE 13184
#define DASD_3390_TYPE 13200
#define DASD_9345_TYPE 37701
#define DASD_3380_VALUE 0xbb60
#define DASD_3390_VALUE 0xe5a2
#define DASD_9345_VALUE 0xbc98
#define VOLSER_LENGTH 6
#define BIG_DISK_SIZE 0x10000
#define LV_COMPAT_CYL 0xFFFE
#define VTOC_ERROR "VTOC error:"
/* definition from hdreq.h */
struct hd_geometry {
unsigned char heads;
unsigned char sectors;
unsigned short cylinders;
unsigned long start;
};
typedef struct ttr
{
u_int16_t tt;
u_int8_t r;
} __attribute__ ((packed)) ttr_t;
typedef struct cchhb
{
u_int16_t cc;
u_int16_t hh;
u_int8_t b;
} __attribute__ ((packed)) cchhb_t;
typedef struct cchh
{
u_int16_t cc;
u_int16_t hh;
} __attribute__ ((packed)) cchh_t;
typedef struct labeldate
{
u_int8_t year;
u_int16_t day;
} __attribute__ ((packed)) labeldate_t;
/*
* The following structure is a merger of the cdl and ldl volume label.
* On an ldl disk there is no key information, so when reading an
* ldl label from disk, the data should be copied at the address of vollbl.
* On the other side, the field ldl_version is reserved in a cdl record
* and the field formatted_cyl exists only for ldl labels. So when
* reading a cdl label from disk, the formatted_cyl field will contain
* arbitrary data.
* This layout may be a bit awkward, but the advantage of having the
* same label type for both disk layout types is bigger than the effort
* for taking a bit of extra care at the fringes.
*/
typedef struct volume_label
{
char volkey[4]; /* volume key = volume label */
char vollbl[4]; /* volume label */
char volid[6]; /* volume identifier */
u_int8_t security; /* security byte */
cchhb_t vtoc; /* VTOC address */
char res1[5]; /* reserved */
char cisize[4]; /* CI-size for FBA,... */
/* ...blanks for CKD */
char blkperci[4]; /* no of blocks per CI (FBA), blanks for CKD */
char labperci[4]; /* no of labels per CI (FBA), blanks for CKD */
char res2[4]; /* reserved */
char lvtoc[14]; /* owner code for LVTOC */
char res3[28]; /* reserved */
char ldl_version; /* version number, valid for ldl format */
unsigned long long formatted_blocks; /* valid when ldl_version >= f2 */
} __attribute__ ((packed)) volume_label_t;
typedef struct extent
{
u_int8_t typeind; /* extent type indicator */
u_int8_t seqno; /* extent sequence number */
cchh_t llimit; /* starting point of this extent */
cchh_t ulimit; /* ending point of this extent */
} __attribute__ ((packed)) extent_t;
typedef struct dev_const
{
u_int16_t DS4DSCYL; /* number of logical cyls */
u_int16_t DS4DSTRK; /* number of tracks in a logical cylinder */
u_int16_t DS4DEVTK; /* device track length */
u_int8_t DS4DEVI; /* non-last keyed record overhead */
u_int8_t DS4DEVL; /* last keyed record overhead */
u_int8_t DS4DEVK; /* non-keyed record overhead differential */
u_int8_t DS4DEVFG; /* flag byte */
u_int16_t DS4DEVTL; /* device tolerance */
u_int8_t DS4DEVDT; /* number of DSCB's per track */
u_int8_t DS4DEVDB; /* number of directory blocks per track */
} __attribute__ ((packed)) dev_const_t;
/*
* format 1 and format 8 label have the same layout so we use the following
* structure for both.
*/
typedef struct format1_label
{
char DS1DSNAM[44]; /* data set name */
u_int8_t DS1FMTID; /* format identifier */
unsigned char DS1DSSN[6];/* data set serial number */
u_int16_t DS1VOLSQ; /* volume sequence number */
labeldate_t DS1CREDT; /* creation date: ydd */
labeldate_t DS1EXPDT; /* expiration date */
u_int8_t DS1NOEPV; /* number of extents on volume */
u_int8_t DS1NOBDB; /* no. of bytes used in last direction blk */
u_int8_t DS1FLAG1; /* flag 1 */
unsigned char DS1SYSCD[13]; /* system code */
labeldate_t DS1REFD; /* date last referenced */
u_int8_t DS1SMSFG; /* system managed storage indicators */
u_int8_t DS1SCXTF; /* sec. space extension flag byte */
u_int16_t DS1SCXTV; /* secondary space extension value */
u_int8_t DS1DSRG1; /* data set organisation byte 1 */
u_int8_t DS1DSRG2; /* data set organisation byte 2 */
u_int8_t DS1RECFM; /* record format */
u_int8_t DS1OPTCD; /* option code */
u_int16_t DS1BLKL; /* block length */
u_int16_t DS1LRECL; /* record length */
u_int8_t DS1KEYL; /* key length */
u_int16_t DS1RKP; /* relative key position */
u_int8_t DS1DSIND; /* data set indicators */
u_int8_t DS1SCAL1; /* secondary allocation flag byte */
char DS1SCAL3[3]; /* secondary allocation quantity */
ttr_t DS1LSTAR; /* last used track and block on track */
u_int16_t DS1TRBAL; /* space remaining on last used track */
u_int16_t res1; /* reserved */
extent_t DS1EXT1; /* first extent description */
extent_t DS1EXT2; /* second extent description */
extent_t DS1EXT3; /* third extent description */
cchhb_t DS1PTRDS; /* possible pointer to f2 or f3 DSCB */
} __attribute__ ((packed)) format1_label_t;
typedef struct format3_label
{
char DS3KEYID[4]; /* key identifier */
extent_t DS3EXTNT[4]; /* first 4 extent descriptions */
u_int8_t DS3FMTID; /* format identifier */
extent_t DS3ADEXT[9]; /* last 9 extent description */
cchhb_t DS3PTRDS; /* pointer to next format3 DSCB */
} __attribute__ ((packed)) format3_label_t;
typedef struct format4_label
{
char DS4KEYCD[44]; /* key code for VTOC labels: 44 times 0x04 */
u_int8_t DS4IDFMT; /* format identifier */
cchhb_t DS4HPCHR; /* highest address of a format 1 DSCB */
u_int16_t DS4DSREC; /* number of available DSCB's */
cchh_t DS4HCCHH; /* CCHH of next available alternate track */
u_int16_t DS4NOATK; /* number of remaining alternate tracks */
u_int8_t DS4VTOCI; /* VTOC indicators */
u_int8_t DS4NOEXT; /* number of extents in VTOC */
u_int8_t DS4SMSFG; /* system managed storage indicators */
u_int8_t DS4DEVAC; /* number of alternate cylinders.
Subtract from first two bytes of
DS4DEVSZ to get number of usable
cylinders. can be zero. valid
only if DS4DEVAV on. */
dev_const_t DS4DEVCT; /* device constants */
char DS4AMTIM[8]; /* VSAM time stamp */
char DS4AMCAT[3]; /* VSAM catalog indicator */
char DS4R2TIM[8]; /* VSAM volume/catalog match time stamp */
char res1[5]; /* reserved */
char DS4F6PTR[5]; /* pointer to first format 6 DSCB */
extent_t DS4VTOCE; /* VTOC extent description */
char res2[10]; /* reserved */
u_int8_t DS4EFLVL; /* extended free-space management level */
cchhb_t DS4EFPTR; /* pointer to extended free-space info */
char res3; /* reserved */
u_int32_t DS4DCYL; /* number of logical cyls */
char res4[2]; /* reserved */
u_int8_t DS4DEVF2; /* device flags */
char res5; /* reserved */
} __attribute__ ((packed)) format4_label_t;
typedef struct ds5ext
{
u_int16_t t; /* RTA of the first track of free extent */
u_int16_t fc; /* number of whole cylinders in free ext. */
u_int8_t ft; /* number of remaining free tracks */
} __attribute__ ((packed)) ds5ext_t;
typedef struct format5_label
{
char DS5KEYID[4]; /* key identifier */
ds5ext_t DS5AVEXT; /* first available (free-space) extent. */
ds5ext_t DS5EXTAV[7]; /* seven available extents */
u_int8_t DS5FMTID; /* format identifier */
ds5ext_t DS5MAVET[18]; /* eighteen available extents */
cchhb_t DS5PTRDS; /* pointer to next format5 DSCB */
} __attribute__ ((packed)) format5_label_t;
typedef struct ds7ext
{
u_int32_t a; /* starting RTA value */
u_int32_t b; /* ending RTA value + 1 */
} __attribute__ ((packed)) ds7ext_t;
typedef struct format7_label
{
char DS7KEYID[4]; /* key identifier */
ds7ext_t DS7EXTNT[5]; /* space for 5 extent descriptions */
u_int8_t DS7FMTID; /* format identifier */
ds7ext_t DS7ADEXT[11]; /* space for 11 extent descriptions */
char res1[2]; /* reserved */
cchhb_t DS7PTRDS; /* pointer to next FMT7 DSCB */
} __attribute__ ((packed)) format7_label_t;
typedef struct format9_label
{
u_int8_t DS9KEYID; /* key code for format 9 labels (0x09) */
u_int8_t DS9SUBTY; /* subtype (0x01) */
u_int8_t DS9NUMF9; /* number of F9 datasets */
u_int8_t res1[41]; /* reserved */
u_int8_t DS9FMTID; /* format identifier */
u_int8_t res2[90]; /* reserved */
cchhb_t DS9PTRDS; /* pointer to next DSCB */
} __attribute__ ((packed)) format9_label_t;
char * vtoc_ebcdic_enc (char *source, char *target, int l);
char * vtoc_ebcdic_dec (char *source, char *target, int l);
void vtoc_set_extent (
extent_t * ext,
u_int8_t typeind,
u_int8_t seqno,
cchh_t * lower,
cchh_t * upper);
void vtoc_set_cchh (
cchh_t * addr,
u_int32_t cc,
u_int16_t hh);
u_int32_t vtoc_get_cyl_from_cchh(cchh_t *addr);
u_int16_t vtoc_get_head_from_cchh(cchh_t *addr);
void vtoc_set_cchhb (
cchhb_t * addr,
u_int32_t cc,
u_int16_t hh,
u_int8_t b);
u_int32_t vtoc_get_cyl_from_cchhb(cchhb_t *addr);
u_int16_t vtoc_get_head_from_cchhb(cchhb_t *addr);
u_int64_t cchhb2blk(cchhb_t *p, struct hd_geometry *geo);
u_int64_t cchh2blk (cchh_t *p, struct hd_geometry *geo);
u_int32_t cchh2trk (cchh_t *p, struct hd_geometry *geo);
void vtoc_set_date (
labeldate_t * d,
u_int8_t year,
u_int16_t day);
void vtoc_volume_label_init (
volume_label_t *vlabel);
int vtoc_read_volume_label (
char * device,
unsigned long vlabel_start,
volume_label_t * vlabel);
int vtoc_write_volume_label (
char *device,
unsigned long vlabel_start,
volume_label_t *vlabel);
void vtoc_volume_label_set_volser (
volume_label_t *vlabel,
char *volser);
char *vtoc_volume_label_get_volser (
volume_label_t *vlabel,
char *volser);
void vtoc_volume_label_set_key (
volume_label_t *vlabel,
char *key);
void vtoc_volume_label_set_label (
volume_label_t *vlabel,
char *lbl);
char *vtoc_volume_label_get_label (
volume_label_t *vlabel,
char *lbl);
void vtoc_read_label (
char *device,
unsigned long position,
format1_label_t *f1,
format4_label_t *f4,
format5_label_t *f5,
format7_label_t *f7);
void vtoc_write_label (
char *device,
unsigned long position,
format1_label_t *f1,
format4_label_t *f4,
format5_label_t *f5,
format7_label_t *f7,
format9_label_t *f9);
void vtoc_init_format1_label (
unsigned int blksize,
extent_t *part_extent,
format1_label_t *f1);
void vtoc_init_format4_label (
format4_label_t *f4lbl,
unsigned int compat_cylinders,
unsigned int real_cylinders,
unsigned int tracks,
unsigned int blocks,
unsigned int blksize,
u_int16_t dev_type);
void vtoc_update_format4_label (
format4_label_t *f4,
cchhb_t *highest_f1,
u_int16_t unused_update);
void vtoc_init_format5_label (
format5_label_t *f5);
void vtoc_update_format5_label_add (
format5_label_t *f5,
int verbose,
int trk,
u_int16_t a,
u_int16_t b,
u_int8_t c);
void vtoc_update_format5_label_del (
format5_label_t *f5,
int verbose,
int trk,
u_int16_t a,
u_int16_t b,
u_int8_t c);
void vtoc_init_format7_label (
format7_label_t *f7);
void vtoc_update_format7_label_add (
format7_label_t *f7,
int verbose,
u_int32_t a,
u_int32_t b);
void vtoc_update_format7_label_del (
format7_label_t *f7,
int verbose,
u_int32_t a,
u_int32_t b);
void vtoc_init_format8_label (
unsigned int blksize,
extent_t *part_extent,
format1_label_t *f1);
void vtoc_update_format8_label (
cchhb_t *associated_f9,
format1_label_t *f8);
void vtoc_init_format9_label (
format9_label_t *f9);
void vtoc_set_freespace(
format4_label_t *f4,
format5_label_t *f5,
format7_label_t *f7,
char ch,
int verbose,
u_int32_t start,
u_int32_t stop,
u_int32_t cyl,
u_int32_t trk);
#endif /* LIB_VTOC_H */
+43
View File
@@ -0,0 +1,43 @@
/*
* s390-tools/include/zt_common.h
* common s390-tools definitions.
*
* Copyright IBM Corp. 2004, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*
*/
#ifndef LIB_ZT_COMMON_H
#define LIB_ZT_COMMON_H
#define STRINGIFY_1(x) #x
#define STRINGIFY(x) STRINGIFY_1(x)
#ifdef UNUSED
#elif defined(__GNUC__)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#else
# define UNUSED(x) x
#endif
#define RELEASE_STRING STRINGIFY (S390_TOOLS_RELEASE)
#define TOOLS_LIBDIR STRINGIFY (S390_TOOLS_LIBDIR)
#define TOOLS_SYSCONFDIR STRINGIFY (S390_TOOLS_SYSCONFDIR)
#define __noreturn __attribute__((noreturn))
#define __packed __attribute__((packed))
#define __aligned(x) __attribute__((aligned(x)))
#define __may_alias __attribute__((may_alias))
typedef unsigned long long u64;
typedef signed long long s64;
typedef unsigned int u32;
typedef signed int s32;
typedef unsigned short int u16;
typedef signed short int s16;
typedef unsigned char u8;
typedef signed char s8;
#endif /* LIB_ZT_COMMON_H */