Commit edb853ff authored by Kari Argillander's avatar Kari Argillander Committed by Konstantin Komarov

fs/ntfs3: Fix ntfs_look_for_free_space() does only report -ENOSPC

If ntfs_refresh_zone() returns error it will be changed to -ENOSPC. It
is not right. Also caller of this functions also check other errors.

Fixes: 78ab59fe ("fs/ntfs3: Rework file operations")
Signed-off-by: default avatarKari Argillander <kari.argillander@gmail.com>
Signed-off-by: default avatarKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
parent cffb5152
...@@ -357,7 +357,7 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len, ...@@ -357,7 +357,7 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len,
enum ALLOCATE_OPT opt) enum ALLOCATE_OPT opt)
{ {
int err; int err;
CLST alen = 0; CLST alen;
struct super_block *sb = sbi->sb; struct super_block *sb = sbi->sb;
size_t alcn, zlen, zeroes, zlcn, zlen2, ztrim, new_zlen; size_t alcn, zlen, zeroes, zlcn, zlen2, ztrim, new_zlen;
struct wnd_bitmap *wnd = &sbi->used.bitmap; struct wnd_bitmap *wnd = &sbi->used.bitmap;
...@@ -369,13 +369,15 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len, ...@@ -369,13 +369,15 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len,
if (!zlen) { if (!zlen) {
err = ntfs_refresh_zone(sbi); err = ntfs_refresh_zone(sbi);
if (err) if (err)
goto out; goto up_write;
zlen = wnd_zone_len(wnd); zlen = wnd_zone_len(wnd);
} }
if (!zlen) { if (!zlen) {
ntfs_err(sbi->sb, "no free space to extend mft"); ntfs_err(sbi->sb, "no free space to extend mft");
goto out; err = -ENOSPC;
goto up_write;
} }
lcn = wnd_zone_bit(wnd); lcn = wnd_zone_bit(wnd);
...@@ -384,12 +386,11 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len, ...@@ -384,12 +386,11 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len,
wnd_zone_set(wnd, lcn + alen, zlen - alen); wnd_zone_set(wnd, lcn + alen, zlen - alen);
err = wnd_set_used(wnd, lcn, alen); err = wnd_set_used(wnd, lcn, alen);
if (err) { if (err)
up_write(&wnd->rw_lock); goto up_write;
return err;
}
alcn = lcn; alcn = lcn;
goto out; goto space_found;
} }
/* /*
* 'Cause cluster 0 is always used this value means that we should use * 'Cause cluster 0 is always used this value means that we should use
...@@ -403,15 +404,17 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len, ...@@ -403,15 +404,17 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len,
alen = wnd_find(wnd, len, lcn, BITMAP_FIND_MARK_AS_USED, &alcn); alen = wnd_find(wnd, len, lcn, BITMAP_FIND_MARK_AS_USED, &alcn);
if (alen) if (alen)
goto out; goto space_found;
/* Try to use clusters from MftZone. */ /* Try to use clusters from MftZone. */
zlen = wnd_zone_len(wnd); zlen = wnd_zone_len(wnd);
zeroes = wnd_zeroes(wnd); zeroes = wnd_zeroes(wnd);
/* Check too big request */ /* Check too big request */
if (len > zeroes + zlen || zlen <= NTFS_MIN_MFT_ZONE) if (len > zeroes + zlen || zlen <= NTFS_MIN_MFT_ZONE) {
goto out; err = -ENOSPC;
goto up_write;
}
/* How many clusters to cat from zone. */ /* How many clusters to cat from zone. */
zlcn = wnd_zone_bit(wnd); zlcn = wnd_zone_bit(wnd);
...@@ -430,9 +433,12 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len, ...@@ -430,9 +433,12 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len,
/* Allocate continues clusters. */ /* Allocate continues clusters. */
alen = wnd_find(wnd, len, 0, alen = wnd_find(wnd, len, 0,
BITMAP_FIND_MARK_AS_USED | BITMAP_FIND_FULL, &alcn); BITMAP_FIND_MARK_AS_USED | BITMAP_FIND_FULL, &alcn);
if (!alen) {
err = -ENOSPC;
goto up_write;
}
out: space_found:
if (alen) {
err = 0; err = 0;
*new_len = alen; *new_len = alen;
*new_lcn = alcn; *new_lcn = alcn;
...@@ -442,10 +448,7 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len, ...@@ -442,10 +448,7 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len,
/* Set hint for next requests. */ /* Set hint for next requests. */
if (!(opt & ALLOCATE_MFT)) if (!(opt & ALLOCATE_MFT))
sbi->used.next_free_lcn = alcn + alen; sbi->used.next_free_lcn = alcn + alen;
} else { up_write:
err = -ENOSPC;
}
up_write(&wnd->rw_lock); up_write(&wnd->rw_lock);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment