From 8deae6d2cc27f84d8b1c7112de2b41a2346670b8 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 13 Jun 2012 22:09:13 +0100 Subject: New API: device-index. This returns the index of the device, eg. /dev/sdb => 1. Or you can think of it as the order that the device was added, or the index of the device in guestfs_list_devices. (cherry picked from commit a9d7d044f552855a7ef78d953c0c2672e35bfc80) --- daemon/devsparts.c | 23 +++++++++++++++++++++++ generator/generator_actions.ml | 15 ++++++++++++++- src/MAX_PROC_NR | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/daemon/devsparts.c b/daemon/devsparts.c index c1457b0d..8f85624f 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -245,3 +245,26 @@ do_part_to_partnum (const char *part) return r; } + +int +do_device_index (const char *device) +{ + char **devices; + size_t i; + int ret = -1; + + devices = do_list_devices (); + if (devices == NULL) + return -1; + + for (i = 0; devices[i] != NULL; ++i) { + if (STREQ (device, devices[i])) + ret = (int) i; + free (devices[i]); + } + free (devices); + + if (ret == -1) + reply_with_error ("device not found"); + return ret; +} diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 6954542a..14618c29 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -5954,7 +5954,7 @@ removes the partition number, returning the device name The named partition must exist, for example as a string returned from C. -See also C."); +See also C, C."); ("upload_offset", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"; Int64 "offset"], []), 273, [Progress; Cancellable], @@ -6651,6 +6651,19 @@ This option may not be specified at the same time as the C option. =back"); + ("device_index", (RInt "index", [Device "device"], []), 335, [], + [InitEmpty, Always, TestOutputInt ( + [["device_index"; "/dev/sda"]], 0)], + "convert device to index", + "\ +This function takes a device name (eg. \"/dev/sdb\") and +returns the index of the device in the list of devices. + +Index numbers start from 0. The named device must exist, +for example as a string returned from C. + +See also C, C."); + ] let all_functions = non_daemon_functions @ daemon_functions diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 873b744b..3d9988ad 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -304 +335 -- cgit