diff --git a/daemon/devsparts.c b/daemon/devsparts.c index b6f755beb..8020fbe14 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -241,3 +241,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 7b2bd97f8..f249991e8 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -6062,7 +6062,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], @@ -7323,6 +7323,19 @@ different operation that turns free space in the filesystem into zeroes. It is valid to call C either instead of, or after calling C."); + ("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 0ae9d1ef4..3d9988adc 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -334 +335