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: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/5] libfile: drop TFTP-specific hack in open_fdt()
Date: Thu, 12 Mar 2026 15:44:24 +0100	[thread overview]
Message-ID: <20260312144428.2158727-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260312144428.2158727-1-a.fatoum@pengutronix.de>

Now that TFTP internally does the equivalent of closing and reopening
a file when seeking back, switch to using that in open_fdt() instead
of open-coding it.

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

diff --git a/lib/libfile.c b/lib/libfile.c
index f5cea7b94998..0670ef0584cb 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -976,7 +976,7 @@ int open_fdt(const char *filename, size_t *size)
 	if (ret)
 		goto err;
 
-	ret = pread_full(fd, &fdt_hdr, sizeof(fdt_hdr), 0);
+	ret = read_full(fd, &fdt_hdr, sizeof(fdt_hdr));
 	if (ret >= 0 && ret < sizeof(fdt_hdr))
 		ret = -EILSEQ;
 	if (ret < 0)
@@ -988,13 +988,12 @@ int open_fdt(const char *filename, size_t *size)
 		goto err;
 	}
 
-	close(fd);
-
-	/* HACK: TFTP doesn't support backwards seeking, so reopen afresh */
-	fd = open(filename, O_RDONLY);
-	if (fd >= 0)
-		*size = fdt_size;
+	if (lseek(fd, 0, SEEK_SET) != 0) {
+		ret = -errno;
+		goto err;
+	}
 
+        *size = fdt_size;
 	return fd;
 err:
 	close(fd);
-- 
2.47.3




  parent reply	other threads:[~2026-03-12 14:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 14:44 [PATCH 1/5] tftp: skip memory allocation when seeking to current position Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 2/5] tftp: warn when seek-heavy access wastes network bandwidth Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 3/5] tftp: emulate backwards seek by reopening the file Ahmad Fatoum
2026-03-12 14:44 ` Ahmad Fatoum [this message]
2026-03-12 14:44 ` [PATCH 5/5] fs: fix relative path resolution when CWD is on a TFTP mount Ahmad Fatoum
2026-03-17 10:21 ` [PATCH 1/5] tftp: skip memory allocation when seeking to current position 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=20260312144428.2158727-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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