From: Daniel Stodden Date: Tue, 29 Jun 2010 20:03:09 +0000 (-0700) Subject: blktap2: Add tap_ctl_find_minor X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9ebeb00ae2cc2a535c7e5ad67a039698b58a7b27;p=people%2Fdstodden%2Fblktap.git blktap2: Add tap_ctl_find_minor Slack 'tap-ctl find -t -f '. Signed-off-by: Daniel Stodden --- diff --git a/control/tap-ctl-list.c b/control/tap-ctl-list.c index af59227..55de3e7 100644 --- a/control/tap-ctl-list.c +++ b/control/tap-ctl-list.c @@ -504,3 +504,33 @@ out: 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 --git a/control/tap-ctl.h b/control/tap-ctl.h index 850f9f0..96142e4 100644 --- a/control/tap-ctl.h +++ b/control/tap-ctl.h @@ -77,6 +77,7 @@ int tap_ctl_get_driver_id(const char *handle); 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);