summaryrefslogtreecommitdiff
path: root/extras/multipath/devmap_name.c
blob: 08e526e0721b8861649821ea98380756a04df889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "libdevmapper/libdevmapper.h"
                                                                                
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <linux/kdev_t.h>

static void usage(char * progname) {
	fprintf(stderr, "usage : %s major minor\n", progname);
	exit(1);
}

int main(int argc, char **argv)
{
        int r = 0;
        struct dm_names *names;
        unsigned next = 0;
	int major, minor;
                                                                                
	/* sanity check */
	if (argc != 3)
		usage(argv[0]);

	major = atoi(argv[1]);
	minor = atoi(argv[2]);

        struct dm_task *dmt;
                                                                                
        if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
                return 0;
                                                                                
        if (!dm_task_run(dmt))
                goto out;
                                                                                
        if (!(names = dm_task_get_names(dmt)))
                goto out;
                                                                                
        if (!names->dev) {
                printf("No devices found\n");
                goto out;
        }
                                                                                
        do {
                names = (void *) names + next;
		if ((int) MAJOR(names->dev) == major &&
		    (int) MINOR(names->dev) == minor) {
	                printf("%s\n", names->name);
			goto out;
		}
                next = names->next;
        } while (next);
                                                                                
      /* No correspondance found */
      r = 1;

      out:
        dm_task_destroy(dmt);
        return r;
}