mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Marco Felsch <m.felsch@pengutronix.de>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] fs: align truncate return codes with POSIX
Date: Thu,  2 Feb 2023 13:20:00 +0100	[thread overview]
Message-ID: <20230202122000.195253-1-a.fatoum@pengutronix.de> (raw)

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(+)

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




             reply	other threads:[~2023-02-02 12:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 12:20 Ahmad Fatoum [this message]
2023-02-02 13:12 ` Marco Felsch
2023-02-03  7:52 ` Sascha Hauer

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=20230202122000.195253-1-a.fatoum@pengutronix.de \
    --to=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