@@ -59,7 +59,7 @@ void ntfs3_exit_bitmap(void)
59
59
*
60
60
* Return: -1 if not found.
61
61
*/
62
- static size_t wnd_scan (const ulong * buf , size_t wbit , u32 wpos , u32 wend ,
62
+ static size_t wnd_scan (const void * buf , size_t wbit , u32 wpos , u32 wend ,
63
63
size_t to_alloc , size_t * prev_tail , size_t * b_pos ,
64
64
size_t * b_len )
65
65
{
@@ -504,7 +504,6 @@ static int wnd_rescan(struct wnd_bitmap *wnd)
504
504
u8 cluster_bits = sbi -> cluster_bits ;
505
505
u32 wbits = 8 * sb -> s_blocksize ;
506
506
u32 used , frb ;
507
- const ulong * buf ;
508
507
size_t wpos , wbit , iw , vbo ;
509
508
struct buffer_head * bh = NULL ;
510
509
CLST lcn , clen ;
@@ -558,9 +557,7 @@ static int wnd_rescan(struct wnd_bitmap *wnd)
558
557
goto out ;
559
558
}
560
559
561
- buf = (ulong * )bh -> b_data ;
562
-
563
- used = __bitmap_weight (buf , wbits );
560
+ used = ntfs_bitmap_weight_le (bh -> b_data , wbits );
564
561
if (used < wbits ) {
565
562
frb = wbits - used ;
566
563
wnd -> free_bits [iw ] = frb ;
@@ -574,7 +571,7 @@ static int wnd_rescan(struct wnd_bitmap *wnd)
574
571
wbits = wnd -> nbits - wbit ;
575
572
576
573
do {
577
- used = find_next_zero_bit_le (buf , wbits , wpos );
574
+ used = find_next_zero_bit_le (bh -> b_data , wbits , wpos );
578
575
579
576
if (used > wpos && prev_tail ) {
580
577
wnd_add_free_ext (wnd , wbit + wpos - prev_tail ,
@@ -590,7 +587,7 @@ static int wnd_rescan(struct wnd_bitmap *wnd)
590
587
break ;
591
588
}
592
589
593
- frb = find_next_bit_le (buf , wbits , wpos );
590
+ frb = find_next_bit_le (bh -> b_data , wbits , wpos );
594
591
if (frb >= wbits ) {
595
592
/* Keep last free block. */
596
593
prev_tail += frb - wpos ;
@@ -718,7 +715,6 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
718
715
719
716
while (iw < wnd -> nwnd && bits ) {
720
717
u32 tail , op ;
721
- ulong * buf ;
722
718
723
719
if (iw + 1 == wnd -> nwnd )
724
720
wbits = wnd -> bits_last ;
@@ -732,11 +728,9 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
732
728
break ;
733
729
}
734
730
735
- buf = (ulong * )bh -> b_data ;
736
-
737
731
lock_buffer (bh );
738
732
739
- ntfs_bitmap_clear_le (buf , wbit , op );
733
+ ntfs_bitmap_clear_le (bh -> b_data , wbit , op );
740
734
741
735
wnd -> free_bits [iw ] += op ;
742
736
@@ -771,7 +765,6 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
771
765
772
766
while (iw < wnd -> nwnd && bits ) {
773
767
u32 tail , op ;
774
- ulong * buf ;
775
768
776
769
if (unlikely (iw + 1 == wnd -> nwnd ))
777
770
wbits = wnd -> bits_last ;
@@ -784,11 +777,10 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
784
777
err = PTR_ERR (bh );
785
778
break ;
786
779
}
787
- buf = (ulong * )bh -> b_data ;
788
780
789
781
lock_buffer (bh );
790
782
791
- ntfs_bitmap_set_le (buf , wbit , op );
783
+ ntfs_bitmap_set_le (bh -> b_data , wbit , op );
792
784
wnd -> free_bits [iw ] -= op ;
793
785
794
786
set_buffer_uptodate (bh );
@@ -836,7 +828,7 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits)
836
828
if (IS_ERR (bh ))
837
829
return false;
838
830
839
- ret = are_bits_clear (( ulong * ) bh -> b_data , wbit , op );
831
+ ret = are_bits_clear (bh -> b_data , wbit , op );
840
832
841
833
put_bh (bh );
842
834
if (!ret )
@@ -928,7 +920,7 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
928
920
if (IS_ERR (bh ))
929
921
goto out ;
930
922
931
- ret = are_bits_set (( ulong * ) bh -> b_data , wbit , op );
923
+ ret = are_bits_set (bh -> b_data , wbit , op );
932
924
put_bh (bh );
933
925
if (!ret )
934
926
goto out ;
@@ -959,7 +951,6 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
959
951
size_t fnd , max_alloc , b_len , b_pos ;
960
952
size_t iw , prev_tail , nwnd , wbit , ebit , zbit , zend ;
961
953
size_t to_alloc0 = to_alloc ;
962
- const ulong * buf ;
963
954
const struct e_node * e ;
964
955
const struct rb_node * pr , * cr ;
965
956
u8 log2_bits ;
@@ -1185,14 +1176,13 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
1185
1176
continue ;
1186
1177
}
1187
1178
1188
- buf = (ulong * )bh -> b_data ;
1189
-
1190
1179
/* Scan range [wbit, zbit). */
1191
1180
if (wpos < wzbit ) {
1192
1181
/* Scan range [wpos, zbit). */
1193
- fnd = wnd_scan (buf , wbit , wpos , wzbit ,
1194
- to_alloc , & prev_tail ,
1195
- & b_pos , & b_len );
1182
+ fnd = wnd_scan (bh -> b_data , wbit , wpos ,
1183
+ wzbit , to_alloc ,
1184
+ & prev_tail , & b_pos ,
1185
+ & b_len );
1196
1186
if (fnd != MINUS_ONE_T ) {
1197
1187
put_bh (bh );
1198
1188
goto found ;
@@ -1203,7 +1193,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
1203
1193
1204
1194
/* Scan range [zend, ebit). */
1205
1195
if (wzend < wbits ) {
1206
- fnd = wnd_scan (buf , wbit ,
1196
+ fnd = wnd_scan (bh -> b_data , wbit ,
1207
1197
max (wzend , wpos ), wbits ,
1208
1198
to_alloc , & prev_tail ,
1209
1199
& b_pos , & b_len );
@@ -1242,11 +1232,9 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
1242
1232
continue ;
1243
1233
}
1244
1234
1245
- buf = (ulong * )bh -> b_data ;
1246
-
1247
1235
/* Scan range [wpos, eBits). */
1248
- fnd = wnd_scan (buf , wbit , wpos , wbits , to_alloc , & prev_tail ,
1249
- & b_pos , & b_len );
1236
+ fnd = wnd_scan (bh -> b_data , wbit , wpos , wbits , to_alloc ,
1237
+ & prev_tail , & b_pos , & b_len );
1250
1238
put_bh (bh );
1251
1239
if (fnd != MINUS_ONE_T )
1252
1240
goto found ;
@@ -1344,7 +1332,6 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
1344
1332
size_t frb ;
1345
1333
u64 vbo , lbo , bytes ;
1346
1334
struct buffer_head * bh ;
1347
- ulong * buf ;
1348
1335
1349
1336
if (iw + 1 == new_wnd )
1350
1337
wbits = new_last ;
@@ -1361,10 +1348,9 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
1361
1348
return - EIO ;
1362
1349
1363
1350
lock_buffer (bh );
1364
- buf = (ulong * )bh -> b_data ;
1365
1351
1366
- ntfs_bitmap_clear_le (buf , b0 , blocksize * 8 - b0 );
1367
- frb = wbits - __bitmap_weight ( buf , wbits );
1352
+ ntfs_bitmap_clear_le (bh -> b_data , b0 , blocksize * 8 - b0 );
1353
+ frb = wbits - ntfs_bitmap_weight_le ( bh -> b_data , wbits );
1368
1354
wnd -> total_zeroes += frb - wnd -> free_bits [iw ];
1369
1355
wnd -> free_bits [iw ] = frb ;
1370
1356
@@ -1411,7 +1397,6 @@ int ntfs_trim_fs(struct ntfs_sb_info *sbi, struct fstrim_range *range)
1411
1397
CLST lcn_from = bytes_to_cluster (sbi , range -> start );
1412
1398
size_t iw = lcn_from >> (sb -> s_blocksize_bits + 3 );
1413
1399
u32 wbit = lcn_from & (wbits - 1 );
1414
- const ulong * buf ;
1415
1400
CLST lcn_to ;
1416
1401
1417
1402
if (!minlen )
@@ -1446,10 +1431,8 @@ int ntfs_trim_fs(struct ntfs_sb_info *sbi, struct fstrim_range *range)
1446
1431
break ;
1447
1432
}
1448
1433
1449
- buf = (ulong * )bh -> b_data ;
1450
-
1451
1434
for (; wbit < wbits ; wbit ++ ) {
1452
- if (!test_bit_le (wbit , buf )) {
1435
+ if (!test_bit_le (wbit , bh -> b_data )) {
1453
1436
if (!len )
1454
1437
lcn = lcn_wnd + wbit ;
1455
1438
len += 1 ;
@@ -1482,42 +1465,69 @@ int ntfs_trim_fs(struct ntfs_sb_info *sbi, struct fstrim_range *range)
1482
1465
return err ;
1483
1466
}
1484
1467
1485
- void ntfs_bitmap_set_le (unsigned long * map , unsigned int start , int len )
1468
+ #if BITS_PER_LONG == 64
1469
+ typedef __le64 bitmap_ulong ;
1470
+ #define cpu_to_ul (x ) cpu_to_le64(x)
1471
+ #define ul_to_cpu (x ) le64_to_cpu(x)
1472
+ #else
1473
+ typedef __le32 bitmap_ulong ;
1474
+ #define cpu_to_ul (x ) cpu_to_le32(x)
1475
+ #define ul_to_cpu (x ) le32_to_cpu(x)
1476
+ #endif
1477
+
1478
+ void ntfs_bitmap_set_le (void * map , unsigned int start , int len )
1486
1479
{
1487
- unsigned long * p = map + BIT_WORD (start );
1480
+ bitmap_ulong * p = ( bitmap_ulong * ) map + BIT_WORD (start );
1488
1481
const unsigned int size = start + len ;
1489
1482
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 ));
1483
+ bitmap_ulong mask_to_set = cpu_to_ul (BITMAP_FIRST_WORD_MASK (start ));
1491
1484
1492
1485
while (len - bits_to_set >= 0 ) {
1493
1486
* p |= mask_to_set ;
1494
1487
len -= bits_to_set ;
1495
1488
bits_to_set = BITS_PER_LONG ;
1496
- mask_to_set = ~0UL ;
1489
+ mask_to_set = cpu_to_ul ( ~0UL ) ;
1497
1490
p ++ ;
1498
1491
}
1499
1492
if (len ) {
1500
- mask_to_set &= cpu_to_le32 (BITMAP_LAST_WORD_MASK (size ));
1493
+ mask_to_set &= cpu_to_ul (BITMAP_LAST_WORD_MASK (size ));
1501
1494
* p |= mask_to_set ;
1502
1495
}
1503
1496
}
1504
1497
1505
- void ntfs_bitmap_clear_le (unsigned long * map , unsigned int start , int len )
1498
+ void ntfs_bitmap_clear_le (void * map , unsigned int start , int len )
1506
1499
{
1507
- unsigned long * p = map + BIT_WORD (start );
1500
+ bitmap_ulong * p = ( bitmap_ulong * ) map + BIT_WORD (start );
1508
1501
const unsigned int size = start + len ;
1509
1502
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 ));
1503
+ bitmap_ulong mask_to_clear = cpu_to_ul (BITMAP_FIRST_WORD_MASK (start ));
1511
1504
1512
1505
while (len - bits_to_clear >= 0 ) {
1513
1506
* p &= ~mask_to_clear ;
1514
1507
len -= bits_to_clear ;
1515
1508
bits_to_clear = BITS_PER_LONG ;
1516
- mask_to_clear = ~0UL ;
1509
+ mask_to_clear = cpu_to_ul ( ~0UL ) ;
1517
1510
p ++ ;
1518
1511
}
1519
1512
if (len ) {
1520
- mask_to_clear &= cpu_to_le32 (BITMAP_LAST_WORD_MASK (size ));
1513
+ mask_to_clear &= cpu_to_ul (BITMAP_LAST_WORD_MASK (size ));
1521
1514
* p &= ~mask_to_clear ;
1522
1515
}
1523
1516
}
1517
+
1518
+ unsigned int ntfs_bitmap_weight_le (const void * bitmap , int bits )
1519
+ {
1520
+ const ulong * bmp = bitmap ;
1521
+ unsigned int k , lim = bits / BITS_PER_LONG ;
1522
+ unsigned int w = 0 ;
1523
+
1524
+ for (k = 0 ; k < lim ; k ++ )
1525
+ w += hweight_long (bmp [k ]);
1526
+
1527
+ if (bits % BITS_PER_LONG ) {
1528
+ w += hweight_long (ul_to_cpu (((bitmap_ulong * )bitmap )[k ]) &
1529
+ BITMAP_LAST_WORD_MASK (bits ));
1530
+ }
1531
+
1532
+ return w ;
1533
+ }
0 commit comments