Blob Blame History Raw
From a8532145296a97ffe1df63f9be91c88b63cbf603 Mon Sep 17 00:00:00 2001
From: Pino Toscano <ptoscano@redhat.com>
Date: Mon, 5 Dec 2016 16:10:20 +0100
Subject: [PATCH] inspect: change is_root flag into enum

Introduce a new enum to classify the role of a filesystem, if available.
This will help later on when doing operations on non-root filesystems,
like detecting particular mountpoints such as /usr.

The new enum has only "root" as known role, which replaces the is_root
flag.

(cherry picked from commit 0c4edcecbaa82be2251d296e524e3bb50840ba9e)
---
 src/guestfs-internal.h |  7 ++++++-
 src/inspect-fs-cd.c    |  2 +-
 src/inspect-fs.c       | 20 ++++++++++----------
 src/inspect.c          | 17 +++++++++--------
 4 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 2002253..6f31438 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -594,8 +594,13 @@ enum inspect_os_package_management {
   OS_PACKAGE_MANAGEMENT_APK,
 };
 
+enum inspect_os_role {
+  OS_ROLE_UNKNOWN = 0,
+  OS_ROLE_ROOT,
+};
+
 struct inspect_fs {
-  int is_root;
+  enum inspect_os_role role;
   char *mountable;
   enum inspect_os_type type;
   enum inspect_os_distro distro;
diff --git a/src/inspect-fs-cd.c b/src/inspect-fs-cd.c
index 09974b5..ab6ee4e 100644
--- a/src/inspect-fs-cd.c
+++ b/src/inspect-fs-cd.c
@@ -525,7 +525,7 @@ guestfs_int_check_installer_iso (guestfs_h *g, struct inspect_fs *fs,
 
   /* Otherwise we matched an ISO, so fill in the fs fields. */
   fs->mountable = safe_strdup (g, device);
-  fs->is_root = 1;
+  fs->role = OS_ROLE_ROOT;
   if (osinfo->is_installer)
     fs->format = OS_FORMAT_INSTALLER;
   fs->type = osinfo->type;
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index 87609ab..58f08b8 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -166,7 +166,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
            is_dir_bin &&
            guestfs_is_file (g, "/etc/freebsd-update.conf") > 0 &&
            guestfs_is_file (g, "/etc/fstab") > 0) {
-    fs->is_root = 1;
+    fs->role = OS_ROLE_ROOT;
     fs->format = OS_FORMAT_INSTALLED;
     if (guestfs_int_check_freebsd_root (g, fs) == -1)
       return -1;
@@ -177,7 +177,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
            guestfs_is_file (g, "/netbsd") > 0 &&
            guestfs_is_file (g, "/etc/fstab") > 0 &&
            guestfs_is_file (g, "/etc/release") > 0) {
-    fs->is_root = 1;
+    fs->role = OS_ROLE_ROOT;
     fs->format = OS_FORMAT_INSTALLED;
     if (guestfs_int_check_netbsd_root (g, fs) == -1)
       return -1;
@@ -188,7 +188,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
            guestfs_is_file (g, "/bsd") > 0 &&
            guestfs_is_file (g, "/etc/fstab") > 0 &&
            guestfs_is_file (g, "/etc/motd") > 0) {
-    fs->is_root = 1;
+    fs->role = OS_ROLE_ROOT;
     fs->format = OS_FORMAT_INSTALLED;
     if (guestfs_int_check_openbsd_root (g, fs) == -1)
       return -1;
@@ -197,7 +197,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
   else if (guestfs_is_file (g, "/hurd/console") > 0 &&
            guestfs_is_file (g, "/hurd/hello") > 0 &&
            guestfs_is_file (g, "/hurd/null") > 0) {
-    fs->is_root = 1;
+    fs->role = OS_ROLE_ROOT;
     fs->format = OS_FORMAT_INSTALLED; /* XXX could be more specific */
     if (guestfs_int_check_hurd_root (g, fs) == -1)
       return -1;
@@ -208,7 +208,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
            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->role = OS_ROLE_ROOT;
     fs->format = OS_FORMAT_INSTALLED;
     if (guestfs_int_check_minix_root (g, fs) == -1)
       return -1;
@@ -219,7 +219,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
             is_symlink_to (g, "/bin", "usr/bin") > 0) &&
            (guestfs_is_file (g, "/etc/fstab") > 0 ||
             guestfs_is_file (g, "/etc/hosts") > 0)) {
-    fs->is_root = 1;
+    fs->role = OS_ROLE_ROOT;
     fs->format = OS_FORMAT_INSTALLED;
     if (guestfs_int_check_linux_root (g, fs) == -1)
       return -1;
@@ -230,7 +230,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
            guestfs_is_dir (g, "/home") > 0 &&
            guestfs_is_dir (g, "/usr") > 0 &&
            guestfs_is_file (g, "/etc/coreos/update.conf") > 0) {
-    fs->is_root = 1;
+    fs->role = OS_ROLE_ROOT;
     fs->format = OS_FORMAT_INSTALLED;
     if (guestfs_int_check_coreos_root (g, fs) == -1)
       return -1;
@@ -265,7 +265,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
   /* Windows root? */
   else if ((windows_systemroot = guestfs_int_get_windows_systemroot (g)) != NULL)
     {
-      fs->is_root = 1;
+      fs->role = OS_ROLE_ROOT;
       fs->format = OS_FORMAT_INSTALLED;
       if (guestfs_int_check_windows_root (g, fs, windows_systemroot) == -1)
 	return -1;
@@ -280,7 +280,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
   /* FreeDOS? */
   else if (guestfs_int_is_dir_nocase (g, "/FDOS") > 0 &&
            guestfs_int_is_file_nocase (g, "/FDOS/FREEDOS.BSS") > 0) {
-    fs->is_root = 1;
+    fs->role = OS_ROLE_ROOT;
     fs->format = OS_FORMAT_INSTALLED;
     fs->type = OS_TYPE_DOS;
     fs->distro = OS_DISTRO_FREEDOS;
@@ -308,7 +308,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
             guestfs_is_file (g, "/amd64/txtsetup.sif") > 0 ||
             guestfs_is_file (g, "/freedos/freedos.ico") > 0 ||
             guestfs_is_file (g, "/boot/loader.rc") > 0)) {
-    fs->is_root = 1;
+    fs->role = OS_ROLE_ROOT;
     fs->format = OS_FORMAT_INSTALLER;
     if (guestfs_int_check_installer_root (g, fs) == -1)
       return -1;
diff --git a/src/inspect.c b/src/inspect.c
index 497794e..e82c476 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -105,7 +105,7 @@ collect_coreos_inspection_info (guestfs_h *g)
   for (i = 0; i < g->nr_fses; ++i) {
     struct inspect_fs *fs = &g->fses[i];
 
-    if (fs->distro == OS_DISTRO_COREOS && fs->is_root)
+    if (fs->distro == OS_DISTRO_COREOS && fs->role == OS_ROLE_ROOT)
       root = fs;
   }
 
@@ -115,7 +115,7 @@ collect_coreos_inspection_info (guestfs_h *g)
   for (i = 0; i < g->nr_fses; ++i) {
     struct inspect_fs *fs = &g->fses[i];
 
-    if (fs->distro != OS_DISTRO_COREOS || fs->is_root != 0)
+    if (fs->distro != OS_DISTRO_COREOS || fs->role == OS_ROLE_ROOT)
       continue;
 
     /* CoreOS is designed to contain 2 /usr partitions (USR-A, USR-B):
@@ -162,15 +162,16 @@ check_for_duplicated_bsd_root (guestfs_h *g)
       fs->type == OS_TYPE_NETBSD ||
       fs->type == OS_TYPE_OPENBSD;
 
-    if (fs->is_root && is_bsd &&
+    if (fs->role == OS_ROLE_ROOT && is_bsd &&
         match (g, fs->mountable, re_primary_partition)) {
       bsd_primary = fs;
       continue;
     }
 
-    if (fs->is_root && bsd_primary && bsd_primary->type == fs->type) {
-      /* remove the is root flag from the bsd_primary */
-      bsd_primary->is_root = 0;
+    if (fs->role == OS_ROLE_ROOT && bsd_primary &&
+        bsd_primary->type == fs->type) {
+      /* remove the root role from the bsd_primary */
+      bsd_primary->role = OS_ROLE_UNKNOWN;
       bsd_primary->format = OS_FORMAT_UNKNOWN;
       return;
     }
@@ -196,7 +197,7 @@ guestfs_impl_inspect_get_roots (guestfs_h *g)
    * list in this case.
    */
   for (i = 0; i < g->nr_fses; ++i) {
-    if (g->fses[i].is_root)
+    if (g->fses[i].role == OS_ROLE_ROOT)
       guestfs_int_add_string (g, &ret, g->fses[i].mountable);
   }
   guestfs_int_end_stringsbuf (g, &ret);
@@ -694,7 +695,7 @@ guestfs_int_search_for_root (guestfs_h *g, const char *root)
 
   for (i = 0; i < g->nr_fses; ++i) {
     struct inspect_fs *fs = &g->fses[i];
-    if (fs->is_root && STREQ (root, fs->mountable))
+    if (fs->role == OS_ROLE_ROOT && STREQ (root, fs->mountable))
       return fs;
   }
 
-- 
2.7.4