mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<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],
|
||||
@@ -7323,6 +7323,19 @@ different operation that turns free space in the filesystem
|
||||
into zeroes. It is valid to call C<guestfs_fstrim> either
|
||||
instead of, or after calling C<guestfs_zero_free_space>.");
|
||||
|
||||
("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
|
||||
|
||||
@@ -1 +1 @@
|
||||
334
|
||||
335
|
||||
|
||||
Reference in New Issue
Block a user