libvirt_parthelper_SOURCES = $(STORAGE_HELPER_DISK_SOURCES)
libvirt_parthelper_LDFLAGS = $(WARN_LDFLAGS) $(COVERAGE_LDFLAGS)
-libvirt_parthelper_LDADD = $(LIBPARTED_LIBS) ../gnulib/lib/libgnu.la
-libvirt_parthelper_CFLAGS = $(LIBPARTED_CFLAGS)
+libvirt_parthelper_LDADD = \
+ $(LIBPARTED_LIBS) \
+ $(DEVMAPPER_LIBS) \
+ libvirt_util.la \
+ ../gnulib/lib/libgnu.la
+
+libvirt_parthelper_CFLAGS = $(LIBPARTED_CFLAGS) $(DEVMAPPER_CFLAGS)
endif
endif
EXTRA_DIST += $(STORAGE_HELPER_DISK_SOURCES)
#include <parted/parted.h>
#include <stdio.h>
#include <string.h>
+#include <libdevmapper.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include "util.h"
#include "c-ctype.h"
/* we don't need to include the full internal.h just for this */
DISK_GEOMETRY
};
+static int
+is_dm_device(const char *devname)
+{
+ struct stat buf;
+
+ if (devname && !stat(devname, &buf) && dm_is_dm_major(major(buf.st_rdev))) {
+ return 1;
+ }
+
+ return 0;
+}
+
int main(int argc, char **argv)
{
PedDevice *dev;
PedPartition *part;
int cmd = DISK_LAYOUT;
const char *path;
+ char *canonical_path;
const char *partsep;
if (argc == 3 && STREQ(argv[2], "-g")) {
}
path = argv[1];
- partsep = *path && c_isdigit(path[strlen(path)-1]) ? "p" : "";
+ if (is_dm_device(path)) {
+ partsep = "p";
+ canonical_path = strdup(path);
+ if (canonical_path == NULL) {
+ return 2;
+ }
+ } else {
+ if (virFileResolveLink(path, &canonical_path) != 0) {
+ return 2;
+ }
+
+ partsep = *canonical_path &&
+ c_isdigit(canonical_path[strlen(canonical_path)-1]) ? "p" : "";
+ }
if ((dev = ped_device_get(path)) == NULL) {
fprintf(stderr, "unable to access device %s\n", path);
*/
if (part->num != -1) {
printf("%s%s%d%c%s%c%s%c%llu%c%llu%c%llu%c",
- path, partsep,
+ canonical_path, partsep,
part->num, '\0',
type, '\0',
content, '\0',