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;
"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);
}
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);
}
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
*/
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;
+ }
+
+ 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';
+ }
- /* 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';
+ /* 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);
+ }
}
- /* 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);
+ 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);
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)
- goto out;
-
- device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
+ 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);
+ }
}
- out:
/* Didn't match device pattern, return original spec unchanged. */
if (device == NULL)
device = safe_strdup (g, spec);