diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-06-13 22:09:13 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-07-06 17:36:29 +0100 |
commit | 3004973f5cc97c9e2a0c22c33598235ae8220ea5 (patch) | |
tree | 1be5b5bb3f27f186b6bf79279869fa78e3991e60 | |
parent | f66b27ef2455969be7a5812914bda9023645d440 (diff) | |
download | libguestfs-3004973f5cc97c9e2a0c22c33598235ae8220ea5.tar.gz libguestfs-3004973f5cc97c9e2a0c22c33598235ae8220ea5.tar.xz libguestfs-3004973f5cc97c9e2a0c22c33598235ae8220ea5.zip |
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)
-rw-r--r-- | daemon/devsparts.c | 23 | ||||
-rw-r--r-- | generator/generator_actions.ml | 15 |
2 files changed, 37 insertions, 1 deletions
diff --git a/daemon/devsparts.c b/daemon/devsparts.c index b6f755be..8020fbe1 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 11ce5fc6..4cad3323 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -6019,7 +6019,7 @@ removes the partition number, returning the device name The named partition must exist, for example as a string returned from C<guestfs_list_partitions>. -See also C<guestfs_part_to_partnum>."); +See also C<guestfs_part_to_partnum>, C<guestfs_device_index>."); ("upload_offset", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"; Int64 "offset"], []), 273, [Progress; Cancellable], @@ -7240,6 +7240,19 @@ a btrfs filesystem."); Used to check a btrfs filesystem, C<device> is the device file where the filesystem is stored."); + ("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<guestfs_list_devices>. + +See also C<guestfs_list_devices>, C<guestfs_part_to_dev>."); + ] let all_functions = non_daemon_functions @ daemon_functions |