diff options
author | Konstantin Komarov <almaz.alexandrovich@paragon-software.com> | 2022-10-11 20:19:36 +0300 |
---|---|---|
committer | Konstantin Komarov <almaz.alexandrovich@paragon-software.com> | 2022-11-14 19:50:48 +0300 |
commit | ec5fc72013762500867c9cef96fed89dc7161832 (patch) | |
tree | 1a7b889fe1a3d168eb1453666f5755274a429f11 /fs/ntfs3/bitmap.c | |
parent | 60ce8dfde03558bfc290cd915c60fa243ba2ae84 (diff) | |
download | lwn-ec5fc72013762500867c9cef96fed89dc7161832.tar.gz lwn-ec5fc72013762500867c9cef96fed89dc7161832.zip |
fs/ntfs3: Improve checking of bad clusters
Added new function wnd_set_used_safe.
Load $BadClus before $AttrDef instead of before $Bitmap.
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Diffstat (limited to 'fs/ntfs3/bitmap.c')
-rw-r--r-- | fs/ntfs3/bitmap.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c index a51805a3d91f..723fb64e6531 100644 --- a/fs/ntfs3/bitmap.c +++ b/fs/ntfs3/bitmap.c @@ -801,6 +801,44 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits) } /* + * wnd_set_used_safe - Mark the bits range from bit to bit + bits as used. + * + * Unlikely wnd_set_used/wnd_set_free this function is not full trusted. + * It scans every bit in bitmap and marks free bit as used. + * @done - how many bits were marked as used. + * + * NOTE: normally *done should be 0. + */ +int wnd_set_used_safe(struct wnd_bitmap *wnd, size_t bit, size_t bits, + size_t *done) +{ + size_t i, from = 0, len = 0; + int err = 0; + + *done = 0; + for (i = 0; i < bits; i++) { + if (wnd_is_free(wnd, bit + i, 1)) { + if (!len) + from = bit + i; + len += 1; + } else if (len) { + err = wnd_set_used(wnd, from, len); + *done += len; + len = 0; + if (err) + break; + } + } + + if (len) { + /* last fragment. */ + err = wnd_set_used(wnd, from, len); + *done += len; + } + return err; +} + +/* * wnd_is_free_hlp * * Return: True if all clusters [bit, bit+bits) are free (bitmap only). |