From: Juergen Borleis <jbe@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] sparse_image_fd: add function to re-use a file descriptor
Date: Thu, 14 Sep 2023 11:58:58 +0200 [thread overview]
Message-ID: <20230914095859.22166-1-jbe@pengutronix.de> (raw)
Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
---
include/image-sparse.h | 1 +
lib/image-sparse.c | 17 +++++++++++------
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/include/image-sparse.h b/include/image-sparse.h
index 6bff844..d969ca1 100644
--- a/include/image-sparse.h
+++ b/include/image-sparse.h
@@ -59,6 +59,7 @@ static inline int is_sparse_image(const void *buf)
struct sparse_image_ctx;
struct sparse_image_ctx *sparse_image_open(const char *path);
+struct sparse_image_ctx *sparse_image_fd(int infd);
int sparse_image_read(struct sparse_image_ctx *si, void *buf,
loff_t *pos, size_t len, size_t *retlen);
void sparse_image_close(struct sparse_image_ctx *si);
diff --git a/lib/image-sparse.c b/lib/image-sparse.c
index eb5242e..b686d25 100644
--- a/lib/image-sparse.c
+++ b/lib/image-sparse.c
@@ -146,7 +146,7 @@ loff_t sparse_image_size(struct sparse_image_ctx *si)
return (loff_t)si->sparse.blk_sz * si->sparse.total_blks;
}
-struct sparse_image_ctx *sparse_image_open(const char *path)
+struct sparse_image_ctx *sparse_image_fd(int infd)
{
struct sparse_image_ctx *si;
loff_t offs;
@@ -154,11 +154,7 @@ struct sparse_image_ctx *sparse_image_open(const char *path)
si = xzalloc(sizeof(*si));
- si->fd = open(path, O_RDONLY);
- if (si->fd < 0) {
- ret = -errno;
- goto out;
- }
+ si->fd = infd;
/* Read and skip over sparse image header */
read(si->fd, &si->sparse, sizeof(struct sparse_header));
@@ -186,6 +182,15 @@ struct sparse_image_ctx *sparse_image_open(const char *path)
return ERR_PTR(ret);
}
+struct sparse_image_ctx *sparse_image_open(const char *path)
+{
+ int fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return ERR_PTR(-errno);
+
+ return sparse_image_fd(fd);
+}
+
int sparse_image_read(struct sparse_image_ctx *si, void *buf, loff_t *pos,
size_t len, size_t *retlen)
{
--
2.30.2
next reply other threads:[~2023-09-14 10:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-14 9:58 Juergen Borleis [this message]
2023-09-14 9:58 ` [PATCH 2/2] uncompress: add Android sparse image support Juergen Borleis
2023-09-16 16:01 ` Uwe Kleine-König
2023-09-21 12:04 ` Sascha Hauer
2023-09-21 12:01 ` 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=20230914095859.22166-1-jbe@pengutronix.de \
--to=jbe@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