Skip to content

Commit 88a8d0d

Browse files
Thomas Kühnelaalexandrovich
authored andcommitted
fs/ntfs3: Add functions to modify LE bitmaps
__bitmap_set/__bitmap_clear only works with bitmaps in CPU order. Define a variant of these functions in ntfs3 to handle modifying bitmaps read from the filesystem. Signed-off-by: Thomas Kühnel <[email protected]> Reviewed-by: Nicolas Schier <[email protected]> Signed-off-by: Konstantin Komarov <[email protected]>
1 parent 90c1cd5 commit 88a8d0d

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

fs/ntfs3/bitmap.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
736736

737737
lock_buffer(bh);
738738

739-
__bitmap_clear(buf, wbit, op);
739+
ntfs_bitmap_clear_le(buf, wbit, op);
740740

741741
wnd->free_bits[iw] += op;
742742

@@ -788,7 +788,7 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
788788

789789
lock_buffer(bh);
790790

791-
__bitmap_set(buf, wbit, op);
791+
ntfs_bitmap_set_le(buf, wbit, op);
792792
wnd->free_bits[iw] -= op;
793793

794794
set_buffer_uptodate(bh);
@@ -1363,7 +1363,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
13631363
lock_buffer(bh);
13641364
buf = (ulong *)bh->b_data;
13651365

1366-
__bitmap_clear(buf, b0, blocksize * 8 - b0);
1366+
ntfs_bitmap_clear_le(buf, b0, blocksize * 8 - b0);
13671367
frb = wbits - __bitmap_weight(buf, wbits);
13681368
wnd->total_zeroes += frb - wnd->free_bits[iw];
13691369
wnd->free_bits[iw] = frb;
@@ -1481,3 +1481,43 @@ int ntfs_trim_fs(struct ntfs_sb_info *sbi, struct fstrim_range *range)
14811481

14821482
return err;
14831483
}
1484+
1485+
void ntfs_bitmap_set_le(unsigned long *map, unsigned int start, int len)
1486+
{
1487+
unsigned long *p = map + BIT_WORD(start);
1488+
const unsigned int size = start + len;
1489+
int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
1490+
unsigned long mask_to_set = cpu_to_le32(BITMAP_FIRST_WORD_MASK(start));
1491+
1492+
while (len - bits_to_set >= 0) {
1493+
*p |= mask_to_set;
1494+
len -= bits_to_set;
1495+
bits_to_set = BITS_PER_LONG;
1496+
mask_to_set = ~0UL;
1497+
p++;
1498+
}
1499+
if (len) {
1500+
mask_to_set &= cpu_to_le32(BITMAP_LAST_WORD_MASK(size));
1501+
*p |= mask_to_set;
1502+
}
1503+
}
1504+
1505+
void ntfs_bitmap_clear_le(unsigned long *map, unsigned int start, int len)
1506+
{
1507+
unsigned long *p = map + BIT_WORD(start);
1508+
const unsigned int size = start + len;
1509+
int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
1510+
unsigned long mask_to_clear = cpu_to_le32(BITMAP_FIRST_WORD_MASK(start));
1511+
1512+
while (len - bits_to_clear >= 0) {
1513+
*p &= ~mask_to_clear;
1514+
len -= bits_to_clear;
1515+
bits_to_clear = BITS_PER_LONG;
1516+
mask_to_clear = ~0UL;
1517+
p++;
1518+
}
1519+
if (len) {
1520+
mask_to_clear &= cpu_to_le32(BITMAP_LAST_WORD_MASK(size));
1521+
*p &= ~mask_to_clear;
1522+
}
1523+
}

fs/ntfs3/fslog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3624,7 +3624,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
36243624
goto dirty_vol;
36253625
}
36263626

3627-
__bitmap_set(Add2Ptr(buffer_le, roff), off, bits);
3627+
ntfs_bitmap_set_le(Add2Ptr(buffer_le, roff), off, bits);
36283628
a_dirty = true;
36293629
break;
36303630

@@ -3637,7 +3637,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
36373637
goto dirty_vol;
36383638
}
36393639

3640-
__bitmap_clear(Add2Ptr(buffer_le, roff), off, bits);
3640+
ntfs_bitmap_clear_le(Add2Ptr(buffer_le, roff), off, bits);
36413641
a_dirty = true;
36423642
break;
36433643

fs/ntfs3/ntfs_fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits);
839839
void wnd_zone_set(struct wnd_bitmap *wnd, size_t Lcn, size_t Len);
840840
int ntfs_trim_fs(struct ntfs_sb_info *sbi, struct fstrim_range *range);
841841

842+
void ntfs_bitmap_set_le(unsigned long *map, unsigned int start, int len);
843+
void ntfs_bitmap_clear_le(unsigned long *map, unsigned int start, int len);
844+
842845
/* Globals from upcase.c */
843846
int ntfs_cmp_names(const __le16 *s1, size_t l1, const __le16 *s2, size_t l2,
844847
const u16 *upcase, bool bothcase);

0 commit comments

Comments
 (0)