From e09c675b7094d1605d32ed0cfb49f18e25c05cc8 Mon Sep 17 00:00:00 2001 From: Eduard Shishkin Date: Tue, 22 Nov 2022 12:46:25 +0100 Subject: [PATCH] libvtoc: Introduce is_vol1() check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce is_vol1() in vtoc.h and update the user in libzds.c Signed-off-by: Eduard Shishkin Reviewed-by: Jan Hoeppner Signed-off-by: Jan Höppner --- include/lib/vtoc.h | 7 +++++++ libzds/libzds.c | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/lib/vtoc.h b/include/lib/vtoc.h index fdc3bf78..6c1b24ac 100644 --- a/include/lib/vtoc.h +++ b/include/lib/vtoc.h @@ -97,6 +97,13 @@ typedef struct volume_label unsigned long long formatted_blocks; /* valid when ldl_version >= f2 */ } __attribute__ ((packed)) volume_label_t; +static inline int is_vol1(char *this) +{ + char vol1[] = {0xe5, 0xd6, 0xd3, 0xf1, 0x00} /* "VOL1" in EBCDIC */; + + return !strncmp(this, vol1, 4); +} + typedef struct extent { u_int8_t typeind; /* extent type indicator */ diff --git a/libzds/libzds.c b/libzds/libzds.c index dbf810d1..a0399b12 100644 --- a/libzds/libzds.c +++ b/libzds/libzds.c @@ -1419,7 +1419,6 @@ int lzds_dasd_read_rawvtoc(struct dasd *dasd, struct raw_vtoc *rawvtoc) volume_label_t *vlabel = NULL; char *trackdata = NULL; - char vol1[] = {0xe5, 0xd6, 0xd3, 0xf1, 0x00}; /* "VOL1" in EBCDIC */ errorlog_clear(dasd->log); @@ -1431,8 +1430,7 @@ int lzds_dasd_read_rawvtoc(struct dasd *dasd, struct raw_vtoc *rawvtoc) goto cleanup; } /* verify that we have a proper VOL1 label */ - if (strncmp(vlabel->volkey, vol1, 4) || - strncmp(vlabel->vollbl, vol1, 4)) { + if (!is_vol1(vlabel->volkey) || !is_vol1(vlabel->vollbl)) { rc = EINVAL; errorlog_add_message( &dasd->log, NULL, rc,