From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpDeQ-0003Jk-NA for qemu-devel@nongnu.org; Mon, 13 Aug 2018 10:17:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fpDeK-0004rt-Le for qemu-devel@nongnu.org; Mon, 13 Aug 2018 10:16:54 -0400 Date: Mon, 13 Aug 2018 16:16:41 +0200 From: Kevin Wolf Message-ID: <20180813141641.GI4323@localhost.localdomain> References: <20180810040743.25424-1-jcfaracco@gmail.com> <20180810040743.25424-4-jcfaracco@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180810040743.25424-4-jcfaracco@gmail.com> Subject: Re: [Qemu-devel] [PATCH 3/4] dmg: including dmg-lzfse module inside dmg block driver. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Julio Faracco Cc: qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com, qemu-block@nongnu.org Am 10.08.2018 um 06:07 hat Julio Faracco geschrieben: > 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; Indentation is off. I think you got a tab instead of spaces here. > 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) { More tab damage in these two lines. > + 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) { lzfse_decode_buffer() returns 0 in error cases, and possibly a short number of bytes. Should the condition compare ret with the expected full byte count? > + return ret; > + } > + break; > case 1: /* copy */ > ret = bdrv_pread(bs->file, s->offsets[chunk], > s->uncompressed_chunk, s->lengths[chunk]); Kevin