[Libguestfs] [PATCH v2] inspector: recognize ppc64 and ppc64le archs (RHBZ#1211996)

Maros Zatko mzatko at redhat.com
Thu Apr 16 14:51:48 UTC 2015


---
 src/filearch.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/filearch.c b/src/filearch.c
index df65c98..5de2959 100644
--- a/src/filearch.c
+++ b/src/filearch.c
@@ -59,8 +59,9 @@ 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, "MSB.*64.*PowerPC", 0)
+COMPILE_REGEXP (re_elf_ppc64le, "LSB.*64.*PowerPC", 0)
 
 /* Convert output from 'file' command on ELF files to the canonical
  * architecture string.  Caller must free the result.
@@ -87,6 +88,8 @@ canonical_elf_arch (guestfs_h *g, const char *elf_arch)
     r = "ia64";
   else if (match (g, elf_arch, re_elf_ppc64))
     r = "ppc64";
+  else if (match (g, elf_arch, re_elf_ppc64le))
+    r = "ppc64le";
   else if (strstr (elf_arch, "PowerPC"))
     r = "ppc";
   else if (strstr (elf_arch, "ARM aarch64"))
@@ -114,6 +117,7 @@ magic_for_file (guestfs_h *g, const char *filename, bool *loading_ok,
 {
   int flags;
   CLEANUP_MAGIC_T_FREE magic_t m = NULL;
+  CLEANUP_FREE char *tmp = NULL;
   const char *line;
   char *elf_arch;
 
@@ -145,7 +149,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, &tmp, &elf_arch);
   if (elf_arch == NULL) {
     error (g, "no re_file_elf match in '%s'", line);
     return NULL;
@@ -315,6 +319,8 @@ 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;
+  CLEANUP_FREE char *end_elf_arch = NULL;
   char *ret = NULL;
 
   /* Get the output of the "file" command.  Note that because this
@@ -324,8 +330,10 @@ 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) {
+    end_elf_arch = guestfs_int_safe_asprintf (g, "%s %s", endianness, elf_arch);
+    ret = canonical_elf_arch (g, end_elf_arch);
+  }
   else if (strstr (file, "PE32 executable"))
     ret = safe_strdup (g, "i386");
   else if (strstr (file, "PE32+ executable"))
-- 
1.9.3




More information about the Libguestfs mailing list