-
- /* create a unique mountpoint */
- dir = malloc(strlen(TMP_DIR) + 13 + strlen(basename));
- sprintf(dir, "%s/mnt-%s-XXXXXX", TMP_DIR, basename);
-
- if (!mkdtemp(dir)) {
- pb_log("failed to create temporary directory in %s: %s",
- TMP_DIR, strerror(errno));
- goto out;
+
+ /* check existing entries in the map */
+ for (i = 0; (i < DEVICE_MAP_SIZE) && device_map[i].dev; i++)
+ if (!strcmp(device_map[i].dev, basename))
+ return device_map[i].mnt;
+
+ if (i == DEVICE_MAP_SIZE)
+ return NULL;
+
+ device_map[i].dev = strdup(dev_path);
+ asprintf(&device_map[i].mnt, "%s/%s", TMP_DIR, basename);
+ return device_map[i].mnt;
+}
+
+/**
+ * Resolve a path given in a config file, to a path in the local filesystem.
+ * Paths may be of the form:
+ * device:path (eg /dev/sda:/boot/vmlinux)
+ *
+ * or just a path:
+ * /boot/vmlinux
+ * - in this case, the default mountpoint is used.
+ *
+ * Returns a newly-allocated string containing a full path to the file in path
+ */
+char *resolve_path(const char *path, const char *default_mountpoint)
+{
+ char *ret;
+ const char *devpath, *sep;
+
+ sep = strchr(path, ':');
+ if (!sep) {
+ devpath = default_mountpoint;
+ asprintf(&ret, "%s/%s", devpath, path);
+ } else {
+ /* copy just the device name into tmp */
+ char *dev = strndup(path, sep - path);
+ devpath = mountpoint_for_device(dev);
+ asprintf(&ret, "%s/%s", devpath, sep + 1);
+ free(dev);