From 80b126032c7e73d273bc883e973b5f1a94aac581 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 5 Aug 2024 10:38:39 +0200 Subject: Merging upstream version 2.10. Signed-off-by: Daniel Baumann --- plugins/sed/sedopal_cmd.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'plugins/sed/sedopal_cmd.c') diff --git a/plugins/sed/sedopal_cmd.c b/plugins/sed/sedopal_cmd.c index 21ebd36..d9a789c 100644 --- a/plugins/sed/sedopal_cmd.c +++ b/plugins/sed/sedopal_cmd.c @@ -251,8 +251,21 @@ int sedopal_cmd_lock(int fd) */ int sedopal_cmd_unlock(int fd) { + int rc; + + rc = sedopal_lock_unlock(fd, OPAL_RW); - return sedopal_lock_unlock(fd, OPAL_RW); + /* + * If the unlock was successful, force a re-read of the + * partition table. Return rc of unlock operation. + */ + if (rc == 0) { + if (ioctl(fd, BLKRRPART, 0) != 0) + fprintf(stderr, + "Warning: failed re-reading partition\n"); + } + + return rc; } /* @@ -275,18 +288,6 @@ int sedopal_lock_unlock(int fd, int lock_state) if (rc != 0) fprintf(stderr, "Error: failed locking or unlocking - %d\n", rc); - - /* - * If the unlock was successful, force a re-read of the - * partition table. - */ - if (rc == 0) { - rc = ioctl(fd, BLKRRPART, 0); - if (rc != 0) - fprintf(stderr, - "Error: failed re-reading partition\n"); - } - return rc; } @@ -397,6 +398,14 @@ int sedopal_cmd_revert(int fd) revert_lsp.__pad = 0; rc = ioctl(fd, IOC_OPAL_REVERT_LSP, &revert_lsp); + if (rc == 0) { + /* + * TPER must also be reverted. + */ + rc = ioctl(fd, IOC_OPAL_REVERT_TPR, &revert_lsp.key); + if (rc != 0) + fprintf(stderr, "Error: revert TPR - %d\n", rc); + } #else rc = -EOPNOTSUPP; #endif @@ -465,7 +474,7 @@ void sedopal_print_locking_features(uint8_t features) int sedopal_cmd_discover(int fd) { #ifdef IOC_OPAL_DISCOVERY - int rc; + int rc, feat_length; bool sedopal_locking_supported = false; struct opal_discovery discover; struct level_0_discovery_header *dh; @@ -500,6 +509,7 @@ int sedopal_cmd_discover(int fd) */ while (feat < feat_end) { code = be16toh(feat->code); + feat_length = feat->length + 4 /* hdr */; switch (code) { case OPAL_FEATURE_CODE_LOCKING: locking_flags = feat->feature; @@ -511,7 +521,7 @@ int sedopal_cmd_discover(int fd) break; } - feat++; + feat = (struct level_0_discovery_features *)((char *)feat + feat_length); } rc = 0; -- cgit v1.2.3