From patchwork Fri Aug 10 04:07:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julio Faracco X-Patchwork-Id: 955932 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="n4PSf1jo"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41ms9z31Xpz9s4Z for ; Fri, 10 Aug 2018 14:11:03 +1000 (AEST) Received: from localhost ([::1]:54185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnylR-0003pH-3s for incoming@patchwork.ozlabs.org; Fri, 10 Aug 2018 00:11:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnyir-0000u0-B0 for qemu-devel@nongnu.org; Fri, 10 Aug 2018 00:08:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnyiq-0002iN-Cn for qemu-devel@nongnu.org; Fri, 10 Aug 2018 00:08:21 -0400 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:39352) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fnyiq-0002hs-7M; Fri, 10 Aug 2018 00:08:20 -0400 Received: by mail-qt0-x241.google.com with SMTP id q12-v6so9008808qtp.6; Thu, 09 Aug 2018 21:08:20 -0700 (PDT) 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=n/xFIIG+C1fNrhN1pK2crLOmdXAwwmn5njoEGnl+9ME=; b=n4PSf1jon7zZHbxrQMan3ZDBWilwtl7je5wK2BGKeNSBINUZYBDkEZP9kbIIxwho4P q8mPASIGpmexwDTR4JqXjYsHbjF5pCBkSlsCeaEJwOc9CLAOZrmGpZXQLFKQ2zb9dC7W 6tOe2ep/Z+vysEwtmyHX4380CCWKaKEcS6igb5Y1LqmYdCLquzcMUqU8FLL3/eIXKhTg yx/9Pujq0t0wWIn28sIj5OWsIAH879m4T+em+xzXR6jVY50kN0n1GSr7/AQ81THSJCv8 rym/yIszw4Dnb0SRMdUWsXYslecVeR33qwP6KfwHBdDyXDpapaGb4qQZJboS8kJJybkp aSPg== 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=n/xFIIG+C1fNrhN1pK2crLOmdXAwwmn5njoEGnl+9ME=; b=dY3PsbnpVySWiY1K1UwsMQaiw2fJiAznBpGqVgQvZbNf9Bnz8uVxTWDboBgP2GDlOX PuY4WdwPgdvKu6cMExz62D3um3bGJXrBD6C9l/eeb06Hqb/XiGnt9le+aGfHxnJOe1rc mo/7otWs294ESjVtqie6CSNU2QmKRk7TqWSgsR8Bg+g9bWxAXAtdhLyxWvRcv4wmvbKU U1Dx6xb5lmP0DTGLdJvdDLVmOtQpjuYUmei48Xegb/tD9gzbTVv5ipn9yVGkU3JNVXuU rqO/qs2c9tmsnCQAgHpGZwRSPKPDIEGeAR5Dib3P7uaNPZjyo9TCMMNdwZfEUmQrLpYn 5NJQ== X-Gm-Message-State: AOUpUlERZZK1HdSDe1MyRaiWeW40kcWR6+lFvnRBUQhGqxuZ1yGH5yYA R53hAHGjhctCi+35LgwdVQPacfg6 X-Google-Smtp-Source: AA+uWPxQlD8WflxHWSpxyduR9Dh1wWGeAZfAcdb1kA7sQ+79RUuoDo6MQv7QEMUOc15jm0UFrZkVjw== X-Received: by 2002:ac8:1b49:: with SMTP id p9-v6mr4994829qtk.132.1533874099330; Thu, 09 Aug 2018 21:08:19 -0700 (PDT) Received: from localhost.localdomain ([186.223.91.15]) by smtp.gmail.com with ESMTPSA id s53-v6sm6561555qts.5.2018.08.09.21.08.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 21:08:18 -0700 (PDT) From: Julio Faracco To: qemu-devel@nongnu.org Date: Fri, 10 Aug 2018 01:07:42 -0300 Message-Id: <20180810040743.25424-4-jcfaracco@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180810040743.25424-1-jcfaracco@gmail.com> References: <20180810040743.25424-1-jcfaracco@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::241 Subject: [Qemu-devel] [PATCH 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: kwolf@redhat.com, qemu-block@nongnu.org, stefanha@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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..390ab67e53 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); +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 used * or truncating when converting to 32-bit types @@ -107,6 +110,7 @@ static void update_max_chunk_size(BDRVDMGState *s, uint32_t chunk, switch (s->types[chunk]) { case 0x80000005: /* zlib compressed */ case 0x80000006: /* bzip2 compressed */ + case 0x80000007: /* lzfse compressed */ compressed_size = s->lengths[chunk]; uncompressed_sectors = 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 *options, int flags, } block_module_load_one("dmg-bz2"); + block_module_load_one("dmg-lzfse"); s->n_chunks = 0; s->offsets = s->lengths = s->sectors = s->sectorcounts = 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 = bdrv_pread(bs->file, s->offsets[chunk], + s->compressed_chunk, s->lengths[chunk]); + if (ret != s->lengths[chunk]) { + return -1; + } + + ret = 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 = 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); +extern int (*dmg_uncompress_lzfse)(char *next_in, unsigned int avail_in, + char *next_out, unsigned int avail_out); + #endif