From patchwork Mon Nov 13 17:37:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 164577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1364339vqg; Mon, 13 Nov 2023 09:38:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+2t+sbenmiB6b792e21nLA3XsWn7Vh7FcfLSkop9TnU1LqVeCOX4PW8iDQWBD55VGchpz X-Received: by 2002:aa7:8184:0:b0:68e:496a:7854 with SMTP id g4-20020aa78184000000b0068e496a7854mr4563846pfi.18.1699897085309; Mon, 13 Nov 2023 09:38:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699897085; cv=none; d=google.com; s=arc-20160816; b=GQ6/QMCE7dXRz/XcLzhUp9gg0TG/OceeZwXVlDvJbzQ0m5zRv06TnEvP2bhEIWx4xv 1a16hVq88Fz9b0s2zFDb9zG9tRhvRI25nTbCGAELpiqhkJ87niP5sTziHElew1BqOajW vKF3aG1t9r/0PXyxA4j/HYNS8eZR8pN72y8dGA5g9ZQbLE9kXZoKTywgbMmbxWgWLLHy 47u495vWlmBLVTSrcZ8jwLddrsb4W3tgbTrHA4US25lQ25dg+G3wNymeZjqUIGaKRbMC kOnosttVf6eW644uAFGsQw9RQPjKvnbB7zGgJpdwIRhUHUq/v1dYmNq4fmD2MoF8vL51 rwwg== 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=s0ol6UVCvynEQyR7YiBxTLCIedLvnMkJZLFGRNnf/1I=; fh=7T8J1tID+HXiburls5V3xBaEKIOm4ZSfaNvYfh+9ozY=; b=XWiXkXY/gFrCx14XF19/7YSMzU01rXISbDwoPUJ1GTXi5eiwIGhezP4ow0B/SamCcB K+j5OqKZvlEm9eV9T0KUs4E2rGo96j8XDGxTnb7P5070ZoeCCtvJ516gHEhsgwAgAu2O VXYuuEWbpJhEgM/S3AoeWkJv0d3wfHdcRVcE2l5AtnfY+6zNi8UbJm3ea/6Xm7nuuxMP qjpW/VgvT72/au6HXMlUW8xJrYvjkzy37/vQLNqc29cTKMlJIxZwHLEfjxu4fevLqPyG ICoNij6QAzoYLJdk0Sw1DO2agcsFAIXUCLiyFO71iAmI+lTumdftZQwCjTWxv+jy1ZNO 88EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NxeAFITB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m14-20020a056a00080e00b006b70c01a08dsi6183950pfk.161.2023.11.13.09.38.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 09:38:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NxeAFITB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 696C0802E3FB; Mon, 13 Nov 2023 09:38:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232011AbjKMRiA (ORCPT + 30 others); Mon, 13 Nov 2023 12:38:00 -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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,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-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 13 Nov 2023 09:38:04 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782471286017814983 X-GMAIL-MSGID: 1782471286017814983 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 = nbits; wnd->extent_max = MINUS_ONE_T; wnd->zone_bit = wnd->zone_end = 0; - wnd->nwnd = bytes_to_block(sb, bitmap_size(nbits)); + wnd->nwnd = bytes_to_block(sb, ntfs3_bitmap_size(nbits)); wnd->bits_last = nbits & (wbits - 1); if (!wnd->bits_last) wnd->bits_last = wbits; @@ -1347,7 +1347,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits) return -EINVAL; /* Align to 8 byte boundary. */ - new_wnd = bytes_to_block(sb, bitmap_size(new_bits)); + new_wnd = bytes_to_block(sb, ntfs3_bitmap_size(new_bits)); new_last = new_bits & (wbits - 1); if (!new_last) new_last = 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 = true; /* Step 2: Resize $MFT::BITMAP. */ - new_bitmap_bytes = bitmap_size(new_mft_total); + new_bitmap_bytes = ntfs3_bitmap_size(new_mft_total); err = 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 *indx, struct ntfs_inode *ni, alloc->nres.valid_size = alloc->nres.data_size = cpu_to_le64(data_size); - err = ni_insert_resident(ni, bitmap_size(1), ATTR_BITMAP, in->name, - in->name_len, &bitmap, NULL, NULL); + err = ni_insert_resident(ni, ntfs3_bitmap_size(1), ATTR_BITMAP, + in->name, in->name_len, &bitmap, NULL, NULL); if (err) goto out2; @@ -1518,8 +1518,9 @@ static int indx_add_allocate(struct ntfs_index *indx, struct ntfs_inode *ni, if (bmp) { /* Increase bitmap. */ err = 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, struct ntfs_inode *ni, if (in->name == I30_NAME) ni->vfs_inode.i_size = new_data; - bpb = bitmap_size(bit); + bpb = ntfs3_bitmap_size(bit); if (bpb * 8 == nbits) return 0; 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) } /* 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); } #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, struct fs_context *fc) /* Check bitmap boundary. */ tt = 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 = -EINVAL; goto put_inode_out;