fs/ntfs3: add prefix to bitmap_size() and use BITS_TO_U64()
authorAlexander Lobakin <aleksander.lobakin@intel.com>
Wed, 27 Mar 2024 15:23:46 +0000 (16:23 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 1 Apr 2024 09:49:27 +0000 (10:49 +0100)
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 <yury.norov@gmail.com> # BITS_TO_U64()
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Reviewed-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
fs/ntfs3/bitmap.c
fs/ntfs3/fsntfs.c
fs/ntfs3/index.c
fs/ntfs3/ntfs_fs.h
fs/ntfs3/super.c

index 845f9b22deef0f42cabfb4156d4d8fe05c31fce9..c9eb01ccee51bb705be4c45534d15556305805b7 100644 (file)
@@ -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;
index ae2ef5c11868c360f1285feffae734b2974d0d5c..626d3f2c7e2d86aaf5a5a39953d82230e450c5b3 100644 (file)
@@ -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);
index daabaad63aaf64ae65b8d67bbd40de837bfe3486..43796aaa3d976b5646c921364891f3db4f9ee3a9 100644 (file)
@@ -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)
                i_size_write(&ni->vfs_inode, new_data);
 
-       bpb = bitmap_size(bit);
+       bpb = ntfs3_bitmap_size(bit);
        if (bpb * 8 == nbits)
                return 0;
 
index 79356fd29a14141de34ed006517b153fd9e4872b..ea5b5e814e6340b1b61c96ee3665bff3e5e1c05c 100644 (file)
@@ -966,9 +966,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
index 9df7c20d066f6125dda2406a0481e4eab300bb80..71dfeb0c432385271f1f1d994a00ac1e67475e65 100644 (file)
@@ -1341,7 +1341,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;