[Pkg-libvirt-commits] [libguestfs] 37/66: inspect: basic Minix support

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:47:45 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.54-1
in repository libguestfs.

commit 5b65d05d5a31415aaa6f284f73da745e0ee0408a
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Mon Sep 22 19:48:41 2014 +0200

    inspect: basic Minix support
    
    Add a basic support for identifying Minix, extracting its version and
    hostname.
    
    Related to RHBZ#1144137.
---
 src/guestfs-internal.h |  2 ++
 src/inspect-apps.c     |  1 +
 src/inspect-fs-unix.c  | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/inspect-fs.c       | 11 ++++++++++
 src/inspect-icon.c     |  1 +
 src/inspect.c          |  1 +
 6 files changed, 73 insertions(+)

diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 69ea2dc..fd0c4a1 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -513,6 +513,7 @@ enum inspect_os_type {
   OS_TYPE_HURD,
   OS_TYPE_DOS,
   OS_TYPE_OPENBSD,
+  OS_TYPE_MINIX,
 };
 
 enum inspect_os_distro {
@@ -758,6 +759,7 @@ extern int guestfs___check_linux_root (guestfs_h *g, struct inspect_fs *fs);
 extern int guestfs___check_freebsd_root (guestfs_h *g, struct inspect_fs *fs);
 extern int guestfs___check_netbsd_root (guestfs_h *g, struct inspect_fs *fs);
 extern int guestfs___check_hurd_root (guestfs_h *g, struct inspect_fs *fs);
+extern int guestfs___check_minix_root (guestfs_h *g, struct inspect_fs *fs);
 
 /* inspect-fs-windows.c */
 extern char *guestfs___case_sensitive_path_silently (guestfs_h *g, const char *);
diff --git a/src/inspect-apps.c b/src/inspect-apps.c
index c199238..a77e9ce 100644
--- a/src/inspect-apps.c
+++ b/src/inspect-apps.c
@@ -157,6 +157,7 @@ guestfs__inspect_list_applications2 (guestfs_h *g, const char *root)
       break;
 
     case OS_TYPE_FREEBSD:
+    case OS_TYPE_MINIX:
     case OS_TYPE_NETBSD:
     case OS_TYPE_DOS:
     case OS_TYPE_OPENBSD:
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 89236ab..3f57cd5 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -77,6 +77,7 @@ static pcre *re_nld;
 static pcre *re_opensuse_version;
 static pcre *re_sles_version;
 static pcre *re_sles_patchlevel;
+static pcre *re_minix;
 
 static void compile_regexps (void) __attribute__((constructor));
 static void free_regexps (void) __attribute__((destructor));
@@ -135,6 +136,7 @@ compile_regexps (void)
   COMPILE (re_opensuse_version, "^VERSION = (\\d+)\\.(\\d+)", 0);
   COMPILE (re_sles_version, "^VERSION = (\\d+)", 0);
   COMPILE (re_sles_patchlevel, "^PATCHLEVEL = (\\d+)", 0);
+  COMPILE (re_minix, "^(\\d+)\\.(\\d+)(\\.(\\d+))?", 0);
 }
 
 static void
@@ -167,6 +169,7 @@ free_regexps (void)
   pcre_free (re_opensuse_version);
   pcre_free (re_sles_version);
   pcre_free (re_sles_patchlevel);
+  pcre_free (re_minix);
 }
 
 static void check_architecture (guestfs_h *g, struct inspect_fs *fs);
@@ -782,6 +785,48 @@ guestfs___check_hurd_root (guestfs_h *g, struct inspect_fs *fs)
   return 0;
 }
 
+/* The currently mounted device is maybe to be a Minix root. */
+int
+guestfs___check_minix_root (guestfs_h *g, struct inspect_fs *fs)
+{
+  fs->type = OS_TYPE_MINIX;
+
+  if (guestfs_is_file_opts (g, "/etc/version",
+                            GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+    char *major, *minor;
+    if (parse_release_file (g, fs, "/etc/version") == -1)
+      return -1;
+
+    if (match2 (g, fs->product_name, re_minix, &major, &minor)) {
+      fs->major_version = guestfs___parse_unsigned_int (g, major);
+      free (major);
+      if (fs->major_version == -1) {
+        free (minor);
+        return -1;
+      }
+      fs->minor_version = guestfs___parse_unsigned_int (g, minor);
+      free (minor);
+      if (fs->minor_version == -1)
+        return -1;
+    }
+  } else {
+    return -1;
+  }
+
+  /* Determine the architecture. */
+  check_architecture (g, fs);
+
+  /* TODO: enable fstab inspection once resolve_fstab_device implements
+   * the proper mapping from the Minix device names to the appliance names
+   */
+
+  /* Determine hostname. */
+  if (check_hostname_unix (g, fs) == -1)
+    return -1;
+
+  return 0;
+}
+
 static void
 check_architecture (guestfs_h *g, struct inspect_fs *fs)
 {
@@ -863,6 +908,18 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs)
     }
     break;
 
+  case OS_TYPE_MINIX:
+    if (guestfs_is_file (g, "/etc/hostname.file")) {
+      fs->hostname = guestfs___first_line_of_file (g, "/etc/hostname.file");
+      if (fs->hostname == NULL)
+        return -1;
+      if (STREQ (fs->hostname, "")) {
+        free (fs->hostname);
+        fs->hostname = NULL;
+      }
+    }
+    break;
+
   case OS_TYPE_WINDOWS: /* not here, see check_windows_system_registry */
   case OS_TYPE_DOS:
   case OS_TYPE_OPENBSD:
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index 21d2a23..539d814 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -247,6 +247,17 @@ check_filesystem (guestfs_h *g, const char *mountable,
     if (guestfs___check_hurd_root (g, fs) == -1)
       return -1;
   }
+  /* Minix root? */
+  else if (is_dir_etc &&
+           is_dir_bin &&
+           guestfs_is_file (g, "/service/vm") > 0 &&
+           guestfs_is_file (g, "/etc/fstab") > 0 &&
+           guestfs_is_file (g, "/etc/version") > 0) {
+    fs->is_root = 1;
+    fs->format = OS_FORMAT_INSTALLED;
+    if (guestfs___check_minix_root (g, fs) == -1)
+      return -1;
+  }
   /* Linux root? */
   else if (is_dir_etc &&
            (is_dir_bin ||
diff --git a/src/inspect-icon.c b/src/inspect-icon.c
index 94b63a2..0ffca72 100644
--- a/src/inspect-icon.c
+++ b/src/inspect-icon.c
@@ -197,6 +197,7 @@ guestfs__inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r,
   case OS_TYPE_NETBSD:
   case OS_TYPE_DOS:
   case OS_TYPE_OPENBSD:
+  case OS_TYPE_MINIX:
   case OS_TYPE_UNKNOWN:
     ; /* nothing */
   }
diff --git a/src/inspect.c b/src/inspect.c
index 1a9554e..9248b06 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -118,6 +118,7 @@ guestfs__inspect_get_type (guestfs_h *g, const char *root)
   case OS_TYPE_FREEBSD: ret = safe_strdup (g, "freebsd"); break;
   case OS_TYPE_HURD: ret = safe_strdup (g, "hurd"); break;
   case OS_TYPE_LINUX: ret = safe_strdup (g, "linux"); break;
+  case OS_TYPE_MINIX: ret = safe_strdup (g, "minix"); break;
   case OS_TYPE_NETBSD: ret = safe_strdup (g, "netbsd"); break;
   case OS_TYPE_OPENBSD: ret = safe_strdup (g, "openbsd"); break;
   case OS_TYPE_WINDOWS: ret = safe_strdup (g, "windows"); break;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list