From: Michael Scherer <misc@zarb.org> --- src/guestfs-internal.h | 1 + src/inspect_fs.c | 17 +++++++++++++++++ src/inspect_fs_unix.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 0 deletions(-) diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index 52e3963..0e60175 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -239,6 +239,7 @@ enum inspect_fs_content { FS_CONTENT_LINUX_USR_LOCAL, FS_CONTENT_LINUX_VAR, FS_CONTENT_FREEBSD_ROOT, + FS_CONTENT_NETBSD_ROOT, FS_CONTENT_INSTALLER, }; diff --git a/src/inspect_fs.c b/src/inspect_fs.c index 68e2ddb..25bb492 100644 --- a/src/inspect_fs.c +++ b/src/inspect_fs.c @@ -190,6 +190,23 @@ check_filesystem (guestfs_h *g, const char *device, if (guestfs___check_freebsd_root (g, fs) == -1) return -1; } + else if (is_dir_etc && + is_dir_bin && + guestfs_is_file (g, "/etc/fstab") > 0 && + guestfs_is_file (g, "/etc/release") > 0) { + /* Ignore /dev/sda1 which is a shadow of the real root filesystem + * that is probably /dev/sda5 (see: + * http://www.freebsd.org/doc/handbook/disk-organization.html) + */ + if (match (g, device, re_first_partition)) + return 0; + + fs->is_root = 1; + fs->content = FS_CONTENT_NETBSD_ROOT; + fs->format = OS_FORMAT_INSTALLED; + if (guestfs___check_netbsd_root (g, fs) == -1) + return -1; + } /* Linux root? */ else if (is_dir_etc && is_dir_bin && diff --git a/src/inspect_fs_unix.c b/src/inspect_fs_unix.c index 20c164e..c4aa6ef 100644 --- a/src/inspect_fs_unix.c +++ b/src/inspect_fs_unix.c @@ -66,6 +66,7 @@ static pcre *re_aug_seq; static pcre *re_xdev; static pcre *re_first_partition; static pcre *re_freebsd; +static pcre *re_netbsd; static void compile_regexps (void) __attribute__((constructor)); static void free_regexps (void) __attribute__((destructor)); @@ -108,6 +109,7 @@ compile_regexps (void) COMPILE (re_aug_seq, "/\\d+$", 0); COMPILE (re_xdev, "^/dev/(?:h|s|v|xv)d([a-z]\\d*)$", 0); COMPILE (re_freebsd, "^/dev/ad(\\d+)s(\\d+)([a-z])$", 0); + COMPILE (re_netbsd, "^NetBSD (\\d+)\\.(\\d+)", 0); } static void @@ -127,6 +129,7 @@ free_regexps (void) pcre_free (re_aug_seq); pcre_free (re_xdev); pcre_free (re_freebsd); + pcre_free (re_netbsd); } static void check_architecture (guestfs_h *g, struct inspect_fs *fs); @@ -483,6 +486,48 @@ guestfs___check_freebsd_root (guestfs_h *g, struct inspect_fs *fs) return 0; } +/* The currently mounted device is maybe to be a *BSD root. */ +int +guestfs___check_netbsd_root (guestfs_h *g, struct inspect_fs *fs) +{ + + if (guestfs_exists (g, "/etc/release") > 0) { + char *major, *minor; + if (parse_release_file (g, fs, "/etc/release") == -1) + return -1; + + if (match2 (g, fs->product_name, re_netbsd, &major, &minor)) { + fs->type = OS_TYPE_NETBSD; + 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); + + /* We already know /etc/fstab exists because it's part of the test above. */ + if (inspect_with_augeas (g, fs, "/etc/fstab", check_fstab) == -1) + return -1; + + /* Determine hostname. */ + if (check_hostname_unix (g, fs) == -1) + return -1; + + return 0; +} + + static void check_architecture (guestfs_h *g, struct inspect_fs *fs) { -- 1.7.1