Received: by 2002:ac0:de83:0:0:0:0:0 with SMTP id b3csp1321097imk; Mon, 4 Jul 2022 00:08:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uNz10xNBZDfOxRO7DY7RkcQMNJNjUuJ0X7WDRTG16AK9qLgKBtGNBsf1Jw8A3wCf3QgdyE X-Received: by 2002:aa7:c657:0:b0:43a:4a68:bcc5 with SMTP id z23-20020aa7c657000000b0043a4a68bcc5mr6362263edr.337.1656918488941; Mon, 04 Jul 2022 00:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656918488; cv=none; d=google.com; s=arc-20160816; b=0inE0mzAEWBN1EJiydQ28aIlgs/us1gI4v/oovlaUNB+sBa5FjJs3xKhMwqU+PvKl8 J/Dfs485zbrdbZ9IDmB8zStAuniWDGBYjsqq6VsFLQZqRHbQg5PA7s6T83GG/mU/kQPU XdM2Osj+vDLqgDbAfA7rIXOPfFDZwhkNaH0Mk+odutAilXRBn/4saLaPmNzqBBll5KL9 J71skq8LTcIgRhX8w9TEojiGhWgktvPUXByomgqBT/iIfBGh7IgNT+QEiPeUASGe2UK3 9/UGcRrWxUAx4UESu5l8c5Xe9cflkyGv8FCKFu1UcJXd0io1a1So0iZEhGgfetTPLu9M M4WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9W3gRWmGUweo497W/5hFRRz/NYJ+5R4fTtzWnF2at2E=; b=RBl2V5MOxuy3+Du+TlSF2vltPEXKcOmH/dDGfgqPnFu8u+7gti6+zycy2ly0N1piJt pdLa4XDHy72kR0ceSeVt7SOy0KxCKNtUmbHUZxWb619j/PpyOTW2JD4mr6lnPKSpoxUG vTcGtj32cWbVeE8t+gn64lQn8I5dG4SkyotpLBQVRj3qn6NJts4/jBavhY+YNmyrZEAa 0SJccneKtVY8MLd4vZ0ZYg8HQRapBG/F/TsNkRp5O7hvELgfed2G+NGoo4cKoKVkkVO8 8diHiZAp5nD4E7wGa4PUFGKY8KSmjufSjOG5Es0TqibQR2l8HdqDQ1HHRt+eCialYUin cj6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nKKV59eq; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt2-20020a170907728200b0072a47b13d67si19644799ejc.582.2022.07.04.00.07.44; Mon, 04 Jul 2022 00:08:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nKKV59eq; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232593AbiGDHHd (ORCPT + 99 others); Mon, 4 Jul 2022 03:07:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232546AbiGDHHc (ORCPT ); Mon, 4 Jul 2022 03:07:32 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F104E66 for ; Mon, 4 Jul 2022 00:07:31 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d17so8139859pfq.9 for ; Mon, 04 Jul 2022 00:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9W3gRWmGUweo497W/5hFRRz/NYJ+5R4fTtzWnF2at2E=; b=nKKV59eqrRGyihZiPUos1JCkNwWlbj4nSA4W3XfrejIVu48f7af7Iv/6RrX2YPoOiz FUTg69Bed8gQYhkRm/EytrzpAXUo1JNJ7j9uwoUwX4Jf6l76ev7INsw0m3m8oE7qMTP3 zeGpeSB93C1BVIWy1AxUmGQi7xgv3MNEZqQEDOuMxO3x8jJUswCyXFzKnwPv+3lFKflI wTi55zWvn1OZkru297UXm7U2GQmvtdVuS4LpErKr7F67D81m2DgVVn2Xt46/jsBRABbQ R+Ss8tW+SxqszH4+J3eu1O7b+8FArwEc+b9MwyVF4xVraRF98XPdTFdx7lCFkGhZjT7S XdkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9W3gRWmGUweo497W/5hFRRz/NYJ+5R4fTtzWnF2at2E=; b=avmJ6Bm19HYQ/Z6ThIK3WljOUkzCkd898kxfXdRCXO7NXGSrg5jj5xMPdEEvEt3vHB a4PpJlJExovZNgljSoDmqwj5eIxrpqmkbnkzb2BCMyWRn/Vffw6gvZ7daSt3Pkh5e5Ce cczi+k/wVwSa/PL5Ti18fHD2kDhL5KotQXnASzfJQojqu+wFcaCV1NAdBFvy+gpdT1Vf mWj36t8AHnQgQ5H5OZHQHsU52O5RsR+iStcKmI7vT/jSW0Mbp+MdTjswJGOsjf2xXEbN 6UX3o1ueKTtzlyZQp4EfwEpTNAYHXm8jIsojUfEYID8fnvVfbOyDrigiwXZRbUEy8SN+ 9LxQ== X-Gm-Message-State: AJIora9/VA3bLZbc41hCufDjXRnEjat7mI7Nv90Jlha79C8ZGSdmo8+h cg3wZSah9MDLQfJXrrO/Y7F4BafCSPI= X-Received: by 2002:a05:6a00:2407:b0:528:5bbc:aa0d with SMTP id z7-20020a056a00240700b005285bbcaa0dmr7514549pfh.40.1656918451143; Mon, 04 Jul 2022 00:07:31 -0700 (PDT) Received: from localhost ([2406:7400:63:cb1d:811:33e9:9bc2:d40]) by smtp.gmail.com with ESMTPSA id e7-20020a170902784700b0015eab1b097dsm20317725pln.22.2022.07.04.00.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 00:07:30 -0700 (PDT) From: Ritesh Harjani To: Theodore Ts'o Cc: Harshad Shirwadkar , Andreas Dilger , linux-ext4 , Ritesh Harjani Subject: [RFC 03/13] blkmap64_ba: Add common helper for bits size calculation Date: Mon, 4 Jul 2022 12:36:52 +0530 Message-Id: <2418fae44393d8696cc848b682a24e58d334e1a2.1656912918.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Just a quick common helper for bits size calculation. Signed-off-by: Ritesh Harjani --- lib/ext2fs/blkmap64_ba.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/ext2fs/blkmap64_ba.c b/lib/ext2fs/blkmap64_ba.c index 5d8f1548..4e7007f0 100644 --- a/lib/ext2fs/blkmap64_ba.c +++ b/lib/ext2fs/blkmap64_ba.c @@ -40,6 +40,13 @@ struct ext2fs_ba_private_struct { typedef struct ext2fs_ba_private_struct *ext2fs_ba_private; +#define ba_bits_size(start, end) ((((end) - (start)) / 8 + 1)) + +static size_t ba_bitmap_size(ext2fs_generic_bitmap_64 bitmap) +{ + return (size_t) ba_bits_size(bitmap->start, bitmap->real_end); +} + static errcode_t ba_alloc_private_data (ext2fs_generic_bitmap_64 bitmap) { ext2fs_ba_private bp; @@ -56,7 +63,7 @@ static errcode_t ba_alloc_private_data (ext2fs_generic_bitmap_64 bitmap) if (retval) return retval; - size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1); + size = ba_bitmap_size(bitmap); retval = ext2fs_get_mem(size, &bp->bitarray); if (retval) { @@ -80,7 +87,7 @@ static errcode_t ba_new_bmap(ext2_filsys fs EXT2FS_ATTR((unused)), return retval; bp = (ext2fs_ba_private) bitmap->private; - size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1); + size = ba_bitmap_size(bitmap); memset(bp->bitarray, 0, size); return 0; @@ -115,7 +122,7 @@ static errcode_t ba_copy_bmap(ext2fs_generic_bitmap_64 src, dest_bp = (ext2fs_ba_private) dest->private; - size = (size_t) (((src->real_end - src->start) / 8) + 1); + size = ba_bitmap_size(src); memcpy (dest_bp->bitarray, src_bp->bitarray, size); return 0; @@ -145,8 +152,8 @@ static errcode_t ba_resize_bmap(ext2fs_generic_bitmap_64 bmap, return 0; } - size = ((bmap->real_end - bmap->start) / 8) + 1; - new_size = ((new_real_end - bmap->start) / 8) + 1; + size = ba_bitmap_size(bmap); + new_size = ba_bits_size(new_real_end, bmap->start); if (size != new_size) { retval = ext2fs_resize_mem(size, new_size, &bp->bitarray); @@ -306,8 +313,7 @@ static void ba_clear_bmap(ext2fs_generic_bitmap_64 bitmap) { ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; - memset(bp->bitarray, 0, - (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1)); + memset(bp->bitarray, 0, ba_bitmap_size(bitmap)); } #ifdef ENABLE_BMAP_STATS -- 2.35.3