From nobody Wed Dec 31 00:37:15 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 526C3C4332F for ; Mon, 13 Nov 2023 17:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232032AbjKMRiB (ORCPT ); Mon, 13 Nov 2023 12:38:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231745AbjKMRhr (ORCPT ); Mon, 13 Nov 2023 12:37:47 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1679819A7; Mon, 13 Nov 2023 09:37:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699897063; x=1731433063; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eF/TA+8XfUedFbqrzYuYUb78X0CRiVueaoHeJnxBGYU=; b=NxeAFITBG4Jvt+Iy28MRGpWfBFYZm3VCGSD4Y1GCF7v5uC+VzY9Dfq/E 0E9KAyLBe78x14OWLvDaAcnqt/ital6etz7s6WUQnu9/r7gyWg5RcIhkj yoS4BnLB5FCLN+BBlCNaDr8dOB7c+GLukji9Mvhw4MOCXfc+oakKrnmB4 HbtTUOxHX6WYKk/Im4cUg2/fQfb8EOfVuPuv/pdZi5TUBYIR0uxgNex/E xA8HmETtoicOQBQiR4Loxy0ef8Vbdzfdu6M+m1YsrUScvs4WQgGSBoGNW i98UCYPalWaozQjQvcXXR9n4tQxl8vOAsHJfSfkEuYv4RgWi+9lb76mWT A==; X-IronPort-AV: E=McAfee;i="6600,9927,10893"; a="370671586" X-IronPort-AV: E=Sophos;i="6.03,299,1694761200"; d="scan'208";a="370671586" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2023 09:37:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10893"; a="1095812682" X-IronPort-AV: E=Sophos;i="6.03,299,1694761200"; d="scan'208";a="1095812682" Received: from newjersey.igk.intel.com ([10.102.20.203]) by fmsmga005.fm.intel.com with ESMTP; 13 Nov 2023 09:37:39 -0800 From: Alexander Lobakin To: Yury Norov Cc: Alexander Lobakin , Andy Shevchenko , Rasmus Villemoes , Alexander Potapenko , Jakub Kicinski , Przemek Kitszel , netdev@vger.kernel.org, linux-btrfs@vger.kernel.org, dm-devel@redhat.com, ntfs3@lists.linux.dev, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 06/11] fs/ntfs3: add prefix to bitmap_size() and use BITS_TO_U64() Date: Mon, 13 Nov 2023 18:37:12 +0100 Message-ID: <20231113173717.927056-7-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231113173717.927056-1-aleksander.lobakin@intel.com> References: <20231113173717.927056-1-aleksander.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" bitmap_size() is a pretty generic name and one may want to use it for a generic bitmap API function. At the same time, its logic is NTFS-specific, as it aligns to the sizeof(u64), not the sizeof(long) (although it uses ideologically right ALIGN() instead of division). Add the prefix 'ntfs3_' used for that FS (not just 'ntfs_' to not mix it with the legacy module) and use generic BITS_TO_U64() while at it. Suggested-by: Yury Norov # BITS_TO_U64() Reviewed-by: Przemek Kitszel Signed-off-by: Alexander Lobakin --- fs/ntfs3/bitmap.c | 4 ++-- fs/ntfs3/fsntfs.c | 2 +- fs/ntfs3/index.c | 11 ++++++----- fs/ntfs3/ntfs_fs.h | 4 ++-- fs/ntfs3/super.c | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c index 63f14a0232f6..a19a73ed630b 100644 --- a/fs/ntfs3/bitmap.c +++ b/fs/ntfs3/bitmap.c @@ -654,7 +654,7 @@ int wnd_init(struct wnd_bitmap *wnd, struct super_block= *sb, size_t nbits) wnd->total_zeroes =3D nbits; wnd->extent_max =3D MINUS_ONE_T; wnd->zone_bit =3D wnd->zone_end =3D 0; - wnd->nwnd =3D bytes_to_block(sb, bitmap_size(nbits)); + wnd->nwnd =3D bytes_to_block(sb, ntfs3_bitmap_size(nbits)); wnd->bits_last =3D nbits & (wbits - 1); if (!wnd->bits_last) wnd->bits_last =3D wbits; @@ -1347,7 +1347,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bit= s) return -EINVAL; =20 /* Align to 8 byte boundary. */ - new_wnd =3D bytes_to_block(sb, bitmap_size(new_bits)); + new_wnd =3D bytes_to_block(sb, ntfs3_bitmap_size(new_bits)); new_last =3D new_bits & (wbits - 1); if (!new_last) new_last =3D wbits; diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index fbfe21dbb425..e18de9c4c2fa 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -522,7 +522,7 @@ static int ntfs_extend_mft(struct ntfs_sb_info *sbi) ni->mi.dirty =3D true; =20 /* Step 2: Resize $MFT::BITMAP. */ - new_bitmap_bytes =3D bitmap_size(new_mft_total); + new_bitmap_bytes =3D ntfs3_bitmap_size(new_mft_total); =20 err =3D attr_set_size(ni, ATTR_BITMAP, NULL, 0, &sbi->mft.bitmap.run, new_bitmap_bytes, &new_bitmap_bytes, true, NULL); diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index cf92b2433f7a..e0cef8f4e414 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -1456,8 +1456,8 @@ static int indx_create_allocate(struct ntfs_index *in= dx, struct ntfs_inode *ni, =20 alloc->nres.valid_size =3D alloc->nres.data_size =3D cpu_to_le64(data_siz= e); =20 - err =3D ni_insert_resident(ni, bitmap_size(1), ATTR_BITMAP, in->name, - in->name_len, &bitmap, NULL, NULL); + err =3D ni_insert_resident(ni, ntfs3_bitmap_size(1), ATTR_BITMAP, + in->name, in->name_len, &bitmap, NULL, NULL); if (err) goto out2; =20 @@ -1518,8 +1518,9 @@ static int indx_add_allocate(struct ntfs_index *indx,= struct ntfs_inode *ni, if (bmp) { /* Increase bitmap. */ err =3D attr_set_size(ni, ATTR_BITMAP, in->name, in->name_len, - &indx->bitmap_run, bitmap_size(bit + 1), - NULL, true, NULL); + &indx->bitmap_run, + ntfs3_bitmap_size(bit + 1), NULL, true, + NULL); if (err) goto out1; } @@ -2092,7 +2093,7 @@ static int indx_shrink(struct ntfs_index *indx, struc= t ntfs_inode *ni, if (in->name =3D=3D I30_NAME) ni->vfs_inode.i_size =3D new_data; =20 - bpb =3D bitmap_size(bit); + bpb =3D ntfs3_bitmap_size(bit); if (bpb * 8 =3D=3D nbits) return 0; =20 diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index f6706143d14b..16b84d605cd2 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -961,9 +961,9 @@ static inline bool run_is_empty(struct runs_tree *run) } =20 /* NTFS uses quad aligned bitmaps. */ -static inline size_t bitmap_size(size_t bits) +static inline size_t ntfs3_bitmap_size(size_t bits) { - return ALIGN((bits + 7) >> 3, 8); + return BITS_TO_U64(bits) * sizeof(u64); } =20 #define _100ns2seconds 10000000 diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 9153dffde950..0248db1e5c01 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -1331,7 +1331,7 @@ static int ntfs_fill_super(struct super_block *sb, st= ruct fs_context *fc) =20 /* Check bitmap boundary. */ tt =3D sbi->used.bitmap.nbits; - if (inode->i_size < bitmap_size(tt)) { + if (inode->i_size < ntfs3_bitmap_size(tt)) { ntfs_err(sb, "$Bitmap is corrupted."); err =3D -EINVAL; goto put_inode_out; --=20 2.41.0