# HG changeset patch # User Daniel Stodden # Date 1276140316 25200 # Node ID 51ed44eb2e9f899d338d9ee9a88903ff3c4216f5 # Parent bbdfc4c5a31e26d23411a83edbef4a55ff904f2d blktap2: Add tap_ctl_find_minor. Slack 'tap-ctl find -t -f '. Signed-off-by: Daniel Stodden diff -r bbdfc4c5a31e -r 51ed44eb2e9f tools/blktap2/control/tap-ctl-list.c --- a/tools/blktap2/control/tap-ctl-list.c Wed Jun 09 20:25:11 2010 -0700 +++ b/tools/blktap2/control/tap-ctl-list.c Wed Jun 09 20:25:16 2010 -0700 @@ -504,3 +504,33 @@ return err; } + +int +tap_ctl_find_minor(const char *type, const char *path) +{ + tap_list_t **list, **_entry; + int minor, err; + + err = tap_ctl_list(&list); + if (err) + return err; + + minor = -1; + + for (_entry = list; *_entry != NULL; ++_entry) { + tap_list_t *entry = *_entry; + + if (type && (!entry->type || strcmp(entry->type, type))) + continue; + + if (path && (!entry->path || strcmp(entry->path, path))) + continue; + + minor = entry->minor; + break; + } + + tap_ctl_free_list(list); + + return minor >= 0 ? minor : -ENOENT; +} diff -r bbdfc4c5a31e -r 51ed44eb2e9f tools/blktap2/control/tap-ctl.h --- a/tools/blktap2/control/tap-ctl.h Wed Jun 09 20:25:11 2010 -0700 +++ b/tools/blktap2/control/tap-ctl.h Wed Jun 09 20:25:16 2010 -0700 @@ -77,6 +77,7 @@ int tap_ctl_list(tap_list_t ***list); void tap_ctl_free_list(tap_list_t **list); +int tap_ctl_find_minor(const char *type, const char *path); int tap_ctl_allocate(int *minor, char **devname); int tap_ctl_free(const int minor);