diff -urp lilo-22.8/geometry.c lilo-22.8-alt-devmapper/geometry.c --- lilo-22.8/geometry.c 2013-08-11 01:15:44.000000000 +0300 +++ lilo-22.8-alt-devmapper/geometry.c 2013-08-11 01:41:30.000000000 +0300 @@ -873,18 +873,25 @@ int is_first(int device) } } +#ifdef LCF_DEVMAPPER +static int +is_devmapper_device(int device) +{ + int i; + + for (i = 0; i < dm_major_nr; ++i) + if (MAJOR(device) == dm_major_list[i]) + return 1; + return 0; +} +#endif /* LCF_DEVMAPPER */ void geo_get(GEOMETRY *geo,int device,int user_device,int all) { DT_ENTRY *walk; int inherited,keep_cyls,is_raid=0; #ifdef LCF_DEVMAPPER - int i; - - for(i = 0; i < dm_major_nr; i++) - if (MAJOR(device) == dm_major_list[i]) - break; - while (i < dm_major_nr) { + while (is_devmapper_device(device)) { DM_TABLE *dm_table; for(dm_table = dmtab; dm_table; dm_table = dm_table->next) @@ -898,43 +905,45 @@ void geo_get(GEOMETRY *geo,int device,in for(target = dm_table->target; target; target = target->next) device = target->device; } else { - DEVICE dev; struct dm_task *dmt; - void *next = NULL; - char dmdev[PATH_MAX+1]; - char buf[PATH_MAX+1]; - char *slash; - int result; - - dev_open(&dev, device, -1); - strncpy(dmdev, dev.name, PATH_MAX); - dmdev[PATH_MAX] = 0; + struct dm_names *names = 0; + void *next = NULL; + char dmdev[PATH_MAX + 1]; + char buf[PATH_MAX + 1]; + char *slash = 0; + uint32_t nnext = 0; + + if (!(dmt = dm_task_create(DM_DEVICE_LIST))) + die("device-mapper: dm_task_create(DM_DEVICE_LIST) failed"); + if (!dm_task_run(dmt)) + die("device-mapper: dm_task_run(DM_DEVICE_LIST) failed"); + if (!(names = dm_task_get_names(dmt))) + die("device-mapper: dm_task_get_names() failed"); + if (!names->dev) + die("device-mapper: dm_task_get_names() names->dev"); + do { - memset(buf, 0, PATH_MAX + 1); - if ((result = readlink(dmdev, buf, PATH_MAX)) < 0 && errno != EINVAL) - die("device-mapper: readlink(\"%s\") failed with: %s",buf, - strerror(errno)); - if (result >= 0) { - if (buf[0] != '/' && (slash = strrchr(dmdev, '/')) != NULL) - slash++; - else - slash = dmdev; - strncpy(slash, buf, PATH_MAX - (slash-dmdev)); + names = (void *) names + nnext; + if (verbose > 3) { + printf("device-mapper: device: 0x%llx: name: [%s]\n", + names->dev, names->name); + } + nnext = names->next; + if (names->dev == device) { + strncpy(dmdev, names->name, PATH_MAX); + dmdev[PATH_MAX] = 0; + slash = dmdev; + break; } - if (realpath(dmdev, buf) == NULL) - die("device-mapper: realpath(\"%s\") failed with: %s",dmdev, - strerror(errno)); - strncpy(dmdev, buf, PATH_MAX); - } while (result >= 0); - dmdev[PATH_MAX] = 0; + } while (nnext); + + if (!slash || !*slash) + die("device-mapper: name not found for device [%d]\n", device); + + dm_task_destroy(dmt); if (!(dmt = dm_task_create(DM_DEVICE_TABLE))) die("device-mapper: dm_task_create(DM_DEVICE_TABLE) failed"); - slash = strrchr(dmdev, '/'); - if (slash) - slash++; - else - slash = dmdev; if (!dm_task_set_name(dmt, slash)) die("device-mapper: dm_task_set_name(\"%s\") failed",dmdev); if (!dm_task_run(dmt)) @@ -986,7 +995,7 @@ void geo_get(GEOMETRY *geo,int device,in if (p == NULL) die("device-mapper: parse error in linear params (\"%s\")", params); *p = 0; - sprintf(buf, DEV_DIR "/%s", params); /* let's hope it's there */ + snprintf(buf, sizeof buf, DEV_DIR "/%s", params); /* let's hope it's there */ if (stat(buf, &st) == 0) { if (!S_ISBLK(st.st_mode)) die("device-mapper: %s is not a valid block device", buf); @@ -994,7 +1003,7 @@ void geo_get(GEOMETRY *geo,int device,in minor = MINOR(st.st_rdev); } else { /* let's try sysfs */ int dev; - sprintf(buf, "/sys/block/%s/dev", params); + snprintf(buf, sizeof buf, "/sys/block/%s/dev", params); file = fopen(buf, "r"); if (!file) die("device-mapper: \"%s\" could not be opened. /sys mounted?", buf); @@ -1020,19 +1029,13 @@ void geo_get(GEOMETRY *geo,int device,in } while(next); dm_task_destroy(dmt); - - dev_close(&dev); } if (!device) die("device-mapper: Error finding real device"); geo->base_dev = device; - - for(i = 0; i < dm_major_nr; i++) - if (MAJOR(device) == dm_major_list[i]) - break; } -#endif +#endif /* LCF_DEVMAPPER */ if (verbose>=5) printf("geo_get: device %04X, all=%d\n", device, all); #ifdef LCF_LVM @@ -1089,10 +1092,10 @@ void geo_get(GEOMETRY *geo,int device,in md_disk_info_t md_disk_info; int raid_limit; - sprintf(mdxxx, DEV_DISK_DIR "/md%d", MINOR(device)); + snprintf(mdxxx, sizeof mdxxx, DEV_DISK_DIR "/md%d", MINOR(device)); if ((md_fd=open(mdxxx,O_NOACCESS)) < 0) { - sprintf(mdxxx, DEV_DIR "/md/%d", MINOR(device)); + snprintf(mdxxx, sizeof mdxxx, DEV_DIR "/md/%d", MINOR(device)); if ((md_fd=open(mdxxx,O_NOACCESS)) < 0) die("Unable to open %s", mdxxx); }