From: Bhupesh Sharma <bhsharma@redhat.com>
To: kexec@lists.infradead.org
Cc: bhupesh.linux@gmail.com, bhsharma@redhat.com, horms@verge.net.au,
takahiro.akashi@linaro.org
Subject: [PATCH 3/4] kexec/kexec-zlib.h: Add 'is_zlib_file()' helper function
Date: Thu, 11 Jul 2019 01:24:28 +0530 [thread overview]
Message-ID: <1562788469-22935-4-git-send-email-bhsharma@redhat.com> (raw)
In-Reply-To: <1562788469-22935-1-git-send-email-bhsharma@redhat.com>
This patch adds 'is_zlib_file()' helper function which can be
used to quickly determine with the passed kernel image is a zlib
compressed kernel image.
This is specifically useful for arm64 zImage (or Image.gz) support,
which is introduced by later patches in this patchset.
Signed-off-by: Bhupesh Sharma <bhsharma@redhat.com>
---
kexec/kexec-zlib.h | 1 +
kexec/zlib.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/kexec/kexec-zlib.h b/kexec/kexec-zlib.h
index 43c107bf4a72..16300f294759 100644
--- a/kexec/kexec-zlib.h
+++ b/kexec/kexec-zlib.h
@@ -6,5 +6,6 @@
#include "config.h"
+int is_zlib_file(const char *filename, off_t *r_size);
char *zlib_decompress_file(const char *filename, off_t *r_size);
#endif /* __KEXEC_ZLIB_H */
diff --git a/kexec/zlib.c b/kexec/zlib.c
index 95b608059d41..34d5ca566769 100644
--- a/kexec/zlib.c
+++ b/kexec/zlib.c
@@ -23,6 +23,32 @@ static void _gzerror(gzFile fp, int *errnum, const char **errmsg)
}
}
+int is_zlib_file(const char *filename, off_t *r_size)
+{
+ gzFile fp;
+ int errnum;
+ const char *msg;
+
+ if (!filename)
+ goto out;
+
+ fp = gzopen(filename, "rb");
+ if (fp == 0) {
+ _gzerror(fp, &errnum, &msg);
+ dbgprintf("Cannot open `%s': %s\n", filename, msg);
+ goto out;
+ }
+
+ if (gzdirect(fp))
+ /* It's not in gzip format */
+ goto out;
+
+ /* It's in gzip format */
+ return 1;
+out:
+ return 0;
+}
+
char *zlib_decompress_file(const char *filename, off_t *r_size)
{
gzFile fp;
@@ -84,6 +110,12 @@ fail:
return buf;
}
#else
+
+int is_zlib_file(const char *filename, off_t *r_size)
+{
+ return 0;
+}
+
char *zlib_decompress_file(const char *UNUSED(filename), off_t *UNUSED(r_size))
{
return NULL;
--
2.7.4
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2019-07-10 19:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-10 19:54 [PATCH 0/4] kexec/arm64: Add support for zlib compressed kernel images (Image.gz) Bhupesh Sharma
2019-07-10 19:54 ` [PATCH 1/4] kexec/kexec.c: Add the missing close() for fd used for kexec_file_load() Bhupesh Sharma
2019-07-10 19:54 ` [PATCH 2/4] kexec-uImage-arm64.c: Fix return value of uImage_arm64_probe() Bhupesh Sharma
2019-07-10 19:54 ` Bhupesh Sharma [this message]
2019-07-11 9:58 ` [PATCH 3/4] kexec/kexec-zlib.h: Add 'is_zlib_file()' helper function Simon Horman
2019-07-12 8:06 ` Bhupesh Sharma
2019-07-10 19:54 ` [PATCH 4/4] kexec/arm64: Add support for handling zlib compressed (Image.gz) image Bhupesh Sharma
2019-07-11 10:08 ` Simon Horman
2019-07-12 8:06 ` Bhupesh Sharma
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=1562788469-22935-4-git-send-email-bhsharma@redhat.com \
--to=bhsharma@redhat.com \
--cc=bhupesh.linux@gmail.com \
--cc=horms@verge.net.au \
--cc=kexec@lists.infradead.org \
--cc=takahiro.akashi@linaro.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