diff options
author | greg@kroah.com <greg@kroah.com> | 2004-03-10 22:40:39 -0800 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 21:35:09 -0700 |
commit | a3b37a073d52ff01d4ef023a10f13316da4c9966 (patch) | |
tree | 349bfb87361de4b6d1990b9d5a9283d445b7ea37 /extras/multipath-tools/devmap_name/devmap_name.c | |
parent | 49f9acf3844aa5c004b5794e919bd54166e53227 (diff) |
[PATCH] Added multipath-tools 0.1.1 release
Diffstat (limited to 'extras/multipath-tools/devmap_name/devmap_name.c')
-rw-r--r-- | extras/multipath-tools/devmap_name/devmap_name.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/extras/multipath-tools/devmap_name/devmap_name.c b/extras/multipath-tools/devmap_name/devmap_name.c new file mode 100644 index 0000000000..0932e4f8bb --- /dev/null +++ b/extras/multipath-tools/devmap_name/devmap_name.c @@ -0,0 +1,60 @@ +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <linux/kdev_t.h> + +#include "../libdevmapper/libdevmapper.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; +} + |