On 06/01/2018 09:13 AM, AKASHI, Takahiro wrote: > Heinrich, > > On Sat, May 26, 2018 at 10:34:47AM +0200, Heinrich Schuchardt wrote: >> Signed-off-by: Heinrich Schuchardt <xypron.g...@gmx.de> >> --- >> lib/efi_selftest/efi_selftest_block_device.c | 56 ++++++++++++++++++++ >> 1 file changed, 56 insertions(+) >> >> diff --git a/lib/efi_selftest/efi_selftest_block_device.c >> b/lib/efi_selftest/efi_selftest_block_device.c >> index 4af8bd8cb28..9209ce678ee 100644 >> --- a/lib/efi_selftest/efi_selftest_block_device.c >> +++ b/lib/efi_selftest/efi_selftest_block_device.c >> @@ -377,6 +377,7 @@ static int execute(void) >> "Wrong volume label '%ps', expected 'U-BOOT TEST'\n", >> system_info.info.volume_label); >> } >> + /* Read file */ >> ret = root->open(root, &file, (s16 *)L"hello.txt", EFI_FILE_MODE_READ, >> 0); >> if (ret != EFI_SUCCESS) { >> @@ -389,6 +390,11 @@ static int execute(void) >> efi_st_error("Failed to read file\n"); >> return EFI_ST_FAILURE; >> } >> + if (buf_size != 13) { >> + efi_st_error("Wrong number of bytes read: %u\n", >> + (unsigned int)buf_size); >> + return EFI_ST_FAILURE; >> + } >> if (efi_st_memcmp(buf, "Hello world!", 12)) { >> efi_st_error("Unexpected file content\n"); >> return EFI_ST_FAILURE; >> @@ -399,6 +405,56 @@ static int execute(void) >> return EFI_ST_FAILURE; >> } >> ret = root->close(root); >
Your observation is correct. This is why I already sent a revised version of the patch series. I unfortunately missed to put you on copy. You can find the current patch here: [PATCH v2 3/3] efi_selftest: test writing to file https://patchwork.ozlabs.org/patch/921166/ https://lists.denx.de/pipermail/u-boot/2018-May/329730.html Best regards Heinrich > We should not close 'root' here as >> + /* Write file */ >> + ret = root->open(root, &file, (s16 *)L"u-boot.txt", >> + EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); > > we will use it here. > >> + if (ret != EFI_SUCCESS) { >> + efi_st_error("Failed to open file\n"); >> + return EFI_ST_FAILURE; >> + } >> + buf_size = 7; >> + boottime->set_mem(buf, sizeof(buf), 0); >> + boottime->copy_mem(buf, "U-Boot", buf_size); >> + ret = file->write(file, &buf_size, buf); >> + if (ret != EFI_SUCCESS || buf_size != 7) { >> + efi_st_error("Failed to write file\n"); >> + return EFI_ST_FAILURE; >> + } >> + ret = file->close(file); >> + if (ret != EFI_SUCCESS) { >> + efi_st_error("Failed to close file\n"); >> + return EFI_ST_FAILURE; >> + } >> + ret = root->close(root); > > ditto > > Thanks, > -Takahiro AKASHI > >> + /* Verify file */ >> + boottime->set_mem(buf, sizeof(buf), 0); >> + ret = root->open(root, &file, (s16 *)L"u-boot.txt", EFI_FILE_MODE_READ, >> + 0); >> + if (ret != EFI_SUCCESS) { >> + efi_st_error("Failed to open file\n"); >> + return EFI_ST_FAILURE; >> + } >> + buf_size = sizeof(buf) - 1; >> + ret = file->read(file, &buf_size, buf); >> + if (ret != EFI_SUCCESS) { >> + efi_st_error("Failed to read file\n"); >> + return EFI_ST_FAILURE; >> + } >> + if (buf_size != 7) { >> + efi_st_error("Wrong number of bytes read: %u\n", >> + (unsigned int) buf_size); >> + return EFI_ST_FAILURE; >> + } >> + if (efi_st_memcmp(buf, "U-Boot", 7)) { >> + efi_st_error("Unexpected file content %s\n", buf); >> + return EFI_ST_FAILURE; >> + } >> + ret = file->close(file); >> + if (ret != EFI_SUCCESS) { >> + efi_st_error("Failed to close file\n"); >> + return EFI_ST_FAILURE; >> + } >> + ret = root->close(root); >> if (ret != EFI_SUCCESS) { >> efi_st_error("Failed to close volume\n"); >> return EFI_ST_FAILURE; >> -- >> 2.17.0 >> > _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot