@@ -710,20 +710,17 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
710
710
{
711
711
int err = 0 ;
712
712
struct super_block * sb = wnd -> sb ;
713
- size_t bits0 = bits ;
714
713
u32 wbits = 8 * sb -> s_blocksize ;
715
714
size_t iw = bit >> (sb -> s_blocksize_bits + 3 );
716
715
u32 wbit = bit & (wbits - 1 );
717
716
struct buffer_head * bh ;
717
+ u32 op ;
718
718
719
- while (iw < wnd -> nwnd && bits ) {
720
- u32 tail , op ;
721
-
719
+ for (; iw < wnd -> nwnd && bits ; iw ++ , bit += op , bits -= op , wbit = 0 ) {
722
720
if (iw + 1 == wnd -> nwnd )
723
721
wbits = wnd -> bits_last ;
724
722
725
- tail = wbits - wbit ;
726
- op = min_t (u32 , tail , bits );
723
+ op = min_t (u32 , wbits - wbit , bits );
727
724
728
725
bh = wnd_map (wnd , iw );
729
726
if (IS_ERR (bh )) {
@@ -736,20 +733,15 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
736
733
ntfs_bitmap_clear_le (bh -> b_data , wbit , op );
737
734
738
735
wnd -> free_bits [iw ] += op ;
736
+ wnd -> total_zeroes += op ;
739
737
740
738
set_buffer_uptodate (bh );
741
739
mark_buffer_dirty (bh );
742
740
unlock_buffer (bh );
743
741
put_bh (bh );
744
742
745
- wnd -> total_zeroes += op ;
746
- bits -= op ;
747
- wbit = 0 ;
748
- iw += 1 ;
743
+ wnd_add_free_ext (wnd , bit , op , false);
749
744
}
750
-
751
- wnd_add_free_ext (wnd , bit , bits0 , false);
752
-
753
745
return err ;
754
746
}
755
747
@@ -760,20 +752,17 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
760
752
{
761
753
int err = 0 ;
762
754
struct super_block * sb = wnd -> sb ;
763
- size_t bits0 = bits ;
764
755
size_t iw = bit >> (sb -> s_blocksize_bits + 3 );
765
756
u32 wbits = 8 * sb -> s_blocksize ;
766
757
u32 wbit = bit & (wbits - 1 );
767
758
struct buffer_head * bh ;
759
+ u32 op ;
768
760
769
- while (iw < wnd -> nwnd && bits ) {
770
- u32 tail , op ;
771
-
761
+ for (; iw < wnd -> nwnd && bits ; iw ++ , bit += op , bits -= op , wbit = 0 ) {
772
762
if (unlikely (iw + 1 == wnd -> nwnd ))
773
763
wbits = wnd -> bits_last ;
774
764
775
- tail = wbits - wbit ;
776
- op = min_t (u32 , tail , bits );
765
+ op = min_t (u32 , wbits - wbit , bits );
777
766
778
767
bh = wnd_map (wnd , iw );
779
768
if (IS_ERR (bh )) {
@@ -785,21 +774,16 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
785
774
786
775
ntfs_bitmap_set_le (bh -> b_data , wbit , op );
787
776
wnd -> free_bits [iw ] -= op ;
777
+ wnd -> total_zeroes -= op ;
788
778
789
779
set_buffer_uptodate (bh );
790
780
mark_buffer_dirty (bh );
791
781
unlock_buffer (bh );
792
782
put_bh (bh );
793
783
794
- wnd -> total_zeroes -= op ;
795
- bits -= op ;
796
- wbit = 0 ;
797
- iw += 1 ;
784
+ if (!RB_EMPTY_ROOT (& wnd -> start_tree ))
785
+ wnd_remove_free_ext (wnd , bit , op );
798
786
}
799
-
800
- if (!RB_EMPTY_ROOT (& wnd -> start_tree ))
801
- wnd_remove_free_ext (wnd , bit , bits0 );
802
-
803
787
return err ;
804
788
}
805
789
@@ -852,15 +836,13 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits)
852
836
size_t iw = bit >> (sb -> s_blocksize_bits + 3 );
853
837
u32 wbits = 8 * sb -> s_blocksize ;
854
838
u32 wbit = bit & (wbits - 1 );
839
+ u32 op ;
855
840
856
- while (iw < wnd -> nwnd && bits ) {
857
- u32 tail , op ;
858
-
841
+ for (; iw < wnd -> nwnd && bits ; iw ++ , bits -= op , wbit = 0 ) {
859
842
if (unlikely (iw + 1 == wnd -> nwnd ))
860
843
wbits = wnd -> bits_last ;
861
844
862
- tail = wbits - wbit ;
863
- op = min_t (u32 , tail , bits );
845
+ op = min_t (u32 , wbits - wbit , bits );
864
846
865
847
if (wbits != wnd -> free_bits [iw ]) {
866
848
bool ret ;
@@ -875,10 +857,6 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits)
875
857
if (!ret )
876
858
return false;
877
859
}
878
-
879
- bits -= op ;
880
- wbit = 0 ;
881
- iw += 1 ;
882
860
}
883
861
884
862
return true;
@@ -928,6 +906,7 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
928
906
size_t iw = bit >> (sb -> s_blocksize_bits + 3 );
929
907
u32 wbits = 8 * sb -> s_blocksize ;
930
908
u32 wbit = bit & (wbits - 1 );
909
+ u32 op ;
931
910
size_t end ;
932
911
struct rb_node * n ;
933
912
struct e_node * e ;
@@ -945,14 +924,11 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
945
924
return false;
946
925
947
926
use_wnd :
948
- while (iw < wnd -> nwnd && bits ) {
949
- u32 tail , op ;
950
-
927
+ for (; iw < wnd -> nwnd && bits ; iw ++ , bits -= op , wbit = 0 ) {
951
928
if (unlikely (iw + 1 == wnd -> nwnd ))
952
929
wbits = wnd -> bits_last ;
953
930
954
- tail = wbits - wbit ;
955
- op = min_t (u32 , tail , bits );
931
+ op = min_t (u32 , wbits - wbit , bits );
956
932
957
933
if (wnd -> free_bits [iw ]) {
958
934
bool ret ;
@@ -966,10 +942,6 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
966
942
if (!ret )
967
943
goto out ;
968
944
}
969
-
970
- bits -= op ;
971
- wbit = 0 ;
972
- iw += 1 ;
973
945
}
974
946
ret = true;
975
947
0 commit comments