Maros Zatko
2015-May-22 15:10 UTC
[Libguestfs] [PATCH v5] inspector: recognize ppc64 and ppc64le archs (RHBZ#1211996)
Patch extracts MSB/LSB info from /bin/file output and passes it as separate parameret from elf_arch. Then it is sent to impl_file_architecture and checked/ Modified magic_for_file to handle regex changes. Now with tests for file_architecture, and error reporting for unknown endianness. Fixes: RHBZ#1211996 Maros Zatko (1): inspector: recognize ppc64 and ppc64le archs (RHBZ#1211996) generator/actions.ml | 8 ++++++++ src/filearch.c | 28 +++++++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) -- 1.9.3
Maros Zatko
2015-May-22 15:10 UTC
[Libguestfs] [PATCH v5] inspector: recognize ppc64 and ppc64le archs (RHBZ#1211996)
---
generator/actions.ml | 8 ++++++++
src/filearch.c | 28 +++++++++++++++++++---------
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/generator/actions.ml b/generator/actions.ml
index 4447de6..6648d63 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -788,6 +788,10 @@ to specify the QEMU interface emulation to use at run
time." };
InitISOFS, Always, TestResultString (
[["file_architecture"; "/bin-i586-dynamic"]],
"i386"), [];
InitISOFS, Always, TestResultString (
+ [["file_architecture"; "/bin-ppc64-dynamic"]],
"ppc64"), [];
+ InitISOFS, Always, TestResultString (
+ [["file_architecture"; "/bin-ppc64le-dynamic"]],
"ppc64le"), [];
+ InitISOFS, Always, TestResultString (
[["file_architecture"; "/bin-sparc-dynamic"]],
"sparc"), [];
InitISOFS, Always, TestResultString (
[["file_architecture"; "/bin-win32.exe"]],
"i386"), [];
@@ -802,6 +806,10 @@ to specify the QEMU interface emulation to use at run
time." };
InitISOFS, Always, TestResultString (
[["file_architecture"; "/lib-i586.so"]],
"i386"), [];
InitISOFS, Always, TestResultString (
+ [["file_architecture"; "/lib-ppc64.so"]],
"ppc64"), [];
+ InitISOFS, Always, TestResultString (
+ [["file_architecture"; "/lib-ppc64le.so"]],
"ppc64le"), [];
+ InitISOFS, Always, TestResultString (
[["file_architecture"; "/lib-sparc.so"]],
"sparc"), [];
InitISOFS, Always, TestResultString (
[["file_architecture"; "/lib-win32.dll"]],
"i386"), [];
diff --git a/src/filearch.c b/src/filearch.c
index 8fb1acf..a309bbe 100644
--- a/src/filearch.c
+++ b/src/filearch.c
@@ -59,14 +59,14 @@ cleanup_magic_t_free (void *ptr)
# endif
COMPILE_REGEXP (re_file_elf,
- "ELF.*(?:executable|shared object|relocatable),
(.+?),", 0)
-COMPILE_REGEXP (re_elf_ppc64, "64.*PowerPC", 0)
+ "ELF.*(MSB|LSB).*(?:executable|shared object|relocatable),
(.+?),", 0)
+COMPILE_REGEXP (re_elf_ppc64, ".*64.*PowerPC", 0)
/* Convert output from 'file' command on ELF files to the canonical
* architecture string. Caller must free the result.
*/
static char *
-canonical_elf_arch (guestfs_h *g, const char *elf_arch)
+canonical_elf_arch (guestfs_h *g, const char *endianness, const char *elf_arch)
{
const char *r;
char *ret;
@@ -85,8 +85,16 @@ canonical_elf_arch (guestfs_h *g, const char *elf_arch)
r = "sparc64";
else if (strstr (elf_arch, "IA-64"))
r = "ia64";
- else if (match (g, elf_arch, re_elf_ppc64))
- r = "ppc64";
+ else if (match (g, elf_arch, re_elf_ppc64)) {
+ if (strstr (endianness, "MSB"))
+ r = "ppc64";
+ else if (strstr (endianness, "LSB"))
+ r = "ppc64le";
+ else {
+ error (g, "file_architecture: unknown endianness '%s'",
endianness);
+ return NULL;
+ }
+ }
else if (strstr (elf_arch, "PowerPC"))
r = "ppc";
else if (strstr (elf_arch, "ARM aarch64"))
@@ -116,6 +124,7 @@ magic_for_file (guestfs_h *g, const char *filename, bool
*loading_ok,
CLEANUP_MAGIC_T_FREE magic_t m = NULL;
const char *line;
CLEANUP_FREE char *elf_arch = NULL;
+ CLEANUP_FREE char *endianness = NULL;
flags = g->verbose ? MAGIC_DEBUG : 0;
flags |= MAGIC_ERROR | MAGIC_RAW;
@@ -145,7 +154,7 @@ magic_for_file (guestfs_h *g, const char *filename, bool
*loading_ok,
if (loading_ok)
*loading_ok = true;
- elf_arch = match1 (g, line, re_file_elf);
+ match2 (g, line, re_file_elf, &endianness, &elf_arch);
if (elf_arch == NULL) {
error (g, "no re_file_elf match in '%s'", line);
return NULL;
@@ -154,7 +163,7 @@ magic_for_file (guestfs_h *g, const char *filename, bool
*loading_ok,
if (matched)
*matched = true;
- return canonical_elf_arch (g, elf_arch);
+ return canonical_elf_arch (g, endianness, elf_arch);
}
/* Download and uncompress the cpio file to find binaries within. */
@@ -315,6 +324,7 @@ guestfs_impl_file_architecture (guestfs_h *g, const char
*path)
{
CLEANUP_FREE char *file = NULL;
CLEANUP_FREE char *elf_arch = NULL;
+ CLEANUP_FREE char *endianness = NULL;
char *ret = NULL;
/* Get the output of the "file" command. Note that because this
@@ -324,8 +334,8 @@ guestfs_impl_file_architecture (guestfs_h *g, const char
*path)
if (file == NULL)
return NULL;
- if ((elf_arch = match1 (g, file, re_file_elf)) != NULL)
- ret = canonical_elf_arch (g, elf_arch);
+ if ((match2 (g, file, re_file_elf, &endianness, &elf_arch)) != 0)
+ ret = canonical_elf_arch (g, endianness, elf_arch);
else if (strstr (file, "PE32 executable"))
ret = safe_strdup (g, "i386");
else if (strstr (file, "PE32+ executable"))
--
1.9.3
Richard W.M. Jones
2015-May-28 11:52 UTC
Re: [Libguestfs] [PATCH v5] inspector: recognize ppc64 and ppc64le archs (RHBZ#1211996)
On Fri, May 22, 2015 at 05:10:14PM +0200, Maros Zatko wrote:> @@ -145,7 +154,7 @@ magic_for_file (guestfs_h *g, const char *filename, bool *loading_ok, > if (loading_ok) > *loading_ok = true; > > - elf_arch = match1 (g, line, re_file_elf); > + match2 (g, line, re_file_elf, &endianness, &elf_arch); > if (elf_arch == NULL) { > error (g, "no re_file_elf match in '%s'", line); > return NULL;I was a bit worried about not checking the return from match2, so I applied this patch on top: diff --git a/src/filearch.c b/src/filearch.c index a309bbe..29c9ba6 100644 --- a/src/filearch.c +++ b/src/filearch.c @@ -154,8 +154,7 @@ magic_for_file (guestfs_h *g, const char *filename, bool *loading_ok, if (loading_ok) *loading_ok = true; - match2 (g, line, re_file_elf, &endianness, &elf_arch); - if (elf_arch == NULL) { + if (!match2 (g, line, re_file_elf, &endianness, &elf_arch)) { error (g, "no re_file_elf match in '%s'", line); return NULL; } This is consistent with what the old code did, although I'm not 100% convinced it is correct. I pushed this, thanks. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Possibly Parallel Threads
- [PATCH v4 1/2] inspector: recognize ppc64 and ppc64le archs (RHBZ#1211996)
- [PATCH 12/27] daemon: Reimplement ‘file_architecture’ API in OCaml.
- [PATCH 1/2] filearch: Add RISC-V architecture.
- [PATCH v4 0/2] inspector: recognize ppc64 and ppc64le archs (RHBZ#1211996)
- [PATCH v5] inspector: recognize ppc64 and ppc64le archs (RHBZ#1211996)