Skip to content

Commit 4a66443

Browse files
gjoyce-ibmigaw
authored andcommitted
sed: better error messages for revert and password
Use context to print better error messages for common revert and password errors. Signed-off-by: Greg Joyce <[email protected]>
1 parent cc93333 commit 4a66443

2 files changed

Lines changed: 35 additions & 10 deletions

File tree

plugins/sed/sed.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static int sed_opal_revert(int argc, char **argv, struct command *cmd,
130130
return err;
131131

132132
err = sedopal_cmd_revert(dev->direct.fd);
133-
if ((err != 0) && (err != -EOPNOTSUPP))
133+
if ((err != 0) && (err != -EOPNOTSUPP) && (err != EPERM))
134134
fprintf(stderr, "revert: SED error - %s\n",
135135
sedopal_error_to_text(err));
136136

@@ -190,7 +190,7 @@ static int sed_opal_password(int argc, char **argv, struct command *cmd,
190190
return err;
191191

192192
err = sedopal_cmd_password(dev->direct.fd);
193-
if (err != 0)
193+
if ((err != 0) && (err != EPERM))
194194
fprintf(stderr, "password: SED error - %s\n",
195195
sedopal_error_to_text(err));
196196

plugins/sed/sedopal_cmd.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,15 @@ char *sedopal_get_password(char *prompt)
127127
return NULL;
128128

129129
len = strlen(pass);
130-
if (len < SEDOPAL_MIN_PASSWORD_LEN)
130+
if (len < SEDOPAL_MIN_PASSWORD_LEN) {
131+
fprintf(stderr, "Error: password is not long enough\n");
131132
return NULL;
133+
}
132134

133-
if (len > SEDOPAL_MAX_PASSWORD_LEN)
135+
if (len > SEDOPAL_MAX_PASSWORD_LEN) {
136+
fprintf(stderr, "Error: password is too long\n");
134137
return NULL;
138+
}
135139

136140
return pass;
137141
}
@@ -425,8 +429,12 @@ static int sedopal_revert_psid(int fd)
425429
rc = sedopal_set_key(&key);
426430
if (rc == 0) {
427431
rc = ioctl(fd, IOC_OPAL_PSID_REVERT_TPR, &key);
428-
if (rc != 0)
429-
fprintf(stderr, "PSID_REVERT_TPR rc %d\n", rc);
432+
if (rc != 0) {
433+
if (rc == EPERM)
434+
fprintf(stderr, "Error: incorrect password\n");
435+
else
436+
fprintf(stderr, "PSID_REVERT_TPR rc %d\n", rc);
437+
}
430438
}
431439

432440
return rc;
@@ -457,6 +465,7 @@ int sedopal_cmd_revert(int fd)
457465
#ifdef IOC_OPAL_REVERT_LSP
458466
struct opal_revert_lsp revert_lsp;
459467
uint8_t locking_state;
468+
char *revert = "LSP";
460469

461470
locking_state = sedopal_locking_state(fd);
462471

@@ -481,19 +490,28 @@ int sedopal_cmd_revert(int fd)
481490

482491
rc = ioctl(fd, IOC_OPAL_REVERT_LSP, &revert_lsp);
483492
if (rc == 0) {
493+
revert = "TPER";
484494
/*
485495
* TPER must also be reverted.
486496
*/
487497
rc = ioctl(fd, IOC_OPAL_REVERT_TPR, &revert_lsp.key);
488498
if (rc != 0)
489499
fprintf(stderr, "Error: revert TPR - %d\n", rc);
490500
}
501+
502+
if (rc != 0) {
503+
if (rc == EPERM)
504+
fprintf(stderr, "Error: incorrect password\n");
505+
else
506+
fprintf(stderr, "Error: revert %s - %d\n",
507+
revert, rc);
508+
}
491509
#else
492510
rc = -EOPNOTSUPP;
493511
#endif
494512
}
495513

496-
if (rc != 0)
514+
if ((rc != 0) && (rc != EPERM))
497515
fprintf(stderr, "Error: failed reverting drive - %d\n", rc);
498516

499517
return rc;
@@ -533,7 +551,10 @@ int sedopal_cmd_password(int fd)
533551
*/
534552
rc = ioctl(fd, IOC_OPAL_SET_PW, &new_pw);
535553
if (rc != 0) {
536-
fprintf(stderr, "Error: failed setting password - %d\n", rc);
554+
if (rc == EPERM)
555+
fprintf(stderr, "Error: incorrect password\n");
556+
else
557+
fprintf(stderr, "Error: setting password - %d\n", rc);
537558
return rc;
538559
}
539560

@@ -542,8 +563,12 @@ int sedopal_cmd_password(int fd)
542563
* set sid password
543564
*/
544565
rc = ioctl(fd, IOC_OPAL_SET_SID_PW, &new_pw);
545-
if (rc != 0)
546-
fprintf(stderr, "Error: failed setting SID password - %d\n", rc);
566+
if (rc != 0) {
567+
if (rc == EPERM)
568+
fprintf(stderr, "Error: incorrect password\n");
569+
else
570+
fprintf(stderr, "Error: setting SID pw - %d\n", rc);
571+
}
547572
#endif
548573

549574
return rc;

0 commit comments

Comments
 (0)