@@ -710,20 +710,17 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
710710{
711711 int err = 0 ;
712712 struct super_block * sb = wnd -> sb ;
713- size_t bits0 = bits ;
714713 u32 wbits = 8 * sb -> s_blocksize ;
715714 size_t iw = bit >> (sb -> s_blocksize_bits + 3 );
716715 u32 wbit = bit & (wbits - 1 );
717716 struct buffer_head * bh ;
717+ u32 op ;
718718
719- while (iw < wnd -> nwnd && bits ) {
720- u32 tail , op ;
721-
719+ for (; iw < wnd -> nwnd && bits ; iw ++ , bit += op , bits -= op , wbit = 0 ) {
722720 if (iw + 1 == wnd -> nwnd )
723721 wbits = wnd -> bits_last ;
724722
725- tail = wbits - wbit ;
726- op = min_t (u32 , tail , bits );
723+ op = min_t (u32 , wbits - wbit , bits );
727724
728725 bh = wnd_map (wnd , iw );
729726 if (IS_ERR (bh )) {
@@ -736,20 +733,15 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
736733 ntfs_bitmap_clear_le (bh -> b_data , wbit , op );
737734
738735 wnd -> free_bits [iw ] += op ;
736+ wnd -> total_zeroes += op ;
739737
740738 set_buffer_uptodate (bh );
741739 mark_buffer_dirty (bh );
742740 unlock_buffer (bh );
743741 put_bh (bh );
744742
745- wnd -> total_zeroes += op ;
746- bits -= op ;
747- wbit = 0 ;
748- iw += 1 ;
743+ wnd_add_free_ext (wnd , bit , op , false);
749744 }
750-
751- wnd_add_free_ext (wnd , bit , bits0 , false);
752-
753745 return err ;
754746}
755747
@@ -760,20 +752,17 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
760752{
761753 int err = 0 ;
762754 struct super_block * sb = wnd -> sb ;
763- size_t bits0 = bits ;
764755 size_t iw = bit >> (sb -> s_blocksize_bits + 3 );
765756 u32 wbits = 8 * sb -> s_blocksize ;
766757 u32 wbit = bit & (wbits - 1 );
767758 struct buffer_head * bh ;
759+ u32 op ;
768760
769- while (iw < wnd -> nwnd && bits ) {
770- u32 tail , op ;
771-
761+ for (; iw < wnd -> nwnd && bits ; iw ++ , bit += op , bits -= op , wbit = 0 ) {
772762 if (unlikely (iw + 1 == wnd -> nwnd ))
773763 wbits = wnd -> bits_last ;
774764
775- tail = wbits - wbit ;
776- op = min_t (u32 , tail , bits );
765+ op = min_t (u32 , wbits - wbit , bits );
777766
778767 bh = wnd_map (wnd , iw );
779768 if (IS_ERR (bh )) {
@@ -785,21 +774,16 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
785774
786775 ntfs_bitmap_set_le (bh -> b_data , wbit , op );
787776 wnd -> free_bits [iw ] -= op ;
777+ wnd -> total_zeroes -= op ;
788778
789779 set_buffer_uptodate (bh );
790780 mark_buffer_dirty (bh );
791781 unlock_buffer (bh );
792782 put_bh (bh );
793783
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 );
798786 }
799-
800- if (!RB_EMPTY_ROOT (& wnd -> start_tree ))
801- wnd_remove_free_ext (wnd , bit , bits0 );
802-
803787 return err ;
804788}
805789
@@ -852,15 +836,13 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits)
852836 size_t iw = bit >> (sb -> s_blocksize_bits + 3 );
853837 u32 wbits = 8 * sb -> s_blocksize ;
854838 u32 wbit = bit & (wbits - 1 );
839+ u32 op ;
855840
856- while (iw < wnd -> nwnd && bits ) {
857- u32 tail , op ;
858-
841+ for (; iw < wnd -> nwnd && bits ; iw ++ , bits -= op , wbit = 0 ) {
859842 if (unlikely (iw + 1 == wnd -> nwnd ))
860843 wbits = wnd -> bits_last ;
861844
862- tail = wbits - wbit ;
863- op = min_t (u32 , tail , bits );
845+ op = min_t (u32 , wbits - wbit , bits );
864846
865847 if (wbits != wnd -> free_bits [iw ]) {
866848 bool ret ;
@@ -875,10 +857,6 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits)
875857 if (!ret )
876858 return false;
877859 }
878-
879- bits -= op ;
880- wbit = 0 ;
881- iw += 1 ;
882860 }
883861
884862 return true;
@@ -928,6 +906,7 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
928906 size_t iw = bit >> (sb -> s_blocksize_bits + 3 );
929907 u32 wbits = 8 * sb -> s_blocksize ;
930908 u32 wbit = bit & (wbits - 1 );
909+ u32 op ;
931910 size_t end ;
932911 struct rb_node * n ;
933912 struct e_node * e ;
@@ -945,14 +924,11 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
945924 return false;
946925
947926use_wnd :
948- while (iw < wnd -> nwnd && bits ) {
949- u32 tail , op ;
950-
927+ for (; iw < wnd -> nwnd && bits ; iw ++ , bits -= op , wbit = 0 ) {
951928 if (unlikely (iw + 1 == wnd -> nwnd ))
952929 wbits = wnd -> bits_last ;
953930
954- tail = wbits - wbit ;
955- op = min_t (u32 , tail , bits );
931+ op = min_t (u32 , wbits - wbit , bits );
956932
957933 if (wnd -> free_bits [iw ]) {
958934 bool ret ;
@@ -966,10 +942,6 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
966942 if (!ret )
967943 goto out ;
968944 }
969-
970- bits -= op ;
971- wbit = 0 ;
972- iw += 1 ;
973945 }
974946 ret = true;
975947
0 commit comments