ziomon/ziorep_cfgreader: extract PCHID from .config file

Add an ability for ziorep_config tool to extract PCHID additional adapter
parameter from .config file. With this patch device_info structure will have
pchid field, which can be used by different printers classes. Also add
function for querying PCHID by using of devno for providing reports. Translate
"n/a" field from .config file record into invalid PCHID number.

Signed-off-by: Fedor Loshakov <loshakov@linux.ibm.com>
Reviewed-by: Sakshi Singh <005c7w@linux.ibm.com>
Reviewed-by: M Nikhil <nikh1092@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Fedor Loshakov
2024-12-09 14:50:35 +01:00
committed by Jan Höppner
parent 798bd752cf
commit f340a96fdf
4 changed files with 63 additions and 9 deletions

View File

@@ -3,7 +3,7 @@
*
* Utility functions
*
* Copyright IBM Corp. 2008, 2017
* Copyright IBM Corp. 2008, 2024
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@@ -552,6 +552,36 @@ FILE* open_csv_output_file(const char *filename, const char *extension,
return fp;
}
/**
* parse_pchid_str - parse PCHID from string to 32-bit number
* @pchid_str: PCHID string
* @pchid: 32-bit PCHID number
*
* Reads PCHID string, checks for corner cases, converts to 32-bit
* PCHID number, checks for errors, writes resulted PCHID to specified
* location.
*/
int parse_pchid_str(const char *const pchid_str, __u32 *const pchid)
{
unsigned long parsed;
char *end;
if (strcmp(pchid_str, "n/a") == 0) {
parsed = ZIOREP_PCHID_NA;
goto out;
}
parsed = strtoul(pchid_str, &end, 16);
if (parsed > 0xffff) {
fprintf(stderr, "%s: PCHID %s exceeds maximum possible value for a PCHID.\n",
toolname, pchid_str);
return -1;
} else if (parsed == 0 && end == &pchid_str[0]) {
fprintf(stderr, "%s: PCHID %s could not be converted.\n", toolname, pchid_str);
return -1;
}
out:
*pchid = (__u32)parsed;
return 0;
}