[PATCH 1/4] inspect_os: Add support for detecting OpenBSD
by Nikos Skalkotos
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
src/guestfs-internal.h | 1 +
src/inspect-fs-unix.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++--
src/inspect-fs.c | 12 ++++++
3 files changed, 116 insertions(+), 3 deletions(-)
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 33d28f5..c8dd084 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -782,6 +782,7 @@ extern void guestfs___check_package_management (guestfs_h *g, struct inspect_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_openbsd_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs___check_hurd_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs___check_minix_root (guestfs_h *g, struct inspect_fs *fs);
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index f55e53b..ab76bc6 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -80,6 +80,9 @@ COMPILE_REGEXP (re_sles_version, "^VERSION = (\\d+)", 0)
COMPILE_REGEXP (re_sles_patchlevel, "^PATCHLEVEL = (\\d+)", 0)
COMPILE_REGEXP (re_minix, "^(\\d+)\\.(\\d+)(\\.(\\d+))?", 0)
COMPILE_REGEXP (re_hurd_dev, "^/dev/(h)d(\\d+)s(\\d+)$", 0)
+COMPILE_REGEXP (re_openbsd, "^OpenBSD (\\d+|\\?)\\.(\\d+|\\?)", 0)
+COMPILE_REGEXP (re_openbsd_duid, "^[0-9a-f]{16}\\.[a-z]", 0)
+COMPILE_REGEXP (re_openbsd_dev, "^/dev/(s|w)d([0-9])([a-z])$", 0)
static void check_architecture (guestfs_h *g, struct inspect_fs *fs);
static int check_hostname_unix (guestfs_h *g, struct inspect_fs *fs);
@@ -659,6 +662,55 @@ guestfs___check_netbsd_root (guestfs_h *g, struct inspect_fs *fs)
return 0;
}
+/* The currently mounted device may be an OpenBSD root. */
+int
+guestfs___check_openbsd_root (guestfs_h *g, struct inspect_fs *fs)
+{
+ if (guestfs_is_file_opts (g, "/etc/motd",
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ CLEANUP_FREE char *major = NULL, *minor = NULL;
+
+ /* The first line of this file gets automatically updated at boot. */
+ if (parse_release_file (g, fs, "/etc/motd") == -1)
+ return -1;
+
+ if (match2 (g, fs->product_name, re_openbsd, &major, &minor)) {
+ fs->type = OS_TYPE_OPENBSD;
+ fs->distro = OS_DISTRO_OPENBSD;
+
+ /* Before the first boot, the first line will look like this:
+ *
+ * OpenBSD ?.? (UNKNOWN)
+ */
+ if ((fs->product_name[8] != '?') && (fs->product_name[10] != '?')) {
+ fs->major_version = guestfs___parse_unsigned_int (g, major);
+ if (fs->major_version == -1)
+ return -1;
+
+ fs->minor_version = guestfs___parse_unsigned_int (g, 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. */
+ const char *configfiles[] = { "/etc/fstab", NULL };
+ if (inspect_with_augeas (g, fs, configfiles, check_fstab) == -1)
+ return -1;
+
+ /* Determine hostname. */
+ if (check_hostname_unix (g, fs) == -1)
+ return -1;
+
+ return 0;
+}
+
/* The currently mounted device may be a Hurd root. Hurd has distros
* just like Linux.
*/
@@ -821,6 +873,18 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs)
}
break;
+ case OS_TYPE_OPENBSD:
+ if (guestfs_is_file (g, "/etc/myname")) {
+ fs->hostname = guestfs___first_line_of_file (g, "/etc/myname");
+ if (fs->hostname == NULL)
+ return -1;
+ if (STREQ (fs->hostname, "")) {
+ free (fs->hostname);
+ fs->hostname = NULL;
+ }
+ }
+ break;
+
case OS_TYPE_MINIX:
if (guestfs_is_file (g, "/etc/hostname.file")) {
fs->hostname = guestfs___first_line_of_file (g, "/etc/hostname.file");
@@ -835,7 +899,6 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs)
case OS_TYPE_WINDOWS: /* not here, see check_windows_system_registry */
case OS_TYPE_DOS:
- case OS_TYPE_OPENBSD:
case OS_TYPE_UNKNOWN:
/* nothing */;
}
@@ -921,6 +984,9 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
char **entry;
char augpath[256];
CLEANUP_HASH_FREE Hash_table *md_map = NULL;
+ bool is_bsd = (fs->type == OS_TYPE_FREEBSD ||
+ fs->type == OS_TYPE_NETBSD ||
+ fs->type == OS_TYPE_OPENBSD);
/* Generate a map of MD device paths listed in /etc/mdadm.conf to MD device
* paths in the guestfs appliance */
@@ -975,12 +1041,31 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
else if (STRPREFIX (spec, "LABEL="))
mountable = guestfs_findfs_label (g, &spec[6]);
/* Ignore "/.swap" (Pardus) and pseudo-devices like "tmpfs". */
- else if (STREQ (spec, "/dev/root"))
- /* Resolve /dev/root to the current device. */
+ else if (STREQ (spec, "/dev/root") || (is_bsd && STREQ (mp, "/")))
+ /* Resolve /dev/root to the current device.
+ * Do the same for the / partition of the *BSD systems, since the
+ * BSD -> Linux device translation is not straight forward.
+ */
mountable = safe_strdup (g, fs->mountable);
else if (STRPREFIX (spec, "/dev/"))
/* Resolve guest block device names. */
mountable = resolve_fstab_device (g, spec, md_map);
+ else if (match (g, spec, re_openbsd_duid)) {
+ /* In OpenBSD's fstab you can specify partitions on a disk by appending a
+ * period and a partition letter to a Disklable Unique Identifier. The
+ * DUID is a 16 hex digit field found in the OpenBSD's altered BSD
+ * disklabel. For more info see here:
+ * http://www.openbsd.org/faq/faq14.html#intro
+ */
+ char device[10]; /* /dev/sd[0-9][a-z] */
+ char part = spec[17];
+
+ /* We cannot peep into disklables, we can only assume that this is the
+ * first disk.
+ */
+ snprintf(device, 10, "%s%c", "/dev/sd0", part);
+ mountable = resolve_fstab_device (g, device, md_map);
+ }
/* If we haven't resolved the device successfully by this point,
* we don't care, just ignore it.
@@ -1542,6 +1627,21 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map)
device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
}
}
+ else if (match3 (g, spec, re_openbsd_dev, &type, &disk, &part)) {
+ int disk_i = guestfs___parse_unsigned_int (g, disk);
+ int part_i = part[0] - 'a'; /* counting from 0 */
+ free (type);
+ free (disk);
+ free (part);
+
+ if (part_i > 2)
+ /* Partition 'c' is the hard disk itself. Not mapped under Linux */
+ part_i -= 1;
+
+ /* In OpenBSD MAXPARTITIONS is defined to 16 for all architectures */
+ if (disk_i != -1 && part_i >= 0 && part_i < 15)
+ device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
+ }
else if ((part = match1 (g, spec, re_diskbyid)) != NULL) {
r = resolve_fstab_device_diskbyid (g, part, &device);
free (part);
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index fe82132..aaddb49 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -177,6 +177,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
if (guestfs___check_freebsd_root (g, fs) == -1)
return -1;
}
+ /* NetBSD root? */
else if (is_dir_etc &&
is_dir_bin &&
guestfs_is_file (g, "/netbsd") > 0 &&
@@ -187,6 +188,17 @@ check_filesystem (guestfs_h *g, const char *mountable,
if (guestfs___check_netbsd_root (g, fs) == -1)
return -1;
}
+ /* OpenBSD root? */
+ else if (is_dir_etc &&
+ is_dir_bin &&
+ 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->format = OS_FORMAT_INSTALLED;
+ if (guestfs___check_openbsd_root (g, fs) == -1)
+ return -1;
+ }
/* Hurd root? */
else if (guestfs_is_file (g, "/hurd/console") > 0 &&
guestfs_is_file (g, "/hurd/hello") > 0 &&
--
2.1.3
9 years, 9 months
[PATCH v2] v2v: When picking a default kernel, favour non-debug kernels over debug kernels (RHBZ#1170073).
by Richard W.M. Jones
---
v2v/convert_linux.ml | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index f670812..39a520c 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -49,13 +49,14 @@ type kernel_info = {
ki_modules : string list; (* The list of module names. *)
ki_supports_virtio : bool; (* Kernel has virtio drivers? *)
ki_is_xen_kernel : bool; (* Is a Xen paravirt kernel? *)
+ ki_is_debug : bool; (* Is debug kernel? *)
}
let string_of_kernel_info ki =
- sprintf "(%s, %s, %s, %s, %s, virtio=%b, xen=%b)"
+ sprintf "(%s, %s, %s, %s, %s, virtio=%b, xen=%b, debug=%b)"
ki.ki_name ki.ki_version ki.ki_arch ki.ki_vmlinuz
(match ki.ki_initrd with None -> "None" | Some f -> f)
- ki.ki_supports_virtio ki.ki_is_xen_kernel
+ ki.ki_supports_virtio ki.ki_is_xen_kernel ki.ki_is_debug
(* The conversion function. *)
let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
@@ -241,6 +242,11 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
let supports_virtio = List.mem "virtio_net" modules in
let is_xen_kernel = List.mem "xennet" modules in
+ (* If the package name is like "kernel-debug", then it's
+ * a debug kernel.
+ *)
+ let is_debug = string_find app.G.app2_name "debug" >= 0 in
+
Some {
ki_app = app;
ki_name = name;
@@ -253,6 +259,7 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
ki_modules = modules;
ki_supports_virtio = supports_virtio;
ki_is_xen_kernel = is_xen_kernel;
+ ki_is_debug = is_debug;
}
)
@@ -745,7 +752,12 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
let compare_best_kernels k1 k2 =
let i = compare k1.ki_supports_virtio k2.ki_supports_virtio in
if i <> 0 then i
- else compare_app2_versions k1.ki_app k2.ki_app
+ else (
+ let i = compare_app2_versions k1.ki_app k2.ki_app in
+ if i <> 0 then i
+ (* Favour non-debug kernels over debug kernels (RHBZ#1170073). *)
+ else compare k2.ki_is_debug k1.ki_is_debug
+ )
in
let kernels = grub_kernels in
let kernels = List.filter (fun { ki_is_xen_kernel = is_xen_kernel } -> not is_xen_kernel) kernels in
--
2.1.0
9 years, 9 months
[PATCH 0/4] fix bad commit ids referenced in commit messages
by Hu Tao
Hi,
This series fix two bad commit ids referenced in commit messages, by
first reverting the two commits and then re-applying them with correct
commit ids referenced. No big problem, but for clarity.
Hu Tao (4):
Revert "Update gobject/Makefile.inc and POTFILES"
Revert "Update gobject/Makefile.inc and POTFILES"
Update gobject/Makefile.inc and POTFILES
Update gobject/Makefile.inc and POTFILES
--
1.9.3
9 years, 9 months
'make rpm' target for libguestfs?
by Kashyap Chamarthy
The libvirt project has a convenient RPM target for `make`, and
sometimes I wished there was such a target for libguestfs, too.
Though, most of my needs of testing from libguestfs git are satisfied
via the useful './run' script, thought I'd check here on the list. :-)
--
/kashyap
9 years, 9 months
[PATCH] v2v: When picking a default kernel, favour non-debug kernels over debug kernels (RHBZ#1170073).
by Richard W.M. Jones
---
v2v/convert_linux.ml | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index f670812..420aba5 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -49,13 +49,14 @@ type kernel_info = {
ki_modules : string list; (* The list of module names. *)
ki_supports_virtio : bool; (* Kernel has virtio drivers? *)
ki_is_xen_kernel : bool; (* Is a Xen paravirt kernel? *)
+ ki_is_debug : bool; (* Is debug kernel? *)
}
let string_of_kernel_info ki =
- sprintf "(%s, %s, %s, %s, %s, virtio=%b, xen=%b)"
+ sprintf "(%s, %s, %s, %s, %s, virtio=%b, xen=%b, debug=%b)"
ki.ki_name ki.ki_version ki.ki_arch ki.ki_vmlinuz
(match ki.ki_initrd with None -> "None" | Some f -> f)
- ki.ki_supports_virtio ki.ki_is_xen_kernel
+ ki.ki_supports_virtio ki.ki_is_xen_kernel ki.ki_is_debug
(* The conversion function. *)
let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
@@ -241,6 +242,11 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
let supports_virtio = List.mem "virtio_net" modules in
let is_xen_kernel = List.mem "xennet" modules in
+ (* If the package name is like "kernel-debug", then it's
+ * a debug kernel.
+ *)
+ let is_debug = string_find app.G.app2_name "debug" >= 0 in
+
Some {
ki_app = app;
ki_name = name;
@@ -253,6 +259,7 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
ki_modules = modules;
ki_supports_virtio = supports_virtio;
ki_is_xen_kernel = is_xen_kernel;
+ ki_is_debug = is_debug;
}
)
@@ -745,7 +752,12 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
let compare_best_kernels k1 k2 =
let i = compare k1.ki_supports_virtio k2.ki_supports_virtio in
if i <> 0 then i
- else compare_app2_versions k1.ki_app k2.ki_app
+ else (
+ let i = compare_app2_versions k1.ki_app k2.ki_app in
+ if i <> 0 then i
+ (* Favour non-debug kernels over debug kernels (RHBZ#1170073). *)
+ else compare k2.ki_is_debug k1.ki_is_debug in
+ )
in
let kernels = grub_kernels in
let kernels = List.filter (fun { ki_is_xen_kernel = is_xen_kernel } -> not is_xen_kernel) kernels in
--
2.1.0
9 years, 9 months
[PATCH] v2v: Disable autoreboot when converting Windows guests.
by Richard W.M. Jones
This allows users to see stop errors, so we can get an accurate report
when things go wrong.
---
v2v/convert_windows.ml | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index e37c6b8..c8db860 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -191,6 +191,7 @@ echo uninstalling Xen PV driver
if verbose then printf "current ControlSet is %s\n%!" current_cs;
disable_services root current_cs;
+ disable_autoreboot root current_cs;
install_virtio_drivers root current_cs
and disable_services root current_cs =
@@ -212,6 +213,17 @@ echo uninstalling Xen PV driver
)
) disable
+ and disable_autoreboot root current_cs =
+ (* If the guest reboots after a crash, it's hard to see the original
+ * error (eg. the infamous 0x0000007B). Turn off autoreboot.
+ *)
+ try
+ let crash_control =
+ get_node root [current_cs; "Control"; "CrashControl"] in
+ g#hivex_node_set_value crash_control "AutoReboot" 4_L (le32_of_int 0_L)
+ with
+ Not_found -> ()
+
and install_virtio_drivers root current_cs =
(* Copy the virtio drivers to the guest. *)
let driverdir = sprintf "%s/Drivers/VirtIO" systemroot in
--
2.1.0
9 years, 9 months
[PATCH 4/4] Add freebsd and netbsd distros
by Nikos Skalkotos
Prior to this commit the distro for a FreeBSD or a NetBSD system, in
conjuction to what happened for OpenBSD, was shown as 'unknown'.
*BSDs are complete OSes, not a kernel like Linux, but theoritically you
could have FreeBSD as ostype and PC-BSD as distro.
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
generator/actions.ml | 8 ++++++++
src/guestfs-internal.h | 2 ++
src/inspect-fs-unix.c | 2 ++
src/inspect-fs.c | 4 ++++
src/inspect-icon.c | 2 ++
src/inspect.c | 2 ++
src/osinfo.c | 4 ++++
7 files changed, 24 insertions(+)
diff --git a/generator/actions.ml b/generator/actions.ml
index 385b620..d4ec0b1 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -1065,6 +1065,10 @@ Debian.
Fedora.
+=item \"freebsd\"
+
+FreeBSD.
+
=item \"freedos\"
FreeDOS.
@@ -1089,6 +1093,10 @@ Mandriva.
MeeGo.
+=item \"netbsd\"
+
+NetBSD.
+
=item \"openbsd\"
OpenBSD.
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index c8dd084..0a4a6f2 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -543,6 +543,8 @@ enum inspect_os_distro {
OS_DISTRO_SLES,
OS_DISTRO_OPENBSD,
OS_DISTRO_ORACLE_LINUX,
+ OS_DISTRO_FREEBSD,
+ OS_DISTRO_NETBSD,
};
enum inspect_os_package_format {
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index b3c813d..750c27b 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -591,6 +591,7 @@ int
guestfs___check_freebsd_root (guestfs_h *g, struct inspect_fs *fs)
{
fs->type = OS_TYPE_FREEBSD;
+ fs->distro = OS_DISTRO_FREEBSD;
/* FreeBSD has no authoritative version file. The version number is
* in /etc/motd, which the system administrator might edit, but
@@ -634,6 +635,7 @@ guestfs___check_netbsd_root (guestfs_h *g, struct inspect_fs *fs)
if (match2 (g, fs->product_name, re_netbsd, &major, &minor)) {
fs->type = OS_TYPE_NETBSD;
+ fs->distro = OS_DISTRO_NETBSD;
fs->major_version = guestfs___parse_unsigned_int (g, major);
free (major);
if (fs->major_version == -1) {
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index aaddb49..e9cc2e9 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -448,6 +448,8 @@ guestfs___check_package_format (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_BUILDROOT:
case OS_DISTRO_CIRROS:
case OS_DISTRO_FREEDOS:
+ case OS_DISTRO_FREEBSD:
+ case OS_DISTRO_NETBSD:
case OS_DISTRO_OPENBSD:
case OS_DISTRO_UNKNOWN:
fs->package_format = OS_PACKAGE_FORMAT_UNKNOWN;
@@ -507,6 +509,8 @@ guestfs___check_package_management (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_BUILDROOT:
case OS_DISTRO_CIRROS:
case OS_DISTRO_FREEDOS:
+ case OS_DISTRO_FREEBSD:
+ case OS_DISTRO_NETBSD:
case OS_DISTRO_OPENBSD:
case OS_DISTRO_UNKNOWN:
fs->package_management = OS_PACKAGE_MANAGEMENT_UNKNOWN;
diff --git a/src/inspect-icon.c b/src/inspect-icon.c
index b1b3adf..a7318c6 100644
--- a/src/inspect-icon.c
+++ b/src/inspect-icon.c
@@ -178,6 +178,8 @@ guestfs__inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r,
case OS_DISTRO_SLACKWARE:
case OS_DISTRO_TTYLINUX:
case OS_DISTRO_WINDOWS:
+ case OS_DISTRO_FREEBSD:
+ case OS_DISTRO_NETBSD:
case OS_DISTRO_OPENBSD:
case OS_DISTRO_UNKNOWN:
; /* nothing */
diff --git a/src/inspect.c b/src/inspect.c
index c3b88e1..bdb45c3 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -203,12 +203,14 @@ guestfs__inspect_get_distro (guestfs_h *g, const char *root)
case OS_DISTRO_CIRROS: ret = safe_strdup (g, "cirros"); break;
case OS_DISTRO_DEBIAN: ret = safe_strdup (g, "debian"); break;
case OS_DISTRO_FEDORA: ret = safe_strdup (g, "fedora"); break;
+ case OS_DISTRO_FREEBSD: ret = safe_strdup (g, "freebsd"); break;
case OS_DISTRO_FREEDOS: ret = safe_strdup (g, "freedos"); break;
case OS_DISTRO_GENTOO: ret = safe_strdup (g, "gentoo"); break;
case OS_DISTRO_LINUX_MINT: ret = safe_strdup (g, "linuxmint"); break;
case OS_DISTRO_MAGEIA: ret = safe_strdup (g, "mageia"); break;
case OS_DISTRO_MANDRIVA: ret = safe_strdup (g, "mandriva"); break;
case OS_DISTRO_MEEGO: ret = safe_strdup (g, "meego"); break;
+ case OS_DISTRO_NETBSD: ret = safe_strdup (g, "netbsd"); break;
case OS_DISTRO_OPENBSD: ret = safe_strdup (g, "openbsd"); break;
case OS_DISTRO_OPENSUSE: ret = safe_strdup (g, "opensuse"); break;
case OS_DISTRO_ORACLE_LINUX: ret = safe_strdup (g, "oraclelinux"); break;
diff --git a/src/osinfo.c b/src/osinfo.c
index 3a6d342..aee3b8f 100644
--- a/src/osinfo.c
+++ b/src/osinfo.c
@@ -498,8 +498,12 @@ parse_distro (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo)
osinfo->distro = OS_DISTRO_DEBIAN;
else if (STREQ (content, "fedora"))
osinfo->distro = OS_DISTRO_FEDORA;
+ else if (STREQ (content, "freebsd"))
+ osinfo->distro = OS_DISTRO_FREEBSD;
else if (STREQ (content, "mandriva"))
osinfo->distro = OS_DISTRO_MANDRIVA;
+ else if (STREQ (content, "netbsd"))
+ osinfo->distro = OS_DISTRO_NETBSD;
else if (STREQ (content, "openbsd"))
osinfo->distro = OS_DISTRO_OPENBSD;
else if (STREQ (content, "opensuse"))
--
2.1.3
9 years, 9 months
[PATCH 3/4] Fix fstab block device resolution for FreeBSD
by Nikos Skalkotos
Take into granted that partition 'c' has a special purpose. It has
always the same size as the enclosing slice and is not mapped under
Linux.
This is a best effort try. The mapping will be incorrect if there is a
gap in the disklabel partitions sequence, e.g. 'b' (swap) partition is
missing but 'd' partition is defined.
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
src/inspect-fs-unix.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 18be68b..b3c813d 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -1624,9 +1624,13 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map,
free (slice);
free (part);
+ if (part_i > 2)
+ /* Partition 'c' has the size of the enclosing slice. Not mapped under Linux. */
+ part_i -= 1;
+
if (disk_i != -1 && disk_i <= 26 &&
slice_i > 0 && slice_i <= 1 /* > 4 .. see comment above */ &&
- part_i >= 0 && part_i < 26) {
+ part_i >= 0 && part_i < 25) {
device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
}
}
--
2.1.3
9 years, 9 months
[PATCH 2/4] Support fstab block device resolution for NetBSD
by Nikos Skalkotos
Make a best effort try to map NetBSD disklabel partitions to Linux
partitions. The mapping will be incorrect if there is a gap in the
disklabel partitions sequence, e.g. 'b' (swap) partition is missing but
'e' partition is defined.
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
src/inspect-fs-unix.c | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index ab76bc6..18be68b 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -83,6 +83,7 @@ COMPILE_REGEXP (re_hurd_dev, "^/dev/(h)d(\\d+)s(\\d+)$", 0)
COMPILE_REGEXP (re_openbsd, "^OpenBSD (\\d+|\\?)\\.(\\d+|\\?)", 0)
COMPILE_REGEXP (re_openbsd_duid, "^[0-9a-f]{16}\\.[a-z]", 0)
COMPILE_REGEXP (re_openbsd_dev, "^/dev/(s|w)d([0-9])([a-z])$", 0)
+COMPILE_REGEXP (re_netbsd_dev, "^/dev/(l|s)d([0-9])([a-z])$", 0)
static void check_architecture (guestfs_h *g, struct inspect_fs *fs);
static int check_hostname_unix (guestfs_h *g, struct inspect_fs *fs);
@@ -92,7 +93,8 @@ static int check_fstab (guestfs_h *g, struct inspect_fs *fs);
static int add_fstab_entry (guestfs_h *g, struct inspect_fs *fs,
const char *mountable, const char *mp);
static char *resolve_fstab_device (guestfs_h *g, const char *spec,
- Hash_table *md_map);
+ Hash_table *md_map,
+ enum inspect_os_type os_type);
static int inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs, const char **configfiles, int (*f) (guestfs_h *, struct inspect_fs *));
static int is_partition (guestfs_h *g, const char *partition);
@@ -1049,7 +1051,7 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
mountable = safe_strdup (g, fs->mountable);
else if (STRPREFIX (spec, "/dev/"))
/* Resolve guest block device names. */
- mountable = resolve_fstab_device (g, spec, md_map);
+ mountable = resolve_fstab_device (g, spec, md_map, fs->type);
else if (match (g, spec, re_openbsd_duid)) {
/* In OpenBSD's fstab you can specify partitions on a disk by appending a
* period and a partition letter to a Disklable Unique Identifier. The
@@ -1064,7 +1066,7 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
* first disk.
*/
snprintf(device, 10, "%s%c", "/dev/sd0", part);
- mountable = resolve_fstab_device (g, device, md_map);
+ mountable = resolve_fstab_device (g, device, md_map, fs->type);
}
/* If we haven't resolved the device successfully by this point,
@@ -1548,7 +1550,8 @@ resolve_fstab_device_diskbyid (guestfs_h *g, const char *part,
* anything we don't recognize unchanged.
*/
static char *
-resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map)
+resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map,
+ enum inspect_os_type os_type)
{
char *device = NULL;
char *type, *slice, *disk, *part;
@@ -1627,7 +1630,25 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map)
device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
}
}
- else if (match3 (g, spec, re_openbsd_dev, &type, &disk, &part)) {
+ else if ((os_type == OS_TYPE_NETBSD) &&
+ match3 (g, spec, re_netbsd_dev, &type, &disk, &part)) {
+ int disk_i = guestfs___parse_unsigned_int (g, disk);
+ int part_i = part[0] - 'a'; /* counting from 0 */
+ free (type);
+ free (disk);
+ free (part);
+
+ if (part_i > 3)
+ /* Partition 'c' is the disklabel partition and 'd' the hard disk itself.
+ * Not mapped under Linux.
+ */
+ part_i -= 2;
+
+ if (disk_i != -1 && part_i >= 0 && part_i < 24)
+ device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
+ }
+ else if ((os_type == OS_TYPE_OPENBSD) &&
+ match3 (g, spec, re_openbsd_dev, &type, &disk, &part)) {
int disk_i = guestfs___parse_unsigned_int (g, disk);
int part_i = part[0] - 'a'; /* counting from 0 */
free (type);
--
2.1.3
9 years, 9 months