From: "Richard W.M. Jones" <rjones(a)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)
(cherry picked from commit 750841e389b14318f698dd57b26bdfada5c0c78f)
---
src/guestfs-internal-frontend.h | 1 +
src/guestfs-internal.h | 3 ---
src/launch-appliance.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 06ed37f..ca1701f 100644
--- a/src/guestfs-internal-frontend.h
+++ b/src/guestfs-internal-frontend.h
@@ -96,6 +96,7 @@ extern void guestfs___free_string_list (char **);
extern size_t guestfs___count_strings (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 428fdb9..7c37e57 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -521,9 +521,6 @@ extern void guestfs___launch_failed_error (guestfs_h *g);
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 int guestfs___feature_available (guestfs_h *g, const char *feature);
diff --git a/src/launch-appliance.c b/src/launch-appliance.c
index f0278ce..69c4145 100644
--- a/src/launch-appliance.c
+++ b/src/launch-appliance.c
@@ -1030,18 +1030,6 @@ qemu_drive_param (guestfs_h *g, const struct drive *drv, size_t
index)
return r; /* caller frees */
}
-/*
https://rwmj.wordpress.com/2011/01/09/how-are-linux-drives-named-beyond-d...
*/
-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_appliance (guestfs_h *g, int check_for_errors)
{
diff --git a/src/utils.c b/src/utils.c
index 01c31d6..54d9d7e 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)
{
@@ -122,3 +127,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-d...
+ */
+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