On Wed, Dec 03, 2025 at 11:18:29AM +0000, Richard W.M. Jones via Libguestfs wrote:
+/* btrfsvol:/dev/sdX also needs reversing. */
+static char *
+reverse_btrfsvol (const char *device)
+{
+ const char prefix[] = "btrfsvol:";
+ const char *device_start, *device_end;
+ CLEANUP_FREE char *device_name = NULL;
+ CLEANUP_FREE char *reversed_device = NULL;
+ char *ret;
+
+ device_start = device + strlen (prefix);
+ device_end = strchr (device_start + strlen ("/dev/"), '/');
+ device_name = strndup (device_start, device_end - device_start);
^^ Missing an error check here.
I added this in my copy:
if (device_name == NULL) {
reply_with_perror ("strndup");
return NULL;
}
+
+ reversed_device = reverse_device_name_translation (device_name);
+ if (reversed_device == NULL)
+ return NULL;
+
+ /* Construct the final btrfsvol: and return it, caller frees. */
+ if (asprintf (&ret, "%s%s%s", prefix, reversed_device, device_end) ==
-1) {
+ reply_with_perror ("asprintf");
+ return NULL;
+ }
+
+ return ret;
+}
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top