From: "Richard W.M. Jones" <rjo...@redhat.com> For some historical reason, it was stuck in src/launch-direct.c and the comment referred to launch-appliance.c!
(cherry picked from commit 00cbb5c1854a52a5b4742aa7ca9601a9aaaab529) --- src/guestfs-internal-frontend.h | 1 + src/guestfs-internal.h | 3 --- src/launch-direct.c | 12 ------------ src/utils.c | 23 +++++++++++++++++++++++ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/guestfs-internal-frontend.h b/src/guestfs-internal-frontend.h index 2070fa8..3e2c433 100644 --- a/src/guestfs-internal-frontend.h +++ b/src/guestfs-internal-frontend.h @@ -98,6 +98,7 @@ extern char *guestfs___concat_strings (char *const *); extern char *guestfs___join_strings (const char *sep, char *const *); extern char *guestfs___exit_status_to_string (int status, const char *cmd_name, char *buffer, size_t buflen); extern int guestfs___random_string (char *ret, size_t len); +extern char *guestfs___drive_name (size_t index, char *ret); /* These functions are used internally by the CLEANUP_* macros. * Don't call them directly. diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index 28e40a2..1c3fea9 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -641,9 +641,6 @@ extern void guestfs___launch_send_progress (guestfs_h *g, int perdozen); extern char *guestfs___appliance_command_line (guestfs_h *g, const char *appliance_dev, int flags); #define APPLIANCE_COMMAND_LINE_IS_TCG 1 -/* launch-appliance.c */ -extern char *guestfs___drive_name (size_t index, char *ret); - /* inspect.c */ extern void guestfs___free_inspect_info (guestfs_h *g); extern char *guestfs___download_to_tmp (guestfs_h *g, struct inspect_fs *fs, const char *filename, const char *basename, uint64_t max_size); diff --git a/src/launch-direct.c b/src/launch-direct.c index ce39e0c..ac4f7fc 100644 --- a/src/launch-direct.c +++ b/src/launch-direct.c @@ -1003,18 +1003,6 @@ qemu_drive_param (guestfs_h *g, const struct drive *drv, size_t index) iface); } -/* https://rwmj.wordpress.com/2011/01/09/how-are-linux-drives-named-beyond-drive-26-devsdz/ */ -char * -guestfs___drive_name (size_t index, char *ret) -{ - if (index >= 26) - ret = guestfs___drive_name (index/26 - 1, ret); - index %= 26; - *ret++ = 'a' + index; - *ret = '\0'; - return ret; -} - static int shutdown_direct (guestfs_h *g, int check_for_errors) { diff --git a/src/utils.c b/src/utils.c index 4a9ae96..f8d2509 100644 --- a/src/utils.c +++ b/src/utils.c @@ -31,6 +31,11 @@ #include "guestfs.h" #include "guestfs-internal-frontend.h" +/* Note that functions in libutils are used by the tools and language + * bindings. Therefore these must not call internal library functions + * such as safe_*, error or perrorf. + */ + void guestfs___free_string_list (char **argv) { @@ -164,3 +169,21 @@ guestfs___random_string (char *ret, size_t len) return 0; } + +/* This turns a drive index (eg. 27) into a drive name (eg. "ab"). + * Drive indexes count from 0. The return buffer has to be large + * enough for the resulting string, and the returned pointer points to + * the *end* of the string. + * + * https://rwmj.wordpress.com/2011/01/09/how-are-linux-drives-named-beyond-drive-26-devsdz/ + */ +char * +guestfs___drive_name (size_t index, char *ret) +{ + if (index >= 26) + ret = guestfs___drive_name (index/26 - 1, ret); + index %= 26; + *ret++ = 'a' + index; + *ret = '\0'; + return ret; +} -- 1.8.3.1 _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs