2
* device-mapper (dm) topology
3
* -- this is fallback for old systems where the topology information is not
6
* Copyright (C) 2009 Karel Zak <kzak@redhat.com>
8
* This file may be redistributed under the terms of the
9
* GNU Lesser General Public License.
19
#include <sys/types.h>
24
static int is_dm_device(dev_t devno)
26
return blkid_driver_has_major("device-mapper", major(devno));
29
static int probe_dm_tp(blkid_probe pr, const struct blkid_idmag *mag)
31
const char *paths[] = {
32
"/usr/local/sbin/dmsetup",
36
int i, dmpipe[] = { -1, -1 }, stripes, stripesize;
39
long long offset, size;
40
dev_t devno = blkid_probe_get_devno(pr);
43
goto nothing; /* probably not a block device */
44
if (!is_dm_device(devno))
47
for (i = 0; i < ARRAY_SIZE(paths); i++) {
49
if (stat(paths[i], &sb) == 0) {
50
cmd = (char *) paths[i];
57
if (pipe(dmpipe) < 0) {
59
printf("Failed to open pipe: errno=%d", errno));
66
char *dmargv[7], maj[16], min[16];
71
if (dmpipe[1] != STDOUT_FILENO)
72
dup2(dmpipe[1], STDOUT_FILENO);
74
/* The libblkid library could linked with setuid programs */
75
if (setgid(getgid()) < 0)
77
if (setuid(getuid()) < 0)
80
snprintf(maj, sizeof(maj), "%d", major(devno));
81
snprintf(min, sizeof(min), "%d", minor(devno));
91
execv(dmargv[0], dmargv);
94
printf("Failed to execute %s: errno=%d", cmd, errno));
99
printf("Failed to forking: errno=%d", errno));
105
stream = fdopen(dmpipe[0], "r");
109
i = fscanf(stream, "%lld %lld striped %d %d ",
110
&offset, &size, &stripes, &stripesize);
114
blkid_topology_set_minimum_io_size(pr, stripesize << 9);
115
blkid_topology_set_optimal_io_size(pr, (stripes * stripesize) << 9);
124
else if (dmpipe[0] != -1)
131
const struct blkid_idinfo dm_tp_idinfo =
134
.probefunc = probe_dm_tp,
135
.magics = BLKID_NONE_MAGIC