+
+ return -ENOENT;
+}
+
+int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,
+ struct disk_partition *info)
+{
+ return part_get_info_by_name_type(dev_desc, name, info, PART_TYPE_ALL);
+}
+
+/**
+ * Get partition info from device number and partition name.
+ *
+ * Parse a device number and partition name string in the form of
+ * "devicenum.hwpartnum#partition_name", for example "0.1#misc". devicenum and
+ * hwpartnum are both optional, defaulting to 0. If the partition is found,
+ * sets dev_desc and part_info accordingly with the information of the
+ * partition with the given partition_name.
+ *
+ * @param[in] dev_iface Device interface
+ * @param[in] dev_part_str Input string argument, like "0.1#misc"
+ * @param[out] dev_desc Place to store the device description pointer
+ * @param[out] part_info Place to store the partition information
+ * @return 0 on success, or a negative on error
+ */
+static int part_get_info_by_dev_and_name(const char *dev_iface,
+ const char *dev_part_str,
+ struct blk_desc **dev_desc,
+ struct disk_partition *part_info)
+{
+ char *dup_str = NULL;
+ const char *dev_str, *part_str;
+ int ret;
+
+ /* Separate device and partition name specification */
+ part_str = strchr(dev_part_str, '#');
+ if (part_str) {
+ dup_str = strdup(dev_part_str);
+ dup_str[part_str - dev_part_str] = 0;
+ dev_str = dup_str;
+ part_str++;
+ } else {
+ return -EINVAL;
+ }
+
+ ret = blk_get_device_by_str(dev_iface, dev_str, dev_desc);
+ if (ret)
+ goto cleanup;
+
+ ret = part_get_info_by_name(*dev_desc, part_str, part_info);
+ if (ret < 0)
+ printf("Could not find \"%s\" partition\n", part_str);
+
+cleanup:
+ free(dup_str);
+ return ret;
+}
+
+int part_get_info_by_dev_and_name_or_num(const char *dev_iface,
+ const char *dev_part_str,
+ struct blk_desc **dev_desc,
+ struct disk_partition *part_info,
+ int allow_whole_dev)
+{
+ int ret;
+
+ /* Split the part_name if passed as "$dev_num#part_name". */
+ ret = part_get_info_by_dev_and_name(dev_iface, dev_part_str,
+ dev_desc, part_info);
+ if (ret >= 0)
+ return ret;
+ /*
+ * Couldn't lookup by name, try looking up the partition description
+ * directly.
+ */
+ ret = blk_get_device_part_str(dev_iface, dev_part_str,
+ dev_desc, part_info, allow_whole_dev);
+ if (ret < 0)
+ printf("Couldn't find partition %s %s\n",
+ dev_iface, dev_part_str);
+ return ret;