From 7c89d9ef6b37314fb55aabd0c389a9d652acdb0f Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 28 Nov 2011 20:40:01 +0000 Subject: [PATCH] inspection: Add outline support for GNU/Hurd. --- generator/generator_actions.ml | 4 ++++ src/guestfs-internal.h | 3 +++ src/inspect.c | 1 + src/inspect_apps.c | 1 + src/inspect_fs.c | 10 ++++++++++ src/inspect_fs_unix.c | 36 ++++++++++++++++++++++++++++++++++++ src/inspect_icon.c | 1 + 7 files changed, 56 insertions(+) diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index d73a999..0e39e2f 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -747,6 +747,10 @@ FreeBSD. NetBSD. +=item \"hurd\" + +GNU/Hurd. + =item \"unknown\" The operating system type could not be determined. diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index d9e1264..4b7cb16 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -256,6 +256,7 @@ enum inspect_fs_content { FS_CONTENT_FREEBSD_ROOT, FS_CONTENT_NETBSD_ROOT, FS_CONTENT_INSTALLER, + FS_CONTENT_HURD_ROOT, }; enum inspect_os_format { @@ -271,6 +272,7 @@ enum inspect_os_type { OS_TYPE_WINDOWS, OS_TYPE_FREEBSD, OS_TYPE_NETBSD, + OS_TYPE_HURD, }; enum inspect_os_distro { @@ -420,6 +422,7 @@ 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___check_hurd_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 f9b8298..a7291da 100644 --- a/src/inspect.c +++ b/src/inspect.c @@ -189,6 +189,7 @@ 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_HURD: ret = safe_strdup (g, "hurd"); 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; diff --git a/src/inspect_apps.c b/src/inspect_apps.c index c6ddd05..18f2ae3 100644 --- a/src/inspect_apps.c +++ b/src/inspect_apps.c @@ -72,6 +72,7 @@ guestfs__inspect_list_applications (guestfs_h *g, const char *root) if (fs->format == OS_FORMAT_INSTALLED) { switch (fs->type) { case OS_TYPE_LINUX: + case OS_TYPE_HURD: switch (fs->package_format) { case OS_PACKAGE_FORMAT_RPM: #ifdef DB_DUMP diff --git a/src/inspect_fs.c b/src/inspect_fs.c index 25bb492..2b8c8e9 100644 --- a/src/inspect_fs.c +++ b/src/inspect_fs.c @@ -207,6 +207,16 @@ check_filesystem (guestfs_h *g, const char *device, if (guestfs___check_netbsd_root (g, fs) == -1) return -1; } + /* Hurd root? */ + 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->content = FS_CONTENT_HURD_ROOT; + fs->format = OS_FORMAT_INSTALLED; /* XXX could be more specific */ + if (guestfs___check_hurd_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 3046e02..340fe6a 100644 --- a/src/inspect_fs_unix.c +++ b/src/inspect_fs_unix.c @@ -533,6 +533,41 @@ guestfs___check_netbsd_root (guestfs_h *g, struct inspect_fs *fs) return 0; } +/* The currently mounted device may be a Hurd root. Hurd has distros + * just like Linux. + */ +int +guestfs___check_hurd_root (guestfs_h *g, struct inspect_fs *fs) +{ + int r; + + fs->type = OS_TYPE_HURD; + + if (guestfs_exists (g, "/etc/debian_version") > 0) { + fs->distro = OS_DISTRO_DEBIAN; + + if (parse_release_file (g, fs, "/etc/debian_version") == -1) + return -1; + + if (guestfs___parse_major_minor (g, fs) == -1) + return -1; + } + + /* Arch Hurd also exists, but inconveniently it doesn't have + * the normal /etc/arch-release file. XXX + */ + + /* Determine the architecture. */ + check_architecture (g, fs); + + /* XXX Check for /etc/fstab. */ + + /* Determine hostname. */ + if (check_hostname_unix (g, fs) == -1) + return -1; + + return 0; +} static void check_architecture (guestfs_h *g, struct inspect_fs *fs) @@ -569,6 +604,7 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs) { switch (fs->type) { case OS_TYPE_LINUX: + case OS_TYPE_HURD: /* Red Hat-derived would be in /etc/sysconfig/network, and * Debian-derived in the file /etc/hostname. Very old Debian and * SUSE use /etc/HOSTNAME. It's best to just look for each of diff --git a/src/inspect_icon.c b/src/inspect_icon.c index 662edbc..ee74bf6 100644 --- a/src/inspect_icon.c +++ b/src/inspect_icon.c @@ -113,6 +113,7 @@ guestfs__inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r, */ switch (fs->type) { case OS_TYPE_LINUX: + case OS_TYPE_HURD: switch (fs->distro) { case OS_DISTRO_FEDORA: r = icon_fedora (g, fs, &size); -- 1.8.3.1