From 1a4fb80232fe50952e5fcd12f6f823490a624658 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 5 Nov 2013 11:40:23 +0000 Subject: [PATCH] FreeBSD: Add (back) support for old guests using /dev/adN convention. --- src/inspect-fs-unix.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c index 8e0f135..02c744e 100644 --- a/src/inspect-fs-unix.c +++ b/src/inspect-fs-unix.c @@ -64,6 +64,7 @@ static pcre *re_major_minor; static pcre *re_xdev; static pcre *re_cciss; static pcre *re_mdN; +static pcre *re_freebsd_old; static pcre *re_freebsd_mbr; static pcre *re_freebsd_gpt; static pcre *re_diskbyid; @@ -116,6 +117,7 @@ compile_regexps (void) COMPILE (re_xdev, "^/dev/(h|s|v|xv)d([a-z]+)(\\d*)$", 0); COMPILE (re_cciss, "^/dev/(cciss/c\\d+d\\d+)(?:p(\\d+))?$", 0); COMPILE (re_mdN, "^(/dev/md\\d+)$", 0); + COMPILE (re_freebsd_old, "^/dev/ad(\\d+)s(\\d+)([a-z])$", 0); COMPILE (re_freebsd_mbr, "^/dev/(ada{0,1}|vtbd)(\\d+)s(\\d+)([a-z])$", 0); COMPILE (re_freebsd_gpt, "^/dev/(ada{0,1}|vtbd)(\\d+)p(\\d+)$", 0); COMPILE (re_diskbyid, "^/dev/disk/by-id/.*-part(\\d+)$", 0); @@ -145,6 +147,7 @@ free_regexps (void) pcre_free (re_xdev); pcre_free (re_cciss); pcre_free (re_mdN); + pcre_free (re_freebsd_old); pcre_free (re_freebsd_mbr); pcre_free (re_freebsd_gpt); pcre_free (re_diskbyid); @@ -1503,6 +1506,20 @@ 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_freebsd_old, &disk, &slice, &part)) { + int disk_i = guestfs___parse_unsigned_int (g, disk); + int slice_i = guestfs___parse_unsigned_int (g, slice); + int part_i = part[0] - 'a' /* counting from 0 */; + free (disk); + free (slice); + free (part); + + if (disk_i != -1 && disk_i <= 26 && + slice_i > 0 && slice_i <= 1 /* > 4 .. see comment above */ && + part_i >= 0 && part_i < 26) { + 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); -- 1.8.3.1