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.
---
src/guestfs-internal.h | 11 ++++++++---
src/inspect-fs-cd.c | 2 +-
src/inspect-fs.c | 20 ++++++++++----------
src/inspect.c | 17 +++++++++--------
4 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index f2f2a97..861ca75 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -633,15 +633,20 @@ enum inspect_os_package_management {
OS_PACKAGE_MANAGEMENT_XBPS,
};
+enum inspect_os_role {
+ OS_ROLE_UNKNOWN = 0,
+ OS_ROLE_ROOT,
+};
+
/**
* The inspection code maintains one of these structures per mountable
* filesystem found in the disk image. The struct (or structs) which
- * have the C<is_root> flag set are inspection roots, each
- * corresponding to a single guest. Note that a filesystem can be
+ * have the C<role> attribute set to C<OS_ROLE_ROOT> are inspection roots,
+ * each corresponding to a single guest. Note that a filesystem can be
* shared between multiple guests.
*/
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 10e9d54..278386e 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 5e5b004..1951678 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -164,7 +164,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;
@@ -175,7 +175,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;
@@ -186,7 +186,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;
@@ -195,7 +195,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;
@@ -206,7 +206,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;
@@ -217,7 +217,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;
@@ -228,7 +228,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;
@@ -263,7 +263,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;
@@ -278,7 +278,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;
@@ -306,7 +306,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 9a60aa0..ae5c457 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -113,7 +113,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;
}
@@ -123,7 +123,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):
@@ -168,15 +168,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;
}
@@ -202,7 +203,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);
@@ -704,7 +705,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