From nobody Sun Feb 8 18:32:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1581959660013371.0164868831031; Mon, 17 Feb 2020 09:14:20 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-307-WEC_arjNNdiWOhm5ZAziPQ-1; Mon, 17 Feb 2020 12:14:14 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2D1C2100DFC4; Mon, 17 Feb 2020 17:14:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B90488B563; Mon, 17 Feb 2020 17:14:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 98F1735B02; Mon, 17 Feb 2020 17:14:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HHE4EE018667 for ; Mon, 17 Feb 2020 12:14:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id 655F110001AE; Mon, 17 Feb 2020 17:14:04 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id B69F01001B28 for ; Mon, 17 Feb 2020 17:14:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581959658; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bJGFB6TZ4kdtC1o9ECxM3NBWCypYNZ0lc9wP6WdY8rE=; b=GpaUKwBYqHI2ny5TKJ1QT8QMdFYD+QYwsb3VmuFBxAmkJ83vvPAI1L7s15qWL95y1xaAOa 7GnZzTwEUr5JYqKBhqPqu72YQFvXBVBQUMic3wXQNT6YYLIxliOvsWMYnaDQ6vyQfqFTch rmNcRLpXTtYChLyUVwvvUpY6hwqxbjg= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/9] util: storagefile: Drop image format probing by file suffix Date: Mon, 17 Feb 2020 18:13:51 +0100 Message-Id: <8b9739f571c2a0dffcf8ebcef0490e45545def75.1581959449.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: WEC_arjNNdiWOhm5ZAziPQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Probing by file suffix was meant to be a last resort if probing by contents fails or is not supported. For most formats we never specified any suffix. There's a few formats implementing both magic bytes and suffix and finally DMG which had only suffix probing. Since suffix probing is nowhere reliable and only one format depends on in whic has a comment that qemu doesn't do the probing either drop the whole infrastructure. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virstoragefile.c | 58 ++++++++++++--------------------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 9347c7ab30..4d2e39246c 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -146,12 +146,10 @@ struct FileEncryptionInfo { int payloadOffset; /* start offset of the volume data (in 512 byte sec= tors) */ }; -/* Either 'magic' or 'extension' *must* be provided */ struct FileTypeInfo { int magicOffset; /* Byte offset of the magic */ const char *magic; /* Optional string of file magic * to check at head of file */ - const char *extension; /* Optional file extension to check */ enum lv_endian endian; /* Endianness of file format */ int versionOffset; /* Byte offset from start of file @@ -297,17 +295,17 @@ static struct FileEncryptionInfo const qcow2Encryptio= nInfo[] =3D { }; static struct FileTypeInfo const fileTypeInfo[] =3D { - [VIR_STORAGE_FILE_NONE] =3D { 0, NULL, NULL, LV_LITTLE_ENDIAN, + [VIR_STORAGE_FILE_NONE] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, - [VIR_STORAGE_FILE_RAW] =3D { 0, NULL, NULL, LV_LITTLE_ENDIAN, + [VIR_STORAGE_FILE_RAW] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, luksEncryptionInfo, NULL, NULL }, - [VIR_STORAGE_FILE_DIR] =3D { 0, NULL, NULL, LV_LITTLE_ENDIAN, + [VIR_STORAGE_FILE_DIR] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, [VIR_STORAGE_FILE_BOCHS] =3D { /*"Bochs Virtual HD Image", */ /* Untested */ - 0, NULL, NULL, + 0, NULL, LV_LITTLE_ENDIAN, 64, 4, {0x20000}, 32+16+16+4+4+4+4+4, 8, 1, NULL, NULL, NULL }, @@ -316,7 +314,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { #V2.0 Format modprobe cloop file=3D$0 && mount -r -t iso9660 /dev/cloop $1 */ /* Untested */ - 0, NULL, NULL, + 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, -1, 0, 0, NULL, NULL, NULL }, @@ -324,50 +322,50 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { /* XXX QEMU says there's no magic for dmg, * /usr/share/misc/magic lists double magic (both offsets * would have to match) but then disables that check. */ - 0, NULL, ".dmg", + 0, NULL, 0, -1, 0, {0}, -1, 0, 0, NULL, NULL, NULL }, [VIR_STORAGE_FILE_ISO] =3D { - 32769, "CD001", ".iso", + 32769, "CD001", LV_LITTLE_ENDIAN, -2, 0, {0}, -1, 0, 0, NULL, NULL, NULL }, [VIR_STORAGE_FILE_VPC] =3D { - 0, "conectix", NULL, + 0, "conectix", LV_BIG_ENDIAN, 12, 4, {0x10000}, 8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, NULL, NULL, NULL }, /* TODO: add getBackingStore function */ [VIR_STORAGE_FILE_VDI] =3D { - 64, "\x7f\x10\xda\xbe", ".vdi", + 64, "\x7f\x10\xda\xbe", LV_LITTLE_ENDIAN, 68, 4, {0x00010001}, 64 + 5 * 4 + 256 + 7 * 4, 8, 1, NULL, NULL, NULL}, /* Not direct file formats, but used for various drivers */ - [VIR_STORAGE_FILE_FAT] =3D { 0, NULL, NULL, LV_LITTLE_ENDIAN, + [VIR_STORAGE_FILE_FAT] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, - [VIR_STORAGE_FILE_VHD] =3D { 0, NULL, NULL, LV_LITTLE_ENDIAN, + [VIR_STORAGE_FILE_VHD] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, - [VIR_STORAGE_FILE_PLOOP] =3D { 0, "WithouFreSpacExt", NULL, LV_LITTLE_= ENDIAN, + [VIR_STORAGE_FILE_PLOOP] =3D { 0, "WithouFreSpacExt", LV_LITTLE_ENDIAN, -2, 0, {0}, PLOOP_IMAGE_SIZE_OFFSET, 0, PLOOP_SIZE_MULTIPLIER, NULL, NULL, NULL }, /* All formats with a backing store probe below here */ [VIR_STORAGE_FILE_COW] =3D { - 0, "OOOM", NULL, + 0, "OOOM", LV_BIG_ENDIAN, 4, 4, {2}, 4+4+1024+4, 8, 1, NULL, cowGetBackingStore, NULL }, [VIR_STORAGE_FILE_QCOW] =3D { - 0, "QFI", NULL, + 0, "QFI", LV_BIG_ENDIAN, 4, 4, {1}, QCOWX_HDR_IMAGE_SIZE, 8, 1, qcow1EncryptionInfo, qcowXGetBackingStore, NULL }, [VIR_STORAGE_FILE_QCOW2] =3D { - 0, "QFI", NULL, + 0, "QFI", LV_BIG_ENDIAN, 4, 4, {2, 3}, QCOWX_HDR_IMAGE_SIZE, 8, 1, qcow2EncryptionInfo, @@ -376,12 +374,12 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { }, [VIR_STORAGE_FILE_QED] =3D { /* https://wiki.qemu.org/Features/QED */ - 0, "QED", NULL, + 0, "QED", LV_LITTLE_ENDIAN, -2, 0, {0}, QED_HDR_IMAGE_SIZE, 8, 1, NULL, qedGetBackingStore, NULL }, [VIR_STORAGE_FILE_VMDK] =3D { - 0, "KDMV", NULL, + 0, "KDMV", LV_LITTLE_ENDIAN, 4, 4, {1, 2, 3}, 4+4+4, 8, 512, NULL, vmdk4GetBackingStore, NULL }, @@ -707,20 +705,6 @@ virStorageFileMatchesMagic(int magicOffset, } -static bool -virStorageFileMatchesExtension(const char *extension, - const char *path) -{ - if (extension =3D=3D NULL) - return false; - - if (virStringHasCaseSuffix(path, extension)) - return true; - - return false; -} - - static bool virStorageFileMatchesVersion(int versionOffset, int versionSize, @@ -842,14 +826,6 @@ virStorageFileProbeFormatFromBuf(const char *path, "Please report new version to libvir-list@redhat.com", path, virStorageFileFormatTypeToString(possibleFormat)); - /* No magic, so check file extension */ - for (i =3D 0; i < VIR_STORAGE_FILE_LAST; i++) { - if (virStorageFileMatchesExtension(fileTypeInfo[i].extension, path= )) { - format =3D i; - goto cleanup; - } - } - cleanup: VIR_DEBUG("format=3D%d", format); return format; --=20 2.24.1