From: Michael Scherer Date: Thu, 13 Oct 2011 23:05:05 +0000 (+0200) Subject: Add basic support for netbsd detection. X-Git-Tag: 1.13.21~2 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=f25d2300ce0206b3d4ef5e38d0314d86ea20136e;p=libguestfs.git Add basic support for netbsd detection. --- diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 02eb2ef..86865b8 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -743,6 +743,10 @@ Any Microsoft Windows operating system. FreeBSD. +=item \"netbsd\" + +NetBSD. + =item \"unknown\" The operating system type could not be determined. diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index eacf502..cd732e1 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, }; @@ -254,6 +255,7 @@ enum inspect_os_type { OS_TYPE_LINUX, OS_TYPE_WINDOWS, OS_TYPE_FREEBSD, + OS_TYPE_NETBSD, }; enum inspect_os_distro { @@ -400,6 +402,7 @@ extern int guestfs___read_db_dump (guestfs_h *g, const char *dumpfile, void *opa extern int guestfs___check_installer_root (guestfs_h *g, struct inspect_fs *fs); 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___has_windows_systemroot (guestfs_h *g); extern int guestfs___check_windows_root (guestfs_h *g, struct inspect_fs *fs); #endif diff --git a/src/inspect.c b/src/inspect.c index 1432735..91b84cb 100644 --- a/src/inspect.c +++ b/src/inspect.c @@ -163,9 +163,10 @@ guestfs__inspect_get_type (guestfs_h *g, const char *root) char *ret; switch (fs->type) { + case OS_TYPE_FREEBSD: ret = safe_strdup (g, "freebsd"); break; case OS_TYPE_LINUX: ret = safe_strdup (g, "linux"); break; + case OS_TYPE_NETBSD: ret = safe_strdup (g, "netbsd"); break; case OS_TYPE_WINDOWS: ret = safe_strdup (g, "windows"); break; - case OS_TYPE_FREEBSD: ret = safe_strdup (g, "freebsd"); break; case OS_TYPE_UNKNOWN: default: ret = safe_strdup (g, "unknown"); break; } diff --git a/src/inspect_apps.c b/src/inspect_apps.c index a77da73..c6ddd05 100644 --- a/src/inspect_apps.c +++ b/src/inspect_apps.c @@ -104,6 +104,7 @@ guestfs__inspect_list_applications (guestfs_h *g, const char *root) break; case OS_TYPE_FREEBSD: + case OS_TYPE_NETBSD: case OS_TYPE_UNKNOWN: default: /* nothing - keep GCC happy */; 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..12bda68 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) { @@ -542,6 +587,7 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs) break; case OS_TYPE_FREEBSD: + case OS_TYPE_NETBSD: /* /etc/rc.conf contains the hostname, but there is no Augeas lens * for this file. */ diff --git a/src/inspect_icon.c b/src/inspect_icon.c index 7d08a00..662edbc 100644 --- a/src/inspect_icon.c +++ b/src/inspect_icon.c @@ -165,6 +165,7 @@ guestfs__inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r, break; case OS_TYPE_FREEBSD: + case OS_TYPE_NETBSD: case OS_TYPE_UNKNOWN: default: ; }