From nobody Fri Oct 24 09:58:53 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519146369676372.61650963545367; Tue, 20 Feb 2018 09:06:09 -0800 (PST) Received: from localhost ([::1]:56669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoBMm-0004DH-3Z for importer@patchew.org; Tue, 20 Feb 2018 12:06:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoBJP-0001B6-3j for qemu-devel@nongnu.org; Tue, 20 Feb 2018 12:02:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eoBJJ-0000R3-VK for qemu-devel@nongnu.org; Tue, 20 Feb 2018 12:02:39 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:49679) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eoBJJ-0008TQ-I6; Tue, 20 Feb 2018 12:02:33 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1eoBIh-0002yd-8k; Tue, 20 Feb 2018 18:01:55 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1eoBIO-0001OL-Ma; Tue, 20 Feb 2018 19:01:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Message-Id:Date:Subject:Cc:To:From; bh=xoK9HEJtW9upkyxx6xuD5k9ymX+611R597MIL8bBtMs=; b=c2O0XMZRyqErKQldzA+MPnPr9XOdquZV4oC0VmnmswHokQujtI/5/msbVvEbvwiw5ZSG3UFcMmFwpAMcw9VD9TY79omwoOfbDzMUFbg4UfzLPcwtt+LStdv2m53Z9hHS3EEVSWhl6/pjPyA34oSmNA9pqobup36QKlC5ubSYOw2UoMO8+DxDU73VqEEpiCj5aT6m/Usr4uG5OVgc9ufxzLXwI6vMLk4IJ76jz/v9MsiYabrcMCcFvC6DhS7pSx8Eu9Writ/E+1cSXThYmf+QcKHB5aChzKtYPR3XoIM2aCJl0mEcsyZ7vujsUK8Ir4s70ILMRjkwLnQaPIcevtolGA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 20 Feb 2018 19:01:35 +0200 Message-Id: <20180220170135.5299-1-berto@igalia.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2] specs/qcow2: Fix documentation of the compressed cluster descriptor 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The documentation claims that the cluster descriptor contains the number of sectors used to store the compressed data, but what it actually contains is the number of sectors *minus one*. That can be easily seen in qcow2_decompress_cluster(), that adds one to the value stored in that field: nb_csectors =3D ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1; In addition to that this patch clarifies where the actual compressed data is located. Although the size of the data is specified in sectors, the offset is not necessarily aligned to a sector boundary, so the actual data goes from the specified offset until the end of the last sector, leaving the initial bytes of the first sector (if any) unused. Signed-off-by: Alberto Garcia --- v2: I realized that the documentation is not completely clear about the exact location and size of the compressed data, so I updated the patch to clarify this. --- docs/interop/qcow2.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index d7fdb1fee3..dc2b9cefb2 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -427,9 +427,17 @@ Standard Cluster Descriptor: Compressed Clusters Descriptor (x =3D 62 - (cluster_bits - 8)): =20 Bit 0 - x: Host cluster offset. This is usually _not_ aligned to a - cluster boundary! + cluster or sector boundary! =20 - x+1 - 61: Compressed size of the images in sectors of 512 bytes + x+1 - 61: Number of 512-byte sectors used for the compressed dat= a, + minus one (that is, a value of n here means n+1 sector= s). + + The actual compressed data is located at the end of th= is + region, from the offset indicated in the previous field + until the end of the last sector. + + The initial bytes of this region are therefore unused = if + the offset is not aligned to a sector boundary. =20 If a cluster is unallocated, read requests shall read the data from the ba= cking file (except if bit 0 in the Standard Cluster Descriptor is set). If there= is --=20 2.11.0