Skip to content

Commit

Permalink
inspect: change is_root flag into enum
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ptoscano committed Dec 6, 2016
1 parent b014161 commit 0c4edce
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
11 changes: 8 additions & 3 deletions src/guestfs-internal.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/inspect-fs-cd.c
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/inspect-fs.c
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions src/inspect.c
Expand Up @@ -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;
}

Expand All @@ -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):
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 0c4edce

Please sign in to comment.