Commit 63e92a0c authored by Konstantin Komarov's avatar Konstantin Komarov

fs/ntfs3: Undo critial modificatins to keep directory consistency

Affect xfstest 320.
Signed-off-by: default avatarKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
parent e483783c
...@@ -1778,10 +1778,11 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni, ...@@ -1778,10 +1778,11 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,
struct indx_node *n1 = fnd->nodes[level]; struct indx_node *n1 = fnd->nodes[level];
struct INDEX_HDR *hdr1 = &n1->index->ihdr; struct INDEX_HDR *hdr1 = &n1->index->ihdr;
struct INDEX_HDR *hdr2; struct INDEX_HDR *hdr2;
u32 to_copy, used; u32 to_copy, used, used1;
CLST new_vbn; CLST new_vbn;
__le64 t_vbn, *sub_vbn; __le64 t_vbn, *sub_vbn;
u16 sp_size; u16 sp_size;
void *hdr1_saved = NULL;
/* Try the most easy case. */ /* Try the most easy case. */
e = fnd->level - 1 == level ? fnd->de[level] : NULL; e = fnd->level - 1 == level ? fnd->de[level] : NULL;
...@@ -1814,6 +1815,13 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni, ...@@ -1814,6 +1815,13 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,
return -ENOMEM; return -ENOMEM;
memcpy(up_e, sp, sp_size); memcpy(up_e, sp, sp_size);
used1 = le32_to_cpu(hdr1->used);
hdr1_saved = kmemdup(hdr1, used1, GFP_NOFS);
if (!hdr1_saved) {
err = -ENOMEM;
goto out;
}
if (!hdr1->flags) { if (!hdr1->flags) {
up_e->flags |= NTFS_IE_HAS_SUBNODES; up_e->flags |= NTFS_IE_HAS_SUBNODES;
up_e->size = cpu_to_le16(sp_size + sizeof(u64)); up_e->size = cpu_to_le16(sp_size + sizeof(u64));
...@@ -1846,7 +1854,7 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni, ...@@ -1846,7 +1854,7 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,
hdr_insert_head(hdr2, de_t, to_copy); hdr_insert_head(hdr2, de_t, to_copy);
/* Remove all entries (sp including) from hdr1. */ /* Remove all entries (sp including) from hdr1. */
used = le32_to_cpu(hdr1->used) - to_copy - sp_size; used = used1 - to_copy - sp_size;
memmove(de_t, Add2Ptr(sp, sp_size), used - le32_to_cpu(hdr1->de_off)); memmove(de_t, Add2Ptr(sp, sp_size), used - le32_to_cpu(hdr1->de_off));
hdr1->used = cpu_to_le32(used); hdr1->used = cpu_to_le32(used);
...@@ -1876,8 +1884,6 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni, ...@@ -1876,8 +1884,6 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,
if (!level) { if (!level) {
/* Insert in root. */ /* Insert in root. */
err = indx_insert_into_root(indx, ni, up_e, NULL, ctx, fnd, 0); err = indx_insert_into_root(indx, ni, up_e, NULL, ctx, fnd, 0);
if (err)
goto out;
} else { } else {
/* /*
* The target buffer's parent is another index buffer. * The target buffer's parent is another index buffer.
...@@ -1885,12 +1891,20 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni, ...@@ -1885,12 +1891,20 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,
*/ */
err = indx_insert_into_buffer(indx, ni, root, up_e, ctx, err = indx_insert_into_buffer(indx, ni, root, up_e, ctx,
level - 1, fnd); level - 1, fnd);
if (err) }
goto out;
if (err) {
/*
* Undo critical operations.
*/
indx_mark_free(indx, ni, new_vbn >> indx->idx2vbn_bits);
memcpy(hdr1, hdr1_saved, used1);
indx_write(indx, ni, n1, 0);
} }
out: out:
kfree(up_e); kfree(up_e);
kfree(hdr1_saved);
return err; return err;
} }
...@@ -1949,16 +1963,12 @@ int indx_insert_entry(struct ntfs_index *indx, struct ntfs_inode *ni, ...@@ -1949,16 +1963,12 @@ int indx_insert_entry(struct ntfs_index *indx, struct ntfs_inode *ni,
*/ */
err = indx_insert_into_root(indx, ni, new_de, fnd->root_de, ctx, err = indx_insert_into_root(indx, ni, new_de, fnd->root_de, ctx,
fnd, undo); fnd, undo);
if (err)
goto out;
} else { } else {
/* /*
* Found a leaf buffer, so we'll insert the new entry into it. * Found a leaf buffer, so we'll insert the new entry into it.
*/ */
err = indx_insert_into_buffer(indx, ni, root, new_de, ctx, err = indx_insert_into_buffer(indx, ni, root, new_de, ctx,
fnd->level - 1, fnd); fnd->level - 1, fnd);
if (err)
goto out;
} }
out: out:
......
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