From nobody Fri May 3 23:32:56 2024 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.zoho.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 1497964446602808.5570685792275; Tue, 20 Jun 2017 06:14:06 -0700 (PDT) Received: from localhost ([::1]:48814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNIyr-0000Ia-37 for importer@patchew.org; Tue, 20 Jun 2017 09:14:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNInn-0007n7-DL for qemu-devel@nongnu.org; Tue, 20 Jun 2017 09:02:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dNInj-0000kg-FN for qemu-devel@nongnu.org; Tue, 20 Jun 2017 09:02:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:60605) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dNInj-0000Xq-21; Tue, 20 Jun 2017 09:02:35 -0400 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 1dNIn5-0005CG-QH; Tue, 20 Jun 2017 15:01:55 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dNImq-0003nW-4q; Tue, 20 Jun 2017 16:01:40 +0300 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=gBwpE98eJf9IwcP52umaUiuOI0qN267C4vW5zlrCoqI=; b=XGEdoZrwdFPWuOcApkkp82g9OU/UZYShH/dPfuqZkiumVbG+eoGmHfh1+uxqjvXe9uwSYqGhjDZgpcZ+pxgmZelmtVbHz/pZb0WyYO9IKzOpV58aL3oAgHlmUX7/kP0qll53o8AOLacY/p4B8qeKdTb8WwQXC7f9KXrtr4pA78CAG/6klX9CCJdDIr0/VoVKXPbofgaRJGqQf+yEA+BRO673q/+UX/m63mQgWublmxk1NS354MyRSIqR1aKfbJJ32tRduJe16Z2MxcIGOelGAQmJWVzOYGreeCx+/ygCuo3XkUbndwS+O0wTzXgzUUPM1WMv8hZJQ8FPJnetvET0Pg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 20 Jun 2017 16:01:36 +0300 Message-Id: <20170620130136.14557-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] qcow2: Use offset_into_cluster() and offset_to_l2_index() 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" We already have functions for doing these calculations, so let's use them instead of doing everything by hand. This makes the code a bit more readable. Signed-off-by: Alberto Garcia --- block/qcow2-cluster.c | 4 ++-- block/qcow2.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index d779ea19cf..a2c612433d 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -548,7 +548,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, =20 /* find the cluster offset for the given disk offset */ =20 - l2_index =3D (offset >> s->cluster_bits) & (s->l2_size - 1); + l2_index =3D offset_to_l2_index(s, offset); *cluster_offset =3D be64_to_cpu(l2_table[l2_index]); =20 nb_clusters =3D size_to_clusters(s, bytes_needed); @@ -685,7 +685,7 @@ static int get_cluster_table(BlockDriverState *bs, uint= 64_t offset, =20 /* find the cluster offset for the given disk offset */ =20 - l2_index =3D (offset >> s->cluster_bits) & (s->l2_size - 1); + l2_index =3D offset_to_l2_index(s, offset); =20 *new_l2_table =3D l2_table; *new_l2_index =3D l2_index; diff --git a/block/qcow2.c b/block/qcow2.c index b3ba5daa93..adb604fc81 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -356,7 +356,7 @@ static int validate_table_offset(BlockDriverState *bs, = uint64_t offset, } =20 /* Tables must be cluster aligned */ - if (offset & (s->cluster_size - 1)) { + if (offset_into_cluster(s, offset) !=3D 0) { return -EINVAL; } =20 --=20 2.11.0