mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrej Picej <andrej.picej@norik.com>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH 3/3] Revert "scripts/common: fix write_file when opened with mmap"
Date: Thu, 24 Feb 2022 14:22:12 +0100	[thread overview]
Message-ID: <2fc596cc-031c-0f53-4646-72ad03bbc8a7@norik.com> (raw)
In-Reply-To: <20220211094230.1807262-3-s.hauer@pengutronix.de>

Hi Sascha,

sorry for responding this late, but we are still getting the same errors 
as before when using bareboximd with these three patches.

Are you sure we can revert this patch? The file can still be opened in 
bareboximd with mmap(), and then be written with this write_file(), 
which fails with the same error:

> Cannot write to barebox.bin: Bad address
> CRC: write crc token to barebox.bin failed: -14
> Bad address

Best regards,
Andrej



On 11. 02. 22 10:42, Sascha Hauer wrote:
> mmap() is no longer used in read_file_2(), so this patch is no longer
> necessary.
> 
> This reverts commit 738601e1258c55953284ee10801b26b9977918c2.
> ---
>   scripts/common.c | 15 ++++-----------
>   1 file changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/scripts/common.c b/scripts/common.c
> index 3d07be3630..2be41615ea 100644
> --- a/scripts/common.c
> +++ b/scripts/common.c
> @@ -102,33 +102,26 @@ int write_file(const char *filename, const void *buf, size_t size)
>   {
>   	int fd, ret = 0;
>   	int now;
> -	size_t left = size;
>   
> -	/* The same file may be mmapped currently, so can't use O_TRUNC here */
> -	fd = open(filename, O_WRONLY | O_CREAT,
> +	fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT,
>   		  S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
>   	if (fd < 0) {
>   		fprintf(stderr, "Cannot open %s: %s\n", filename, strerror(errno));
>   		return -errno;
>   	}
>   
> -	while (left) {
> -		now = write(fd, buf, left);
> +	while (size) {
> +		now = write(fd, buf, size);
>   		if (now < 0) {
>   			fprintf(stderr, "Cannot write to %s: %s\n", filename,
>   				strerror(errno));
>   			ret = -errno;
>   			goto out;
>   		}
> -		left -= now;
> +		size -= now;
>   		buf += now;
>   	}
>   
> -	if (ftruncate(fd, size) < 0) {
> -		fprintf(stderr, "Cannot truncate file: %s", strerror(errno));
> -		ret = -errno;
> -	}
> -
>   out:
>   	close(fd);
>   

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2022-02-24 13:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-11  9:42 [PATCH 1/3] scripts/common: Do not mmap in read_file_2() Sascha Hauer
2022-02-11  9:42 ` [PATCH 2/3] scripts: bareboximd: Use mmap when possible Sascha Hauer
2022-02-11  9:42 ` [PATCH 3/3] Revert "scripts/common: fix write_file when opened with mmap" Sascha Hauer
2022-02-24 13:22   ` Andrej Picej [this message]
2022-02-28 10:16     ` Sascha Hauer
2022-02-28 11:40       ` Andrej Picej

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=2fc596cc-031c-0f53-4646-72ad03bbc8a7@norik.com \
    --to=andrej.picej@norik.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.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