From c7d257db1cde62f30f9968a0d644aeb6497f75a2 Mon Sep 17 00:00:00 2001 From: Andrey Drobyshev Date: Mon, 25 Apr 2022 22:35:47 +0300 Subject: [PATCH] appliance: don't read extfs signature from QCOW2 image directly If the appliance is a QCOW2 image, function get_root_uuid_with_file() fails to read ext filesystem signature (0x53EF at offset 0x438) from it. This results in the following error: libguestfs: error: /usr/lib64/guestfs/appliance/root: appliance is not an extfs filesystem The error itself is harmless, but misleading. So let's skip retrieving the signature and UUID in case the image contains QCOW2 header. It's safe because in this case we'll retrieve it later from RAW image dumped from that QCOW2 by "qemu-img dd". Signed-off-by: Andrey Drobyshev (cherry picked from commit ef8c6593eb4ab232891aeb6f144cf275a40efcbf) --- lib/appliance-kcmdline.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/appliance-kcmdline.c b/lib/appliance-kcmdline.c index 8b78655eb..092d37329 100644 --- a/lib/appliance-kcmdline.c +++ b/lib/appliance-kcmdline.c @@ -65,7 +65,7 @@ static char * get_root_uuid_with_file (guestfs_h *g, const char *appliance) { - unsigned char magic[2], uuid[16]; + unsigned char magic[4], uuid[16]; char *ret; int fd; @@ -74,6 +74,10 @@ get_root_uuid_with_file (guestfs_h *g, const char *appliance) perrorf (g, _("open: %s"), appliance); return NULL; } + if (read (fd, magic, 4) != 4 || !strncmp ((char *) magic, "QFI\xfb", 4)) { + /* No point looking for extfs signature in QCOW2 directly. */ + return NULL; + } if (lseek (fd, 0x438, SEEK_SET) != 0x438) { magic_error: error (g, _("%s: cannot read extfs magic in superblock"), appliance);