|
|
603de6 |
From 0e709571bfe7e3b8160044970e2084194f9a963b Mon Sep 17 00:00:00 2001
|
|
|
603de6 |
From: Bhupesh Sharma <bhsharma@redhat.com>
|
|
|
603de6 |
Date: Mon, 15 Jul 2019 11:32:55 +0530
|
|
|
603de6 |
Subject: [PATCH 3/5] kexec/kexec-zlib.h: Add 'is_zlib_file()' helper function
|
|
|
603de6 |
|
|
|
603de6 |
This patch adds 'is_zlib_file()' helper function which can be
|
|
|
603de6 |
used to quickly determine with the passed kernel image is a zlib
|
|
|
603de6 |
compressed kernel image.
|
|
|
603de6 |
|
|
|
603de6 |
This is specifically useful for arm64 zImage (or Image.gz) support,
|
|
|
603de6 |
which is introduced by later patches in this patchset.
|
|
|
603de6 |
|
|
|
603de6 |
Signed-off-by: Bhupesh Sharma <bhsharma@redhat.com>
|
|
|
603de6 |
Signed-off-by: Simon Horman <horms@verge.net.au>
|
|
|
603de6 |
---
|
|
|
603de6 |
kexec/kexec-zlib.h | 1 +
|
|
|
603de6 |
kexec/zlib.c | 38 ++++++++++++++++++++++++++++++++++++++
|
|
|
603de6 |
2 files changed, 39 insertions(+)
|
|
|
603de6 |
|
|
|
603de6 |
diff --git a/kexec/kexec-zlib.h b/kexec/kexec-zlib.h
|
|
|
603de6 |
index 43c107bf4a72..16300f294759 100644
|
|
|
603de6 |
--- a/kexec/kexec-zlib.h
|
|
|
603de6 |
+++ b/kexec/kexec-zlib.h
|
|
|
603de6 |
@@ -6,5 +6,6 @@
|
|
|
603de6 |
|
|
|
603de6 |
#include "config.h"
|
|
|
603de6 |
|
|
|
603de6 |
+int is_zlib_file(const char *filename, off_t *r_size);
|
|
|
603de6 |
char *zlib_decompress_file(const char *filename, off_t *r_size);
|
|
|
603de6 |
#endif /* __KEXEC_ZLIB_H */
|
|
|
603de6 |
diff --git a/kexec/zlib.c b/kexec/zlib.c
|
|
|
603de6 |
index 95b608059d41..9bc340d85001 100644
|
|
|
603de6 |
--- a/kexec/zlib.c
|
|
|
603de6 |
+++ b/kexec/zlib.c
|
|
|
603de6 |
@@ -23,6 +23,38 @@ static void _gzerror(gzFile fp, int *errnum, const char **errmsg)
|
|
|
603de6 |
}
|
|
|
603de6 |
}
|
|
|
603de6 |
|
|
|
603de6 |
+int is_zlib_file(const char *filename, off_t *r_size)
|
|
|
603de6 |
+{
|
|
|
603de6 |
+ gzFile fp;
|
|
|
603de6 |
+ int errnum;
|
|
|
603de6 |
+ int is_zlib_file = 0; /* default: It's not in gzip format */
|
|
|
603de6 |
+ const char *msg;
|
|
|
603de6 |
+ ssize_t result;
|
|
|
603de6 |
+
|
|
|
603de6 |
+ if (!filename)
|
|
|
603de6 |
+ goto out;
|
|
|
603de6 |
+
|
|
|
603de6 |
+ fp = gzopen(filename, "rb");
|
|
|
603de6 |
+ if (fp == 0) {
|
|
|
603de6 |
+ _gzerror(fp, &errnum, &msg;;
|
|
|
603de6 |
+ dbgprintf("Cannot open `%s': %s\n", filename, msg);
|
|
|
603de6 |
+ goto out;
|
|
|
603de6 |
+ }
|
|
|
603de6 |
+
|
|
|
603de6 |
+ if (!gzdirect(fp))
|
|
|
603de6 |
+ /* It's in gzip format */
|
|
|
603de6 |
+ is_zlib_file = 1;
|
|
|
603de6 |
+
|
|
|
603de6 |
+ result = gzclose(fp);
|
|
|
603de6 |
+ if (result != Z_OK) {
|
|
|
603de6 |
+ _gzerror(fp, &errnum, &msg;;
|
|
|
603de6 |
+ dbgprintf(" Close of %s failed: %s\n", filename, msg);
|
|
|
603de6 |
+ }
|
|
|
603de6 |
+
|
|
|
603de6 |
+out:
|
|
|
603de6 |
+ return is_zlib_file;
|
|
|
603de6 |
+}
|
|
|
603de6 |
+
|
|
|
603de6 |
char *zlib_decompress_file(const char *filename, off_t *r_size)
|
|
|
603de6 |
{
|
|
|
603de6 |
gzFile fp;
|
|
|
603de6 |
@@ -84,6 +116,12 @@ fail:
|
|
|
603de6 |
return buf;
|
|
|
603de6 |
}
|
|
|
603de6 |
#else
|
|
|
603de6 |
+
|
|
|
603de6 |
+int is_zlib_file(const char *filename, off_t *r_size)
|
|
|
603de6 |
+{
|
|
|
603de6 |
+ return 0;
|
|
|
603de6 |
+}
|
|
|
603de6 |
+
|
|
|
603de6 |
char *zlib_decompress_file(const char *UNUSED(filename), off_t *UNUSED(r_size))
|
|
|
603de6 |
{
|
|
|
603de6 |
return NULL;
|
|
|
603de6 |
--
|
|
|
603de6 |
2.7.4
|
|
|
603de6 |
|