aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2021-01-17 05:13:21 +0100
committerHeinrich Schuchardt <xypron.glpk@gmx.de>2021-01-20 08:17:17 +0100
commitb6f6080f56986670a3012fa565391da112724d21 (patch)
tree98a0b569fefa966caa52a01e55117028bf475f1e
parent19ea5e66de3b68fc12533a32c412bfe0594f9ea0 (diff)
downloadu-boot-b6f6080f56986670a3012fa565391da112724d21.zip
u-boot-b6f6080f56986670a3012fa565391da112724d21.tar.gz
u-boot-b6f6080f56986670a3012fa565391da112724d21.tar.bz2
efi_selftest: ask before overwriting in dtbdump.efi
Before overwriting an existing file ask the user. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
-rw-r--r--lib/efi_selftest/dtbdump.c60
1 files changed, 59 insertions, 1 deletions
diff --git a/lib/efi_selftest/dtbdump.c b/lib/efi_selftest/dtbdump.c
index efef759..cbc9067 100644
--- a/lib/efi_selftest/dtbdump.c
+++ b/lib/efi_selftest/dtbdump.c
@@ -41,7 +41,51 @@ static void error(u16 *string)
}
/**
- * input() - read string from console
+ * efi_input_yn() - get answer to yes/no question
+ *
+ * Return:
+ * y or Y
+ * EFI_SUCCESS
+ * n or N
+ * EFI_ACCESS_DENIED
+ * ESC
+ * EFI_ABORTED
+ */
+static efi_status_t efi_input_yn(void)
+{
+ struct efi_input_key key = {0};
+ efi_uintn_t index;
+ efi_status_t ret;
+
+ /* Drain the console input */
+ ret = cin->reset(cin, true);
+ for (;;) {
+ ret = bs->wait_for_event(1, &cin->wait_for_key, &index);
+ if (ret != EFI_SUCCESS)
+ continue;
+ ret = cin->read_key_stroke(cin, &key);
+ if (ret != EFI_SUCCESS)
+ continue;
+ switch (key.scan_code) {
+ case 0x17: /* Escape */
+ return EFI_ABORTED;
+ default:
+ break;
+ }
+ /* Convert to lower case */
+ switch (key.unicode_char | 0x20) {
+ case 'y':
+ return EFI_SUCCESS;
+ case 'n':
+ return EFI_ACCESS_DENIED;
+ default:
+ break;
+ }
+ }
+}
+
+/**
+ * efi_input() - read string from console
*
* @buffer: input buffer
* @buffer_size: buffer size
@@ -379,6 +423,20 @@ efi_status_t do_save(u16 *filename)
error(L"Failed to open volume\n");
return ret;
}
+ /* Check if file already exists */
+ ret = root->open(root, &file, filename, EFI_FILE_MODE_READ, 0);
+ if (ret == EFI_SUCCESS) {
+ file->close(file);
+ cout->output_string(cout, L"Overwrite existing file (y/n)? ");
+ ret = efi_input_yn();
+ cout->output_string(cout, L"\n");
+ if (ret != EFI_SUCCESS) {
+ root->close(root);
+ error(L"Aborted by user\n");
+ return ret;
+ }
+ }
+
/* Create file */
ret = root->open(root, &file, filename,
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE |