From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-pg1-f193.google.com ([209.85.215.193]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hlIfu-0006Lh-UI for kexec@lists.infradead.org; Wed, 10 Jul 2019 19:54:48 +0000 Received: by mail-pg1-f193.google.com with SMTP id g15so1736820pgi.4 for ; Wed, 10 Jul 2019 12:54:46 -0700 (PDT) From: Bhupesh Sharma Subject: [PATCH 3/4] kexec/kexec-zlib.h: Add 'is_zlib_file()' helper function Date: Thu, 11 Jul 2019 01:24:28 +0530 Message-Id: <1562788469-22935-4-git-send-email-bhsharma@redhat.com> In-Reply-To: <1562788469-22935-1-git-send-email-bhsharma@redhat.com> References: <1562788469-22935-1-git-send-email-bhsharma@redhat.com> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: kexec@lists.infradead.org Cc: bhupesh.linux@gmail.com, bhsharma@redhat.com, horms@verge.net.au, takahiro.akashi@linaro.org 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 --- 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