From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org, Marco Felsch <m.felsch@pengutronix.de>
Subject: Re: [PATCH master] fs: align truncate return codes with POSIX
Date: Fri, 3 Feb 2023 08:52:07 +0100 [thread overview]
Message-ID: <20230203075207.GM13319@pengutronix.de> (raw)
In-Reply-To: <20230202122000.195253-1-a.fatoum@pengutronix.de>
On Thu, Feb 02, 2023 at 01:20:00PM +0100, Ahmad Fatoum wrote:
> Writing past end of a file results in a cryptic error code:
>
> barebox@board:/ cp /dev/zero /dev/mmc0.part
> write: Operation not permitted
> cp: Operation not permitted
>
> Because the cdev's truncate is not implemented and as such partition
> can't be increased in size. POSIX specifies EPERM as the correct return
> code for truncate(2) in such a situation, but for write(2) it is ENOSPC.
> Thus most truncate callbacks in barebox instead return ENOSPC, when
> according to POSIX, EPERM would have been the correct error code to
> propagate.
>
> Switching all truncate drivers is a bit more involved, so for now let's
> treat EPERM and ENOSPC instead when truncate fails to enlarge a file.
>
> Reported-by: Marco Felsch <m.felsch@pengutronix.de>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> fs/fs.c | 2 ++
> 1 file changed, 2 insertions(+)
Applied, thanks
Sascha
>
> diff --git a/fs/fs.c b/fs/fs.c
> index 752688b574a0..c463466e1be0 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -441,6 +441,8 @@ static ssize_t __write(FILE *f, const void *buf, size_t count)
> if (f->size != FILE_SIZE_STREAM && f->pos + count > f->size) {
> ret = fsdev_truncate(&f->fsdev->dev, f, f->pos + count);
> if (ret) {
> + if (ret == -EPERM)
> + ret = -ENOSPC;
> if (ret != -ENOSPC)
> goto out;
> count = f->size - f->pos;
> --
> 2.30.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
prev parent reply other threads:[~2023-02-03 7:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-02 12:20 Ahmad Fatoum
2023-02-02 13:12 ` Marco Felsch
2023-02-03 7:52 ` Sascha Hauer [this message]
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=20230203075207.GM13319@pengutronix.de \
--to=sha@pengutronix.de \
--cc=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=m.felsch@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