X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Finspect_fs_unix.c;h=6b1a05baabb2f48d194e3244e7666684e59c3c70;hb=c81a16a4e2e703d0aaa595151602bcf03430f6ab;hp=34e65bf699771cb508c5ef23733aff4c40d71240;hpb=1f615fddaffd33afc75a582021769583c8f4db4e;p=libguestfs.git diff --git a/src/inspect_fs_unix.c b/src/inspect_fs_unix.c index 34e65bf..6b1a05b 100644 --- a/src/inspect_fs_unix.c +++ b/src/inspect_fs_unix.c @@ -64,6 +64,7 @@ static pcre *re_scientific_linux_no_minor; static pcre *re_major_minor; static pcre *re_aug_seq; static pcre *re_xdev; +static pcre *re_cciss; static pcre *re_first_partition; static pcre *re_freebsd; static pcre *re_netbsd; @@ -107,7 +108,8 @@ compile_regexps (void) "Scientific Linux.*release (\\d+)", 0); COMPILE (re_major_minor, "(\\d+)\\.(\\d+)", 0); COMPILE (re_aug_seq, "/\\d+$", 0); - COMPILE (re_xdev, "^/dev/(?:h|s|v|xv)d([a-z]+)(\\d*)$", 0); + 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_freebsd, "^/dev/ad(\\d+)s(\\d+)([a-z])$", 0); COMPILE (re_netbsd, "^NetBSD (\\d+)\\.(\\d+)", 0); } @@ -128,6 +130,7 @@ free_regexps (void) pcre_free (re_major_minor); pcre_free (re_aug_seq); pcre_free (re_xdev); + pcre_free (re_cciss); pcre_free (re_freebsd); pcre_free (re_netbsd); } @@ -817,7 +820,7 @@ static char * resolve_fstab_device (guestfs_h *g, const char *spec) { char *device = NULL; - char *slice, *disk, *part; + char *type, *slice, *disk, *part; if (STRPREFIX (spec, "/dev/mapper/")) { /* LVM2 does some strange munging on /dev/mapper paths for VGs and @@ -832,33 +835,79 @@ resolve_fstab_device (guestfs_h *g, const char *spec) */ device = guestfs_lvm_canonical_lv_name (g, spec); } - else if (match2 (g, spec, re_xdev, &disk, &part)) { - /* disk: ([a-z]+) + else if (match3 (g, spec, re_xdev, &type, &disk, &part)) { + /* type: (h|s|v|xv) + * disk: ([a-z]+) * part: (\d*) */ char **devices = guestfs_list_devices (g); if (devices == NULL) return NULL; - /* Count how many disks the libguestfs appliance has */ - size_t count; - for (count = 0; devices[count] != NULL; count++) - ; + /* Check any hints we were passed for a non-heuristic mapping */ + char *name = safe_asprintf (g, "%sd%s", type, disk); + size_t i = 0; + struct drive *drive = g->drives; + while (drive) { + if (drive->name && STREQ(drive->name, name)) { + device = safe_asprintf (g, "%s%s", devices[i], part); + break; + } - /* Calculate the numerical index of the disk */ - size_t i = disk[0] - 'a'; - for (char *p = disk + 1; *p != '\0'; p++) { - i += 1; i *= 26; - i += *p - 'a'; + i++; drive = drive->next; } + free (name); + + /* Guess the appliance device name if we didn't find a matching hint */ + if (!device) { + /* Count how many disks the libguestfs appliance has */ + size_t count; + for (count = 0; devices[count] != NULL; count++) + ; + + /* Calculate the numerical index of the disk */ + i = disk[0] - 'a'; + for (char *p = disk + 1; *p != '\0'; p++) { + i += 1; i *= 26; + i += *p - 'a'; + } - /* Check the index makes sense wrt the number of disks the appliance has. - * If it does, map it to an appliance disk. */ - if (i < count) { - size_t len = strlen (devices[i]) + strlen (part) + 1; - device = safe_malloc (g, len); - snprintf (device, len, "%s%s", devices[i], part); + /* Check the index makes sense wrt the number of disks the appliance has. + * If it does, map it to an appliance disk. */ + if (i < count) { + device = safe_asprintf (g, "%s%s", devices[i], part); + } } + free (type); + free (disk); + free (part); + guestfs___free_string_list (devices); + } + else if (match2 (g, spec, re_cciss, &disk, &part)) { + /* disk: (cciss/c\d+d\d+) + * part: (\d+)? */ + char **devices = guestfs_list_devices (g); + if (devices == NULL) + return NULL; + + /* Check any hints we were passed for a non-heuristic mapping */ + size_t i = 0; + struct drive *drive = g->drives; + while (drive) { + if (drive->name && STREQ(drive->name, disk)) { + if (part) { + device = safe_asprintf (g, "%s%s", devices[i], part); + } else { + device = safe_strdup (g, devices[i]); + } + break; + } + + i++; drive = drive->next; + } + + /* We don't try to guess mappings for cciss devices */ + free (disk); free (part); guestfs___free_string_list (devices);