public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: AKASHI, Takahiro <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC 3/3] efi_selftest: test writing to file
Date: Fri, 1 Jun 2018 16:13:11 +0900	[thread overview]
Message-ID: <20180601071310.GN30789@linaro.org> (raw)
In-Reply-To: <20180526083447.2917-4-xypron.glpk@gmx.de>

Heinrich,

On Sat, May 26, 2018 at 10:34:47AM +0200, Heinrich Schuchardt wrote:
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@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);

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
> 

  reply	other threads:[~2018-06-01  7:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-26  8:34 [U-Boot] [RFC 0/3] efi_loader: allow writing to FAT Heinrich Schuchardt
2018-05-26  8:34 ` [U-Boot] [RFC 1/3] fs: fat: cannot write to subdirectories Heinrich Schuchardt
2018-05-28  7:30   ` Lukasz Majewski
2018-05-26  8:34 ` [U-Boot] [RFC 2/3] efi_selftest: imply FAT, FAT_WRITE Heinrich Schuchardt
2018-05-26  8:34 ` [U-Boot] [RFC 3/3] efi_selftest: test writing to file Heinrich Schuchardt
2018-06-01  7:13   ` AKASHI, Takahiro [this message]
2018-06-01  7:38     ` Heinrich Schuchardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180601071310.GN30789@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox