diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-06-29 19:03:37 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-06-29 19:04:21 +0100 |
commit | 152b179a19e43fcb0baec65ea65d394ee1dba891 (patch) | |
tree | 89a2b0057c62d594d77b474cd120cce137497732 /daemon/devsparts.c | |
parent | cba49169094f04dead9b165b6b5991afa92132ff (diff) | |
download | libguestfs-152b179a19e43fcb0baec65ea65d394ee1dba891.tar.gz libguestfs-152b179a19e43fcb0baec65ea65d394ee1dba891.tar.xz libguestfs-152b179a19e43fcb0baec65ea65d394ee1dba891.zip |
New API: guestfs_nr_devices
This returns the number of whole block devices added. It is usually
simpler to call this than to list the devices and count them, which
is what we do in some places in the current codebase.
Diffstat (limited to 'daemon/devsparts.c')
-rw-r--r-- | daemon/devsparts.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/daemon/devsparts.c b/daemon/devsparts.c index 8020fbe1..bd955da5 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -264,3 +264,20 @@ do_device_index (const char *device) reply_with_error ("device not found"); return ret; } + +int +do_nr_devices (void) +{ + char **devices; + size_t i; + + devices = do_list_devices (); + if (devices == NULL) + return -1; + + for (i = 0; devices[i] != NULL; ++i) + free (devices[i]); + free (devices); + + return (int) i; +} |