static char *lookup_dev(const char *dev_id) { uint32_t major, minor; dev_t dev; char *result = NULL, buf[PATH_MAX + 1]; if (sscanf(dev_id, "%" PRIu32 ":%" PRIu32, &major, &minor) != 2) return NULL; dev = makedev(major, minor); strncpy(buf, DEVICE_DIR, PATH_MAX); buf[PATH_MAX] = '\0'; /* First try low level device */ if ((result = __lookup_dev(buf, dev, 0, 0))) return result; /* If it is dm, try DM dir */ if (dm_is_dm_major(major)) { strncpy(buf, dm_dir(), PATH_MAX); if ((result = __lookup_dev(buf, dev, 0, 0))) return result; } strncpy(buf, DEVICE_DIR, PATH_MAX); result = __lookup_dev(buf, dev, 0, 4); /* If not found, return NULL */ return result; }
static int grub_util_open_dm (const char *os_dev, struct dm_tree **tree, struct dm_tree_node **node) { uint32_t maj, min; struct stat st; *node = NULL; *tree = NULL; if (stat (os_dev, &st) < 0) return 0; maj = major (st.st_rdev); min = minor (st.st_rdev); if (!dm_is_dm_major (maj)) return 0; *tree = dm_tree_create (); if (! *tree) { grub_puts_ (N_("Failed to create `device-mapper' tree")); grub_dprintf ("hostdisk", "dm_tree_create failed\n"); return 0; } if (! dm_tree_add_dev (*tree, maj, min)) { grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n"); dm_tree_free (*tree); *tree = NULL; return 0; } *node = dm_tree_find_node (*tree, maj, min); if (! *node) { grub_dprintf ("hostdisk", "dm_tree_find_node failed\n"); dm_tree_free (*tree); *tree = NULL; return 0; } return 1; }