daemon: Reimplement ‘nr_devices’ API in OCaml.

This commit is contained in:
Richard W.M. Jones
2017-06-03 14:56:57 +01:00
parent c37c8e770d
commit 90c6bffcdd
4 changed files with 5 additions and 15 deletions

View File

@@ -54,21 +54,6 @@ do_device_index (const char *device)
return ret;
}
int
do_nr_devices (void)
{
size_t i;
CLEANUP_FREE_STRING_LIST char **devices = do_list_devices ();
if (devices == NULL)
return -1;
for (i = 0; devices[i] != NULL; ++i)
;
return (int) i;
}
#define GUESTFSDIR "/dev/disk/guestfs"
char **

View File

@@ -89,6 +89,8 @@ and add_partitions dev =
let parts = List.filter (fun part -> String.is_prefix part dev) parts in
List.map ((^) "/dev/") parts
let nr_devices () = List.length (list_devices ())
let part_to_dev part =
let dev, part = split_device_partition part in
if part = 0 then

View File

@@ -19,6 +19,8 @@
val list_devices : unit -> string list
val list_partitions : unit -> string list
val nr_devices : unit -> int
val part_to_dev : string -> string
val part_to_partnum : string -> int

View File

@@ -7432,6 +7432,7 @@ See also C<guestfs_list_devices>, C<guestfs_part_to_dev>." };
{ defaults with
name = "nr_devices"; added = (1, 19, 15);
impl = OCaml "Devsparts.nr_devices";
style = RInt "nrdisks", [], [];
tests = [
InitEmpty, Always, TestResult (