From nobody Wed Nov 5 10:33:18 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; dkim=fail; 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=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541430805977476.67491756143477; Mon, 5 Nov 2018 07:13:25 -0800 (PST) Received: from localhost ([::1]:35726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJgZA-0002Bw-Oy for importer@patchew.org; Mon, 05 Nov 2018 10:13:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJgUd-0005la-Ta for qemu-devel@nongnu.org; Mon, 05 Nov 2018 10:08:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJgUc-0002jv-Gw for qemu-devel@nongnu.org; Mon, 05 Nov 2018 10:08:43 -0500 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]:36926) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gJgUc-0002di-8B; Mon, 05 Nov 2018 10:08:42 -0500 Received: by mail-qk1-x741.google.com with SMTP id 131so15207348qkd.4; Mon, 05 Nov 2018 07:08:42 -0800 (PST) Received: from localhost.localdomain ([177.45.6.151]) by smtp.gmail.com with ESMTPSA id v57sm5720501qtv.80.2018.11.05.07.08.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 07:08:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NM/TVz2txh2dTUWoK7dh7L5SubuA3O4s/CJVw731UUM=; b=S85Ggp1sMxpctt03uBx6Iw59i5Lw6eix7X9bRGaEW8bO3OKkxHLOM9GKYs1DnE12oi iNPsDOGzalxiISrs7J93CSzkUqgf38G2M72A5LBEAad8w6DX9Da7no4NTsIiRIw7xozU +ZkrRZ9K0rMUKENCgkMErQD3MpKnTukqLv7Kiy0Arc0kDQbMls4niI4+WestM0/Pu2IU iOtwLRkA9PfGhrIGH8SBVlU0nvP/jmjrd11OKiPqUsU3bCHaBg01cctxJqw4DhEH02vt hNfhoDoMmgTCJtTd/i2qNBzzTBJdgmOim2uKoeN+upNkyQvFXZ/t5d0Ue8xlV++SAdPB is7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NM/TVz2txh2dTUWoK7dh7L5SubuA3O4s/CJVw731UUM=; b=uMUJPdnCKMBiHU2aUoXwKBIRUb7cSde677vP3cat8W+wzU/J0YZ7WnlpIeFsirmxnH MUGjqVDiMXr5E6/lHVbGiTg8I9bWWTo0jBxioppE4K/PKHOiK8XjdXH3vICm72w0MC/n MPCvH5WPoPGFvFciThr1sqPaxm/Emy22GOWeDj3hfSRYnkdaQ/xmtG3VeUdy0pDyZQjV 4jLOvnSsFjelv+zXeHMMqh1ENzK50CadhA9ehNcY4P/H+biSG1ZCEGGPC9Fmg4o8loHG CHHNkxZzxoCVZaRe1WwPoqtAeOXkNNnusTNfshLiaw/seOtHF+0q5L6umWUsTjTtckDU Z5Ew== X-Gm-Message-State: AGRZ1gJ36Ku6DvC9YXUbPrt0X0qN7s1vdSgvPgSmy2t0kIvvbl+Hz1P6 n25xhF7pJSULF1Um+3Am2xvnjl9a X-Google-Smtp-Source: AJdET5doPyb+gCI1KyQH0iW4kcKpBrutD6I+7mDolz+6SJ9yQdv+8mf2LrO80SR4F01Q0WqovFHKmQ== X-Received: by 2002:a0c:e789:: with SMTP id x9mr1569099qvn.245.1541430521384; Mon, 05 Nov 2018 07:08:41 -0800 (PST) From: Julio Faracco To: qemu-devel@nongnu.org Date: Mon, 5 Nov 2018 13:08:05 -0200 Message-Id: <20181105150806.13649-4-jcfaracco@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181105150806.13649-1-jcfaracco@gmail.com> References: <20181105150806.13649-1-jcfaracco@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::741 Subject: [Qemu-devel] [PATCH v3 3/4] 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: Kevin Wolf , qemu-block@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- block/dmg.c | 28 ++++++++++++++++++++++++++++ block/dmg.h | 3 +++ 2 files changed, 31 insertions(+) diff --git a/block/dmg.c b/block/dmg.c index c9b3c519c4..615f818c5a 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; } @@ -431,6 +437,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; @@ -629,6 +636,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]); 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 --=20 2.17.1