9 static char *mount_base;
15 #define DEVICE_MAP_SIZE 32
16 static struct device_map device_map[DEVICE_MAP_SIZE];
18 const char *mountpoint_for_device(const char *dev_path)
23 /* shorten '/dev/foo' to 'foo' */
24 basename = strrchr(dev_path, '/');
30 /* check existing entries in the map */
31 for (i = 0; (i < DEVICE_MAP_SIZE) && device_map[i].dev; i++)
32 if (!strcmp(device_map[i].dev, basename))
33 return device_map[i].mnt;
35 if (i == DEVICE_MAP_SIZE)
38 device_map[i].dev = strdup(dev_path);
39 asprintf(&device_map[i].mnt, "%s/%s", mount_base, basename);
40 return device_map[i].mnt;
43 char *resolve_path(const char *path, const char *current_mountpoint)
46 const char *devpath, *sep;
48 sep = strchr(path, ':');
50 devpath = current_mountpoint;
51 asprintf(&ret, "%s/%s", devpath, path);
53 /* copy just the device name into tmp */
54 char *dev = strndup(path, sep - path);
55 devpath = mountpoint_for_device(dev);
56 asprintf(&ret, "%s/%s", devpath, sep + 1);
63 void set_mount_base(const char *path)
67 mount_base = strdup(path);