mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] libfile: advance offset in pread_full() on short reads
@ 2026-08-26  9:55 Ahmad Fatoum
  2026-08-26  9:55 ` [PATCH 2/2] libfile: allow fixup_path_case() to resolve directories Ahmad Fatoum
  2026-08-28 12:18 ` [PATCH 1/2] libfile: advance offset in pread_full() on short reads Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2026-08-26  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

pread_full() loops until the requested size was read, but reads from
the same offset on every iteration, so a short read is followed by
re-reading the same data instead of the remainder.

Advance the offset along with the buffer pointer.

Fixes: 59d6b83f1d4b ("libfile: implement new pread_full")
Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
While a fix, I would keep it in next, just to watch if this leads to
adverse effects.
---
 lib/libfile.c    | 1 +
 scripts/common.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/lib/libfile.c b/lib/libfile.c
index cf78c70354d9..bd0118a7e5be 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -93,6 +93,7 @@ int pread_full(int fd, void *buf, size_t size, loff_t offset)
 			return now;
 		size -= now;
 		buf += now;
+		offset += now;
 	}
 
 	return insize - size;
diff --git a/scripts/common.c b/scripts/common.c
index a6eee968b79d..6615cfb38b55 100644
--- a/scripts/common.c
+++ b/scripts/common.c
@@ -210,6 +210,7 @@ int pread_full(int fd, void *buf, size_t size, loff_t offset)
 			return now;
 		size -= now;
 		buf += now;
+		offset += now;
 	}
 
 	return insize - size;
-- 
2.47.3




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] libfile: allow fixup_path_case() to resolve directories
  2026-08-26  9:55 [PATCH 1/2] libfile: advance offset in pread_full() on short reads Ahmad Fatoum
@ 2026-08-26  9:55 ` Ahmad Fatoum
  2026-08-28 12:18 ` [PATCH 1/2] libfile: advance offset in pread_full() on short reads Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2026-08-26  9:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

fixup_path_case() opens the final path component without O_DIRECTORY
and thus fails with -EISDIR if that component is a directory.

The only user so far resolved a file and called fstat() on the fd,
but in future we may extend it to handle directories as well,
so prepare for that.

Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/libfile.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/libfile.c b/lib/libfile.c
index bd0118a7e5be..35ec631de82f 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -869,7 +869,12 @@ int fixup_path_case(int fd, const char **path)
 		free(imatch);
 
 next_component:
-		fd = openat(fd, curr, next ? O_DIRECTORY : 0);
+		/*
+		 * The final component may be a directory as well, which
+		 * can't be opened without O_DIRECTORY, but O_PATH suffices
+		 * for the fstat() callers usually follow up with.
+		 */
+		fd = openat(fd, curr, next ? O_DIRECTORY : O_PATH);
 		closedir(dir);
 
 		if (fd < 0)
-- 
2.47.3




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] libfile: advance offset in pread_full() on short reads
  2026-08-26  9:55 [PATCH 1/2] libfile: advance offset in pread_full() on short reads Ahmad Fatoum
  2026-08-26  9:55 ` [PATCH 2/2] libfile: allow fixup_path_case() to resolve directories Ahmad Fatoum
@ 2026-08-28 12:18 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2026-08-28 12:18 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Wed, 26 Aug 2026 11:55:37 +0200, Ahmad Fatoum wrote:
> pread_full() loops until the requested size was read, but reads from
> the same offset on every iteration, so a short read is followed by
> re-reading the same data instead of the remainder.
> 
> Advance the offset along with the buffer pointer.
> 
> 
> [...]

Applied, thanks!

[1/2] libfile: advance offset in pread_full() on short reads
      https://git.pengutronix.de/cgit/barebox/commit/?id=ab863d035c6d (link may not be stable)
[2/2] libfile: allow fixup_path_case() to resolve directories
      https://git.pengutronix.de/cgit/barebox/commit/?id=edf68574ef1f (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-28 12:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-26  9:55 [PATCH 1/2] libfile: advance offset in pread_full() on short reads Ahmad Fatoum
2026-08-26  9:55 ` [PATCH 2/2] libfile: allow fixup_path_case() to resolve directories Ahmad Fatoum
2026-08-28 12:18 ` [PATCH 1/2] libfile: advance offset in pread_full() on short reads Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox