+ 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;
+
+ /* 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';
+ }
+
+ /* 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+)? */