From nobody Wed Apr 16 12:19:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544621636888636.0754316264295; Wed, 12 Dec 2018 05:33:56 -0800 (PST) Received: from localhost ([::1]:44922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4e9-00073c-7v for importer@patchew.org; Wed, 12 Dec 2018 08:33:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4YR-0002L5-O6 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4YP-0000qf-NM for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:27:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34042) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YK-0000lr-0g; Wed, 12 Dec 2018 08:27:52 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5618AC034DC2; Wed, 12 Dec 2018 13:27:51 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4472E60C5C; Wed, 12 Dec 2018 13:27:50 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:26:57 +0100 Message-Id: <20181212132735.16080-4-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 12 Dec 2018 13:27:51 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 03/41] dmg: including dmg-lzfse module inside dmg block driver. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Julio Faracco This commit includes the support to new module dmg-lzfse into dmg block driver. It includes the support for block type ULFO (0x80000007). Signed-off-by: Julio Faracco Signed-off-by: Kevin Wolf --- block/dmg.h | 3 +++ block/dmg.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/block/dmg.h b/block/dmg.h index 2ecf239ba5..f28929998f 100644 --- a/block/dmg.h +++ b/block/dmg.h @@ -55,4 +55,7 @@ typedef struct BDRVDMGState { extern int (*dmg_uncompress_bz2)(char *next_in, unsigned int avail_in, char *next_out, unsigned int avail_out); =20 +extern int (*dmg_uncompress_lzfse)(char *next_in, unsigned int avail_in, + char *next_out, unsigned int avail_out); + #endif diff --git a/block/dmg.c b/block/dmg.c index 1d9283ba2f..86bb2344ea 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -33,6 +33,9 @@ int (*dmg_uncompress_bz2)(char *next_in, unsigned int avail_in, char *next_out, unsigned int avail_out); =20 +int (*dmg_uncompress_lzfse)(char *next_in, unsigned int avail_in, + char *next_out, unsigned int avail_out); + enum { /* Limit chunk sizes to prevent unreasonable amounts of memory being u= sed * or truncating when converting to 32-bit types @@ -107,6 +110,7 @@ static void update_max_chunk_size(BDRVDMGState *s, uint= 32_t chunk, switch (s->types[chunk]) { case 0x80000005: /* zlib compressed */ case 0x80000006: /* bzip2 compressed */ + case 0x80000007: /* lzfse compressed */ compressed_size =3D s->lengths[chunk]; uncompressed_sectors =3D s->sectorcounts[chunk]; break; @@ -188,6 +192,8 @@ static bool dmg_is_known_block_type(uint32_t entry_type) return true; case 0x80000006: /* bzip2 */ return !!dmg_uncompress_bz2; + case 0x80000007: /* lzfse */ + return !!dmg_uncompress_lzfse; default: return false; } @@ -425,6 +431,7 @@ static int dmg_open(BlockDriverState *bs, QDict *option= s, int flags, } =20 block_module_load_one("dmg-bz2"); + block_module_load_one("dmg-lzfse"); =20 s->n_chunks =3D 0; s->offsets =3D s->lengths =3D s->sectors =3D s->sectorcounts =3D NULL; @@ -623,6 +630,27 @@ static inline int dmg_read_chunk(BlockDriverState *bs,= uint64_t sector_num) return ret; } break; + case 0x80000007: + if (!dmg_uncompress_lzfse) { + break; + } + /* we need to buffer, because only the chunk as whole can be + * inflated. */ + ret =3D bdrv_pread(bs->file, s->offsets[chunk], + s->compressed_chunk, s->lengths[chunk]); + if (ret !=3D s->lengths[chunk]) { + return -1; + } + + ret =3D dmg_uncompress_lzfse((char *)s->compressed_chunk, + (unsigned int) s->lengths[chunk], + (char *)s->uncompressed_chunk, + (unsigned int) + (512 * s->sectorcounts[chunk])); + if (ret < 0) { + return ret; + } + break; case 1: /* copy */ ret =3D bdrv_pread(bs->file, s->offsets[chunk], s->uncompressed_chunk, s->lengths[chunk]); --=20 2.19.2